/* ─── design tokens ──────────────────────────────────────────────── */
:root {
  color-scheme: light;
  --bg: #f7efe3;
  --bg-soft: rgba(255,255,255,0.68);
  --panel: rgba(255,255,255,0.84);
  --panel-strong: #ffffff;
  --text: #241a14;
  --muted: #6b5d52;
  --line: rgba(60,42,30,0.16);
  --accent: #b8502f;
  --accent-strong: #81351f;
  --accent-soft: rgba(184,80,47,0.13);
  --shadow: 0 22px 60px rgba(45,28,16,0.16);
  --radius-lg: 28px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --arc-start: #e8834a;
  --arc-mid:   #f6c84e;
  --arc-end:   #e8834a;
  --sun-color: #f7b731;
  --tz-ocean:  #d4e8f5;
}

body[data-theme="deep-night"] {
  color-scheme: dark;
  --bg: #081225;
  --bg-soft: rgba(20,32,58,0.78);
  --panel: rgba(13,26,50,0.88);
  --panel-strong: #14203b;
  --text: #edf4ff;
  --muted: #a7b4ca;
  --line: rgba(217,227,255,0.14);
  --accent: #8db7ff;
  --accent-strong: #c7dcff;
  --accent-soft: rgba(141,183,255,0.16);
  --shadow: 0 24px 70px rgba(0,0,0,0.36);
  --arc-start: #1a2a5e;
  --arc-mid:   #2a3a7a;
  --arc-end:   #1a2a5e;
  --sun-color: #4a6ab0;
  --tz-ocean:  #1a2a40;
}

body[data-theme="dawn"] {
  --bg: #fae4cf;
  --bg-soft: rgba(255,247,235,0.72);
  --panel: rgba(255,250,242,0.88);
  --text: #2b1b15;
  --muted: #755f55;
  --accent: #d96133;
  --accent-strong: #8d3521;
  --accent-soft: rgba(217,97,51,0.14);
  --arc-start: #c96b30;
  --arc-mid:   #f5a54a;
  --arc-end:   #d96133;
  --sun-color: #f5a54a;
}

body[data-theme="morning"] {
  --bg: #edf6df;
  --bg-soft: rgba(255,255,255,0.68);
  --panel: rgba(255,255,255,0.86);
  --text: #182315;
  --muted: #53614a;
  --accent: #568b3a;
  --accent-strong: #345c23;
  --accent-soft: rgba(86,139,58,0.14);
  --arc-start: #87b85a;
  --arc-mid:   #f0d060;
  --arc-end:   #87b85a;
  --sun-color: #e8c84a;
}

body[data-theme="afternoon"] {
  --bg: #fff4bf;
  --bg-soft: rgba(255,255,255,0.64);
  --panel: rgba(255,255,255,0.88);
  --text: #241e10;
  --muted: #6b6043;
  --accent: #bb7a13;
  --accent-strong: #7c500b;
  --accent-soft: rgba(187,122,19,0.15);
  --arc-start: #d4a020;
  --arc-mid:   #ffe060;
  --arc-end:   #d4a020;
  --sun-color: #ffe060;
}

body[data-theme="sunset"] {
  --bg: #f5d3c6;
  --bg-soft: rgba(255,247,240,0.7);
  --panel: rgba(255,251,248,0.88);
  --text: #291819;
  --muted: #705a5b;
  --accent: #be4f5a;
  --accent-strong: #82313b;
  --accent-soft: rgba(190,79,90,0.14);
  --arc-start: #c85050;
  --arc-mid:   #f07050;
  --arc-end:   #c85050;
  --sun-color: #f07050;
}

body[data-theme="evening"] {
  color-scheme: dark;
  --bg: #161936;
  --bg-soft: rgba(28,31,64,0.76);
  --panel: rgba(25,29,59,0.9);
  --panel-strong: #222747;
  --text: #f5f0ff;
  --muted: #bab4d2;
  --line: rgba(237,229,255,0.16);
  --accent: #c4a1ff;
  --accent-strong: #eadcff;
  --accent-soft: rgba(196,161,255,0.16);
  --shadow: 0 24px 70px rgba(0,0,0,0.3);
  --arc-start: #6050c0;
  --arc-mid:   #9070e0;
  --arc-end:   #6050c0;
  --sun-color: #9070e0;
  --tz-ocean:  #1e1e3a;
}

