@property --heat { syntax: "<number>"; inherits: true; initial-value: 0; }

:root {
  --bg: #0b0716;
  --bg-2: #120c26;
  --surface: #161034;
  --surface-2: #1f1747;
  --ink: #f3f1ff;
  --muted: #aaa6d1;
  --line: #3b3175;
  --accent: #22d3ee;
  --accent-ink: #03141b;
  --accent-2: #f472b6;
  --gold: #facc15;
  --good: #a3e635;
  --good-bg: #17260b;
  --bad: #fb7185;
  --bad-bg: #3a1022;
  --warn: #facc15;
  --life: #ff3b6b;
  --grid: rgba(34, 211, 238, 0.22);
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --radius: 6px;
  --px: 3px;
  --shadow: 0 0 0 2px var(--line), 5px 5px 0 0 rgba(0, 0, 0, 0.55);
  --tier-color: #94a3b8;
  --heat: 0;
  color-scheme: dark;
  transition: --heat 0.6s ease-out;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4ecd6;
    --bg-2: #efe3c4;
    --surface: #fffaf0;
    --surface-2: #f6ecd3;
    --ink: #1d1530;
    --muted: #574f6e;
    --line: #c9b98f;
    --accent: #0e7490;
    --accent-ink: #ffffff;
    --accent-2: #be185d;
    --gold: #713f12;
    --good: #3f6212;
    --good-bg: #ecf5d8;
    --bad: #be123c;
    --bad-bg: #fde4ea;
    --warn: #854d0e;
    --life: #e11d48;
    --grid: rgba(14, 116, 144, 0.14);
    --shadow: 0 0 0 2px var(--line), 4px 4px 0 0 rgba(60, 40, 10, 0.25);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
html, body { margin: 0; background: var(--bg); color: var(--ink); overflow-x: clip; }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; overflow-x: hidden; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0.4em 0; }
code { font-size: 0.9em; }
#app { position: relative; z-index: 1; }

.boot { padding: 2rem 1rem; text-align: center; color: var(--muted); font-family: var(--pixel); font-size: 0.8rem; }
.boot.error { color: var(--bad); }

#bg { position: fixed; inset: 0; contain: strict; z-index: 0; pointer-events: none; overflow: hidden; background: radial-gradient(120% 80% at 50% 0%, var(--bg-2), var(--bg) 70%); }
#bg .grid { position: absolute; left: -50%; right: -50%; bottom: -10%; height: 70%; transform: perspective(380px) rotateX(62deg); transform-origin: 50% 100%;
  background-image: linear-gradient(var(--grid) 2px, transparent 2px), linear-gradient(90deg, var(--grid) 2px, transparent 2px); background-size: 48px 48px;
  opacity: calc(0.45 + var(--heat) * 0.55); animation: grid-run calc(7s - var(--heat) * 5.5s) linear infinite;
  mask-image: linear-gradient(transparent, #000 40%); -webkit-mask-image: linear-gradient(transparent, #000 40%); }
@keyframes grid-run { to { background-position: 0 48px, 0 0; } }
#bg .sparks { position: absolute; inset: 0; opacity: 0; background:
  linear-gradient(105deg, transparent 47%, var(--tier-color) 49%, transparent 51%) 0 0 / 260px 100% no-repeat,
  linear-gradient(75deg, transparent 48%, var(--accent-2) 49.5%, transparent 51%) 0 0 / 200px 100% no-repeat; }
html[data-tier="6"] #bg .sparks, html[data-tier="7"] #bg .sparks { opacity: 0.55; animation: sparks 2.4s linear infinite; }
@keyframes sparks { from { background-position: -300px 0, 120% 0; } to { background-position: 120% 0, -300px 0; } }

.crt .screen.game::after, .crt .screen.home::after { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 15;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px), radial-gradient(130% 100% at 50% 50%, transparent 60%, rgba(0, 0, 0, 0.35)); }
@media (prefers-color-scheme: light) { .crt .screen.game::after, .crt .screen.home::after { background: repeating-linear-gradient(to bottom, rgba(60, 40, 10, 0.06) 0 1px, transparent 1px 3px); } }

.screen { position: relative; max-width: 760px; margin: 0 auto; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); min-height: 100vh; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; flex-wrap: nowrap; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.9rem; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.tag { display: inline-block; font-size: 0.72rem; padding: 1px 7px; border-radius: 3px; background: var(--surface-2); color: var(--muted); margin-right: 6px; vertical-align: 1px; }

button { cursor: pointer; border: 0; background: var(--surface); border-radius: var(--radius); padding: 10px 14px; min-height: 44px; box-shadow: var(--shadow); transition: transform 0.06s, box-shadow 0.06s; }
button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 0 0 0 2px var(--line), 2px 2px 0 0 rgba(0, 0, 0, 0.5); }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 60%, #000), 5px 5px 0 0 rgba(0, 0, 0, 0.55), 0 0 18px color-mix(in srgb, var(--accent) 45%, transparent); }
button.ghost, label.ghost { background: var(--surface); border-radius: var(--radius); padding: 10px 14px; min-height: 44px; display: inline-flex; align-items: center; gap: 6px; box-shadow: var(--shadow); }
button.wide { width: 100%; }
label.file input { display: none; }
label.file { cursor: pointer; }

