:root {
  --ground: #10160f; --panel: #1b231a; --panel-raised: #243022;
  --ink: #efe6cf; --ink-dim: #b3ab95; --line: #3a4a38;
  --gold: #f2b632; --hp: #e2493f; --xp: #5cc8ff;
  --speed: #8be36b; --aoe: #ff6e42; --util: #f2b632;
  --lightning: #5fb0ff; --impact: #e0a860; --tide: #7fe0ff; --fire: #ff7a3c; --gravity: #b48cff; --radiance: #ffe27a; --circuit: #7dffb0;   /* the elements (config ELEMENTS) */
  --on: var(--lightning);   /* the R button's lit colour: set per element by ui.js */
  --boon: #c98bff;          /* boss loot (boons.js) */
  color-scheme: dark;
}
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--ground); color: var(--ink);
  font: 15px/1.4 Nunito, system-ui, sans-serif;
  overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: none; -webkit-tap-highlight-color: transparent;
}
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.disp { font-family: 'Lilita One', Impact, 'Arial Black', sans-serif; letter-spacing: .02em; font-weight: 400; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, .card:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; padding: calc(10px + env(safe-area-inset-top, 0px)) 16px calc(10px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; justify-content: space-between; }
.row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.stats { display: flex; flex-direction: column; gap: 6px; min-width: 190px; max-width: 260px; }
.gold { font-size: 30px; line-height: 1; color: var(--gold); text-shadow: 0 2px 0 #0008; font-variant-numeric: tabular-nums; }
.gold small { font-size: 14px; color: var(--ink-dim); font-family: Nunito, system-ui, sans-serif; margin-left: 4px; }
.bar { position: relative; height: 14px; background: #0009; border-radius: 7px; overflow: hidden; box-shadow: inset 0 0 0 1px #0006; }
.bar i { position: absolute; inset: 0; width: 0; border-radius: 7px; transition: width .12s; }
.bar.hp i { background: linear-gradient(#f06a5a, var(--hp)); }
.bar.xp i { background: linear-gradient(#8fdcff, var(--xp)); }
.bar b { position: absolute; inset: 0; font: 800 10px/14px Nunito, system-ui, sans-serif; text-align: center; color: #fff; text-shadow: 0 1px 0 #000a; letter-spacing: .04em; }
.lvl { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-dim); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.lvl span { color: var(--ink); }
.right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.chip { background: #0009; border: 1px solid #fff2; border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 700; white-space: nowrap; backdrop-filter: blur(4px); }
.chip.combat { border-color: var(--aoe); color: #ffd2c2; }
.chip.emblem { border-color: var(--gold); color: var(--gold); }
/* A boss banner pinned near the top-centre, out of the HUD's space-between flow
   (which otherwise floats it into the middle of the play area). Only shown while a boss is alive. */
#bossBar { position: absolute; top: calc(102px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%);
  width: min(520px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 4px; align-items: center; }
#bossBar span { font-size: 22px; color: #ffb59a; text-shadow: 0 2px 0 #000a; }
.bar.boss { width: 100%; height: 18px; }
/* The death beat (beat.js): the fill drains over most of a second, then the banner folds shut. */
#bossBar { transition: transform .35s ease-in, opacity .35s ease-in; transform-origin: 50% 0; }
#bossBar.drain .bar.boss i { transition: width .8s ease-out; }
#bossBar.fold { transform: translateX(-50%) scaleY(0); opacity: 0; }
.bar.boss i { background: linear-gradient(#ff8a5c, #c8361c); }
.bar.boss b { line-height: 18px; font-size: 11px; }
.chip.token { border-color: #6bd0a8; color: #6bd0a8; }
.bar.quest { height: 16px; margin-top: 2px; }
.bar.quest i { background: linear-gradient(#7fe0bd, #3fa886); }
.bar.quest b { line-height: 16px; font-size: 10px; }
.item.quest { grid-template-columns: 1fr auto; }
.item.quest.ready { border-color: #6bd0a8aa; }
.item.quest.ready h3 em { color: #6bd0a8; }
.item.quest.active { border-color: #f2b63288; }
.item.quest.active h3 em { color: #f2b632; }
.item.quest.locked { opacity: .72; }
.btns { display: flex; gap: 8px; }
.btn { pointer-events: auto; background: var(--panel-raised); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; font-weight: 800; box-shadow: 0 2px 0 #0007; }
.btn:hover { background: #2e3d2b; }
.btn:disabled { opacity: .5; cursor: default; box-shadow: none; }
.btn.on { opacity: 1; color: var(--on); border-color: var(--on); box-shadow: 0 0 0 1px var(--on), 0 2px 0 #0007; }
.btn.gold { background: var(--gold); color: #241a05; border-color: #b9861f; }
.btn.gold:hover { background: #ffc94a; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.abil { display: flex; gap: 6px; flex-wrap: wrap; max-width: 60%; }
.ab { display: flex; align-items: center; gap: 6px; background: #000a; border-radius: 8px; padding: 4px 8px; font-size: 12px; font-weight: 800; border-left: 4px solid var(--util); }
.ab.speed { border-color: var(--speed); } .ab.aoe { border-color: var(--aoe); }
.ab.lightning { border-color: var(--lightning); } .ab.impact { border-color: var(--impact); } .ab.tide { border-color: var(--tide); } .ab.fire { border-color: var(--fire); }
.ab.gravity { border-color: var(--gravity); } .ab.radiance { border-color: var(--radiance); } .ab.circuit { border-color: var(--circuit); }
.ab em { font-style: normal; color: var(--ink-dim); }
#prompt { pointer-events: auto; align-self: center; margin-bottom: 8px; background: #1b231aee; border: 2px solid var(--gold); border-radius: 12px; padding: 10px 18px; font-weight: 800; font-size: 15px; box-shadow: 0 6px 20px #000a; display: flex; gap: 10px; align-items: center; }
#prompt kbd { background: var(--gold); color: #241a05; border-radius: 6px; padding: 1px 7px; font: 800 12px Nunito, system-ui, sans-serif; }
#prompt.poor { border-color: var(--hp); }
#prompt.poor kbd { background: var(--hp); color: #fff; }
/* Guided start (guide.js): one line under the E-prompt, and a pulse on the control it points at. */
#guide { position: absolute; left: 50%; bottom: calc(64px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); max-width: calc(100% - 32px); text-align: center; background: #0009; border-radius: 10px; padding: 6px 14px; font-weight: 700; font-size: 14px; color: var(--gold); text-shadow: 0 1px 0 #000a; animation: guide-in .3s ease-out; }
#guide b { color: var(--ink); }
#guide .qp { margin-left: 10px; color: var(--ink); font-variant-numeric: tabular-nums; }
#guide .qbar { display: block; height: 4px; margin-top: 5px; background: #fff2; border-radius: 2px; overflow: hidden; }
#guide .qbar b { display: block; height: 100%; background: var(--gold); border-radius: 2px; transition: width .2s; }
.btn.guide { animation: guide-pulse 1.4s ease-in-out infinite; }
#luSub.guide { color: var(--gold); }
@keyframes guide-in { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes guide-pulse { 0%, 100% { box-shadow: 0 0 0 0 var(--gold), 0 2px 0 #0007; } 50% { box-shadow: 0 0 0 5px #f2b63200, 0 2px 0 #0007; } }
#toasts { position: absolute; left: 0; right: 0; top: 32%; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: #000b; border-radius: 8px; padding: 6px 14px; font-weight: 800; animation: toast 2.2s forwards; }
.toast.bad { color: #ffb3ab; }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 12% { opacity: 1; transform: none; } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }

/* Drawer and modals */
.overlay { position: absolute; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(3px); }
#shop { position: absolute; top: 0; right: 0; bottom: 0; width: min(400px, 100%); background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: -10px 0 40px #000a; padding-top: env(safe-area-inset-top, 0px); }
.shead { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.shead h2 { margin: 0; font-size: 26px; }
.tabs { display: flex; gap: 4px; padding: 10px 16px 0; }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; padding: 6px 10px; font-weight: 800; color: var(--ink-dim); }
.tab.on { color: var(--ink); border-color: var(--gold); }
.list { overflow: auto; padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; flex: 1; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; background: var(--panel-raised); border-radius: 10px; padding: 10px 12px; border: 1px solid transparent; }
.item.locked { opacity: .85; }
.item.plain { grid-template-columns: 1fr; }
.item h3 { margin: 0; font-size: 15px; display: flex; gap: 8px; align-items: baseline; }
.item h3 em { font-style: normal; font-size: 11px; color: var(--ink-dim); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.item p { margin: 0; font-size: 13px; color: var(--ink-dim); }
.item .buy { grid-column: 2; grid-row: 1 / 3; min-width: 88px; text-align: center; font-variant-numeric: tabular-nums; }
.item.kind-combat { border-color: #ff6e4233; } .item.kind-farm { border-color: #8be36b22; }

#levelup .box, #levelcomplete .box, #boon .box { max-width: 860px; width: 100%; text-align: center; }
#levelup h2, #levelcomplete h2, #boon h2 { margin: 0 0 4px; font-size: 40px; color: var(--gold); text-shadow: 0 3px 0 #0009; }
#levelup p, #levelcomplete p, #boon p { margin: 0 0 18px; color: var(--ink-dim); font-weight: 700; }
/* Boss loot (boons.js): its own colour and frame, so the screen reads "loot", not "level up". */
#boon { background: #14081ecc; }
#boon .eyebrow { display: inline-block; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .18em; color: var(--boon); border: 1px solid var(--boon); border-radius: 999px; padding: 3px 12px; margin-bottom: 10px; }
#boon h2 { color: var(--boon); }
.card.boon { border-top-color: var(--boon); border-color: #6a3f8a; background: linear-gradient(#2a1a38, var(--panel)); box-shadow: 0 8px 24px #000a, 0 0 0 1px #c98bff22, 0 0 28px #c98bff22; }
.card.boon:hover { box-shadow: 0 14px 30px #000a, 0 0 0 1px #c98bff55, 0 0 36px #c98bff44; }
.card.boon .br { color: var(--boon); }
.lcstats { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 6px 0 18px; }
.lcstats div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; min-width: 96px; display: flex; flex-direction: column; }
.lcstats b { font-size: 24px; color: var(--ink); font-variant-numeric: tabular-nums; }
/* Where the run's time went, zone by zone (ui.js showLevelComplete). */
.lczones { display: grid; grid-template-columns: minmax(90px, 1.3fr) 3fr auto auto; gap: 4px 10px; align-items: center; max-width: 620px; margin: 0 auto 18px; text-align: left; font-size: 13px; font-variant-numeric: tabular-nums; }
.lczones .zh { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.lczones .zn { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lczones .zn.combat { color: #ffd2c2; }
.lczones .zb { height: 10px; background: #0006; border-radius: 5px; overflow: hidden; }
.lczones .zb i { display: block; height: 100%; background: var(--util); border-radius: 5px; }
.lczones .zb i.combat { background: var(--aoe); }
.lczones .zt { color: var(--ink); font-weight: 800; }
.lczones .za { color: var(--muted); }
@media (max-width: 560px) { .lczones { grid-template-columns: minmax(80px, 1.2fr) 2fr auto; } .lczones .za, .lczones .zh.za { display: none; } }
.lcstats span { font-size: 11px; color: var(--ink-dim); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.lcstats .best { flex-basis: 100%; text-align: left; background: none; border: 0; padding: 4px 0 0; }
.lcstats .best p { margin: 2px 0; font-size: 13px; color: var(--ink); font-weight: 600; }

/* The conversation window. Portrait beside the text, choices under it — the panel it leads to
   opens on top of this one, so the two never have to agree about layout. */
.talkbox {
  max-width: 560px; width: 100%; display: flex; gap: 14px; align-items: stretch; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px;
  box-shadow: 0 14px 40px #000a;
}
/* Square and centred. The crop anchors the head at a fraction of the frame's HEIGHT, so the
   figure fills a square and floats in anything taller — stretching this to the box's height
   left the townsperson adrift with a third of the frame empty under their boots. Centred, the
   panel either side reads as margin rather than as a portrait that failed to load. */
#talkPortrait { width: 136px; height: 136px; flex: none; align-self: center; border-radius: 12px; border: 1px solid var(--line); display: block; }
.tbody { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.thead { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.thead h2 { margin: 0; font-size: 26px; line-height: 1.05; }
.trole { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-dim); }
/* min-height holds two lines, so the box does not jump as the text reveals or a line changes. */
.tline { margin: 0; min-height: 2.8em; font-size: 15px; line-height: 1.4; cursor: pointer; }
.tchoices { display: flex; flex-direction: column; gap: 6px; }
.tchoice {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  background: var(--panel-raised); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 11px; font-weight: 700;
}
.tchoice:hover { background: #2e3d2b; border-color: var(--gold); }
.tchoice .k { flex: none; }
@media (max-width: 460px) {
  .talkbox { flex-direction: column; }
  #talkPortrait { width: 96px; height: 96px; align-self: flex-start; }
}

/* Home base overlays reuse the shop drawer styling inside a centered box */
.panelbox { max-width: 520px; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; text-align: left; }
.panelbox .list h4, .list .sect { margin: 10px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-dim); }
.panelbox .list h4:first-child { margin-top: 0; }
#boardUp { display: flex; flex-direction: column; gap: 8px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid #0006; vertical-align: -2px; margin-right: 6px; }
.cards { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.card { flex: 1 1 200px; max-width: 260px; min-height: 150px; background: var(--panel); border: 1px solid var(--line); border-top: 6px solid var(--util); border-radius: 14px; padding: 14px 14px 16px; text-align: left; display: flex; flex-direction: column; gap: 6px; transition: transform .1s, box-shadow .1s; box-shadow: 0 8px 24px #0008; }
.card:hover { transform: translateY(-4px); box-shadow: 0 14px 30px #000a; }
.card.speed { border-top-color: var(--speed); } .card.aoe { border-top-color: var(--aoe); }
.card.lightning { border-top-color: var(--lightning); } .card.impact { border-top-color: var(--impact); } .card.tide { border-top-color: var(--tide); } .card.fire { border-top-color: var(--fire); }
.card.gravity { border-top-color: var(--gravity); } .card.radiance { border-top-color: var(--radiance); } .card.circuit { border-top-color: var(--circuit); }
.card .br { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-dim); }
.card.speed .br { color: var(--speed); } .card.aoe .br { color: var(--aoe); } .card.util .br { color: var(--util); }
.card.lightning .br { color: var(--lightning); } .card.impact .br { color: var(--impact); } .card.tide .br { color: var(--tide); } .card.fire .br { color: var(--fire); }
.card.gravity .br { color: var(--gravity); } .card.radiance .br { color: var(--radiance); } .card.circuit .br { color: var(--circuit); }
.card h3 { margin: 0; font-size: 24px; line-height: 1.05; }
.card .lv { font-size: 12px; color: var(--ink-dim); font-weight: 800; }
.card .lv.cap { color: var(--gold); }
.card p { margin: 2px 0 0; font-size: 14px; color: var(--ink); font-weight: 600; line-height: 1.35; }
@media (prefers-reduced-motion: reduce) { .card, .bar i, .toast, #guide { transition: none; animation-duration: .01s; } .btn.guide { animation: none; box-shadow: 0 0 0 2px var(--gold), 0 2px 0 #0007; } }

#ask { z-index: 5; }   /* above the help screen, which is where Reset lives */
#ask .box { max-width: 400px; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 18px 14px; }
#ask p { margin: 0 0 14px; font-weight: 700; line-height: 1.4; }
#help .box { max-width: 560px; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px 22px 18px; max-height: 90vh; overflow: auto; }
#help h1 { margin: 0; font-size: 46px; line-height: 1; color: var(--gold); text-shadow: 0 3px 0 #0009; }
#help .sub { margin: 2px 0 10px; color: var(--ink-dim); font-weight: 700; }
#help .controls { margin: 0; font-size: 13px; color: var(--ink-dim); line-height: 1.9; }
#help .hrow { margin-top: 12px; }
/* The long-form help and the settings fold away so a first screen is a title, one line, the controls and Play. */
.fold { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.fold summary { cursor: pointer; list-style: none; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-dim); }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::before { content: '\25B8'; display: inline-block; width: 14px; transition: transform .12s; }
.fold[open] summary::before { transform: rotate(90deg); }
.fold[open] summary { margin-bottom: 6px; color: var(--ink); }
#help ul { margin: 0; padding-left: 18px; font-size: 14px; }
#help li { margin: 2px 0; }
.brs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
.brs div { background: var(--panel-raised); border-radius: 10px; padding: 8px 10px; font-size: 13px; border-top: 4px solid; }
.brs b { display: block; font-size: 14px; }
@media (max-width: 520px) { .brs { grid-template-columns: 1fr; } }
kbd.k { background: #000a; border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; font: 800 12px Nunito, system-ui, sans-serif; }
.hrow { display: flex; gap: 8px; justify-content: space-between; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.muted { color: var(--ink-dim); font-size: 12px; }

/* Audio settings (help panel, Settings fold) */
.audio { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-top: 6px; }
.audio label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-dim); }
.audio label.chk { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 6px; }
.audio input[type=range] { width: 120px; accent-color: var(--gold); }
.audio .btn.on { color: var(--hp); border-color: var(--hp); box-shadow: 0 0 0 1px var(--hp), 0 2px 0 #0007; }

/* Debug panel (` to toggle) — always above every other overlay */
#debug { z-index: 50; }
.dbg { max-width: 640px; }
.item.dbgrow { display: block; }
.item.dbgrow h3 { margin-bottom: 8px; }
.dbgbtns { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.dbgbtns .btn { padding: 6px 10px; font-size: 13px; }
.dbg select { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: inherit; font-weight: 700; }
