@font-face {
  font-family: 'Bravura';
  src: url('/fonts/Bravura.woff2') format('woff2');
  font-display: block;
}

:root {
  --bg: #0b1020;
  --card: #161c30;
  --card-2: #1f2740;
  --line: #2b3454;
  --text: #e9edf8;
  --muted: #98a2bd;
  --blue: #4cc9f0;
  --orange: #ffb454;
  --green: #5ee08a;
  --red: #ff6b6b;
  --kb-h: min(36dvh, 240px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; letter-spacing: -0.02em; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---- pages with tabs ---- */

#app.page { min-height: 100dvh; display: flex; flex-direction: column; }
.page-body {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 18px) calc(16px + var(--safe-r)) calc(96px + var(--safe-b)) calc(16px + var(--safe-l));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  padding: 6px 8px calc(6px + var(--safe-b));
  background: rgba(11, 16, 32, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.tab { flex: 1; max-width: 130px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 0; font-size: 11px; color: var(--muted); }
.tab-icon { font-size: 21px; line-height: 1.1; }
.tab.on { color: var(--blue); }

.home-head, .plain-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.plain-head { flex-direction: column; gap: 2px; }
.back { color: var(--blue); font-size: 15px; padding: 4px 0; }
.icon-btn { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 12px; background: var(--card); font-size: 18px; color: var(--muted); }
.section { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 10px; font-weight: 600; }

.stats { display: flex; gap: 16px; align-items: center; background: var(--card); border-radius: 20px; padding: 16px; }
.ring { --p: 0; width: 104px; height: 104px; flex: none; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--green) calc(var(--p) * 360deg), var(--card-2) 0); }
.ring-in { width: 84px; height: 84px; border-radius: 50%; background: var(--card); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-in b { font-size: 28px; line-height: 1; }
.ring-in span { font-size: 11px; color: var(--muted); }
.stats-side { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.streak b { font-size: 20px; margin-right: 6px; }
.streak span { color: var(--muted); font-size: 13px; }
.week { display: flex; gap: 6px; }
.day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10px; color: var(--muted); }
.day i { width: 100%; max-width: 22px; aspect-ratio: 1; border-radius: 7px; background: var(--card-2); }
.day.did i { background: var(--green); }
.day.today { color: var(--text); font-weight: 700; }

.plan { display: flex; align-items: center; gap: 14px; background: var(--card); border-radius: 18px; padding: 14px 16px; border: 1px solid transparent; }
.plan:active { background: var(--card-2); }
.plan-check { width: 42px; height: 42px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--blue); color: #06202b; font-size: 17px; font-weight: 700; }
.plan.done .plan-check { background: var(--card-2); color: var(--green); }
.plan-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.plan-text b { font-size: 16px; }
.plan-text span { font-size: 13px; color: var(--muted); }
.plan-time { font-size: 12px; color: var(--muted); white-space: nowrap; }

.tip { position: relative; background: #17233a; border: 1px solid #2c4468; border-radius: 16px; padding: 14px 40px 14px 16px; }
.tip p { font-size: 14px; color: var(--muted); margin-top: 2px; }
.tip-x { position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; color: var(--muted); }

.unit { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.unit-head { display: flex; gap: 12px; align-items: center; margin-bottom: 4px; }
.unit-head h2 { font-size: 18px; }
.unit-head p { font-size: 13px; }
.unit-num { width: 36px; height: 36px; flex: none; border-radius: 11px; background: var(--card-2); display: grid; place-items: center; font-weight: 700; color: var(--blue); }
.unit-count { margin-left: auto; font-size: 12px; color: var(--muted); }
.lesson-row, .song-row { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px; padding: 12px 14px; min-height: 58px; }
.lesson-row.next { border: 1px solid var(--blue); }
.lesson-row.locked { opacity: 0.45; }
.lesson-state { width: 30px; height: 30px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--card-2); font-size: 13px; color: var(--green); }
.lesson-row.next .lesson-state { background: var(--blue); color: #06202b; }
.lesson-text, .song-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lesson-text span, .song-text span { font-size: 12px; color: var(--muted); }
.lesson-stars, .summary-stars, .song-best { color: #fde047; letter-spacing: 2px; white-space: nowrap; }
.song-best { font-size: 15px; }

.btn { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 18px; border-radius: 14px; font-weight: 650; text-align: center; background: var(--card-2); }
.btn.big { min-height: 54px; font-size: 17px; width: 100%; }
.btn.primary { background: var(--blue); color: #06202b; }
.btn.soft { background: var(--card-2); color: var(--text); }
.btn.ghost { background: none; color: var(--muted); }
.btn.danger { background: #3a1820; color: var(--red); margin-top: 6px; }
.btn:disabled { opacity: 0.35; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.chip { padding: 7px 12px; border-radius: 999px; background: var(--card-2); font-size: 13px; font-weight: 600; white-space: nowrap; }

.seg-group { display: flex; flex-direction: column; gap: 6px; }
.seg-group label { font-size: 13px; color: var(--muted); }
.seg { display: flex; background: var(--card); border-radius: 12px; padding: 3px; gap: 3px; }
.seg.wrap { flex-wrap: wrap; }
.seg button { flex: 1; min-height: 40px; padding: 6px 10px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--card-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 14px; background: var(--card); border-radius: 14px; padding: 14px 16px; }
.setting.col { flex-direction: column; align-items: stretch; }
.setting b { display: block; }
.setting span { font-size: 13px; color: var(--muted); }
.setting input[type='checkbox'] { width: 26px; height: 26px; accent-color: var(--blue); flex: none; }
.code { width: 100%; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: 8px; font: 12px ui-monospace, monospace; -webkit-user-select: text; user-select: text; }
.mic-test { font-size: 15px; padding: 8px 0; }

/* ---- lesson runner ---- */

#app.runner, #app.summary {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) 0 var(--safe-l);
  overflow: hidden;
}
.runner-head { display: flex; align-items: center; gap: 12px; padding: 8px 12px; flex: none; }
.runner-head .icon-btn { width: 36px; height: 36px; background: none; }
.runner-title { flex: 1; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { flex: 1; height: 10px; border-radius: 6px; background: var(--card-2); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--green); border-radius: 6px; transition: width 0.3s; }
.runner-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 0 12px; position: relative; }
.runner-foot { flex: none; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px calc(12px + var(--safe-b)); }
.runner-note { min-height: 22px; text-align: center; color: var(--green); font-weight: 650; }

.immersive .runner-body { padding: 0; gap: 0; }
.immersive .runner-foot { display: none; }
.immersive .runner-foot.ready {
  display: flex;
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px calc(14px + var(--safe-r)) calc(14px + var(--safe-b)) calc(14px + var(--safe-l));
  background: rgba(11, 16, 32, 0.96);
  border-top: 1px solid var(--line);
  z-index: 20;
  animation: rise 0.25s ease-out;
}
@keyframes rise { from { transform: translateY(100%); } }

.card { background: var(--card); border-radius: 20px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.card.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.card.grow { flex: 1; min-height: 0; justify-content: center; text-align: center; overflow-y: auto; }
.card h2 { font-size: 22px; letter-spacing: -0.01em; line-height: 1.25; }
.prose { display: flex; flex-direction: column; gap: 12px; font-size: 16.5px; line-height: 1.5; color: #d5dbee; }
.prose b { color: #fff; }
.prose ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.formula { text-align: center; font-weight: 700; color: var(--blue); background: var(--card-2); border-radius: 12px; padding: 10px; font-size: 15px; }

.art { border-radius: 14px; background: var(--card-2); padding: 10px; }
.art-keys .kb-wrap { height: 130px; padding: 0; }
.art-caption { text-align: center; font-size: 13px; color: var(--muted); margin-top: 8px; }
.art-staff { background: #f6f7fb; color: #141a2c; overflow-x: auto; }
.art-staff .art-caption { color: #55607d; }
.art-hands { display: flex; gap: 8px; justify-content: center; }
.hand { width: 46%; max-width: 170px; }
.hand-palm, .hand-finger { fill: #3a466b; }
.hand-num { fill: #fff; font: 700 14px system-ui; text-anchor: middle; }
.hand-label { fill: var(--muted); font: 600 11px system-ui; text-anchor: middle; }

.options { display: flex; flex-direction: column; gap: 10px; }
.options.two { flex-direction: row; flex-wrap: wrap; }
.options.two .option { flex: 1 1 40%; text-align: center; }
.option { min-height: 54px; padding: 12px 16px; border-radius: 14px; background: var(--card-2); text-align: left; font-size: 17px; font-weight: 600; border: 2px solid transparent; }
.option.right { border-color: var(--green); background: #173527; }
.option.wrong { border-color: var(--red); background: #3a1820; opacity: 0.7; animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.explain { color: var(--green); min-height: 22px; font-size: 15px; }
.dots { display: flex; gap: 6px; justify-content: center; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--card-2); }
.dots i.on { background: var(--green); }
.find-status { color: var(--muted); font-weight: 600; min-height: 22px; }
.read-staff { align-self: center; background: #f6f7fb; border-radius: 14px; padding: 4px 10px; }
.read-answer { min-height: 26px; font-size: 20px; font-weight: 700; color: var(--green); }
.meter { height: 12px; border-radius: 8px; background: var(--card-2); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--orange); transition: width 0.15s; }

/* ---- keyboard ---- */

.kb-wrap { flex: none; height: var(--kb-h); padding: 0 0 calc(var(--safe-b) + 6px); }
.kb-wrap.tall { height: min(46dvh, 300px); }
.runner-body > .kb-wrap { margin: 0 -12px; }
.kb { position: relative; width: 100%; height: 100%; touch-action: none; overflow: hidden; border-top: 3px solid #05070f; background: #05070f; }
.key { position: absolute; top: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.key.white { bottom: 0; background: linear-gradient(#fdfdff 0%, #eef0f6 80%, #dfe3ee 100%); border: 1px solid #8f98ad; border-top: 0; border-radius: 0 0 7px 7px; padding-bottom: 8px; }
.key.black { height: 62%; background: linear-gradient(#2a2f40, #0d1018); border-radius: 0 0 5px 5px; z-index: 2; box-shadow: 0 3px 4px rgba(0, 0, 0, 0.45); padding-bottom: 6px; }
.key.white.down { background: linear-gradient(#dfe5f2, #c6cee0); }
.key.black.down { background: linear-gradient(#4a5270, #252a3a); }
.key-label { font-size: 13px; font-weight: 700; color: #6b7590; pointer-events: none; }
.key.black .key-label { color: #cdd3e6; font-size: 10px; }
.kb-dense .key-label { font-size: 10px; }
.kb-dense .key.black .key-label { font-size: 8px; }
.key.middle-c::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--blue); margin-bottom: 4px; }
.key.mark.white { background: linear-gradient(#f0fbff, #bfe9f8); }
.key.mark.black { background: linear-gradient(#3fa8c9, #1c6f8c); }
.key.hl.rh.white { background: linear-gradient(#d9f5ff, var(--blue)); }
.key.hl.lh.white { background: linear-gradient(#fff0d9, var(--orange)); }
.key.hl.rh.black { background: linear-gradient(#7fdcf7, #1f95bd); }
.key.hl.lh.black { background: linear-gradient(#ffd08f, #d0801f); }
.key.hl .key-label { color: #06202b; }
.key.pulse { animation: pulse 0.7s infinite; }
@keyframes pulse { 50% { filter: brightness(1.35) saturate(1.5); box-shadow: 0 0 0 3px var(--green) inset; } }
.key.good { animation: good 0.42s; }
.key.bad { animation: bad 0.42s; }
@keyframes good { 0%, 60% { background: var(--green); } }
@keyframes bad { 0%, 60% { background: var(--red); } }
.finger { width: 24px; height: 24px; border-radius: 50%; background: #06202b; color: #fff; font-size: 14px; font-weight: 700; display: grid; place-items: center; margin-bottom: 4px; pointer-events: none; }
.kb-dense .finger { width: 18px; height: 18px; font-size: 11px; }
.key.black .finger { width: 18px; height: 18px; font-size: 11px; background: #fff; color: #06202b; }

/* ---- play surface ---- */

.play-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 0 12px 6px; }
.play-prompt { flex: 1; font-weight: 600; font-size: 15px; line-height: 1.3; }
.play-tools { display: flex; gap: 6px; flex: none; }
.play-surface { flex: 1; min-height: 0; position: relative; }
.play { height: 100%; display: flex; flex-direction: column; position: relative; }
.play-stage { flex: 1; min-height: 0; position: relative; background: linear-gradient(#0d1326, #10172d); overflow: hidden; }
.fall { position: absolute; inset: 0; width: 100%; height: 100%; }
.play-hint { flex: none; height: 26px; line-height: 26px; text-align: center; font-size: 14px; font-weight: 650; color: var(--blue); background: #05070f; white-space: nowrap; overflow: hidden; }
.count-in { position: absolute; inset: 0; display: none; place-items: center; font-size: 96px; font-weight: 800; color: var(--blue); text-shadow: 0 2px 18px rgba(5, 7, 15, 0.55); pointer-events: none; z-index: 2; }
.count-in.on { display: grid; }
.rotate-tip { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); background: rgba(22, 28, 48, 0.92); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 12px; color: var(--muted); white-space: nowrap; pointer-events: none; z-index: 3; animation: tip-out 0.5s 4s forwards; }
@keyframes tip-out { to { opacity: 0; } }
.staff-box { position: absolute; inset: 0; overflow-y: auto; background: #f6f7fb; padding: 4px 6px; }
.tap-pad { width: calc(100% - 24px); height: calc(100% - 12px); margin: 6px 12px; border-radius: 22px; background: var(--card-2); border: 2px solid var(--line); font-size: 30px; font-weight: 800; letter-spacing: 0.1em; color: var(--muted); touch-action: none; }
.tap-pad.down { background: var(--blue); color: #06202b; transform: scale(0.985); }
.tap-pad.good { border-color: var(--green); }
.retry, .mic-ask { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(86%, 340px); background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 18px; display: flex; flex-direction: column; gap: 10px; text-align: center; z-index: 5; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); }
.mic-pill { position: absolute; top: 8px; right: 8px; display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: rgba(22, 28, 48, 0.9); font-size: 12px; color: var(--muted); z-index: 3; }
.mic-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.mic-pill.loud .mic-dot { background: var(--green); }

/* ---- sheet music ---- */

.staff { color: #141a2c; }
.staff-line { display: block; max-width: none; }
.staff .sl { stroke: #141a2c; stroke-width: 1; }
.staff .bl { stroke: #141a2c; stroke-width: 1.2; }
.staff .stem { stroke: currentColor; stroke-width: 1.3; }
.staff .glyph { font-family: 'Bravura'; font-size: 40px; fill: currentColor; }
.staff .fill { fill: currentColor; }
.staff .note-name { font: 700 12px system-ui, sans-serif; fill: #55607d; text-anchor: middle; }
.staff .ev { color: #141a2c; }
.staff .ev.cur { color: #0a84c4; }
.staff .ev.cur .note-name { fill: #0a84c4; }
.staff .ev.done { color: #2fa35a; }
.staff .ledger { stroke-width: 1.2; }

/* ---- free play ---- */

.runner-body.free { justify-content: flex-end; gap: 8px; }
.now-playing { flex: 1; min-height: 0; display: grid; place-items: center; font-size: min(30vw, 22dvh); font-weight: 800; color: var(--card-2); transition: color 0.25s; overflow: hidden; }
.now-playing.on { color: var(--blue); transition: none; }
.free-panel { padding: 0 12px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 0; }
.free-label { font-size: 13px; color: var(--muted); }
.free-range { display: flex; align-items: center; justify-content: space-between; padding: 0 12px; }
.range-label { color: var(--muted); font-size: 13px; }

/* ---- summary ---- */

#app.summary { align-items: center; justify-content: center; padding: 24px; }
.summary-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.summary-stars { font-size: 44px; }
.summary-xp { font-weight: 700; color: var(--orange); font-size: 18px; margin-bottom: 10px; }
.retry .summary-stars { font-size: 32px; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { top: 105%; transform: rotate(720deg); } }

/* ---- phone held sideways ---- */

@media (orientation: landscape) and (max-height: 520px) {
  :root { --kb-h: 48dvh; }
  .runner-head { padding: 3px 12px; }
  .runner-head .icon-btn { height: 30px; }
  .play-head { padding: 0 12px 3px; }
  .play-prompt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
  .play-hint { height: 20px; line-height: 20px; font-size: 12px; }
  .rotate-tip { display: none; }
  .kb-wrap.tall { height: 52dvh; }
  .free-panel .free-label, .free-panel p, .now-playing { display: none; }
  .card { padding: 14px; }
  .card.grow h2 { font-size: 18px; }
  .runner-foot { padding-top: 4px; padding-bottom: calc(6px + var(--safe-b)); }
  .runner-note { display: none; }
  .btn.big { min-height: 44px; }
  .count-in { font-size: 70px; }
}
