/* ═══════════════════════════════════════════════════════════════
   AGATE CORE VALUE QUEST — base styles
   Tokens follow the Agate 2023 Visual Brand Guideline:
   • Primary: Darkest Blue #050a1a · Dark Blue #0b173b · Strong Blue #132967 · Navy #22304f
   • Secondary: Classic Cyan #207fad · Classic Violet #3d346f · #b5ade0
   • Accents: #d84767 #f2793c #26a668 #5a4da2 #f7c827
   • Type: Odudo Soft (headlines) → fallback Nunito · Mulish (body)
   • Graphic elements: floating windows, crossline borders, diamond-pixel
     pattern, 5–15° slant cuts
════════════════════════════════════════════════════════════════ */

/* Odudo Soft — drop licensed files into assets/fonts/ (see data/assets.js) */
@font-face { font-family: 'Odudo Soft'; src: url('../assets/fonts/OdudoSoft-SemiBold.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Odudo Soft'; src: url('../assets/fonts/OdudoSoft-Light.woff2') format('woff2'); font-weight: 300; font-display: swap; }

:root {
  --navy-950: #050a1a; --navy-900: #0b173b; --navy-800: #132967; --navy-700: #22304f; --navy-600: #27385c; --navy-500: #324875; --navy-400: #435f9c; --navy-300: #7684a2;
  --cyan-600: #207fad; --cyan-500: #2287ba; --cyan-300: #5fa3c6;
  --violet-900: #211c3c; --violet-800: #221d3d; --violet-700: #3d346f; --violet-600: #453b7d; --violet-400: #767193; --violet-200: #b5ade0;
  --red: #d84767; --orange: #f2793c; --green: #26a668; --purple: #5a4da2; --yellow: #f7c827;

  --bg: var(--navy-950);
  --fg: #ffffff;
  --fg-dim: rgba(255,255,255,.72);
  --fg-faint: rgba(255,255,255,.48);
  --line: rgba(181,173,224,.22);
  --line-strong: rgba(181,173,224,.45);
  --win-bg: rgba(11,23,59,.72);
  --win-bg-solid: #0f1f4d;
  --accent: var(--cyan-300);
  --class: var(--cyan-300);

  --font-head: 'Odudo Soft', 'Nunito', 'Mulish', system-ui, sans-serif;
  --font-body: 'Mulish', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --radius: 14px; --radius-sm: 10px;
  --slant: 8deg;
  --col-max: 560px;
  --topbar-h: clamp(52px, 12cqw, 64px);
  --shadow: 0 10px 40px rgba(0,0,0,.45), 0 1px 0 rgba(255,255,255,.06) inset;
  --ease: cubic-bezier(.2,.8,.2,1);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body); color: var(--fg); background: var(--bg);
  overflow: hidden; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
  font-size: 16px; line-height: 1.5;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; }
img { display: block; max-width: 100%; user-select: none; -webkit-user-drag: none; }
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; margin: 0; line-height: 1.15; letter-spacing: .01em; }
p { margin: 0; }
::selection { background: rgba(32,127,173,.6); }

.is-hidden { display: none !important; }

