:root {
  --bg: #150f22;
  --bg2: #1c1530;
  --card: #211939;
  --card2: #2b2148;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3edff;
  --muted: rgba(243, 237, 255, 0.6);
  --accent: #ffa53a;
  --ok: #4ade80;
  --off: #fb7185;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(120% 55% at 50% -10%, #3a2253 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Devanagari', sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.modal, body.live { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: 0.45; cursor: default; }
h1 { font-size: 30px; line-height: 1.1; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 0 0 8px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; gap: 12px; }
.gap-s { gap: 8px; flex-wrap: wrap; }
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 18px) 16px calc(var(--safe-b) + 150px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.head { display: flex; align-items: flex-end; gap: 12px; padding: 8px 2px 2px; }
.head.sub { align-items: center; }
.head.sub h1 { font-size: 24px; }
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 500; margin-bottom: 2px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: block; }
.card.empty { text-align: center; padding: 28px 18px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.card.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #241300; font-weight: 700;
  padding: 10px 18px; border-radius: 999px; min-height: 44px; white-space: nowrap;
}
.btn.small { padding: 6px 14px; min-height: 36px; font-size: 14px; font-weight: 600; }
.btn.big { width: 100%; min-height: 56px; font-size: 17px; }
.btn.ghost { background: var(--card2); color: var(--text); border: 1px solid var(--line); font-weight: 600; }
.btn .i { width: 18px; height: 18px; }
.round { width: 44px; height: 44px; border-radius: 50%; background: var(--card2); display: grid; place-items: center; flex: none; border: 1px solid var(--line); }
.round.small { width: 36px; height: 36px; }
.round .i { width: 18px; height: 18px; }
.round [points^="7 4"] { fill: currentColor; }

/* swara notation */
.sw { position: relative; display: inline-block; font-weight: 700; }
.sw.komal { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 2px; }
.sw.tivra::before { content: ''; position: absolute; left: 50%; top: -0.3em; width: 2px; height: 0.35em; background: currentColor; }
.sw.mandra::after, .sw.taar::after { content: ''; position: absolute; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: currentColor; }
.sw.mandra::after { bottom: -0.45em; }
.sw.taar::after { top: -0.35em; }
.sw.taar.tivra::after { top: -0.65em; }
.sw.komal.mandra::after { bottom: -0.7em; }

/* practice */
.sa-title { font-size: 26px; font-weight: 800; letter-spacing: -0.01em; color: #ffd29a; }
.ex-list { display: grid; gap: 8px; }
.ex { text-align: left; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 11px 14px; display: flex; flex-direction: column; gap: 2px; }
.ex span { color: var(--muted); font-size: 13px; }
.ex.on { border-color: var(--accent); background: rgba(255, 165, 58, 0.12); }
.form { display: flex; flex-direction: column; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.field.col { flex-direction: column; align-items: stretch; gap: 8px; }
.field:last-child { border-bottom: 0; padding-bottom: 2px; }
.field > div { min-width: 0; }
select { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; max-width: 160px; }
input[type="range"] { accent-color: var(--accent); width: 150px; }
.seg { display: flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 8px; border-radius: 9px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--accent); color: #241300; font-weight: 700; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--card2); border: 1px solid var(--line); border-radius: 999px; transition: 0.2s; }
.switch span::after { content: ''; position: absolute; width: 24px; height: 24px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: 0.2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.start-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--safe-b) + 62px); z-index: 9;
  padding: 10px 16px; display: flex; justify-content: center;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}
