/* STAX — styles.css
   Retro-arcade / CRT-era, modern-polished. Dark only.
   Shares brand tokens with The Lab root and Morph (LEVEL 01).
   Pixel type (Press Start 2P) lives in header, HUD and key actions;
   working controls stay clean and utilitarian. */

/* ---------- fonts (self-hosted, shared with the lab root) ---------- */

@font-face { font-family: "Press Start 2P"; font-style: normal; font-weight: 400; font-display: swap; src: url("/press-start-2p.woff2") format("woff2"); }
@font-face { font-family: "Press Start 2P Fallback"; src: local("Courier New"); size-adjust: 166.64%; ascent-override: 60%; descent-override: 0%; line-gap-override: 0%; }

/* ---------- tokens ---------- */

:root {
  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --line: #28283c;
  --control-line: #5e5e80; /* >=3:1 against --surface for form-field boundaries */
  --text: #e9e9f2;
  --dim: #9aa0b5;
  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;

  --pixel: "Press Start 2P", "Press Start 2P Fallback", "Courier New", monospace;
  --body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  --radius: 8px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.35);
  --space-gutter: clamp(16px, 4vw, 48px);
  --checker: repeating-conic-gradient(#1c1c2c 0% 25%, #14141f 0% 50%);
  --thumb-w: 150px;
}

/* ---------- base ---------- */

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

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(69, 240, 255, 0.05), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(69, 240, 255, 0.3); }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 200;
  background: var(--cyan); color: #05050d; padding: 10px 16px; border-radius: 6px;
  font-family: var(--mono); font-weight: 700; text-decoration: none;
  transition: transform 0.2s var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(60px); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.15);
}

a { color: var(--cyan); }

kbd {
  font-family: var(--mono); font-size: 11px; background: var(--surface-2);
  border: 1px solid var(--control-line); border-radius: 4px; padding: 1px 5px;
}

/* ---------- header ---------- */

.site-header {
  padding: 26px var(--space-gutter) 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lab-link {
  align-self: flex-start;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  padding: 6px 2px;
  transition: color 0.15s, text-shadow 0.15s;
}
.lab-link:hover { color: var(--cyan); text-shadow: var(--glow-cyan); }

.level {
  margin: 0;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--gold);
}

.wordmark {
  margin: 6px 0 4px;
  font-family: var(--pixel);
  font-size: clamp(22px, 4.5vw, 34px);
  letter-spacing: 3px;
  color: var(--text);
  text-shadow: 0 0 16px rgba(69, 240, 255, 0.55), 3px 3px 0 var(--magenta);
}

.tagline {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}

.cursor { color: var(--cyan); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- layout ---------- */

main {
  flex: 1;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 20px var(--space-gutter) 72px;
}

/* ---------- drop zone ---------- */

.drop-zone {
  border: 2px dashed var(--line);
  border-radius: 14px;
  padding: clamp(40px, 8vw, 90px) 20px;
  text-align: center;
  cursor: pointer;
  background: linear-gradient(180deg, var(--surface), rgba(18, 18, 29, 0.3));
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s var(--ease-out);
}
.drop-zone:hover, .drop-zone.is-over {
  border-color: var(--cyan);
  box-shadow: 0 0 28px rgba(69, 240, 255, 0.12), inset 0 0 48px rgba(69, 240, 255, 0.04);
}
.drop-zone.is-over { transform: scale(1.01); }

.drop-art {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0;
  margin-bottom: 28px;
  height: 56px;
}

.sheet {
  display: inline-block;
  width: 34px; height: 46px;
  border-radius: 2px;
  border: 2px solid rgba(10, 10, 18, 0.6);
}
.sheet-a { background: var(--gold); transform: rotate(-10deg) translate(8px, 2px); }
.sheet-b { background: var(--magenta); transform: translateY(-4px); z-index: 1; position: relative; }
.sheet-c { background: var(--cyan); transform: rotate(10deg) translate(-8px, 2px); }

.drop-zone:hover .sheet-a { animation: fan-a 1.4s var(--ease-out) infinite alternate; }
.drop-zone:hover .sheet-c { animation: fan-c 1.4s var(--ease-out) infinite alternate; }
@keyframes fan-a { to { transform: rotate(-18deg) translate(4px, 0); } }
@keyframes fan-c { to { transform: rotate(18deg) translate(-4px, 0); } }

.drop-title {
  margin: 0 0 14px;
  font-family: var(--pixel);
  font-size: clamp(11px, 2.6vw, 15px);
  color: var(--text);
  letter-spacing: 1px;
}

.drop-sub { margin: 0 0 18px; color: var(--dim); font-size: 14px; }

.drop-formats {
  margin: 22px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
}

.privacy-note {
  margin: 18px auto 0;
  max-width: 520px;
  text-align: center;
  font-size: 12.5px;
  color: var(--dim);
}

/* ---------- HUD strip ---------- */

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 14px;
}

