/* ============================================================
   Sargam Riyaz — main stylesheet (dark theme, mobile-first)
   ============================================================ */
:root {
  color-scheme: dark;
  /* surfaces & ink */
  --page: #0b0b0b;
  --surface: #191919;
  --surface-2: #222222;
  --surface-3: #2b2b2b;
  --hair: #303030;
  --axis: #474747;
  --ink: #efefef;
  --ink-2: #9c9c9c;
  /* brand */
  --accent: #9887ef;
  --accent-strong: #6a4ce2;
  --accent-wash: rgba(152, 135, 239, 0.14);
  /* status (in tune / slightly off / off) */
  --good: #0aac23;
  --warn: #fbb315;
  --bad: #dc3c3d;
  /* data (diverging flat <-> sharp, magnitude) */
  --flat: #338ced;
  --sharp: #eb6263;
  --mag: #338ced;

  --radius: 14px;
  --radius-sm: 10px;
  --gap: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
  --bottom-ad-h: 0px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--ink-2); }
.tiny { font-size: 12px; }

/* ---------- icons ---------- */
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.sm { width: 14px; height: 14px; }

/* ---------- app shell ---------- */
.app { max-width: 1140px; margin: 0 auto; min-height: 100vh; }
body.ads-bottom .app { padding-bottom: var(--bottom-ad-h); }

/* ---------- top bar: logo · tabs · Sa · tanpura · settings — ONE row ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 8px; padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(11, 11, 11, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--hair);
}
.brand { display: none; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: .2px; min-width: 0; flex: none; }
.brand img { border-radius: 8px; display: block; }
.brand-name { white-space: nowrap; display: none; }
.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; flex: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 10px;
  border-radius: 999px; border: 1px solid var(--hair);
  background: var(--surface); color: var(--ink);
  font-size: 14px; white-space: nowrap;
}
.chip:hover { background: var(--surface-2); }
.chip.icon-only { width: 36px; padding: 0; justify-content: center; }
.chip-k { color: var(--ink-2); }
.chip-sub { color: var(--ink-2); font-size: 12px; display: none; }
#saChip > .i { display: none; }

/* tanpura toggle: icon + status dot (label on wide screens) */
.chip.toggle { position: relative; width: 40px; padding: 0; justify-content: center; }
.chip.toggle .tp-label { display: none; }
.chip.toggle .dot { position: absolute; top: 5px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--axis); }
.chip.toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-wash); }
.chip.toggle[aria-pressed="true"] .i { color: var(--accent); }
.chip.toggle[aria-pressed="true"] .dot { background: var(--good); box-shadow: 0 0 0 2px rgba(10,172,35,.3); }

.tanpura-ctl { position: relative; display: flex; gap: 2px; }
.tanpura-ctl #tanpuraBtn { border-top-right-radius: 6px; border-bottom-right-radius: 6px; }
.tanpura-ctl #tanpuraMore { border-top-left-radius: 6px; border-bottom-left-radius: 6px; width: 26px; }

.popover {
  position: absolute; right: 0; top: 44px; z-index: 30;
  width: 270px; padding: 14px;
  background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
  display: grid; gap: 12px;
}
.popover p { margin: 0; }

/* tabs (inside the top bar) — icons only on phones, icon + label on wider screens */
.tabs {
  display: flex; gap: 2px; padding: 3px; flex: none;
  background: var(--surface); border: 1px solid var(--hair); border-radius: 12px;
}
.tabs button {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 40px; height: 32px; padding: 0; border: 0; border-radius: 9px;
  background: transparent; color: var(--ink-2);
  font-weight: 600; font-size: 14px; white-space: nowrap;
}
.tabs button span { /* visually hidden on phones, still read by screen readers */
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--surface-3); color: var(--ink); }
.tabs button[aria-selected="true"] .i { color: var(--accent); }

/* ---------- layout ---------- */
.layout { display: block; padding: 0 12px; }
main { min-width: 0; }
.side { display: none; }
.view { display: grid; gap: var(--gap); padding-top: var(--gap); }
.view-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 26px; }
.today-chip { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--hair); }

.card {
  background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius);
  padding: 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-title { font-weight: 600; font-size: 14px; }
.card-tools { display: flex; gap: 4px; }

