:root { --gold: #e0b24a; --ink: #eef1f6; --panel: rgba(14, 18, 26, 0.94); --line: rgba(255, 255, 255, 0.1); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0d12; color: var(--ink); font-family: "Segoe UI", Roboto, system-ui, -apple-system, Arial, sans-serif; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button { font: inherit; color: inherit; }
kbd { display: inline-block; min-width: 1.6em; padding: 0 .35em; border-radius: 5px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); font-size: .8em; text-align: center; margin-right: .3em; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .5s; }
body.playing #hud { opacity: 1; }
#topleft { position: absolute; left: max(12px, env(safe-area-inset-left)); top: max(12px, env(safe-area-inset-top)); width: 250px; padding: 10px 12px; background: rgba(10,13,19,.72); border: 1px solid var(--line); border-radius: 14px; backdrop-filter: blur(6px); }
.who { display: flex; justify-content: space-between; font-weight: 700; color: var(--gold); margin-bottom: 6px; font-size: 14px; }
.meter { position: relative; height: 16px; border-radius: 9px; background: rgba(0,0,0,.55); overflow: hidden; margin-top: 5px; }
.meter i { position: absolute; inset: 0 auto 0 0; width: 100%; border-radius: 9px; transition: width .25s; }
.meter span { position: absolute; inset: 0; font-size: 11px; line-height: 16px; text-align: center; font-weight: 700; text-shadow: 0 1px 2px #000; }
.hp i { background: linear-gradient(90deg, #d33, #ff6b6b); }
.xp i { background: linear-gradient(90deg, #b8860b, #ffd76a); }
#deptbars { position: absolute; right: max(12px, env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top)); width: 270px; padding: 8px 10px; background: rgba(10,13,19,.72); border: 1px solid var(--line); border-radius: 14px; pointer-events: auto; backdrop-filter: blur(6px); }
.dbar { display: grid; grid-template-columns: 22px 1fr 70px 38px; align-items: center; gap: 6px; font-size: 12px; padding: 3px 2px; cursor: pointer; border-radius: 8px; }
.dbar.cur { background: rgba(255,255,255,.08); }
.dbar .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dbar .bar, .prl .bar { height: 8px; background: rgba(0,0,0,.5); border-radius: 5px; overflow: hidden; display: block; }
.dbar .bar i, .prl .bar i { display: block; height: 100%; border-radius: 5px; }
.dbar b { text-align: right; }
#objective { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); padding: 8px 16px; background: rgba(10,13,19,.72); border: 1px solid var(--line); border-radius: 20px; font-size: 14px; max-width: 46vw; text-align: center; backdrop-filter: blur(6px); }
#objective b { color: var(--gold); }
#prompt { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%) translateY(10px); padding: 10px 18px; border-radius: 12px; background: rgba(10,13,19,.85); border: 1px solid rgba(224,178,74,.5); font-size: 16px; opacity: 0; transition: .2s; white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; }
#prompt.show { opacity: 1; transform: translateX(-50%); }
#toasts { position: absolute; left: 50%; top: 70px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; width: min(560px, 92vw); }
.toast { padding: 9px 16px; border-radius: 12px; background: rgba(12,16,24,.92); border: 1px solid var(--line); font-size: 14px; animation: tin .3s ease; transition: opacity .5s, transform .5s; text-align: center; }
.toast.good { border-color: #37d67a; } .toast.bad { border-color: #ff6b6b; } .toast.gold { border-color: var(--gold); background: rgba(60,45,10,.92); font-size: 16px; }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes tin { from { opacity: 0; transform: translateY(-10px); } }
#bossbar { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); width: min(560px, 80vw); display: none; text-align: center; }
#bossbar.show { display: block; }
#bossname { font-weight: 800; color: #ff8a8a; text-shadow: 0 2px 4px #000; margin-bottom: 4px; letter-spacing: .5px; }
#bossbar .meter { height: 14px; border: 1px solid rgba(255,100,100,.5); }
#bossbar .meter i { background: linear-gradient(90deg, #8b0000, #ff4d4d); }
#bossbar.show ~ #toasts { top: 112px; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: rgba(255,255,255,.5); box-shadow: 0 0 0 2px rgba(0,0,0,.3); display: none; }
body.locked #crosshair { display: block; }
.hbtn { position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: rgba(10,13,19,.75); font-size: 20px; pointer-events: auto; cursor: pointer; }
#btnMenu { left: max(14px, env(safe-area-inset-left)); }
#btnBook { left: calc(max(14px, env(safe-area-inset-left)) + 56px); }
#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; }
#flash.go { animation: fl .35s ease-out; }
@keyframes fl { from { opacity: 1; } to { opacity: 0; } }
#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .4s; z-index: 30; }
#fade.on { opacity: 1; }

/* touch controls */
#joy, .tbtn { display: none; }
body.touch #joy { display: block; position: absolute; width: 120px; height: 120px; left: 40px; bottom: 60px; top: auto; border-radius: 50%; border: 2px solid rgba(255,255,255,.18); background: rgba(255,255,255,.05); opacity: .55; }
body.touch #joy.on { opacity: 1; bottom: auto; }
#knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(224,178,74,.6); }
body.touch .tbtn { display: block; position: absolute; pointer-events: auto; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); background: rgba(10,13,19,.6); font-size: 30px; }
body.touch #btnAtk { right: 28px; bottom: 40px; width: 84px; height: 84px; background: rgba(140,30,30,.6); }
body.touch #btnAct { right: 124px; bottom: 34px; width: 64px; height: 64px; opacity: .35; }
body.touch #btnAct.show { opacity: 1; background: rgba(224,178,74,.55); }
body.touch #prompt { bottom: 140px; }
body.touch #btnMenu, body.touch #btnBook { top: calc(max(12px, env(safe-area-inset-top)) + 96px); bottom: auto; }

/* ---------------- modal panels ---------------- */
#modal { position: fixed; inset: 0; display: none; z-index: 20; background: rgba(4,6,10,.45); align-items: center; justify-content: center; padding: 14px; }
#modal.show { display: flex; }
.panel { width: min(560px, 96vw); max-height: 92vh; overflow-y: auto; background: var(--panel); border: 1px solid rgba(224,178,74,.35); border-radius: 18px; padding: 18px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.6); animation: pin .2s ease; }
.panel.wide { width: min(820px, 96vw); }
.panel.bottom { align-self: flex-end; width: min(820px, 96vw); margin-bottom: 30px; cursor: pointer; }
@keyframes pin { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.dlg .who { font-size: 15px; letter-spacing: .5px; margin-bottom: 6px; }
.dlg .say { font-size: 19px; line-height: 1.5; min-height: 3em; }
.dlg .hint { text-align: right; font-size: 12px; opacity: .55; margin-top: 6px; }
.card { --c: var(--gold); }
.card h2 { margin: 2px 0 12px; font-family: Georgia, serif; color: var(--c); font-size: 24px; }
.card h3 { color: var(--c); margin: 18px 0 6px; font-size: 17px; }
.card .sub { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; opacity: .65; }
.card ul { padding-left: 20px; margin: 6px 0; } .card li { margin: 7px 0; line-height: 1.45; }
.card p { line-height: 1.5; }
.formula { margin: 12px 0; padding: 10px 14px; border-left: 4px solid var(--c, var(--gold)); background: rgba(255,255,255,.05); border-radius: 8px; font-family: "Cambria Math", Georgia, serif; font-size: 16px; line-height: 1.5; }
.example { margin: 12px 0; padding: 10px 14px; background: rgba(55,214,122,.08); border: 1px dashed rgba(55,214,122,.4); border-radius: 10px; font-family: ui-monospace, Consolas, monospace; font-size: 14px; line-height: 1.6; }
.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.btn { padding: 10px 18px; border-radius: 11px; border: 1px solid var(--line); background: rgba(255,255,255,.07); cursor: pointer; font-weight: 600; }
.btn:hover { background: rgba(255,255,255,.13); }
.btn.primary { background: linear-gradient(180deg, #e6b94d, #b98a22); color: #1b1305; border: none; }
.btn.danger { border-color: rgba(255,90,90,.5); color: #ff9a9a; }
.small { font-size: 13px; opacity: .75; }
.menu .btn { display: block; width: 100%; text-align: left; margin: 7px 0; }

.q .qhead { display: flex; gap: 10px; align-items: center; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; opacity: .85; margin-bottom: 10px; flex-wrap: wrap; }
.q .qhead span:first-child { color: var(--c); font-weight: 700; }
.q .tag { padding: 2px 8px; border-radius: 10px; color: #000; font-weight: 700; text-transform: none; letter-spacing: 0; margin-left: auto; }
.q .ctx { font-size: 13px; opacity: .75; margin-bottom: 8px; }
.q .qt { font-size: 19px; line-height: 1.45; margin: 6px 0 14px; }
.opts { display: grid; gap: 8px; }
.opts.tf { grid-template-columns: 1fr 1fr; }
.opts.grid3 { grid-template-columns: 1fr 1fr; }
.opt { text-align: left; padding: 12px 14px; border-radius: 11px; border: 1px solid var(--line); background: rgba(255,255,255,.05); cursor: pointer; font-size: 16px; line-height: 1.35; transition: .12s; }
.opt:hover:not(:disabled) { background: rgba(255,255,255,.12); border-color: var(--c); }
.opt.right { background: rgba(55,214,122,.22); border-color: #37d67a; }
.opt.wrong { background: rgba(255,90,90,.2); border-color: #ff5a5a; }
.opt:disabled { cursor: default; }
.calc { display: flex; gap: 8px; align-items: center; }
.calc input { flex: 1; padding: 12px; font-size: 18px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,.35); color: #fff; min-width: 0; }
.calc input.right { border-color: #37d67a; } .calc input.wrong { border-color: #ff5a5a; }
.calc .unit { opacity: .7; white-space: nowrap; }
.verdict { margin-top: 14px; font-size: 17px; font-weight: 600; } .verdict.ok { color: #5ef09a; } .verdict.no { color: #ff8a8a; }
.why { margin-top: 8px; padding: 10px 12px; background: rgba(255,255,255,.05); border-radius: 10px; line-height: 1.5; font-size: 15px; }
.timer { height: 6px; background: rgba(255,255,255,.08); border-radius: 4px; overflow: hidden; margin-bottom: 10px; }
.timer i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ff5a5a, #ffd166, #37d67a); }
.streak { color: #ffb347; font-weight: 800; margin-bottom: 4px; }
.big2 { font-size: 24px; font-weight: 700; }
.cust { display: flex; gap: 14px; align-items: center; } .cust .av { font-size: 44px; }
.case { padding: 12px; background: #f3ead2; color: #2a2010; border-radius: 6px; font-family: Georgia, serif; box-shadow: inset 0 0 0 1px #c8b88a; }
.result .big { font-size: 34px; font-weight: 800; margin: 8px 0; color: var(--c); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tab { padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.05); cursor: pointer; font-size: 13px; }
.tab.on { border-color: var(--c); background: rgba(255,255,255,.12); }
details.nb { border: 1px solid var(--line); border-radius: 10px; margin: 6px 0; padding: 6px 10px; }
details.nb summary { cursor: pointer; font-weight: 600; color: #8ff0b5; }
details.nb .card { padding: 6px 0; } details.nb .card h2 { font-size: 18px; }
.nb.lock { padding: 8px 10px; opacity: .5; border: 1px dashed var(--line); border-radius: 10px; margin: 6px 0; font-size: 14px; }
.search { width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,.35); color: #fff; font-size: 15px; margin-bottom: 8px; }
.gi { padding: 7px 0; border-bottom: 1px solid var(--line); line-height: 1.45; font-size: 14px; }
.pr { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin: 10px 0; }
.pr.focus { border-color: var(--c); }
.pr h3 { margin: 4px 0; display: flex; justify-content: space-between; }
.prl { display: grid; grid-template-columns: 1fr 120px auto; gap: 8px; align-items: center; font-size: 13px; margin: 5px 0; }
.prl i { font-style: normal; opacity: .6; } .pr .prl .bar i { background: var(--c); }
.ctl { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* exhibits */
.flow { position: relative; display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: auto auto auto; gap: 10px; margin: 10px 0; }
.flow .node { padding: 12px; border-radius: 12px; text-align: center; font-weight: 700; background: rgba(255,255,255,.06); border: 2px solid; }
.flow .hh { border-color: #2fe0a0; grid-column: 1; grid-row: 1; } .flow .bz { border-color: #ff9f43; grid-column: 3; grid-row: 1; } .flow .fi { border-color: #4fc3ff; grid-column: 2; grid-row: 3; }
.flow .lane { grid-column: 1 / 4; font-size: 13px; padding: 6px 10px; border-radius: 8px; }
.flow .direct { grid-row: 2; background: rgba(255,209,102,.12); color: #ffd166; text-align: center; animation: pulse 2s infinite; }
.flow .ind { grid-row: 4; background: rgba(79,195,255,.12); color: #8fd8ff; text-align: center; animation: pulse 2s 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.calcgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.calcgrid label { font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.calcgrid input[type=number] { padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: rgba(0,0,0,.35); color: #fff; font-size: 15px; }
.calcgrid .formula { grid-column: 1 / 3; }
.timeline { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ts { padding: 10px; border-radius: 12px; background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.ts .ti { font-size: 34px; } .ts p { font-size: 13px; margin: 4px 0 0; opacity: .85; }
.scale { display: flex; align-items: center; justify-content: center; gap: 0; margin: 16px 0 6px; }
.scale .pan { width: 120px; padding: 8px; text-align: center; border-radius: 10px; background: rgba(255,255,255,.07); font-size: 14px; }
.scale .pan b { display: block; font-size: 22px; }
.scale .beam { width: 180px; height: 6px; background: var(--gold); border-radius: 3px; transition: transform .3s; margin: 0 -6px; }
.bs { font-size: 14px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.bl { display: flex; justify-content: space-between; padding: 6px 10px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,.05); }
.bl:hover, .bl.sel { background: rgba(224,165,38,.18); }
.bl.T { font-weight: 800; background: rgba(255,255,255,.06); }
.bl.L span::before { content: 'L · '; color: #ff9f43; } .bl.E span::before { content: 'E · '; color: #9b6bff; } .bl.A span::before { content: 'A · '; color: #2fe0a0; }

/* ---------------- loading ---------------- */
#loading { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at center, rgba(30,24,12,.82), rgba(5,6,9,.97)); transition: opacity .6s; padding: 16px; overflow-y: auto; }
#loading.gone { opacity: 0; pointer-events: none; }
.lbox { text-align: center; max-width: 720px; }
.logo { font-size: 64px; }
#loading h1 { font-family: Georgia, serif; letter-spacing: 6px; font-size: clamp(32px, 7vw, 60px); margin: 4px 0; color: #f0d48a; text-shadow: 0 4px 20px rgba(224,178,74,.4); }
#loading h1 span { color: #fff; font-size: .6em; }
.tag { opacity: .8; }
.chapters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 22px 0; }
.chapters div { padding: 12px 8px; border-radius: 12px; border: 1px solid var(--c); background: rgba(255,255,255,.04); font-size: 14px; }
.chapters small { display: block; opacity: .7; margin-top: 4px; }
#start { padding: 14px 40px; font-size: 20px; font-weight: 800; border-radius: 14px; border: none; cursor: pointer; background: linear-gradient(180deg, #f0c75e, #b98a22); color: #1b1305; box-shadow: 0 8px 30px rgba(224,178,74,.35); }
#start:disabled { opacity: .5; cursor: wait; }
#loadmsg { min-height: 1.2em; opacity: .7; font-size: 14px; }

@media (max-width: 760px) {
  #topleft { width: 180px; padding: 7px 9px; } .who { font-size: 12px; }
  #deptbars { width: 150px; } .dbar { grid-template-columns: 18px 1fr 30px; font-size: 11px; } .dbar .nm { display: none; }
  #objective { top: auto; bottom: 150px; max-width: 70vw; font-size: 12px; }
  .chapters { grid-template-columns: 1fr 1fr; }
  .q .qt { font-size: 17px; } .opt { font-size: 15px; padding: 10px 12px; }
  .opts.grid3 { grid-template-columns: 1fr; }
  .timeline { grid-template-columns: 1fr 1fr; } .ctl { grid-template-columns: 1fr; } .calcgrid { grid-template-columns: 1fr; } .calcgrid .formula { grid-column: 1; }
  .panel { padding: 14px; }
}
@media (max-height: 500px) { #objective { display: none; } }
