/*
  Prodigies Tuner — clean, kid-friendly chromatic tuner.
  White/light base, Prodigies teal primary, rainbow accents on the dial.
*/

:root {
  --ink: #1b233e;
  --muted: #65728f;
  --panel: #ffffff;
  --teal: #099695;
  --teal-dim: #1a7086;
  --teal-soft: #e7f7f7;
  --line: #d8e1ef;
  /* Pop color used when the note color is dark — readable against any bell color */
  --pop: #66ccff;
  --pop-dim: rgba(102, 204, 255, 0.55);
  /* The dial's fill color is set per-detected-note (defaults to a soft slate) */
  --dial-color: #b3bccd;
  /* Letter color: matches the bell color by default, swaps to brown #512d1b
     for light notes (E, D#) via JS so it stays readable on a pastel wash. */
  --note-text-color: var(--dial-color);
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(180deg, #f5f8fc 0%, #eef3f8 100%);
  color: var(--ink);
  font-family: "Nunito", "Avenir Next Rounded", "Trebuchet MS", Verdana, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body { overflow-x: hidden; min-height: 100vh; min-height: 100svh; }

button { font: inherit; cursor: pointer; }


.tuner-app {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: calc(64px + env(safe-area-inset-top)) 18px calc(26px + env(safe-area-inset-bottom));
  display: grid;
  gap: 18px;
}

.tuner-header {
  text-align: center;
  display: grid;
  gap: 4px;
}
.tuner-header h1 {
  margin: 0;
  font-size: clamp(1.7rem, 7vw, 2.4rem);
  font-weight: 900;
  letter-spacing: -0.01em;
}
.tuner-sub {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.96rem;
}

/* ---- Permission gate ---- */
.start-gate {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 32px 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 8px 22px rgba(27, 73, 122, 0.08);
}
.start-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(9, 150, 149, 0.32);
  transition: transform 0.08s ease, filter 0.08s ease;
}
.start-btn:active { transform: translateY(2px); filter: brightness(1.04); }
.start-btn-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: #fff;
}
.start-btn-icon svg { width: 100%; height: 100%; }
.permission-hint { margin: 0; color: var(--muted); font-weight: 800; text-align: center; }
.permission-error {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: #fff0f0;
  color: #9c2626;
  font-weight: 800;
  text-align: center;
}

/* ---- Tuner stage ---- */
.tuner-stage {
  display: grid;
  gap: 16px;
  justify-items: center;
}

/* The dial: large semicircular indicator with note in the center */
.dial {
  position: relative;
  width: min(86vw, 360px);
  aspect-ratio: 1;
}
.dial-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
/* The big disc fills with a PASTEL wash of the detected note's color:
   roughly 22% bell color + 78% white. Soft, brand-tinted, easy on the eyes. */