/* ── Stage & app column ─────────────────────────────────────── */
#stage {
  position: fixed; inset: 0; overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(32,127,173,.35), transparent 60%),
    radial-gradient(80% 60% at 100% 100%, rgba(61,52,111,.55), transparent 60%),
    linear-gradient(180deg, var(--navy-950) 0%, var(--navy-900) 55%, var(--navy-800) 100%);
}
#stage::before { /* diamond pixel pattern */
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .55;
  background-image:
    radial-gradient(rgba(95,163,198,.55) 1.1px, transparent 1.6px),
    radial-gradient(rgba(181,173,224,.35) 1px, transparent 1.5px);
  background-size: 34px 34px, 58px 58px; background-position: 0 0, 17px 21px;
  -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,.9), rgba(0,0,0,.25) 45%, rgba(0,0,0,.7));
          mask-image: linear-gradient(180deg, rgba(0,0,0,.9), rgba(0,0,0,.25) 45%, rgba(0,0,0,.7));
}
#stage.stage--img::after {
  content: ''; position: absolute; inset: 0; background: var(--bg-img) center / cover no-repeat; opacity: .85; pointer-events: none;
  -webkit-mask-image: linear-gradient(180deg, #000 55%, rgba(0,0,0,.55)); mask-image: linear-gradient(180deg, #000 55%, rgba(0,0,0,.55));
}
#stage.stage--img::before { opacity: .25; }
/* crossline decoration on wide screens */
#stage .crosslines { position: absolute; inset: 0; pointer-events: none; opacity: .5; }
#stage .crosslines::before, #stage .crosslines::after { content: ''; position: absolute; background: var(--line); }
#stage .crosslines::before { left: max(24px, calc(50% - var(--col-max) / 2 - 40px)); top: 0; bottom: 0; width: 1px; }
#stage .crosslines::after  { right: max(24px, calc(50% - var(--col-max) / 2 - 40px)); top: 0; bottom: 0; width: 1px; }

#app {
  position: relative; z-index: 1; margin: 0 auto; height: 100dvh; width: 100%; max-width: var(--col-max);
  container-type: inline-size; container-name: app; display: flex; flex-direction: column;
}
@media (min-width: 640px) {
  #app { box-shadow: 0 0 0 1px var(--line), 0 30px 80px rgba(0,0,0,.6); background: rgba(5,10,26,.35); backdrop-filter: blur(6px); }
}
#pages { position: relative; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--navy-400) transparent; }
.page { position: relative; min-height: 100%; display: flex; flex-direction: column; padding: 12px 14px calc(16px + env(safe-area-inset-bottom)); gap: 12px; }
.page-enter { animation: pageIn .55s var(--ease) both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ── Topbar ─────────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-h); display: grid; grid-template-columns: 40px 1fr auto 40px; align-items: center; gap: 8px; padding: 0 10px;
  border-bottom: 1px solid var(--line); background: rgba(5,10,26,.55); backdrop-filter: blur(8px); position: relative; z-index: 5;
  transition: opacity .3s, transform .3s;
}
#topbar.tb--hidden { opacity: 0; pointer-events: none; transform: translateY(-100%); position: absolute; width: 100%; }
.tb-logo { height: 22px; width: auto; justify-self: start; }
.tb-logo img { height: 22px; width: auto; }
.tb-logo .ph { height: 22px; min-height: 0; padding: 0 6px; font-family: var(--font-head); font-size: 15px; letter-spacing: .02em; border-style: solid; background: none; }
.tb-logo .ph .ph-dots, .tb-logo .ph .ph-size, .tb-logo .ph .ph-key { display: none; }
.wordmark { display: inline-block; font-family: var(--font-head); font-size: 17px; letter-spacing: .02em; padding: 1px 8px; border: 1px solid var(--line-strong); border-radius: 6px; line-height: 1.2; white-space: nowrap; }
.wordmark--lg { font-size: 22px; padding: 3px 12px; }
.tb-logo { min-width: 60px; }
.tb-mid { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; grid-column: 3; }
.tb-chapter { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-faint); font-weight: 700; }
.tb-progress { display: flex; gap: 8px; }
.tb-diamond { width: 9px; height: 9px; transform: rotate(45deg); background: rgba(255,255,255,.12); border: 1px solid var(--line-strong); transition: all .4s var(--ease); }
.tb-diamond.is-done { background: var(--cyan-300); border-color: var(--cyan-300); }
.tb-diamond.is-current { background: var(--yellow); border-color: var(--yellow); box-shadow: 0 0 10px var(--yellow); transform: rotate(45deg) scale(1.25); }
.tb-mute, .tb-back { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; color: var(--fg-dim); }
.tb-mute:active, .tb-back:active { background: rgba(255,255,255,.08); }
.tb-back { grid-column: 1; }
.tb-back-arrow { width: 10px; height: 10px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin-left: 4px; }
.tb-mute { grid-column: 4; }
.tb-mute-icon { width: 14px; height: 14px; position: relative; }
.tb-mute-icon::before { content: ''; position: absolute; left: 0; top: 3px; width: 5px; height: 8px; background: currentColor; }
.tb-mute-icon::after { content: ''; position: absolute; left: 4px; top: 0; border: 7px solid transparent; border-right: 6px solid currentColor; border-left: 0; }
.tb-mute.is-muted { color: var(--red); }
.tb-mute.is-muted::after { content: ''; position: absolute; width: 22px; height: 2px; background: var(--red); transform: rotate(-45deg); }