.title-screen { text-align: center; padding: 18px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.insert { margin: 0; font-weight: 800; font-size: 0.78rem; letter-spacing: 0.3em; color: var(--accent-2); }
.logo { font-family: var(--pixel); font-size: clamp(2rem, 11vw, 4.2rem); margin: 4px 0; letter-spacing: 0.08em; display: flex; flex-direction: column; align-items: center; gap: 0.12em; }
.logo-word { display: flex; gap: 0.04em; }
.logo-word > span { display: inline-block; color: var(--accent); text-shadow: 4px 4px 0 var(--accent-2), 8px 8px 0 rgba(0, 0, 0, 0.5), 0 0 22px color-mix(in srgb, var(--accent) 60%, transparent);
  animation: logo-bob 2.4s ease-in-out infinite; animation-delay: calc(var(--i) * 0.12s); }
@media (prefers-color-scheme: light) { .logo-word > span { text-shadow: 3px 3px 0 var(--accent-2), 6px 6px 0 rgba(60, 40, 10, 0.25); } }
@keyframes logo-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.hi { margin: 0; font-family: var(--pixel); font-size: 0.72rem; color: var(--muted); }
.hi b { color: var(--gold); font-weight: 400; }
.press-start { font-family: var(--pixel); font-size: 0.8rem; background: transparent; box-shadow: none; color: var(--gold); padding: 12px 18px; animation: blink 1.1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
.press-start:focus-visible { animation: none; }
.session-note { text-align: center; font-size: 0.8rem; }

.mix { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #13071f; font-family: var(--pixel); font-size: 0.72rem; line-height: 1.6; padding: 16px; text-align: left; }
.mix .best { color: inherit; }
@media (prefers-color-scheme: light) { .mix { color: #ffffff; text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35); } }
.maps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 700px) { .maps { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.map-card { display: flex; gap: 8px; min-width: 0; }
.map-play { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; background: var(--surface); padding: 12px 14px; border-left: 6px solid hsl(var(--hue) 85% 60%); }
.map-play .num { width: 34px; height: 34px; display: grid; place-items: center; background: hsl(var(--hue) 85% 60%); color: #120a24; font-family: var(--pixel); font-size: 0.8rem; flex: none; border-radius: 3px; }
.map-play .txt, .mode .txt { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.map-play small, .mode small { color: var(--muted); }
.best { color: var(--gold); font-weight: 600; white-space: nowrap; font-family: var(--pixel); font-size: 0.62rem; }
.map-view { flex: none; width: 52px; justify-content: center; }
.tools { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; align-items: center; }
.toggle { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.toggle.small { font-size: 0.9rem; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

.sheet { position: fixed; inset: 0; background: rgba(5, 2, 14, 0.7); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet-body { background: var(--surface); width: 100%; max-width: 760px; max-height: 88vh; overflow: auto; border-radius: 10px 10px 0 0; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; box-shadow: 0 0 0 2px var(--line); }
.sheet-body h3 { font-family: var(--pixel); font-size: 0.78rem; line-height: 1.6; }
.modes { display: grid; gap: 10px; }
.modes > div { display: grid; }
.sheet-head h2 { font-family: var(--pixel); font-size: 0.78rem; line-height: 1.6; }
.mode { display: flex; align-items: center; gap: 12px; text-align: left; padding: 12px; background: var(--surface-2); }
.mode .icon { font-size: 1.4rem; width: 32px; text-align: center; }

.hud { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); padding: 8px 0; border-bottom: 2px solid var(--line); }
.hud .icon-btn { flex: none; min-width: 40px; min-height: 40px; }
@media (max-width: 420px) { .hud .heart { width: 16px; height: 14px; } .hud .score { font-size: 0.72rem; } .round-n { font-size: 0.46rem; } }
.hud .score { font-family: var(--pixel); font-size: 0.9rem; margin-left: auto; color: var(--gold); text-shadow: 0 0 calc(4px + var(--heat) * 14px) color-mix(in srgb, var(--gold) 70%, transparent); font-variant-numeric: tabular-nums; }
.round-n { display: inline-grid; grid-template-columns: auto auto; column-gap: 5px; align-items: baseline; font-family: var(--pixel); font-size: 0.52rem; color: var(--muted); white-space: nowrap; }
.round-n b { font-weight: 400; color: var(--accent); }
.round-bar { grid-column: 1 / -1; height: 3px; background: var(--surface-2); margin-top: 3px; }
.round-bar span { display: block; height: 100%; background: var(--accent); }
.lives { display: inline-flex; gap: 3px; align-items: center; }
.heart { fill: var(--life); filter: drop-shadow(0 0 4px color-mix(in srgb, var(--life) 60%, transparent)); }
.heart.lost { fill: var(--line); filter: none; }
.combo { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center; flex: 1; min-width: 0; max-width: 200px; }
.combo-name { overflow: hidden; text-overflow: ellipsis; }
.combo-n { grid-row: span 2; font-family: var(--pixel); font-size: 0.95rem; color: var(--tier-color); display: flex; align-items: baseline; gap: 4px; }
.combo-n i { font-style: normal; font-size: 0.62rem; color: var(--gold); }
.combo-bar { height: 6px; background: var(--surface-2); box-shadow: 0 0 0 1px var(--line); }
.combo-bar span { display: block; height: 100%; background: var(--tier-color); box-shadow: 0 0 8px var(--tier-color); transition: width 0.25s; }
.combo-name { font-family: var(--pixel); font-size: 0.48rem; color: var(--muted); white-space: nowrap; }
.combo.t1 .combo-n { animation: beat 0.9s ease-in-out infinite; }
.combo:is(.t3, .t4, .t5, .t6, .t7) .combo-n { animation: beat 0.5s ease-in-out infinite; text-shadow: 0 -3px 0 #f97316, 0 -6px 0 #facc15, 0 0 12px #f97316; }
.combo:is(.t3, .t4, .t5, .t6, .t7) .combo-name { color: var(--tier-color); }
@keyframes beat { 50% { transform: scale(1.14); } }

.question, .correction, .over, .paused { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 10px; position: relative; }
.game .question { box-shadow: var(--shadow), 0 0 calc(var(--heat) * 36px) calc(var(--heat) * 4px) color-mix(in srgb, var(--tier-color) 70%, transparent); }
.game:is(.tier-4, .tier-5, .tier-6, .tier-7) .question::before { content: ""; position: absolute; inset: -4px; pointer-events: none; border-radius: calc(var(--radius) + 3px); padding: 4px;
  background: linear-gradient(90deg, #22d3ee, #f472b6, #facc15, #a3e635, #22d3ee); background-size: 300% 100%; animation: fever 2s linear infinite;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0); }
@keyframes fever { to { background-position: 300% 0; } }
.game.tier-5 .option, .game.tier-6 .option, .game.tier-7 .option { box-shadow: var(--shadow), 0 0 14px color-mix(in srgb, var(--tier-color) 50%, transparent); }
.question.golden { box-shadow: 0 0 0 3px var(--gold), 5px 5px 0 0 rgba(0, 0, 0, 0.55), 0 0 30px color-mix(in srgb, var(--gold) 55%, transparent); background: linear-gradient(160deg, color-mix(in srgb, var(--gold) 12%, var(--surface)), var(--surface) 50%); }
.question.boss { box-shadow: 0 0 0 3px var(--bad), 5px 5px 0 0 rgba(0, 0, 0, 0.55), 0 0 26px color-mix(in srgb, var(--bad) 50%, transparent); }
.q-tags { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tag-stage, .tag-boss, .tag-gold, .redo-tag { font-family: var(--pixel); font-size: 0.55rem; line-height: 1.6; padding: 3px 7px; border-radius: 3px; }
.tag-stage { color: var(--muted); background: var(--surface-2); }
.tag-boss { color: #fff; background: repeating-linear-gradient(135deg, #be123c 0 10px, #111 10px 20px); text-shadow: 1px 1px 0 #000; }
.tag-gold { color: #2a1a00; background: var(--gold); }
.redo-tag { color: var(--accent-ink); background: var(--warn); }
.pathway { margin: 0; font-size: 0.85rem; font-weight: 700; color: var(--accent-2); overflow-wrap: anywhere; }
.route-name { margin: 0; font-size: 0.82rem; color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.cross-tag { margin: 0; font-weight: 700; color: var(--warn); }
.ask { font-size: 1.12rem; font-weight: 500; }
.chain { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 3px solid var(--line); display: flex; flex-direction: column; gap: 4px; font-size: 0.92rem; }
.chain li { position: relative; color: var(--muted); }
.chain li::before { content: ""; position: absolute; left: -20px; top: 0.5em; width: 9px; height: 9px; background: var(--line); }
.chain li.current { color: var(--ink); font-weight: 600; }
.chain li.current::before { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.chain li.next { color: var(--accent); font-weight: 800; }

.options { display: grid; gap: 10px; }
.option { text-align: left; padding: 12px 14px; font-size: 0.98rem; min-height: 52px; background: var(--surface-2); animation: deal 0.22s ease-out both; animation-delay: calc(var(--i, 0) * 40ms); }
@keyframes deal { from { opacity: 0; transform: translateY(6px); } }
.option:hover:not(:disabled) { box-shadow: 0 0 0 2px var(--accent), 5px 5px 0 0 rgba(0, 0, 0, 0.55); }
.option.check { display: flex; gap: 10px; align-items: flex-start; }
.option.check.on { box-shadow: 0 0 0 2px var(--accent), 5px 5px 0 0 rgba(0, 0, 0, 0.55); background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); }
.option .box { font-size: 1.15rem; line-height: 1.2; }
.recall { display: flex; flex-direction: column; gap: 8px; align-items: stretch; text-align: center; }
.recall p { margin: 0; color: var(--muted); }
.bar, .timer { height: 10px; background: var(--surface-2); overflow: hidden; box-shadow: 0 0 0 2px var(--line); }
.bar span, .timer span { display: block; height: 100%; background: repeating-linear-gradient(90deg, var(--accent) 0 8px, color-mix(in srgb, var(--accent) 70%, #000) 8px 10px); transition: width 0.1s linear; }
.timer span { background: repeating-linear-gradient(90deg, var(--warn) 0 8px, color-mix(in srgb, var(--warn) 70%, #000) 8px 10px); }
.boss .timer span { background: repeating-linear-gradient(90deg, var(--bad) 0 8px, #6b0f23 8px 10px); }
.affected { margin: 0; padding-left: 20px; }

.impulse { list-style: none; margin: 4px 0 0; padding: 0 0 0 18px; display: grid; gap: 6px; position: relative; }
.impulse::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 3px; background: var(--line); }
.impulse::after { content: ""; position: absolute; left: 1px; top: 0; width: 11px; height: 11px; background: var(--gold); box-shadow: 0 0 12px var(--gold), 0 0 4px #fff;
  animation: travel calc(var(--n) * 110ms + 200ms) ease-in forwards; opacity: 0; }
@keyframes travel { 0% { top: 0; opacity: 1; } 95% { opacity: 1; } 100% { top: calc(100% - 11px); opacity: 0; } }
.impulse li { position: relative; opacity: 0.35; animation: light 0.2s forwards; animation-delay: calc(var(--i) * 110ms); }
.impulse li::before { content: ""; position: absolute; left: -17px; top: 0.45em; width: 9px; height: 9px; background: var(--muted); }
@keyframes light { to { opacity: 1; } }
.impulse li.done::before { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.impulse li.target { color: var(--good); font-weight: 700; }
.impulse li.target::before { background: var(--good); box-shadow: 0 0 10px var(--good); }
.impulse li.wrong { color: var(--bad); font-weight: 700; }
.impulse li.wrong::before { background: var(--bad); box-shadow: 0 0 10px var(--bad); }
.impulse li.later { color: var(--muted); }
.impulse.compact { display: flex; flex-wrap: wrap; gap: 4px 6px; padding: 0; }
.impulse.compact::before, .impulse.compact::after { display: none; }
.impulse.compact li { font-size: 0.75rem; padding: 2px 8px; background: color-mix(in srgb, var(--accent) 16%, var(--surface)); box-shadow: 0 0 0 1px var(--accent); border-radius: 3px; }
.impulse.compact li::before { display: none; }
.stage-strip { padding: 8px 10px; border-radius: var(--radius); background: var(--surface); box-shadow: 0 0 0 2px var(--good), 0 0 20px color-mix(in srgb, var(--good) 35%, transparent); animation: strip 2.6s ease-in forwards; }
@keyframes strip { 0% { opacity: 0; transform: translateY(-6px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.correction { box-shadow: 0 0 0 3px var(--bad), 5px 5px 0 0 rgba(0, 0, 0, 0.55); }
.correction h2 { color: var(--bad); font-family: var(--pixel); font-size: 0.78rem; line-height: 1.6; }
.multi-reveal .full { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.multi-reveal .full .ok { color: var(--good); }
.multi-reveal .full .miss { color: var(--bad); }
.multi-reveal .note { color: var(--warn); font-size: 0.85rem; }
.over { align-items: stretch; text-align: left; }
.go-title { font-family: var(--pixel); font-size: clamp(1.2rem, 6vw, 2rem); text-align: center; color: var(--bad); text-shadow: 3px 3px 0 #000; margin: 6px 0 !important; }
.go-top { display: flex; gap: 16px; align-items: center; justify-content: center; flex-wrap: wrap; }
.rank { font-family: var(--pixel); font-size: 3.6rem; width: 104px; height: 104px; display: grid; place-items: center; background: var(--surface-2); box-shadow: var(--shadow); animation: rank-in 0.6s cubic-bezier(0.2, 2, 0.4, 1) both 0.3s; }
@keyframes rank-in { from { transform: scale(3) rotate(-12deg); opacity: 0; } }
.rank.r-s { color: var(--gold); text-shadow: 0 0 18px var(--gold); }
.rank.r-a { color: var(--good); }
.rank.r-b { color: var(--accent); }
.rank.r-c { color: var(--accent-2); }
.rank.r-d { color: var(--muted); }
.over .big { font-family: var(--pixel); font-size: 1.5rem; margin: 0; color: var(--gold); }
.over .big span { font-size: 0.6rem; color: var(--muted); }
.hiscore { font-family: var(--pixel); font-size: 0.62rem; color: var(--muted); margin-top: 8px !important; }
.hiscore.new { color: var(--gold); animation: blink 0.8s steps(2, start) 4; }
.stats { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats li { background: var(--surface-2); padding: 10px 6px; text-align: center; display: flex; flex-direction: column; gap: 6px; border-radius: 3px; }
.stats b { font-family: var(--pixel); font-size: 0.9rem; color: var(--accent); }
.stats span { font-size: 0.75rem; color: var(--muted); }
.confs { margin: 0; padding-left: 20px; }
.continue { font-family: var(--pixel); font-size: 0.75rem; text-align: center; color: var(--gold); }
.continue b { font-size: 1.1rem; font-weight: 400; }
.paused h2 { font-family: var(--pixel); font-size: 1rem; }

#fx-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 55; image-rendering: pixelated; }
#fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.float-text { position: absolute; transform: translate(-50%, -50%); font-family: var(--pixel); font-size: 0.8rem; color: var(--accent); text-shadow: 2px 2px 0 #000; white-space: nowrap; animation: rise 1s ease-out forwards; }
.float-text.gold { color: var(--gold); font-size: 1rem; }
.float-text.speed { color: var(--good); font-size: 0.6rem; }
.float-text:is(.t3, .t4, .t5, .t6, .t7) { color: var(--tier-color); font-size: 0.95rem; }
@keyframes rise { 0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); } 15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -260%) scale(1); } }
.banner { position: absolute; left: 50%; top: 24%; transform: translate(-50%, -50%); text-align: center; max-width: 94vw; display: flex; flex-direction: column; gap: 8px; align-items: center; animation: slam 0.32s cubic-bezier(0.2, 1.8, 0.4, 1) both; }
.banner b { font-family: var(--pixel); font-weight: 400; font-size: clamp(1.3rem, 7.5vw, 2.8rem); line-height: 1.25; color: var(--tier-color); -webkit-text-stroke: 1px #000;
  text-shadow: 3px 3px 0 #000, 6px 6px 0 rgba(0, 0, 0, 0.4), 0 0 24px var(--tier-color); }
.banner small { font-family: var(--pixel); font-size: clamp(0.5rem, 2.4vw, 0.7rem); color: #fff; background: rgba(0, 0, 0, 0.88); padding: 6px 10px; letter-spacing: 0.05em; }
@keyframes slam { from { transform: translate(-50%, -50%) scale(2.6); opacity: 0; } }
.banner.tier.t5 b, .banner.tier.t6 b { font-size: clamp(1.5rem, 8.5vw, 3.2rem); }
.banner.tier.t7 b { font-size: clamp(1.4rem, 8vw, 3.4rem); color: #fde047; background: linear-gradient(90deg, #fde047, #f472b6, #22d3ee, #a3e635, #fde047); background-size: 300% 100%; -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; animation: gold-run 2s linear infinite; }
@keyframes gold-run { to { background-position: 300% 0; } }
.banner.break b { color: #94a3b8; animation: crack 0.4s steps(4) 1; }
@keyframes crack { 25% { transform: translateX(-6px) rotate(-2deg); } 50% { transform: translateX(5px) rotate(2deg); } 75% { transform: translateX(-3px); } }
.banner.oneup b { color: var(--good); text-shadow: 3px 3px 0 #000, 0 0 24px var(--good); }
.banner.stage b { color: var(--accent); text-shadow: 3px 3px 0 #000, 0 0 24px var(--accent); }
.banner.perfect b, .banner.boss-clear b { color: var(--gold); text-shadow: 3px 3px 0 #000, 0 0 28px var(--gold); }
.banner.boss b { color: #fff; background: repeating-linear-gradient(135deg, #be123c 0 14px, #111 14px 28px); padding: 10px 18px; -webkit-text-stroke: 0; }
.screen-flash { position: absolute; inset: 0; animation: flash 0.42s ease-out forwards; }
.screen-flash.red { background: radial-gradient(circle, transparent 40%, rgba(255, 40, 80, 0.45)); }
.screen-flash.gold { background: radial-gradient(circle, rgba(250, 204, 21, 0.25), transparent 70%); }
.screen-flash.tier { background: radial-gradient(circle, color-mix(in srgb, var(--tier-color) 30%, transparent), transparent 70%); }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
#app.shake-1 { animation: shake 0.3s linear; }
#app.shake-2 { animation: shake 0.42s linear; --amp: 8px; }
@keyframes shake { 10%, 90% { transform: translate(calc(var(--amp, 4px) * -1), 1px); } 20%, 80% { transform: translate(var(--amp, 4px), -2px); } 30%, 50%, 70% { transform: translate(calc(var(--amp, 4px) * -1), 2px); } 40%, 60% { transform: translate(var(--amp, 4px), -1px); } }
#app.tier-zoom .question { animation: zoom 0.32s ease-out; }
@keyframes zoom { from { transform: scale(1.06); filter: brightness(1.6); } }
#app.pop .hud .score { animation: pop 0.18s ease-out; }
@keyframes pop { 50% { transform: scale(1.25); } }
#app.hitstop .question { filter: saturate(0) brightness(1.4); }

.puzzle { display: flex; flex-direction: column; gap: 10px; }
.board { position: relative; display: flex; flex-direction: column; gap: 22px; padding: 14px 10px; background:
  radial-gradient(circle, color-mix(in srgb, var(--accent) 18%, transparent) 1px, transparent 1.5px) 0 0 / 18px 18px, var(--bg-2); border-radius: var(--radius); box-shadow: inset 0 0 0 2px var(--line); }
.wires { position: absolute; inset: 0; pointer-events: none; overflow: visible; z-index: 0; }
.wire { stroke: var(--accent); stroke-width: 4; stroke-linecap: square; stroke-dasharray: 10 6; opacity: 0.85; animation: dash 0.9s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -16; } }
.wire.lit { stroke: var(--gold); stroke-dasharray: none; filter: drop-shadow(0 0 6px var(--gold)); stroke-width: 5; }
.wire.leak { stroke: var(--bad); stroke-dasharray: 4 6; filter: drop-shadow(0 0 6px var(--bad)); }
.wire.ghost { stroke: var(--accent-2); stroke-dasharray: 4 6; }
.arrowhead { fill: var(--accent); }
.slot { display: flex; justify-content: center; position: relative; z-index: 1; }
.loose { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(150px, 44%), 1fr)); gap: 26px 16px; position: relative; z-index: 1; padding: 4px; }
.piece { position: relative; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left; font-size: 0.88rem; line-height: 1.25; padding: 10px 12px; background: var(--surface);
  transform: translate(var(--jx, 0), var(--jy, 0)) rotate(var(--jr, 0)); touch-action: none; user-select: none; -webkit-user-select: none; }
.piece:active:not(:disabled) { transform: translate(var(--jx, 0), var(--jy, 0)) rotate(var(--jr, 0)) translate(2px, 2px); }
.piece.source, .piece.sink { min-width: min(320px, 92%); align-items: center; text-align: center; transform: none; }
.piece.source { box-shadow: 0 0 0 2px var(--accent), 5px 5px 0 0 rgba(0, 0, 0, 0.55); }
.piece.sink { box-shadow: 0 0 0 2px var(--good), 5px 5px 0 0 rgba(0, 0, 0, 0.55); }
.piece .pin { font-family: var(--pixel); font-size: 0.5rem; color: var(--muted); }
.piece.wired { box-shadow: 0 0 0 2px var(--accent), 5px 5px 0 0 rgba(0, 0, 0, 0.55); }
.piece.sel { box-shadow: 0 0 0 3px var(--gold), 0 0 18px color-mix(in srgb, var(--gold) 60%, transparent); animation: glow 0.8s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 3px var(--gold), 0 0 4px color-mix(in srgb, var(--gold) 30%, transparent); } }
.piece.lit { background: color-mix(in srgb, var(--gold) 22%, var(--surface)); box-shadow: 0 0 0 2px var(--gold), 0 0 16px var(--gold); }
.piece.leak { background: var(--bad-bg); box-shadow: 0 0 0 3px var(--bad), 0 0 16px var(--bad); }
.piece:disabled { opacity: 1; }
.piece.dragging { opacity: 0.45; }
.drag-ghost { position: fixed; left: 0; top: 0; z-index: 70; pointer-events: none; margin: 0; opacity: 0.95;
  box-shadow: 0 0 0 3px var(--gold), 0 12px 28px rgba(0, 0, 0, 0.55) !important; }
.drop-over { outline: 3px dashed var(--gold); outline-offset: 3px; }
.bin.drop-over { outline-offset: -4px; background: color-mix(in srgb, var(--gold) 12%, var(--bg-2)); }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
@media (hover: none) { .piece { -webkit-touch-callout: none; } }
.cables summary { cursor: pointer; font-size: 0.9rem; color: var(--muted); min-height: 32px; }
.cables ul { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.cable { font-size: 0.8rem; min-height: 36px; padding: 6px 10px; gap: 6px; }
.cable .x { color: var(--bad); }
.puzzle-actions { display: flex; gap: 10px; justify-content: flex-end; position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 3; flex-wrap: wrap; }
.puzzle-actions .primary { flex: 1; font-family: var(--pixel); font-size: 0.72rem; line-height: 1.6; }
.bins { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
.bin { background: var(--bg-2); box-shadow: inset 0 0 0 2px var(--line); border-radius: var(--radius); padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 92px; }
.bin.ready { box-shadow: inset 0 0 0 2px var(--gold); }
.bin-head { width: 100%; font-family: var(--pixel); font-size: 0.58rem; line-height: 1.6; text-align: left; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; background: var(--surface-2); }
.bin-head small { font-family: system-ui, sans-serif; font-size: 0.75rem; color: var(--gold); }
.bin-body { display: flex; flex-wrap: wrap; gap: 8px; }
.bin-body .piece { transform: none; font-size: 0.82rem; }
.assemble .loose { padding: 8px 4px; }
.sorting .bins { grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); gap: 8px; }
.sorting .bin { min-height: 72px; padding: 6px; }
.sorting .bin-head { font-family: system-ui, sans-serif; font-size: 0.8rem; font-weight: 600; line-height: 1.3; }
.sorting .bin-body .piece { width: 100%; }
.functions-reveal .full li { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.functions-reveal .full li > :not(:first-child) { grid-column: 2; }
.functions-reveal .function-text { color: var(--ink); }
.functions-reveal .function-answer { color: var(--good); display: inline-flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.tray-label { margin: 0 0 4px; font-size: 0.8rem; color: var(--muted); }
.tray-hint { display: none; }
@media (max-width: 1024px) {
  .assemble > .hint { order: -2; }
  .assemble .tray { order: -1; position: sticky; top: 64px; z-index: 4; padding: 6px 8px 8px; border-radius: var(--radius);
    background: color-mix(in srgb, var(--bg-2) 95%, transparent); box-shadow: 0 0 0 2px var(--line), 0 8px 20px rgba(0, 0, 0, 0.35); }
  .tray-hint { display: inline; }
  .assemble .loose { display: flex; flex-wrap: nowrap; gap: 10px; overflow-x: auto; overscroll-behavior-x: contain; padding: 4px 4px 8px; scroll-snap-type: x proximity; }
  .assemble .loose .piece { flex: 0 0 auto; max-width: min(66vw, 320px); transform: none; scroll-snap-align: start; }
}


.toast { position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 6px; z-index: 40; }

.source img { width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.source figcaption { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }
.source { margin: 0 0 12px; }
.textbox { white-space: pre-wrap; background: var(--bg); padding: 10px; border-radius: 6px; font-size: 0.9rem; }

.mapview .cy { touch-action: none; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.select { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.select select { padding: 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); min-height: 44px; max-width: 100%; }
.legend { font-size: 0.85rem; margin: 0; }
.legend .ok { color: var(--good); }
.detail { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.levels details { background: var(--surface); border-radius: 6px; padding: 8px 12px; margin-bottom: 6px; }
.report { list-style: none; padding: 0; display: grid; gap: 8px; }
.report li { background: var(--surface); border-radius: 6px; padding: 10px; }

body.modal-open { overflow: hidden; }
.sheet-body.wide { max-width: 980px; }
@media (min-width: 760px) {
  .sheet { align-items: center; padding: 24px; }
  .sheet-body { border-radius: 10px; max-height: 92vh; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: -14px; background: var(--surface); padding: 6px 0; z-index: 2; }
.sheet-head h2 { font-size: 1.15rem; margin: 0; }
.icon-btn { min-width: 44px; min-height: 44px; padding: 0; display: inline-grid; place-items: center; font-size: 1.2rem; border-radius: 6px; }
.icon-btn:disabled { opacity: 0.4; cursor: default; }

.source-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.source-meta { margin: 0; line-height: 1.35; }
.source-meta span { color: var(--muted); font-size: 0.88rem; }
.pager { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.zoombar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.open-full { margin-left: auto; color: var(--accent); font-weight: 600; text-decoration: none; padding: 10px 4px; }
.open-full:hover { text-decoration: underline; }
.frame { max-height: 66vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; overscroll-behavior: contain; }
.frame .canvas { position: relative; min-width: 100%; }
.frame img { display: block; width: 100%; height: auto; }
.mark { position: absolute; outline: 2px solid #ea580c; outline-offset: 1px; background: rgba(250, 204, 21, 0.16); border-radius: 3px; pointer-events: none; animation: markpulse 1.6s ease-out 2; mix-blend-mode: multiply; }
@keyframes markpulse { 0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7); } 100% { box-shadow: 0 0 0 10px rgba(245, 158, 11, 0); } }
.textsource { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; line-height: 1.5; }
.textsource p { margin: 0; }
.ts-head { margin: 0; font-size: 1.05rem; }
.ts-sub { margin: 6px 0 0; font-size: 0.78rem; letter-spacing: 0.06em; color: var(--muted); }
.ts-comp { display: flex; gap: 10px; align-items: baseline; }
.ts-note { color: var(--warn); font-weight: 600; }
.ts-route { list-style: none; margin: 0 0 0 6px; padding: 0 0 0 18px; border-left: 3px solid var(--line); display: grid; gap: 6px; }
.ts-route li { position: relative; }
.ts-route li::before { content: ""; position: absolute; left: -22px; top: 0.6em; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.ts-route li.foramen::before { display: none; }
.ts-route li.foramen .ring { position: absolute; left: -25px; margin: 0; background: var(--bg); line-height: 1; }
.ts-route li.foramen { font-weight: 600; }
.ring { margin-right: 6px; color: var(--accent); }
mark { background: color-mix(in srgb, #f59e0b 35%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.chip { display: inline-block; min-width: 44px; text-align: center; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.04em; padding: 2px 6px; border-radius: 3px; color: #fff; background: #475569; flex: none; }
.chip.c-asg { background: #1d4ed8; } .chip.c-ase { background: #7c3aed; } .chip.c-avg { background: #0e7490; } .chip.c-ave { background: #9333ea; }
.chip.c-esg { background: #b91c1c; } .chip.c-ese { background: #be123c; } .chip.c-evg { background: #c2410c; } .chip.c-eve { background: #a16207; } .chip.c-simp { background: #374151; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.kbd { display: inline-grid; place-items: center; min-width: 1.6em; height: 1.6em; border: 1px solid var(--line); border-radius: 3px; font-size: 0.75rem; color: var(--muted); margin-right: 8px; flex: none; }
.primary .kbd { color: inherit; border-color: currentColor; margin: 0 0 0 8px; }
.multi-reveal .summary { margin: 0; font-size: 1.02rem; }
.multi-reveal .zone h3 { font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 10px 0 4px; }
.multi-reveal .full li { padding: 2px 0; }
.multi-reveal .full .extra { color: var(--bad); }
.map-play .txt b { line-height: 1.25; }
.correction p, .over p, .question p { margin: 0; }
.correction .good { font-size: 1.05rem; }
.multi { display: flex; flex-direction: column; gap: 16px; }
.multi .options { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.multi .option.check { min-height: 44px; padding: 8px 12px; font-size: 0.95rem; }
.multi > .primary.wide { position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 3; margin-top: 4px; }
.node-label { display: inline-flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.node-label .long { color: var(--muted); font-size: 0.88rem; }
.ask .chip { font-size: 0.9rem; vertical-align: 2px; }
.card-tools { display: flex; flex-direction: column; gap: 8px; }
.card-tools .map-view { flex: 1; min-height: 40px; }
.gallery input[type=search] { padding: 10px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); min-height: 44px; color: var(--ink); }
.gal-group h3 { font-size: 1rem; margin: 14px 0 6px; }
.gal-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.gal-item { width: 100%; display: flex; flex-direction: column; gap: 6px; padding: 6px; text-align: left; background: var(--surface); }
.gal-item img { width: 100%; height: 130px; object-fit: contain; background: #fff; border-radius: 4px; }
.gal-item span { font-size: 0.8rem; color: var(--muted); line-height: 1.3; }
.gal-item:hover, .gal-item:focus-visible { box-shadow: 0 0 0 2px var(--accent), 5px 5px 0 0 rgba(0, 0, 0, 0.55); }
.dot { width: 12px; height: 12px; border-radius: 2px; flex: none; align-self: center; background: #475569; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35); }
.dot.c-asg { background: #3b82f6; } .dot.c-ase { background: #a78bfa; } .dot.c-avg { background: #22d3ee; } .dot.c-ave { background: #c084fc; }
.dot.c-esg { background: #f87171; } .dot.c-ese { background: #fb7185; } .dot.c-evg { background: #fb923c; } .dot.c-eve { background: #facc15; } .dot.c-simp { background: #94a3b8; }
.correction .about { font-weight: 700; font-size: 1.02rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  #bg .grid, #bg .sparks { animation: none !important; }
  .crt .screen.game::after, .crt .screen.home::after { display: none; }
  .press-start { animation: none; }
}

@media (min-width: 1000px) {
  .screen { max-width: 980px; }
  .ask { max-width: 62ch; }
  .multi .options { grid-template-columns: repeat(3, 1fr); }
  .loose { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 480px) {
  .screen { padding-left: 12px; padding-right: 12px; }
  .question, .correction, .over, .paused { padding: 12px; }
  .ask { font-size: 1.02rem; }
  .puzzle .hint { font-size: 0.8rem; }
  .board { gap: 16px; padding: 10px 6px; }
  .loose { gap: 18px 10px; }
  .piece { font-size: 0.82rem; padding: 8px 10px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .rank { width: 84px; height: 84px; font-size: 2.8rem; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .hud { position: static; }
  .multi > .primary.wide, .puzzle-actions { position: static; }
  .assemble .tray { position: static; }
}

.skip-btn { margin-left: auto; min-height: 36px; padding: 4px 10px; font-size: 0.85rem; gap: 6px; }
.skip-btn .kbd { margin: 0; }
.banner.skip b { color: var(--muted); font-size: clamp(1rem, 5vw, 1.6rem); }
.banner.skip small { max-width: 88vw; white-space: normal; line-height: 1.6; }
.given { font-size: 0.85rem; color: var(--muted); border-left: 3px solid var(--accent); padding-left: 8px; }

:root:lang(ko) { --pixel: "Press Start 2P", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif; }
:root:lang(ja) { --pixel: "Press Start 2P", "Noto Sans JP", "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif; }
:root:lang(ko) body, :root:lang(ja) body { line-break: strict; word-break: keep-all; overflow-wrap: anywhere; }

.topbar { position: relative; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 10px; max-width: 980px; margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; }
.brand-mark { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; margin: 0; font-size: 0.85rem; min-width: 0; }
.brand-diamond { flex: none; border-radius: 9px; box-shadow: 0 0 0 1px var(--line); }
.view { display: contents; }
.brand-name { font-family: "Press Start 2P", ui-monospace, monospace; font-size: 0.7rem; letter-spacing: 0.06em; color: var(--ink); }
.brand-by { color: var(--muted); }
.brand-link { color: var(--accent); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.brand-link:hover { color: var(--accent-2); }
.lang-menu { position: relative; flex: none; }
.lang-button { min-height: 40px; padding: 6px 12px; font-size: 0.9rem; display: inline-flex; align-items: center; gap: 6px; }
.lang-list { position: absolute; right: 0; top: calc(100% + 8px); z-index: 70; list-style: none; margin: 0; padding: 6px; min-width: 170px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; }
.lang-list a { display: block; padding: 10px 12px; border-radius: 4px; color: var(--ink); text-decoration: none; }
.lang-list a:hover { background: var(--surface-2); }
.lang-list a[aria-current="true"] { background: var(--surface-2); color: var(--accent); font-weight: 700; }
.site-footer { position: relative; z-index: 1; max-width: 980px; margin: 0 auto; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); text-align: center;
  color: var(--muted); font-size: 0.85rem; }
.site-footer p { margin: 0; }
.source-lang { margin: 0; font-style: italic; }