/* ---------- welcome (first visit) ---------- */
.welcome { position: relative; padding: 16px; border-color: var(--accent-strong); background: linear-gradient(180deg, rgba(106, 76, 226, .16), var(--surface) 70%); }
.welcome[hidden] { display: none; }
.app-version { text-align: center; margin: 2px 0 6px; }
.welcome-x { position: absolute; top: 8px; right: 8px; }
.welcome-title { margin: 0 34px 6px 0; font-size: 18px; line-height: 1.3; }
.welcome-text { margin: 0 0 12px; color: #d6d6d6; font-size: 14.5px; line-height: 1.55; }
.welcome .btn.primary { width: 100%; max-width: 320px; }
.welcome-links { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; font-size: 13px; }
.welcome-links a { color: var(--accent); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--hair); background: var(--surface-2); color: var(--ink);
  font-weight: 600;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #7a5ff0; }
.btn.primary.stop { background: var(--surface-3); border-color: var(--bad); color: var(--ink); }
.btn.ghost { background: transparent; }
.btn.small { height: 34px; padding: 0 12px; font-size: 13px; }
.btn.big { height: 54px; font-size: 17px; width: 100%; max-width: 420px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.big { width: 48px; height: 48px; border-color: var(--hair); background: var(--surface-2); color: var(--ink); }
.icon-btn.big .i { width: 24px; height: 24px; }
.link-btn { border: 0; background: none; color: var(--accent); padding: 6px 0; text-decoration: underline; font-size: 14px; }

.actions { display: flex; justify-content: center; padding: 4px 0 8px; }
.actions.two { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }

/* segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--page); border: 1px solid var(--hair); border-radius: 10px; }
.seg button { border: 0; background: transparent; color: var(--ink-2); padding: 6px 12px; border-radius: 7px; font-size: 13px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--ink); }
.seg.wide { display: grid; grid-template-columns: 1fr 1fr; }
.seg.wide button { padding: 9px; font-size: 14px; }
.seg.small button { padding: 4px 10px; font-size: 12px; }

/* form fields */
.field { display: grid; gap: 6px; font-size: 13px; color: var(--ink-2); min-width: 0; }
.field.grow { flex: 1; }
.field > span b { color: var(--ink); }
.field-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.field-row .field { flex: 1 1 140px; }
select {
  height: 38px; padding: 0 10px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--hair); color: var(--ink); width: 100%;
}
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); min-height: 38px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.controls { display: grid; gap: 12px; }
.controls.compact { gap: 10px; padding: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tempo-row { display: flex; align-items: center; gap: 12px; }
.tempo { flex: 1; display: grid; gap: 0; min-width: 0; }
.tempo-val { font-size: 12px; color: var(--ink-2); line-height: 1; }
.tempo-val b { color: var(--ink); }
.tempo-row .check { min-height: 0; }

/* switch */
.switch { position: relative; display: inline-block; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--hair); transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: var(--ink-2); transition: .2s; }
.switch input:checked + span { background: var(--accent-strong); border-color: var(--accent-strong); }
.switch input:checked + span::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- swar labels (octave dots, komal / tivra marks) ---------- */
.sw { position: relative; display: inline-block; line-height: 1; white-space: nowrap; }
.sw.komal { text-decoration: underline; text-decoration-thickness: .08em; text-underline-offset: .14em; }
.sw.tivra::before { content: ""; position: absolute; left: 50%; top: -.32em; width: .08em; min-width: 1.5px; height: .26em; background: currentColor; transform: translateX(-50%); }
.sw.taar::after, .sw.mandra::after {
  content: ""; position: absolute; left: 50%; width: .17em; height: .17em; min-width: 3px; min-height: 3px;
  border-radius: 50%; background: currentColor; transform: translateX(-50%);
}
.sw.taar::after { top: -.3em; }
.sw.mandra::after { bottom: -.36em; }
.sw.komal.mandra::after { bottom: -.5em; }

