:root {
  --bg: #120f0c;
  --bg2: #1a1511;
  --panel: #221c16;
  --ink: #f3ece3;
  --muted: #b7a894;
  --line: rgba(243, 236, 227, 0.1);
  --copper: #c9854a;
  --copper2: #e2b07a;
  --ivory: #f7f1e6;
  --ivory2: #e7dccb;
  --ebony: #161310;
  --felt: #7a2430;
  --good: #d7c4a3;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100%;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(1200px 500px at 50% -10%, #3a2a1c 0%, transparent 55%),
    linear-gradient(180deg, var(--bg2), var(--bg));
  -webkit-font-smoothing: antialiased;
}

.wrap {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 48px;
}
.wrap.intro {
  padding-bottom: 8px;
}
.wrap:not(.intro) {
  padding-top: 10px;
}

header {
  text-align: center;
  margin-bottom: 28px;
}
.brand {
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: var(--copper2);
  margin: 0 0 6px;
}
.build {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
}
h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(36px, 6vw, 54px);
  letter-spacing: -0.03em;
  margin: 0 0 8px;
}
.lede {
  margin: 0;
  color: var(--muted);
  font-size: 17px;
}

.piano-shell {
  width: calc(100% - 24px);
  max-width: 2400px;
  margin: 8px auto 18px;
  background: linear-gradient(180deg, #4a3424 0%, #2a1c14 100%);
  border-radius: 16px;
  padding: 16px 12px 14px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.14);
}
.felt {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, #5c1b24, var(--felt), #5c1b24);
  margin: 0 6px 10px;
}
.piano-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(201,133,74,.55) transparent;
  -webkit-overflow-scrolling: touch;
}
.piano {
  --ww: 44px;
  --bw: 28px;
  position: relative;
  height: 188px;
  user-select: none;
}
.whites {
  display: flex;
  height: 100%;
}
.white {
  position: relative;
  flex: 0 0 var(--ww);
  width: var(--ww);
  border: 0;
  border-radius: 0 0 7px 7px;
  background: linear-gradient(180deg, var(--ivory) 0%, var(--ivory2) 100%);
  color: #6d6256;
  font: 700 12px/1 var(--sans);
  padding-top: 148px;
  box-shadow: inset -1px 0 0 rgba(80, 50, 20, 0.12), inset 0 -10px 16px rgba(80, 50, 20, 0.1), 0 8px 0 #c4b49a;
  cursor: pointer;
}
.white .letter {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 32px;
  text-align: center;
  font-size: var(--ls, 13px);
  font-weight: 800;
  letter-spacing: 0;
  color: #3a220c;
}
.white.octave { color: #5a3a18; font-weight: 700; }
.white:hover { filter: brightness(1.03); }
.white.home {
  box-shadow: inset -1px 0 0 rgba(80, 50, 20, 0.12), inset 0 0 0 2px rgba(201, 133, 74, 0.45), 0 8px 0 #c4b49a;
}
.white.selected {
  background: linear-gradient(180deg, #fff8ee, #f0d8b0);
  color: #5a3a18;
  box-shadow: inset 0 0 0 2px var(--copper), 0 6px 0 #c4b49a;
}
.white.on {
  background: linear-gradient(180deg, #ffe2b0, #e09a48);
  color: #3a220c;
  box-shadow: inset 0 0 0 2px #c9854a, 0 6px 0 #b07d3c;
}
.white.under {
  background: linear-gradient(180deg, #f3e6cf, #dfc9a4);
  box-shadow: inset -1px 0 0 rgba(80, 50, 20, 0.12), inset 0 0 0 1px rgba(201, 133, 74, 0.35), 0 8px 0 #c4b49a;
}
.black.under {
  background: linear-gradient(180deg, #5a4a3a, #2a2018);
  box-shadow: inset 0 0 0 1px rgba(226, 176, 122, 0.4), 0 8px 10px rgba(0,0,0,.35);
}
.white:active { transform: translateY(2px); box-shadow: 0 4px 0 #c4b49a; }
.white.next {
  background: linear-gradient(180deg, #f0b56a, #d98a3a) !important;
  color: #2a1606;
  box-shadow: inset 0 0 0 3px var(--copper2), 0 0 0 4px rgba(232, 162, 74, 0.55), 0 6px 0 #8a5a2a;
}
.white.next-legacy {
  background: linear-gradient(180deg, #fff3dc, #f3c98a);
  color: #3a220c;
  box-shadow: inset 0 0 0 3px var(--copper), 0 0 0 3px rgba(226, 176, 122, 0.45), 0 6px 0 #b07d3c;
  animation: nextPulse 1.1s ease-in-out infinite;
}
.white.wrong, .black.wrong {
  animation: wrongShake 0.3s ease;
  box-shadow: inset 0 0 0 3px #b23b3b !important;
}
@keyframes nextPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.16); }
}
@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
.blacks { position: absolute; inset: 0 0 38% 0; pointer-events: none; }
.black {
  pointer-events: auto;
  position: absolute;
  top: 0;
  width: var(--bw);
  height: 100%;
  border: 0;
  border-radius: 0 0 5px 5px;
  background: linear-gradient(180deg, #3a342e, var(--ebony));
  color: transparent;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 8px 10px rgba(0,0,0,.35);
  cursor: pointer;
}
.black .letter {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  text-align: center;
  color: #ffe2b0;
  font: 800 var(--ls, 12px)/1 var(--sans);
  letter-spacing: 0;
}
.black.home { box-shadow: inset 0 0 0 2px rgba(226, 176, 122, 0.55); }
.black.selected {
  background: linear-gradient(180deg, #6a4a2a, #2a1a10);
  box-shadow: inset 0 0 0 2px var(--copper2);
}
.black.on {
  background: linear-gradient(180deg, #c9854a, #5a3010);
  box-shadow: inset 0 0 0 2px var(--copper2);
}
.black:active { transform: translateY(1px); }
.black.next {
  background: linear-gradient(180deg, #e2b07a, #8a5a2a);
  box-shadow: inset 0 0 0 3px var(--copper2), 0 0 0 4px rgba(232, 162, 74, 0.55), 0 8px 10px rgba(0,0,0,.35);
  animation: nextPulse 1.1s ease-in-out infinite;
}
.white.mapped .letter, .black.mapped .letter { opacity: 1; }

.key-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
  padding: 2px 4px 0;
}
.octave-btns {
  display: flex;
  align-items: center;
  gap: 10px;
}
.auto-chords {
  display: flex;
  align-items: center;
  gap: 10px;
}
.auto-chords .opt-label { margin: 0; color: var(--ivory); }
.auto-chords .seg { min-width: 150px; }
.octave-btns p {
  margin: 0;
  color: var(--ivory);
  font-size: 14px;
}
.octave-btns strong {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 400;
}
.octave-btns button {
  border: 1px solid rgba(243, 236, 227, 0.18);
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  font: 600 13px/1 var(--sans);
  cursor: pointer;
}
.octave-btns button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.comp-shell {
  width: min(calc(100% - 24px), 1100px);
  margin: 8px auto 22px;
  background: linear-gradient(180deg, #2a231c, var(--panel));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 18px 16px;
}
.comp-ask {
  text-align: center;
  margin-bottom: 14px;
}
.comp-ask-q {
  font-family: var(--serif);
  font-size: 22px;
  margin: 0 0 10px;
}
.comp-ask .seg {
  max-width: 420px;
  margin: 0 auto;
}
.seg.big button {
  font-size: 15px;
  padding: 12px 10px;
}
.comp-ask-h {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
}
.comp-lede {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  line-height: 1.45;
}
.comp-scroll {
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: thin;
}
.comp-board {
  min-width: 760px;
  background: #161310;
  border-radius: 14px;
  padding: 16px 14px 14px;
}
.ckey-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 6px;
}
.ckey {
  box-sizing: border-box;
  min-width: 54px;
  height: 70px;
  margin: 0;
  border: 1px solid rgba(243, 236, 227, 0.12);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  padding: 6px 7px 8px;
  cursor: pointer;
  user-select: none;
  text-align: left;
  color: var(--ink);
  background: #2a241c;
}
.comp-board.mac .ckey { border-radius: 10px; }
.comp-board.pc .ckey { border-radius: 5px; }
.ckey-letter {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  opacity: 0.72;
}
.ckey-note {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 400;
  line-height: 1;
  align-self: flex-end;
}
.ckey-shift {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0.8;
  align-self: flex-end;
}
.ckey.natural {
  background: linear-gradient(180deg, #f7f1e6, #e7dccb);
  color: #1a110a;
  border-color: rgba(80, 50, 20, 0.18);
}
.ckey.sharp {
  background: linear-gradient(180deg, #3a342e, #161310);
  color: #f0d8b0;
}
.ckey.action {
  background: linear-gradient(180deg, var(--copper2), var(--copper));
  color: #1a110a;
  border: 0;
}
.ckey.dim {
  opacity: 0.42;
  cursor: default;
  min-width: 46px;
  height: 52px;
  align-self: flex-end;
}
.ckey.wide { min-width: 280px; align-items: center; }
.ckey.wide .ckey-note { align-self: center; }
.ckey.enter { min-width: 92px; }
.ckey.hit {
  box-shadow: 0 0 0 2px var(--copper2);
  filter: brightness(1.08);
}
.ckey.next {
  box-shadow: 0 0 0 3px var(--copper2), 0 0 18px rgba(226, 176, 122, 0.55);
  animation: nextPulse 1.1s ease-in-out infinite;
}
.ckey-spacer { width: 28px; flex: 0 0 28px; }
.ckey-spacer.lg { width: 44px; flex: 0 0 44px; }
.letter-layout {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.letter-layout .seg { min-width: 240px; }

.home-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 2px 22px;
  color: var(--muted);
  font-size: 14px;
}
.home-row strong {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 400;
}

.songs-wrap { padding-top: 4px; padding-bottom: 8px; }
.songs { margin: 0 2px 14px; }
.song-opts {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 14px;
  margin: 0 2px 4px;
  align-items: end;
}
.song-speed .seg { max-width: 520px; }
.learn-btn {
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 10px 12px;
  font: 700 13px/1 var(--sans);
  background: linear-gradient(180deg, var(--copper2), var(--copper));
  color: #1a110a;
  cursor: pointer;
}
.learn-btn:disabled { opacity: 1; cursor: not-allowed; background: rgba(201, 133, 74, 0.22); color: var(--copper2); border: 1px solid rgba(226, 176, 122, 0.5); }
.learn-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin: 12px 2px 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(226, 176, 122, 0.55);
  background: rgba(201, 133, 74, 0.12);
}
.learn-bar[hidden] { display: none; }
.learn-bar.done {
  border-color: rgba(215, 196, 163, 0.7);
  background: rgba(215, 196, 163, 0.12);
}
.learn-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.learn-text strong { font-family: var(--serif); font-weight: 400; font-size: 18px; }
.learn-text span { color: var(--ink); font-size: 14px; line-height: 1.4; }
.learn-actions { display: flex; gap: 8px; }
.learn-actions button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 12px;
  font: 600 13px/1 var(--sans);
  cursor: pointer;
}
.learn-actions button:hover { border-color: rgba(201, 133, 74, .55); }
.songs-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.song-chip {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.05);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 12px;
  font: 600 13px/1 var(--sans);
  cursor: pointer;
}
.song-chip:hover { border-color: rgba(201, 133, 74, .55); }
.song-chip.on {
  background: linear-gradient(180deg, var(--copper2), var(--copper));
  color: #1a110a;
  border-color: transparent;
}

.opts {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
.opt-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.seg {
  display: flex;
  background: rgba(0,0,0,.28);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 600 13px/1 var(--sans);
  padding: 9px 6px;
  border-radius: 999px;
  cursor: pointer;
}
.seg button.on {
  background: linear-gradient(180deg, var(--copper2), var(--copper));
  color: #1a110a;
}

.vol-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 2px 16px;
  color: var(--muted);
  font-size: 13px;
}
.vol-row label { letter-spacing: 0.12em; text-transform: uppercase; font-size: 11px; }
.vol-row input[type="range"] {
  flex: 1;
  accent-color: var(--copper);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 22px;
}
.actions button {
  border: 0;
  cursor: pointer;
  border-radius: 12px;
  font: 700 15px/1 var(--sans);
  padding: 14px 14px;
}
.actions button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}
#btnWrite {
  flex: 1.6 1 140px;
  background: linear-gradient(180deg, var(--copper2), var(--copper));
  color: #1a110a;
  box-shadow: 0 10px 24px rgba(201, 133, 74, 0.28);
}
#btnWrite.busy { filter: saturate(0.7); }
#btnPlay, #btnSaveWav, #btnSaveMid, #btnCopy, #btnLoop, #btnRec {
  flex: 1 1 110px;
  background: rgba(255,255,255,.06);
  color: var(--ink);
  border: 1px solid var(--line);
}
#btnLoop, #btnRec { flex: 0 1 96px; }
#btnLoop.on {
  background: rgba(201, 133, 74, 0.22);
  border-color: rgba(226, 176, 122, 0.7);
  color: var(--copper2);
}
#btnRec::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #c9503f;
  margin-right: 7px;
  vertical-align: -1px;
}
#btnRec.rec {
  background: rgba(178, 59, 59, 0.22);
  border-color: rgba(226, 120, 110, 0.7);
  color: #ffd9d2;
}
#btnRec.rec::before { animation: recBlink 1s steps(1) infinite; }
@keyframes recBlink { 50% { opacity: 0.25; } }
.kind-learn { color: #ffe2b0; }
.kind-record { color: #ffb8ad; }
.chord { cursor: pointer; }
.chord:hover { border-color: rgba(201, 133, 74, .45); }

.recents { margin-top: 16px; }
.activity {
  margin-top: 28px;
  background: linear-gradient(180deg, #2a231c, var(--panel));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
}
.log-toggle {
  display: inline-block;
  margin: 2px 0 0;
  border: 1px solid rgba(243, 236, 227, 0.18);
  background: rgba(0, 0, 0, 0.22);
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 14px;
  font: 600 13px/1 var(--sans);
  cursor: pointer;
}
.log-toggle:hover { border-color: rgba(201, 133, 74, .55); }
.log-toggle[aria-expanded="true"] { margin-bottom: 12px; }
.activity-body[hidden] { display: none; }
.activity h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 22px;
  margin: 0 0 4px;
}
.activity-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.activity-lede {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}
#logCount {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  padding-top: 6px;
}
.keymap {
  margin: 0 0 14px;
  padding: 12px;
  background: rgba(0,0,0,.22);
  border-radius: 12px;
}
.keymap-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}
.kpair {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  background: rgba(255,255,255,.04);
}
.kpair .note {
  font-family: var(--serif);
  color: var(--ink);
}
.kpair.sharp {
  background: #161310;
}
.kpair.sharp .note { color: var(--copper2); }
.keymap-help {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.log-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.log-actions button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 12px;
  font: 600 13px/1 var(--sans);
  cursor: pointer;
}
.log-actions button:hover { border-color: rgba(201, 133, 74, .55); }
.activity-log {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  max-height: 280px;
  overflow: auto;
  background: #100d0b;
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  min-height: 88px;
  scrollbar-width: thin;
}
.log-row {
  color: var(--good);
  white-space: pre-wrap;
  word-break: break-word;
}
.kind-key { color: var(--copper2); }
.kind-piano { color: var(--ink); }
.kind-write, .kind-play { color: #f0d8b0; }
.kind-button { color: #e2b07a; }
.kind-session, .kind-log { color: var(--muted); }
.kind-option, .kind-volume { color: #c9b89a; }
.kind-chord, .kind-recent { color: #d7c4a3; }
.recents-label {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.recents-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.recent {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 12px;
  font: 600 13px/1 var(--sans);
  cursor: pointer;
}
.recent:hover { border-color: rgba(201, 133, 74, .55); }

.sheet {
  background: linear-gradient(180deg, #2a231c, var(--panel));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 18px 16px;
  min-height: 148px;
}
#status {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}
.progress {
  height: 3px;
  background: rgba(255,255,255,.08);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 14px;
}
#progressFill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--copper), var(--copper2));
}
.chords {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
  padding-bottom: 4px;
}
.chords.empty { display: none; }
.chord {
  flex: 0 0 calc((100% - 56px) / 8);
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 6px;
  text-align: center;
  scroll-snap-align: center;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.chord.now {
  transform: translateY(-2px);
  border-color: rgba(201, 133, 74, .7);
  background: rgba(201, 133, 74, .14);
}
.chords.melody .chord {
  flex: 0 0 56px;
  padding: 10px 4px;
}
.chords.melody .sym { font-size: 18px; }
.sym {
  font-family: var(--serif);
  font-size: clamp(20px, 4vw, 28px);
  line-height: 1.1;
}
.sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}
#sentence { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
#saveHint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

footer {
  margin-top: 26px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
kbd {
  font: 600 11px var(--sans);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--good);
}

@media (max-width: 620px) {
  .wrap { width: min(100% - 20px, 760px); padding-top: 22px; }
  .piano-shell { width: calc(100% - 16px); padding: 12px 8px 10px; }
  .piano { height: 150px; }
  .white { padding-top: 114px; font-size: 11px; }
  .white .letter { bottom: 26px; }
  .black .letter { font-size: 11px; }
  .opts { grid-template-columns: 1fr; }
  .song-opts { grid-template-columns: 1fr; }
  .actions { flex-direction: column; }
  .chord { flex-basis: calc((100% - 8px) / 2); }
  .activity-head { flex-direction: column; }
  .keymap-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .key-bar { flex-direction: column; align-items: stretch; }
  .octave-btns { justify-content: space-between; }
  .comp-shell { width: calc(100% - 16px); padding: 14px 12px; }
  .ckey { min-width: 50px; height: 58px; }
  .ckey-note { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .chord, .white, .black { transition: none; }
  .white.next, .black.next, .ckey.next, .white.wrong, .black.wrong { animation: none; }
  #btnRec.rec::before { animation: none; }
}

/* ===== Touch devices (iPhone / iPad / Android). Desktop is untouched: everything is under html.touch / html.phone. ===== */
.touch-only { display: none; }
html.touch .kb-only { display: none !important; }
html.touch .touch-only { display: block; }
html.touch .octave-btns .touch-only { margin: 0; color: var(--ivory); font-size: 13px; }
html.touch .comp-shell { display: none; }
html.touch body { -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
html.touch button, html.touch .seg, html.touch .song-chip, html.touch .chord, html.touch .recent { touch-action: manipulation; }
html.touch .piano { touch-action: pan-x; }
html.touch .piano-scroll { scrollbar-width: none; }
html.touch .piano-scroll::-webkit-scrollbar { display: none; }
html.touch .white, html.touch .black { -webkit-user-select: none; user-select: none; }
html.touch .white:hover { filter: none; }
html.touch .white .n { font-size: 12px; color: #8a7a66; }
html.touch .white.octave .n { color: #5a3a18; font-weight: 700; }
html.touch .seg button { min-height: 42px; }
html.touch .octave-btns button { min-height: 40px; padding: 8px 16px; }
html.touch .actions button { min-height: 46px; }
html.touch .song-chip { min-height: 40px; }
html.touch .white:active { transform: none; }
html.touch .white.on, html.touch .white.selected { transform: none; }

/* ----- Phone (narrow touch screen) ----- */
html.phone body { padding-bottom: env(safe-area-inset-bottom); }
html.phone .wrap.intro { padding-top: calc(12px + env(safe-area-inset-top)); padding-bottom: 0; width: calc(100% - 24px); }
html.phone header { margin-bottom: 10px; }
html.phone .brand { font-size: 11px; margin-bottom: 4px; }
html.phone .build { display: none; }
html.phone h1 { font-size: 27px; margin: 0 0 4px; letter-spacing: -0.02em; }
html.phone .lede { font-size: 13.5px; line-height: 1.35; }
html.phone .piano-shell { width: calc(100% - 12px); margin: 6px auto 12px; padding: 10px 6px 8px; border-radius: 14px; }
html.phone .felt { margin: 0 4px 8px; height: 5px; }
html.phone .piano { height: 168px; }
html.phone .white { padding-top: 132px; font-size: 11px; border-radius: 0 0 6px 6px; box-shadow: inset -1px 0 0 rgba(80, 50, 20, 0.12), inset 0 -10px 16px rgba(80, 50, 20, 0.1), 0 6px 0 #c4b49a; }
html.phone .white .letter { display: none; }
html.phone .black .letter { display: none; }
html.phone .key-bar { flex-direction: row; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; padding: 0 2px; }
html.phone .octave-btns { gap: 6px; }
html.phone .octave-btns .touch-only { display: none; }
html.phone .octave-btns button { padding: 8px 12px; font-size: 12px; min-height: 38px; }
html.phone .auto-chords { gap: 6px; }
html.phone .auto-chords .opt-label { font-size: 10px; letter-spacing: 0.08em; white-space: nowrap; }
html.phone .auto-chords .seg { min-width: 96px; }
.phone-only { display: none; }
html.phone .phone-only { display: inline; }
html.phone .phone-hide { display: none; }
html.phone .auto-chords .seg button { min-height: 36px; padding: 6px 8px; font-size: 12px; }
@media (orientation: landscape) {
  html.phone .wrap.intro { padding-top: 6px; }
  html.phone header { display: none; }
  html.phone .piano { height: 150px; }
  html.phone .white { padding-top: 116px; }
}
html.phone .wrap:not(.intro) { width: calc(100% - 24px); padding-top: 6px; }
html.phone .songs-wrap { padding-top: 0; }
html.phone .song-chip { font-size: 13px; padding: 8px 12px; }
html.phone .opts { gap: 10px; }
html.phone .opt-label { font-size: 10.5px; }
html.phone .seg button { font-size: 13px; padding: 8px 6px; }
html.phone .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
html.phone .actions #btnWrite { grid-column: 1 / -1; min-height: 52px; font-size: 17px; }
html.phone .actions button { flex: none; width: auto; }
html.phone .learn-bar { flex-direction: column; align-items: stretch; gap: 10px; }
html.phone .learn-actions button { flex: 1; min-height: 42px; }
html.phone .activity-log { max-height: 180px; }
html.phone footer { font-size: 12px; line-height: 1.5; }

html.phone body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }

/* ===== Debut panel (2026-08-23): status mirror, action row under the piano, phone bar, focus, targets ===== */
.shell-status {
  margin: 10px 6px 0;
  color: var(--ivory);
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 17px;
  opacity: 0.92;
}
.shell-status:empty { display: none; }
.actions-wrap { padding-top: 0; padding-bottom: 4px; }
.actions-wrap .actions { margin-top: 0; }
:focus-visible { outline: 3px solid var(--copper2); outline-offset: 2px; }
.white:focus-visible, .black:focus-visible { outline-offset: -3px; }
html:not(.phone) .seg button.on::before { content: "✓ "; font-weight: 700; }
#btnWrite.busy { opacity: 0.8; }
.touch-only.inline { display: none; }
html.touch .touch-only.inline { display: inline; }
html.touch .kb-only.inline { display: none !important; }
html.touch #learnHelp[hidden] { display: none; }
html.native .chrome-only, html.native .build, html.native #compAsk { display: none; }
html.touch .learn-btn, html.touch .log-toggle, html.touch .learn-actions button { min-height: 48px; font-size: 15px; }
html.touch .song-chip, html.touch .octave-btns button, html.touch .auto-chords .seg button { min-height: 44px; }
html.touch .white .n { font-size: 15px; }
html.touch .black::after { content: ""; position: absolute; inset: 0 -5px; }
.phone-bar { display: none; }
html.phone .piano-shell { position: sticky; top: env(safe-area-inset-top); z-index: 6; box-shadow: var(--shadow), 0 10px 30px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.14); }
html.phone { scroll-padding-top: 280px; }
html.phone .actions-wrap { display: none; }
html.phone .phone-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel, #1d1610);
  border-top: 1px solid rgba(226, 176, 122, 0.35);
}
html.phone .phone-bar button {
  min-height: 44px; border: 1px solid rgba(243, 236, 227, 0.18); border-radius: 999px;
  background: rgba(0, 0, 0, 0.28); color: var(--ink); font: 700 14px/1 var(--sans);
}
html.phone .phone-bar button[data-proxy="btnWrite"] { background: linear-gradient(180deg, var(--copper2), var(--copper)); color: #1a110a; border: 0; }
html.phone .phone-bar button.active { background: rgba(201, 133, 74, 0.35); border-color: var(--copper2); }
html.phone .phone-bar button:disabled { opacity: 0.4; }
html.phone body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
html.phone .shell-status { font-size: 12.5px; margin-top: 8px; }
@media (orientation: landscape) {
  html.phone .piano { height: 110px; }
  html.phone .white { padding-top: 78px; }
  html.phone .key-bar { margin-top: 6px; }
}
@media (orientation: landscape) and (max-height: 900px) {
  html.touch:not(.phone) header { display: none; }
  html.touch:not(.phone) .wrap.intro { padding-top: 6px; }
}
@media (orientation: portrait) {
  html.touch:not(.phone) .piano-shell { position: sticky; top: 0; z-index: 6; }
}

/* ===== Mode bar: who plays ===== */
.mode-wrap { padding-top: 0; padding-bottom: 6px; }
.mode-seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; }
.mode-seg button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 6px; min-height: 54px; line-height: 1.1; }
.mode-seg button strong { font-size: 14px; font-weight: 700; }
.mode-seg button small { font-size: 11px; opacity: 0.75; font-weight: 500; }
.mode-seg button.on small { opacity: 0.9; }
html:not(.phone) .mode-seg button.on::before { content: none; }
.mode-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-top: 8px; }
.mode-hint { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.4; flex: 1 1 280px; }
.accomp-row { display: flex; align-items: center; gap: 10px; }
.accomp-row .opt-label { margin: 0; white-space: nowrap; }
.accomp-row .seg { min-width: 220px; }
html.mode-me .accomp-row, html.mode-learn .accomp-row { display: none; }
html.phone .mode-wrap { width: calc(100% - 24px); padding-top: 8px; }
html.phone .mode-seg button { min-height: 56px; padding: 8px 2px; }
html.phone .mode-seg button strong { font-size: 12.5px; }
html.phone .mode-seg button small { font-size: 9.5px; }
html.phone .mode-hint { font-size: 13px; }
html.phone .accomp-row { width: 100%; justify-content: space-between; }
html.phone .accomp-row .seg { min-width: 0; flex: 1; }
html.touch .mode-seg button { min-height: 58px; }

html.phone .mode-seg button small { display: none; }
html.phone .mode-seg button { min-height: 46px; }
html.phone .mode-seg button strong { font-size: 13.5px; }

/* Finishing a song: a light sweep across the piano (skipped under reduced motion). */
@keyframes doneSweep {
  0% { box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.14); }
  40% { box-shadow: var(--shadow), 0 0 0 3px rgba(232,162,74,.55), inset 0 1px 0 rgba(255,255,255,.35); }
  100% { box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.14); }
}
.piano-shell.done-flash { animation: doneSweep 0.7s ease-out 1; }
@media (prefers-reduced-motion: reduce) { .piano-shell.done-flash { animation: none; } }
/* Long songs: show every chord card instead of clipping at 8 (phones keep the swipe row). */
.chords.many { flex-wrap: wrap; }
html.phone .chords.many { flex-wrap: nowrap; }