.hud-stats {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--dim);
}
.hud-stat output { color: var(--cyan); text-shadow: 0 0 8px rgba(69, 240, 255, 0.4); }
.hud-sel output { color: var(--gold); text-shadow: 0 0 8px rgba(255, 200, 87, 0.4); }

.hud-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- sources strip ---------- */

.sources {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.sources:empty { display: none; }

.source {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 6px 5px 12px;
  font-family: var(--mono);
  font-size: 12px;
  max-width: 100%;
}
.source-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-pages { color: var(--dim); flex: 0 0 auto; }

.dot {
  flex: 0 0 auto;
  width: 10px; height: 10px;
  border-radius: 2px;
  background: var(--c, var(--cyan));
  box-shadow: 0 0 6px var(--c, var(--cyan));
}

.source-remove {
  position: relative; /* anchors the coarse-pointer ::after hit-area */
  flex: 0 0 auto;
  width: 24px; height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  color: var(--dim);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.source-remove:hover { color: var(--red); border-color: var(--red); }

.hint { margin: 0 0 16px; font-size: 12px; color: var(--dim); }

/* ---------- page grid ---------- */

.page-grid {
  position: relative;
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--thumb-w), 1fr));
  gap: 14px;
}

.empty-note {
  margin: 0 0 18px;
  padding: 28px 16px;
  text-align: center;
  border: 2px dashed var(--line);
  border-radius: 12px;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 13px;
}

.thumb {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: grab;
  touch-action: pan-y;
  transition: border-color 0.12s, box-shadow 0.12s, opacity 0.15s;
}
.thumb:hover { border-color: var(--control-line); }
.thumb:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
.thumb.is-picked {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold), 0 0 18px rgba(255, 200, 87, 0.35);
}
.thumb.drag-src { opacity: 0.35; cursor: grabbing; }
.thumb.is-selected { border-color: var(--cyan); box-shadow: inset 0 0 0 1px rgba(69, 240, 255, 0.4); }

.thumb-top {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
}
.thumb-num { font-family: var(--pixel); font-size: 9px; color: var(--text); }
.thumb-rot-badge { margin-left: auto; color: var(--gold); font-size: 11px; }

.thumb-check {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.thumb-check input {
  width: 16px; height: 16px;
  margin: 0;
  accent-color: var(--cyan);
  cursor: pointer;
}

.thumb-frame {
  position: relative;
  aspect-ratio: 1 / 1.414;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--checker) 0 0 / 12px 12px;
  border-radius: 6px;
  overflow: hidden;
  cursor: zoom-in;
}
.thumb-frame canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

/* shimmer rides a transform (compositor-only) — dozens of skeletons may
   animate at once on big docs, so no background-position repaints */
.thumb-skel { position: absolute; inset: 0; overflow: hidden; background: var(--surface-2); }
.thumb-skel::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 40%, #232336 50%, transparent 60%);
  transform: translateX(-100%); animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

.thumb-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface-2);
  color: var(--red);
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
  padding: 8px;
}

.thumb-btns { display: flex; gap: 6px; }

.t-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--dim);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.t-btn:hover { color: var(--cyan); border-color: var(--cyan); }
.t-btn.t-del:hover { color: var(--red); border-color: var(--red); }

/* drag affordances */

.drop-indicator {
  position: absolute;
  width: 3px;
  border-radius: 2px;
  background: var(--cyan);
  box-shadow: var(--glow-cyan);
  pointer-events: none;
  z-index: 5;
}

.drag-ghost {
  position: fixed;
  z-index: 150;
  width: var(--thumb-w);
  pointer-events: none;
  opacity: 0.85;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.6));
  transform: rotate(2deg);
}
.drag-ghost .thumb { cursor: grabbing; }

.page-grid.is-reordering .thumb { cursor: grabbing; }

/* ---------- actions bar ---------- */

.actions-bar {
  position: sticky;
  bottom: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(26, 26, 42, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 -8px 30px rgba(5, 5, 12, 0.45);
}

.out-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 28px;
  align-items: center;
}