/* ---------- riyaz: now card ---------- */
.now-card { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; }
.now-main { display: grid; gap: 6px; justify-items: center; min-width: 0; }
.big-swar { font-size: 64px; font-weight: 700; height: 84px; display: flex; align-items: center; justify-content: center; letter-spacing: .5px; }
.big-swar .sw.taar::after { top: -.12em; width: .12em; height: .12em; }
.big-swar .sw.mandra::after { bottom: -.1em; width: .12em; height: .12em; }
.big-swar .sw.komal.mandra::after { bottom: -.22em; }
.big-swar.idle { color: var(--axis); }
.start-btn { height: 84px; font-size: 18px; border-radius: 16px; }
.start-btn .i { width: 24px; height: 24px; }
.now-card:not(.active) .big-swar { display: none; }
.now-card.active .start-btn { display: none; }
.stop-btn { border-color: var(--bad); height: 30px; }
.stop-btn .i { color: var(--bad); }
.big-swar.good { color: var(--ink); }
.now-sub { display: flex; gap: 8px; align-items: baseline; min-height: 22px; }
.tune-text { font-weight: 600; font-size: 15px; }
.tune-text.good { color: var(--good); }
.tune-text.warn { color: var(--warn); }
.tune-text.bad { color: var(--bad); }

.meter { position: relative; width: 100%; max-width: 360px; padding-top: 2px; }
.meter-track { display: grid; grid-template-columns: 2fr 1.5fr 1.2fr 1.5fr 2fr; gap: 2px; height: 8px; }
.mz { border-radius: 4px; opacity: .35; }
.mz.good { background: var(--good); }
.mz.warn { background: var(--warn); }
.mz.bad { background: var(--bad); }
.meter-needle {
  position: absolute; top: -4px; left: 50%; width: 4px; height: 18px; margin-left: -2px;
  border-radius: 2px; background: var(--ink); box-shadow: 0 0 0 2px var(--surface);
  transition: transform .06s linear, opacity .2s; opacity: .25;
}
.meter-needle.on { opacity: 1; }
.meter-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-2); margin-top: 6px; }
.meter.small { max-width: 300px; margin: 0 auto; }

.hold { position: relative; width: 112px; height: 112px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring-track { stroke: var(--surface-3); }
.ring-fill { stroke: var(--good); stroke-linecap: round; stroke-dasharray: 263.9; stroke-dashoffset: 263.9; transition: stroke-dashoffset .1s linear, stroke .3s; }
.ring-fill.warn { stroke: var(--warn); }
.ring-fill.bad { stroke: var(--bad); }
.hold.done .ring-fill { stroke: var(--accent); }
.hold.done { animation: pop .5s ease; }
@keyframes pop { 50% { transform: scale(1.08); } }
.hold-text { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 1px; }
.hold-text b { font-size: 20px; }

/* ---------- graph ---------- */
.graph-card { padding: 10px 10px 8px; }
.graph-card .card-head { margin: 0 4px 6px; }
.graph-wrap { position: relative; height: 200px; }
.graph-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; }
.graph-card.collapsed .graph-wrap { display: none; }
.graph-card.collapsed .card-head { margin-bottom: 0; }
.graph-card.collapsed #riyazGraphToggle .i { transform: rotate(-90deg); }

