:root {
  --bg: #0e1013;
  --panel: #171a20;
  --panel-2: #20242d;
  --line: #2b303b;
  --text: #eceff4;
  --muted: #8b93a1;
  --accent: #f5a524;
  --accent-ink: #1a1203;
  --khali: #6fb8ff;
  --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 { 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; }
.count {
  display: inline-block; min-width: 20px; margin-left: 7px; padding: 0 6px;
  border-radius: 99px; background: var(--accent); color: var(--accent-ink);
  font-size: 12px; font-weight: 700; line-height: 20px; text-align: center;
}

/* ---- taal chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; }
.chip {
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }

.taal-info { margin: -6px 0 0; text-align: center; color: var(--muted); font-size: 14px; }
.draft-note { margin: -8px 0 0; text-align: center; color: #e8c37a; font-size: 12.5px; }

/* ---- matra display ----
   --n / --v (cells and vibhags in the widest row) are set from Alpine; the cell width fills the screen. */
.beats {
  --cell: min(56px, calc((min(100vw, 520px) - 36px - (var(--v, 2) - 1) * 14px - (var(--n, 8) - var(--v, 2)) * 3px) / var(--n, 8)));
  display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 4px 0;
}
.beat-row { display: flex; gap: 14px; justify-content: center; }
.vibhag { display: flex; flex-direction: column; gap: 4px; }
.mark { height: 18px; padding-left: 2px; font-size: 13px; font-weight: 700; line-height: 18px; color: var(--muted); }
.mark.k-sam { color: var(--accent); }
.mark.k-tali { color: var(--text); }
.mark.k-khali { color: var(--khali); }
.cells { display: flex; gap: 3px; }

.cell {
  width: var(--cell);
  min-height: calc(var(--cell) * 1.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 0;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  transition: background .12s ease-out, transform .12s ease-out, box-shadow .12s ease-out;
}
.cell.has-bol { min-height: calc(var(--cell) * 1.5); }
.cell .num { font-size: clamp(14px, calc(var(--cell) * .42), 22px); line-height: 1.1; }
.cell .bol {
  font-size: clamp(9px, calc(var(--cell) * .21), 12px);
  line-height: 1.15;
  white-space: nowrap;
  color: var(--muted);
  letter-spacing: -.01em;
}
.cell .dots { display: flex; gap: 3px; height: 6px; visibility: hidden; }
.cell .dots i { width: 5px; height: 5px; border-radius: 50%; background: rgba(26, 18, 3, .3); }
.cell .dots i.lit { background: var(--accent-ink); }
.cell.on .dots { visibility: visible; }

.cell.sam   { border-color: var(--accent); color: var(--text); }
.cell.tali  { border-color: #c9ced8; color: var(--text); }
.cell.khali { border-color: var(--khali); border-style: dashed; color: var(--text); }
.cell.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 18px rgba(245, 165, 36, .55);
  transform: scale(1.07);
  transition: none;
}
.cell.on .bol { color: var(--accent-ink); }
.cell.on.khali { background: var(--khali); border-color: var(--khali); box-shadow: 0 0 18px rgba(111, 184, 255, .5); }

/* ---- control 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; }
.label { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.value { font-weight: 650; font-variant-numeric: tabular-nums; font-size: 14px; }
.ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

.tempo-head { display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; gap: 8px; margin-bottom: 4px; }
.tempo-val { text-align: center; }
.tempo-val .num { font-size: 56px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.tempo-val .unit { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); }
.step {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 28px; line-height: 1;
}
.step:active { background: var(--line); }
.ghost { padding: 7px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); font-size: 14px; }
.ghost:active { background: var(--line); }

/* ---- 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.four { grid-template-columns: repeat(4, 1fr); gap: 3px; }
.seg button { padding: 12px 8px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 600; }
.seg.four button { padding: 9px 2px; font-size: 12.5px; line-height: 1.2; }
.seg.four button small { display: block; margin-top: 1px; font-size: 11px; font-weight: 500; opacity: .8; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.seg-hint { margin: 8px 2px 0; font-size: 13px; color: var(--muted); }

/* ---- on/off switch ---- */
.bols-row { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: -4px; }
.switch { position: relative; 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; }

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

/* ---- 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);
}

/* ---- 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; }

/* ---- sessions sheet ---- */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .6);
}
.sheet {
  width: 100%; max-width: 520px; max-height: 88vh; max-height: 88dvh; overflow-y: auto;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  border: 1px solid var(--line); border-bottom: 0;
  border-radius: 22px 22px 0 0;
  background: var(--panel);
  overscroll-behavior: contain;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.save-row { display: flex; gap: 8px; }
.save-row input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit;
}
.save-btn { padding: 0 20px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.slist { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.srow { padding: 10px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-2); }
.sload { display: block; width: 100%; padding: 2px 0 8px; border: 0; background: transparent; text-align: left; }
.sname { display: block; font-weight: 650; overflow-wrap: anywhere; }
.ssum { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); }
.sact { display: flex; gap: 8px; }
.mini { padding: 7px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 13px; }
.mini.danger { margin-left: auto; color: #ffb4b4; }
.mini.danger.sure { background: var(--stop); border-color: var(--stop); color: #fff; }
.sheet-foot { display: flex; gap: 8px; margin-top: 16px; }

.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) {
  .cell, .switch i { transition: none; }
}
