/* Quick Scan — global stylesheet.
 *
 * Token layer + shared chrome (:root, .panel, .btn, .toast, the overlay
 * anatomy, .app-header, .home) copied from arcade/public/styles.css so the
 * platform look is identical: Atkinson Hyperlegible, dark navy surfaces, jewel
 * praise tiers, 22px radius, 64px taps, no error-red. The "scan components"
 * section at the bottom is Quick Scan's own: the camera frame, the guide
 * overlay, the roster name tiles, the captured page, the name/save screen.
 */

:root {
  /* Praise tiers — gold=perfect, cyan=amazing, emerald=great, amethyst=good,
     slate=gentle; never an error red. */
  --gold: #ffd23f;
  --cyan: #36f1cd;
  --emerald: #7ae582;
  --amethyst: #9d8df1;
  --slate: #6c7a89;
  /* Surfaces */
  --bg-0: #070a1c;
  --bg-1: #0e1430;
  --bg-2: #161d44;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(150, 180, 255, 0.18);
  --ink: #eaf0ff;
  --ink-dim: #9fb0d8;
  --accent: #7aa2ff;
  --danger: #ff9aa2;
  /* Sizing */
  --radius: 22px;
  --tap-min: 64px;
  /* Ambient animation period. */
  --beat: 833ms;
}

@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('/fonts/atkinson-hyperlegible-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('/fonts/atkinson-hyperlegible-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 18px;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: 'Atkinson Hyperlegible', 'Quicksand', 'Segoe UI Rounded', 'Nunito',
    system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 800px at 50% -10%, #21306e 0%, transparent 60%),
    radial-gradient(900px 700px at 90% 110%, #2a1b54 0%, transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-0));
  background-attachment: fixed;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 {
  margin: 0 0 12px;
}

/* ---------- shared components (from arcade) ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.btn {
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  border-radius: var(--radius);
  padding: 16px 26px;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.btn:active {
  transform: scale(0.96);
}
.btn.primary {
  background: linear-gradient(150deg, #5f7bff, #8a5cff);
  border-color: transparent;
  box-shadow: 0 10px 30px -8px #5f7bff88;
}
.btn.ghost {
  min-height: 52px;
  padding: 10px 22px;
  font-size: 1.05rem;
  opacity: 0.92;
}
.btn[disabled] {
  opacity: 0.4;
  pointer-events: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%) translateY(20px);
  background: #11183c;
  border: 1px solid var(--panel-border);
  color: var(--ink);
  padding: 14px 22px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1.1rem;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Overlay anatomy (z-index ladder kept from arcade). */
.gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 6, 20, 0.7);
  backdrop-filter: blur(6px);
}
.gate-box {
  width: min(440px, 100%);
  border-radius: 20px;
  padding: 22px;
  background: linear-gradient(160deg, #1a2350, #11183c);
  border: 1px solid var(--panel-border);
  box-shadow: 0 24px 60px -20px #000d;
}

/* ---------- app chrome (from arcade) ---------- */

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin-bottom: 10px;
}
.app-header .header-title {
  font-weight: 700;
  font-size: 1.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-icon {
  min-width: 48px;
  min-height: 48px;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  font-size: 1.5rem;
  cursor: pointer;
}
.app-header .header-right {
  margin-left: auto;
}

/* ---------- home (from arcade) ---------- */

.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  gap: 8px;
}
.home-title {
  font-size: clamp(2rem, 9vw, 3.2rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0;
}
.home-tag {
  color: var(--ink-dim);
  font-size: 1.05rem;
  margin: 0 0 26px;
}
.home .btn.primary {
  min-height: 96px;
  font-size: 1.5rem;
  align-self: center;
  width: min(340px, 100%);
}
.settings-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 5;
}

/* The settings sheet (settings.js), opened via overlay(). */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.settings-row:last-child {
  margin-bottom: 0;
}
.settings-label {
  font-weight: 700;
}
.settings-select {
  min-height: var(--tap-min);
  max-width: 55%;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  padding: 0 12px;
  font-size: 1rem;
  font-family: inherit;
}
.settings-info {
  color: var(--ink-dim);
  font-size: 0.95rem;
  text-align: right;
}

/* ================= scan components (Quick Scan's own) ================= */

