/* ═══════════════════════════════════════════════════════
   Obzek.io — Comyc Storyc
   Tokens mirror ../styles.css so the app reads as part of the site.
   ═══════════════════════════════════════════════════════ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* Author `display` rules outrank the UA stylesheet's `[hidden] { display:none }`,
   so anything toggled via the `hidden` property needs this to actually hide. */
[hidden] { display: none !important; }

:root {
  --bg:           #05020F;
  --bg-surface:   #0A0619;
  --bg-card:      #0F0A22;
  --purple-mid:   #4A1D96;
  --purple-vivid: #6D28D9;
  --gold:         #C47B0A;
  --gold-bright:  #F59E0B;
  --gold-light:   #FCD34D;
  --text:         #EDE8FF;
  --text-sub:     #9D8EC4;
  --text-muted:   #4D4068;
  --border:       rgba(109, 40, 217, 0.22);
  --border-gold:  rgba(245, 158, 11, 0.32);
  --danger:       #F87171;
  --ok:           #34D399;

  --font-head: 'Sora', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --r: 12px;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Same purple wash the landing page uses, so the app doesn't feel bolted on. */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60rem 40rem at 12% -10%, rgba(109,40,217,.20), transparent 65%),
    radial-gradient(45rem 35rem at 95% 5%, rgba(245,158,11,.07), transparent 60%);
}

a { color: var(--gold-light); }

/* The topbar and its tool switcher live in ../shared/css/topbar.css. */

/* ─── LAYOUT ────────────────────────────────────────── */
main { max-width: 1400px; margin: 0 auto; padding: 2.5rem 2rem 4rem; }

.page-head { margin-bottom: 2rem; max-width: 64ch; }
.page-head h1 {
  font-family: 'Bangers', var(--font-head), sans-serif;
  font-weight: 400; font-size: clamp(2.3rem, 5vw, 3.4rem);
  letter-spacing: .02em; line-height: 1;
  /* The one place the app wears the comic voice its output has. */
  text-shadow: 2px 2px 0 var(--purple-mid), 4px 4px 0 rgba(5,2,15,.6);
}
.page-head p { color: var(--text-sub); margin-top: .8rem; font-size: .95rem; }

.layout { display: grid; grid-template-columns: minmax(0,1fr) 420px; gap: 1.5rem; align-items: start; }
.col-build { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }

/* The gift tag sits above the build layout rather than inside it: it only
   appears once a book has been exported, and when it does it's the thing
   to act on. */
#stepGift { margin-bottom: 1.5rem; }

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .col-preview { grid-column: 1; grid-row: auto; }
}
@media (max-width: 640px) {
  main { padding: 1.5rem 1rem 3rem; }
  .controls { grid-template-columns: 1fr !important; }
}

/* ─── PANEL ─────────────────────────────────────────── */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 1.25rem;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.panel-head h2 {
  font-family: var(--font-head); font-size: .95rem; font-weight: 700;
  letter-spacing: -.01em; display: flex; align-items: center; gap: .6rem;
}
.step {
  display: grid; place-items: center; width: 1.4rem; height: 1.4rem;
  border-radius: 50%; font-size: .7rem; font-weight: 700;
  background: rgba(109,40,217,.28); color: var(--gold-light);
  border: 1px solid var(--border);
}
.panel-actions { display: flex; gap: .5rem; }
.plan { font-size: .74rem; color: var(--text-sub); font-variant-numeric: tabular-nums; }

