:root {
  color-scheme: dark;
  --bg: #08131a;
  --panel: rgba(11, 24, 32, 0.84);
  --panel-strong: #10222d;
  --line: rgba(130, 176, 193, 0.14);
  --line-strong: rgba(130, 176, 193, 0.28);
  --text: #edf5f7;
  --muted: #8ea8b3;
  --accent: #ff8c42;
  --accent-dark: #d66c27;
  --shadow: 0 28px 70px rgba(0, 0, 0, 0.35);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(56, 96, 120, 0.35), transparent 25%),
    radial-gradient(circle at top right, rgba(255, 140, 66, 0.18), transparent 28%),
    linear-gradient(135deg, #061017 0%, #0b1720 45%, #132631 100%);
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  width: min(1400px, calc(100vw - 32px));
  margin: 0 auto;
  min-height: 100vh;
  padding: 28px 0 36px;
  display: flex;
  flex-direction: column;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-top: 24px;
  padding: 16px 4px 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.site-footer-links {
  display: flex;
  align-items: center;
  gap: 14px;
}

.site-footer a {
  color: var(--text);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.footer-icon-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.site-footer .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease;
}

.site-footer .icon-button:hover {
  text-decoration: none;
  transform: translateY(-1px);
  border-color: rgba(255, 176, 124, 0.45);
  background: rgba(255, 176, 124, 0.12);
}

.icon-button:focus-visible {
  outline: 2px solid rgba(255, 176, 124, 0.85);
  outline-offset: 2px;
}

.site-footer .icon-button svg {
  width: 1.1rem;
  height: 1.1rem;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 420px);
  gap: 24px;
  align-items: stretch;
  margin-bottom: 24px;
}

.hero-copy {
  align-self: center;
}

.eyebrow {
  margin: 0 0 12px;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #ffb07c;
}

.hero h1 {
  margin: 0 0 12px;
  max-width: 13ch;
  font-size: clamp(2.3rem, 4vw, 4.6rem);
  line-height: 0.94;
}

.lede {
  margin: 0;
  max-width: 70ch;
  color: var(--muted);
  line-height: 1.6;
}

