:root {
  --bg: #0e1013;
  --panel: #171a20;
  --panel-2: #20242d;
  --line: #2b303b;
  --text: #eceff4;
  --muted: #8b93a1;
  --accent: #f5a524;
  --accent-ink: #1a1203;
  --good: #3ecf6e;
  --stop: #e5484d;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[x-cloak] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
}
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button:disabled { opacity: .45; cursor: default; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 0;
}

/* ---- header ---- */
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.top h1 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: .01em; }
.top .hindi { margin: 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.ghost { display: inline-block; padding: 7px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); font-size: 14px; color: inherit; text-decoration: none; }
.ghost:active { background: var(--line); }

/* ---- pickers ---- */
.picks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.label { font-size: 12.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.label .hz { margin-left: 4px; text-transform: none; letter-spacing: 0; color: var(--text); }
select {
  width: 100%; min-width: 0; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-size: 15px;
}
.raag-info { margin: -4px 0 0; text-align: center; color: var(--muted); font-size: 13.5px; }
.raag-info .draft { color: #e8c37a; }

/* ---- panels ---- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; }
.row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; min-height: 34px; gap: 10px; }
.row-head.sep { margin-top: 12px; }
.value { font-weight: 650; font-variant-numeric: tabular-nums; font-size: 14px; }
.seg-hint { margin: 8px 2px 0; font-size: 13px; color: var(--muted); }

details.fold > summary {
  list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); min-height: 24px;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: '+'; font-size: 20px; line-height: 1; color: var(--muted); }
details.fold[open] > summary::after { content: '−'; }
details.fold[open] > summary { margin-bottom: 8px; }

/* ---- segmented toggles ---- */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 6px; padding: 4px; border-radius: 14px; background: var(--panel-2); }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg button { padding: 11px 6px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg.compact { margin-top: 0; }
.seg.compact button { padding: 8px 6px; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }

/* ---- on/off switch ---- */
.switch { position: relative; flex: none; width: 52px; height: 30px; padding: 0; border: 0; border-radius: 99px; background: var(--panel-2); }
.switch i { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #c9ced8; transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on i { transform: translateX(22px); background: #fff; }

/* ---- sliders ---- */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 40px; margin: 0; background: transparent; touch-action: pan-y; --p: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 99px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--panel-2) var(--p));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 30px; height: 30px; margin-top: -11px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
}
input[type="range"]::-moz-range-track { height: 8px; border-radius: 99px; background: var(--panel-2); }
input[type="range"]::-moz-range-progress { height: 8px; border-radius: 99px; background: var(--accent); }
input[type="range"]::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
}

/* ---- target swar and ring ---- */
.stage { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.ring-wrap { position: relative; width: min(256px, 70vw); aspect-ratio: 1; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--panel-2); stroke-width: 5; }
.ring-fg { fill: none; stroke: var(--good); stroke-width: 11; stroke-linecap: round; transition: stroke-dashoffset .12s linear; }
.ring-fg.done { stroke: var(--accent); }
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.ring-text .oct { font-size: 10px; letter-spacing: .3em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.ring-text .hindi-note { font-size: 13px; color: var(--muted); margin-top: 2px; min-height: 18px; }
.ring-text .big { font-size: clamp(52px, 17vw, 76px); font-weight: 800; line-height: 1.05; transition: color .15s; }
.ring-text .big.done { color: var(--good); }
.ring-text .hz { font: 12px ui-monospace, Menlo, Consolas, monospace; color: var(--muted); margin-top: 2px; }
.ring-text .status { margin-top: 6px; min-height: 22px; font-size: 15px; font-weight: 650; color: var(--accent); }

/* ---- tuner bar (+-100 cents) ---- */
.tuner { position: relative; width: min(100%, 400px); height: 12px; margin-top: 6px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); overflow: visible; }
.tuner .band { position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%); background: rgba(62, 207, 110, .18); border-left: 1px solid rgba(62, 207, 110, .5); border-right: 1px solid rgba(62, 207, 110, .5); }
.tuner .mid { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px; background: var(--good); }
.tuner .needle { position: absolute; top: -5px; bottom: -5px; width: 0; transition: left .08s linear; }
.tuner .needle i { position: absolute; left: -3px; top: 0; bottom: 0; width: 6px; border-radius: 99px; background: #fff; box-shadow: 0 0 10px rgba(255, 255, 255, .8); }
.tuner .needle.ok i { background: var(--good); box-shadow: 0 0 12px var(--good); }
.tuner-labels { display: flex; justify-content: space-between; align-items: center; width: min(100%, 400px); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tuner-labels .reading { font: 13px ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0; color: var(--text); text-transform: none; }

/* ---- swar strip ---- */
.strip { display: flex; gap: 6px; overflow-x: auto; padding: 8px 2px 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.strip::-webkit-scrollbar { display: none; }
.sw {
  flex: none; min-width: 48px; padding: 4px 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 1px;
  border: 1px solid transparent; border-radius: 12px; background: transparent; color: var(--muted); font-size: 16px; font-weight: 700;
}
.sw.on { color: var(--accent); border-color: var(--accent); background: rgba(245, 165, 36, .1); transform: scale(1.12); }
.sw.komal span { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 2px; }
.sw.tivra span { text-decoration: overline; text-decoration-thickness: 2px; }
.sw .dot { width: 5px; height: 5px; border-radius: 50%; background: transparent; }
.sw .dot.show { background: currentColor; }

.nav { display: flex; gap: 8px; align-items: center; }
.nav .ghost { flex: 1; text-align: center; padding: 12px 8px; }
.count-note { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }

.offline-note { margin: -4px 0 0; text-align: center; font-size: 12.5px; color: var(--muted); }

/* ---- start / stop dock ---- */
.dock {
  position: sticky; bottom: 0; margin: auto -16px 0;
  padding: 18px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 72%, rgba(14, 16, 19, 0));
}
.go {
  width: 100%; height: 64px; display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 20px; background: var(--accent); color: var(--accent-ink); font-size: 20px; font-weight: 700;
}
.go svg { width: 24px; height: 24px; fill: currentColor; }
.go.running { background: var(--stop); color: #fff; }
.notice { margin: 10px 0 0; text-align: center; font-size: 14px; color: #ffb4b4; }

.toast {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); z-index: 30;
  transform: translateX(-50%); max-width: min(92vw, 440px);
  padding: 11px 16px; border-radius: 12px; background: #2f3542; color: var(--text); font-size: 14px; text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5); pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .ring-fg, .tuner .needle, .switch i, .sw { transition: none; }
}

/* ---- microphone level meter ---- */
.mic-meter { display: flex; align-items: center; gap: 10px; width: min(100%, 400px); margin-top: 8px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.mic-meter .bar { position: relative; flex: 1; height: 8px; border-radius: 99px; background: var(--panel-2); overflow: visible; }
.mic-meter .bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; background: #5a6272; transition: width .06s linear; }
.mic-meter .bar i.hi { background: var(--good); }
.mic-meter .bar b { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--accent); }
