/* Polished modern theme.
   Deep charcoal canvas, subtle panel gradients with thin borders + inset
   highlights, refined accents (mint for in-tune, amber for warn).
   Inter for UI text + Space Grotesk for the note display. */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Space+Grotesk:wght@500;700&display=swap');

:root {
  /* Surfaces */
  --bg:           #0b0c10;
  --bg-elevated:  #14161c;
  --panel-grad:   linear-gradient(180deg, #181b23 0%, #11141a 100%);
  --panel-grad-active: linear-gradient(180deg, #1f232d 0%, #15191f 100%);
  /* Slightly lighter than --panel-grad — gives buttons enough lift to read
     as distinct from the surrounding panel surfaces. */
  --btn-grad:        linear-gradient(180deg, #262a36 0%, #1a1d27 100%);
  --btn-grad-hover:  linear-gradient(180deg, #2d323f 0%, #20242e 100%);

  /* Text */
  --fg:           #f4f5f8;
  --muted:        #a1a6b3;
  --subtle:       #6b7180;

  /* Accents */
  --accent:       #5eead4;        /* mint — in-tune */
  --accent-soft:  rgba(94, 234, 212, 0.15);
  --accent-glow:  rgba(94, 234, 212, 0.35);
  --warn:         #f5b042;        /* warm amber — caution */
  --warn-soft:    rgba(245, 176, 66, 0.12);
  --bad:          #f87171;        /* refined red — over-limit */
  --bad-soft:     rgba(248, 113, 113, 0.12);

  /* Lines & shadows */
  --border:       rgba(255, 255, 255, 0.08);
  --border-hi:    rgba(255, 255, 255, 0.14);
  --inset-hi:     inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --shadow-sm:    0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md:    0 6px 20px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-lg:    0 14px 40px rgba(0, 0, 0, 0.55), 0 4px 10px rgba(0, 0, 0, 0.4);

  /* Type */
  --font-ui:      'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;

  /* Geometry */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #1a1d28 0%, var(--bg) 60%) fixed;
  color: var(--fg);
  font: 15px/1.5 var(--font-ui);
  font-weight: 500;
  min-height: 100vh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── Header ─────────────────────────────────────────────────── */
.hd {
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 12, 16, 0.7);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
}
.hd::after {
  /* Phantom slot mirroring the back-button width so the title sits visually
     centered between the two edges instead of being shifted by the back btn. */
  content: '';
  display: block;
}
.hd-back {
  color: var(--fg);
  text-decoration: none;
  font-size: 18px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg-elevated);
  box-shadow: var(--inset-hi);
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.hd-back:hover  { border-color: var(--border-hi); background: #1a1d26; }
.hd-back:active { transform: scale(0.96); }
.hd-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
  text-align: center;
}

#app {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 16px 28px;
  max-width: 520px;
  margin: 0 auto;
}

/* ── Pickers ────────────────────────────────────────────────── */
.pickers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.picker { display: flex; flex-direction: column; gap: 6px; }
.picker label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 600;
}
.picker select {
  appearance: none;
  -webkit-appearance: none;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='none' stroke='%23a1a6b3' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5l5 5 5-5'/></svg>")
      no-repeat right 12px center,
    var(--panel-grad);
  background-size: 12px 8px, auto;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 13px 36px 13px 14px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-ui);
  width: 100%;
  box-shadow: var(--inset-hi), var(--shadow-sm);
  transition: border-color 0.15s, background 0.15s;
}
.picker select:hover  { border-color: var(--border-hi); }
.picker select:focus  { outline: none; border-color: var(--accent); }

/* Options: native dropdown panels in Chromium/Windows ignore inherited
   colors and default to white-on-white, hiding everything except the
   currently highlighted option. Style each <option> directly so the open
   menu matches the dark UI. (Safari/macOS still defers to the OS.) */
.picker select option {
  background-color: var(--bg-elevated);
  color: var(--fg);
}
/* The OS repaints the currently-highlighted option with its system colour
   (typically a near-white) when the dropdown is open, so any custom bg/colour
   we'd set here gets clobbered and ends up low-contrast. Keep the same dark
   bg + white text as the unselected rows and signal "current" with weight. */
.picker select option:checked {
  background-color: var(--bg-elevated);
  color: var(--fg);
  font-weight: 700;
}

/* ── Start button ───────────────────────────────────────────── */
.start-btn {
  background: linear-gradient(180deg, #6df0d7 0%, #3dd0b8 100%);
  color: #04221d;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--r-md);
  padding: 18px;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 6px 16px rgba(94, 234, 212, 0.18),
    var(--shadow-sm);
  transition: transform 0.05s, box-shadow 0.2s, filter 0.15s;
}
.start-btn:hover   { filter: brightness(1.04); }
.start-btn:active  { transform: scale(0.99); box-shadow: var(--shadow-sm); }
.start-btn:disabled { opacity: 0.55; cursor: default; filter: saturate(0.5); }

/* ── Note display ───────────────────────────────────────────── */
.note-display {
  position: relative;
  background: var(--panel-grad);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px 18px 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 220px;
  justify-content: center;
  box-shadow: var(--inset-hi), var(--shadow-md);
  overflow: hidden;
}
.note-display::after {
  /* soft top vignette to add depth */
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 60% at 50% 0%, rgba(255, 255, 255, 0.04), transparent 60%);
}
.note-name {
  font-family: var(--font-display);
  font-size: 108px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--fg);
  text-shadow: 0 4px 24px rgba(94, 234, 212, 0.18);
  transition: color 0.2s, text-shadow 0.2s;
}
.note-name.dim {
  color: var(--subtle);
  text-shadow: none;
}
.note-octave {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.note-freq {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* ── Cents bar ──────────────────────────────────────────────── */
/* The bar is a horizontal slot. Its overflow:hidden + rounded ends clip
   anything inside it (needle and overshoot chips), so the chips appear to
   live "behind" the surrounding note-display panel and only become visible
   through this slot. */
.cents-bar {
  position: relative;
  height: 28px;
  margin: 14px auto 0;
  width: 100%;
  max-width: 360px;
  background:
    linear-gradient(90deg,
      var(--bad-soft) 0%, transparent 18%,
      transparent 82%, var(--bad-soft) 100%),
    var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  box-shadow:
    /* deep inner shadow sells the "cut into the plate" feel */
    inset 0 2px 4px rgba(0, 0, 0, 0.5),
    inset 0 -1px 1px rgba(255, 255, 255, 0.04);
}
.cents-bar .center-mark {
  position: absolute;
  left: 50%;
  top: 5px;
  bottom: 5px;
  width: 2px;
  background: var(--border-hi);
  transform: translateX(-50%);
  border-radius: 1px;
}
.cents-bar .needle {
  position: absolute;
  top: 3px;
  bottom: 3px;
  width: 8px;
  border-radius: 4px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow), 0 0 2px rgba(255, 255, 255, 0.4);
  /* Eased transition longer than the 60ms pitch-update throttle gives the
     needle visual continuity between detections instead of step-jumping. */
  transition: left 180ms cubic-bezier(0.22, 1, 0.36, 1),
              background-color 180ms ease,
              box-shadow 180ms ease;
  transform: translateX(-50%);
}
.cents-bar .needle.warn {
  background: var(--warn);
  box-shadow: 0 0 12px rgba(245, 176, 66, 0.45), 0 0 2px rgba(255, 255, 255, 0.4);
}
.cents-bar .needle.bad {
  background: var(--bad);
  box-shadow: 0 0 12px rgba(248, 113, 113, 0.5), 0 0 2px rgba(255, 255, 255, 0.4);
}

/* Chips live INSIDE the bar — the bar's overflow:hidden + rounded ends
   clip them to the slot. Anything outside is invisible, so the chip looks
   like it's sliding in from behind the surrounding plate. */
.cents-bar .overshoot-arrow {
  position: absolute;
  top: 50%;
  bottom: auto;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 14px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
  color: #2a0a0a;
  background: var(--bad);
  border-radius: 999px;
  box-shadow: 0 0 12px rgba(248, 113, 113, 0.45);
  pointer-events: none;
  white-space: nowrap;
  /* Slow, gentle breath rather than a fast blink — calm but still alive. */
  animation: overshoot-pulse 2200ms ease-in-out 400ms infinite;
}
.cents-bar .overshoot-arrow .arr { font-size: 12px; line-height: 1; }

.cents-bar .overshoot-arrow.left  {
  left: 0;
  right: auto;
  transform: translateY(-50%);
  animation-name: overshoot-enter-left, overshoot-pulse;
}
.cents-bar .overshoot-arrow.right {
  right: 0;
  left: auto;
  transform: translateY(-50%);
  animation-name: overshoot-enter-right, overshoot-pulse;
}
.cents-bar .overshoot-arrow.left,
.cents-bar .overshoot-arrow.right {
  animation-duration: 280ms, 2200ms;
  animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1), ease-in-out;
  animation-delay: 0ms, 400ms;
  animation-iteration-count: 1, infinite;
  animation-fill-mode: backwards, none;
}

