:root {
  --bg: #0b2f44;
  --card: #113d55;
  --line: #1f5a72;
  --text: #e6f7f3;
  --muted: #8cc4bd;
  --accent: #f9e08c;
  --accent-ink: #0b2f44;
  --err: #f08a74;
  --dev: "Noto Sans Devanagari", "Inter", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
}

.hud-btn {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 0;
  background: rgba(11, 47, 68, 0.6);
  color: var(--text);
  z-index: 5;
}
.hud-btn.inline { position: static; }

/* Title over the play area: "Sur" (the note) lit up, "ang" quieter. */
.brand {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  height: 40px;
  padding: 0 18px;
  display: flex;
  align-items: baseline;
  line-height: 40px;
  border-radius: 999px;
  background: rgba(11, 47, 68, 0.6);
  font-size: 24px;
  letter-spacing: 0.5px;
  pointer-events: none;
  user-select: none;
  z-index: 4;
}
.brand .sur { font-weight: 800; color: var(--accent); text-shadow: 0 0 14px rgba(249, 224, 140, 0.45); }
.brand .ang { font-weight: 300; font-style: italic; color: #a8e6db; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
}
.overlay.center { display: grid; place-items: center; padding: 20px; background: rgba(6, 30, 44, 0.6); }

/* ---------- Start ---------- */

.start { display: grid; place-items: center; align-content: center; gap: 16px; background: rgba(6, 30, 44, 0.4); }
.start-btn {
  width: 96px;
  height: 96px;
  border-radius: 999px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 10px rgba(249, 224, 140, 0.22), 0 0 0 22px rgba(249, 224, 140, 0.1);
  animation: pulse 2.2s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 14px rgba(249, 224, 140, 0.26), 0 0 0 30px rgba(249, 224, 140, 0.08); } }
.err { color: var(--err); font-size: 14px; max-width: 320px; text-align: center; }

/* ---------- Settings sheet ---------- */

.sheet { background: rgba(6, 30, 44, 0.72); overflow-y: auto; }
.sheet-inner {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  background: var(--bg);
  padding: calc(16px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
  display: grid;
  gap: 18px;
  align-content: start;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.title { display: flex; align-items: baseline; gap: 10px; }
.title .dev { font-family: var(--dev); font-size: 32px; font-weight: 700; color: var(--accent); line-height: 1.2; }
.title .rom { font-weight: 800; color: var(--muted); }
.intro { color: var(--muted); font-size: 14px; }
section { display: grid; gap: 8px; }
h2 { font-size: 12px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
h2 .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.muted { color: var(--muted); font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
select {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
input[type=range] { accent-color: var(--accent); flex: 1; min-width: 140px; max-width: 260px; }
code { font-size: 13px; background: var(--card); padding: 1px 6px; border-radius: 6px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; width: fit-content; flex-wrap: wrap; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; white-space: nowrap; padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; font-family: var(--dev); }
.seg small { font-weight: 400; opacity: 0.8; font-family: "Inter", sans-serif; font-size: 11px; }
@media (max-width: 400px) { .seg span { padding: 6px 9px; font-size: 13px; } }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.switch { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.switch input { accent-color: var(--accent); width: 18px; height: 18px; }

.stage-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; }
.stage {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 8px 12px;
}
.stage:hover { border-color: var(--accent); }
.stage.current { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.stage .num { font-size: 12px; font-weight: 700; color: var(--muted); min-width: 18px; }
.stage .line { font-family: var(--dev); font-size: 17px; line-height: 1.6; }
.back { color: var(--muted); text-decoration: none; font-weight: 600; }

/* Swar notation (komal: line under, teevra: line over, octave digits) */
.swar { display: inline-block; white-space: nowrap; }
.swar .sn { position: relative; display: inline-block; }
.swar .sn.komal::after, .swar .sn.teevra::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 0.08em;
  min-height: 1.5px;
  background: currentColor;
}
.swar .sn.komal::after { bottom: 0.05em; }
.swar .sn.teevra::before { top: 0.05em; }
.swar sup, .swar sub { font-family: "Inter", sans-serif; font-size: 0.58em; font-weight: 600; line-height: 0; }
.swar sup { vertical-align: 0.85em; }
.swar sub { vertical-align: -0.4em; }
.beats { font-family: "Inter", sans-serif; font-size: 0.68em; color: var(--accent); margin-left: 2px; }
.hold { color: var(--muted); }
.rest { color: var(--muted); }

/* ---------- Result ---------- */

.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  max-width: 400px;
  width: 100%;
  display: grid;
  gap: 16px;
  text-align: center;
}
.card h2 { font-size: 24px; text-transform: none; letter-spacing: 0; color: var(--text); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stats div { border: 1px solid var(--line); border-radius: 12px; padding: 8px; display: grid; }
.stats b { font-size: 22px; }
.stats span { font-size: 12px; color: var(--muted); }
.worst { display: grid; gap: 4px; text-align: left; margin-top: 12px; }
.worst div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding: 4px 0; font-family: var(--dev); }
.actions { display: flex; gap: 10px; justify-content: center; }
.primary, .ghost { padding: 10px 20px; border-radius: 999px; font-weight: 700; }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; }
.ghost { background: none; border: 1px solid var(--line); }