.start-bar .btn { max-width: 608px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  background: rgba(21, 15, 34, 0.9); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(var(--safe-b) + 6px);
}
.tabbar a { flex: 1; max-width: 150px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--muted); font-size: 11px; font-weight: 500; }
.tabbar a.on { color: var(--text); }
.tabbar a.on svg { stroke: var(--accent); }
.tabbar svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
body.live .tabbar, body.live .view { display: none; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 60; background: rgba(5, 2, 12, 0.6); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 22px 22px 0 0; padding: 18px 18px calc(var(--safe-b) + 22px); display: flex; flex-direction: column; gap: 14px;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.find-live { text-align: center; display: flex; flex-direction: column; gap: 10px; padding: 8px 0; }
.find-hz { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.1s; }
.found { font-size: 48px; font-weight: 800; text-align: center; color: #ffd29a; }
.stack-btns { display: flex; flex-direction: column; gap: 8px; }
.scale-list { display: flex; flex-direction: column; }
.scale { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.scale.on .scale-pick b { color: var(--accent); }
.scale-pick { flex: 1; text-align: left; display: flex; flex-direction: column; }

/* live */
.live {
  position: fixed; inset: 0; z-index: 50; background: #0e0919; display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 12px) 14px calc(var(--safe-b) + 14px); gap: 10px;
}
.live-top { display: flex; justify-content: space-between; align-items: center; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
.seq { display: flex; gap: 6px; overflow-x: auto; padding: 10px 2px 8px; scrollbar-width: none; }
.seq::-webkit-scrollbar { display: none; }
.seq-n { flex: none; min-width: 42px; padding: 7px 8px; text-align: center; border-radius: 10px; background: var(--card); border: 1px solid var(--line); color: var(--muted); }
.seq-n.cur { border-color: var(--accent); color: var(--text); background: rgba(255, 165, 58, 0.18); }
.seq-n.hit { color: var(--ok); }
.seq-n.missed { color: var(--off); opacity: 0.7; }
.readout { display: flex; gap: 16px; align-items: center; }
.now { width: 112px; flex: none; text-align: center; }
.now-label { font-size: 12px; color: var(--muted); min-height: 16px; }
.now-sw { font-size: 44px; line-height: 1.25; color: #ffd29a; min-height: 56px; }
.meter-wrap { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.cents-meter { position: relative; height: 26px; border-radius: 13px; background: rgba(255, 255, 255, 0.06); overflow: hidden; }
.cents-meter .zone { position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%); background: rgba(74, 222, 128, 0.18); }
.cents-meter > i { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: rgba(255, 255, 255, 0.5); }
.cents-meter b { position: absolute; top: 3px; bottom: 3px; width: 8px; margin-left: -4px; border-radius: 4px; left: 50%; transition: left 0.06s linear; }
.cents-meter b.ok { background: var(--ok); }
.cents-meter b.off { background: var(--off); }
.cents-meter b.idle { background: rgba(255, 255, 255, 0.2); }
#cents-text { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.hold { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.06); overflow: hidden; margin-top: 4px; }
.hold i { display: block; height: 100%; width: 0; background: var(--ok); }
.hint { font-size: 14px; color: var(--muted); min-height: 20px; font-weight: 600; }
.hint.ok { color: var(--ok); }
.live-chart { flex: 1; min-height: 200px; width: 100%; border-radius: 14px; background: rgba(255, 255, 255, 0.025); }
.live-actions { display: flex; gap: 8px; }
.live-actions .btn { flex: 1; }
.btn.stop { background: var(--off); color: #2a0610; }

/* results */
.ring { position: relative; flex: none; }
.ring svg { width: 100%; height: 100%; }
.ring-bg { fill: none; stroke: rgba(255, 255, 255, 0.08); stroke-width: 10; }
.ring-fg { fill: none; stroke-width: 10; stroke-linecap: round; }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-label b { line-height: 1; }
.ring-label span { font-size: 12px; color: var(--muted); margin-top: 3px; }
.score-card { display: flex; align-items: center; gap: 18px; }
.mini { margin: 0; display: grid; gap: 6px; flex: 1; }
.mini div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.mini div:last-child { border-bottom: 0; }
.mini dt { color: var(--muted); font-size: 13px; }
.mini dd { margin: 0; font-weight: 700; white-space: nowrap; }
.tips ul { margin: 0; padding-left: 18px; display: grid; gap: 7px; color: var(--muted); }
.tips b { color: var(--text); }
.res-chart { height: 220px; margin-bottom: 8px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin: 0 4px 0 8px; }
.dot.ok { background: var(--ok); margin-left: 0; }
.dot.off { background: var(--off); }
.note-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.nchip { display: flex; flex-direction: column; align-items: center; min-width: 52px; padding: 8px 6px 6px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); gap: 4px; }
.nchip span { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nchip.great { border-color: rgba(74, 222, 128, 0.6); }
.nchip.great .sw { color: var(--ok); }
.nchip.hit .sw { color: var(--accent); }
.nchip.missed .sw, .nchip.pending .sw { color: var(--muted); }
.sw-rows { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.sw-row { display: grid; grid-template-columns: 46px 1fr 92px; align-items: center; gap: 10px; padding: 7px 0; }
.sw-name { font-size: 18px; text-align: center; color: #ffd29a; }
.dev-bar { position: relative; height: 14px; border-radius: 7px; background: rgba(255, 255, 255, 0.06); }
.dev-bar .band { position: absolute; top: 0; bottom: 0; background: rgba(74, 222, 128, 0.18); }
.dev-bar .mid { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: rgba(255, 255, 255, 0.45); }
.dev-bar b { position: absolute; top: 1px; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; }
.dev-bar b.ok { background: var(--ok); }
.dev-bar b.off { background: var(--off); }
.sw-val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; display: flex; flex-direction: column; }
.sw-val span { font-size: 11px; color: var(--muted); font-weight: 500; }
.actions-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* progress */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; }
.tile span { color: var(--muted); font-size: 13px; }
.tile b { font-size: 28px; }
.trend { height: 150px; }
.sess-list { display: flex; flex-direction: column; }
.sess { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.sess:last-child { border-bottom: 0; }
.sess > div { display: flex; flex-direction: column; }
.sess-score { font-size: 22px; }

canvas { display: block; width: 100%; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 140px); transform: translateX(-50%); z-index: 100;
  background: #f6efff; color: #1a1028; padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

@media (max-width: 380px) {
  .score-card { flex-direction: column; align-items: stretch; }
  .score-card .ring { align-self: center; }
  .now { width: 92px; }
  .now-sw { font-size: 36px; }
}

/* find my Sa curve */
.sa-curve { height: 240px; border-radius: 14px; background: rgba(255, 255, 255, 0.025); }
.find-now { font-variant-numeric: tabular-nums; color: #ffd29a; }
.find-result .found { font-size: 38px; }

/* mic level + warning */
.mic-level { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.mic-level .i { width: 15px; height: 15px; }
.mic-level i { display: block; width: 46px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.mic-level b { display: block; height: 100%; width: 0; background: var(--ok); transition: width 0.06s linear; }
.mic-warn { width: 100%; padding: 10px 12px; border-radius: 12px; background: rgba(251, 113, 133, 0.15); color: #ffc2cc; font-weight: 600; font-size: 14px; text-align: left; }
.link-btn { color: var(--accent); font-weight: 600; padding: 0; text-align: left; }
.live > * { width: 100%; max-width: 900px; margin-left: auto; margin-right: auto; }
.live > .live-chart { flex: 1; }