@keyframes overshoot-enter-left {
  0%   { transform: translate(-16px, -50%) scale(0.4); opacity: 0; }
  60%  { transform: translate(3px, -50%)   scale(1.2); opacity: 1; }
  100% { transform: translate(0, -50%)     scale(1);   opacity: 1; }
}
@keyframes overshoot-enter-right {
  0%   { transform: translate(16px, -50%)  scale(0.4); opacity: 0; }
  60%  { transform: translate(-3px, -50%)  scale(1.2); opacity: 1; }
  100% { transform: translate(0, -50%)     scale(1);   opacity: 1; }
}
@keyframes overshoot-pulse {
  0%, 100% { opacity: 0.88; }
  50%      { opacity: 1; }
}

/* Reserve line-height-worth of space on the rows that toggle empty/filled
   so the note-display flex column doesn't recenter and the title doesn't
   visibly jump when detection toggles. */
.cents-label {
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 8px;
  min-height: 1.5em;
}

.note-freq { min-height: 1.5em; }

.target-info {
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
  min-height: 1.5em;
}
.target-info strong {
  color: var(--fg);
  font-weight: 700;
}

/* ── String chips ───────────────────────────────────────────── */
.strings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 8px;
}
.string-chip {
  position: relative;
  background: var(--panel-grad);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--fg);
  text-align: center;
  cursor: pointer;
  user-select: none;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-ui);
  box-shadow: var(--inset-hi), var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s, transform 0.05s, color 0.15s;
}
.string-chip:hover  { border-color: var(--border-hi); background: var(--panel-grad-active); }
.string-chip:active { transform: scale(0.97); }
.string-chip.active {
  background: var(--accent-soft);
  border-color: rgba(94, 234, 212, 0.45);
  color: var(--accent);
  box-shadow: var(--inset-hi), 0 0 0 1px var(--accent-soft), 0 4px 14px rgba(94, 234, 212, 0.12);
}
.string-chip.locked {
  background: linear-gradient(180deg, #6df0d7 0%, #3dd0b8 100%);
  border-color: rgba(255, 255, 255, 0.2);
  color: #04221d;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 6px 18px rgba(94, 234, 212, 0.25),
    0 1px 2px rgba(0, 0, 0, 0.5);
}
.string-chip .sub {
  display: block;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
  margin-top: 3px;
  letter-spacing: 0.02em;
}
.string-chip.active .sub { color: var(--accent); opacity: 0.8; }
.string-chip.locked .sub { color: inherit; opacity: 0.78; }

.string-chip.above-std {
  border-color: rgba(245, 176, 66, 0.4);
}
.string-chip.above-std.active,
.string-chip.above-std.locked {
  /* When the chip is the highlighted/locked one, keep the active visual but
     surface the warning via the corner badge only. */
  border-color: rgba(245, 176, 66, 0.55);
}
.string-chip .string-warn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--warn);
  color: #2a1a05;
  font-size: 11px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  font-family: var(--font-ui);
  box-shadow: 0 0 0 2px var(--bg-elevated), 0 2px 6px rgba(245, 176, 66, 0.35);
}