/* A plain top-to-bottom screen wrapper: header pinned, body fills. */
.scan {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.scan-body {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* The roster: big name tiles, grouped by class. */
.who-class {
  margin-bottom: 18px;
}
.who-class-name {
  color: var(--ink-dim);
  font-weight: 700;
  margin: 0 0 10px;
}
.name-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.name-tile {
  min-height: var(--tap-min);
  border-radius: 16px;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--panel-border);
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.name-tile:active {
  transform: scale(0.97);
}
.who-empty {
  color: var(--ink-dim);
  text-align: center;
  margin-top: 30px;
}

/* The camera stage: a 4:3 frame holding live video (S2) or, in this scaffold,
   a placeholder. The guide overlay draws focus corners on top. */
.camera-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  justify-content: center;
}
.frame {
  position: relative;
  width: 100%;
  max-width: 520px;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0a0f28;
  border: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.frame video,
.frame img,
.frame canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.frame-placeholder {
  color: var(--ink-dim);
  font-weight: 700;
  text-align: center;
  padding: 20px;
}
/* Guide corners — a calm cue where the page should sit, never a red box.
   Slate while searching, emerald once camera.js's hold-still sampler has
   seen the page held steady — a hint, not a timer, and capture stays manual. */
.guide {
  position: absolute;
  inset: 8%;
  pointer-events: none;
  border-radius: 12px;
}
.guide::before,
.guide::after,
.guide > span::before,
.guide > span::after {
  content: '';
  position: absolute;
  width: 34px;
  height: 34px;
  border: 4px solid var(--slate);
  opacity: 0.9;
  transition: border-color 0.25s ease;
}
.guide.ready::before,
.guide.ready::after,
.guide.ready > span::before,
.guide.ready > span::after {
  border-color: var(--emerald);
}
.guide::before { top: 0; left: 0; border-right: none; border-bottom: none; border-top-left-radius: 10px; }
.guide::after { top: 0; right: 0; border-left: none; border-bottom: none; border-top-right-radius: 10px; }
.guide > span::before { bottom: 0; left: 0; border-right: none; border-top: none; border-bottom-left-radius: 10px; }
.guide > span::after { bottom: 0; right: 0; border-left: none; border-top: none; border-bottom-right-radius: 10px; }

/* A big round capture button, and the row of secondary actions. */
.scan-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}
.scan-actions .btn {
  flex: 1;
  min-width: 140px;
}
.capture-btn {
  min-width: min(320px, 100%);
}
.page-count {
  color: var(--ink-dim);
  font-weight: 700;
  text-align: center;
  margin: 0 0 8px;
}
.camera-status {
  color: var(--ink-dim);
  text-align: center;
  min-height: 1.2em;
  margin: 0;
}
.camera-hint {
  color: var(--ink-dim);
  font-weight: 700;
  text-align: center;
  min-height: 1.2em;
  margin: 0;
}
.camera-hint.ready {
  color: var(--emerald);
}

/* The name/save screen: title field, quick chips, filename preview. */
.name-field {
  width: 100%;
  min-height: 64px;
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  padding: 0 18px;
  font-size: 1.3rem;
  font-family: inherit;
  margin-bottom: 12px;
}
.chips {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.chip {
  min-height: 48px;
  padding: 8px 16px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.filename-preview {
  color: var(--ink-dim);
  font-size: 0.95rem;
  word-break: break-word;
  margin: 0 0 18px;
}
.filename-preview strong {
  color: var(--ink);
  font-weight: 700;
}

/* Saving: a calm centered progress state (no countdown). */
.saving {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}
.spinner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 5px solid var(--panel-border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Done: a bright confirmation. */
.done {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}
.done-burst {
  font-size: 3.4rem;
  color: var(--gold);
  animation: done-pop var(--beat) ease-out;
}
@keyframes done-pop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.done-title {
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  margin: 0;
}
.done-file {
  color: var(--ink-dim);
  word-break: break-word;
}

/* Error: a calm slate message, never error-red framing. */
.error {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}
.error-mark {
  font-size: 3rem;
  color: var(--slate);
}
.error-msg {
  color: var(--ink-dim);
}

.center-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  width: min(360px, 100%);
}
.center-actions .btn {
  flex: 1;
  min-width: 140px;
}

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

@media (max-width: 480px) {
  #app {
    padding: 12px;
  }
}

@media (min-width: 1025px) and (pointer: fine) {
  #app {
    max-width: 900px;
  }
}

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