: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: 54px; display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 16px; background: var(--accent); color: var(--accent-ink); font-size: 18px; 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); }

/* ================= Swar Rachana ================= */
.text { width: 100%; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 16px; }
textarea.text { resize: vertical; line-height: 1.5; }
textarea.notes { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .02em; }
.label.sm { display: block; margin: 10px 0 4px; font-size: 11.5px; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.doc-actions .ghost { flex: 1; text-align: center; padding: 9px 8px; cursor: pointer; }
.file { cursor: pointer; }
.ghost.danger, .mini.danger { color: #ff9a9a; }
.ghost.wide { width: 100%; text-align: center; padding: 13px; }

.sections { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0; scrollbar-width: none; }
.sections::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 9px 16px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-weight: 600; font-size: 14px; }
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.add { border-style: dashed; }
.sec-edit { display: flex; gap: 8px; align-items: center; }
.sec-edit .text { flex: 1; }
.sec-edit .ghost { flex: none; padding: 9px 12px; font-size: 13px; }

.av .row-head { flex-wrap: wrap; }
.av-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.mini { padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); font-size: 13px; }
.err { margin: 6px 0 0; color: #ff9a9a; font-size: 13.5px; }
.warn { margin: 6px 0 0; color: #e8c37a; font-size: 13.5px; }

/* the written notation */
.grid { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.grow { display: flex; gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
.vib { display: flex; flex-direction: column; min-width: 0; border-left: 2px solid var(--line); }
.vib:first-child { border-left: 0; }
.vmark { height: 20px; line-height: 20px; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--panel-2); border-bottom: 1px solid var(--line); }
.vib.sam .vmark { color: var(--accent-ink); background: var(--accent); }
.vib.khali .vmark { color: var(--text); }
.vbeats { display: flex; flex: 1; }
.beat { flex: 1 1 0; min-width: 0; padding: 6px 2px 4px; text-align: center; border-left: 1px solid rgba(255, 255, 255, .06); cursor: pointer; transition: background .08s; }
.beat:first-child { border-left: 0; }
.beat.now { background: rgba(245, 165, 36, .28); }
.sws { min-height: 26px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0 4px; font-size: 15px; font-weight: 700; line-height: 1.5; }
.sws.many { font-size: 11px; gap: 0 2px; }
.sws .sw { display: inline-block; position: relative; padding: 0 1px; }
.sw.komal { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 2px; }
.sw.tivra { text-decoration: overline; text-decoration-thickness: 2px; }
.sw.taar::before, .sw.mandra::after { content: ''; position: absolute; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: currentColor; }
.sw.taar::before { top: -4px; }
.sw.mandra::after { bottom: -4px; }
.sw.hold, .sw.rest { color: var(--muted); font-weight: 400; }
.lyr { min-height: 20px; margin-top: 2px; font-size: 13px; font-weight: 600; color: #f4f6fa; line-height: 1.3; overflow-wrap: anywhere; }

/* swar keypad */
.keypad { padding: 8px; margin-bottom: 10px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 -6px 18px rgba(0, 0, 0, .45); }
.kp-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.kp-row + .kp-row { margin-top: 6px; }
.kp-row.two { grid-template-columns: repeat(4, 1fr); }
.key { padding: 11px 2px; border: 0; border-radius: 10px; background: var(--panel-2); font-size: 16px; font-weight: 700; color: var(--text); user-select: none; -webkit-user-select: none; }
.key:active { background: var(--accent); color: var(--accent-ink); }
.key.komal { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px; }
.key.tivra { text-decoration: overline; text-decoration-thickness: 2px; }
.kp-row.two .key { font-size: 13px; font-weight: 600; }

.help { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.help li + li { margin-top: 6px; }
.help b { color: var(--text); }
body.has-keypad .app { padding-bottom: 150px; }

.kp-row.oct { grid-template-columns: repeat(3, 1fr); }
.kp-row.oct .key { font-size: 13px; font-weight: 600; }
.key.on { background: var(--accent); color: var(--accent-ink); }
.kp-row:not(.oct):not(.two) .key.taar, .kp-row:not(.oct):not(.two) .key.mandra { position: relative; }
.key.taar::before, .key.mandra::after { content: ''; position: absolute; left: 50%; width: 5px; height: 5px; margin-left: -2px; border-radius: 50%; background: currentColor; }
.key.taar::before { top: 4px; }
.key.mandra::after { bottom: 4px; }

.av-actions.play, .av-actions.edit { margin-top: 8px; }
.av-actions .mini.pri { flex: 1; text-align: center; background: var(--panel-2); border-color: var(--accent); color: var(--text); font-weight: 600; padding: 9px 6px; }
.av-actions.edit .mini { flex: 1; text-align: center; }
.rep { display: inline-flex; align-items: center; gap: 6px; }
.rep-l { font-size: 12px; color: var(--muted); }
.rep b { min-width: 28px; text-align: center; font-variant-numeric: tabular-nums; }
.mini.sq { width: 32px; padding: 5px 0; text-align: center; font-size: 16px; line-height: 1; }
.mini:disabled { opacity: .35; }
.dock-btns { display: flex; gap: 10px; }
.dock-btns .go { flex: 1; }
.dock-btns .go.alt { flex: 0 0 38%; background: var(--panel-2); color: var(--text); border: 1px solid var(--accent); }

.summary { margin: 10px 0 0; font-size: 14px; color: var(--text); }
.credit { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
.where { text-transform: none; letter-spacing: 0; font-size: 12.5px; color: var(--accent); margin-left: 4px; }

.avwrap { display: flex; flex-direction: column; gap: 10px; }
.sec-head { margin: 8px 2px 0; font-size: 15px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.mini:disabled { opacity: .35; }

.span-row { display: flex; gap: 10px; margin: 6px 0 2px; }
.span-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted, #8a93a6); flex: 1; }
.span-row input[type=number] { width: 100%; }

/* sheet (spreadsheet-style) layout */
.app.wide { max-width: 1180px; }
.sheetwrap { margin-top: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.sheet { border-collapse: collapse; width: 100%; min-width: 760px; table-layout: fixed; font-size: 14px; }
.sheet th, .sheet td { border: 1px solid rgba(255, 255, 255, .09); padding: 0; text-align: center; height: 30px; }
.sheet .vs { border-left: 2px solid rgba(255, 255, 255, .35); }
.sheet .sh-num th { font-weight: 700; color: var(--text); padding: 3px 0; background: rgba(255, 255, 255, .03); }
.sheet .sh-num th small { display: block; font-size: 11px; color: var(--accent); min-height: 13px; }
.sheet .sh-bol th { font-weight: 400; font-size: 12px; color: var(--muted, #8a93a6); padding: 2px 0; }
.sheet tbody { border-top: 6px solid transparent; }
.sheet tbody:first-of-type { border-top: 0; }
.sheet td.off { background: rgba(255, 255, 255, .02); }
.sheet td.now { background: rgba(245, 165, 36, .28); }
.sheet .cell { display: block; width: 100%; min-height: 30px; line-height: 30px; padding: 0 2px; border: 0; background: transparent; color: inherit; font: inherit; text-align: center; border-radius: 0; cursor: pointer; }
.sheet input.cell:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: rgba(245, 165, 36, .08); cursor: text; }
.sheet .lyc { font-size: 13px; font-weight: 600; color: #f4f6fa; }
.sheet .swc { font-weight: 700; font-size: 15px; letter-spacing: .02em; color: var(--accent); }

.fold-help { margin-top: 10px; font-size: 14px; }
.fold-help summary { cursor: pointer; color: var(--accent); }
.help-list { margin: 8px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.help-list b { color: var(--text); }

.grp { margin: 12px 0 4px; }
.seg-hint.warn { color: #ffb4a8; }

/* ---- sync ---- */
.sync-p { margin: 8px 0; font-size: 14px; line-height: 1.5; }
.sync-p.warn { color: #ffd9a0; }
.sync-p.sep { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }
.sync-in { width: 100%; box-sizing: border-box; background: var(--panel-2); color: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; }
.sync-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; align-items: center; }
.sync-join { display: flex; gap: 8px; align-items: flex-end; margin: 10px 0; }
.sync-join .field { flex: 1; }
.sync-box { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 12px 0; }
.sync-key { font: 600 20px/1.4 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .06em; margin: 6px 0; word-break: break-all; }
.pair { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.qr { width: 180px; max-width: 100%; background: #fff; padding: 6px; border-radius: 10px; }
.qr svg { display: block; width: 100%; height: auto; }
.pair-code { font: 700 30px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .08em; margin: 4px 0; }
.devs { list-style: none; margin: 8px 0; padding: 0; }
.devs li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }
.pill { font-size: 11px; background: var(--accent); color: #111; padding: 1px 8px; border-radius: 99px; margin-left: 6px; }
.link-offer { margin-bottom: 12px; border-color: var(--accent); }
.ghost.small { padding: 4px 10px; font-size: 13px; }
.ghost.strong { border-color: var(--accent); color: var(--accent); }

.avwrap { scroll-margin-top: 8px; }
/* wide screens and landscape phones: let all 16 columns fit */
@media (min-width: 600px) { .sheet { min-width: 0; } .sheet .swc { font-size: 14px; } }
/* short screens (phone in landscape): slimmer Play/Pause/Stop bar */
@media (max-height: 520px) {
  .go { height: 40px; font-size: 16px; border-radius: 12px; }
  .go svg { width: 18px; height: 18px; }
  .dock { padding-top: 8px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
}