.dial-ring {
  fill: color-mix(in srgb, var(--dial-color) 22%, #ffffff);
  stroke: color-mix(in srgb, var(--dial-color) 35%, #d8e1ef);
  stroke-width: 2;
  transition: fill 220ms ease, stroke 220ms ease, filter 220ms ease;
}

/* Cents meter zones — neutrals + cyan in-tune. Now stand against the pale fill. */
.zone {
  fill: none;
  stroke-width: 14;
  stroke-linecap: butt;
}
.zone-flat-far,
.zone-sharp-far  { stroke: rgba(27, 35, 62, 0.12); }
.zone-flat-near,
.zone-sharp-near { stroke: rgba(27, 35, 62, 0.22); }
.zone-in         { stroke: var(--pop); opacity: 0.9; }

.ticks line {
  stroke: rgba(27, 35, 62, 0.35);
  stroke-width: 2;
  stroke-linecap: round;
  transition: stroke 220ms ease;
}
.ticks line.major  { stroke: rgba(27, 35, 62, 0.55); stroke-width: 3; }
.ticks line.center { stroke: var(--pop); stroke-width: 4; }

.dial-label {
  fill: rgba(27, 35, 62, 0.45);
  font-size: 11px;
  font-weight: 800;
  font-family: inherit;
}

.needle {
  transform: rotate(0deg);
  transform-origin: 0 0;
  transition: transform 0.12s ease-out;
}
.needle-line {
  stroke: color-mix(in srgb, var(--dial-color) 55%, #1b233e);
  stroke-width: 3;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 2px rgba(27, 35, 62, 0.18));
  transition: stroke 220ms ease;
}
.needle-hub {
  fill: var(--dial-color);
  stroke: #ffffff;
  stroke-width: 2;
  transition: fill 220ms ease;
}

/* In-tune state: brighten the cents zone, soft halo */
.dial.in-tune .zone-in {
  stroke: var(--pop);
  opacity: 1;
}
.dial.in-tune .dial-ring {
  filter:
    drop-shadow(0 0 24px color-mix(in srgb, var(--dial-color) 35%, transparent))
    drop-shadow(0 0 6px rgba(255, 255, 255, 0.6));
}

/* Empty / "no note" state: keep the neutral slate look */
.dial.is-idle .dial-ring {
  fill: #f3f5fa;
  stroke: #d8e1ef;
}
.dial.is-idle .needle-line { stroke: rgba(27, 35, 62, 0.32); }
.dial.is-idle .needle-hub  { fill: #b3bccd; }
.dial.is-idle .zone-in     { stroke: var(--pop-dim); opacity: 0.7; }

.dial-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  padding-top: 18%;
}
.note-name {
  font-size: clamp(3rem, 14vw, 5.4rem);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.02em;
  /* Bell color, or brown fallback for light notes (set by JS). */
  color: var(--note-text-color, var(--dial-color));
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
  min-height: 1em;
  transition: color 220ms ease, text-shadow 220ms ease;
}
.dial.is-idle .note-name {
  color: #b3bccd;
  text-shadow: none;
}
.note-detail {
  margin-top: 6px;
  font-size: 1rem;
  font-weight: 800;
  color: var(--muted);
  min-height: 1.2em;
}
.note-cents {
  margin-top: 2px;
  font-size: 0.94rem;
  font-weight: 900;
  /* Mix the chosen text color (bell or brown fallback) with ink for readability */
  color: color-mix(in srgb, var(--note-text-color, var(--dial-color)) 65%, #1b233e);
  min-height: 1.2em;
  font-variant-numeric: tabular-nums;
  transition: color 220ms ease;
}
.dial.is-idle .note-cents { color: var(--muted); }

.tuner-status {
  margin: 0;
  font-weight: 900;
  font-size: 1.05rem;
  color: var(--muted);
  text-align: center;
}
.tuner-status.in-tune    { color: #2f8a1a; }
.tuner-status.too-flat,
.tuner-status.too-sharp  { color: #b04444; }
.tuner-status.almost     { color: #b07014; }

/* ---- Preset tabs ---- */
.preset-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding-top: 4px;
}
.preset-tab {
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  padding: 7px 13px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--teal-dim);
  font-size: 0.86rem;
  font-weight: 900;
  box-shadow: 0 6px 14px rgba(22, 49, 95, 0.08);
  -webkit-tap-highlight-color: transparent;
}
.preset-tab.is-active { color: #fff; background: var(--teal); }

/* ---- Target strings ---- */
.target-strings {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.target-string {
  min-width: 48px;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 12px;
  background: #ffffff;
  border: 2px solid var(--line);
  display: inline-grid;
  place-items: center;
  font-weight: 900;
  font-size: 0.94rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.target-string.is-active {
  border-color: var(--teal);
  background: var(--teal-soft);
  color: var(--teal-dim);
}
.target-string.is-locked {
  border-color: var(--green);
  background: #effbe6;
  color: #2f6b1a;
  box-shadow: 0 0 0 4px rgba(106, 187, 74, 0.18);
}

/* ---- Settings ---- */
.settings-drawer {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 16px;
}
.settings-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  padding: 12px 0;
  font-weight: 900;
  color: var(--teal-dim);
}
.settings-summary::-webkit-details-marker { display: none; }
.settings-summary svg { width: 18px; height: 18px; color: var(--teal); }

.settings-body { padding: 4px 0 16px; }
.setting-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}
.setting-label { font-weight: 800; color: var(--ink); }
.setting-value {
  min-width: 64px;
  text-align: right;
  font-weight: 900;
  color: var(--teal-dim);
  font-variant-numeric: tabular-nums;
}
.setting-row input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

/* in-tune pulse */
@keyframes inTunePulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}
.dial.in-tune .dial-center { animation: inTunePulse 1.2s ease-in-out infinite; }

@media (min-width: 700px) {
  .dial { width: min(64vw, 420px); }
}


/* ── The live microphone lane (ported from Sing the Interval) ──────────────
   Same panel, same lane, same rung ladder, so the tuner and the singing
   games read as one instrument. Values match si-mic / si-lane / si-rung. */
.tnr-mic {
  width: min(560px, 100%);
  margin: 18px auto 0;
  background: #fff;
  border: 2px solid #e3e8f2;
  border-radius: 18px;
  padding: 14px 14px 16px;
}
.tnr-mic-head h2 {
  margin: 0 0 10px;
  font-size: 10px; font-weight: 900;
  letter-spacing: 2px; text-transform: uppercase; color: #8a94ab;
}
.tnr-lane {
  position: relative;
  height: clamp(150px, 26vh, 220px);
  border: 2px solid #e3e8f2;
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(30, 127, 195, 0.05), rgba(255, 255, 255, 0) 45%),
    #fff;
  overflow: hidden;
}
.tnr-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tnr-ladder { position: absolute; inset: 0; pointer-events: none; }
.tnr-ladder-edge {
  position: absolute; right: 8px; top: 4px;
  font-size: 8px; font-weight: 900; letter-spacing: 1.5px;
  color: #8a94ab; opacity: 0.6;
}
.tnr-ladder-edge.low { top: auto; bottom: 4px; }
.tnr-rung {
  position: absolute; left: 8px; display: flex; align-items: center; gap: 6px;
  transform: translateY(-50%);
  transition: top 0.25s ease;      /* rungs glide as the window follows the note */
}
.tnr-rung-dot { width: 8px; height: 8px; border-radius: 50%; opacity: 0.55; }
.tnr-rung-label { font-size: 11px; font-weight: 900; color: #8a94ab; }
.tnr-rung.is-target .tnr-rung-dot { width: 12px; height: 12px; opacity: 1; }
.tnr-rung.is-target .tnr-rung-label { font-size: 15px; }