/* ─── reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html {
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  max-width: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, var(--accent-soft), transparent 34rem),
    linear-gradient(135deg, var(--bg), color-mix(in srgb, var(--bg), #fff 10%));
  color: var(--text);
  font-family: var(--font-sans);
  transition: background 320ms ease, color 320ms ease;
}

button, input, select { font: inherit; color: inherit; }

/* ─── app shell ──────────────────────────────────────────────────── */
.app-shell {
  width: min(820px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 0 0 80px;
}

/* ─── top bar ────────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 10px;
  gap: 12px;
}

.top-bar-left {
  display: flex;
  align-items: baseline;
  gap: 16px;
}

.wordmark {
  font-size: 0.78rem;
  font-weight: 780;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.tz-btn {
  display: flex;
  align-items: baseline;
  gap: 8px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 120ms;
}
.tz-btn:hover { opacity: 1; }

#tz-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

#local-time {
  font-size: 1.05rem;
  letter-spacing: -0.03em;
  font-weight: 700;
}

.theme-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: right;
}

/* ─── sun arc ────────────────────────────────────────────────────── */
.sun-arc-wrap {
  padding: 4px 20px 0;
  position: relative;
}

.sun-arc-svg {
  width: 100%;
  height: 130px;
  display: block;
  cursor: ew-resize;
  touch-action: none;  /* allow pointer capture on touch without scroll conflict */
}

.sun-arc-svg.is-dragging { cursor: grabbing; }

.sky-bg {
  fill: var(--accent-soft);
  opacity: 0.3;
}

.ground-bg {
  fill: var(--muted);
  opacity: 0.05;
}

.arc-path {
  stroke-width: 1.8;
  fill: none;
}

.arc-day {
  stroke: url(#arc-grad);
  stroke-dasharray: 4 5;
  opacity: 0.65;
}

.arc-night {
  stroke: var(--muted);
  stroke-dasharray: 2 7;
  opacity: 0.22;
}

.horizon-line {
  stroke: var(--muted);
  stroke-width: 1;
  opacity: 0.3;
}

.horizon-tick {
  stroke: var(--muted);
  stroke-width: 1.5;
  opacity: 0.3;
}

/* day: glowing; night: dim moon appearance */
.sun-dot {
  fill: var(--sun-color);
  filter: drop-shadow(0 0 6px var(--sun-color));
}

.sun-dot.is-night {
  fill: var(--muted);
  filter: none;
  opacity: 0.45;
}

.arc-labels {
  display: flex;
  justify-content: space-between;
  padding: 3px 20px 0;
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.55;
}

/* ─── raag list ──────────────────────────────────────────────────── */
.raag-list {
  margin-top: 10px;
  padding: 0 12px;
}

.raag-row {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 13px 10px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 100ms;
  border-radius: 0;
}

.raag-row:first-child {
  border-top: 1px solid var(--line);
}

.raag-row:hover {
  background: var(--accent-soft);
}

.raag-row-name {
  font-size: 1.05rem;
  font-weight: 550;
  letter-spacing: -0.01em;
}

.raag-row-star {
  display: inline-block;
  font-size: 0.6rem;
  opacity: 0.35;
  vertical-align: middle;
  margin-right: 5px;
  transform: translateY(-1px);
}

.raag-row-time {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.raag-list-empty {
  padding: 3rem 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ─── detail overlay ─────────────────────────────────────────────── */
.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  overflow-y: auto;
  overflow-x: hidden;
  animation: slide-in 220ms cubic-bezier(0.22,1,0.36,1) both;
}

.detail-overlay[hidden] {
  display: none;
}

@keyframes slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.detail-overlay-inner {
  width: min(820px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 18px 20px 80px;
}

.detail-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 24px;
  opacity: 0.8;
  transition: opacity 120ms;
}
.detail-back:hover { opacity: 1; }

/* ─── detail content ─────────────────────────────────────────────── */
.detail-title {
  font-size: clamp(2.4rem, 8vw, 5rem);
  letter-spacing: -0.07em;
  line-height: 1;
  margin: 0 0 6px;
  overflow-wrap: anywhere;
}

.detail-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 18px;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 24px; }
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--muted);
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 650;
}
.chip.strong { color: var(--accent-strong); background: var(--accent-soft); border-color: transparent; }
.chip.warn { color: #92531d; background: rgba(255,174,68,0.17); }
body[data-theme="deep-night"] .chip.warn,
body[data-theme="evening"] .chip.warn { color: #ffd498; }

.detail-tonic-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.detail-tonic-row label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
}

.detail-tonic-row select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  padding: 0.3rem 0.8rem;
  outline: none;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 14px;
  min-width: 0;
}

