:root {
  --ink: #1d2318;
  --paper: #f7f3e8;
  --muted: #5d6452;
  --fat: #c98a2b;
  --syn: #c0392b;
  --panic: #6c4bc4;
  --ok: #2f7d4f;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2c3b22; font-family: var(--font); color: var(--ink); }
canvas { display: block; width: 100vw; height: 100vh; touch-action: none; }
[hidden] { display: none !important; }

#hud { position: fixed; top: 10px; left: 10px; right: 10px; display: flex; gap: 12px; align-items: flex-start; pointer-events: none; flex-wrap: wrap; }
.bars { display: grid; gap: 6px; width: min(260px, 60vw); }
.bar { position: relative; height: 22px; border-radius: 6px; background: rgba(20, 26, 16, 0.65); overflow: hidden; }
.bar span { position: absolute; left: 8px; top: 0; line-height: 22px; font-size: 12px; font-weight: 600; color: #fff; z-index: 2; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.bar i { position: absolute; inset: 0 auto 0 0; width: 0; transition: width 0.25s; }
.bar.fat i { background: var(--fat); }
.bar.syn i { background: var(--syn); }
.bar.panic i { background: var(--panic); }
.bar.trip i { background: var(--ok); }

#touch { position: fixed; left: 0; right: 0; bottom: 50px; display: flex; gap: 10px; padding: 0 12px; pointer-events: none; }
#touch button { pointer-events: auto; width: 64px; height: 64px; border-radius: 50%; border: 0; background: rgba(20, 26, 16, 0.55); color: #fff; font-size: 26px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; transition: background 0.15s; }
#touch button.sprint { background: rgba(232, 164, 0, 0.75); }
#touch .gap { flex: 1; }
#touch.ride button[data-key="ArrowDown"], #touch.ride button[data-key="ArrowUp"] { visibility: hidden; }
#touch.ride button[data-key="ArrowLeft"], #touch.ride button[data-key="ArrowRight"] { background: rgba(20, 26, 16, 0.72); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.55); }
#touch .act { position: absolute; right: 12px; bottom: 76px; display: flex; gap: 10px; opacity: 0; transform: translateY(8px) scale(0.9); transition: opacity 0.18s, transform 0.18s; pointer-events: none; }
#touch .act.on { opacity: 1; transform: none; }
#touch .act.on button { pointer-events: auto; }
#touch .act button { pointer-events: none; width: 58px; height: 58px; font-size: 24px; background: rgba(214, 51, 108, 0.78); }
#touch .act button[data-key="KeyX"] { background: rgba(163, 38, 31, 0.8); }
.bar em { position: absolute; top: 0; bottom: 0; left: 60%; width: 2px; background: #fff; opacity: 0.8; z-index: 1; }
.side { background: rgba(20, 26, 16, 0.65); color: #fff; border-radius: 6px; padding: 4px 10px; font-size: 13px; font-weight: 600; line-height: 1.5; }
#badges { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
#goals { display: flex; flex-wrap: wrap; gap: 4px; margin: 3px 0 2px; }
.goal { display: inline-flex; align-items: center; gap: 4px; padding: 0 7px 0 5px; border-radius: 10px; background: rgba(255, 255, 255, 0.1); font-size: 12px; line-height: 20px; transition: background-color 0.9s, color 0.9s, box-shadow 0.9s; }
.goal i { font-style: normal; }
.goal b { font-weight: 600; opacity: 0.85; }
.goal em { font-style: normal; font-weight: 700; font-variant-numeric: tabular-nums; }
.goal em:empty { display: none; }
.goal.done { color: #c6f2d4; }
.goal.next { box-shadow: inset 0 0 0 1.5px rgba(240, 192, 48, 0.9); }
.goal.just { background: rgba(47, 125, 79, 0.95); transition: none; }
#hud .right { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#hud.ride .right { margin-right: 46px; }
#tray { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 6px; max-width: 360px; padding: 5px 6px; border-radius: 8px; background: rgba(20, 26, 16, 0.65); color: #fff; font: 700 14px/26px var(--font); }
#tray .chip { display: inline-flex; align-items: center; gap: 5px; padding: 0 10px 0 7px; border-radius: 13px; background: rgba(255, 255, 255, 0.12); white-space: nowrap; transition: background-color 1s, box-shadow 1s; }
#tray .chip i { font-style: normal; font-size: 18px; line-height: 1; }
#tray .chip b { font-weight: 700; font-variant-numeric: tabular-nums; }
#tray .chip.up { background: rgba(240, 192, 48, 0.35); box-shadow: inset 0 0 0 1.5px rgba(240, 192, 48, 0.7); transition: none; }
.badge { background: #c0392b; color: #fff; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; padding: 3px 8px; border-radius: 4px; text-transform: uppercase; }
.badge.calm { background: #2f7d4f; }
.badge.dark { background: #333; }
.badge.love { background: #d6336c; }

#ticker { position: fixed; left: 0; right: 0; bottom: 0; display: flex; align-items: stretch; min-height: 36px; background: linear-gradient(180deg, #17345c, #0b1b34); border-top: 2px solid #c0392b; color: #fff; font: 600 15px/1.3 var(--font); pointer-events: none; transition: background-color 0.3s; }
.tv-label { flex: none; display: flex; font-size: 13px; line-height: 1; }
.tv-bug { display: flex; background: #f4f1ea; color: #0b1b34; font-weight: 900; letter-spacing: 0.03em; }
.tv-bug b, .tv-bug i { display: flex; align-items: center; }
.tv-bug b { padding: 0 7px 0 10px; }
.tv-bug i { font-style: normal; padding: 0 7px; background: #c0392b; color: #fff; }
.tv-flag { display: flex; align-items: center; gap: 6px; padding: 0 17px 0 10px; background: #8f2318; font-size: 11px; font-weight: 800; letter-spacing: 0.1em; clip-path: polygon(0 0, 100% 0, calc(100% - 9px) 100%, 0 100%); transition: background-color 0.3s, color 0.3s; }
.tv-flag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; transition: background-color 0.3s; }
.tv-body { flex: 1; min-width: 0; display: flex; align-items: center; padding: 5px 14px; }
.tv-body p { display: flex; gap: 8px; margin: 0; animation: tvIn 0.25s ease-out; }
.tv-body i { flex: none; font-style: normal; }
#ticker.hot { background: linear-gradient(180deg, #9a1f15, #6c140d); }
#ticker.hot .tv-flag { background: #ffd166; color: #3a1300; }
#ticker.hot .tv-flag::before { background: #c0392b; }
@keyframes tvIn { from { opacity: 0; transform: translateY(4px); } }
@media (max-height: 500px) {
  #ticker { min-height: 28px; font-size: 12px; line-height: 1.2; }
  .tv-label { font-size: 10.5px; }
  .tv-flag { font-size: 9px; padding: 0 14px 0 7px; }
  .tv-body { padding: 3px 10px; }
  #touch { bottom: 40px; }
}

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(16, 22, 12, 0.72); overflow-y: auto; }
.card { background: var(--paper); border-radius: 14px; max-width: 560px; width: 100%; padding: 24px 22px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4); margin: auto; }
.card.loading { max-width: 260px; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 26px 22px 22px; }
.card .loader { display: flex; gap: 10px; font-size: 26px; }
.card .loader .paw { opacity: 0.15; animation: pawStep 1.2s ease-in-out infinite; }
.card .loader .paw:nth-child(2) { animation-delay: 0.2s; }
.card .loader .paw:nth-child(3) { animation-delay: 0.4s; }
.card .loader-title { font-size: 20px; letter-spacing: -0.01em; color: var(--ink); }
@keyframes pawStep { 0%, 100% { opacity: 0.15; transform: translateY(2px); } 30% { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .card .loader .paw { animation: none; opacity: 0.7; } }
.card h1 { margin: 0 0 4px; font-size: 34px; letter-spacing: -0.01em; }
.card h2 { margin: 0 0 8px; font-size: 24px; }
.card .sub { margin: 0 0 16px; color: var(--muted); }
.card p { margin: 0 0 12px; line-height: 1.55; }
.card kbd { font: 12px ui-monospace, Menlo, monospace; background: #e7e0cc; border-radius: 4px; padding: 1px 6px; }
.card .goals { font-weight: 700; font-size: 14px; color: var(--muted); margin: -4px 0 10px; }
.card .stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 0 0 16px; }
.card .stat { background: #ece5d2; border-radius: 8px; padding: 8px 10px; }
.card .stat b { display: block; font-size: 20px; }
.card .stat span { font-size: 12px; color: var(--muted); }
.card button { font: 600 17px var(--font); background: var(--ok); color: #fff; border: 0; border-radius: 10px; padding: 12px 22px; cursor: pointer; }
.card button:hover { filter: brightness(1.08); }
.card button.ghost { background: #e7e0cc; color: var(--ink); }
.card button.mute { min-width: 52px; padding: 12px 14px; line-height: 1.2; }
.card .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.card.start { max-width: 860px; padding: 20px 24px 16px; }
.card.pause { max-width: 400px; }
.card .head { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 14px; margin: 0 0 6px; }
.card .head h1 { margin: 0; }
.card .head .sub { margin: 0; }
.card .lang { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 15px; }
.card .lang select { font: 600 14px var(--font); color: var(--ink); background: #e7e0cc; border: 0; border-radius: 8px; padding: 6px 8px; cursor: pointer; }
#corner { position: fixed; top: 12px; right: 12px; display: flex; gap: 8px; align-items: flex-start; z-index: 5; }
#corner .round { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: rgba(247, 243, 232, 0.9); color: var(--ink); font-size: 20px; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); text-decoration: none; }
#corner .round:hover, #corner .round[aria-expanded="true"] { background: #fff; }
#corner .menu { position: absolute; top: 48px; right: 0; display: flex; flex-direction: column; gap: 2px; min-width: 180px; padding: 6px; background: #fff; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); }
#corner .menu[hidden] { display: none; }
#corner .menu button, #corner .menu a { font: 600 14px var(--font); text-align: left; padding: 8px 12px; border: 0; border-radius: 7px; background: transparent; color: var(--ink); cursor: pointer; text-decoration: none; }
#corner .menu button:hover, #corner .menu a:hover { background: #ece5d2; }
#corner .menu button.on { background: var(--ok); color: #fff; }
#corner .menu a { border-top: 1px solid #ece5d2; border-radius: 0 0 7px 7px; margin-top: 4px; color: var(--muted); }
@media (max-width: 980px) { .screen.with-corner { padding-top: 64px; } }
.card .lead { margin: 0 0 4px; }
.card h3.pick { margin: 12px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.card .levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; margin: 0 0 14px; }
.card button.level { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; padding: 12px 14px; border-radius: 12px; font-weight: 400; font-size: 15px; color: #fff; background: linear-gradient(120deg, #2f7d4f, #4f8a45); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18); }
.card button.level.winter { background: linear-gradient(120deg, #2f5f8f, #6f9fc8); }
.card button.level:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18); }
.card button.level .num { flex: none; width: 38px; height: 38px; border-radius: 50%; background: rgba(255, 255, 255, 0.22); display: grid; place-items: center; font-size: 20px; font-weight: 800; }
.card button.level .body { display: block; line-height: 1.35; }
.card button.level b { font-size: 18px; margin-right: 8px; }
.card button.level small { display: block; font-size: 13px; opacity: 0.92; margin-top: 2px; }
.card .tag { display: inline-block; vertical-align: 2px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; background: #f0c030; color: #3a2a00; border-radius: 4px; padding: 1px 6px; }
.card .tag.done { background: rgba(255, 255, 255, 0.9); color: #2f7d4f; }
.card .howto { display: grid; gap: 8px; }
.card .stage { position: relative; height: clamp(170px, 32vh, 250px); border-radius: 12px; overflow: hidden; background: #b9d4e0; }
.card .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: auto; pointer-events: none; }
.card .stage .hud { position: absolute; left: 10px; top: 9px; right: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; pointer-events: none; }
.card .stage .cue { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 12px; padding: 16px 14px 9px;
  background: linear-gradient(rgba(20, 26, 16, 0), rgba(20, 26, 16, 0.5)); pointer-events: none; }
.card .stage .say { color: #fff; font: 700 16px/1.25 var(--font); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7); animation: cueIn 0.4s ease-out; }
.card .stage .say kbd { font: 700 13px/1 var(--font); padding: 2px 6px; background: rgba(247, 243, 232, 0.94); color: var(--ink); text-shadow: none; vertical-align: 1px; }
.card .stage .keys { flex: none; display: flex; gap: 5px; animation: cueIn 0.4s ease-out; }
@keyframes cueIn { from { opacity: 0; } }
.card .howto kbd { transition: background-color 0.1s, color 0.1s, transform 0.1s, box-shadow 0.1s; }
.card .howto kbd.on { background: #f0c030; color: #3a2a00; }
.card .stage .keys kbd { display: grid; place-items: center; min-width: 28px; height: 28px; padding: 0 7px; border-radius: 6px; font: 700 15px/1 var(--font);
  background: rgba(247, 243, 232, 0.95); color: var(--ink); box-shadow: 0 3px 0 rgba(29, 35, 24, 0.6); }
.card .stage .keys kbd[data-k="Space"] { min-width: 52px; }
.card .stage .keys kbd.on { background: #f0c030; color: #3a2a00; transform: translateY(3px); box-shadow: 0 0 0 3px rgba(255, 236, 160, 0.7); }
.card .stage .keys.pads kbd { min-width: 32px; height: 32px; padding: 0; border-radius: 50%; font-size: 15px; background: rgba(20, 26, 16, 0.62); color: #fff; box-shadow: none; }
.card .stage .keys.pads kbd.on { background: rgba(47, 125, 79, 0.95); transform: scale(1.1); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.8); }
.card .stage .keys.pads kbd.sprint { background: rgba(232, 164, 0, 0.95); }
.card .stage .mini { position: relative; width: 190px; max-width: 48%; height: 17px; border-radius: 5px; background: rgba(20, 26, 16, 0.62); overflow: hidden; }
.card .stage .mini i { position: absolute; inset: 0 auto 0 0; width: 0; transition: width 0.25s; }
.card .stage .mini b { position: relative; display: block; padding: 0 7px; font: 700 11px/17px var(--font); color: #fff; white-space: nowrap; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.card .stage .mini.fat i { background: var(--fat); }
.card .stage .mini.syn i { background: var(--syn); }
.card .stage .mini.panic i { background: var(--panic); }
.card .stage .goal { font: 700 13px/1 var(--font); color: #fff; background: rgba(20, 26, 16, 0.62); border-radius: 5px; padding: 4px 7px; }
.card .stage .goal.done { background: #d6336c; animation: pop 0.3s ease-out; }
.card .stage .flag { font: 800 11px/1 var(--font); letter-spacing: 0.04em; text-transform: uppercase; color: #fff; background: #c0392b; border-radius: 4px; padding: 4px 7px; animation: pop 0.3s ease-out; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
.card .chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.card button.chip { display: block; width: 100%; min-width: 0; padding: 6px 8px; border-radius: 8px; background: #ece5d2; color: var(--ink); font: 400 11.5px/1.3 var(--font); text-align: left; box-shadow: inset 0 0 0 1.5px transparent; transition: background-color 0.2s, box-shadow 0.2s; }
.card button.chip .t { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card button.chip .k { float: left; display: flex; gap: 2px; margin: 0 5px 0 0; }
.card button.chip .k:empty { display: none; }
.card button.chip kbd { display: inline-grid; place-items: center; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 3px; font: 700 9.5px/1 var(--font); background: #fff; color: var(--ink); box-shadow: 0 1px 0 rgba(29, 35, 24, 0.35); }
.card button.chip .t kbd { display: inline; padding: 0 3px; vertical-align: 0; }
.card button.chip .k kbd[data-k="Space"] { min-width: 24px; }
.card button.chip.on { background: #fff8e1; box-shadow: inset 0 0 0 2px #f0c030; }
.card button.chip kbd.on { background: #f0c030; color: #3a2a00; }
.card button.chip .k.pads kbd { min-width: 17px; height: 17px; padding: 0; border-radius: 50%; font-size: 9px; background: rgba(20, 26, 16, 0.6); color: #fff; box-shadow: none; }
.card button.chip .k.pads kbd.on { background: rgba(47, 125, 79, 0.95); }
@media (prefers-reduced-motion: reduce) {
  .card .howto * { animation: none !important; transition: none !important; }
}

@media (max-width: 720px) {
  .card .stage { height: clamp(150px, 46vw, 240px); }
  .card .chips { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: max-content; overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: 5px; scrollbar-width: thin; }
  .card button.chip { white-space: nowrap; padding: 6px 9px; }
  .card button.chip .t { display: inline; }
  .card button.chip .k { float: none; display: inline-flex; vertical-align: -2px; }
}

@media (max-width: 560px) {
  .bar { height: 18px; }
  .bar span { line-height: 18px; font-size: 11px; }
  .side { font-size: 12px; }
  .goal b { display: none; }
  .goal { font-size: 11px; line-height: 18px; padding: 0 6px 0 4px; }
  #tray { max-width: 190px; padding: 4px; gap: 3px; font-size: 13px; line-height: 22px; }
  #tray .chip { padding: 0 6px 0 4px; gap: 2px; border-radius: 11px; }
  #tray .chip i { font-size: 15px; }
  #hud.ride .right { margin-right: 0; }
  #ticker { min-height: 30px; font-size: 13px; line-height: 1.25; }
  .tv-label { position: absolute; left: 0; bottom: 100%; height: 19px; font-size: 11px; box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.25); }
  .tv-bug b { padding: 0 5px 0 7px; }
  .tv-bug i { padding: 0 5px; }
  .tv-flag { font-size: 9px; padding: 0 14px 0 7px; letter-spacing: 0.08em; }
  .tv-body { padding: 5px 10px; }
  .tv-body p { gap: 6px; }
  #touch { bottom: 92px; }
  .card { padding: 18px 16px; }
  .card h1 { font-size: 28px; }
  .card h2 { font-size: 22px; }
  .card p { line-height: 1.45; }
  .card .stats { grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0 0 12px; }
  .card .stat { padding: 6px 8px; }
  .card .stat b { font-size: 17px; }
  .card .stat span { font-size: 11px; }
  .card button { font-size: 16px; padding: 11px 18px; }
  .card .stage { height: 180px; }
  .card .howto { gap: 6px; }
  .card .chips { padding-bottom: 3px; }
  .card button.chip { padding: 5px 9px; }
  .card .stage .say { font-size: 13.5px; }
  .card .stage .cue { gap: 9px; padding: 14px 10px 7px; }
  .card .stage .keys kbd { min-width: 24px; height: 24px; font-size: 13px; padding: 0 5px; }
  .card .stage .keys kbd[data-k="Space"] { min-width: 42px; }
  .card .stage .keys.pads kbd { min-width: 28px; height: 28px; font-size: 13px; }
  .card .stage .mini { height: 15px; }
  .card .stage .mini b { font-size: 10px; line-height: 15px; }
  .card .stage .flag { font-size: 9.5px; }
  .card .head { align-items: center; }
  .card .head .sub { order: 3; flex-basis: 100%; font-size: 14px; }
  .card .lang { order: 2; }
  .card.start { padding: 16px 16px 14px; }
  .card .lead { font-size: 15px; line-height: 1.4; }
  .card h3.pick { margin: 10px 0 6px; }
  .card .levels { gap: 8px; margin: 0 0 10px; }
  .card button.level { padding: 10px 12px; }
  .card button.level small { font-size: 12.5px; }
}

@media (max-height: 720px) and (min-width: 561px) {
  .card { padding: 18px 22px; }
  .card p { margin: 0 0 10px; }
  .card .stats { margin: 0 0 12px; }
}