/* ---------- mini keyboard ---------- */
.keys-card { display: grid; gap: 6px; margin: 0 -6px; }
.keys-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-left: 2px; }
.kh-cap { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.kh-cap > .tiny { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-help {
  flex: none; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  border: 1px solid var(--axis); color: var(--ink-2); font-size: 12px; font-weight: 700; text-decoration: none;
}
.kb-help:hover { border-color: var(--accent); color: var(--accent); }
.keys-head .kh-long { display: none; }   /* phones: short caption so it stays on one line */
.hold-ctl { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.seg.mini { padding: 2px; gap: 1px; border-radius: 8px; }
.seg.mini button { padding: 3px 7px; font-size: 12px; border-radius: 6px; min-width: 28px; }
.keyboard {
  position: relative; display: flex; height: 88px;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  border-radius: 10px; background: var(--page);
}
.keyboard::-webkit-scrollbar { display: none; }
.kb-inner { position: relative; display: flex; height: 100%; flex: 1 0 auto; min-width: 100%; }
.key {
  position: relative; border: 0; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.key .kn { font-size: 8.5px; font-weight: 600; line-height: 1; opacity: .55; letter-spacing: -.2px; }
.key .ks { line-height: 1; }
.key.w {
  flex: 1 0 19px; height: 100%; margin-right: 2px; gap: 5px;
  background: #d9d9de; color: #19191c; border-radius: 0 0 7px 7px;
  padding-bottom: 8px; font-size: 10.5px; font-weight: 600;
}
.key.w:last-child { margin-right: 0; }
.key.w.sa { background: #cbc3fa; }
.key.b {
  position: absolute; top: 0; z-index: 2; height: 56%; width: 4.2%; min-width: 17px; gap: 4px;
  background: #26262b; color: #d4d4da; border-radius: 0 0 5px 5px;
  font-size: 8.5px; font-weight: 600; padding-bottom: 5px; box-shadow: 0 0 0 2px var(--page); transform: translateX(-50%);
}
.key.b .kn { font-size: 7.5px; opacity: .65; }
.key.b.sa { background: #4b3a9e; color: #fff; }
.key.b.sa .kn { opacity: .8; }
/* keys just outside the practice range (needed to complete the piano layout) */
.key.w.out { background: #a8a8ae; color: #46464c; }
.key.b.out { background: #17171a; color: #77777d; }
/* note sounding now (tap again to stop) */
.key.w.playing { background: var(--accent-strong); color: #fff; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .6); }
.key.b.playing { background: var(--accent-strong); color: #fff; box-shadow: 0 0 0 2px var(--page), inset 0 0 0 2px rgba(255, 255, 255, .8); }
.key.playing .kn { opacity: .85; }
.key.live .kn { opacity: .85; }
.key.w.live { background: var(--good); color: #fff; }
.key.b.live { background: var(--good); color: #fff; }
.key.w.live.warn, .key.b.live.warn { background: var(--warn); color: #0b0b0b; }
.key.w.live.bad, .key.b.live.bad { background: var(--bad); color: #fff; }
.key.pressed { filter: brightness(.82); }

/* ---------- patterns ---------- */
.notes-card { padding: 12px; position: relative; }
/* count-in: 3 · 2 · 1 over the notes box */
.count-in {
  position: absolute; inset: 0; z-index: 3; border-radius: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: rgba(25, 25, 25, .78); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
.count-in[hidden] { display: none; }
.count-in b {
  width: 58px; height: 58px; border-radius: 50%; border: 2px solid var(--accent);
  display: grid; place-items: center; font-size: 28px; font-weight: 700; color: var(--ink);
  background: var(--accent-wash); animation: cnt-pop .3s ease-out;
}
.count-in .cnt-note { font-size: 13px; color: var(--ink-2); }
@keyframes cnt-pop { from { transform: scale(.8); opacity: .4; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .count-in b { animation: none; } }
.pat-notes {
  position: relative; display: flex; flex-wrap: wrap; gap: 6px 10px; align-content: flex-start;
  max-height: 120px; overflow-y: auto; padding: 6px 2px;
}
.pgroup { display: inline-flex; gap: 3px; }
.pgroup.turn { margin-left: 8px; padding-left: 10px; border-left: 1px solid var(--axis); }
.pchip {
  min-width: 34px; height: 30px; padding: 0 6px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--hair); font-size: 14px; font-weight: 600;
}
.pchip.cur { border-color: var(--accent); background: var(--accent-wash); transform: translateY(-1px); }
.pchip.good { background: rgba(10,172,35,.22); border-color: var(--good); }
.pchip.warn { background: rgba(251,179,21,.18); border-color: var(--warn); }
.pchip.bad  { background: rgba(220,60,61,.22); border-color: var(--bad); }
.pchip.miss { opacity: .45; border-style: dashed; }
.pat-result { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--hair); display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: baseline; }
.pat-result .score { font-size: 26px; font-weight: 700; }
/* small Listen / Practice buttons in the graph card's header row */
.pat-actions { display: flex; gap: 6px; }
.pat-actions .btn { height: 34px; padding: 0 12px; gap: 6px; font-size: 13px; }
.pat-actions .btn .i { width: 15px; height: 15px; }
.pat-actions .btn.primary { min-width: 98px; } /* same width for "Practice" and "Stop" */
.legend-item { font-size: 12px; }
.pat-result .legend-item i.miss { background: transparent; border: 1px dashed var(--ink-2); }
.pat-hint { flex-basis: 100%; font-size: 12px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.legend-item i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- ear training ---------- */
.ear-card { display: grid; gap: 12px; text-align: center; padding: 16px 14px; }
.ear-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); }
.ear-prompt { font-size: 20px; font-weight: 600; min-height: 56px; display: grid; place-items: center; }
.ear-prompt .sw { font-size: 40px; }
.ear-feedback { min-height: 24px; font-weight: 600; }
.ear-feedback.good { color: var(--good); }
.ear-feedback.warn { color: var(--warn); }
.ear-feedback.bad { color: var(--bad); }
.ear-answers { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.ans {
  height: 52px; border-radius: 12px; border: 1px solid var(--hair); background: var(--surface-2);
  font-size: 18px; font-weight: 700;
}
.ans:hover:not(:disabled) { background: var(--surface-3); }
.ans.correct { background: rgba(10,172,35,.25); border-color: var(--good); }
.ans.wrong { background: rgba(220,60,61,.25); border-color: var(--bad); }
.hear-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- stats ---------- */
.stat-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 2px; }
.tile .label { font-size: 12px; color: var(--ink-2); }
.tile .value { font-size: 26px; font-weight: 600; line-height: 1.15; }
.tile .sub { font-size: 12px; color: var(--ink-2); }
.tile .bar { height: 6px; border-radius: 3px; background: var(--surface-3); margin-top: 6px; overflow: hidden; }
.tile .bar i { display: block; height: 100%; border-radius: 3px; background: var(--good); }
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--font); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .mark, .chart .mark:hover { filter: brightness(1.2); }
.chart-empty { color: var(--ink-2); font-size: 13px; padding: 18px 0; text-align: center; }
.insight { margin: 0 0 10px; font-size: 14px; color: var(--ink); min-height: 1em; }
.chart-legend { display: flex; gap: 14px; margin-top: 8px; }
.stats-foot { display: flex; justify-content: center; padding: 4px 0 8px; }

/* tooltip */
.tip {
  position: fixed; z-index: 60; pointer-events: none;
  padding: 6px 10px; border-radius: 8px; font-size: 12px;
  background: #0b0b0b; color: var(--ink); border: 1px solid var(--axis);
  box-shadow: 0 6px 18px rgba(0,0,0,.5); max-width: 220px;
}
.tip b { font-size: 14px; display: block; }

/* ---------- footer ---------- */
.site-foot { margin-top: 24px; padding: 16px 0 24px; border-top: 1px solid var(--hair); text-align: center; }
.foot-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; margin-bottom: 8px; }
.foot-links a { color: var(--ink-2); text-decoration: none; font-size: 13px; }
.foot-links a:hover { color: var(--ink); text-decoration: underline; }
.foot-links.in-sheet { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--hair); }

/* ---------- dialogs / sheets ---------- */
dialog.sheet {
  width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  padding: 18px; border: 1px solid var(--hair); border-radius: 18px;
  background: var(--surface); color: var(--ink); overflow-y: auto;
}
dialog.sheet::backdrop { background: rgba(0,0,0,.65); backdrop-filter: blur(3px); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; margin-top: 14px; }
.sa-step p { margin: 8px 0; }
.read-text {
  margin: 10px 0; padding: 12px 14px; border-left: 3px solid var(--accent);
  background: var(--surface-2); border-radius: 0 10px 10px 0; font-size: 16px; line-height: 1.55;
}
.read-text span { display: block; }
.read-text .lang-hi { margin-top: 8px; color: var(--ink-2); }
.listen-box { margin-top: 12px; display: grid; gap: 8px; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .1s linear; }
.listen-status { font-size: 14px; color: var(--ink-2); min-height: 20px; }
.listen-status.live { color: var(--ink); }
.sa-found { font-size: 14px; color: var(--ink-2); }
.sa-found b { color: var(--ink); }
.sa-picker { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; margin: 12px 0; }
.sa-value { text-align: center; }
.sa-note { font-size: 40px; font-weight: 700; line-height: 1.1; }
.sa-kali { color: var(--accent); font-weight: 600; }
.quick-picks { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.quick-picks .chip { height: 32px; font-size: 13px; }
details.fine { margin-top: 12px; }
details.fine summary { cursor: pointer; color: var(--ink-2); font-size: 14px; }

.settings-list { display: grid; }
.set-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--hair); }
.set-row:last-child { border-bottom: 0; }
.set-row input[type="range"] { width: 130px; }
.set-row select { width: 110px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--bottom-ad-h)); transform: translateX(-50%); z-index: 70;
  padding: 10px 16px; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--axis);
  box-shadow: 0 8px 24px rgba(0,0,0,.5); font-size: 14px; max-width: calc(100vw - 32px);
}

/* ---------- ads ---------- */
.ad { display: none; }
body.ads-on .ad, body.ads-placeholder .ad { display: flex; align-items: center; justify-content: center; }
.ad-placeholder {
  width: 100%; height: 100%; display: grid; place-content: center; text-align: center;
  border: 1px dashed var(--axis); border-radius: 10px; color: var(--ink-2); font-size: 12px; background: var(--surface);
}
.ad-label { font-size: 10px; letter-spacing: .5px; text-transform: uppercase; color: var(--ink-2); }
.ad-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  height: var(--bottom-ad-h); padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
  background: var(--page); border-top: 1px solid var(--hair);
}
.ad-bottom > * { max-width: 728px; }
.ad-inline { min-height: 100px; }
body.ads-on, body.ads-placeholder { --bottom-ad-h: 62px; }
body.ads-on .app, body.ads-placeholder .app { padding-bottom: calc(var(--bottom-ad-h) + 8px); }

/* ---------- responsive ---------- */
@media (max-width: 370px) {
  .tabs button { width: 36px; }
  .chip-k { display: none; }
  /* fit all 16 piano keys without scrolling on small phones */
  .key.w { flex-basis: 18px; }
  .key.b { min-width: 16px; }
  .seg.mini button { padding: 3px 5px; min-width: 26px; }
}
@media (max-width: 420px) {
  .big-swar { font-size: 56px; height: 72px; }
  .start-btn { height: 72px; }
  .hold { width: 96px; height: 96px; }
  .hold-text b { font-size: 17px; }
}
@media (min-width: 640px) {
  .topbar { padding-left: 12px; padding-right: 12px; gap: 12px; }
  .brand { display: flex; }
  .tabs { margin: 0 auto; }
  .top-actions { margin-left: 0; }
  .tabs button { width: auto; padding: 0 12px; }
  .tabs button span { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
  #saChip > .i { display: inline; }
}
@media (min-width: 700px) {
  .layout { padding: 0 16px; }
  .big-swar { font-size: 76px; height: 96px; }
  .start-btn { height: 96px; }
  .hold { width: 130px; height: 130px; }
  .graph-wrap { height: 240px; }
  .stat-tiles { grid-template-columns: repeat(4, 1fr); }
  .actions.two { max-width: 520px; margin: 0 auto; width: 100%; }
}
@media (min-width: 520px) {
  .keys-head .kh-long { display: inline; }
  .keys-head .kh-short { display: none; }
}
@media (min-width: 700px) {
  .keys-card { margin: 0; }
  .keyboard { height: 104px; }
  .key.w { font-size: 13px; gap: 6px; padding-bottom: 10px; }
  .key .kn { font-size: 10px; }
  .key.b { font-size: 10px; padding-bottom: 7px; gap: 5px; }
  .key.b .kn { font-size: 9px; }
}
@media (min-width: 900px) {
  .brand-name { display: inline; }
  .chip.toggle { width: auto; padding: 0 12px 0 10px; gap: 6px; }
  .chip.toggle .tp-label { display: inline; }
  .chip.toggle .dot { position: static; }
  .tabs button { padding: 0 16px; }
}
@media (min-width: 1100px) {
  .chip-sub { display: inline; }
}
@media (min-width: 760px) {
  body.ads-on, body.ads-placeholder { --bottom-ad-h: 100px; }
}
/* desktop: side ad instead of bottom ad */
@media (min-width: 1100px) {
  .layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; }
  .side { display: block; padding-top: 12px; }
  .ad-side { position: sticky; top: 72px; width: 300px; height: 250px; }
  body.ads-on, body.ads-placeholder { --bottom-ad-h: 0px; }
  body.ads-on .ad-bottom, body.ads-placeholder .ad-bottom { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
