/* Colorwake camera (scanner) pages. Uses /assets/tokens.css and /assets/fonts.css.
   Layout follows design-system/scanner-pages.md: one screen at a time via body[data-state]. */

[hidden] { display: none !important; }

/* Cover shape for the corner guide, per collection (width / height of the printed cover) */
:root, [data-theme="halloween"] { --cover-ratio: 25 / 33; }
[data-theme="football"] { --cover-ratio: 7 / 10; }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--surface); color: var(--ink); font: 400 16px/24px var(--font-body); -webkit-font-smoothing: antialiased;
  overflow: hidden; overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none;
  /* Safari/WebKit: MindAR's negative-z-index camera <video> only composites behind the canvas
     if the parent has its own explicit stacking context. Do not remove. */
  position: relative; z-index: 0;
}
a { color: var(--accent-ink); font-weight: 600; }
:focus-visible { outline: 2px solid transparent; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--focus); border-radius: 8px; }
svg { flex: none; }

/* The AR scene and camera video only show while the camera screens are up */
a-scene { position: fixed; inset: 0; width: 100%; height: 100%; }
body:not([data-state="scanning"]):not([data-state="found"]) a-scene,
body:not([data-state="scanning"]):not([data-state="found"]) > video { visibility: hidden; }

/* One screen per state: body[data-state] shows exactly one .screen */
.screen { position: fixed; inset: 0; display: none; flex-direction: column; background: var(--surface);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
body[data-state="start"] #s-start, body[data-state="scanning"] #s-scanning, body[data-state="found"] #s-scanning,
body[data-state="blocked"] #s-blocked, body[data-state="unsupported"] #s-unsupported, body[data-state="error"] #s-error { display: flex; }

.top { height: 64px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; position: relative; z-index: 3; }
.wordmark { font: 800 20px/1 var(--font-display); letter-spacing: -.03em; color: var(--ink); text-decoration: none; }
.wordmark span { color: var(--accent); }
.help { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font: 600 14px/20px var(--font-body); color: var(--ink-muted); text-decoration: none; }
.body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; padding: 0 24px; min-height: 0; }
.center { align-items: center; text-align: center; }
.foot { padding: 16px 24px 28px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.muted { margin: 0; color: var(--ink-muted); font-size: 13px; line-height: 18px; }
.lead { margin: 0; font-size: 17px; line-height: 26px; color: var(--ink-muted); max-width: 320px; }
.body:not(.center) .lead { max-width: none; }

.cover-well { width: 100%; max-width: 360px; height: min(300px, 36vh); background: var(--surface-sunken); border-radius: var(--radius-lg); padding: 24px 40px 0; display: flex; justify-content: center; align-items: flex-end; }
.cover-well img { height: 100%; width: auto; border-radius: 4px 4px 0 0; box-shadow: var(--shadow-pop); }
.pop { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px 0 8px; border-radius: 999px; background: var(--pop); color: var(--on-pop); font: 700 13px/18px var(--font-body); }
.title { margin: 0; font: 400 40px/44px var(--cw-display); text-transform: var(--cw-display-case); }
.h { margin: 0; font: 750 30px/36px var(--font-display); letter-spacing: -.015em; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; max-width: 420px; min-height: 52px; padding: 0 24px; border: 0; border-radius: var(--radius-md);
  background: var(--accent); color: var(--on-accent); font: 700 16px/20px var(--font-body); cursor: pointer; text-decoration: none; }
.btn[disabled] { opacity: .7; cursor: progress; }
.btn-secondary { width: auto; min-height: 44px; padding: 0 16px; background: var(--surface-raised); color: var(--ink); border: 1.5px solid var(--ink-muted); font-size: 15px; }
.icon-circle { width: 64px; height: 64px; border-radius: 999px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-ink); }
.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.cards li { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; background: var(--surface-raised); border-radius: var(--radius-md); box-shadow: var(--shadow-card); }
.cards b { font-size: 15px; line-height: 20px; }
.cards span { font-size: 15px; line-height: 22px; color: var(--ink-muted); }
.linkbox { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 12px 12px 16px; background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-md); font-weight: 600; font-size: 15px; }
.linkbox span { overflow-wrap: anywhere; }

