:root {
  --ink: #23405a;
  --muted: #627a8c;
  --sky: #8fd3fb;
  --sky-deep: #3d9be0;
  --paper: #fffdf7;
  --gold: #ffc94a;
  --gold-deep: #e39a22;
  --teal: #147d79;
  --red: #e2574c;
  --green: #2d9b64;
  --display: "Baloo 2", "Nunito", system-ui, sans-serif;
  --body: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; color: var(--ink); background: var(--sky); font: 700 14px/1.5 var(--body); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: .45; }
:focus-visible { outline: 3px solid #ec9b40; outline-offset: 3px; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin: 0; }
h1, h2 { font-family: var(--display); line-height: 1.1; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { flex: none; width: 20px; height: 20px; }
kbd { display: inline-block; min-width: 22px; margin: 0 1px; padding: 0 5px; border: 1.5px solid #c6d6e0; border-bottom-width: 3px; border-radius: 6px; background: white; font: 800 11px/18px var(--body); text-align: center; }

.shell { display: flex; flex-direction: column; height: 100dvh; }
.topbar { z-index: 3; display: flex; align-items: center; gap: 14px; flex: none; min-height: 64px; padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); background: var(--paper); border-bottom: 2px solid var(--ink); }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand img { width: 38px; height: 38px; object-fit: contain; }
.brand span { display: grid; line-height: 1.05; }
.brand small { color: var(--muted); font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; }
.brand strong { font: 800 23px var(--display); white-space: nowrap; }
.brand em, h1 span { color: var(--sky-deep); font-style: normal; }
.hud { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.hud-pill { display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px; border: 2px solid var(--ink); border-radius: 12px; background: white; box-shadow: 0 3px 0 var(--ink); font-variant-numeric: tabular-nums; }
.hud-pill span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.hud-pill strong { font: 800 20px var(--display); }
.hud-pill.score strong { min-width: 3ch; }
.hud-pill.stars { color: var(--gold-deep); }
.hud-pill.stars strong { color: var(--ink); }
.hud-pill.lives { gap: 3px; color: var(--red); }
.hud-pill.lives .icon { width: 21px; height: 21px; transition: transform .3s, opacity .3s; }
.hud-pill.lives .icon.lost { color: #c8d3da; transform: scale(.75); }
.hud-pill.bump { animation: bump .35s ease; }
@keyframes bump { 40% { transform: scale(1.15); } }
.top-actions { display: flex; gap: 8px; }
.round-button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 2px solid var(--ink); border-radius: 12px; background: white; box-shadow: 0 3px 0 var(--ink); }
.round-button:hover:not(:disabled) { background: #eef8ff; }
.round-button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

.level-hud { --level-accent: var(--gold-deep); flex: none; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 18px; padding: 8px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); border-bottom: 2px solid var(--ink); background: var(--paper); }
.level-hud[data-weather="rainy"] { --level-accent: #557da8; }
.level-hud[data-weather="snowy"] { --level-accent: #5987ac; }
.level-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 12px; }
.level-head strong { color: var(--level-accent); }
.level-head span { flex: none; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.level-progress { height: 10px; overflow: hidden; border: 1.5px solid var(--ink); border-radius: 99px; background: #e6eef4; }
.level-progress span { display: block; width: 100%; height: 100%; background: var(--level-accent); transform: scaleX(0); transform-origin: left; }
.level-steps { grid-column: 2; grid-row: 1 / span 2; align-self: center; display: flex; gap: 6px; margin: 0; padding: 0; list-style: none; counter-reset: level; }
.level-steps li { display: flex; align-items: center; gap: 5px; padding: 4px 8px; border: 1.5px solid #d5e2ea; border-radius: 10px; color: var(--muted); font-size: 11px; counter-increment: level; }
.level-steps li::before { content: counter(level); display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: #e6eef4; font-size: 10px; }
.level-steps li.current { border-color: var(--level-accent); color: var(--level-accent); background: white; }
.level-steps li.current::before { background: var(--level-accent); color: white; }
.level-steps li.completed { border-color: var(--green); color: var(--green); background: #edf9f2; }
.level-steps li.completed::before { background: var(--green); color: white; }

.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#sky { display: block; width: 100%; height: 100%; }

.overlay { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; padding: 18px; overflow-y: auto; background: rgba(35, 64, 90, .28); backdrop-filter: blur(2px); }
.panel { width: min(100%, 460px); padding: 24px; border: 2px solid var(--ink); border-radius: 26px; background: var(--paper); box-shadow: 0 6px 0 var(--ink), 0 22px 50px rgba(20, 50, 80, .25); animation: pop .28s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop { from { transform: scale(.88); opacity: 0; } }
.eyebrow { color: #b98546; font-size: 10px; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; }
.start-panel, .over-panel { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 24px; width: min(100%, 820px); }
.start-main h1 { margin: 4px 0 6px; font-size: clamp(38px, 6vw, 54px); letter-spacing: -.02em; }
.lead { color: var(--muted); font-size: 13.5px; }
.lead strong { color: var(--ink); }
#start-form { display: grid; gap: 14px; margin-top: 16px; }
.characters { margin: 0; padding: 0; border: 0; min-width: 0; }
.characters legend, .name-field { margin-bottom: 7px; padding: 0; font-size: 12px; font-weight: 900; }
.character-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.character { position: relative; display: grid; justify-items: center; gap: 2px; padding: 8px 4px 6px; border: 2px solid #d5e2ea; border-radius: 16px; background: white; cursor: pointer; transition: border-color .15s, transform .15s, background .15s; }
.character input { position: absolute; opacity: 0; pointer-events: none; }
.character img { width: 100%; height: 58px; object-fit: contain; transition: transform .2s; }
.character span { font-size: 11px; font-weight: 800; white-space: nowrap; }
.character:hover { border-color: #9fcdec; transform: translateY(-2px); }
.character:has(input:checked) { border-color: var(--sky-deep); background: #e7f5ff; box-shadow: 0 3px 0 var(--sky-deep); }
.character:has(input:checked) img { transform: scale(1.08) rotate(-4deg); }
.character:has(input:focus-visible) { outline: 3px solid #ec9b40; outline-offset: 2px; }
.name-field { display: grid; gap: 6px; }
.name-field small { color: var(--muted); font-weight: 700; }
.name-field input { height: 44px; padding: 0 14px; border: 2px solid #d5e2ea; border-radius: 12px; background: white; font-weight: 800; }
.name-field input:focus { border-color: var(--sky-deep); outline: none; }
.primary-button, .ghost-button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 46px; padding: 10px 18px; border: 2px solid var(--ink); border-radius: 14px; font-weight: 900; transition: transform .12s, box-shadow .12s; }
.primary-button { background: var(--gold); box-shadow: 0 4px 0 var(--ink); }
.primary-button:hover { background: #ffd56e; }
.primary-button:active, .ghost-button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.primary-button.big { min-height: 54px; font: 800 20px var(--display); }
.ghost-button { background: white; box-shadow: 0 4px 0 #c6d6e0; border-color: #c6d6e0; }
.rules { display: grid; gap: 5px; margin: 16px 0 0; padding: 14px 0 0; border-top: 1.5px dashed #d5e2ea; list-style: none; color: var(--muted); font-size: 12px; }
.rule-star, .rule-q, .rule-heart { display: inline-grid; place-items: center; width: 20px; height: 20px; margin-right: 4px; border-radius: 6px; font-weight: 900; }
.rule-star { color: var(--gold-deep); }
.rule-q { background: #7c5ce0; color: white; }
.rule-heart { color: var(--red); }

.board-card { align-self: start; padding: 16px; border: 2px solid #d5e2ea; border-radius: 20px; background: white; }
.board-card h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 19px; }
.board-card h2 .icon { color: var(--gold-deep); }
.board { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; counter-reset: rank; }
.board li { display: grid; grid-template-columns: 24px 28px minmax(0, 1fr) auto; align-items: center; gap: 7px; min-height: 36px; padding: 3px 8px; border-radius: 11px; background: #f4f9fc; counter-increment: rank; font-size: 12.5px; }
.board li::before { content: counter(rank); color: var(--muted); font: 800 14px var(--display); text-align: center; }
.board li:nth-child(1)::before { color: #d79a10; }
.board li:nth-child(2)::before { color: #8a9aa6; }
.board li:nth-child(3)::before { color: #b8733c; }
.board li img { width: 28px; height: 28px; object-fit: contain; }
.board li .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li strong { font: 800 15px var(--display); font-variant-numeric: tabular-nums; }
.board li.mine { background: #fff1c7; box-shadow: inset 0 0 0 2px var(--gold); animation: bump .5s ease 2; }
.board .empty { display: block; padding: 14px 8px; background: none; color: var(--muted); text-align: center; }
.board .empty::before { content: none; }
.board-note { margin-top: 8px; color: #93a4b0; font-size: 10.5px; text-align: center; }

.question-panel { width: min(100%, 560px); }
.question-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topic { padding: 3px 11px; border-radius: 9px; background: #efe9ff; color: #6142c9; font-size: 11px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; }
.question-timer { display: flex; align-items: baseline; gap: 4px; color: var(--muted); font-size: 12px; }
.question-timer strong { color: var(--ink); font: 800 30px/1 var(--display); font-variant-numeric: tabular-nums; }
.question-timer.urgent strong { color: var(--red); animation: bump .5s ease infinite; }
.timer-track { height: 10px; margin: 12px 0 16px; overflow: hidden; border: 2px solid var(--ink); border-radius: 99px; background: #eef3f6; }
.timer-track span { display: block; height: 100%; width: 100%; border-radius: inherit; background: linear-gradient(90deg, #4fc28b, #ffc94a); transform-origin: left; }
.timer-track.urgent span { background: var(--red); }
#question-text { font-size: clamp(20px, 3.4vw, 26px); }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.answer { display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 10px 12px; border: 2px solid var(--ink); border-radius: 15px; background: white; box-shadow: 0 4px 0 var(--ink); font-size: 15px; font-weight: 800; text-align: left; transition: transform .12s, background .15s; }
.answer kbd { flex: none; }
.answer:hover:not(:disabled) { background: #eef8ff; transform: translateY(-2px); }
.answer:disabled { opacity: 1; cursor: default; }
.answer.correct { background: #d6f5e3; border-color: var(--green); box-shadow: 0 4px 0 var(--green); }
.answer.wrong { background: #ffe1dd; border-color: var(--red); box-shadow: 0 4px 0 var(--red); animation: shake .35s; }
.answer.dim { opacity: .45; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.question-feedback { min-height: 24px; margin-top: 14px; font-weight: 900; text-align: center; }
.question-feedback.good { color: var(--green); }
.question-feedback.bad { color: var(--red); }

.small-panel { width: min(100%, 360px); text-align: center; }
.small-panel h2 { margin: 4px 0 16px; font-size: 34px; }
.panel-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 4px; }
.over-main { text-align: center; }
.over-avatar { width: 92px; height: 92px; object-fit: contain; animation: float 2.4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(3deg); } }
.over-main h2 { margin: 2px 0; font-size: 34px; }
.result-message { margin: 8px 0 12px; color: var(--muted); font-size: 13px; }
.victory .over-panel { border-color: var(--gold-deep); }
.victory .over-main h2 { color: var(--green); }
.final-score { color: var(--muted); }
.final-score strong { color: var(--sky-deep); font: 800 56px/1 var(--display); }
.breakdown { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 10px; }
.breakdown div { padding: 8px 4px; border-radius: 13px; background: #eef7fd; }
.breakdown dt { color: var(--muted); font-size: 10.5px; }
.breakdown dd { margin: 0; font: 800 20px var(--display); }
.rank-note { min-height: 22px; margin-bottom: 12px; color: #b97510; font-weight: 900; }

.toast { position: absolute; top: 16px; left: 50%; z-index: 3; width: max-content; max-width: calc(100% - 32px); padding: 10px 18px; border: 2px solid var(--ink); border-radius: 14px; background: white; box-shadow: 0 4px 0 var(--ink); font-weight: 900; text-align: center; transform: translateX(-50%); animation: toast-in .25s ease; }
.toast.bad { background: #ffe1dd; }
.toast.good { background: #d6f5e3; }
@keyframes toast-in { from { transform: translate(-50%, -12px); opacity: 0; } }

.touch-pad { position: absolute; inset: auto 0 0; z-index: 2; display: none; justify-content: space-between; align-items: end; padding: 0 max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); pointer-events: none; }
.touch-move { display: flex; gap: 12px; }
.touch-button { display: grid; place-items: center; width: 72px; height: 72px; padding: 0; border: 2px solid rgba(35, 64, 90, .7); border-radius: 22px; background: rgba(255, 255, 255, .72); box-shadow: 0 4px 0 rgba(35, 64, 90, .6); pointer-events: auto; touch-action: none; }
.touch-button .icon { width: 32px; height: 32px; }
.touch-button.jump { width: 92px; height: 92px; border-radius: 50%; background: rgba(255, 201, 74, .88); }
.touch-button.jump span { margin-top: -10px; font-size: 11px; font-weight: 900; }
.touch-button.active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(35, 64, 90, .6); background: white; }
.playing .touch-pad { display: flex; }
@media (hover: hover) and (pointer: fine) { .playing .touch-pad { display: none; } }

@media (max-width: 760px) {
  .start-panel, .over-panel { grid-template-columns: 1fr; }
  .topbar { gap: 8px; min-height: 56px; padding-top: 6px; padding-bottom: 6px; }
  .brand small { display: none; }
  .brand strong { font-size: 19px; }
  .brand img { width: 32px; height: 32px; }
  .hud { gap: 5px; }
  .hud-pill { height: 34px; padding: 0 8px; }
  .hud-pill.score span { display: none; }
  .hud-pill strong { font-size: 17px; }
  .hud-pill.lives .icon { width: 16px; height: 16px; }
  .round-button { width: 34px; height: 34px; }
  .top-actions { gap: 5px; }
  .panel { padding: 18px; border-radius: 22px; }
  .overlay { place-items: start center; }
  .character img { height: 46px; }
  .character span { font-size: 10px; }
  .answers { grid-template-columns: 1fr; }
  .answer { min-height: 48px; }
}
@media (max-width: 420px) {
  .brand span { display: none; }
  .character-grid { gap: 5px; }
  .character span { display: none; }
}
@media (max-width: 600px) {
  .level-hud { grid-template-columns: 1fr; gap: 5px; padding: 7px 12px; }
  .level-steps { grid-column: 1; grid-row: auto; justify-content: center; }
}
@media (max-height: 500px) {
  .topbar { min-height: 48px; padding-top: 4px; padding-bottom: 4px; }
  .brand small { display: none; }
  .hud-pill, .round-button { height: 32px; }
  .round-button { width: 32px; }
  .touch-button { width: 58px; height: 58px; border-radius: 18px; opacity: .85; }
  .touch-button.jump { width: 74px; height: 74px; }
  .touch-button .icon { width: 26px; height: 26px; }
  .overlay { place-items: start center; }
  .level-hud { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding-top: 5px; padding-bottom: 5px; }
  .level-steps { grid-column: 2; grid-row: 1 / span 2; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
