/* Online Kalimba (newellabs.com/play/kalimba). Self-contained; system fonts only. */
:root {
  color-scheme: light dark;
  --bg: #f5f0e6; --well: #ece4d4; --card: #fffcf7;
  --ink: #1b2130; --ink-2: #3a4254; --muted: #596070; --faint: #a39d92; --done: #756f66;
  --line: #e1d7c5; --line-strong: #cdbfa6;
  --accent: #875810; --accent-bright: #dfa140; --glow: rgba(236, 170, 64, .75);
  --focus: #2459d6; --rec: #c2362b; --rec-on: #c2362b;
  --wood-hi: #e6c795; --wood-lo: #c7995b; --grain: rgba(112, 66, 22, .075);
  --engrave: #43280a; --engrave-hi: rgba(255, 245, 225, .6);
  --steel-1: #7b828b; --steel-2: #f4f6f8; --steel-3: #adb3bb;
  --tine-shadow: rgba(62, 34, 8, .45);
  --kc-bg: rgba(255, 250, 240, .38); --kc-line: rgba(80, 48, 14, .28);
  --veil: rgba(245, 240, 230, .5);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --well: #1a1f29; --card: #1c212b;
    --ink: #ece7de; --ink-2: #d0cac0; --muted: #a4aab5; --faint: #5d6470; --done: #858c98;
    --line: #2a3140; --line-strong: #3b4354;
    --accent: #e9bb6c; --accent-bright: #e2a646; --glow: rgba(240, 180, 80, .6);
    --focus: #93b4ff; --rec: #ee5b4d; --rec-on: #c0392f;
    --wood-hi: #6f4b2f; --wood-lo: #45301f; --grain: rgba(0, 0, 0, .16);
    --engrave: #f2dfbf; --engrave-hi: rgba(0, 0, 0, .45);
    --steel-1: #6a7079; --steel-2: #e1e5ea; --steel-3: #99a0a9;
    --tine-shadow: rgba(0, 0, 0, .55);
    --kc-bg: rgba(0, 0, 0, .22); --kc-line: rgba(255, 235, 205, .18);
    --veil: rgba(18, 21, 28, .5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.6 var(--sans); overflow-x: hidden; }
a { color: inherit; text-decoration-color: var(--accent-bright); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button { font: inherit; color: inherit; touch-action: manipulation; }
.seg label, .chip { touch-action: manipulation; }
kbd { font: 500 .82em/1 var(--mono); display: inline-block; min-width: 1.6em; padding: .22em .38em; text-align: center; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--card); color: var(--ink); }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }
.fine-only { display: none; }
.vh { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.skip { position: absolute; left: -9999px; top: 8px; z-index: 50; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; }
.skip:focus { left: 16px; }

/* Header, hero, footer */
.top { border-bottom: 1px solid var(--line); }
.top-in { min-height: 54px; display: flex; align-items: center; }
.brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; font-weight: 650; font-size: 15px; padding: 8px 0; }
.brand svg { width: 22px; height: 22px; color: var(--accent-bright); }
.brand-sub { color: var(--muted); font-weight: 500; margin-left: 2px; }
.brand-sub::before { content: "/"; margin-right: 6px; color: var(--faint); }
.hero { padding-top: 22px; padding-bottom: 4px; }
h1 { font: 700 clamp(2rem, 7vw, 3rem)/1.05 var(--serif); letter-spacing: -.01em; margin: 0 0 8px; }
.lede { margin: 0; color: var(--ink-2); max-width: 620px; font-size: 1rem; line-height: 1.5; }
.foot { border-top: 1px solid var(--line); margin-top: 56px; padding: 22px 0 32px; color: var(--muted); font-size: .9rem; }
.foot p { margin: 0; }
.foot a { color: var(--muted); }