/* ─── BUTTONS ───────────────────────────────────────── */
.btn {
  font-family: var(--font-head); font-size: .8rem; font-weight: 600;
  padding: .55rem .95rem; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; transition: .18s ease; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  background: none; color: var(--text);
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-ghost { border-color: var(--border); color: var(--text-sub); }
.btn-ghost:hover:not(:disabled) { border-color: var(--purple-vivid); color: var(--text); background: rgba(109,40,217,.14); }
.btn-ghost.danger:hover:not(:disabled) { border-color: rgba(248,113,113,.5); color: var(--danger); background: rgba(248,113,113,.08); }
.btn-primary {
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  color: #1a0d00; font-weight: 700;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.btn-block { width: 100%; margin-top: .75rem; padding: .8rem; }
.btn-tiny { padding: .35rem .6rem; font-size: .7rem; }

/* ─── DROPZONE ──────────────────────────────────────── */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: .4rem;
  padding: 2rem 1rem; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border); border-radius: var(--r);
  color: var(--text-sub); transition: .2s ease;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.over {
  border-color: var(--gold-bright); background: rgba(245,158,11,.06); color: var(--text);
  outline: none;
}
.dropzone.over { transform: scale(1.005); }
.dropzone strong { font-family: var(--font-head); font-size: .95rem; color: var(--text); }
.dropzone span { font-size: .76rem; max-width: 52ch; }

.frames-ctrl { margin-top: .9rem; }
.ingest-status { margin-top: .8rem; font-size: .78rem; color: var(--text-sub); }
.ingest-status .err { color: var(--danger); display: block; }

/* ─── SHOT TRAY ─────────────────────────────────────── */
.tray {
  list-style: none; display: grid; gap: .6rem; margin-top: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
}
.tray:empty { display: none; }
.tile {
  position: relative; aspect-ratio: 1; border-radius: 9px; overflow: hidden;
  border: 1px solid var(--border); background: var(--bg-surface);
  cursor: grab; transition: .15s ease;
}
.tile:hover { border-color: var(--purple-vivid); }
.tile.selected { border-color: var(--gold-bright); box-shadow: 0 0 0 2px rgba(245,158,11,.25); }
.tile.dragging { opacity: .35; cursor: grabbing; }
.tile.drop-target { border-color: var(--gold-bright); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.tile .idx {
  position: absolute; top: 4px; left: 4px; z-index: 2;
  font-family: var(--font-head); font-size: .62rem; font-weight: 700;
  padding: .1rem .35rem; border-radius: 4px;
  background: rgba(5,2,15,.8); color: var(--gold-light);
}
/* The first shot is the cover, and the tray is where that gets decided —
   so it says so rather than leaving the rule to be discovered. */
.tile.cover .idx {
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  color: #1a0d00;
}
.tile .rm {
  position: absolute; top: 3px; right: 3px; z-index: 3;
  width: 1.15rem; height: 1.15rem; border-radius: 50%; border: none;
  background: rgba(5,2,15,.85); color: var(--text-sub);
  cursor: pointer; font-size: .8rem; line-height: 1; display: grid; place-items: center;
  opacity: 0; transition: .15s;
}
.tile:hover .rm { opacity: 1; }
.tile .rm:hover { background: var(--danger); color: #fff; }
.tile .lettered {
  position: absolute; bottom: 3px; right: 4px; z-index: 2;
  font-size: .62rem; color: var(--gold-light);
  text-shadow: 0 1px 3px rgba(5,2,15,.9);
}
.hint { font-size: .74rem; color: var(--text-muted); margin-top: .7rem; }

/* ─── CONTROLS ──────────────────────────────────────── */
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.ctrl { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.ctrl-wide { grid-column: 1 / -1; }
.ctrl > span { font-size: .74rem; color: var(--text-sub); display: flex; justify-content: space-between; gap: .5rem; }
.ctrl > span b { color: var(--gold-light); font-family: var(--font-head); font-variant-numeric: tabular-nums; }
.ctrl > span small { color: var(--text-muted); font-size: .95em; }

select, input[type="range"], input[type="text"] { width: 100%; font-family: var(--font-body); }
select, input[type="text"] {
  padding: .5rem .6rem; border-radius: 8px; font-size: .8rem;
  background: var(--bg-surface); color: var(--text); border: 1px solid var(--border);
}
select { cursor: pointer; }
input[type="text"]::placeholder { color: var(--text-muted); }
select:focus-visible, input:focus-visible { outline: 2px solid var(--purple-vivid); outline-offset: 1px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; height: 4px; border-radius: 2px;
  background: rgba(109,40,217,.35); cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--gold-bright); border: none; cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--gold-bright); border: none; cursor: pointer;
}
input[type="range"]:disabled { opacity: .4; cursor: not-allowed; }

.ctrl.check { flex-direction: row; align-items: center; gap: .55rem; }
.ctrl.check span { font-size: .78rem; color: var(--text-sub); }
input[type="checkbox"] {
  width: 1rem; height: 1rem; accent-color: var(--gold-bright);
  cursor: pointer; flex: none;
}

/* ─── PALETTE SWATCHES ──────────────────────────────── */
.swatch-row { display: flex; flex-wrap: wrap; gap: .45rem; }
/* A palette is four colours doing four jobs, so the swatch shows all four
   rather than picking one to stand for the set. */
.swatch {
  width: 3.1rem; height: 2rem; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); padding: 0; overflow: hidden;
  display: flex; transition: .15s ease;
}
.swatch i { display: block; height: 100%; }
.swatch:hover { transform: translateY(-1px); border-color: var(--purple-vivid); }
.swatch.active { border-color: var(--gold-bright); box-shadow: 0 0 0 2px rgba(245,158,11,.3); }

/* ─── INK PICKER ────────────────────────────────────── */
.ink-picker {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: .55rem;
}
.ink-opt {
  display: flex; flex-direction: column; gap: .4rem; align-items: center;
  padding: .5rem .4rem; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-surface);
  color: var(--text-sub); font-family: var(--font-body); transition: .15s ease;
}
.ink-opt:hover { border-color: var(--purple-vivid); background: rgba(109,40,217,.12); color: var(--text); }
.ink-opt.active { border-color: var(--gold-bright); background: rgba(245,158,11,.08); color: var(--text); }
.ink-opt canvas { width: 100%; height: auto; display: block; border-radius: 4px; }
.ink-opt span { font-size: .68rem; font-weight: 500; text-align: center; line-height: 1.25; }