.hero-card,
.panel {
  backdrop-filter: blur(10px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero-card {
  display: grid;
  gap: 16px;
  padding: 20px;
  align-content: start;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.stat {
  padding: 16px;
  border-radius: 18px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.stat span {
  display: block;
  font-size: 2rem;
  font-weight: 700;
}

.stat label {
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  flex: 1 0 auto;
}

.panel {
  padding: 20px;
}

.panel-wide {
  grid-column: 1 / -1;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 240px;
  padding: 28px;
  border: 2px dashed var(--line-strong);
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(18, 37, 49, 0.96), rgba(13, 28, 37, 0.98)),
    repeating-linear-gradient(
      -45deg,
      rgba(255, 140, 66, 0.05),
      rgba(255, 140, 66, 0.05) 14px,
      transparent 14px,
      transparent 28px
    );
  text-align: center;
  transition: border-color 0.2s ease, transform 0.2s ease, background-color 0.2s ease;
}

.drop-zone.is-active {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.drop-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 650;
}

.drop-subtitle {
  margin: 8px 0 14px;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.controls-spacer {
  flex: 1 1 auto;
  min-width: 24px;
}

.checkbox-field {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.checkbox-field span {
  white-space: nowrap;
}

.output-planner {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.output-plan-panel.is-collapsed #output-planner {
  display: none;
}

.planner-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  color: var(--text);
}

.planner-head-copy {
  display: grid;
  gap: 4px;
}

.planner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.planner-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.planner-summary-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.pattern-card {
  display: grid;
  gap: 8px;
  min-width: 110px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
}

.pattern-card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.pattern-name {
  font-size: 0.78rem;
  color: var(--muted);
}

.pattern-card-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.pattern-count-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.82rem;
}

.pattern-count-pill strong {
  color: var(--text);
  font-size: 0.95rem;
}

.pattern-grid {
  display: grid;
  grid-template-columns: repeat(2, 12px);
  grid-template-rows: repeat(2, 12px);
  gap: 3px;
}

.pattern-cell {
  border-radius: 2px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.05);
}

.pattern-cell.is-filled {
  background: rgba(255, 140, 66, 0.85);
  border-color: rgba(255, 140, 66, 0.95);
}

.pattern-stepper {
  display: inline-flex;
  gap: 8px;
}

.pattern-adjust {
  min-width: 42px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
}

.pattern-adjust:hover {
  background: rgba(255, 255, 255, 0.08);
}

.pattern-adjust-primary {
  border-color: rgba(255, 140, 66, 0.45);
  background: rgba(255, 140, 66, 0.16);
}

.pattern-adjust-primary:hover {
  background: rgba(255, 140, 66, 0.24);
}

.button {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background-color 0.15s ease;
}

.button:hover:enabled {
  transform: translateY(-1px);
  background: var(--accent-dark);
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button-secondary {
  background: #183443;
  color: var(--text);
}

.button-secondary:hover:enabled {
  background: #214759;
}

.status,
.section-meta {
  color: var(--muted);
}

.action-panel {
  display: grid;
  gap: 12px;
}

.progress-stack {
  display: grid;
  gap: 12px;
}

.progress-stack.is-hidden {
  display: none;
}

.progress-block {
  display: grid;
  gap: 8px;
}

.progress-head,
.section-head-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.progress-head {
  font-size: 0.92rem;
  color: var(--muted);
}

.progress-meta {
  color: var(--text);
}

.progress-track {
  position: relative;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff8c42 0%, #ffd166 100%);
  transition: width 0.2s ease;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.collapse-button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
}

.collapse-button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.file-list,
.preview-grid,
.merged-preview {
  min-height: 160px;
}

.file-list {
  display: grid;
  gap: 14px;
}

.file-card {
  display: grid;
  grid-template-columns: minmax(0, 190px) minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  border-radius: 18px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.file-card-meta {
  display: grid;
  gap: 12px;
  align-content: start;
}

.file-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.file-card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.file-card strong {
  font-size: 0.98rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: #ffbf95;
  background: rgba(255, 140, 66, 0.08);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover {
  background: rgba(255, 140, 66, 0.12);
  border-color: rgba(255, 140, 66, 0.4);
}

.trash-icon {
  position: relative;
  width: 12px;
  height: 12px;
  border: 1.8px solid currentColor;
  border-top: 0;
  border-radius: 0 0 2px 2px;
}

.trash-icon::before {
  content: "";
  position: absolute;
  left: -2px;
  top: -4px;
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.trash-icon::after {
  content: "";
  position: absolute;
  left: 3px;
  top: -6px;
  width: 4px;
  height: 2px;
  border: 1.6px solid currentColor;
  border-bottom: 0;
  border-radius: 2px 2px 0 0;
}

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.field span {
  font-size: 0.85rem;
}

.field select {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #0c1a22;
  color: var(--text);
}

.thumb-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-content: start;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}

.preview-card {
  padding: 12px;
  border-radius: 18px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.preview-card.is-draggable {
  cursor: grab;
}

.preview-card.is-dragging {
  opacity: 0.35;
  transform: scale(0.98);
}

.preview-card.is-drop-target {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 140, 66, 0.5);
}

.preview-card p,
.file-card p {
  margin: 10px 0 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.thumb,
.merged-page {
  width: 100%;
  border-radius: 12px;
  background: white;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.thumb-button,
.page-thumb-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.thumb-button img,
.page-thumb-button img {
  display: block;
}

.thumb-label {
  margin: 6px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

.merged-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}

.empty-state {
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 18px;
  padding: 24px;
}

.is-collapsed #label-grid {
  display: none;
}

#source-panel.is-collapsed #source-list {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 8, 12, 0.82);
  backdrop-filter: blur(8px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(1080px, 100%);
  max-height: calc(100vh - 48px);
  display: grid;
  gap: 16px;
  padding: 20px;
  overflow: auto;
  border-radius: 24px;
  border: 1px solid var(--line-strong);
  background: rgba(9, 20, 28, 0.96);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.modal-head h2 {
  margin: 0;
}

.modal-caption {
  margin: 6px 0 0;
  color: var(--muted);
}

.modal-body {
  display: grid;
  place-items: center;
}

.modal-image {
  max-width: 100%;
  max-height: calc(100vh - 180px);
  border-radius: 16px;
  background: white;
}

@media (max-width: 980px) {
  .hero,
  .layout {
    grid-template-columns: 1fr;
  }

  .section-head,
  .section-head-main,
  .progress-head,
  .planner-head {
    align-items: start;
    flex-direction: column;
  }

  .hero-stats {
    grid-template-columns: 1fr 1fr;
  }

  .file-card {
    grid-template-columns: 1fr;
  }

  .site-footer {
    flex-direction: column;
    align-items: start;
  }

  .site-footer-links {
    flex-wrap: wrap;
  }

  .modal {
    padding: 12px;
  }

  .planner-actions {
    width: 100%;
    justify-content: space-between;
    margin-bottom: 8px;
  }

  .output-planner {
    margin-top: 8px;
  }

  .pattern-card {
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
  }

  .pattern-card-footer {
    align-items: stretch;
  }

  .pattern-count-pill,
  .pattern-stepper {
    width: 100%;
  }

  .pattern-stepper {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pattern-adjust {
    width: 100%;
  }
}
