:root {
  --ink: #14291c;
  --muted: #4b5f52;
  --card: #ffffff;
  --brand: #15803d;
  --brand-2: #0e7490;
  --sel: #f0fdf4;
  --sel-border: #16a34a;
  --play: #16a34a;
  --play-dark: #166534;
  --good: #16a34a;
  --bad: #dc2626;
  --hl: #fde047;
  --bg-1: #fde047;
  --bg-2: #4ade80;
  --bg-3: #22d3ee;
  --radius: 22px;
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, sans-serif;
  --emoji: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: var(--font); color: var(--ink);
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3)) fixed;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
kbd { font: inherit; }

.screen { display: none; }
.screen.active { display: block; }

/* ---------- Home & results ---------- */
#home, #results {
  min-height: 100dvh;
  padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
}
.inner { max-width: 820px; margin: 0 auto; display: grid; gap: 16px; }
.back { color: #14532d; font-weight: 600; text-decoration: none; justify-self: start; padding: 11px 2px; }

.brand { text-align: center; color: #14532d; }
.brand .logo { font-size: clamp(40px, 10vw, 64px); line-height: 1.1; font-family: var(--emoji); }
.brand h1 { margin: 2px 0 0; font-size: clamp(34px, 8vw, 56px); color: #fff; text-shadow: 0 3px 0 #15803d, 0 6px 14px rgba(20, 83, 45, .35); }
.brand p { margin: 4px 0 0; font-size: clamp(16px, 4vw, 20px); font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 10px 30px rgba(20, 60, 30, .18); }
.card h2 { margin: 0 0 12px; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 16px; flex: none; }

.years { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 640px) { .years { grid-template-columns: repeat(6, 1fr); } }
.year {
  border: 3px solid #e5e7eb; background: #f8fafc; border-radius: 18px; min-height: 76px;
  display: grid; place-content: center; gap: 0; padding: 6px;
}
.year b { font-size: 28px; line-height: 1; }
.year small { color: var(--muted); font-size: 13px; order: -1; }
.year[aria-checked="true"] { border-color: var(--sel-border); background: var(--sel); box-shadow: 0 0 0 3px rgba(22, 163, 74, .2); }

.dskp { margin-top: 12px; background: #f8fafc; border-radius: 14px; padding: 10px 12px; }
.dskp summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.dskp ul { margin: 10px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.dskp li { display: grid; grid-template-columns: auto 1fr; gap: 8px; font-size: 14px; line-height: 1.35; }
.dskp .code { font-weight: 700; color: var(--brand); white-space: nowrap; }
.dskp li small { color: var(--muted); }
.dskp .note { margin: 10px 0 0; font-size: 12px; color: var(--muted); line-height: 1.4; }

.option { display: grid; gap: 6px; margin-bottom: 12px; }
.option-label { font-weight: 600; color: var(--muted); font-size: 14px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; min-height: 44px; padding: 8px 12px; border-radius: 14px; border: 2px solid #e5e7eb; background: #f8fafc; font-weight: 500; font-size: 15px; }
.seg button[aria-pressed="true"] { border-color: var(--sel-border); background: var(--sel); font-weight: 600; }
.level-seg button { min-height: 56px; font-size: 17px; }
.level-note { margin: 8px 0 0; font-size: 14px; color: var(--muted); line-height: 1.35; }
.tip { margin: 8px 0 0; font-size: 14px; color: var(--muted); line-height: 1.4; }

.songs { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 560px) { .songs { grid-template-columns: 1fr 1fr; } }
.song-btn {
  display: flex; align-items: center; gap: 10px; text-align: left; min-height: 60px;
  border: 3px solid #e5e7eb; background: #f8fafc; border-radius: 18px; padding: 8px 12px;
}
.song-btn .se { font-size: 30px; font-family: var(--emoji); line-height: 1; }
.song-btn .st { display: grid; }
.song-btn b { font-size: 17px; line-height: 1.2; }
.song-btn small { color: var(--muted); font-size: 13px; }
.song-btn[aria-checked="true"] { border-color: var(--sel-border); background: var(--sel); box-shadow: 0 0 0 3px rgba(22, 163, 74, .2); }

.legend { margin-top: 4px; }
.legend-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; justify-content: center; }
.legend-item { display: grid; justify-items: center; width: 74px; padding: 4px; border-radius: 12px; background: var(--sel); color: var(--brand); }
.legend-item .fig { width: 54px; height: 54px; }
.legend-item small { font-size: 12px; line-height: 1.15; text-align: center; color: var(--ink); }

.btn { border: 0; border-radius: 999px; min-height: 52px; padding: 10px 26px; font-weight: 700; font-size: 20px; transition: transform .1s; }
.btn:active { transform: translateY(2px); }
.btn-play { background: var(--play); color: #fff; box-shadow: 0 5px 0 var(--play-dark); }
.btn-ghost { background: #fff; color: var(--brand); box-shadow: 0 5px 0 #bbf7d0; }
.btn-small { border: 2px solid #e2e8f0; background: #fff; border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 15px; min-height: 44px; }
#playBtn { font-size: 28px; min-height: 68px; justify-self: center; width: min(100%, 360px); }
.privacy { margin: 0; text-align: center; color: #14532d; font-size: 14px; line-height: 1.4; font-weight: 500; }
.install { display: grid; justify-items: center; gap: 6px; color: #14532d; font-size: 14px; text-align: center; }
.install p { margin: 0; }

/* ---------- Game ---------- */
#game.active { position: fixed; inset: 0; overflow: hidden; display: block; user-select: none; -webkit-user-select: none; }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); opacity: 0; transition: opacity .3s; }
#game.camera #cam { opacity: 1; }
#game.camera::before { content: ''; position: absolute; inset: 0; background: rgba(10, 30, 15, .25); pointer-events: none; }
#bones { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#game:not(.camera) #bones { display: none; }

.layout {
  position: relative; z-index: 1; height: 100%;
  display: flex; flex-direction: column; gap: 10px;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) calc(12px + var(--safe-l));
}
.hud { display: flex; gap: 8px; align-items: center; }
.pill { background: rgba(255,255,255,.94); border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: clamp(15px, 2.4vw, 22px); box-shadow: 0 4px 12px rgba(0,0,0,.15); white-space: nowrap; }
.hud-see { font-family: var(--font); }
.hud-year { margin-left: auto; background: var(--brand); color: #fff; }
.hud-pause { min-width: 48px; min-height: 44px; }

.song {
  width: min(100%, 940px); margin: 0 auto; flex: none;
  background: rgba(255,255,255,.95); border-radius: var(--radius); padding: 10px 16px 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.18); text-align: center;
}
.song-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; justify-content: center; }
.std { font-size: 12px; font-weight: 600; color: var(--brand); background: var(--sel); border-radius: 999px; padding: 2px 10px; }
.std:empty { display: none; }
.stitle { font-weight: 700; color: var(--brand-2); font-size: clamp(15px, 2.2vw, 20px); }
.rule { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 6px auto 0; padding: 4px 12px; border-radius: 14px; background: #fef9c3; font-weight: 600; font-size: clamp(14px, 2.2vw, 19px); width: fit-content; max-width: 100%; color: #713f12; }
.rule-fig .fig { width: 34px; height: 34px; color: var(--brand); display: block; }
.lyrics { margin-top: 4px; }
.lyric { margin: 0; line-height: 1.3; }
.lyric.dim { color: #94a3b8; font-size: clamp(14px, 2.2vw, 20px); min-height: 1.3em; }
.lyric.cur { font-size: clamp(22px, 4.2vw, 40px); font-weight: 700; margin: 4px 0; min-height: 1.3em; }
.lyric.cur.ask { color: var(--brand-2); }
.lyric .w { border-radius: 8px; padding: 0 2px; transition: background .12s, color .12s; color: #64748b; }
.lyric .w.past { color: var(--ink); }
.lyric .w.on { background: var(--hl); color: var(--ink); box-shadow: 0 0 0 3px var(--hl); }
.lyric .w.cue-word { text-decoration: underline 4px var(--brand); text-underline-offset: 5px; }
.status { font-weight: 600; color: var(--brand); font-size: clamp(15px, 2.2vw, 20px); min-height: 1.3em; }
.bar { height: 8px; border-radius: 999px; background: #e2e8f0; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #f59e0b, #22c55e); }

.cue-wrap { flex: 1 1 auto; min-height: 0; display: grid; place-items: center; }
.cue {
  display: grid; justify-items: center; gap: 2px; background: rgba(255,255,255,.95); color: var(--brand);
  border-radius: 28px; padding: 8px 22px 12px; box-shadow: 0 10px 30px rgba(0,0,0,.2); border: 5px solid var(--hl);
}
.cue.soft { opacity: .85; border-color: #e2e8f0; }
.cue.pop { animation: pop .35s ease-out; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.cue-fig .fig { width: clamp(90px, 22vh, 200px); height: clamp(90px, 22vh, 200px); display: block; }
.cue-text { font-weight: 700; font-size: clamp(20px, 3.4vw, 32px); color: var(--ink); }
#game.camera .cue-wrap { place-items: end center; }
#game.camera .cue { background: rgba(255,255,255,.85); }

.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; width: min(100%, 760px); }
.opt {
  position: relative; display: grid; justify-items: center; gap: 2px; padding: 8px 10px 12px;
  border: 4px solid #fff; border-radius: 22px; background: rgba(255,255,255,.95); box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.opt .fig { width: clamp(60px, 14vh, 120px); height: clamp(60px, 14vh, 120px); color: var(--brand); }
.opt-act { font-size: 14px; color: var(--muted); font-weight: 600; }
.opt b { font-size: clamp(19px, 3vw, 28px); line-height: 1.15; }
.opt.ok, .pad-btn.ok { border-color: var(--good); background: #dcfce7; }
.opt.no, .pad-btn.no { border-color: var(--bad); background: #fee2e2; }
kbd { position: absolute; top: 6px; right: 10px; font-size: 12px; color: #94a3b8; }
@media (hover: none) { kbd { display: none; } }

.pad { display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); gap: 8px; width: min(100%, calc(var(--cols, 4) * 170px)); margin: 0 auto; }
.pad-btn {
  position: relative; display: grid; justify-items: center; gap: 0; padding: 4px 4px 8px; min-height: 88px;
  border: 4px solid #fff; border-radius: 20px; background: rgba(255,255,255,.95); box-shadow: 0 6px 18px rgba(0,0,0,.18);
}
.pad-btn .fig { width: clamp(46px, 9vh, 80px); height: clamp(46px, 9vh, 80px); color: var(--brand); }
.pad-btn span { font-size: 13px; font-weight: 600; line-height: 1.1; }
.pad-btn.hint { border-color: var(--hl); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
#game.camera .pad, #game.asking .pad { display: none; }
#game.asking .cue { display: none; }

.feedback {
  position: absolute; z-index: 3; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.9);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  background: #fff; border-radius: 22px; padding: 12px 22px; text-align: center;
  font-size: clamp(20px, 3.4vw, 32px); font-weight: 700; box-shadow: 0 10px 40px rgba(0,0,0,.3);
  max-width: calc(100% - 32px); border: 5px solid var(--good);
}
.feedback small { display: block; font-size: .6em; font-weight: 500; color: var(--muted); margin-top: 4px; }
.feedback.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.feedback.bad { border-color: var(--bad); }

.overlay { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; padding: 16px; background: rgba(10, 30, 15, .45); overflow: auto; }
.overlay.clear { background: transparent; align-items: start; padding-top: calc(64px + var(--safe-t)); pointer-events: none; }
.overlay.clear .panel { pointer-events: auto; background: rgba(255,255,255,.9); padding: 12px 14px; }
.overlay.clear .ov-icon { font-size: 36px; }
.overlay.clear .panel h2 { font-size: 22px; margin: 2px 0 4px; }
.overlay.clear .panel p { font-size: 15px; margin-bottom: 8px; }
.overlay.clear .btn { min-height: 46px; font-size: 17px; padding: 8px 18px; }
.panel { background: #fff; border-radius: var(--radius); padding: 18px; width: min(100%, 520px); text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.ov-icon { font-size: 52px; line-height: 1.1; font-family: var(--emoji); }
.panel h2 { margin: 6px 0; font-size: 26px; }
.panel p { margin: 0 0 12px; color: var(--muted); font-size: 17px; line-height: 1.4; }
.panel .src { font-size: 13px; margin: 6px 0 10px; }
.intro-figs { margin-bottom: 4px; }
.warm-fig .fig { width: 130px; height: 130px; color: var(--brand); }
.calib-tip { font-weight: 700; color: var(--brand) !important; }
.buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.spinner { width: 44px; height: 44px; margin: 4px auto; border-radius: 50%; border: 5px solid #dcfce7; border-top-color: var(--brand); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Results ---------- */
.results { display: grid; gap: 10px; text-align: center; }
.results h2 { justify-content: center; font-size: 30px; margin: 0; }
.results h3 { margin: 10px 0 0; font-size: 18px; }
.stars { font-size: clamp(48px, 13vw, 72px); letter-spacing: 4px; }
.stars .off { filter: grayscale(1); opacity: .3; }
.res-score { margin: 0; font-size: 19px; font-weight: 600; }
.table-wrap { overflow-x: auto; }
.std-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; }
.std-table th, .std-table td { padding: 8px; border-bottom: 1px solid #e2e8f0; vertical-align: top; }
.std-table th { color: var(--muted); font-weight: 600; }
.std-table td:first-child { font-weight: 700; color: var(--brand); white-space: nowrap; }
.std-table td:last-child { font-weight: 700; white-space: nowrap; }
.std-table .skill { display: block; font-size: 12px; color: var(--muted); }
#copyBtn { justify-self: center; }
.review { text-align: left; margin: 0; padding-left: 24px; display: grid; gap: 8px; }
.review li { line-height: 1.35; }
.review .ok { color: var(--good); font-weight: 600; }
.review .no { color: var(--bad); font-weight: 600; }
.review small { color: var(--muted); }

@media (max-width: 520px) {
  .pad { gap: 6px; }
  .pad-btn { min-height: 76px; border-radius: 16px; }
  .pad-btn span { font-size: 11px; }
  .options { grid-template-columns: 1fr 1fr; }
  .hud .pill { padding: 6px 10px; }
}
@media (max-height: 560px) {
  .lyric.dim { display: none; }
  .cue-fig .fig { width: 70px; height: 70px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
