:root {
  --bg: #faf6ef;
  --card: #ffffff;
  --text: #2b2420;
  --muted: #7a6e64;
  --line: #e8dfd2;
  --accent: #d2691e;
  --accent-soft: #fbe6d4;
  --good: #2e9d6b;
  --bad: #c8463c;
  --bamboo: #d9b779;
  --bamboo-dark: #a8854a;
  --hole-closed: #3a2a1a;
  --hole-open: #fff8ec;
  --hole-ring: #6b4e2e;
  --trace-line: #8a7d70;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1814;
    --card: #26211c;
    --text: #f1e9df;
    --muted: #a99c8f;
    --line: #3a332b;
    --accent: #f08a3c;
    --accent-soft: #3d2a1b;
    --bamboo: #b8975c;
    --bamboo-dark: #8a6d3b;
    --hole-closed: #1a120a;
    --hole-open: #efe3cc;
    --trace-line: #a99c8f;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
h2 { margin: 0.2em 0 0.4em; }
h3 { margin: 0.2em 0 0.5em; }
h4 { margin: 1em 0 0.3em; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.good { color: var(--good); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }
.warn { background: #fdecea; color: #8a2a22; padding: 0.8em 1em; border-radius: 10px; }

header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 0.6em; padding: 0.5em 1em; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; text-decoration: none; color: var(--text); white-space: nowrap; }
nav { display: flex; gap: 0.2em; flex-wrap: wrap; flex: 1; }
nav a { text-decoration: none; color: var(--muted); padding: 0.3em 0.6em; border-radius: 8px; font-size: 0.92em; }
nav a.on, nav a:hover { background: var(--accent-soft); color: var(--accent); }
.iconbtn { background: none; border: 1px solid var(--line); border-radius: 10px; font-size: 1.1em; padding: 0.25em 0.5em; cursor: pointer; color: var(--text); }
.iconbtn.on { background: var(--accent); border-color: var(--accent); }
#menuBtn { display: none; }
.chipish { font-weight: 600; white-space: nowrap; }
.tabbar { display: none; }
@media (max-width: 900px) {
  #menuBtn { display: inline-block; }
  nav { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--card); border-bottom: 1px solid var(--line); padding: 0.5em; }
  nav.open { display: flex; }
  .brand { flex: 1; }
}

/* ---- Phone layout: bottom tab bar, "More" sheet, safe areas (iPhone notch / home bar) ---- */
html { -webkit-text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
header { padding-top: max(0.5em, env(safe-area-inset-top)); padding-left: max(1em, env(safe-area-inset-left)); padding-right: max(1em, env(safe-area-inset-right)); }
@media (max-width: 900px) {
  #menuBtn { display: none; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--card); border-top: 1px solid var(--line);
    padding: 0.3em env(safe-area-inset-right) max(0.4em, env(safe-area-inset-bottom)) env(safe-area-inset-left);
  }
  .tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; gap: 1px;
    font: inherit; font-size: 0.72em; color: var(--muted); text-decoration: none;
    background: none; border: 0; padding: 0.25em 0; cursor: pointer;
  }
  .tabbar span { font-size: 1.45em; line-height: 1.2; }
  .tabbar a.on { color: var(--accent); font-weight: 600; }
  nav {
    position: fixed; top: auto; bottom: calc(3.9em + env(safe-area-inset-bottom)); left: 0; right: 0;
    max-height: 70vh; overflow-y: auto; z-index: 19;
    display: none; grid-template-columns: 1fr 1fr; gap: 0.3em;
    padding: 0.8em; border-top: 1px solid var(--line); border-bottom: 0;
    box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.25); border-radius: 18px 18px 0 0;
  }
  nav.open { display: grid; }
  nav a { font-size: 1em; padding: 0.7em 0.8em; background: var(--bg); border-radius: 12px; }
  main { padding-bottom: calc(6em + env(safe-area-inset-bottom)); }
}
@media (max-width: 520px) {
  body { font-size: 15.5px; }
  main { padding: 0.8em 0.7em calc(6em + env(safe-area-inset-bottom)); }
  .card, .step { padding: 0.9em 0.9em; }
  .brand { font-size: 1.05em; }
  .stats3 { gap: 0.5em; }
  .stat { padding: 0.6em 0.3em; }
  .stat b { font-size: 1.6em; }
  .stat span { font-size: 0.78em; }
  .big.note { font-size: 2.8em; }
  .btn { padding: 0.6em 0.9em; } /* bigger touch targets */
  .btn.small { padding: 0.4em 0.7em; }
  .seg button { padding: 0.5em 0.7em; }
  .beat { width: 42px; }
  .vibhag { padding-right: 0.4em; }
  .grid { gap: 0.5em; }
  .seq { font-size: 1.2em; }
  .cards { grid-template-columns: 1fr; }
  canvas.trace { height: 200px; }
  canvas.trace.short { height: 160px; }
  .ll { padding-left: 1.2em; }
  .ll .acts { float: none; margin-top: 0.4em; }
  .shead h2 { font-size: 1.25em; }
  .facts th, .facts td { display: block; padding: 0.1em 0; }
  .facts td { margin-bottom: 0.4em; }
  .opts .btn { min-width: 0; flex: 1 1 40%; }
  .toolgrid { grid-template-columns: repeat(3, 1fr); }
  .toolgrid a { padding: 0.6em 0.4em; align-items: center; text-align: center; }
  .bpm input { width: 110px; }
}
@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }
}