/* Scanning: the AR canvas fills the screen; this UI floats over it */
#s-scanning { z-index: 2; pointer-events: none; background: transparent; }
#s-scanning > * { pointer-events: auto; }
#s-scanning .top { background: rgba(0,0,0,.35); }
#s-scanning .wordmark { color: #fff; }
.close { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 999px; background: rgba(0,0,0,.45); color: #fff; border: 0; cursor: pointer; }
.frame-zone { flex: 1; display: flex; align-items: center; justify-content: center; pointer-events: none !important; }
.frame { position: relative; width: min(64vw, 260px); aspect-ratio: var(--cover-ratio); }
.frame span { position: absolute; width: 36px; height: 36px; border: 0 solid var(--pop); }
.frame span:nth-child(1) { top: 0; left: 0; border-top-width: 4px; border-left-width: 4px; border-top-left-radius: 14px; }
.frame span:nth-child(2) { top: 0; right: 0; border-top-width: 4px; border-right-width: 4px; border-top-right-radius: 14px; }
.frame span:nth-child(3) { bottom: 0; left: 0; border-bottom-width: 4px; border-left-width: 4px; border-bottom-left-radius: 14px; }
.frame span:nth-child(4) { bottom: 0; right: 0; border-bottom-width: 4px; border-right-width: 4px; border-bottom-right-radius: 14px; }
.sheet { margin: 0 12px 16px; background: var(--surface-raised); color: var(--ink); border-radius: var(--radius-lg); padding: 20px 20px 22px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow-pop); }
.sheet-title { display: flex; align-items: center; gap: 10px; font: 700 18px/24px var(--font-body); }
.dot { width: 10px; height: 10px; border-radius: 999px; background: var(--pop); box-shadow: 0 0 0 5px var(--accent-soft); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 9px var(--accent-soft); } }
.sheet p { margin: 0; font-size: 15px; line-height: 22px; color: var(--ink-muted); }
/* When the cover is found, hide the frame and the sheet; the top bar (with Close) stays. */
body[data-state="found"] .frame-zone, body[data-state="found"] .sheet { visibility: hidden; }
/* With a player switcher, keep the sheet clear of it (the switcher is fixed to the bottom) */
body.has-switcher #s-scanning { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 76px); }

/* ---- Extras the camera pages add on top of the design shell, all from the same tokens ---- */

body:not([data-state="scanning"]):not([data-state="found"]) #player-switcher,
body:not([data-state="scanning"]):not([data-state="found"]) #gesture-hint,
body:not([data-state="scanning"]):not([data-state="found"]) #loader-card { display: none; }

/* Player switcher: BUTTONS = pills with a visible outline; selected = filled with the accent colour.
   Sits at the bottom for thumb reach, 46px tall, scrolls sideways when the names don't fit. */
#player-switcher {
  position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); z-index: 16;
  display: flex; gap: 8px; padding: 0 12px; overflow-x: auto; scrollbar-width: none; touch-action: pan-x; -webkit-overflow-scrolling: touch;
}
#player-switcher::-webkit-scrollbar { display: none; }
#player-switcher button {
  flex: 0 0 auto; min-height: 46px; padding: 10px 20px; border-radius: 999px; cursor: pointer;
  background: var(--surface-raised); color: var(--ink); border: 1.5px solid var(--ink-muted); font: 600 15px/20px var(--font-body);
}
#player-switcher button:first-child { margin-left: auto; }   /* centred when it fits, scrollable when it doesn't */
#player-switcher button:last-child { margin-right: auto; }
#player-switcher button.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
#player-switcher button.loading { opacity: .7; }

