:root {
  --bg: rgba(24, 20, 17, 0.82);
  --bg-solid: #1e1915;
  --line: rgba(255, 255, 255, 0.12);
  --fg: #f6efe4;
  --muted: #b8ab99;
  --accent: #f2a65a;
  --accent-2: #8fd3ff;
  --good: #7bd389;
  --warn: #ff8a65;
  --radius: 14px;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: var(--fg); overflow: hidden; -webkit-tap-highlight-color: transparent; }
#app, #viewport { position: fixed; inset: 0; }
#viewport canvas { display: block; width: 100%; height: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { background: #ffffff1f; border: 1px solid #ffffff2a; border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: 0.8em; font-family: inherit; }

.panel { background: var(--bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px #0006; }
.btn { background: #ffffff14; border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; transition: background 0.15s, transform 0.1s; }
.btn:hover:not(:disabled) { background: #ffffff26; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: #2a1a0b; border-color: transparent; font-weight: 700; }
.btn.primary:hover { background: #ffb873; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn small { display: block; font-weight: 400; opacity: 0.8; font-size: 0.78em; }
.icon { background: none; border: none; padding: 2px 4px; font-size: 1.05em; border-radius: 6px; }
.icon:hover { background: #ffffff1a; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#objectives { position: absolute; top: 14px; left: 14px; padding: 12px 14px; min-width: 230px; max-width: 300px; font-size: 14px; }
#objectives h4 { margin: 0 0 8px; font-size: 14px; color: var(--accent); letter-spacing: 0.02em; }
.obj { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; transition: opacity 0.3s; }
.obj .tick { flex: 0 0 18px; height: 18px; border-radius: 50%; border: 2px solid #ffffff55; font-size: 11px; display: grid; place-items: center; margin-top: 1px; }
.obj.done { opacity: 0.6; }
.obj.done .tick { background: var(--good); border-color: var(--good); color: #10301a; font-weight: 900; }
.obj.done > span:last-child { text-decoration: line-through; text-decoration-color: #ffffff66; }
.obj.opt > span:last-child::after { content: " (bonus)"; color: var(--muted); font-size: 0.85em; }
.obj small { display: block; color: var(--muted); font-size: 0.85em; }
.obj .prog { color: var(--accent-2); font-weight: 600; }
#topbar { position: absolute; top: 14px; right: 14px; display: flex; gap: 8px; }
.pill { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; font-size: 15px; backdrop-filter: blur(10px); }
#settings { position: absolute; top: 60px; right: 14px; padding: 12px 16px; width: 270px; }
#settings h4 { margin: 0 0 8px; }
.toggle { display: flex; gap: 10px; align-items: center; padding: 5px 0; cursor: pointer; font-size: 14px; }
.toggle input { accent-color: var(--accent); width: 17px; height: 17px; }

/* world labels */
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.nametag, .hovertag { position: absolute; left: 0; top: 0; white-space: nowrap; pointer-events: auto; }
.nametag { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px 11px; font-size: 13px; cursor: pointer; text-align: center; }
.nametag b::before { content: "💬 "; }
.nametag small { display: block; color: var(--muted); font-size: 10.5px; margin-top: -2px; }
.hovertag { background: #fff; color: #2a1a0b; border-radius: 8px; padding: 2px 9px; font-weight: 700; font-size: 13px; pointer-events: none; box-shadow: 0 4px 12px #0005; }

#prompt { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 10px 20px; font-size: 15px; backdrop-filter: blur(10px); animation: pop 0.2s ease-out; }

/* dialogue */
#dialogue { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); width: min(760px, calc(100vw - 24px)); background: var(--bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid var(--line); border-radius: 18px; padding: 16px 18px 14px; box-shadow: 0 16px 40px #0008; animation: rise 0.25s ease-out; }
#dialogue .speaker { display: inline-block; background: var(--c); color: #24170c; font-weight: 800; border-radius: 999px; padding: 3px 12px; margin: -30px 0 6px; box-shadow: 0 4px 12px #0006; }
#dialogue .speaker small { font-weight: 500; margin-left: 6px; opacity: 0.75; }
#dialogue .line { display: flex; gap: 8px; align-items: flex-start; }
#dialogue .text { font-size: 21px; line-height: 1.4; margin: 2px 0 4px; flex: 1; }
#dialogue .tr { color: var(--muted); margin: 0 0 10px; font-style: italic; }
.choices { display: grid; gap: 7px; margin-top: 8px; }
.choice { display: flex; gap: 10px; align-items: center; text-align: left; background: #ffffff10; border: 1px solid var(--line); border-radius: 11px; padding: 9px 12px; font-size: 16px; transition: background 0.15s, border-color 0.15s, transform 0.1s; }
.choice:hover { background: #ffffff22; border-color: #ffffff40; }
.choice:active { transform: scale(0.99); }
.choice.matched { border-color: var(--good); background: #7bd38933; }
.choice .num { flex: 0 0 24px; height: 24px; border-radius: 7px; background: #ffffff1f; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.choice small { display: block; color: var(--muted); font-size: 13px; }
.microw { display: flex; gap: 12px; align-items: center; margin-top: 10px; }
.btn.mic.listening { background: #ff6b6b; color: #fff; animation: pulse 1s infinite; }
.heard { color: var(--muted); font-size: 14px; }

/* vocabulary words */
.vw { border-bottom: 2px dotted var(--accent); cursor: pointer; }
.vw.known { border-bottom-style: solid; border-bottom-color: var(--accent-2); }
.vw:hover { background: #ffffff1a; border-radius: 3px; }
#wordpop { position: fixed; transform: translateY(-100%); background: #fff; color: #24170c; border-radius: 12px; padding: 9px 12px; min-width: 160px; max-width: 240px; box-shadow: 0 10px 30px #0007; z-index: 20; animation: pop 0.15s ease-out; }
#wordpop .ipa { color: #7d6a55; font-size: 13px; }
#wordpop .tr1 { margin-top: 2px; }

/* inspect card */
#inspect { position: fixed; right: 16px; top: 50%; transform: translateY(-50%); width: min(340px, calc(100vw - 32px)); padding: 18px 18px 16px; animation: slidein 0.22s ease-out; }
#inspect .close, #notebook .close { position: absolute; top: 10px; right: 10px; }
#inspect h2 { margin: 2px 0 0; font-size: 30px; }
#inspect .ipa { color: var(--muted); }
#inspect .trword { font-size: 18px; color: var(--accent-2); margin: 6px 0 10px; }
#inspect .example { background: #ffffff0d; border-radius: 10px; padding: 8px 10px; }
#inspect .example p { margin: 2px 0; }
#inspect .note { font-size: 14px; color: #ffe3b5; }
#inspect .actions { display: grid; gap: 8px; margin-top: 12px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; color: var(--accent); font-weight: 700; }

/* notebook */
#notebook { position: fixed; right: 16px; top: 64px; bottom: 16px; width: min(360px, calc(100vw - 32px)); padding: 18px; overflow: auto; animation: slidein 0.22s ease-out; }
#notebook h2 { margin: 0 0 4px; }
.nb-list { display: grid; gap: 4px; margin-top: 10px; }
.nb-row { display: grid; grid-template-columns: auto auto 1fr; gap: 2px 8px; align-items: baseline; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.nb-row .ipa { color: var(--muted); font-size: 12px; }
.nb-row .nb-tr { grid-column: 2 / -1; color: var(--accent-2); font-size: 14px; }

/* toasts */
#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; z-index: 30; width: min(560px, calc(100vw - 24px)); }
.toast { background: var(--bg-solid); border: 1px solid var(--line); border-radius: 12px; padding: 9px 14px; font-size: 15px; opacity: 0; transform: translateY(-8px); transition: opacity 0.3s, transform 0.3s; box-shadow: 0 8px 24px #0007; text-align: center; }
.toast.in { opacity: 1; transform: none; }
.toast small { display: block; color: var(--muted); font-size: 13px; }
.toast.goal { border-color: #7bd38988; }
.toast.word { border-color: #8fd3ff88; }
.toast.warn { border-color: #ff8a65aa; background: #3a1f17; }
.toast.tip { border-color: #f2a65a99; background: #33261a; }

/* overlays */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, #0007, #000c); z-index: 40; padding: 16px; overflow: auto; }
.intro-card { background: var(--bg-solid); border: 1px solid var(--line); border-radius: 20px; padding: 26px 28px; width: min(600px, 100%); box-shadow: 0 24px 60px #000a; animation: rise 0.35s ease-out; }
.intro-card h1 { margin: 6px 0 0; font-size: 34px; }
.intro-card .sub { margin: 0 0 12px; color: var(--accent-2); font-style: italic; }
.intro-card h3 { margin: 16px 0 6px; font-size: 15px; color: var(--accent); }
.goal-list { margin: 0; padding-left: 20px; line-height: 1.6; }
.controls { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 16px 0; font-size: 13px; color: var(--muted); }
.intro-card .start { font-size: 18px; padding: 12px 26px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 14px 0; }
.stats div { background: #ffffff0d; border-radius: 12px; padding: 10px; text-align: center; }
.stats b { display: block; font-size: 24px; color: var(--accent); }
.stats span { font-size: 12px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #ffffff12; border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.chip i { color: var(--muted); font-style: normal; }
.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

@keyframes rise { from { opacity: 0; transform: translate(-50%, 14px); } }
.intro-card { animation-name: fadeup; }
@keyframes fadeup { from { opacity: 0; transform: translateY(14px); } }
@keyframes slidein { from { opacity: 0; transform: translate(14px, -50%); } }
#notebook { animation-name: slidein2; }
@keyframes slidein2 { from { opacity: 0; transform: translateX(14px); } }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) scale(0.95); } }
#wordpop { animation-name: none; }
@keyframes pulse { 50% { opacity: 0.7; } }

@media (max-width: 640px) {
  #objectives { font-size: 12.5px; min-width: 0; max-width: 58vw; padding: 9px 10px; }
  #objectives .obj small { display: none; }
  #dialogue .text { font-size: 18px; }
  .choice { font-size: 15px; padding: 8px 10px; }
  #inspect { top: auto; bottom: 12px; right: 12px; left: 12px; width: auto; transform: none; animation-name: fadeup; }
}

/* ---------------- audio-only mode ---------------- */
#audio-app { position: fixed; inset: 0; overflow: auto; background: radial-gradient(ellipse at 50% 30%, #3a2a1f 0%, #15110e 70%); display: flex; flex-direction: column; align-items: center; padding: 18px 16px 30px; }
#audio-app header { width: min(760px, 100%); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
#audio-app header h1 { margin: 2px 0 0; font-size: 24px; }
#audio-app .hdr-right { display: flex; gap: 8px; }
#audio-app #objectives { position: static; width: min(760px, 100%); max-width: none; display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 9px 14px; margin-top: 12px; font-size: 13px; }
.aobj { color: var(--fg); white-space: nowrap; }
.aobj.done { color: var(--good); }
.aobj.opt { color: var(--muted); }
.aobj.opt.done { color: var(--good); }
#audio-app main { width: min(760px, 100%); display: flex; flex-direction: column; align-items: center; }
.stage { display: flex; flex-direction: column; align-items: center; margin: 26px 0 12px; min-height: 250px; }
.orb { --c: #8a7f73; width: 170px; height: 170px; border-radius: 50%; display: grid; place-items: center; font-size: 60px;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--c) 70%, white), var(--c) 60%, color-mix(in srgb, var(--c) 50%, black));
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 60%, transparent), 0 20px 50px #0008; transition: background 0.3s, transform 0.3s; }
.orb.npc, .orb.narrator, .orb.player { animation: talk 0.9s ease-in-out infinite; }
.orb.listening, #audio-app.awaiting .orb:not(.npc):not(.narrator):not(.player) { --c: #e05a5a; }
.orb.listening { animation: ring 1.2s ease-out infinite; }
@keyframes talk { 50% { transform: scale(1.06); box-shadow: 0 0 0 18px color-mix(in srgb, var(--c) 18%, transparent), 0 20px 50px #0008; } }
@keyframes ring { 0% { box-shadow: 0 0 0 0 #e05a5a88, 0 20px 50px #0008; } 100% { box-shadow: 0 0 0 34px #e05a5a00, 0 20px 50px #0008; } }
.who { margin-top: 18px; font-size: 22px; font-weight: 700; min-height: 30px; text-align: center; }
.who small { font-weight: 400; color: var(--muted); font-size: 15px; }
.status { color: var(--muted); min-height: 22px; margin-top: 4px; text-align: center; }
.abtns { display: flex; gap: 12px; }
.btn.big { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 28px; padding: 12px 20px; min-width: 104px; border-radius: 16px; }
.btn.big span { font-size: 13px; font-weight: 600; }
#options { display: grid; gap: 7px; width: 100%; margin-top: 16px; }
#typebox { display: flex; gap: 8px; width: min(520px, 100%); margin-top: 16px; }
#typebox input { flex: 1; background: #ffffff10; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; color: var(--fg); font: inherit; font-size: 16px; }
#typebox input:disabled { opacity: 0.5; }
.toggles { display: flex; flex-wrap: wrap; gap: 4px 18px; justify-content: center; margin-top: 14px; }
#transcript { width: 100%; margin-top: 14px; padding: 10px 14px; max-height: 36vh; overflow: auto; display: grid; gap: 8px; }
#audio-app.no-transcript #transcript { display: none; }
#audio-app.no-tr .ttr { display: none; }
.tline { display: grid; gap: 1px; padding: 6px 10px; border-radius: 10px; background: #ffffff08; max-width: 88%; }
.tline b { font-size: 12px; }
.tline.me { justify-self: end; background: #8fd3ff1a; }
.tline.narr { font-style: italic; background: transparent; max-width: 100%; }
.tline.miss { background: #ff8a6522; }
.tline small { color: var(--muted); font-size: 13px; }
.tline .match { color: var(--good); }
.tline.miss .match { color: var(--warn); }
.note { color: #ffe3b5; }

/* ---------------- character creator ---------------- */
.start-row { justify-content: space-between; flex-wrap: wrap; }
#creator { z-index: 50; }
.creator { display: grid; grid-template-columns: 260px 1fr; gap: 22px; background: var(--bg-solid); border: 1px solid var(--line); border-radius: 20px; padding: 20px; width: min(820px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 24px 60px #000a; }
.creator h2 { margin: 0 0 6px; }
.creator .preview { display: flex; flex-direction: column; align-items: center; gap: 10px; background: radial-gradient(ellipse at 50% 40%, #4a3628, #1e1915 70%); border-radius: 16px; padding: 10px; align-self: start; position: sticky; top: 0; }
.creator canvas { width: 260px; height: 360px; max-width: 100%; }
.creator label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 10px 0 5px; }
.creator label.toggle { text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--fg); }
.creator input[type=range] { width: 160px; vertical-align: middle; accent-color: var(--accent); margin-left: 8px; }
.seg { display: flex; flex-wrap: wrap; gap: 5px; }
.pick { background: #ffffff10; border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: 13px; }
.pick.on { background: var(--accent); color: #2a1a0b; border-color: transparent; font-weight: 700; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0; }
.sw { width: 28px; height: 28px; border-radius: 50%; background: var(--sw); border: 2px solid #ffffff30; padding: 0; }
.sw.on { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (max-width: 640px) { .creator { grid-template-columns: 1fr; } .creator .preview { position: static; } .creator canvas { height: 280px; } }
#audio-app .voice-pick { display: flex; gap: 8px; align-items: center; margin: 8px 0; }

/* ---------------- stats overlay (?stats) ---------------- */
#statspanel { position: fixed; left: 14px; bottom: 14px; z-index: 45; background: #000000c0; color: #d8f5d0; font: 11.5px/1.45 ui-monospace, Menlo, monospace; padding: 8px 10px; border-radius: 10px; min-width: 230px; pointer-events: none; }
#statspanel b { display: block; color: #fff; margin-bottom: 3px; }
#statspanel div { display: flex; justify-content: space-between; gap: 14px; white-space: pre; }

/* homework box on the intro screen */
.hw-box { background: #ffffff0d; border: 1px dashed #f2a65a88; border-radius: 12px; padding: 10px 14px; margin: 12px 0; }
.hw-box p { margin: 6px 0; }
.hw-box label { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.hw-box input { flex: 1; background: #ffffff14; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--fg); font: inherit; }
.hw-box input.need { border-color: var(--warn); box-shadow: 0 0 0 3px #ff8a6544; }
