:root {
  /* Palette: yellows #ffee32 #ffd100, charcoal #202020, grey #4d4d4d,
     plus an off-white #f0f0f0 for text. Every text/background pair here
     is at least 4.5:1 contrast (WCAG AA). */
  --bg: #202020;
  --panel: #2a2a2a;
  --well: #181818; /* insets: graph, chart cells, note boxes */
  --raised: #4d4d4d; /* grey: secondary buttons */
  --line: #3d3d3d;
  --text: #f0f0f0;
  --button: #ffd100; /* yellow: main buttons, dark lettering */
  --muted: #b3b3b3;
  --accent: #6fcf8a; /* in tune: green */
  --accent-soft: rgba(111, 207, 138, 0.3);
  --select: #ffee32; /* outline on what is selected */
  --select-soft: #4d4d4d;
  --tag: #4d4d4d;
  /* Neutral marks: things to fix, hints, rhythm ticks. */
  --note: #969696;
  /* Pitch: below the note is yellow, above it is coral red. */
  --flat: #ffee32;
  --flat-soft: rgba(255, 238, 50, 0.3);
  --sharp: #ff7a59;
  --sharp-soft: rgba(255, 122, 89, 0.3);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  /* Nothing here benefits from text selection; stray highlights during a
     practice session just get in the way. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------- buttons */

button {
  font: inherit;
  font-weight: 600;
  color: var(--bg);
  background: var(--button);
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

button:active {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.secondary {
  background: var(--raised);
  color: var(--text);
}

button.small {
  padding: 8px 12px;
  font-size: 13px;
}

button.active {
  background: var(--button);
  color: var(--bg);
}

/* Boxes on the page: a hairline so they stand apart. */
.flute-box,
.metronome,
.panel,
.history {
  border: 1px solid var(--line);
}

/* -------------------------------------------------------- swara marks */
/* Written sargam: komal underlined, tivra Ma with a tick above, a dot under
   the swara for mandra and above it for taar (two for ati-taar). Sized in
   em so the same marks work on the big readout and in a sentence. */

.sw {
  position: relative;
  display: inline-block;
  line-height: 1;
}

.sw.komal {
  text-decoration: underline;
  text-decoration-thickness: 0.07em;
  text-underline-offset: 0.12em;
}

.sw i {
  position: absolute;
  left: 50%;
  width: 0.17em;
  height: 0.17em;
  border-radius: 50%;
  background: currentColor;
  transform: translateX(-50%);
}

.sw .m-below {
  bottom: -0.32em;
}

.sw .m-above,
.sw .m-above2 {
  top: -0.24em;
}

.sw .m-above2 {
  background: none;
  box-shadow: -0.13em 0 currentColor, 0.13em 0 currentColor;
}

/* Over the M of Ma, clear of a taar dot in the middle. */
.sw .m-tivra {
  left: 0.36em;
  top: -0.3em;
  width: 0.07em;
  height: 0.26em;
  border-radius: 0.03em;
}

/* --------------------------------------------------------------- flute */

.flute-box {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel);
}

.flute-box summary,
.quiz-settings summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
}

.flute-box summary::-webkit-details-marker,
.quiz-settings summary::-webkit-details-marker {
  display: none;
}

.flute-line {
  font-size: 15px;
  font-weight: 600;
}

.flute-change {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.flute-box[open] .flute-change,
.quiz-settings[open] .flute-change {
  display: none;
}

.flute-box[open] summary {
  margin-bottom: 12px;
}

.size-picker,
.key-picker {
  display: grid;
  gap: 6px;
  margin-bottom: 6px;
}

.size-picker {
  grid-template-columns: repeat(2, 1fr);
}

.key-picker {
  grid-template-columns: repeat(6, 1fr);
  margin-bottom: 12px;
}

.flute-btn {
  padding: 9px 4px;
  font-size: 14px;
  border: 2px solid transparent;
}

.flute-btn.selected,
.modes button.selected,
.quiz-picker button.selected,
.physics-views button.selected,
.metro-sound button.selected {
  border-color: var(--select);
  background: var(--select-soft);
  color: var(--text);
}

.flute-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

/* ----------------------------------------------------------- metronome */

.metronome {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel);
}

.metro-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.metro-head button {
  margin-left: auto;
}

.pulse {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
}

.pulse span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--raised);
}