main { max-width: 980px; margin: 0 auto; padding: 1.2em 1em 4em; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1em 1.3em; margin: 0 0 1em; }
.row { display: flex; align-items: center; gap: 0.6em; margin: 0.5em 0; }
.wrap { flex-wrap: wrap; }
label { display: inline-flex; align-items: center; gap: 0.4em; }
select { max-width: 100%; }
label { max-width: 100%; flex-wrap: wrap; }
select, input[type=number] { font: inherit; padding: 0.3em 0.4em; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); }

.btn { display: inline-flex; align-items: center; gap: 0.3em; white-space: nowrap; font: inherit; padding: 0.5em 1em; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; text-decoration: none; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.active { outline: 3px solid var(--accent-soft); background: var(--accent-soft); color: var(--accent); }
.btn.small { padding: 0.25em 0.6em; font-size: 0.9em; }
.btn.big { font-size: 1.15em; padding: 0.7em 1.4em; }
.btn.danger { color: var(--bad); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.seg button { font: inherit; border: 0; background: var(--card); color: var(--text); padding: 0.35em 0.8em; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4em; margin: 0.5em 0; }
.chip { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 0.25em 0.8em; cursor: pointer; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.chip.done { border-color: var(--good); }
.tag { background: var(--accent); color: #fff; border-radius: 6px; padding: 0 0.4em; font-size: 0.8em; }

/* notation */
.sg { font-weight: 600; }
.sg u { text-decoration-thickness: 2px; text-underline-offset: 3px; }
.sg .tivra { font-size: 0.8em; }
.west { color: var(--muted); font-size: 0.6em; margin-left: 0.35em; font-weight: 400; }
.big { font-size: 1.6em; }
.big.note { font-size: 3.4em; line-height: 1.1; }
.note.outside { color: var(--bad); }

/* flute */
.flute { max-width: 100%; height: auto; display: block; }
.flute .hl { font-size: 11px; text-anchor: middle; fill: var(--muted); }
.flute .clickable { cursor: pointer; }
.flute .clickable:hover circle { stroke: var(--accent); }
.legend { font-size: 0.85em; color: var(--muted); margin: 0.4em 0; }
.legend .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--hole-ring); vertical-align: -2px; margin: 0 0.25em 0 0.6em; }
.dot.closed { background: var(--hole-closed); }
.dot.open { background: var(--hole-open); }
.dot.half { background: linear-gradient(var(--hole-open) 50%, var(--hole-closed) 50%); }
.hero-flute { width: 100%; max-width: 420px; display: block; margin-bottom: 0.5em; }

/* today */
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8em; margin-bottom: 1em; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8em; text-align: center; }
.stat b { display: block; font-size: 2em; color: var(--accent); }
.stat span { color: var(--muted); font-size: 0.9em; }
.lesson-card { border-color: var(--accent); }
.welcome { background: var(--accent-soft); }
.toolgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.6em; }
.toolgrid a { display: flex; flex-direction: column; padding: 0.7em; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--text); font-size: 1.3em; }
.toolgrid a:hover { border-color: var(--accent); }
.toolgrid b { font-size: 0.75em; }
.toolgrid span { font-size: 0.6em; color: var(--muted); }

/* lessons */
.ll { padding-left: 1.6em; }
.ll li { padding: 0.5em 0; border-bottom: 1px dashed var(--line); }
.ll li > div { display: inline-block; vertical-align: top; }
.ll li { display: list-item; }
.ll .acts { float: right; display: flex; gap: 0.3em; }
.ll li.cur b { color: var(--accent); }

