/* engine/engine.css — base chrome for every game on this engine. Games add a theme file. */
:root {
  --ink: #e8edf5; --ink-dim: #9aa6b8; --panel: rgba(10, 14, 24, .86); --line: rgba(140, 170, 210, .22);
  --accent: #4cc9f0; --accent-2: #f2c14e; --danger: #ff6b5c;
  --display: 'Space Grotesk', 'Segoe UI', system-ui, sans-serif; --body: 'Lexend', 'Segoe UI', system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: #05070d; color: var(--ink); font-family: var(--body); overflow: hidden; }
#game { position: fixed; inset: 0; }
canvas.gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button { font: inherit; color: inherit; cursor: pointer; }

/* HUD */
.hud { position: absolute; inset: 0 0 auto 0; display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 14px; pointer-events: none; z-index: 5; }
.hud > * { pointer-events: auto; }
.hud-name { font-family: var(--display); font-weight: 700; letter-spacing: .04em; font-size: 15px; text-shadow: 0 1px 2px #000; }
.hud-area { font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .14em; margin-top: 2px; text-shadow: 0 1px 2px #000; }
.hud-right { display: flex; gap: 10px; align-items: center; }
.hud-hz { font-family: var(--display); font-weight: 700; font-size: 17px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; color: var(--accent-2); }
.hud-hz small { font-size: 11px; color: var(--ink-dim); margin-left: 2px; }
.hud-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 13px; }
.hud-btn:hover { border-color: var(--accent); }

.prompt { position: absolute; left: 50%; bottom: 14%; transform: translate(-50%, 8px); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; font-size: 15px; opacity: 0; transition: opacity .15s, transform .15s; pointer-events: none; z-index: 6; white-space: nowrap; max-width: 92vw; text-overflow: ellipsis; overflow: hidden; }
.prompt b { display: inline-block; min-width: 24px; padding: 1px 6px; margin-right: 8px; border-radius: 6px; background: var(--accent); color: #06111a; font-family: var(--display); text-align: center; }
.prompt.show { opacity: 1; transform: translate(-50%, 0); }

.toast { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--accent-2); border-radius: 10px; padding: 8px 14px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 7; }
.toast.show { opacity: 1; }
.fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .4s; z-index: 20; }
.fade.show { opacity: 1; pointer-events: auto; }
.perf { position: absolute; left: 10px; bottom: 8px; font: 11px ui-monospace, monospace; color: #7f8ea3; opacity: .8; pointer-events: none; z-index: 5; }

/* Dialog */
.dialog { position: absolute; left: 50%; bottom: 22px; transform: translate(-50%, 12px); width: min(760px, 94vw); background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 14px; padding: 14px 18px 12px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 8; cursor: pointer; }
.dialog.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.dialog-speaker { font-family: var(--display); font-weight: 700; color: var(--accent); font-size: 13px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 4px; }
.dialog-text { font-size: 16px; line-height: 1.45; }
.dialog-hint { font-size: 11px; color: var(--ink-dim); text-align: right; margin-top: 6px; }

/* Screens */
.screen { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; padding: 16px; z-index: 10; background: radial-gradient(ellipse at 50% 30%, rgba(5, 10, 24, .35), rgba(2, 4, 10, .78)); overflow: auto; }
.screen.show { display: flex; }
.panel { width: min(640px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 26px 26px 22px; backdrop-filter: blur(8px); box-shadow: 0 20px 60px rgba(0,0,0,.5); max-height: calc(100vh - 32px); overflow: auto; }
.panel h2 { font-family: var(--display); font-size: 24px; margin-bottom: 8px; }
.muted { color: var(--ink-dim); font-size: 14px; margin-bottom: 14px; line-height: 1.4; }
.muted.small, .small { font-size: 12px; }
.btn { display: block; width: 100%; background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; font-size: 15px; text-align: center; transition: border-color .12s, background .12s; }
.btn:hover { border-color: var(--accent); background: rgba(76, 201, 240, .08); }
.btn.primary { background: var(--accent); color: #06111a; border-color: var(--accent); font-weight: 700; font-family: var(--display); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(255,107,92,.5); color: var(--danger); }
.btn.small { width: auto; display: inline-block; padding: 8px 14px; font-size: 13px; }
.btn-col { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.btn-row .btn { width: auto; flex: 1; }
.title { text-align: center; }
.title-kicker { font-size: 12px; letter-spacing: .3em; text-transform: uppercase; color: var(--accent); }
.title-name { font-family: var(--display); font-size: clamp(40px, 9vw, 72px); line-height: 1; letter-spacing: -.02em; margin: 8px 0 6px; }
.title-tag { color: var(--ink-dim); font-size: 15px; margin-bottom: 8px; }
.title-mode{margin-top:10px;font-size:13px;font-weight:700;letter-spacing:.04em;color:#8dc63f;text-transform:uppercase}
.title-foot { color: var(--ink-dim); font-size: 11px; margin-top: 10px; }
.mode-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
@media (max-width: 560px) { .mode-row { grid-template-columns: 1fr; } }
.mode-card { text-align: left; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 14px; padding: 16px; transition: border-color .12s, transform .12s; }
.mode-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.mode-title { font-family: var(--display); font-weight: 700; font-size: 18px; }
.mode-std { font-size: 12px; color: var(--accent-2); letter-spacing: .08em; margin: 2px 0 8px; }
.mode-desc { font-size: 13px; color: var(--ink-dim); line-height: 1.4; }
.code-in, .text-in { width: 100%; background: rgba(0,0,0,.35); border: 1px solid var(--line); border-radius: 10px; color: var(--ink); padding: 10px 12px; font: 14px ui-monospace, Menlo, Consolas, monospace; resize: vertical; }
.text-in { font-family: var(--body); font-size: 15px; }
.err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }
.codebox { margin-top: -4px; }
.crow { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 10px; margin-bottom: 10px; }
.clabel { font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .1em; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.sw { width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255,255,255,.18); }
.sw.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.segb { background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.segb.on { background: var(--accent); color: #06111a; border-color: var(--accent); }
.keys-help { margin-top: 6px; text-align: center; }
.screen:has(.panel.creator) { justify-content: flex-end; background: linear-gradient(90deg, rgba(2,4,10,0) 35%, rgba(2,4,10,.72) 70%); }
.panel.creator { width: min(470px, 100%); }
@media (max-width: 820px) { .screen:has(.panel.creator) { justify-content: center; align-items: flex-end; background: linear-gradient(180deg, rgba(2,4,10,0) 25%, rgba(2,4,10,.8) 55%); } .panel.creator { max-height: 62vh; } }

/* Touch controls */
.touch-ui { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.tstick { position: absolute; left: 26px; bottom: 26px; width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,.08); border: 1px solid var(--line); pointer-events: auto; touch-action: none; }
.tknob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(76,201,240,.55); border: 2px solid rgba(255,255,255,.5); }
.tbtn { position: absolute; right: 26px; width: 72px; height: 72px; border-radius: 50%; background: rgba(76,201,240,.35); border: 2px solid rgba(255,255,255,.4); font-family: var(--display); font-weight: 700; pointer-events: auto; touch-action: none; }
.tbtn-a { bottom: 36px; }
.tbtn-b { bottom: 124px; width: 54px; height: 54px; right: 35px; font-size: 18px; }

/* ---- HUD extras ---- */
.hud-title { font-size: 11px; color: var(--accent-2); letter-spacing: .12em; text-transform: uppercase; text-shadow: 0 1px 2px #000; }
.hud-obj { margin-top: 6px; font-size: 13px; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; max-width: min(420px, 60vw); line-height: 1.35; }
.hud-obj:empty { display: none; }

/* ---- Overlays (shop, guide, map, log, minigames) ---- */
.overlay { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; padding: 14px; z-index: 9; background: rgba(2, 4, 10, .55); }
.overlay.show { display: flex; }
.opanel { width: min(560px, 100%); max-height: calc(100vh - 28px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; backdrop-filter: blur(8px); box-shadow: 0 20px 60px rgba(0,0,0,.5); overflow: hidden; }
.opanel.wide { width: min(860px, 100%); }
.ohead { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 10px; border-bottom: 1px solid var(--line); }
.otitle { font-family: var(--display); font-weight: 700; font-size: 20px; }
.osub { font-size: 12px; color: var(--ink-dim); margin-top: 2px; }
.oclose { background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 50%; width: 34px; height: 34px; font-size: 15px; }
.oclose:hover { border-color: var(--accent); }
.obody { padding: 14px 18px 18px; overflow: auto; }
.obody h3 { font-family: var(--display); font-size: 15px; margin: 12px 0 8px; color: var(--accent); letter-spacing: .04em; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab { background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.tab.on { background: var(--accent); color: #06111a; border-color: var(--accent); font-weight: 600; }

/* shop */
.shop-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.shop-bal { font-family: var(--display); font-size: 16px; color: var(--accent-2); white-space: nowrap; }
.shop-bal b { font-size: 20px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.shop-item { background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 5px; }
.shop-item.eq { border-color: var(--accent); }
.si-swatch { height: 46px; border-radius: 8px; background: rgba(255,255,255,.06); display: flex; align-items: center; justify-content: center; font-size: 26px; }
.si-name { font-weight: 600; font-size: 14px; }
.si-desc { font-size: 12px; color: var(--ink-dim); line-height: 1.35; flex: 1; }
.si-count { font-size: 12px; color: var(--accent-2); }
.shop-item .btn.small { width: 100%; padding: 7px 8px; }

/* guide */
.gsec { margin-bottom: 14px; }
.gel { margin-bottom: 6px; font-size: 13px; }
.gel b { color: var(--accent-2); }
.gcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.gcard { background: rgba(255,255,255,.04); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; padding: 10px 12px; }
.gcard.compact { margin-top: 8px; }
.gimg { width: 100%; border-radius: 6px; margin-bottom: 8px; display: block; }
.gtitle { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.gbody { font-size: 13px; line-height: 1.45; color: var(--ink); }
.gempty { padding: 6px 0 0; }

/* story / log */
.chapters { display: flex; flex-direction: column; gap: 6px; }
.chapter { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.03); }
.chapter.cur { border-color: var(--accent); }
.chapter.done { opacity: .7; }
.chapter.locked { opacity: .45; }
.chnum { width: 28px; height: 28px; border-radius: 50%; background: rgba(255,255,255,.08); display: flex; align-items: center; justify-content: center; font-family: var(--display); font-weight: 700; font-size: 13px; }
.chapter.done .chnum { background: var(--accent); color: #06111a; }
.chtitle { font-weight: 600; font-size: 14px; }
.logs { display: flex; flex-direction: column; gap: 8px; }
.logentry { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: rgba(255,255,255,.03); }
.logtitle { font-weight: 700; font-size: 14px; }
.logbody { font-size: 13px; line-height: 1.45; margin-top: 6px; font-style: italic; }

/* map */
.mapcanvas { display: block; margin: 0 auto; border-radius: 12px; border: 1px solid var(--line); max-width: 100%; }
.maplegend { font-size: 12px; color: var(--ink-dim); margin-top: 8px; display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.maplegend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

/* minigames */
.mgcanvas { display: block; margin: 0 auto; border-radius: 12px; border: 1px solid var(--line); background: #070a12; max-width: 100%; outline: none; }
.mgcanvas:focus { border-color: var(--accent); }
.mgstatus { font-size: 14px; line-height: 1.45; margin-bottom: 10px; }
.mgcontrols { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.mgcontrols input[type=range] { flex: 1; min-width: 160px; accent-color: var(--accent); }
.mgcontrols .btn.small { width: auto; }
.mghint { margin-top: 8px; font-size: 13px; }
.mgwhy { color: var(--danger); margin-bottom: 4px; }
.mghintline { color: var(--accent-2); }
.mgkey { display: inline-block; padding: 1px 7px; border-radius: 6px; background: rgba(255,255,255,.1); border: 1px solid var(--line); font-family: var(--display); font-size: 12px; }

/* teacher data */
.treport { background: #fff; color: #111; border-radius: 10px; padding: 18px 20px; font-family: var(--body); }
.thead { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-bottom: 2px solid #16294a; padding-bottom: 10px; margin-bottom: 12px; }
.tgame { font-family: var(--display); font-weight: 700; font-size: 20px; color: #16294a; }
.tsite { font-size: 12px; color: #556; }
.tmeta { font-size: 13px; line-height: 1.5; }
.ttable { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ttable th { text-align: left; background: #eef2f8; color: #16294a; padding: 6px 8px; border-bottom: 1px solid #cfd6e2; }
.ttable td { padding: 7px 8px; border-bottom: 1px solid #e3e8f0; vertical-align: top; }
.tel { font-weight: 700; white-space: nowrap; }
.ttext { color: #333; line-height: 1.35; }
.tnum { text-align: center; white-space: nowrap; }
.tmeter { width: 110px; height: 10px; background: #e3e8f0; border-radius: 999px; overflow: hidden; }
.tfill { height: 100%; background: #2fa9a0; }
.textras { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 12px; font-size: 13px; }
.tnote { font-size: 11px; color: #666; margin-top: 12px; }
#print-root { display: none; }
@media print {
  body.printing #game { display: none !important; }
  body.printing #print-root { display: block !important; }
  body { background: #fff; overflow: visible; }
  .treport { padding: 0; }
}

/* level ladder */
.lvlist { display: flex; flex-direction: column; gap: 8px; }
.lvcard { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.03); }
.lvcard.next { border-color: var(--accent); background: rgba(76,201,240,.06); }
.lvcard.done { opacity: .8; }
.lvcard.locked { opacity: .45; }
.lvcard.cert .lvnum { background: var(--accent-2); color: #06111a; }
.lvnum { width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,.08); display: flex; align-items: center; justify-content: center; font-family: var(--display); font-weight: 700; }
.lvcard.done .lvnum { background: var(--accent); color: #06111a; }
.lvtitle { font-weight: 700; font-size: 14px; }
.lvmeta { font-size: 12px; color: var(--accent-2); margin-top: 3px; }
.lvcard .btn.small { width: auto; min-width: 84px; }
.mgread { margin-top: 6px; font-size: 13px; }

.tbtn-j { bottom: 36px; right: 112px; width: 60px; height: 60px; font-size: 12px; background: rgba(242,193,78,.35); }

/* race HUD + results */
.racehud { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.race-time { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); font-family: var(--display); font-weight: 700; font-size: 34px; color: #fff; text-shadow: 0 2px 6px #000; }
.race-lap { position: absolute; top: 104px; left: 50%; transform: translateX(-50%); font-size: 13px; color: var(--ink-dim); text-shadow: 0 1px 2px #000; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }
.race-arrow { position: absolute; top: 130px; left: 50%; margin-left: -18px; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; font-size: 28px; color: #8dc63f; text-shadow: 0 2px 6px #000; transition: transform .1s; }
.race-count { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); font-family: var(--display); font-weight: 700; font-size: 96px; color: var(--accent-2); text-shadow: 0 4px 12px #000; }
.race-help { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); font-size: 12px; color: var(--ink-dim); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; white-space: nowrap; }
.race-result { text-align: center; }
.medal { display: inline-block; font-family: var(--display); font-weight: 700; font-size: 26px; letter-spacing: .12em; padding: 10px 22px; border-radius: 999px; margin: 6px 0 12px; }
.medal.gold { background: #e3b341; color: #3a2a00; } .medal.silver { background: #c6cbd4; color: #22262e; } .medal.bronze { background: #b07a4a; color: #2a1a08; }
.race-stats { font-size: 14px; line-height: 1.6; }
.race-stats .good { color: var(--accent); }
.lvnum.medal-gold { background: #e3b341; color: #3a2a00; } .lvnum.medal-silver { background: #c6cbd4; color: #22262e; } .lvnum.medal-bronze { background: #b07a4a; color: #2a1a08; }

/* credits */
.credits { text-align: center; }
.credits h3 { margin-top: 14px; }
.credit-row { font-size: 14px; margin: 3px 0; }

/* cinematic layer (engine/cinematic.js) */
.cine { position: absolute; inset: 0; pointer-events: none; z-index: 9; opacity: 0; transition: opacity .45s; }
.cine.show { opacity: 1; }
.cine-bar { position: absolute; left: 0; right: 0; height: 11vh; background: #000; }
.cine-bar.top { top: 0; } .cine-bar.bottom { bottom: 0; }
.cine-cap { position: absolute; left: 0; right: 0; bottom: 14vh; text-align: center; opacity: 0; transform: translateY(8px); transition: opacity .5s, transform .5s; padding: 0 16px; }
.cine-cap.show { opacity: 1; transform: none; }
.cine-title { font-family: var(--display); font-weight: 700; font-size: clamp(18px, 3.2vw, 30px); letter-spacing: .12em; text-transform: uppercase; color: #fff; text-shadow: 0 2px 10px #000; }
.cine-sub { margin-top: 6px; font-size: clamp(13px, 1.6vw, 16px); color: #c9d3e2; text-shadow: 0 1px 6px #000; }
.cine-skip { position: absolute; right: 18px; bottom: 3.5vh; font-size: 12px; color: #9aa6b8; }
.cine-skip b { display: inline-block; padding: 1px 6px; margin-right: 6px; border-radius: 6px; background: var(--accent); color: #06111a; font-family: var(--display); }
.mgkb { margin-top: 6px; font-size: 12px; color: #9aa6b8; }
.mgkb b { display: inline-block; padding: 0 6px; margin: 0 1px; border-radius: 5px; background: rgba(255,255,255,.1); border: 1px solid var(--line); font-family: var(--display); font-size: 11px; color: #e8edf5; }

/* on-screen camera tools: zoom out / zoom in / full screen (bottom-right) */
.hud-tools { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 8px; z-index: 5; }
.hud-btn.tool { width: 40px; height: 40px; padding: 0; font-size: 18px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }

.hud-task { margin-top: 6px; font-size: 13px; color: #fff3c4; background: rgba(242,193,78,.14); border: 1px solid var(--accent-2); border-radius: 10px; padding: 6px 10px; max-width: 460px; line-height: 1.35; }
.hud-task:empty { display: none; }
