:root {
  --bg: #f6f5ff;
  --surface: #ffffff;
  --surface-2: #eeedfb;
  --ink: #1b1938;
  --muted: #6b6a85;
  --line: #e2e0f2;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-soft: #e0e7ff;
  --on-accent: #ffffff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --bad: #e11d48;
  --bad-soft: #ffe4e6;
  --warn: #d97706;
  --star: #f59e0b;
  --staff-bg: #ffffff;
  --staff-line: #b9b6d3;
  --trail: #c7d2fe;
  --auto: #a3a1bd;
  --lh-ink: #9a3412;
  --key-white: #ffffff;
  --key-black: #1f1d36;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(27, 25, 56, .06), 0 6px 20px rgba(27, 25, 56, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121124;
    --surface: #1c1a33;
    --surface-2: #26244a;
    --ink: #eceaff;
    --muted: #a4a2c4;
    --line: #302e55;
    --accent: #818cf8;
    --accent-2: #a78bfa;
    --accent-soft: #2b2a5c;
    --on-accent: #12112a;
    --ok: #4ade80;
    --ok-soft: #173a26;
    --bad: #fb7185;
    --bad-soft: #4a1d2a;
    --staff-bg: #1a1830;
    --staff-line: #4a4775;
    --trail: #3a3a7a;
    --auto: #6f6c96;
    --lh-ink: #fdba74;
    --key-white: #e9e8f5;
    --key-black: #0c0b18;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: Nunito, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
a { color: inherit; }
h1, h2 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 800; }
h2 { font-size: 1.25rem; font-weight: 800; }
p { margin: 0 0 .8em; }
button, input, select { font: inherit; color: inherit; }
h1:focus { outline: none; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; text-decoration: none; }
#nav { display: flex; gap: 4px; overflow-x: auto; }
#nav a { text-decoration: none; padding: 8px 14px; border-radius: 999px; font-weight: 700; color: var(--muted); white-space: nowrap; }
#nav a.active { background: var(--accent-soft); color: var(--accent); }
body.playing .topbar { display: none; }

