:root {
  --cream: #FFF8E7;
  --line: #E9DCC0;
  --sand: #F3E7CB;
  --orange: #F28C28;
  --orange-dark: #A34F06;
  --orange-soft: #FFF0DD;
  --red: #D94F3D;
  --red-dark: #A93627;
  --blue: #3D7DD9;
  --blue-dark: #2A5CA6;
  --green: #2F9E6B;
  --green-dark: #1F6E4A;
  --ink: #2B2B2B;
  --muted: #6E5F43;
  --radius: 18px;
  --shadow: 0 3px 0 rgba(150, 120, 60, .14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--cream); -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button, input, kbd { font: inherit; color: inherit; }
button, .btn { cursor: pointer; border: 0; background: none; user-select: none; -webkit-user-select: none; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }
.sheet:focus { outline: none; }
.icon { display: inline-flex; }
.mus { font-family: 'Noto Music', serif; font-weight: 400; line-height: 1; }
.muted { color: var(--muted); font-size: 15px; }

.card { background: #fff; border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 8px 18px; border-radius: 16px;
  font-weight: 700; font-size: 17px; text-decoration: none; color: var(--ink); text-align: center;
}
.btn.primary { background: var(--orange); box-shadow: 0 4px 0 var(--orange-dark); }
.btn.primary.good { background: var(--green-dark); color: #fff; box-shadow: 0 4px 0 #134A31; }
.btn.ghost { background: #fff; border: 2px solid var(--line); box-shadow: var(--shadow); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.btn:disabled { opacity: .55; }
.btn.wide { width: 100%; min-height: 56px; font-size: 19px; }

/* ---------- Thanh trên ---------- */
.top { display: grid; grid-template-columns: 46px 1fr 46px; align-items: center; gap: 8px; }
.titles { text-align: center; min-width: 0; }
.titles small { display: block; color: var(--muted); font-size: 13px; line-height: 1.1; }
.titles h1 { font-size: 22px; font-weight: 800; line-height: 1.15; }
.square { width: 46px; height: 44px; display: grid; place-items: center; background: #fff; border: 2px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.square.small { width: 40px; height: 40px; flex: none; }

/* ---------- Nhóm nút chọn ---------- */
.chips { display: flex; gap: 6px; }
.chips button { flex: 1 1 0; min-height: 44px; padding: 2px 4px; background: #fff; border: 2px solid var(--line); border-radius: 14px; font-weight: 700; font-size: 15px; line-height: 1.1; color: var(--muted); }
.chips button small { display: block; font-size: 12px; font-weight: 600; }
.chips button[aria-checked="true"] { background: var(--orange-soft); border-color: var(--orange); color: var(--orange-dark); box-shadow: 0 0 0 1px var(--orange); }
.segmented { display: flex; gap: 4px; padding: 4px; background: var(--sand); border-radius: 15px; }
.segmented button { flex: 1 1 0; min-height: 36px; border-radius: 11px; font-weight: 700; font-size: 15px; color: var(--muted); line-height: 1.1; padding: 2px 4px; }
.segmented button small { display: block; font-size: 12px; font-weight: 600; }
.segmented button[aria-checked="true"] { background: #fff; color: var(--orange-dark); box-shadow: var(--shadow); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 48px; padding: 6px 14px; background: #fff; border: 2px solid var(--line); border-radius: 16px; font-weight: 700; }
.switch i { position: relative; flex: none; width: 52px; height: 30px; border-radius: 30px; background: #C9B993; transition: background .15s; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px #0004; }
.switch[aria-checked="true"] i { background: var(--green); }
.switch[aria-checked="true"] i::after { transform: translateX(22px); }

/* ---------- Trang thường ---------- */
.page { max-width: 560px; min-height: 100dvh; margin: 0 auto; padding: calc(12px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 12px; }
.brand h1 { font-size: 34px; font-weight: 800; line-height: 1.05; }
.brand p { color: var(--muted); font-size: 17px; }
.cards { display: grid; gap: 10px; }
.card.mode { display: flex; align-items: center; gap: 14px; padding: 12px 14px; text-align: left; width: 100%; }
.card.mode:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.card.mode:disabled { opacity: .6; }
.badge { flex: none; width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; }
.badge .num { font-size: 28px; font-weight: 800; }
.tone-red .badge { background: #FCE0DC; color: var(--red-dark); }
.tone-blue .badge { background: #DCEAFE; color: var(--blue-dark); }
.tone-green .badge { background: #DFF3E9; color: var(--green-dark); }
.tone-orange .badge { background: #FFE8C9; color: var(--orange-dark); }
.mode .text { flex: 1; min-width: 0; }
.mode b { display: block; font-size: 20px; font-weight: 800; }
.mode small { display: block; color: var(--muted); font-size: 14px; }
.soon { flex: none; font-size: 12px; background: var(--sand); color: var(--muted); border-radius: 20px; padding: 2px 8px; }
.home-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: auto; }
.home-tools .btn { flex-direction: column; gap: 0; padding: 8px 4px; font-size: 14px; line-height: 1.15; }
.home-tools small { display: block; font-size: 11px; color: var(--muted); }

/* ---------- Vịt ---------- */
.scene { position: relative; width: 100%; height: 100%; overflow: hidden; background: linear-gradient(#CDEBFA, #FFF3CF 75%); border-radius: var(--radius); }
.scene svg { display: block; width: 100%; height: 100%; overflow: hidden; }
.scene.hero { flex: 1 1 150px; min-height: 120px; max-height: 340px; cursor: pointer; }
.scene.hero svg { position: absolute; inset: 0; }
.duckling { animation: bob 2.4s ease-in-out infinite; }
.duckling.eat { animation: eat .4s ease; }
.arm, .drum, .mom { transform-box: fill-box; transform-origin: center; }
.hit-C .arm-C { animation: strike-c .22s ease; }
.hit-C .drum-C, .hit-D .drum-D { animation: squash .22s ease; transform-origin: bottom; }
.hit-D .arm-D { animation: strike-d .22s ease; }
@keyframes bob { 50% { transform: translateY(3px); } }
@keyframes eat { 40% { transform: translateY(-7px) rotate(-12deg); } }
@keyframes strike-c { 45% { transform: translateY(7px) rotate(-10deg); } }
@keyframes strike-d { 45% { transform: translate(-6px, 14px) rotate(30deg); } }
@keyframes squash { 45% { transform: scale(1.05, .9); } }

.bubble-row { display: flex; align-items: center; gap: 10px; background: #FFF0C4; border-radius: var(--radius); padding: 10px; }
.duck-head { flex: none; width: 52px; height: 52px; }
.duck-head svg { width: 100%; height: 100%; }
.bubble { background: #fff; border-radius: 14px; padding: 8px 12px; font-size: 15px; font-weight: 700; color: #4E422B; }
.bubble-row .bubble { flex: 1; }

/* ---------- Màn chơi: vừa khít một màn hình ---------- */
.game {
  height: 100dvh; max-width: 560px; margin: 0 auto; overflow: hidden;
  padding: calc(8px + var(--safe-top)) 12px calc(10px + var(--safe-bottom));
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); gap: 8px;
}
.info { display: flex; flex-direction: column; gap: 7px; min-height: 0; overflow-y: auto; scrollbar-width: none; }
.info > * { flex: none; }
.setup { display: flex; flex-direction: column; gap: 6px; }
.summary-line { display: none; text-align: center; font-size: 13px; color: var(--muted); background: var(--sand); border-radius: 12px; padding: 3px 8px; }
.is-playing .setup, .is-playing .metro-row { display: none; }
.is-playing .summary-line { display: block; }
.notice { background: var(--orange-soft); border: 2px solid var(--orange); color: var(--orange-dark); border-radius: 12px; padding: 3px 10px; text-align: center; font-size: 15px; font-weight: 800; }
.tempo-row { display: flex; align-items: center; gap: 6px; }
.chip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; background: #fff; border: 2px solid var(--line); border-radius: 30px; padding: 3px 11px; font-size: 14px; font-weight: 700; color: var(--muted); }
.chip.lead { background: var(--orange-soft); border-color: var(--orange); color: var(--orange-dark); }
.stepper { margin-left: auto; flex: none; display: flex; align-items: center; gap: 4px; }
.stepper button { width: 40px; height: 38px; border-radius: 12px; background: #fff; border: 2px solid var(--line); font-size: 22px; line-height: 1; font-weight: 800; }
.stepper b { min-width: 58px; text-align: center; white-space: nowrap; }
.meter-note { display: flex; align-items: center; justify-content: center; gap: 5px; font-size: 11.5px; color: var(--blue-dark); background: #EAF2FD; border-radius: 10px; padding: 1px 6px; white-space: nowrap; overflow: hidden; }
.meter-note .mus { font-size: 15px; }

.song { display: flex; align-items: center; gap: 10px; padding: 7px 12px 7px 8px; }
.play { flex: none; width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; background: var(--orange); box-shadow: 0 4px 0 var(--orange-dark); color: var(--ink); }
.play:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--orange-dark); }
.play.small { width: 40px; height: 40px; box-shadow: 0 3px 0 var(--orange-dark); }
.play.stop { background: var(--sand); box-shadow: 0 4px 0 #CDB98B; }
.song-main { flex: 1; min-width: 0; }
.song-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.song-title { display: flex; align-items: center; gap: 2px; min-width: 0; font-weight: 800; font-size: 17px; text-align: left; min-height: 28px; }
.song-title span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-title:disabled .icon { display: none; }
.song-head small { flex: 0 1 auto; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.seek { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.seek input { flex: 1; min-width: 0; height: 28px; -webkit-appearance: none; appearance: none; background: transparent; --fill: 0%; }
.seek input::-webkit-slider-runnable-track { height: 8px; border-radius: 8px; background: linear-gradient(90deg, var(--orange) var(--fill), var(--sand) var(--fill)); }
.seek input::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -8px; border-radius: 50%; background: var(--orange); border: 3px solid #fff; box-shadow: 0 1px 4px #0005; }
.seek input::-moz-range-track { height: 8px; border-radius: 8px; background: var(--sand); }
.seek input::-moz-range-progress { height: 8px; border-radius: 8px; background: var(--orange); }
.seek input::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--orange); border: 3px solid #fff; }

.info > .stage { position: relative; flex: 1 0 64px; min-height: 64px; max-height: 210px; }
.stage .scene { position: absolute; inset: 0; }
.say { position: absolute; top: 5px; right: 5px; max-width: 52%; pointer-events: none; }
.say .bubble { font-size: 13px; padding: 4px 9px; line-height: 1.2; box-shadow: var(--shadow); }

/* ---------- Khung Vào bài ---------- */
.frame { padding: 5px 8px 8px; }
.frame-label { text-align: center; font-size: 13px; color: var(--muted); font-weight: 700; }
.measure-box { border: 3px solid #FFD29E; border-radius: 14px; padding: 3px; }
.measure-box.blink { animation: blink .6s ease-out; }
@keyframes blink { 0% { border-color: var(--orange); box-shadow: 0 0 0 5px rgba(242, 140, 40, .45); } 100% { border-color: #FFD29E; box-shadow: 0 0 0 0 transparent; } }
.cells { display: flex; gap: 4px; }
.cell { position: relative; flex: 1 1 0; min-width: 0; height: 42px; display: grid; place-items: center; border-radius: 10px; font-weight: 800; font-size: 15px; line-height: 1; text-align: center; border: 3px solid transparent; background: var(--sand); color: var(--muted); }
.cell.hand-D { background: var(--red); color: #fff; }
.cell.hand-C { background: var(--blue); color: #fff; }
.cell.hand-any { background: var(--orange); color: var(--ink); }
.cell.count { background: #E9DCC0; color: #4E422B; }
.cell.tune { background: #FFE07A; color: #6B4E00; }
.cell.lead { background: var(--orange); color: var(--ink); }
.cell.empty { background: #FFF8E7; border: 2px dashed var(--line); }
.cell.past { opacity: .42; }
.cell.past:has(.mark) { opacity: 1; }
.cell.past:has(.mark) .label { opacity: .35; }
.cell.past.hand-D:has(.mark) { background: #F6CBC5; color: var(--red-dark); }
.cell.past.hand-C:has(.mark) { background: #CBDDF6; color: var(--blue-dark); }
.cell.past.hand-any:has(.mark) { background: #FBDDBE; }
.cell.now { border: 3px solid var(--orange); box-shadow: 0 0 0 2px var(--ink); opacity: 1; z-index: 1; }
.cell .mus { font-size: 24px; }
.cell-mark { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.cell-mark svg { width: 20px; height: 20px; filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 1px #fff); }

.frame.split .measure-box { border-width: 0; padding: 0; }
.beats { display: grid; gap: 5px; }
.beats.one-row { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
.beats.two-rows { grid-template-columns: 1fr 1fr; }
.beat-group em { display: block; text-align: center; font-style: normal; font-size: 11px; color: var(--muted); }
.beat-group .cells { border: 2px solid var(--line); border-radius: 11px; padding: 2px; gap: 2px; }
.frame.split .measure-box.blink { border-radius: 12px; }
.beat-group .cell { height: 36px; font-size: 13px; border-radius: 8px; overflow: hidden; }
.beat-group .cell.hand-D .label { font-size: 11px; line-height: .95; }

.frame.pickup { padding-bottom: 6px; }
.pk-head, .pk-grid { display: grid; grid-template-columns: 50px minmax(0, 1fr) minmax(0, 1fr); gap: 4px; }
.pk-head { text-align: center; font-size: 12px; color: var(--muted); font-weight: 800; }
.pk-names { display: grid; grid-template-rows: repeat(3, 1fr); padding: 6px 0; align-items: center; font-size: 9px; color: var(--muted); }
.pk-block { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.pk-block.count { padding: 6px 0; }
.pk-block .cells { gap: 2px; }
.pk-block .cell { height: 34px; font-size: 10.5px; border-width: 2px; border-radius: 7px; }
.pk-block .cell .mus { font-size: 19px; }
.pk-block .cell-mark svg { width: 16px; height: 16px; }
.frame.listening .pk-block.count .cells:not(:first-child) { opacity: .35; }
.frame.no-pickup .pk-block.count .cells:not(:first-child) { visibility: hidden; }

/* ---------- 8 lần gõ ---------- */
.recent { padding: 4px 8px 5px; }
.recent.unused { display: none; }
.recent-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 12px; color: var(--muted); }
.recent-head strong { color: var(--green-dark); font-size: 13px; text-align: right; }
.recent-head strong.advice { color: var(--orange-dark); }
.slots { display: flex; gap: 4px; }
.slot { position: relative; flex: 1; height: 34px; background: var(--sand); border-radius: 9px; border: 2px solid transparent; }
.slot::before { content: ''; position: absolute; left: calc(50% - 1px); top: 3px; bottom: 3px; width: 2px; background: #CDB98B; }
.slot.next { border-color: var(--orange); background: var(--orange-soft); }
.slot i { position: absolute; top: 50%; left: 50%; width: 18px; height: 18px; transform: translate(-50%, -50%); transition: left .1s; }
.slot i svg { display: block; width: 18px; height: 18px; }
.legend { display: flex; justify-content: center; flex-wrap: wrap; gap: 2px 12px; font-size: 11px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 4px; }
.legend .mark { width: 12px; height: 12px; display: block; }
.metro-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.metro-row .segmented { flex: 1; }

/* ---------- Nút gõ ---------- */
.pads { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; height: clamp(112px, 21dvh, 250px); }
.pads.single { grid-template-columns: 1fr; }
.pad {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 28px; border: 5px solid transparent; color: #fff; min-height: 110px; min-width: 0;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.pad b { font-size: clamp(28px, 5dvh, 56px); font-weight: 800; line-height: 1.1; }
.pad small { font-size: 16px; font-weight: 700; text-align: center; line-height: 1.15; padding: 0 4px; }
.pad kbd { display: none; margin-top: 10px; padding: 3px 14px; border-radius: 10px; background: rgba(0, 0, 0, .22); font-size: 15px; font-weight: 800; }
.pad-D { background: linear-gradient(#E2604F, var(--red)); box-shadow: 0 6px 0 var(--red-dark); }
.pad-C { background: linear-gradient(#4E8BE0, var(--blue)); box-shadow: 0 6px 0 var(--blue-dark); }
.pad-single { background: linear-gradient(#FFA04A, var(--orange)); box-shadow: 0 6px 0 var(--orange-dark); color: var(--ink); }
.pads .pad { margin-bottom: 6px; }
.pad:active { transform: translateY(4px); box-shadow: none; }
.pad[data-result="press"] { animation: press .14s ease-out; }
.pad[data-result="guide"] { animation: guide .25s ease-out; }
.pad[data-result="ok"] { animation: res-ok .35s ease-out; }
.pad[data-result="near"] { animation: res-near .35s ease-out; }
.pad[data-result="off"] { animation: res-off .35s ease-out; }
@keyframes press { 40% { transform: scale(.96); filter: brightness(1.12); } }
@keyframes guide { 30% { filter: brightness(1.3); transform: scale(.97); } }
@keyframes res-ok { 0%, 55% { border-color: #35D68F; transform: scale(.97); } }
@keyframes res-near { 0%, 55% { border-color: #FFD23F; transform: scale(.97); } }
@keyframes res-off { 0%, 55% { border-color: #3A0A05; border-style: dashed; transform: scale(.97); } }

.count-overlay { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 20; display: none; flex-direction: column; align-items: center; pointer-events: none; min-width: 170px; padding: 0 22px 12px; border-radius: 40px; background: rgba(255, 255, 255, .95); border: 5px solid var(--orange); box-shadow: 0 10px 30px #0003; }
.count-overlay.show { display: flex; }
.count-overlay b { font-size: 112px; font-weight: 800; line-height: 1.1; }
.count-overlay span { font-size: 18px; color: var(--muted); font-weight: 800; white-space: nowrap; }
.count-overlay.lead { background: var(--orange); border-color: var(--ink); }
.count-overlay.lead span { color: var(--ink); }

/* ---------- Đoán nhịp ---------- */
.guess-player { display: flex; align-items: center; gap: 12px; padding: 12px; }
.guess-player b { display: block; font-size: 19px; font-weight: 800; }
.guess-player small { color: var(--muted); }
.options { display: grid; gap: 10px; }
.option { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 8px; min-height: 62px; padding: 8px 14px; text-align: left; }
.option b { font-size: 18px; font-weight: 800; }
.option[aria-pressed="true"] { border-color: var(--orange); background: var(--orange-soft); box-shadow: 0 0 0 2px var(--orange); }
.option.right { border-color: var(--green); background: #E4F5EC; box-shadow: 0 0 0 2px var(--green); }
.option .tag { font-size: 13px; color: var(--orange-dark); font-weight: 800; }
.option.right .tag { color: var(--green-dark); }
.dots { display: flex; align-items: center; gap: 4px; }
.dots i { width: 15px; height: 15px; border-radius: 50%; background: var(--blue); }
.dots i.strong { width: 28px; height: 28px; background: var(--red); }
.dots i.now { transform: scale(1.25); box-shadow: 0 0 0 3px var(--orange); }
.answer { display: flex; align-items: center; gap: 16px; padding: 12px 16px; }
.answer.right { border-color: var(--green); color: var(--green-dark); }
.answer.right p { color: var(--muted); font-size: 14px; }
.answer.wrong { border-color: var(--red); color: var(--red-dark); justify-content: center; }
.time-sig { display: grid; text-align: center; font-size: 36px; line-height: 1; }
.time-sig b + b { border-top: 4px solid currentColor; }
.feedback { display: grid; gap: 8px; }
.bottom { position: sticky; bottom: calc(10px + var(--safe-bottom)); margin-top: auto; }

/* ---------- 5a ---------- */
.intro > p { font-size: 15px; color: var(--muted); }
.intro > p.meter-note { color: var(--blue-dark); font-size: 11.5px; white-space: normal; text-align: center; }
.example { padding: 8px 10px 10px; display: grid; gap: 5px; }
.example-head { display: flex; align-items: center; gap: 10px; }
.example-head b { font-weight: 800; }
.enter { margin-left: auto; color: var(--orange-dark); font-weight: 800; font-size: 14px; }
.example .cell { height: 38px; font-size: 12.5px; }
.swatch { width: 14px; height: 14px; border-radius: 4px; }
.swatch.lead { background: var(--orange); }
.swatch.tune { background: #FFE07A; }

/* ---------- Hộp thoại ---------- */
.backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 14px; background: rgba(60, 45, 15, .45); }
.sheet { width: min(480px, 100%); max-height: calc(100dvh - 28px); display: flex; flex-direction: column; gap: 10px; padding: 16px; background: var(--cream); border-radius: 26px; box-shadow: 0 20px 60px #0005; animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet-head h2 { font-size: 21px; font-weight: 800; line-height: 1.2; }
.sheet-body { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 2px 2px 6px; }
.sheet-body > * { flex: none; }
.sheet-body section { display: grid; gap: 6px; }
.sheet-body h3 { font-size: 16px; }
.sheet-body ul { padding-left: 18px; font-size: 15px; }
.sheet-body summary { cursor: pointer; font-weight: 800; }
.sheet-body details p { margin-top: 6px; font-size: 14px; }
.sheet-body .keys { list-style: none; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.keys kbd { display: inline-block; min-width: 52px; margin-right: 8px; padding: 1px 6px; text-align: center; background: #fff; border: 2px solid var(--line); border-radius: 8px; }
.sheet-actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; padding-bottom: 4px; }
.result .big { font-size: 46px; font-weight: 800; text-align: center; color: var(--green-dark); line-height: 1; }
.result ul { list-style: none; padding: 0; text-align: center; }
.song-list { display: grid; gap: 8px; }
.song-item { padding: 8px 14px; text-align: left; }
.song-item b { display: block; font-size: 17px; }
.song-item small { color: var(--muted); }
.song-item[aria-current="true"] { border-color: var(--orange); background: var(--orange-soft); }
.warn { background: var(--orange-soft); border: 2px solid var(--orange); border-radius: 14px; padding: 8px 12px; font-size: 14px; }
.cal-dots { display: flex; justify-content: center; gap: 8px; }
.cal-dots i { width: 22px; height: 22px; border-radius: 50%; background: var(--sand); border: 3px solid transparent; }
.cal-dots i.warmup { background: #fff; border-color: var(--line); }
.cal-dots i.now { border-color: var(--orange); transform: scale(1.2); }
.cal-dots i.hit { background: var(--green); }
.cal-message { text-align: center; font-size: 15px; min-height: 40px; }
.cal-pad { height: 130px; }
.cal-pad:disabled { opacity: .45; }

#flash { position: fixed; inset: 0; z-index: 60; pointer-events: none; opacity: 0; border: 18px solid var(--orange); background: rgba(255, 190, 60, .35); }
#sound-hint { position: fixed; z-index: 40; left: 50%; top: calc(6px + var(--safe-top)); transform: translateX(-50%); white-space: nowrap; background: var(--ink); color: #fff; border-radius: 30px; padding: 8px 18px; font-weight: 700; box-shadow: 0 6px 20px #0004; }
#toast { position: fixed; z-index: 70; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translate(-50%, 20px); width: max-content; max-width: calc(100% - 32px); background: var(--ink); color: #fff; border-radius: 16px; padding: 10px 16px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Màn hình thấp (iPhone SE, trình duyệt có thanh công cụ) ---------- */
@media (max-height: 740px) {
  .page.home { gap: 7px; padding-top: calc(6px + var(--safe-top)); padding-bottom: calc(8px + var(--safe-bottom)); }
  .home .brand h1 { font-size: 27px; }
  .home .brand p { display: none; }
  .home .scene.hero { flex-basis: 92px; min-height: 88px; }
  .home .cards { gap: 7px; }
  .home .card.mode { padding: 5px 10px; }
  .home .badge { width: 42px; height: 42px; }
  .home .mode b { font-size: 17px; line-height: 1.2; }
  .home .mode small { font-size: 12px; line-height: 1.2; }
  .home-tools .btn { min-height: 44px; padding: 3px; font-size: 13px; }
  .home-tools .btn .icon { display: none; }
  .home .switch { min-height: 42px; padding-top: 2px; padding-bottom: 2px; }
  .game { gap: 6px; padding-top: calc(5px + var(--safe-top)); }
  .info { gap: 5px; }
  .top .square { height: 38px; }
  .titles h1 { font-size: 19px; }
  .titles small { font-size: 11px; }
  .setup { gap: 4px; }
  .chips button { min-height: 36px; font-size: 14px; }
  .chips button small { display: inline; margin-left: 4px; }
  .segmented { padding: 3px; }
  .segmented button { min-height: 30px; font-size: 14px; }
  .stepper button { height: 32px; }
  .chip { padding: 1px 9px; font-size: 13px; }
  .notice { font-size: 13px; padding: 1px 8px; }
  .play { width: 46px; height: 46px; }
  .song { padding-top: 3px; padding-bottom: 3px; }
  .song-title { min-height: 24px; font-size: 15px; }
  .seek input { height: 24px; }
  .info > .stage { flex-basis: 52px; min-height: 52px; }
  .cell { height: 34px; }
  .beat-group .cell { height: 30px; }
  .pk-block .cell { height: 28px; }
  .frame { padding: 2px 6px 5px; }
  .legend { display: none; }
  .recent .legend { display: none; }
  .intro .legend, .page .legend { display: flex; }
  .slot { height: 28px; }
  .pads { height: 122px; }
  .pad { border-radius: 22px; }
  .pad small { font-size: 16px; }
}
@media (max-height: 620px) {
  .meter-note { display: none; }
  .page .meter-note { display: flex; }
  .game .info > .stage { flex-basis: 50px; min-height: 50px; }
  .game .pads { height: 108px; }
  .game .pad { min-height: 96px; }
  .game .info { gap: 4px; }
  .game .legend { display: none; }
}

/* ---------- Màn rộng: 2 cột (iPad ngang, máy tính) ---------- */
@media (min-width: 900px), (orientation: landscape) and (max-height: 520px) and (min-width: 600px) {
  .game {
    max-width: 1360px; padding-left: 24px; padding-right: 24px; gap: 12px 24px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
  }
  .game .top { grid-column: 1 / -1; }
  .pads { height: auto; min-height: 0; padding-bottom: 4px; }
  .pad b { font-size: clamp(34px, 5vw, 66px); }
  .pad small { font-size: 18px; }
  .info > .stage { max-height: 320px; }
}

/* Máy tính có chuột: phần cần nhìn là cột to, nút gõ vừa phải và ghi rõ phím. */
@media (min-width: 900px) and (pointer: fine) {
  .game { grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr); }
  .pads { align-self: center; height: min(60dvh, 480px); }
  .pad kbd { display: inline-block; }
  .pad b { font-size: clamp(30px, 3vw, 48px); }
  .game .cell { height: 60px; font-size: 19px; }
  .game .beat-group .cell { height: 50px; font-size: 16px; }
  .game .pk-block .cell { height: 46px; font-size: 13px; }
  .game .slot { height: 48px; }
  .game .slot i, .game .slot i svg { width: 24px; height: 24px; }
}

@media (min-width: 900px) and (min-height: 700px) {
  .page.home { max-width: 980px; }
  .page.home .cards { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .duckling { animation: none; }
  .sheet { animation: none; }
}

/* ---------- Nút bật/tắt nhiều lựa chọn ---------- */
.toggles { display: flex; flex-wrap: wrap; gap: 5px; }
.toggles button { display: inline-flex; align-items: center; gap: 4px; min-height: 34px; padding: 2px 12px; background: #fff; border: 2px solid var(--line); border-radius: 30px; font-size: 14px; font-weight: 700; color: var(--muted); }
.toggles button[aria-pressed="true"] { background: #E4F5EC; border-color: var(--green); color: var(--green-dark); }
.toggles .mus { font-size: 20px; }
.row-buttons { display: flex; gap: 8px; }
.row-buttons > * { flex: 1 1 0; min-width: 0; padding-left: 6px; padding-right: 6px; font-size: 15px; }
.bottom.row-buttons { background: var(--cream); padding: 4px 0; }
.hint-line { text-align: center; font-size: 13.5px; color: var(--muted); min-height: 18px; }
.status-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.song-item.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.song-item.row small { display: block; }
.song-item small.temp { color: var(--orange-dark); }

/* ---------- Khung theo trường độ ---------- */
.cells.proportional { gap: 2px; }
.cells.proportional .cell { height: 54px; padding: 0; overflow: hidden; }
.cell .label small { display: block; font-size: 11px; font-weight: 800; }
.cell.rest { background: var(--sand); color: var(--muted); }
.cell.dot { border: 2px dashed var(--red-dark); font-size: 22px; }
.cell.dot.hand-D { background: #E9877A; }
.cell.dot.now { border: 3px solid var(--orange); }
.beat-count { display: flex; font-size: 12px; color: var(--muted); text-align: center; }
.beat-count span { flex: 1; border-radius: 8px; }
.beat-count span.now { background: var(--orange); color: var(--ink); }
.frame.with-next { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 3fr); gap: 6px; align-items: start; }
.next-box { border: 2px dashed var(--line); border-radius: 12px; padding: 4px 3px; opacity: .75; }
.cells.proportional .cell.small { height: 52px; border-width: 0; font-size: 12px; }
.cell.small .mus { font-size: 17px; }
.cell.small .label small { font-size: 8.5px; }
.picked { display: flex; flex-wrap: wrap; gap: 4px; }
.picked .chip { font-size: 12px; padding: 0 8px; }
a.chip { text-decoration: none; }
.pad b .mus { font-size: 1.35em; }
.pad.holding.enough { border-color: #35D68F; transform: translateY(4px); box-shadow: 0 0 0 7px #1F9D64; }
.pad.holding.enough::after { content: 'Đủ rồi, thả được!'; padding: 1px 10px; border-radius: 20px; background: #fff; color: var(--green-dark); font-size: 14px; font-weight: 800; }
.pad.holding:not(.enough) { border-color: #FFF; transform: translateY(4px); box-shadow: 0 0 0 5px var(--orange); }

/* ---------- Tháp hình nốt ---------- */
.tower-grid { display: grid; gap: 10px; }
.tower-card { padding: 8px; display: grid; gap: 5px; }
.tower-row { display: grid; grid-template-columns: 62px minmax(0, 1fr); align-items: center; gap: 6px; padding: 3px; border: 2px solid transparent; border-radius: 12px; text-align: left; }
.tower-row .name b { display: block; font-size: 13.5px; line-height: 1.1; }
.tower-row .name small { color: var(--muted); font-size: 12px; }
.tower-row.hinted, .tower-row.playing { border-color: var(--orange); background: var(--orange-soft); }
.bricks { display: flex; gap: 3px; }
.bricks.n16 { gap: 1px; }
.brick { flex: 1 1 0; min-width: 0; height: 40px; display: grid; place-items: center; border: 2px solid #C5D7F3; border-radius: 8px; color: var(--blue-dark); overflow: hidden; }
.brick .mus { font-size: 24px; }
.bricks.n16 .brick .mus { font-size: 18px; }
.brick.now { background: var(--blue); border-color: var(--blue-dark); color: #fff; }
.beat-numbers { display: grid; grid-template-columns: 68px minmax(0, 1fr); gap: 6px; font-size: 12px; color: var(--muted); }
.beat-numbers div { display: flex; text-align: center; }
.beat-numbers div span { flex: 1; }
.quiz { background: #FFF0C4; border-radius: var(--radius); padding: 10px; display: grid; gap: 8px; }
.question { font-size: 19px; font-weight: 800; }
.question .mus { font-size: 28px; }
.answers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.answers button { min-height: 56px; background: #fff; border: 2px solid var(--line); border-radius: 14px; font-size: 26px; font-weight: 800; }
.answers button[aria-pressed="true"] { border-color: var(--orange); background: var(--orange-soft); }
.answers button.right { border-color: var(--green); background: #E4F5EC; color: var(--green-dark); }

/* ---------- Đố hình nốt ---------- */
.ask { background: #FFF0C4; border-radius: 14px; padding: 4px 12px; text-align: center; }
.ask small { display: block; color: var(--muted); font-size: 12px; }
.ask b { font-size: 19px; font-weight: 800; }
.ask em { font-style: normal; color: var(--orange-dark); }
.values .row-buttons .btn { min-height: 42px; }
.long-note { --fill: 0%; display: flex; align-items: center; justify-content: center; gap: 8px; height: 40px; margin-bottom: 5px; border-radius: 10px; color: #6B4E00; background: linear-gradient(90deg, #FFC933 var(--fill), #FFE7A0 var(--fill)); }
.long-note .mus { font-size: 26px; }
.beat-names { display: flex; font-size: 11px; color: var(--muted); }
.beat-names span { flex: 1; }
.beat-names span + span { border-left: 2px solid var(--line); padding-left: 4px; }
.values .frame strong { display: block; text-align: center; font-size: 13px; color: var(--green-dark); }
.values .frame .cells.proportional .cell { height: 44px; }

/* ---------- Chọn tiết tấu trống ---------- */
.drum-setup h3, .dictation h3 { font-size: 15px; }
.preview-card { padding: 8px; display: grid; gap: 6px; }
.preview { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.preview > div { border: 2px solid var(--line); border-radius: 12px; background: var(--cream); padding: 3px; }
.preview > div.now { border-color: var(--orange); }
.nbar { display: flex; height: 52px; align-items: center; }
.nbox { text-align: center; min-width: 0; overflow: hidden; }
.nbox .mus { font-size: 24px; }

/* ---------- Chế độ cả lớp: phóng to cho máy chiếu, không có nút gõ ---------- */
a.btn { text-decoration: none; }
.home-tools .btn.on { border-color: var(--green); background: #E4F5EC; }
.level { height: 12px; border-radius: 12px; background: var(--sand); overflow: hidden; }
.level i { display: block; height: 100%; width: 0; background: var(--green); }
.game.classroom { max-width: 1500px; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
.game.classroom .pads { display: none; }
.game.classroom .top { grid-column: auto; }
.game.classroom .info > .stage { max-height: none; flex-basis: 120px; }
.game.classroom .play { width: 84px; height: 84px; }
.game.classroom .play .icon svg { width: 46px; height: 46px; }
.game.classroom .song-title { font-size: 26px; }
.game.classroom .cell { height: clamp(56px, 11vh, 130px); font-size: clamp(20px, 3.4vw, 46px); }
.game.classroom .cell .mus { font-size: clamp(30px, 4vw, 60px); }
.game.classroom .cell .label small { font-size: clamp(13px, 1.8vw, 24px); }
.game.classroom .beat-group .cell { height: clamp(40px, 7vh, 90px); font-size: clamp(14px, 2.2vw, 32px); }
.game.classroom .beat-group .cell.hand-D .label { font-size: .7em; }
.game.classroom .pk-block .cell { height: clamp(34px, 7vh, 84px); font-size: clamp(11px, 1.8vw, 26px); }
.game.classroom .cell-mark { place-items: start end; padding: 4px; }
.game.classroom .cell-mark svg { width: clamp(26px, 4vw, 56px); height: clamp(26px, 4vw, 56px); }
.game.classroom .frame-label { font-size: 20px; }
.verdict { text-align: center; background: #fff; border: 4px solid var(--line); border-radius: 22px; padding: 4px 12px; font-size: clamp(20px, 3.5vw, 44px); line-height: 1.2; }
.verdict b { display: block; font-weight: 800; }
.verdict span { display: block; font-size: .6em; color: var(--muted); }
.verdict.even { border-color: var(--green); background: #E4F5EC; color: var(--green-dark); }
.verdict.messy { border-color: var(--orange); background: var(--orange-soft); color: var(--orange-dark); }
.game.classroom .count-overlay { min-width: min(55vw, 520px); }
.game.classroom .count-overlay b { font-size: min(40vh, 300px); }
.game.classroom .count-overlay span { font-size: 34px; }

.page .count-overlay.show { display: flex; }

@media (min-width: 900px) {
  .page.tower { max-width: 1100px; }
  .tower-grid { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
}
@media (max-height: 740px) {
  .toggles button { min-height: 28px; padding: 0 9px; font-size: 13px; }
  .cells.proportional .cell { height: 44px; }
  .cells.proportional .cell.small { height: 42px; }
  .long-note { height: 30px; }
  .values .frame .cells.proportional .cell { height: 34px; }
  .brick { height: 34px; }
  .values .hint-line { display: none; }
  .game.classroom .info > .stage { flex-basis: 70px; min-height: 60px; }
  .game.classroom .play { width: 64px; height: 64px; }
}

/* Ô hẹp (móc kép) thì chữ nhỏ lại, không chồng lên nhau. */
.cells.proportional .cell { container-type: inline-size; }
.frame.with-next { grid-template-columns: minmax(0, 13fr) minmax(0, 7fr); }
@container (max-width: 28px) { .cell .label small { font-size: 8px; letter-spacing: -.4px; } .cell .label .mus { font-size: 18px; } }
@container (max-width: 17px) { .cell .label small { font-size: 6.5px; } .cell .label .mus { font-size: 14px; } }
.game.classroom .say .bubble { font-size: clamp(14px, 2.2vw, 28px); }

/* ---------- Số chỉ nhịp trong danh sách bài ---------- */
.sig { flex: none; display: grid; justify-items: center; width: 38px; padding: 2px 0; border-radius: 10px; background: #EAF2FD; color: var(--blue-dark); font-size: 20px; line-height: .95; }
.sig b { font-weight: 800; }
.sig b + b { width: 20px; text-align: center; border-top: 2px solid currentColor; }

/* ---------- Cả lớp: phản hồi ngay từng tiếng gõ ---------- */
.class-status { display: flex; align-items: stretch; gap: 8px; }
.class-status .verdict { flex: 1; }
.live { flex: none; width: clamp(96px, 16vw, 240px); display: grid; place-items: center; text-align: center; border-radius: 22px; background: var(--sand); border: 4px solid var(--line); color: var(--muted); font-size: clamp(18px, 3vw, 40px); font-weight: 800; }
.live.ok { background: var(--green-dark); border-color: var(--green-dark); color: #fff; }
.live.near { background: #F5B82E; border-color: #A87708; color: var(--ink); }
.live.off { background: #fff; border-color: var(--red-dark); color: var(--red-dark); }
.live.pulse { animation: live-pulse .2s ease-out; }
@keyframes live-pulse { 40% { transform: scale(1.09); } }

/* ---------- Ô lấy đà ---------- */
.cells.proportional .cell.empty { background: #FFF8E7; border: 2px dashed var(--line); color: var(--muted); }
.cells.proportional .cell.lead { background: var(--orange); color: var(--ink); }
.cells.proportional .cell.empty.now, .cells.proportional .cell.lead.now { border: 3px solid var(--orange); }
.cells.proportional .cell.lead.now { border-color: var(--ink); }
.frame.is-pickup .measure-box { border-style: dashed; border-color: var(--orange); }
.frame.is-pickup .rhythm-main .frame-label { color: var(--orange-dark); }
/* Số đếm vào đặt cao hơn để không che ô lấy đà. */
.game:has(.frame.is-pickup) .count-overlay { top: 24%; }

/* ---------- Đố hình nốt: bộ lọc gọn ---------- */
.filter { display: flex; align-items: center; gap: 6px; min-height: 38px; padding: 2px 12px; background: #fff; border: 2px solid var(--line); border-radius: 30px; font-size: 14px; font-weight: 700; text-align: left; }
.filter .grow { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--green-dark); }
.filter b { color: var(--orange-dark); white-space: nowrap; }
.filter-sheet .toggles .mus { letter-spacing: -2px; }
.long-note small { font-weight: 800; }
.cell .mus sup { font-family: 'Baloo 2', sans-serif; font-size: 11px; font-weight: 800; }

/* ---------- Chơi trống: trang khởi đầu ---------- */
.drum-setup { gap: 9px; }
.song-current { width: 100%; }
.drum-panel { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.preview-row { display: flex; gap: 6px; align-items: stretch; min-width: 0; }
.preview-row .preview { flex: 1; min-width: 0; }
.preview-lead { flex: none; width: 56px; display: flex; flex-direction: column; justify-content: center; text-align: center; border: 2px dashed var(--orange); border-radius: 12px; background: var(--orange-soft); color: var(--orange-dark); }
.preview-lead .nbar { height: 36px; }
.bar-strip { display: flex; gap: 5px; overflow-x: auto; padding: 3px; }
.bar-strip button { flex: none; width: 40px; height: 40px; border-radius: 12px; background: #fff; border: 2px dashed var(--line); font-weight: 800; color: var(--muted); }
.bar-strip button.done { border-style: solid; border-color: var(--green); background: #E4F5EC; color: var(--green-dark); }
.bar-strip button.partial { border-style: solid; border-color: var(--orange); background: var(--orange-soft); color: var(--orange-dark); }
.bar-strip button[aria-current="true"] { box-shadow: 0 0 0 3px var(--ink); }
.compose { display: flex; gap: 3px; padding: 4px; border: 3px solid #FFD29E; border-radius: 14px; background: #fff; }
.compose .cell { height: 52px; overflow: hidden; }
.compose .cell.empty { background: var(--cream); border: 2px dashed var(--orange); color: var(--orange-dark); font-size: 13px; }
.palette { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.palette button { min-width: 0; min-height: 52px; display: grid; place-items: center; align-content: center; padding: 1px 2px; border-radius: 12px; }
.palette .mus { font-size: 22px; letter-spacing: -2px; white-space: nowrap; }
.palette small { font-size: 10px; color: var(--muted); line-height: 1.1; }
.palette button:disabled { opacity: .3; }
.drum-bottom { background: var(--cream); padding-top: 2px; }
.drum-bottom .hint-line:empty { display: none; }
.picked .chip { max-width: 100%; }

/* ---------- Chép nhịp ---------- */
.dictation { gap: 9px; }
.dictation h3 { font-size: 15px; }
.hud { display: flex; align-items: center; gap: 12px; padding: 7px 10px; }
.hud-lives { flex: none; display: grid; justify-items: center; }
.hud-lives small { font-size: 12px; font-weight: 800; color: var(--muted); white-space: nowrap; }
.hud-lives small.danger { color: var(--red-dark); }
.hearts { display: flex; gap: 4px; }
.heart { display: block; width: 32px; height: 30px; }
.heart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.heart.full .shape { fill: var(--red); stroke: var(--red-dark); stroke-width: 2.4; }
.heart.empty .shape { fill: #EFEAE0; stroke: #A99C80; stroke-width: 2.4; stroke-dasharray: 5 3; }
.heart .crack { stroke: #7C6F55; stroke-width: 2.6; stroke-linejoin: round; stroke-linecap: round; }
.heart.breaking { animation: heart-break .9s ease-out 2; }
@keyframes heart-break { 20% { transform: scale(1.5) rotate(-14deg); } 40% { transform: scale(1.25) rotate(12deg); } 60% { transform: scale(1.1) rotate(-6deg); } }
.hud-progress { flex: 1; min-width: 0; display: grid; justify-items: center; gap: 3px; font-size: 14px; }
.progress { display: flex; gap: 3px; width: 100%; max-width: 160px; }
.progress i { flex: 1; height: 9px; border-radius: 9px; background: var(--sand); }
.progress i.now { background: var(--orange); }
.progress i.right { background: var(--green); }
.progress i.wrong { background: var(--red); }
.rules-button { flex: none; display: grid; justify-items: center; line-height: 1.05; }
.rules-button b { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: #EAF2FD; border: 2px solid var(--blue); color: var(--blue-dark); font-size: 17px; }
.rules-button small { font-size: 10px; color: var(--blue-dark); }
.dictation .guess-player { padding: 7px 10px; gap: 10px; }
.dictation .guess-player b { font-size: 17px; line-height: 1.15; }
.dictation .guess-player small { display: block; font-size: 12px; line-height: 1.15; }
.dictation .guess-player .switch { width: auto; flex: none; flex-direction: column; gap: 2px; min-height: 0; padding: 0; border: 0; font-size: 11px; color: var(--muted); }
.dictation .guess-player .switch i { transform: scale(.85); }
.play.call { animation: call 1.2s ease-in-out infinite; }
@keyframes call { 50% { box-shadow: 0 4px 0 var(--orange-dark), 0 0 0 8px rgba(242, 140, 40, .3); } }
.sheet-music { padding: 7px 8px 6px; display: grid; gap: 5px; }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.board { display: flex; gap: 6px; background: var(--orange-soft); border: 3px solid transparent; border-radius: 16px; padding: 5px; }
.board.right { background: #E4F5EC; border-color: var(--green); }
.board.wrong { background: #FCE0DC; border-color: var(--red); animation: shake .45s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
.slot-note { display: grid; place-items: center; min-width: 0; height: 70px; background: #fff; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; text-align: center; }
.slot-note .mus { font-size: 30px; letter-spacing: -2px; }
.slot-note.blank { border: 3px dashed var(--orange); color: var(--orange-dark); }
.slot-note.filled { border: 3px solid var(--orange); }
.board.right .slot-note.filled { border-color: var(--green); color: var(--green-dark); }
.board.wrong .slot-note.filled { border-color: var(--red); color: var(--red-dark); }
.tokens { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.tokens button { min-height: 64px; display: grid; place-items: center; align-content: center; padding: 3px; }
.tokens button:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.tokens .mus { font-size: 28px; letter-spacing: -2px; }
.tokens small { font-size: 12px; color: var(--muted); }
.tokens button:disabled { opacity: .3; }
.feedback-line { min-height: 28px; display: grid; place-items: center; text-align: center; border-radius: 12px; font-size: 15px; font-weight: 800; line-height: 1.15; }
.feedback-line.right { background: var(--green-dark); color: #fff; }
.feedback-line.wrong { background: var(--red-dark); color: #fff; }
.life-lost { position: fixed; z-index: 30; left: 50%; top: 42%; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 0; min-width: 200px; padding: 16px 24px 12px; background: #fff; border: 5px solid var(--red); border-radius: 36px; box-shadow: 0 12px 40px #0004; pointer-events: none; opacity: 0; visibility: hidden; }
.life-lost.show { animation: life-lost 1.5s ease forwards; }
@keyframes life-lost { 0% { opacity: 0; visibility: visible; transform: translate(-50%, -50%) scale(.7); } 12%, 80% { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; visibility: hidden; transform: translate(-50%, -62%) scale(.96); } }
.life-lost .heart { width: 84px; height: 78px; }
.life-lost b { font-size: 32px; font-weight: 800; color: var(--red-dark); }
.life-lost span:last-child { font-weight: 800; color: var(--muted); }
.rule-steps { padding-left: 22px; display: grid; gap: 6px; }
.rule-lives { display: flex; align-items: center; gap: 10px; padding: 10px; background: #FCE0DC; border-radius: 14px; }
.rule-lives .heart { width: 28px; height: 26px; }
.answer-key { display: grid; gap: 4px; text-align: center; }
.answer-key .slot-note { height: 56px; }

@media (max-height: 740px) {
  .drum-setup { gap: 6px; padding-top: calc(6px + var(--safe-top)); }
  .drum-setup .song-current { padding-top: 3px; padding-bottom: 3px; }
  .drum-setup .notice { font-size: 12.5px; }
  .compose .cell { height: 42px; }
  .bar-strip button { width: 34px; height: 34px; }
  .palette button { min-height: 44px; }
  .palette .mus { font-size: 19px; }
  .drum-setup .btn { min-height: 42px; }
  .drum-setup .btn.wide { min-height: 48px; }
  .dictation { gap: 5px; padding-top: calc(6px + var(--safe-top)); }
  .dictation .segmented { flex: none; }
  .hud { padding: 3px 8px; }
  .heart { width: 28px; height: 26px; }
  .dictation .guess-player { padding: 3px 10px; }
  .sheet-music { padding: 3px 6px 4px; gap: 3px; }
  .slot-note { height: 46px; }
  .dictation .tokens { gap: 5px; }
  .dictation .tokens button { min-height: 50px; }
  .dictation .tokens .mus { font-size: 23px; }
  .dictation .bottom .btn { min-height: 42px; line-height: 1.1; }
  .dictation .meter-note { display: none; }
}

/* ---------- Ao vịt ---------- */
.rays { animation: spin 24s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.cloud { animation: drift 14s ease-in-out infinite alternate; }
@keyframes drift { to { transform: translateX(26px); } }
.crown { transform-box: fill-box; transform-origin: bottom center; animation: sway 4.5s ease-in-out infinite alternate; }
@keyframes sway { from { transform: rotate(-2.5deg); } to { transform: rotate(2.5deg); } }
.eye { transform-box: fill-box; transform-origin: center; animation: eye-blink 4.2s infinite; }
@keyframes eye-blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.12); } }
@media (prefers-reduced-motion: reduce) { .rays, .cloud, .crown, .eye { animation: none; } }

/* ---------- Cảnh báo từng lần gõ ---------- */
.judge-pop { position: absolute; z-index: 3; left: 50%; bottom: 6px; transform: translateX(-50%); white-space: nowrap; padding: 2px 14px; border-radius: 30px; font-weight: 800; font-size: 16px; box-shadow: 0 3px 10px #0003; opacity: 0; pointer-events: none; }
.judge-pop.show { animation: judge-pop 1.1s ease forwards; }
.judge-pop.ok { background: var(--green-dark); color: #fff; }
.judge-pop.near { background: #FFD23F; color: var(--ink); }
.judge-pop.off { background: #fff; color: var(--red-dark); border: 2px solid var(--red-dark); }
@keyframes judge-pop { 0% { opacity: 0; transform: translate(-50%, 8px) scale(.8); } 12%, 70% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -6px) scale(1); } }

/* ---------- Chúc mừng ---------- */
.confetti { position: fixed; inset: 0; z-index: 65; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -16px; width: 10px; height: 15px; border-radius: 3px; animation: fall 2s ease-in forwards; }
@keyframes fall { to { transform: translate(var(--drift), 105vh) rotate(620deg); opacity: .7; } }
.result .sheet-actions { grid-auto-flow: row; gap: 8px; }

/* ---------- Đố hình nốt ---------- */
.ask .ratio { font-size: 12.5px; color: var(--blue-dark); font-weight: 800; }
.ask .ratio .mus { font-size: 17px; letter-spacing: -2px; }
.values .tempo-row .meter-note { flex: 1; min-width: 0; white-space: normal; text-align: left; font-size: 10px; line-height: 1.2; }
.values .stage { position: relative; }
.attempts { display: flex; align-items: center; gap: 8px; padding: 4px 10px; font-size: 12.5px; color: var(--muted); }
.attempts b { font-size: 17px; color: var(--ink); }
.attempts > span, .attempts > small { white-space: nowrap; }
.try-slots { flex: 1; display: flex; gap: 3px; min-width: 0; }
.try-slots i { flex: 1; min-width: 0; height: 22px; display: grid; place-items: center; border-radius: 7px; background: var(--sand); font-style: normal; font-size: 10.5px; font-weight: 800; }
.try-slots i.pass { background: var(--green-dark); color: #fff; }
.try-slots i.fail { background: #FFE2B8; color: var(--orange-dark); border: 2px solid var(--orange); }
.beat-names span { text-align: center; border-radius: 6px; }
.beat-names span.now { background: var(--orange); color: var(--ink); font-weight: 800; }
.pair-count { text-align: center; font-size: 13.5px; font-weight: 800; color: var(--green-dark); background: #E4F5EC; border-radius: 12px; padding: 4px 8px; }
.pair-count.bad { color: var(--red-dark); background: #FCE0DC; }
.held-side .toggles button[aria-pressed="true"] { background: #FFE7A0; border-color: #C98A22; color: #6B4E00; }
@media (max-height: 740px) {
  .values .ask { padding: 2px 10px; }
  .values .ask b { font-size: 16px; line-height: 1.15; }
  .values .attempts { padding: 2px 8px; }
  .values .try-slots i { height: 18px; }
  .values .row-buttons .btn { min-height: 38px; }
  .values .info > .stage { flex-basis: 40px; min-height: 40px; }
}
@media (max-height: 620px) { .values .tempo-row .meter-note { visibility: hidden; } }

/* ---------- Vịt ở các màn trả lời ---------- */
.page-stage { position: relative; flex: 1 1 84px; min-height: 76px; max-height: 210px; }
.page.intro .page-stage { flex: none; height: 130px; }
@media (max-height: 740px) {
  .page-stage { flex-basis: 60px; min-height: 56px; }
  .tower .brick { height: 28px; }
  .tower .tower-row { padding: 1px 3px; }
  .tower .tower-card { gap: 2px; padding: 5px 8px; }
  .page.tower, .page.guess { gap: 7px; }
  .guess .option { min-height: 52px; }
  .tower .answers button { min-height: 44px; }
  .tower .quiz { gap: 4px; padding: 7px 10px; }
}

/* ---------- Tiểu cảnh lúc chưa chơi ---------- */
.scene { cursor: pointer; }
.scene.busy .idle-only { display: none; }
.scene:not(.busy):not(.pond) .duckling { animation: paddle 5s ease-in-out infinite; }
@keyframes paddle { 25% { transform: translate(-9px, 3px) rotate(-4deg); } 50% { transform: translate(0, 0); } 75% { transform: translate(9px, 3px) rotate(4deg); } }
.butterfly { animation: flutter 9s ease-in-out infinite; }
@keyframes flutter { 20% { transform: translate(26px, -14px) rotate(12deg); } 45% { transform: translate(48px, 8px) rotate(-8deg); } 70% { transform: translate(14px, 18px) rotate(10deg); } }
.wings { transform-box: fill-box; transform-origin: center; animation: flap .32s ease-in-out infinite alternate; }
@keyframes flap { to { transform: scaleX(.35); } }
.frog { animation: hop 4.8s ease-in-out infinite; }
@keyframes hop { 0%, 72%, 90%, 100% { transform: translate(0, 0); } 77% { transform: translate(0, 2px) scale(1.08, .86); } 83% { transform: translate(0, -18px) scale(.95, 1.08); } }
.fish { opacity: 0; animation: leap 6.5s ease-in-out infinite; }
@keyframes leap { 0%, 58% { opacity: 0; transform: translate(-26px, 8px) rotate(-60deg); } 62% { opacity: 1; } 70% { opacity: 1; transform: translate(0, -34px) rotate(0); } 78% { opacity: 1; } 82%, 100% { opacity: 0; transform: translate(26px, 8px) rotate(60deg); } }
.hum { opacity: 0; animation: hum 3.4s ease-out infinite; }
@keyframes hum { 0% { opacity: 0; transform: translate(0, 10px); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(14px, -30px); } }
@media (prefers-reduced-motion: reduce) {
  .scene:not(.busy):not(.pond) .duckling, .butterfly, .wings, .frog, .fish, .hum { animation: none; }
}
@media (max-height: 620px) {
  .dictation { gap: 3px; }
  .dictation .page-stage, .guess .page-stage { flex-basis: 42px; min-height: 42px; }
  .dictation .slot-note { height: 36px; }
  .dictation .tokens { gap: 3px; }
  .dictation .tokens button { min-height: 40px; }
  .dictation .tokens small { font-size: 10px; line-height: 1; }
  .dictation .tokens .mus { font-size: 20px; }
  .dictation .feedback-line { min-height: 18px; font-size: 13px; }
  .dictation .segmented button { min-height: 26px; }
  .page.guess { gap: 4px; }
  .guess .option { min-height: 44px; padding-top: 2px; padding-bottom: 2px; }
  .guess .bubble { font-size: 13px; padding: 4px 8px; }
  .game .pk-block .cell { height: 24px; }
}
@media (max-height: 620px) { .say { max-width: 44%; top: 2px; right: 2px; } .say .bubble { font-size: 10.5px; padding: 2px 6px; line-height: 1.1; } }