/* ── Floating window (brand element) ───────────────────────── */
.fwin {
  position: relative; border-radius: var(--radius); background: var(--win-bg); backdrop-filter: blur(10px);
  border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; --accent: var(--cyan-300);
}
.fwin::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: linear-gradient(180deg, var(--accent), transparent 90%); opacity: .9; }
.fwin-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px 6px 14px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.03); }
.fwin-dots { display: inline-flex; gap: 5px; }
.fwin-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--violet-200); opacity: .35; }
.fwin-dots i:first-child { background: var(--accent); opacity: .9; }
.fwin-title { font-family: var(--font-head); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-dim); font-weight: 600; }
.fwin-right { margin-left: auto; font-size: 11px; letter-spacing: .1em; color: var(--fg-faint); font-weight: 700; }
.fwin-body { padding: 12px 14px 14px; }
.fwin--solid { background: var(--win-bg-solid); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 22px;
  font-family: var(--font-head); font-weight: 600; font-size: 16px; letter-spacing: .02em; color: #fff; border-radius: 12px;
  background: linear-gradient(135deg, var(--navy-500), var(--navy-700)); border: 1px solid var(--line-strong);
  transition: transform .15s var(--ease), box-shadow .2s, opacity .2s, filter .2s; user-select: none; touch-action: manipulation;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%); /* slant cut corner */
}
.btn:active { transform: translateY(1px) scale(.985); }
.btn:disabled { opacity: .38; filter: saturate(.4); }
.btn--primary { background: linear-gradient(135deg, var(--cyan-500), var(--cyan-600) 60%, #1a6a94); border-color: rgba(95,163,198,.7); box-shadow: 0 8px 24px rgba(32,127,173,.35); }
.btn--primary:not(:disabled):hover { filter: brightness(1.08); }
.btn--secondary { background: linear-gradient(135deg, var(--violet-600), var(--violet-700)); border-color: rgba(181,173,224,.5); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--fg-dim); box-shadow: none; }
.btn--xl { min-height: 58px; padding: 0 34px; font-size: 19px; }
.btn--sm { min-height: 38px; padding: 0 14px; font-size: 14px; }
.btn-label { position: relative; z-index: 1; }
.cta-bar { display: flex; justify-content: center; gap: 10px; padding: 6px 0 2px; margin-top: auto; }
.row-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.row-actions .btn { flex: 1 1 auto; }

/* ── Asset placeholder ──────────────────────────────────────── */
.asset { position: relative; display: block; overflow: hidden; container-type: inline-size; }
.asset--auto { container-type: normal; overflow: visible; }
/* tiny placeholders: label only */
@container (max-width: 120px) { .ph .ph-key, .ph .ph-size, .ph .ph-dots { display: none; } .ph { font-size: 9px; } }
@container (max-width: 64px) { .ph .ph-label { font-size: 9px; } }
.asset img { width: 100%; height: 100%; object-fit: contain; }
.asset.asset--missing { }
.ph {
  --ph-tint: var(--cyan-300);
  position: absolute; inset: 0; min-height: 40px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px;
  border: 1.5px dashed color-mix(in srgb, var(--ph-tint) 65%, transparent); border-radius: 10px; color: var(--fg-dim); text-align: center;
  background: repeating-linear-gradient(-55deg, transparent 0 8px, color-mix(in srgb, var(--ph-tint) 7%, transparent) 8px 9px), rgba(255,255,255,.03);
  font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; font-size: 10px; line-height: 1.25; letter-spacing: 0;
}
.ph-dots { position: absolute; top: 5px; left: 7px; display: flex; gap: 3px; }
.ph-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--ph-tint); opacity: .6; }
.ph-key { font-weight: 700; color: color-mix(in srgb, var(--ph-tint) 85%, #fff); word-break: break-all; }
.ph-size { opacity: .55; }
.ph-label { font-family: var(--font-head); font-size: 12px; color: #fff; opacity: .9; margin-top: 2px; }
.asset:not([style*="aspect-ratio"]) .ph { position: relative; }

/* ── Typing / prompt ────────────────────────────────────────── */
.prompt-win .fwin-body { padding: 12px 14px; }
.prompt-text { font-size: clamp(15px, 4cqw, 18px); line-height: 1.45; min-height: 2.9em; color: #fff; font-weight: 500; }
.typing::after { content: '▍'; color: var(--cyan-300); animation: blink 1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }
.tap-hint { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-faint); text-align: center; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.eyebrow { font-family: var(--font-head); font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--cyan-300); font-weight: 600; }
.h2 { font-size: clamp(20px, 5.5cqw, 26px); margin-bottom: 10px; }
.center-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 10px 0; }

/* ── Chapter intro overlay ──────────────────────────────────── */
.intro { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 18px; background: rgba(5,10,26,.78); backdrop-filter: blur(6px); animation: fadeIn .4s var(--ease) both; }
.intro--out { animation: fadeOut .38s var(--ease) both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; } }
.intro-win { width: 100%; max-width: 440px; animation: pageIn .5s var(--ease) both; }
.intro-text { font-size: clamp(16px, 4.4cqw, 19px); line-height: 1.5; min-height: 4.5em; }
.intro-actions { display: flex; justify-content: flex-end; margin-top: 14px; }

/* ── Flash / toast / particles ──────────────────────────────── */
#flash { position: absolute; inset: 0; z-index: 50; pointer-events: none; opacity: 0; transition: opacity .35s ease; }
#flash.flash--on { opacity: 1; }
.toast { position: absolute; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 60; background: var(--win-bg-solid); border: 1px solid var(--line-strong); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: all .3s var(--ease); pointer-events: none; }
.toast--in { opacity: 1; transform: translate(-50%, 0); }
.particle { position: absolute; width: 8px; height: 8px; transform: translate(-50%,-50%) rotate(45deg); pointer-events: none; z-index: 30; animation: burst var(--d, .8s) var(--ease) forwards; box-shadow: 0 0 8px currentColor; }
@keyframes burst { to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--r)) scale(.2); opacity: 0; } }
.float-text { position: absolute; transform: translate(-50%,-50%); font-family: var(--font-head); font-weight: 600; font-size: 34px; text-shadow: 0 2px 12px rgba(0,0,0,.6); pointer-events: none; z-index: 30; animation: floatUp 1.3s var(--ease) forwards; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%,-30%) scale(.7); } 20% { opacity: 1; transform: translate(-50%,-50%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%,-160%) scale(1); } }
.shake { animation: shake .45s ease; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }

/* ── Debug HUD ── */
#debug-hud { position: absolute; left: 8px; bottom: 8px; z-index: 70; font: 11px/1.4 ui-monospace, monospace; background: rgba(0,0,0,.7); border: 1px solid var(--line); padding: 6px 8px; border-radius: 6px; color: #9fd; pointer-events: none; }
#debug-hud i { color: var(--yellow); font-style: normal; }
.version { position: absolute; left: 12px; bottom: 8px; font-size: 10px; color: var(--fg-faint); letter-spacing: .08em; }