/* Controls */
.stage { padding-top: 20px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 14px; margin: 0 0 14px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { display: inline-flex; align-items: center; background: var(--well); border: 1px solid var(--line); border-radius: 13px; padding: 3px; }
.seg-cap, .songs-cap { font: 650 11px/1 var(--sans); letter-spacing: .09em; text-transform: uppercase; color: var(--muted); padding: 0 6px; white-space: nowrap; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.seg label { min-height: 38px; min-width: 40px; padding: 0 9px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; white-space: nowrap; transition: background-color .15s, color .15s; }
.seg input:checked + label { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 1px var(--line); }
.seg input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 1px; }

.songs { display: flex; align-items: center; gap: 8px; flex: 1 1 260px; min-width: 0; max-width: 380px; }
.songs-cap { flex: none; padding-left: 0; cursor: pointer; }
.pick { position: relative; flex: 1 1 auto; min-width: 0; display: flex; }
.pick::after { content: ""; position: absolute; right: 16px; top: 50%; width: 7px; height: 7px; margin-top: -6px; border: solid var(--ink-2); border-width: 0 2px 2px 0; transform: rotate(45deg); pointer-events: none; }
.pick select { -webkit-appearance: none; appearance: none; width: 100%; min-width: 0; min-height: 44px; padding: 0 40px 0 16px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--card); color: var(--ink); font: 500 15px/1.2 var(--sans); cursor: pointer; text-overflow: ellipsis; }
.pick select:hover { border-color: var(--accent-bright); }
.pick select.has-song { border-color: var(--accent-bright); box-shadow: inset 0 0 0 1px var(--accent-bright); }
.pick select:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--card); font-size: 15px; font-weight: 600; cursor: pointer; transition: border-color .15s, background-color .15s, color .15s; -webkit-tap-highlight-color: transparent; }
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: default; transform: none; border-color: var(--line-strong); }
.btn svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-sm svg { width: 16px; height: 16px; }
.btn-icon { padding: 0; width: 38px; }
.link-btn { background: none; border: 0; padding: 4px 2px; min-height: 32px; color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--accent-bright); text-underline-offset: 3px; cursor: pointer; font-size: inherit; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--rec); flex: none; transition: border-radius .15s; }
.btn-rec[aria-pressed="true"] { background: var(--rec-on); border-color: var(--rec-on); color: #fff; }
.btn-rec[aria-pressed="true"] .rec-dot { background: #fff; border-radius: 2px; animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .35; } }
.btn .i-stop { display: none; }
.btn.is-playing .i-stop { display: block; }
.btn.is-playing .i-play { display: none; }
#play.attention:not([disabled]) { border-color: var(--accent-bright); box-shadow: 0 0 0 3px var(--glow); }

/* Shared-tune banner */
.sent { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin: 0 0 14px; padding: 10px 10px 10px 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--accent-bright); box-shadow: 0 0 0 3px var(--glow); }
.sent-txt { margin: 0; font-size: 15px; line-height: 1.35; }
#sent-meta { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.btn-accent { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn-accent:hover { border-color: var(--ink); opacity: .92; }

/* Play-along panel */
.along { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px 8px; margin: 0 0 14px; }
.along-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; }
.along-title { margin: 0; font-size: 15px; line-height: 1.3; }
.along-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; margin-left: 4px; white-space: nowrap; }
.along-actions { display: flex; gap: 6px; }
.strip { position: relative; display: flex; gap: 3px; overflow-x: auto; padding: 8px 2px 6px; scrollbar-width: none; -webkit-mask-image: linear-gradient(90deg, transparent, #000 18px, #000 calc(100% - 18px), transparent); mask-image: linear-gradient(90deg, transparent, #000 18px, #000 calc(100% - 18px), transparent); }
.strip::-webkit-scrollbar { display: none; }
.strip::before, .strip::after { content: ""; flex: none; width: 40%; }
.tok { flex: none; min-width: 27px; padding: 2px 4px 4px; display: inline-flex; flex-direction: column; align-items: center; border-radius: 8px; font-weight: 650; font-size: 17px; line-height: 1.05; color: var(--ink-2); transition: background-color .12s, color .12s; }
.tok.bar-end { margin-right: 10px; }
.tok.done { color: var(--done); font-weight: 500; }
.tok.cur { background: var(--accent-bright); color: #21170a; }
.tok sub, .lab sub { font-size: .62em; font-weight: 600; vertical-align: baseline; position: relative; top: .1em; margin-left: .5px; }
.tok .dots, .lab .dots { display: block; height: 7px; font-size: 8px; line-height: 7px; letter-spacing: 1px; }
.along-hint { margin: 2px 0 2px; font-size: 13px; color: var(--muted); }
.along-hint a { color: var(--ink-2); white-space: nowrap; }

/* The instrument */
.kalimba { --top: 22px; --max: 184px; --kc: 0px; position: relative; margin: 0 -8px; }
.board {
  position: relative;
  height: calc(var(--top) + var(--max) + 54px + var(--kc));
  padding: 0 6px;
  border-radius: 22px 22px 30px 30px;
  background:
    radial-gradient(140% 90% at 50% -12%, rgba(255, 255, 255, .2), transparent 55%),
    repeating-linear-gradient(90deg, transparent 0 11px, var(--grain) 11px 12px, transparent 12px 23px),
    repeating-linear-gradient(88.5deg, transparent 0 17px, var(--grain) 17px 19px, transparent 19px 41px),
    linear-gradient(180deg, var(--wood-hi), var(--wood-lo));
  box-shadow:
    inset 0 0 0 1px rgba(60, 34, 8, .28),
    inset 0 2px 0 rgba(255, 255, 255, .18),
    inset 0 -14px 26px rgba(50, 28, 6, .16),
    0 2px 4px rgba(60, 34, 8, .12),
    0 22px 44px -22px rgba(60, 34, 8, .55);
}
.saddle, .bar { position: absolute; left: 3%; right: 3%; pointer-events: none; }
.saddle { top: calc(var(--top) + 5px); height: 9px; border-radius: 4px; background: linear-gradient(180deg, rgba(58, 32, 10, .5), rgba(58, 32, 10, .28)); }
.bar { top: calc(var(--top) + 17px); height: 10px; z-index: 2; border-radius: 5px; background: linear-gradient(180deg, #eef1f4, #a3aab3 55%, #6f767f); box-shadow: 0 3px 4px -1px var(--tine-shadow), inset 0 -1px 0 rgba(0, 0, 0, .25); }
.hole { position: absolute; bottom: calc(20px + var(--kc)); width: 34px; height: 34px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 50% 42%, #140c05 0 52%, #2e1c0d 66%, rgba(46, 28, 13, 0) 70%);
  box-shadow: 0 0 0 5px rgba(60, 34, 8, .1), 0 1px 0 5px rgba(255, 255, 255, .12); }
.hole-l { left: 8%; }
.hole-r { right: 8%; }
.tines { position: relative; height: 100%; display: grid; grid-template-columns: repeat(17, minmax(0, 1fr)); touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.col { position: relative; height: 100%; margin: 0; padding: 0; border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.col:focus-visible { outline: none; }
.tine {
  position: absolute; top: var(--top); left: 0; right: 0; margin: 0 auto;
  width: 58%; max-width: 21px; height: calc(var(--max) * var(--len));
  border-radius: 2px 2px 45% 45% / 2px 2px 8px 8px;
  background: linear-gradient(90deg, var(--steel-1), var(--steel-2) 36%, var(--steel-3) 64%, var(--steel-1));
  box-shadow: 1px 4px 4px -1px var(--tine-shadow);
  transform-origin: 50% 0;
}
.shine { position: absolute; inset: 0; border-radius: inherit; opacity: 0; background: linear-gradient(90deg, #c68b2a, #ffe7b3 40%, #e8b659 66%, #b37b20); }
.col.root .tine::after { content: ""; position: absolute; left: 50%; bottom: 11px; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: rgba(40, 30, 20, .42); box-shadow: 0 1px 0 rgba(255, 255, 255, .55); }
.lab { position: absolute; left: 0; right: 0; top: calc(var(--top) + var(--max) * var(--len) + 5px); display: flex; justify-content: center; pointer-events: none; }
.txt { position: relative; display: inline-flex; flex-direction: column; align-items: center; min-width: 17px; padding: 1px 2px 3px; border-radius: 6px; font-weight: 700; font-size: 12px; line-height: 1.05; color: var(--engrave); text-shadow: 0 1px 0 var(--engrave-hi); white-space: nowrap; transition: background-color .15s, color .15s; }
.halo { position: absolute; left: 50%; top: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px; border-radius: 50%; background: radial-gradient(circle, var(--glow), transparent 68%); opacity: 0; pointer-events: none; }
.kc { position: absolute; left: 0; right: 0; bottom: 12px; margin: 0 auto; width: 22px; height: 22px; display: none; align-items: center; justify-content: center; border-radius: 6px; font: 600 11px/1 var(--mono); color: var(--engrave); background: var(--kc-bg); border: 1px solid var(--kc-line); box-shadow: 0 1px 0 var(--kc-line); pointer-events: none; }
.col.next .tine { box-shadow: 0 0 0 2px var(--accent-bright), 0 0 18px 4px var(--glow); }
.col.next .shine { opacity: .5; }
.col.next .txt { background: var(--accent-bright); color: #21170a; text-shadow: none; }
.col.next .halo { animation: halo 1.6s ease-in-out infinite; }
@keyframes halo { 0%, 100% { opacity: .3; transform: scale(.85); } 50% { opacity: .95; transform: scale(1.2); } }
.col:focus-visible .tine { outline: 3px solid var(--focus); outline-offset: 2px; }
.col:focus-visible .txt { box-shadow: 0 0 0 2px var(--focus); }
@media (hover: hover) { .col:hover .tine { filter: brightness(1.07); } }

/* Tap-to-start veil */
.start { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; border: 0; margin: 0; padding: 16px; border-radius: 22px 22px 30px 30px; background: var(--veil); -webkit-backdrop-filter: blur(1px); backdrop-filter: blur(1px); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.start-pill { display: inline-flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 24px; border-radius: 999px; background: var(--ink); color: var(--bg); font-size: 17px; font-weight: 650; box-shadow: 0 10px 24px -10px rgba(0, 0, 0, .5); transition: transform .15s; }
.start-pill svg { width: 22px; height: 22px; fill: currentColor; }
.start:hover .start-pill { transform: scale(1.03); }
.start-sub { font-size: 13px; font-weight: 500; color: var(--ink); background: var(--card); padding: 4px 10px; border-radius: 999px; text-align: center; }
.start:focus-visible { outline-offset: -3px; }

/* Rotate hint */
.turn-hint { display: none; align-items: center; gap: 8px; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.turn-hint svg { width: 20px; height: 20px; flex: none; color: var(--accent); }
@media (pointer: coarse) and (orientation: portrait) and (max-width: 559px) { .turn-hint { display: flex; } }

/* Recorder */
.deck { margin-top: 16px; }
.deck-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.status { margin: 10px 0 0; color: var(--muted); font-size: 14px; line-height: 1.45; min-height: 2.9em; }
#status { font-variant-numeric: tabular-nums; }
.keyhint { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* Help text */
.prose { margin-top: 44px; }
.prose > * { max-width: 700px; }
.prose h2 { font: 700 1.5rem/1.2 var(--serif); margin: 36px 0 12px; }
.prose h3 { font-size: 1.02rem; margin: 22px 0 4px; line-height: 1.35; }
.prose p { margin: 0 0 10px; color: var(--ink-2); }
.prose ul { padding-left: 1.2em; margin: 0; color: var(--ink-2); }
.prose li { margin: 0 0 10px; }
.prose li::marker { color: var(--accent-bright); }
.prose strong { color: var(--ink); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 40; width: max-content; max-width: calc(100vw - 32px); transform: translate(-50%, 12px); opacity: 0; pointer-events: none; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .45); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast input { display: block; width: min(560px, calc(100vw - 64px)); margin-top: 8px; padding: 8px; border-radius: 8px; border: 0; font: 13px var(--mono); color: var(--ink); background: var(--card); }

/* Wider screens */
@media (min-width: 420px) {
  .kalimba { margin: 0; }
  .board { padding: 0 8px; }
}
@media (min-width: 600px) {
  .kalimba { --top: 26px; --max: 212px; }
  .board { padding: 0 16px; border-radius: 28px 28px 36px 36px; }
  .start { border-radius: 28px 28px 36px 36px; }
  .txt { font-size: 14px; }
  .seg label { min-width: 44px; padding: 0 12px; }
  .controls { gap: 10px 14px; }
  .stage { padding-top: 26px; }
  .lab .dots { height: 8px; line-height: 8px; }
  .hole { width: 44px; height: 44px; }
  .hero { padding-top: 34px; }
  .wrap { padding-left: 24px; padding-right: 24px; }
}
@media (min-width: 900px) {
  .kalimba { --max: 236px; }
  .board { padding: 0 26px; }
  .tine { width: 50%; }
}
@media (hover: hover) and (pointer: fine) {
  .kalimba { --kc: 30px; }
  .kc { display: flex; }
  .fine-only { display: revert; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .top-in { min-height: 40px; }
  .brand { padding: 4px 0; }
  .hero { padding-top: 8px; padding-bottom: 0; }
  h1 { font-size: 1.6rem; margin: 0; }
  .lede { display: none; }
  .stage { padding-top: 10px; }
  .toolbar { margin-bottom: 10px; }
  .kalimba { --max: clamp(130px, calc(100vh - 235px - var(--kc)), 212px); }
  .along-hint { display: none; }
  .along { padding-bottom: 2px; }
}
@supports (height: 100svh) {
  @media (orientation: landscape) and (max-height: 500px) {
    .kalimba { --max: clamp(130px, calc(100svh - 235px - var(--kc)), 212px); }
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
  .col.next .halo { animation: none; opacity: .7; }
  .btn-rec[aria-pressed="true"] .rec-dot { animation: none; }
}
.tab-links { list-style: none; padding: 0; margin: 4px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 16px; line-height: 1.35; }
.tab-links li { padding: 5px 0; }