/* ── Mode row ───────────────────────────────────────────────── */
.mode-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.mode-row .spacer { flex: 1; }
.mode-row button {
  background: var(--btn-grad);
  color: var(--fg);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-sm);
  padding: 7px 14px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--inset-hi), var(--shadow-sm);
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
.mode-row button:hover  { background: var(--btn-grad-hover); border-color: rgba(255,255,255,0.22); }
.mode-row button:active { transform: scale(0.97); }
.mode-row button:disabled { opacity: 0.4; cursor: default; }

/* ── Transpose bar ──────────────────────────────────────────── */
.transpose { display: flex; flex-direction: column; gap: 8px; }
.transpose-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-grad);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 10px;
  box-shadow: var(--inset-hi), var(--shadow-sm);
}
.transpose-caption {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-right: auto;
  font-weight: 600;
}
.transpose-btn {
  background: var(--btn-grad);
  color: var(--fg);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  min-width: 50px;
  box-shadow: var(--inset-hi), var(--shadow-sm);
  transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.05s;
}
.transpose-btn:hover  { background: var(--btn-grad-hover); border-color: rgba(255,255,255,0.22); }
.transpose-btn:active { transform: scale(0.96); }
.transpose-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}
.transpose-btn.warn {
  border-color: rgba(245, 176, 66, 0.5);
  color: var(--warn);
  background: var(--warn-soft);
}
.transpose-value {
  flex: 0 0 auto;
  width: 124px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.02em;
}
.transpose-value.warn { color: var(--warn); font-weight: 700; }
.transpose-reset {
  background: var(--btn-grad);
  color: var(--fg);
  border: 1px solid var(--border-hi);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  font-family: var(--font-ui);
  cursor: pointer;
  box-shadow: var(--inset-hi), var(--shadow-sm);
  transition: border-color 0.15s, background 0.15s;
}
.transpose-reset:hover { background: var(--btn-grad-hover); border-color: rgba(255,255,255,0.22); }
.transpose-reset.is-hidden { visibility: hidden; pointer-events: none; }

/* ── Warnings / errors ──────────────────────────────────────── */
.tension-warn {
  background: var(--warn-soft);
  color: #fde4b8;
  border: 1px solid rgba(245, 176, 66, 0.35);
  border-radius: var(--r-md);
  padding: 11px 13px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
  box-shadow: var(--inset-hi);
}
.tension-warn.bad {
  background: var(--bad-soft);
  color: #ffd1d1;
  border-color: rgba(248, 113, 113, 0.4);
}

.error-msg {
  background: var(--bad-soft);
  color: #ffd1d1;
  border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: var(--r-md);
  padding: 11px 13px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--inset-hi);
}

/* ── Larger viewport ────────────────────────────────────────── */
@media (min-width: 600px) {
  .note-name { font-size: 144px; }
  .hd-title  { font-size: 20px; }
}