.opt-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.field-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
}

#fileName {
  width: 200px;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--control-line);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 13px;
  transition: border-color 0.12s;
}
#fileName:hover { border-color: #74749a; }

.action-btns { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- buttons & chips ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  min-height: 40px; /* morph-baseline touch/click target */
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s var(--ease-out), border-color 0.12s, box-shadow 0.12s, color 0.12s;
}
.btn:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 12px rgba(69, 240, 255, 0.22);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.is-busy { opacity: 0.75; cursor: progress; }

.btn-primary { background: var(--cyan); border-color: var(--cyan); color: #05050d; }
.btn-primary:hover { box-shadow: 0 0 18px rgba(69, 240, 255, 0.5); }
.btn-ghost { background: transparent; }
.btn-big { font-family: var(--pixel); font-size: 11px; padding: 14px 20px; }
.btn-sm { font-size: 11.5px; padding: 7px 11px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11.5px;
  min-height: 40px; /* morph-baseline touch/click target */
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, box-shadow 0.12s;
}
.chip:hover:not(:disabled) { border-color: var(--cyan); color: var(--text); }
.chip.is-active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(69, 240, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(69, 240, 255, 0.35);
}
.chip:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- result panel ---------- */

.result-panel {
  margin-top: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 26px 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.result-heading {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(12px, 2.6vw, 16px);
  color: var(--green);
  text-shadow: 0 0 12px rgba(65, 255, 139, 0.5);
}

.result-meta {
  margin: 0;
  font-family: var(--mono);
  font-size: 14px;
  word-break: break-all;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.result-panel .hint { margin: 0; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s var(--ease-out) both;
}
.toast-info { border-left-color: var(--cyan); }
.toast-success { border-left-color: var(--green); }
.toast-warn { border-left-color: var(--gold); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
}

/* ---------- lightbox ---------- */

.lightbox {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  max-width: min(1240px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lightbox:not([open]) { display: none; }
.lightbox::backdrop { background: rgba(5, 5, 12, 0.8); }

.lightbox-close { align-self: flex-end; }

.lightbox-body {
  position: relative;
  flex: 1;
  min-height: 200px;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: var(--checker) 0 0 / 14px 14px;
  border-radius: 8px;
}
.lightbox-body canvas { display: block; max-width: 100%; height: auto; }

.lightbox-caption {
  margin: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
  word-break: break-all;
}

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 22px var(--space-gutter);
  text-align: center;
  color: var(--dim);
  font-size: 13px;
}
.site-footer p { margin: 0; }
.site-footer .footer-privacy { margin-top: 6px; font-size: 12px; }
.site-footer a { color: var(--cyan); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; text-shadow: var(--glow-cyan); }

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  :root { --thumb-w: 132px; }
  /* the tall stacked bar would cover most of a small viewport */
  .actions-bar { position: static; }
  .hud { flex-direction: column; align-items: stretch; }
  .hud-actions { justify-content: center; }
  .action-btns { flex-direction: column; }
  .action-btns .btn { width: 100%; }
  .opt-row { width: 100%; }
  #fileName { flex: 1; width: auto; }
  .wordmark { letter-spacing: 1px; }
  .source-name { max-width: 140px; }
}

@media (max-width: 360px) {
  :root { --thumb-w: 116px; }
  .page-grid { gap: 10px; }
}

/* larger touch targets on coarse pointers */
@media (pointer: coarse) {
  .chip { min-height: 40px; padding: 10px 14px; }
  .btn-sm { min-height: 40px; }
  .t-btn { min-height: 36px; }
  .thumb-check input { width: 20px; height: 20px; }
  /* 24px visual stays — invisible hit-area grows to 40x40 */
  .source-remove::after { content: ''; position: absolute; inset: -8px; }
}

/* full-viewport drop affordance while dragging files over the workbench */
body.is-dragover::after {
  content: var(--drop-overlay, 'DROP TO ADD FILES');
  position: fixed; inset: 12px; z-index: 180; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--cyan); border-radius: 14px;
  background: rgba(10, 10, 18, 0.72);
  color: var(--cyan); font-family: var(--pixel);
  font-size: clamp(11px, 2.6vw, 15px); letter-spacing: 1px; text-shadow: var(--glow-cyan);
}

/* ---------- reduced motion: kill all looping/auto animation ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important; scroll-behavior: auto !important;
  }
  .cursor, .thumb-skel::after { animation: none; }
  .drag-ghost { transform: none; }
}
