/* --- Base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1a1f2e;
  --muted: #5c6478;
  --accent: #3d6ee8;
  --accent-hover: #2d5ad4;
  --border: #e2e6ef;
  --shadow: 0 8px 32px rgba(26, 31, 46, 0.08);
  --shadow-sm: 0 4px 16px rgba(26, 31, 46, 0.06);
  --radius: 16px;
  --radius-sm: 12px;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, sans-serif;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

/* --- Hero --- */
.hero {
  text-align: center;
  margin-bottom: 1.75rem;
}

.hero__title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero__desc {
  margin: 0 auto;
  max-width: 36rem;
  color: var(--muted);
  font-size: 0.95rem;
}

/* --- Layout --- */
.layout {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* --- Card --- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.25rem 1.5rem;
  border: 1px solid var(--border);
}

.card__title {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.card__hint {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

/* --- Upload --- */
.upload-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 560px) {
  .upload-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  padding: 1rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #fafbfd 0%, #fff 100%);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.dropzone:hover,
.dropzone:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.dropzone__label {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.35rem;
}

.dropzone__cta {
  font-size: 0.85rem;
  color: var(--accent);
}

.dropzone__error {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: #c41e3a;
  min-height: 1.2em;
}

/* Merge options */
.merge-options {
  margin: 1.25rem 0 0;
  padding: 0;
  border: none;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.merge-options__legend {
  width: 100%;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  padding: 0;
}

.radio {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.radio input {
  accent-color: var(--accent);
}

/* --- Custom labels & center text --- */
.text-fields {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.text-fields__intro {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.field {
  display: block;
  margin-bottom: 0.85rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field__label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.field__input {
  width: 100%;
  max-width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafbfd;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field__input::placeholder {
  color: #9aa3b2;
}

.field__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 110, 232, 0.15);
  background: #fff;
}

/* --- Buttons --- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn--ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn--ghost:hover {
  background: var(--bg);
  color: var(--text);
}

.btn--download {
  margin-top: 1rem;
  background: #1a1f2e;
  color: #fff;
  width: 100%;
  text-align: center;
}

.btn--download:hover {
  background: #2d3548;
}

/* Loading spinner inside button */
.btn__spinner {
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.btn--primary.is-loading .btn__text {
  opacity: 0.85;
}

/* --- Preview --- */
.preview-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 560px) {
  .preview-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.preview-box {
  margin: 0;
}

.preview-box__cap {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.preview-box__inner {
  position: relative;
  min-height: 160px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.preview-box__inner img {
  max-width: 100%;
  max-height: 280px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.preview-box__placeholder {
  font-size: 0.85rem;
  color: var(--muted);
}

.merge-error {
  margin: 0 0 0.75rem;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  color: #9b1c31;
  background: #fdeef0;
  border-radius: var(--radius-sm);
  border: 1px solid #f5c6cb;
}

.merge-error[hidden] {
  display: none;
}

/* --- Result --- */
.result-wrap {
  min-height: 120px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
}

.result-placeholder {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.result-img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.card--result .btn--download[hidden] {
  display: none;
}

/* --- Footer --- */
.footer {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.footer p {
  margin: 0;
}