.info-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  padding: 16px;
  min-width: 0;
  max-width: 100%;
}

.info-card.full { grid-column: 1 / -1; }
.info-card h3 { margin: 0 0 0.65rem; font-size: 0.9rem; }
.info-card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 0.65rem;
  min-width: 0;
}
.info-card-heading h3 { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.audio-play {
  flex: 0 0 auto;
  min-width: 58px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--accent-strong);
  padding: 0.25rem 0.65rem;
  font-size: 0.74rem;
  font-weight: 800;
  cursor: pointer;
}
.audio-play:hover:not(:disabled),
.audio-play.is-playing {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.audio-play:disabled {
  cursor: default;
  opacity: 0.45;
}
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.mono { font-family: var(--font-mono); }
.sargam-text { margin: 0.15rem 0 0.9rem; font-family: var(--font-mono); overflow-wrap: anywhere; }
.sargam-phrases {
  display: grid;
  gap: 0.28rem;
}
.sargam-phrases span {
  display: block;
}

.note-row {
  display: flex;
  flex-wrap: nowrap;
  gap: max(1px, calc(6px - var(--n, 8) * 0.18px));
  margin: 0.6rem 0 0.9rem;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}
.note-chip {
  flex: 1 1 0;
  min-width: 0;
  max-width: 52px;
  display: inline-flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.35rem max(2px, calc(8px - var(--n, 8) * 0.28px));
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  text-align: center;
  overflow: hidden;
}
.note-chip .swara {
  color: var(--muted);
  font-size: max(0.54rem, calc(0.72rem - var(--n, 8) * 0.009rem));
  font-family: var(--font-mono);
}
.note-chip .note {
  font-weight: 780;
  font-size: max(0.62rem, calc(0.9rem - var(--n, 8) * 0.012rem));
}

/* piano keyboard */
.keyboard {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 160px;
  margin-top: 0.8rem;
  border-radius: 14px;
  overflow: hidden;
  background: color-mix(in srgb, var(--text), transparent 86%);
  border: 1px solid var(--line);
}
.white-keys {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  height: 100%;
  min-width: 0;
}
.key {
  position: relative;
  min-width: 0;
  border: 0;
  border-right: 1px solid rgba(0,0,0,0.18);
  display: flex;
  align-items: end;
  justify-content: center;
  padding: 0 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 800;
  user-select: none;
  overflow: hidden;
}
.key.white { background: #f9f8f4; color: #2a231d; min-width: 0; }
.key.black {
  position: absolute;
  z-index: 2;
  width: 8.6%;
  height: 61%;
  top: 0;
  border-radius: 0 0 8px 8px;
  background: #1c1c22;
  color: #f7f7f7;
  box-shadow: 0 9px 16px rgba(0,0,0,0.28);
  border: 1px solid rgba(255,255,255,0.08);
}
.key.black[data-pc="1"]  { left:  9.7%; }
.key.black[data-pc="3"]  { left: 24.0%; }
.key.black[data-pc="6"]  { left: 52.6%; }
.key.black[data-pc="8"]  { left: 66.9%; }
.key.black[data-pc="10"] { left: 81.2%; }
.key.active { background: var(--accent); color: #fff; }
.key.black.active { background: color-mix(in srgb, var(--accent), #111 20%); }
.key.is-sounding {
  background: var(--sun-color, #f0b448);
  color: #21180b;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.7), 0 0 16px rgba(240,180,72,0.58);
}
.key.black.is-sounding {
  background: var(--sun-color, #f0b448);
  color: #21180b;
  box-shadow: 0 9px 16px rgba(0,0,0,0.24), 0 0 18px rgba(240,180,72,0.7);
}
.key.tonic::after {
  content: "Sa";
  position: absolute;
  top: 0.4rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  opacity: 0.88;
}

.scale-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
  min-width: 0;
}
.scale-summary div { border-radius: 12px; background: var(--panel-strong); border: 1px solid var(--line); padding: 0.7rem; min-width: 0; }
.scale-summary dt { color: var(--muted); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.scale-summary dd { margin: 0.3rem 0 0; font-family: var(--font-mono); overflow-wrap: anywhere; font-size: 0.9rem; }

.notation-glossary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 0;
}
.notation-glossary div {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-strong);
  padding: 0.55rem 0.65rem;
}
.notation-glossary dt {
  margin: 0 0 0.2rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 850;
}
.notation-glossary dd {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.source-list { margin: 0.65rem 0 0; padding-left: 1.1rem; color: var(--muted); }
.source-list li { overflow-wrap: anywhere; }
.source-list a { color: var(--accent-strong); overflow-wrap: anywhere; }

/* ─── timezone dialog ────────────────────────────────────────────── */
dialog {
  border: none;
  padding: 0;
  border-radius: var(--radius-lg);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  color: var(--text);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow: auto;
}

dialog::backdrop {
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
}

.tz-dialog-inner { padding: 24px; }

.tz-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.tz-dialog-header h2 { margin: 0; font-size: 1.15rem; letter-spacing: -0.03em; }
.tz-close {
  border: none;
  background: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
}
.tz-close:hover { background: var(--accent-soft); }

.tz-map-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 16px;
  background: var(--tz-ocean);
  position: relative;
}
.tz-map { width: 100%; height: auto; display: block; }

.tz-map .land {
  fill: #c5d6a2;
  stroke: #a8be84;
  stroke-width: 0.6;
  stroke-linejoin: round;
}
.tz-map .graticule line {
  stroke: rgba(80,120,160,0.18);
  stroke-width: 0.5;
}
.tz-map .graticule line.prime {
  stroke: rgba(80,120,160,0.35);
  stroke-width: 1;
}
.tz-map .equator {
  stroke: rgba(80,120,160,0.22);
  stroke-width: 0.8;
  stroke-dasharray: 4 4;
}
.tz-map .loc-marker {
  fill: var(--accent);
  stroke: var(--panel-strong);
  stroke-width: 2;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.22));
}

body[data-theme="deep-night"] .tz-map .land,
body[data-theme="evening"] .tz-map .land { fill: #3a5040; stroke: #4a6050; }

.tz-offset-track {
  height: 6px;
  background: var(--line);
  position: relative;
  cursor: pointer;
}
.tz-offset-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.22);
  cursor: grab;
  left: 50%;
}

.tz-select-wrap {
  margin-bottom: 16px;
}
.tz-select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  padding: 0.5rem 0.9rem;
  outline: none;
}

.loc-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.loc-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}
.loc-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  padding: 0.5rem 0.75rem;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.tz-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}
.tz-use-local, .tz-apply {
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 0.4rem 1.2rem;
  cursor: pointer;
  font-size: 0.88rem;
}
.tz-use-local { background: var(--bg-soft); }
.tz-apply { background: var(--accent); color: #fff; border-color: transparent; font-weight: 700; }

.cookie-note {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 80;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 28px);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  padding: 0.35rem 0.4rem 0.35rem 0.75rem;
  font-size: 0.76rem;
  font-weight: 700;
}
.cookie-note[hidden] { display: none; }
.cookie-note button {
  min-width: 34px;
  min-height: 28px;
  border: none;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 850;
  cursor: pointer;
}
.cookie-note button:hover {
  background: var(--accent);
  color: #fff;
}

/* ─── responsive ─────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .detail-overlay-inner { padding: 16px 14px 72px; }
  .detail-grid { grid-template-columns: 1fr; }
  .scale-summary { grid-template-columns: 1fr; }
  .notation-glossary { grid-template-columns: 1fr; }
  .loc-grid { grid-template-columns: 1fr; }
  .info-card { padding: 14px; }
  .keyboard { height: 128px; }
  .key { font-size: 0.68rem; }
}
