/* Online Tanpura (newellabs.com/play/tanpura). Self-contained; system fonts only. Tokens follow the harmonium's. */
:root {
  color-scheme: light dark;
  --bg: #f6efe4; --well: #ede3d3; --card: #fffcf7;
  --ink: #1d1712; --ink-2: #3f352c; --muted: #5f554b; --faint: #a3978a;
  --line: #e3d7c4; --line-strong: #cdbca3;
  --accent: #8a3a12; --accent-bright: #e0892c;
  --focus: #2459d6; --on: #8a3a12; --on-ink: #fff8ef;
  --wood-1: #7d4024; --wood-2: #5c2b15; --wood-3: #3a190a;
  --string: #e9c27a; --string-hot: #ffe2a6; --case-ink: #f8ead2; --case-muted: #e8cfa9;
  --now: #f3a23e; --now-ink: #2a1708; --khali: #ede3d3;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Devanagari", 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: #15110e; --well: #1f1915; --card: #231c17;
    --ink: #f1e9de; --ink-2: #d7ccbf; --muted: #ab9f92; --faint: #645a50;
    --line: #342a22; --line-strong: #4b3e33;
    --accent: #f2b46c; --accent-bright: #e8963a;
    --focus: #93b4ff; --on: #f2b46c; --on-ink: #1d1209;
    --wood-1: #5e2f19; --wood-2: #44200f; --wood-3: #2a1207;
    --now: #e8963a; --now-ink: #1d1209; --khali: #2b231d;
  }
}

* { 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; }
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: 1080px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); }
[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; min-height: 44px; 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: 16px; padding-bottom: 0; }
h1 { font: 700 clamp(1.9rem, 7vw, 2.9rem)/1.05 var(--serif); letter-spacing: -.01em; margin: 0 0 6px; }
.h1-and { color: var(--accent); }
.lede { margin: 0; color: var(--ink-2); max-width: 46em; }
.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-in { display: flex; flex-wrap: wrap; justify-content: space-between; column-gap: 20px; }
.foot a { color: var(--muted); display: inline-block; padding: 12px 0; }

/* Controls shared */
.cap { font-size: 13px; font-weight: 650; color: var(--muted); letter-spacing: .02em; }
.seg-cap { font-size: 13px; font-weight: 650; color: var(--muted); padding: 0 8px 0 6px; }
.seg { display: inline-flex; align-items: center; background: var(--well); border: 1px solid var(--line); border-radius: 13px; padding: 2px; max-width: 100%; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.seg label { min-height: 44px; min-width: 48px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; font-weight: 650; font-size: 15px; color: var(--ink-2); cursor: pointer; white-space: nowrap; transition: background-color .15s, color .15s; touch-action: manipulation; }
.seg input:checked + label { background: var(--on); color: var(--on-ink); }
.seg input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 1px; }
.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: 650; 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; }
.btn svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.btn-sm { font-size: 14px; padding: 0 12px; border-radius: 10px; }
.btn-icon { padding: 0; width: 44px; font-size: 22px; line-height: 1; }
.btn .i-stop { display: none; }
.btn.on .i-stop { display: block; }
.btn.on .i-play { display: none; }
.link-btn { background: none; border: 0; padding: 10px 0; min-height: 44px; color: var(--accent); text-decoration: underline; text-decoration-color: var(--accent-bright); text-underline-offset: 3px; cursor: pointer; font-size: 14px; }
input[type="range"] { width: 100%; min-height: 44px; margin: 0; accent-color: var(--accent-bright); background: transparent; cursor: pointer; }
input[type="range"].rev { direction: rtl; }
input[type="number"] { font: 650 17px var(--sans); width: 4.6em; min-height: 44px; text-align: center; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--card); color: var(--ink); padding: 0 4px; -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Stage */
.stage { padding-top: 14px; }
.panels { display: grid; gap: 14px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 14px 14px 12px; min-width: 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 8px; }
.panel h2 { font: 700 1.3rem/1.2 var(--serif); margin: 0; }
.readout { margin: 0; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; margin-top: 10px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 4px; }