/* INFO messages (not tappable): quiet tinted rectangle with an icon, never a pill, never outlined */
#gesture-hint {
  position: fixed; left: 12px; right: 12px; width: fit-content; margin-inline: auto; bottom: calc(env(safe-area-inset-bottom, 0px) + 28px); z-index: 15;
  background: var(--accent-soft); color: var(--ink); padding: 8px 14px 8px 12px; border-radius: 6px;
  font: 500 14px/20px var(--font-body); text-align: center; pointer-events: none;
  opacity: 0; transition: opacity .6s ease;
}
#gesture-hint::before { content: "ⓘ  "; font-weight: 700; }
#gesture-hint.show { opacity: 1; }
body.has-switcher #gesture-hint { bottom: calc(env(safe-area-inset-bottom, 0px) + 78px); }

/* Playful loader */
#loader-card {
  position: fixed; left: 50%; top: 46%; transform: translate(-50%, -50%); z-index: 17; width: min(300px, calc(100vw - 40px));
  padding: 16px 18px 18px; border-radius: var(--radius-lg); background: var(--surface-raised); color: var(--ink); text-align: center;
  box-shadow: var(--shadow-pop); pointer-events: none; opacity: 0; transition: opacity .25s ease;
}
#loader-card.show { opacity: 1; }
#loader-card .msg { min-height: 2.6em; font: 600 16px/21px var(--font-body); display: flex; align-items: center; justify-content: center; }
#loader-card.done .msg { font-size: 24px; color: var(--accent-ink); letter-spacing: .05em; animation: loader-pop .45s ease; }
#loader-card .track {
  --p: 0; position: relative; height: 40px; margin-top: 10px; border-radius: 12px; overflow: hidden; border: 2px solid #fff;
  background: repeating-linear-gradient(90deg, #2f9e4e 0 28px, #38ad58 28px 56px);
}
#loader-card .track::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,.85); }
#loader-card .ball {
  position: absolute; top: 3px; left: calc(var(--p) * (100% - 34px)); width: 34px; height: 34px; line-height: 34px; font-size: 26px;
  transform: rotate(calc(var(--p) * 1440deg)); transition: left .3s linear, transform .3s linear;
}
#loader-card .goal { position: absolute; right: 2px; top: 3px; font-size: 26px; line-height: 34px; }
#loader-card.done .goal { animation: loader-pop .45s ease; }
@keyframes loader-pop { 0% { transform: scale(.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* Developer tools (?debug=1, ?tune=1): fixed colours so they read outdoors, independent of theme */
#debug-panel {
  position: fixed; top: 0; left: 0; z-index: 50; background: #000; color: #7CFC00; font: 11px/1.5 "SF Mono", Menlo, Consolas, monospace;
  padding: 8px 10px; white-space: pre; max-width: 60vw;
}
#debug-panel button { margin-top: 6px; padding: 4px 10px; font-size: 11px; border-radius: 4px; border: 0; cursor: pointer; }
#tune-panel {
  position: fixed; right: 0; top: 0; bottom: 0; z-index: 50; width: 260px; background: rgba(10,7,18,.92); color: #f3efe8;
  font: 11px "SF Mono", Menlo, Consolas, monospace; padding: 10px; overflow-y: auto;
}
#tune-panel h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #b7add0; margin: 14px 0 6px; }
#tune-panel h2:first-child { margin-top: 0; }
#tune-panel label { display: block; margin-top: 8px; }
#tune-panel input[type="range"] { width: 100%; }
#tune-panel pre { background: #000; color: #7CFC00; padding: 6px; white-space: pre-wrap; word-break: break-all; font-size: 10px; margin-top: 6px; }

@media (prefers-reduced-motion: reduce) {
  .dot { animation: none; }
  #loader-card .ball { transition: none; }
  #loader-card.done .msg, #loader-card.done .goal { animation: none; }
  #gesture-hint { transition: none; }
}