/* ─── PREVIEW ───────────────────────────────────────── */
.page-nav {
  display: flex; align-items: center; justify-content: center; gap: .8rem;
  margin-bottom: .8rem;
}
.page-nav span {
  font-family: var(--font-head); font-size: .78rem; font-weight: 600;
  color: var(--text-sub); min-width: 9rem; text-align: center;
}
.page-nav .btn-tiny { font-size: 1rem; line-height: 1; padding: .2rem .6rem; }

.stage {
  position: relative; border-radius: var(--r); overflow: hidden;
  background: repeating-conic-gradient(#151024 0% 25%, #100c1c 0% 50%) 50% / 16px 16px;
  border: 1px solid var(--border);
  display: grid; place-items: center; min-height: 260px;
  padding: .9rem;
}
#preview { display: block; max-width: 100%; touch-action: none; box-shadow: 0 14px 40px rgba(0,0,0,.55); }
#preview.grabbable { cursor: grab; }
#preview.grabbing { cursor: grabbing; }
.stage-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: .82rem; color: var(--text-muted); pointer-events: none; text-align: center; padding: 1rem;
}
.stage-busy {
  position: absolute; top: .6rem; right: .6rem;
  font-family: var(--font-head); font-size: .68rem; font-weight: 600;
  padding: .25rem .6rem; border-radius: 100px;
  background: rgba(5,2,15,.86); border: 1px solid var(--border-gold);
  color: var(--gold-light);
}

/* ─── PAGE STRIP ────────────────────────────────────── */
/* Every page of the book at a glance — the one thing the single-page preview
   can't show, and the fastest way to jump between them. */
.page-strip {
  display: flex; gap: .45rem; margin-top: .8rem;
  overflow-x: auto; padding-bottom: .3rem;
}
.page-strip:empty { display: none; }
.page-thumb {
  flex: none; width: 3.1rem; cursor: pointer; padding: 0;
  border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
  background: var(--bg-surface); transition: .15s ease; position: relative;
}
.page-thumb canvas { display: block; width: 100%; height: auto; }
.page-thumb:hover { border-color: var(--purple-vivid); }
.page-thumb.active { border-color: var(--gold-bright); box-shadow: 0 0 0 2px rgba(245,158,11,.25); }
.page-thumb b {
  position: absolute; inset: auto 0 0 0; font-size: .55rem; font-weight: 600;
  background: rgba(5,2,15,.8); color: var(--text-sub); text-align: center;
}

.result-meta { margin-top: .6rem; font-size: .74rem; color: var(--text-sub); text-align: center; }

.sel-name {
  font-size: .76rem; color: var(--text-sub); margin-bottom: .8rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.footnote { margin-top: 2rem; font-size: .76rem; color: var(--text-muted); text-align: center; max-width: 74ch; margin-inline: auto; }
.footnote strong { color: var(--text-sub); }

/* ─── TOAST ─────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  z-index: 200; padding: .7rem 1.1rem; border-radius: 9px;
  background: var(--bg-card); border: 1px solid var(--border-gold);
  font-size: .8rem; box-shadow: 0 12px 40px rgba(0,0,0,.5); max-width: 90vw;
}
.toast.err { border-color: rgba(248,113,113,.5); color: var(--danger); }

/* ─── PRINTING ──────────────────────────────────────── */
/* Each page is rasterised to a single image first, so what prints is exactly
   what was exported — no reflow, no missing dots. One image per sheet. */
/* Each image is exactly one sheet: the injected @page rule matches the page's
   own proportions, so width:100% with an automatic height lands on it. */
.print-area { display: none; }
.print-area img { display: block; width: 100%; height: auto; }
.print-area img + img { break-before: page; page-break-before: always; }

/* Scoped to `:not(.printing-gift-tag)` so printing the gift tag (see
   ../../shared/css/gift-qr.css) gets the paper to itself. */
@media print {
  body:not(.printing-gift-tag) { background: #fff; }
  body:not(.printing-gift-tag)::before,
  body:not(.printing-gift-tag) #topbar,
  body:not(.printing-gift-tag) main,
  body:not(.printing-gift-tag) .toast { display: none !important; }
  body:not(.printing-gift-tag) .print-area {
    display: block !important;
    position: static; margin: 0; padding: 0; width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