.pulse.hit span {
  animation: beat 0.18s ease-out;
}

.pulse.downbeat span {
  background: var(--select);
  width: 16px;
  height: 16px;
}

@keyframes beat {
  from {
    transform: scale(1.5);
    opacity: 1;
  }
  to {
    transform: scale(1);
    opacity: 0.55;
  }
}

.bpm {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.bpm-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.bpm-label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.1em;
}

.bpm-slider {
  width: 100%;
  margin: 10px 0 0;
  accent-color: var(--accent);
}

/* Click / Tabla, and the tabla's theka: one row per vibhag. */
.metro-sound {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

.metro-sound button {
  border: 2px solid transparent;
}

.theka {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.vibhag {
  display: grid;
  grid-template-columns: 22px repeat(4, 1fr);
  align-items: center;
  gap: 6px;
}

.taal-mark {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.bol {
  padding: 8px 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--well);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}

.bol.light {
  color: var(--muted);
  font-weight: 400;
}

.bol.now {
  border-color: var(--select);
  background: var(--select-soft);
  color: var(--text);
}

/* --------------------------------------------------------------- modes */

.modes {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-top: 4px;
}

.modes button {
  padding: 12px 2px;
  font-size: 14px;
  background: var(--panel);
  color: var(--muted);
  border: 2px solid transparent;
}

/* How to use the box that is picked. */
.mode-help {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

/* --------------------------------------------------------------- panel */

.panel {
  background: var(--panel);
  border-radius: 16px;
  padding: 18px;
}

.listen {
  width: 100%;
  margin-bottom: 18px;
}

.listen.on {
  background: var(--raised);
  color: var(--text);
}

.status {
  margin: -8px 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.status:empty {
  display: none;
}

.status.error {
  color: var(--sharp);
}

/* ---------------------------------------------------------------- tune */

.readout {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.note-name {
  /* Large enough to read at arm's length, which is how you actually glance
     at a tuner while holding an instrument. */
  font-size: 56px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.cents {
  font-size: 22px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 60px;
  text-align: right;
}

.western {
  margin: 6px 0 0;
  font-size: 15px;
  color: var(--muted);
  min-height: 20px;
  font-variant-numeric: tabular-nums;
}

.meter {
  position: relative;
  height: 12px;
  margin: 22px 0 12px;
  background: var(--well);
  border-radius: 999px;
}

.meter-ticks {
  position: absolute;
  inset: 0;
  /* Green band in the middle: the region we call "in tune". */
  background: linear-gradient(
    to right,
    var(--line) 0%,
    var(--line) 42%,
    var(--accent) 42%,
    var(--accent) 58%,
    var(--line) 58%,
    var(--line) 100%
  );
  opacity: 0.55;
  border-radius: 999px;
}

.needle {
  position: absolute;
  top: -5px;
  left: 50%;
  width: 4px;
  height: 22px;
  border-radius: 2px;
  background: var(--text);
  transform: translateX(-50%);
  /* Short transition so the needle glides rather than snapping. Too long and
     it lags behind a note you change quickly. */
  transition: left 0.12s ease-out;
}

.verdict {
  margin: 0;
  min-height: 22px;
  font-size: 15px;
  color: var(--muted);
}

.verdict.good {
  color: var(--accent);
}

.verdict.flat {
  color: var(--flat);
}

.verdict.sharp {
  color: var(--sharp);
}

/* ----------------------------------------------- note chart (in Tune) */

.chart-box {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.chart-box summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.chart-box[open] summary {
  margin-bottom: 12px;
}

.chart {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

/* A new row at each Sa, so each saptak starts on its own line. */
.saptak-break {
  grid-column: 1 / -1;
  height: 2px;
}

.swara-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 8px;
  border-radius: 10px;
  background: var(--well);
  border: 2px solid transparent;
}

.swara-cell.altered {
  background: #232323;
}

.swara-cell.current {
  border-color: var(--text);
}

.cell-swara {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
}

.cell-western {
  font-size: 13px;
}

.cell-hz {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------- long note / meend / alankar */

.practice-status {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--muted);
  line-height: 1.5;
}

.practice-status:empty {
  display: none;
}

.pitch-line {
  display: block;
  width: 100%;
  height: 240px;
  margin: 0;
  border-radius: 10px;
  background: var(--well);
}

.pitch-key {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.pitch-key span::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 3px;
  margin: 0 5px 2px 0;
  border-radius: 2px;
  vertical-align: middle;
}

.pitch-key .flat::before {
  background: var(--flat);
}

.pitch-key .good::before {
  background: var(--accent);
}

.pitch-key .sharp::before {
  background: var(--sharp);
}

.practice-headline {
  margin: 14px 0 8px;
  font-size: 18px;
  font-weight: 600;
}

.practice-headline.hint {
  color: var(--muted);
  font-size: 15px;
}

.practice-headline:empty {
  display: none;
}

.alankar-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}

.alankar-notes:empty {
  display: none;
}

.note-chip {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 38px;
  padding: 7px 4px 9px;
  border-radius: 8px;
  background: var(--well);
  border: 2px solid transparent;
}

.chip-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
}

.note-chip.good {
  background: var(--accent-soft);
}

.note-chip.flat {
  background: var(--flat-soft);
}

.note-chip.sharp {
  background: var(--sharp-soft);
}

/* Not in the pattern: an outline, so it never reads as a pitch colour. */
.note-chip.wrong,
.note-chip.miss {
  background: transparent;
  border: 2px dashed var(--note);
}

/* The slide paused on this note: an outline, like a note off the pattern. */
.note-chip.step {
  background: transparent;
  border: 2px dashed var(--note);
}

.meend-notes {
  align-items: center;
  gap: 6px;
}

.slide-arrow {
  color: var(--muted);
  font-size: 14px;
}

/* A small tick on the side the note was off: left for early, right for late. */
.note-chip.early::before,
.note-chip.late::after {
  content: '';
  position: absolute;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 2px;
  background: var(--note);
}

.note-chip.early::before {
  left: 2px;
}

.note-chip.late::after {
  right: 2px;
}

.practice-results {
  margin: 0;
  padding: 0;
  list-style: none;
}

.practice-results li {
  position: relative;
  padding: 6px 0 6px 24px;
  font-size: 14px;
  line-height: 1.45;
}

.practice-results li::before {
  position: absolute;
  left: 0;
  font-weight: 700;
}

.practice-results li.ok::before {
  content: '✓';
  color: var(--accent);
}

.practice-results li.fix::before {
  content: '•';
  color: var(--note);
}

.practice-results li.label {
  padding-left: 0;
  margin-top: 8px;
  font-weight: 600;
}

/* ------------------------------------------------- key to marks/colours */

.key {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.key-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.key-item .sw {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.note-chip.key-chip {
  display: inline-block;
  min-width: 0;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 5px;
}

.note-chip.key-chip.early,
.note-chip.key-chip.late {
  background: var(--well);
}

.note-chip.key-chip.early::before,
.note-chip.key-chip.late::after {
  top: 3px;
  bottom: 3px;
}

/* -------------------------------------------------------------- recent */

.history {
  background: var(--panel);
  border-radius: 16px;
  padding: 16px 18px;
}

.history.empty {
  display: none;
}

.history h2 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-list > li + li {
  border-top: 1px solid var(--line);
}

.history-list summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  cursor: pointer;
  list-style: none;
}

.history-list summary::-webkit-details-marker {
  display: none;
}

.history-list details[open] {
  padding-bottom: 12px;
}

.tag {
  flex: none;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--tag);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.history-headline {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.6;
}

.history-time {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 420px) {
  .note-name {
    font-size: 44px;
  }
  .chart {
    grid-template-columns: repeat(4, 1fr);
  }
  .modes {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ---------------------------------------------------------------- quiz */

.quiz-settings {
  margin-top: 14px;
}

.quiz-settings summary {
  list-style: none;
  cursor: pointer;
}

.quiz-settings[open] summary {
  margin-bottom: 12px;
}

/* Open settings: a darker inset, one labelled row per setting. */
.quiz-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 14px;
  border-radius: 12px;
  background: var(--well);
}

.quiz-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.quiz-done {
  align-self: flex-end;
}

.quiz-every {
  display: flex;
  align-items: center;
  gap: 12px;
}

.quiz-every .bpm-slider {
  flex: 1;
  margin: 0;
}

.quiz-every-value {
  min-width: 3.5em;
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.quiz-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

#quiz-set {
  grid-template-columns: repeat(2, 1fr);
}

#quiz-saptak {
  grid-template-columns: repeat(3, 1fr);
}

/* "5 / 16": which swara of how many. */
.quiz-count {
  display: block;
  min-height: 20px;
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.quiz-picker button {
  padding: 9px 2px;
  font-size: 14px;
  border: 2px solid transparent;
}

.quiz-now {
  margin: 18px 0 6px;
  text-align: center;
}

.quiz-now .note-name {
  display: block;
  font-size: 88px;
}

/* The tuner under the swara to play: smaller, no Hz, and only while the
   quiz runs (after Stop the feedback takes its place). */
body[data-box="quiz"] .tuner-live {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

body[data-box="quiz"]:not(.listening) .tuner-live {
  display: none;
}

body[data-box="quiz"] .tuner-live .note-name {
  font-size: 36px;
}

body[data-box="quiz"] .western {
  display: none;
}

/* Do-gun and up: the beat's swaras side by side, smaller as there are more.
   Played ones fade, coming ones are grey, the one to play now is bright. */
#quiz-swara[data-size="2"] {
  font-size: 64px;
}

#quiz-swara[data-size="3"] {
  font-size: 52px;
}

#quiz-swara[data-size="4"] {
  font-size: 42px;
}

.quiz-now .q {
  margin: 0 0.18em;
}

.quiz-now .q-past {
  opacity: 0.3;
}

.quiz-now .q-now {
  color: var(--text);
}

.quiz-now .q-next {
  color: var(--muted);
}

/* 3, 2, 1, Go: muted, so the first swara stands out. */
.quiz-now.counting .note-name {
  color: var(--muted);
}

/* Time left on this swara: empties from the right. */
.quiz-timer {
  height: 6px;
  margin-top: 12px;
  border-radius: 3px;
  background: var(--well);
  overflow: hidden;
}

.quiz-timer span {
  display: block;
  height: 100%;
  background: var(--note);
  transform-origin: left;
}

@media (max-width: 420px) {
  #quiz-swara[data-size="3"] {
    font-size: 42px;
  }
  #quiz-swara[data-size="4"] {
    font-size: 34px;
  }
}

/* ------------------------------------------------------------- physics */

/* Wave / Inside the flute. */
.physics-views {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.physics-views button {
  border: 2px solid transparent;
}

/* Between notes the last one stays, dimmed. */
.physics.held .wave,
.physics.held .overtones,
.physics.held .breath-row {
  opacity: 0.45;
}

.wave-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.wave-stats > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  border-radius: 10px;
  background: var(--well);
}

.stat {
  min-height: 24px;
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
}

.wave {
  display: block;
  width: 100%;
  height: 200px;
  border-radius: 10px;
  background: var(--well);
}

.sub-head {
  margin: 16px 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

/* 1× … 6×: bar height = how strong, relative to the strongest. */
.overtones {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.overtone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.overtone-bar {
  position: relative;
  width: 100%;
  height: 90px;
  border-radius: 6px;
  background: var(--well);
  overflow: hidden;
}

.overtone-bar span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  background: var(--text);
}

.overtone-x {
  font-size: 13px;
  font-weight: 600;
}

.overtone-hz {
  min-height: 15px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.breath-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.breath-bar {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--well);
  overflow: hidden;
}

.breath-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--note);
}

.flute-tube {
  height: 230px;
}

.octave {
  height: 270px;
  margin-top: 12px;
}

.scale-wheel {
  height: 320px;
}

.scale-sa {
  height: 200px;
}

.beats-trace {
  height: 170px;
}

.beats-curve {
  height: 150px;
}

@media (max-width: 420px) {
  .stat {
    font-size: 17px;
  }
  .wave {
    height: 170px;
  }
  .flute-tube {
    height: 220px;
  }
  .octave {
    height: 250px;
  }
  .scale-wheel {
    height: 300px;
  }
  .overtones {
    gap: 5px;
  }
}