/* Strings: a wooden neck with four strings that shimmer when plucked */
.strings { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: stretch; margin-bottom: 10px; }
.neck-box { position: relative; min-width: 0; }
.strings svg { display: block; width: 100%; height: 92px; border-radius: 12px; }
/* While the strings move they are drawn on a canvas over the picture (much cheaper than redrawing the SVG) */
.neck-box canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
.strings.live .str { visibility: hidden; }
.neck { fill: var(--wood-2); }
.str { fill: none; stroke: var(--string); stroke-width: 2.2; stroke-linecap: round; }
.str.hot { stroke: var(--string-hot); stroke-width: 3.2; }
.str-labels { list-style: none; margin: 0; padding: 0; display: grid; grid-template-rows: repeat(4, 1fr); font-size: 13px; line-height: 1; min-width: 92px; height: 92px; }
.str-labels li { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.str-labels b { font-weight: 700; color: var(--ink); min-width: 1.6em; }
.str-labels span { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }

/* Scale keys: 12 radio buttons, 6 per row on phones, 12 in a row when there's room */
.key-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.key-grid input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.key-grid label { min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--bg); cursor: pointer; line-height: 1.1; touch-action: manipulation; -webkit-tap-highlight-color: transparent; transition: background-color .15s, border-color .15s; }
.key-grid label b { font-size: 17px; font-weight: 700; }
.key-grid label span { font-size: 11px; color: var(--muted); margin-top: 3px; white-space: nowrap; }
.key-grid label.black { background: var(--well); }
.key-grid input:checked + label { background: var(--on); border-color: var(--on); color: var(--on-ink); }
.key-grid input:checked + label span { color: var(--on-ink); opacity: .85; }
.key-grid input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }

.btn-play { min-height: 52px; padding: 0 22px; font-size: 17px; border-radius: 14px; background: var(--accent); border-color: var(--accent); color: var(--on-ink); flex: 1 1 170px; max-width: 300px; }
.btn-play:hover { border-color: var(--accent); filter: brightness(1.08); }
.btn-play.on { background: var(--card); color: var(--accent); border: 2px solid var(--accent); }
.btn-play.busy { cursor: progress; }
.vol { display: flex; flex-direction: column; flex: 1 1 140px; min-width: 120px; }
/* Messages for one part (a device pause, an error, retuning, taps) sit under its own Play button */
.pstatus { margin: 0; font-size: 14px; color: var(--ink-2); }
.pstatus:not(:empty) { margin-top: 8px; }
.hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.panel .check { margin-top: 2px; }
.vol .cap { margin-bottom: -6px; }
.vol-wide { margin-top: 8px; }

/* More tuning */
.more { margin-top: 8px; border-top: 1px solid var(--line); }
.more summary { min-height: 44px; display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 650; font-size: 15px; color: var(--ink-2); list-style: none; }
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: ""; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; margin: 0 4px; }
.more[open] summary::before { transform: rotate(45deg); }
.more-in { display: grid; gap: 10px; padding: 2px 0 6px; }
.field { display: flex; flex-direction: column; }
.field output { color: var(--ink); font-weight: 700; margin-left: 6px; font-variant-numeric: tabular-nums; }
.stepper { display: inline-flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.stepper .cap { margin-right: 4px; }
.unit { color: var(--muted); font-size: 14px; }
.range-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: -8px; }

/* Taals and theka */
.taal-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.taal-grid input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.taal-grid label { min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--bg); cursor: pointer; line-height: 1.15; touch-action: manipulation; -webkit-tap-highlight-color: transparent; padding: 2px 4px; }
.taal-grid label b { font-size: 15px; font-weight: 700; }
.taal-grid label span { font-size: 12px; color: var(--muted); }
.taal-grid input:checked + label { background: var(--on); border-color: var(--on); color: var(--on-ink); }
.taal-grid input:checked + label span { color: var(--on-ink); opacity: .85; }
.taal-grid input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }
.theka { display: flex; flex-wrap: wrap; gap: 8px 6px; margin-top: 12px; min-height: 64px; }
.vib { display: flex; gap: 3px; position: relative; padding-top: 16px; }
.vib::before { content: attr(data-mark); position: absolute; top: 0; left: 4px; font: 700 12px/1 var(--sans); color: var(--accent); }
.vib.khali::before { color: var(--muted); }
.cell { min-width: 46px; min-height: 40px; padding: 2px 6px; border-radius: 9px; background: var(--well); display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; color: var(--ink-2); white-space: nowrap; transition: background-color .08s, color .08s; }
.vib.khali .cell { background: var(--khali); color: var(--muted); border: 1px dashed var(--line-strong); }
.cell.now { background: var(--now); color: var(--now-ink); border-color: var(--now); box-shadow: inset 0 0 0 2px var(--accent); }
.row-tempo { justify-content: space-between; }
.btn-tap { min-width: 84px; font-size: 16px; padding: 0 14px; }
.btn-tap.flash { background: var(--now); border-color: var(--now); color: var(--now-ink); }
#bpm-slider { margin-top: 2px; }

/* Deck under the panels */
.deck { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; margin-top: 12px; }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 15px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent-bright); margin: 0; }
.keyhint { margin: 0; font-size: 14px; color: var(--muted); }
.keyhint .link-btn { min-height: 0; padding: 2px 0; font-size: 14px; }
.status { min-height: 1.6em; margin: 6px 0 0; font-size: 14px; color: var(--muted); }