/* session */
.shead { display: flex; flex-wrap: wrap; gap: 0.5em 1em; align-items: center; justify-content: space-between; margin-bottom: 0.8em; }
.dots { display: flex; gap: 6px; }
.dots span { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.dots span.d { background: var(--good); }
.dots span.c { background: var(--accent); }
.step { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1em 1.3em; }
.stephead { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 0.5em; }
.nav { justify-content: space-between; margin-top: 1.2em; border-top: 1px solid var(--line); padding-top: 1em; }
.steptext { font-size: 1.05em; }

/* tools */
.readout { text-align: center; padding: 0.5em 0; }
.readout .sub { color: var(--muted); }
.readout .hint { min-height: 1.5em; color: var(--muted); }
.needle { max-width: 420px; margin: 0.6em auto; }
.needle .scale { display: flex; justify-content: space-between; font-size: 0.75em; color: var(--muted); }
.needle .track { position: relative; height: 22px; background: var(--line); border-radius: 11px; }
.needle .zone { position: absolute; left: 50%; transform: translateX(-50%); top: 0; bottom: 0; background: color-mix(in srgb, var(--good) 35%, transparent); border-radius: 11px; }
.needle .pin { position: absolute; top: -3px; width: 6px; height: 28px; margin-left: -3px; left: 50%; background: var(--bad); border-radius: 3px; transition: left 0.08s; }
.needle .pin.ok { background: var(--good); }
canvas.trace { width: 100%; height: 240px; display: block; border: 1px solid var(--line); border-radius: 10px; margin-top: 0.6em; background: var(--bg); }
canvas.trace.short { height: 180px; }
.micbtn .err { color: var(--bad); margin-left: 0.6em; }
.lt-main { display: grid; grid-template-columns: 1fr 1.2fr; gap: 1em; align-items: center; }
@media (max-width: 700px) { .lt-main { grid-template-columns: 1fr; } }
.holdbar, .bar { position: relative; height: 18px; background: var(--line); border-radius: 9px; overflow: hidden; margin: 0.4em 0; }
.holdbar .fill, .bar .fill { height: 100%; width: 0; background: var(--accent); transition: width 0.1s; }
.holdbar .fill.ok { background: var(--good); }
.holdbar .goal { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); }
.holdtext { font-size: 1.4em; }
.attempts { font-size: 0.9em; max-height: 10em; overflow: auto; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.8em; margin-top: 0.6em; }
.fcard { border: 1px solid var(--line); border-radius: 12px; padding: 0.6em 0.8em; transition: box-shadow 0.15s; }
.fcard.hit { border-color: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 40%, transparent); }
.fhead { display: flex; justify-content: space-between; align-items: center; }
.seq { display: flex; flex-wrap: wrap; gap: 0.5em; font-size: 1.35em; margin: 0.5em 0; }
.seq .grp { display: inline-flex; flex-wrap: wrap; gap: 0.15em; padding: 0.1em 0.4em; border: 1px solid var(--line); border-radius: 8px; }
.seq .n { padding: 0 0.15em; border-radius: 6px; }
.seq .n.cur { background: var(--accent); color: #fff; }
.seq .n.ok { color: var(--good); }
.seq .n.miss { color: var(--bad); }
.seqplayer { margin-bottom: 0.4em; }
.raga .s { border-left: 3px solid var(--accent-soft); padding-left: 0.6em; margin: 0.3em 0; }
.raga .s .seq { font-size: 1.15em; }
.facts { border-collapse: collapse; width: 100%; font-size: 0.95em; }
.facts th { text-align: left; color: var(--muted); font-weight: 500; padding: 0.3em 0.6em 0.3em 0; }
.facts td { padding: 0.3em 1em 0.3em 0; }
.tip { background: var(--accent-soft); padding: 0.6em 0.8em; border-radius: 10px; }
.grid { display: flex; flex-wrap: wrap; gap: 0.8em; margin: 0.8em 0; }
.vibhag { display: flex; gap: 0.3em; padding-right: 0.8em; border-right: 2px solid var(--line); }
.beat { width: 56px; text-align: center; border: 1px solid var(--line); border-radius: 10px; padding: 0.3em 0; position: relative; }
.beat .mk { display: block; height: 1.2em; font-weight: 700; color: var(--accent); }
.beat b { display: block; }
.beat small { color: var(--muted); }
.beat.sam { border-color: var(--accent); }
.beat.khali { background: var(--line); }
.beat.cur { background: var(--accent); color: #fff; }
.beat.cur .mk, .beat.cur small { color: #fff; }
.pacer { height: 220px; display: grid; place-items: center; position: relative; }
.pacer .ball { width: 180px; height: 180px; border-radius: 50%; background: radial-gradient(circle, var(--accent-soft), var(--accent)); transform: scale(0.35); opacity: 0.8; }
.pacer .label { position: absolute; font-weight: 600; font-size: 1.2em; }
.meend .mrow { display: flex; align-items: center; gap: 1em; flex-wrap: wrap; }
.meend .arrow { font-size: 2em; color: var(--accent); }
.big-status { font-size: 1.15em; font-weight: 600; margin: 0.6em 0; min-height: 1.6em; }
.drills .q { font-size: 1.15em; }
.opts { display: flex; flex-wrap: wrap; gap: 0.5em; margin: 0.8em 0; }
.opts .btn { font-size: 1.3em; min-width: 4.5em; justify-content: center; }
.fb { margin-top: 0.6em; }
.fb > div { margin-bottom: 0.5em; }
.done h3 { color: var(--good); }

/* progress */
.heat { display: grid; grid-template-rows: repeat(7, 14px); grid-auto-flow: column; grid-auto-columns: 14px; gap: 3px; }
.heat span { border-radius: 3px; background: var(--line); }
.heat .l1 { background: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.heat .l2 { background: color-mix(in srgb, var(--accent) 65%, var(--line)); }
.heat .l3 { background: var(--accent); }
.heat .future { background: transparent; }
.ltgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.5em; }
.ltgrid div { border: 1px solid var(--line); border-radius: 10px; padding: 0.4em 0.6em; display: flex; justify-content: space-between; }
.buy ul { padding-left: 1.2em; }
