/* ---------------------------------------------------------------
   Chromatic Tuner — styling
   Dark theme inspired by the GuitarTuna screenshot:
   deep navy panel, teal accents, green = in tune, red = off.
   --------------------------------------------------------------- */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0b1016;
  --panel: #121a24;
  --teal: #1dd3b0;
  --green: #2ecc71;
  --red: #ff5d6c;
  --orange: #ff8a3d;
  --text: #eaf2f8;
  --muted: #6b7c8f;
  --grid: rgba(255, 255, 255, 0.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at 50% 0%, #16202c 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.tuner {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* ---- Top bar -------------------------------------------------- */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
}

/* self-contained "Star on GitHub" button — no external script, so the app
   stays fully zero-dependency (the trade-off is no live star count) */
.star-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 8px;
  background: #0c131b;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}
.star-btn:hover {
  background: #16202c;
  border-color: rgba(255, 255, 255, 0.3);
}
.star-btn svg {
  flex-shrink: 0;
}

.mode-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}
.mode-title .accent {
  color: var(--teal);
}

/* ---- Big note readout ----------------------------------------- */

.readout {
  text-align: center;
  margin: 20px 0 8px;
  opacity: 0; /* faded in/out per-frame via JS (style.opacity) */
}

.note-name {
  font-size: 72px;
  font-weight: 800;
  line-height: 1;
}

.note-octave {
  font-size: 22px;
  color: var(--muted);
  vertical-align: baseline;
}

.frequency {
  margin-top: 6px;
  font-size: 15px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---- The vertical pitch chart --------------------------------- */

.chart {
  position: relative;
  height: 280px;
  margin: 16px 0;
  border-radius: 16px;
  overflow: hidden;
  /* faint grid: vertical + horizontal lines every 40px */
  background:
    repeating-linear-gradient(to right, var(--grid) 0 1px, transparent 1px 40px),
    repeating-linear-gradient(to bottom, var(--grid) 0 1px, transparent 1px 40px),
    #0c131b;
}

/* flat / sharp labels in the top corners */
.accidental {
  position: absolute;
  top: 12px;
  font-size: 24px;
  color: var(--muted);
  z-index: 2;
}
.accidental.flat {
  left: 16px;
}
.accidental.sharp {
  right: 16px;
}

/* fixed center line = the target (perfectly in tune) */
.center-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.22);
  transition: background 0.2s;
}
.chart.in-tune .center-line {
  background: rgba(46, 204, 113, 0.5);
}

/* the scrolling pitch-over-time trace, filling the whole chart.
   color is set here; the gradient fades it out toward the bottom (older). */
.trace {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  color: var(--red);
  transition: color 0.2s;
}
.chart.in-tune .trace {
  color: var(--green);
  filter: drop-shadow(0 0 5px var(--green));
}
.trace-line {
  fill: none;
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* anchor that slides horizontally to the current pitch; holds the pills.
   opacity (toggled via .active) fades the note in/out instead of snapping */
.bubble {
  position: absolute;
  top: 8px;
  left: 50%;
  width: 0;
  transform: translateX(-50%);
  opacity: 0; /* faded in/out per-frame via JS (style.opacity) */
  transition: left 0.08s linear;
}

/* speech-bubble pill with the cents number (e.g. -5), centered on the anchor;
   the downward tail points at the line, GuitarTuna-style */
.cents-bubble {
  position: absolute;
  top: 0;
  left: 0;
  transform: translateX(-50%);
  background: var(--red);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  padding: 7px 14px;
  border-radius: 999px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 26px;
  text-align: center;
  transition: background 0.2s;
}
.cents-bubble::after {
  content: "";
  position: absolute;
  top: calc(100% - 1px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--red);
  transition: border-top-color 0.2s;
}
/* in tune: bubble turns green while still showing the cents value */
.chart.in-tune .cents-bubble {
  background: var(--green);
  font-size: 20px;
}
.chart.in-tune .cents-bubble::after {
  border-top-color: var(--green);
}
/* the green bubble already means "in tune", so hide the text direction pill then */
.chart.in-tune .direction-pill {
  display: none;
}

/* the grey "Tune up / Tune down" pill floating to the right of the bubble */
.direction-pill {
  position: absolute;
  top: 4px;
  left: 0;
  transform: translateX(40px);
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

/* (the bubble's show/hide + fade is handled by .bubble opacity above) */

/* ---- Status --------------------------------------------------- */

.status {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 12px;
  min-height: 18px;
}

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

.settings {
  margin-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 6px;
  font-size: 13px;
}

.settings > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  list-style: none;
  user-select: none;
  transition: color 0.15s;
}
.settings > summary::-webkit-details-marker {
  display: none;
}
.settings > summary::before {
  content: "⚙";
  font-size: 14px;
}
.settings > summary:hover,
.settings[open] > summary {
  color: var(--text);
}

/* each control: label + value share the top line, the slider/select goes
   full-width on the line below — much cleaner on a narrow card */
.setting {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 12px;
  margin-top: 16px;
}

.setting-label {
  grid-row: 1;
  grid-column: 1;
  color: var(--muted);
}

.setting-value {
  grid-row: 1;
  grid-column: 2;
  justify-self: end;
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.setting input[type="range"],
.setting select {
  grid-row: 2;
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 8px;
}

.setting input[type="range"] {
  accent-color: var(--teal);
  cursor: pointer;
}

.setting select {
  background: #0c131b;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}

.setting.disabled {
  opacity: 0.4;
}