.page { max-width: 1040px; margin: 0 auto; padding: 24px 16px 80px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.lead { font-size: 1.08rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: .78rem; font-weight: 800; color: var(--accent); }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.gap { gap: 10px; }
.wrap { flex-wrap: wrap; }
section { margin-top: 28px; }
.section-title { font-size: 1.1rem; margin-bottom: 12px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; min-height: 44px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 800; cursor: pointer; text-decoration: none;
  transition: transform .08s ease, background .15s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.big { padding: 14px 28px; font-size: 1.1rem; min-height: 54px; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn.danger { color: var(--bad); }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; flex: none;
}
.icon-btn.small { width: 36px; height: 36px; }
.icon-btn:hover { background: var(--surface-2); }
.ic { display: inline-flex; width: 20px; height: 20px; flex: none; }
.ic svg { width: 100%; height: 100%; }

.stars { display: inline-flex; gap: 2px; }
.stars .ic { width: 18px; height: 18px; }
.stars .on svg { fill: var(--star); stroke: var(--star); }
.stars .off svg { stroke: var(--line); }
.result-card .stars .ic { width: 44px; height: 44px; }

.pbar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.pbar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; transition: width .2s; }

.hero { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 20px; }
.streak { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; background: #fff3e0; color: #c2410c; font-weight: 800; }
.streak .ic { width: 22px; height: 22px; }
.tile { display: flex; flex-direction: column; gap: 6px; text-decoration: none; transition: transform .12s; }
.tile:hover { transform: translateY(-2px); }
.tile h2 { margin: 0; }
.tile.accent { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border: none; }
.tile.accent .muted, .tile.accent .eyebrow { color: rgba(255, 255, 255, .85); }
.tile.accent .pbar { background: rgba(255, 255, 255, .25); }
.tile.accent .pbar-fill { background: #fff; }
.tile-ic { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.tile.accent .tile-ic { background: rgba(255, 255, 255, .2); color: #fff; }
.tile-ic .ic { width: 26px; height: 26px; }

.song-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.song-card { display: flex; gap: 12px; padding: 12px; text-decoration: none; align-items: center; transition: transform .12s; }
.song-card:hover { transform: translateY(-2px); }
.sc-body { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 2px; }
.sc-body b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-body .muted { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: .75rem; font-weight: 800; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.cover { width: 64px; height: 64px; border-radius: 14px; flex: none; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #6366f1, #a855f7); }
.cover .ic { width: 28px; height: 28px; }
.cover.big { width: 96px; height: 96px; border-radius: 20px; }
.cover.big .ic { width: 40px; height: 40px; }
.cover[data-hue="0"] { background: linear-gradient(135deg, #f43f5e, #fb923c); }
.cover[data-hue="1"] { background: linear-gradient(135deg, #f97316, #facc15); }
.cover[data-hue="2"] { background: linear-gradient(135deg, #84cc16, #22c55e); }
.cover[data-hue="3"] { background: linear-gradient(135deg, #10b981, #06b6d4); }
.cover[data-hue="4"] { background: linear-gradient(135deg, #0ea5e9, #6366f1); }
.cover[data-hue="5"] { background: linear-gradient(135deg, #6366f1, #a855f7); }
.cover[data-hue="6"] { background: linear-gradient(135deg, #a855f7, #ec4899); }
.cover[data-hue="7"] { background: linear-gradient(135deg, #ec4899, #f43f5e); }
.cover[data-hue="8"] { background: linear-gradient(135deg, #14b8a6, #3b82f6); }
.cover[data-hue="9"] { background: linear-gradient(135deg, #8b5cf6, #3b82f6); }
.cover[data-hue="10"] { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.cover[data-hue="11"] { background: linear-gradient(135deg, #22c55e, #0ea5e9); }

.list { display: flex; flex-direction: column; gap: 8px; }
.row-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 56px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; text-decoration: none;
  text-align: left; cursor: pointer; width: 100%;
}
button.row-item:hover, a.row-item:hover { background: var(--surface-2); }
.row-item.loading { opacity: .6; cursor: progress; }
.ri-link { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; text-decoration: none; }
.ri-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.ri-title { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.more { align-self: center; }
.help-card { margin-top: 8px; }

.searchbar { display: flex; align-items: center; gap: 10px; padding: 4px 16px; background: var(--surface); border: 2px solid var(--line); border-radius: 999px; margin-bottom: 14px; }
.searchbar:focus-within { border-color: var(--accent); }
.searchbar input { flex: 1; border: none; background: transparent; padding: 12px 0; font-size: 1.05rem; outline: none; min-width: 0; }

.chapter { margin-top: 28px; }
.chapter-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.chapter-head h2 { margin: 0; }
.path { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.lesson-node { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; box-shadow: var(--shadow); }
a.lesson-node:hover { border-color: var(--accent); }
.lesson-node.locked { opacity: .55; box-shadow: none; }
.ln-num { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--accent); color: var(--on-accent); flex: none; }
.lesson-node.done .ln-num { background: var(--ok); }
.lesson-node.locked .ln-num { background: var(--surface-2); color: var(--muted); }
.ln-body { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ln-body .muted { font-size: .85rem; }

.lesson-top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.steps-dots { display: flex; gap: 6px; margin-left: auto; }
.steps-dots .d { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.steps-dots .d.done { background: var(--ok); }
.steps-dots .d.on { background: var(--accent); width: 24px; border-radius: 99px; }
.info-card { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.mini-kbd { height: 150px; }
.center { text-align: center; align-items: center; display: flex; flex-direction: column; gap: 10px; max-width: 480px; margin: 40px auto; }

.setup-head { display: flex; gap: 18px; align-items: center; margin-bottom: 18px; }
.setup-head h1 { margin: 0 0 4px; }
.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 14px; }
.level { text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px; border-width: 2px; }
.level b { font-size: 1.15rem; }
.level.on { border-color: var(--accent); background: var(--accent-soft); }
.setup-opts { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; flex-wrap: wrap; }
.opt-row > span:first-child { font-weight: 700; }
.opt-row select { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); max-width: 100%; }
.opt-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
input[type="range"] { accent-color: var(--accent); width: 180px; max-width: 100%; }
.range-wrap { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.range-wrap output { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 7ch; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button { border: none; background: transparent; padding: 7px 14px; border-radius: 999px; font-weight: 800; cursor: pointer; color: var(--muted); min-height: 36px; }
.seg button.on { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

.radio-card { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; border-width: 2px; }
.radio-card.on { border-color: var(--accent); background: var(--accent-soft); }
.radio-card input { margin-top: 4px; accent-color: var(--accent); width: 18px; height: 18px; }
.radio-card span { display: flex; flex-direction: column; gap: 4px; }
.mic-test { margin-top: 14px; text-align: center; }
.meter { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--ok); transition: width .08s; }
.big-num { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 700; transition: all .2s; z-index: 100; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); color: #fff; }

.player-host { height: 100dvh; }
.player { position: relative; height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
.player-top { display: flex; align-items: center; gap: 8px; padding: 8px max(12px, env(safe-area-inset-left)); }
.player-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pt-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .95rem; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: .85rem; cursor: pointer; max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 36px; }
.chip.warn { color: var(--warn); border-color: var(--warn); }
.chip .ic { width: 16px; height: 16px; }
.opts-panel { margin: 0 12px 8px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 4px 20px; }
.opts-panel[hidden] { display: none; }
.staff-wrap { position: relative; flex: 1; min-height: 140px; margin: 0 12px; border-radius: 18px; overflow: hidden; border: 1px solid var(--line); }
canvas.staff { width: 100%; height: 100%; display: block; }
.feedback { position: absolute; top: 12px; left: 50%; transform: translateX(-50%) scale(.9); opacity: 0; padding: 6px 16px; border-radius: 99px; font-weight: 800; transition: all .15s; pointer-events: none; white-space: nowrap; max-width: 90%; overflow: hidden; text-overflow: ellipsis; }
.feedback.show { opacity: 1; transform: translateX(-50%) scale(1); }
.feedback.good { background: var(--ok-soft); color: var(--ok); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.player-mid { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 36px; padding: 2px 12px; }
.player-mid .meter { width: 120px; }
.hint { font-weight: 800; color: var(--accent); }
.player .kbd { height: clamp(110px, 26vh, 220px); margin: 0 max(6px, env(safe-area-inset-left)) max(6px, env(safe-area-inset-bottom)); }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(4px); padding: 16px; z-index: 5; }
.overlay[hidden] { display: none; }
.start-card, .result-card { max-width: 460px; width: 100%; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px; }
.tip { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; font-size: .92rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; margin: 6px 0 10px; }
.stats div { display: flex; flex-direction: column; background: var(--surface-2); border-radius: 12px; padding: 8px; }
.stats b { font-size: 1.2rem; }
.stats span { font-size: .78rem; color: var(--muted); }

.kbd { position: relative; user-select: none; -webkit-user-select: none; touch-action: none; border-radius: 10px; overflow: hidden; background: var(--key-black); padding-top: 4px; }
.key { position: absolute; top: 4px; bottom: 0; cursor: pointer; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; transition: background .08s; }
.key.white { background: var(--key-white); border-right: 1px solid #c9c7dc; border-radius: 0 0 6px 6px; z-index: 1; }
.key.black { background: var(--key-black); height: 62%; bottom: auto; z-index: 2; border-radius: 0 0 5px 5px; box-shadow: inset 0 -4px 0 rgba(255, 255, 255, .12); }
.key.white.down, .key.white.press { background: #dcdaf0; }
.key.black.down, .key.black.press { background: #3c3a60; }
.key.target { background: var(--accent) !important; }
.key.white.target { box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .15); }
.key.soft.white { background: color-mix(in srgb, var(--accent) 18%, var(--key-white)); }
.key.soft.black { background: color-mix(in srgb, var(--accent) 45%, var(--key-black)); }
.key.ok { background: var(--ok) !important; }
.key.bad { background: var(--bad) !important; }
.key.auto.white { background: color-mix(in srgb, var(--auto) 45%, var(--key-white)); }
.klabel { font-size: clamp(9px, 1.4vw, 13px); font-weight: 800; color: #6b6a85; margin-bottom: 6px; pointer-events: none; white-space: nowrap; }
.key.target .klabel { color: #fff; }
.kfinger { position: absolute; top: 30%; font-weight: 800; color: #fff; font-size: clamp(12px, 2vw, 18px); pointer-events: none; }
.key.white .kfinger { top: 58%; }

.player.fall .staff-wrap { margin: 0 max(6px, env(safe-area-inset-left)); border-radius: 14px 14px 0 0; border: none; order: 3; }
.player.fall .player-mid { order: 2; }
.player.fall .kbd { order: 4; border-radius: 0 0 10px 10px; padding-top: 0; }
.player.fall .kbd .key { top: 0; }
.player.fall .rotate-hint { order: 5; }
.player.fall .opts-panel { order: 1; }
.kbd.all-labels .klabel { font-size: clamp(7px, 1.05vw, 12px); }
.kbd.all-labels .key.black .klabel { font-size: clamp(6px, .8vw, 10px); }
.rotate-hint { display: none; }
@media (orientation: portrait) and (max-width: 700px) {
  .rotate-hint { display: block; text-align: center; font-size: .85rem; color: var(--muted); padding: 0 12px 4px; }
}
.suggest { background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 10px 14px; font-weight: 700; font-size: .92rem; }
.key.black .klabel { color: #fff; font-size: clamp(8px, 1.1vw, 11px); margin-bottom: 4px; }
@media (max-width: 640px) {
  .topbar { backdrop-filter: none; background: var(--bg); }
  #nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; justify-content: space-around; gap: 0;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px max(6px, env(safe-area-inset-bottom));
  }
  #nav a { flex: 1; text-align: center; padding: 10px 4px; font-size: .85rem; }
  body.playing #nav { display: none; }
  .hero { flex-direction: column; }
  .chip { display: none; }
  .stats { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .player .kbd { height: 30vh; }
  .player-mid { min-height: 24px; }
  .player-top { padding-top: 4px; padding-bottom: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