/* Prose */
.prose { margin-top: 44px; }
.prose > * { max-width: 760px; }
.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, .prose ol { padding-left: 1.3em; margin: 0 0 10px; color: var(--ink-2); }
.prose li { margin: 0 0 10px; }
.prose li::marker { color: var(--accent-bright); font-weight: 700; }
.prose strong { color: var(--ink); }
.table-box { overflow-x: auto; margin: 0 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl-taals td:nth-child(3) { min-width: 15em; }
.tbl .m { color: var(--accent); font-weight: 700; font-size: 12px; margin-right: 2px; }

/* Toast: at the top, never takes taps */
.toast { position: fixed; left: 50%; top: max(12px, env(safe-area-inset-top)); 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); }
.toast.show.copy { 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); }

/* More toys */
.more-toys { margin-top: 48px; }
.more-toys h2 { font: 700 1.4rem/1.2 var(--serif); margin: 0 0 12px; }
.more-toys ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.more-toys a { display: grid; grid-template-columns: 112px minmax(0, 1fr); align-items: center; column-gap: 14px; min-height: 44px; padding: 10px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink); text-decoration: none; }
.more-toys a:hover { border-color: var(--accent-bright); color: var(--ink); }
.more-toys img { grid-row: 1 / 3; display: block; width: 112px; height: 63px; border-radius: 10px; object-fit: cover; background: var(--well); }
.more-toys b { align-self: end; font-weight: 700; }
.more-toys span { align-self: start; font-size: 0.88rem; line-height: 1.35; color: var(--muted); }
.more-toys + .foot { margin-top: 40px; }

/* Wider screens */
@media (min-width: 600px) {
  .wrap { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }
  .hero { padding-top: 26px; }
  .panel { padding: 18px 18px 14px; }
  .taal-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (min-width: 940px) {
  .panels { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: start; }
}
@media (min-width: 940px) and (max-width: 1100px) {
  .taal-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 700px) and (max-width: 939px) {
  .key-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); }
}
@media (max-width: 420px) {
  .row-tempo .stepper .cap { display: none; } /* still names the group for screen readers (aria-labelledby) */
  .row-tempo { gap: 8px; }
  .row-tempo .stepper { gap: 4px; }
  .row-tempo input[type="number"] { width: 3.4em; }
  .btn-tap { min-width: 0; padding: 0 12px; }
}
/* Phones turned sideways: the scales and Play on the first screen */
@media (orientation: landscape) and (max-height: 500px) {
  .top-in { min-height: 40px; }
  .brand { padding: 4px 0; }
  .hero { padding-top: 6px; }
  h1 { font-size: 1.5rem; margin: 0; }
  .lede { display: none; }
  .stage { padding-top: 8px; }
  .panel { padding-top: 8px; padding-bottom: 8px; }
  .panel-head { margin-bottom: 4px; }
  .strings { margin-bottom: 6px; }
  .strings svg, .str-labels { height: 56px; }
  .str-labels { font-size: 12px; }
  .key-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; }
  .key-grid label { min-height: 46px; }
  .key-grid label span { font-size: 10px; }
  .row { margin-top: 8px; }
}
@media (hover: hover) and (pointer: fine) {
  .fine-only { display: revert; }
}
/* Short or narrow phones: keep the scales and Play on the first screen */
@media (max-width: 380px), (max-height: 700px) {
  .hero { padding-top: 10px; }
  h1 { font-size: 1.75rem; }
  .lede { font-size: 15px; line-height: 1.45; }
  .stage { padding-top: 10px; }
  .panel { padding-top: 10px; }
  .strings svg, .str-labels { height: 76px; }
  .key-grid label { min-height: 46px; }
  .key-grid label span { margin-top: 2px; }
}
@media (max-width: 380px) {
  .btn-tap { padding: 0 8px; font-size: 15px; } /* "Tap tempo" still fits beside the tempo at 360 px */
}
@media (max-width: 360px) {
  .key-grid label span { font-size: 10px; }
  .seg label { padding: 0 9px; min-width: 44px; }
  .cell { min-width: 42px; padding: 2px 4px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
/* Forced colours (Windows contrast themes): the chosen scale, taal, 1st string and tuning are filled with Highlight, the
   current matra is ringed. The chosen labels opt out of forced colours (forced-color-adjust: none): otherwise Chromium
   draws its Canvas-coloured backplate behind their text and HighlightText on it disappears. Everything they use is a
   system colour, so they still follow the user's theme; their focus ring is CanvasText (not the page's own blue). */
@media (forced-colors: active) {
  .key-grid input:checked + label, .taal-grid input:checked + label, .seg input:checked + label { forced-color-adjust: none; background: Highlight; color: HighlightText; border-color: Highlight; }
  .key-grid input:checked + label span, .taal-grid input:checked + label span { color: HighlightText; opacity: 1; }
  .key-grid input:focus-visible + label, .taal-grid input:focus-visible + label, .seg input:focus-visible + label { outline-color: CanvasText; }
  .cell.now { outline: 3px solid Highlight; outline-offset: -3px; }
  .str.hot { stroke: Highlight; }
}
.tbl .small { font-size: 12px; color: var(--muted); }
