/* Guitar Tuner — Warm Analog theme
   Walnut + brass + cream lit-dial, VU-emerald in-tune. Dark-first. */

:root {
  /* Walnut body */
  --wood-0: #0d0904;
  --wood-1: #1b1209;
  --wood-2: #2a1c10;
  --wood-3: #3a2817;
  --faceplate: #241910;

  /* Brass / gold */
  --brass: #c8a24b;
  --brass-bright: #eccd7e;
  --brass-deep: #8a6c2e;
  --cream: #f3e6c4;

  /* States */
  --emerald: #44c98a;
  --emerald-glow: #6ff0b3;
  --amber: #e0a33c;
  --red: #d05a3e;

  /* Text */
  --tan: #c4a878;
  --tan-dim: #8a7350;
  --tan-faint: #5f4f37;

  --shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.75);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, monospace;
}

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

/* the hidden attribute must win over flex/grid display rules below */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--tan);
  background:
    radial-gradient(120% 90% at 50% -10%, #3a2817 0%, var(--wood-1) 42%, var(--wood-0) 100%);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Device / faceplate ---------- */

.tuner {
  position: relative;
  width: min(440px, 100%);
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 3.2vw, 20px);
  padding: clamp(18px, 5vw, 26px) clamp(18px, 5vw, 26px) clamp(16px, 4.5vw, 22px);
  border-radius: 30px;
  background:
    linear-gradient(180deg, #2e2013 0%, var(--faceplate) 14%, #1e150c 100%);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(236, 205, 126, 0.18),
    inset 0 0 0 1px rgba(0, 0, 0, 0.4),
    inset 0 -1px 0 rgba(0, 0, 0, 0.6);
}
/* brass top rail */
.tuner::before {
  content: "";
  position: absolute;
  inset: 8px 8px auto 8px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, rgba(236, 205, 126, 0.5), transparent);
  pointer-events: none;
}

/* ---------- Header ---------- */

.faceplate {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 20px; height: 20px; fill: none;
  stroke: var(--brass); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.brand-name {
  font-weight: 700; font-size: 14px; letter-spacing: 0.34em;
  color: var(--brass-bright);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.icon-btn {
  width: 38px; height: 38px; border: none; border-radius: 50%;
  background: rgba(0, 0, 0, 0.25); color: var(--tan-dim);
  display: grid; place-items: center; cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { color: var(--brass); background: rgba(0, 0, 0, 0.4); }

/* ---------- String pills ---------- */

.strings {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
}
.chip {
  font-family: var(--font);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--tan-dim);
  background: linear-gradient(180deg, #2c1f12, #1d140b);
  border: 1px solid rgba(0, 0, 0, 0.5);
  border-radius: 999px;
  padding: 8px 10px;
  min-width: 34px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.12s, color 0.15s, box-shadow 0.2s, border-color 0.2s, background 0.2s;
  box-shadow: inset 0 1px 0 rgba(236, 205, 126, 0.08);
  -webkit-tap-highlight-color: transparent;
}
.chip:active { transform: translateY(1px) scale(0.97); }
.chip.auto { letter-spacing: 0.08em; font-size: 10px; padding: 8px 11px; color: var(--brass); }
.chip.auto[aria-pressed="true"] {
  color: var(--cream);
  border-color: rgba(200, 162, 75, 0.5);
  background: linear-gradient(180deg, #3a2a16, #281b0e);
}
.chip.string .chip-note { display: block; line-height: 1; }
.chip.active {
  color: var(--cream);
  border-color: var(--brass);
  background: linear-gradient(180deg, #50391b, #2e2010);
  box-shadow: 0 0 0 1px rgba(200, 162, 75, 0.35), 0 6px 16px -8px rgba(200, 162, 75, 0.6), inset 0 1px 0 rgba(236, 205, 126, 0.3);
}
.chip.tuned {
  color: var(--emerald);
  border-color: rgba(68, 201, 138, 0.5);
}
.chip.tuned::after {
  content: "✓";
  position: absolute;
  top: -5px; right: -3px;
  font-size: 11px;
  width: 16px; height: 16px;
  display: grid; place-items: center;
  background: var(--emerald);
  color: #07140d;
  border-radius: 50%;
  font-weight: 900;
  box-shadow: 0 0 10px rgba(68, 201, 138, 0.7);
}

/* ---------- Gauge ---------- */

.gauge-wrap {
  position: relative;
  width: 100%;
  margin-top: 2px;
}
.gauge { display: block; width: 100%; height: auto; overflow: visible; }

.zone { fill: none; stroke-width: 15; stroke-linecap: butt; opacity: 0.92; }
.zone-red { stroke: var(--red); opacity: 0.6; }
.zone-amber { stroke: var(--amber); opacity: 0.7; }
.zone-green { stroke: var(--emerald); opacity: 0.85; }

.tick { stroke: rgba(244, 230, 196, 0.32); stroke-width: 1.5; }
.tick-major { stroke: rgba(244, 230, 196, 0.7); stroke-width: 2.5; }
.tick-label { fill: var(--tan-dim); font-size: 13px; font-family: var(--font); font-weight: 600; }

.needle { transition: none; }
.needle-line {
  stroke: url(#needleGrad);
  stroke-width: 5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 7px rgba(236, 205, 126, 0.7));
}
.needle-hub { fill: url(#hubGrad); stroke: var(--brass-deep); stroke-width: 1; }
.needle-hub-dot { fill: #1a1209; }

/* in-tune glow */
.in-tune .needle-line {
  stroke: var(--emerald-glow);
  filter: drop-shadow(0 0 9px rgba(111, 240, 179, 0.85));
}
.in-tune .zone-green { opacity: 1; filter: drop-shadow(0 0 6px rgba(68, 201, 138, 0.6)); }

/* note readout — hero above the gauge */
.readout {
  text-align: center;
  pointer-events: none;
  margin-top: 2px;
}
.note {
  font-size: clamp(62px, 21vw, 96px);
  font-weight: 800;
  line-height: 0.86;
  letter-spacing: -0.02em;
  color: var(--cream);
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.55), 0 0 24px rgba(236, 205, 126, 0.12);
  transition: color 0.25s;
  font-variant-numeric: tabular-nums;
}
.note .sharp { font-size: 0.5em; vertical-align: 0.5em; margin-left: 0.02em; color: var(--brass-bright); }
.in-tune .note { color: var(--emerald-glow); text-shadow: 0 0 28px rgba(111, 240, 179, 0.45); }
.note-sub {
  margin-top: 4px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--tan-dim);
  min-height: 16px;
}
.octave { font-weight: 700; color: var(--tan); }
.freq { letter-spacing: 0.02em; }

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

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 30px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--tan-dim);
}
.status-arrow { font-size: 18px; line-height: 1; }
.status.flat .status-text, .status.flat .status-arrow { color: var(--amber); }
.status.sharp .status-text, .status.sharp .status-arrow { color: var(--amber); }
.status.intune .status-text, .status.intune .status-arrow { color: var(--emerald-glow); }
.status-cents {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--tan-faint);
  font-weight: 600;
}

/* ---------- Mic level ---------- */

.level {
  height: 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.6);
}
.level-bar {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--brass-deep), var(--brass), var(--brass-bright));
  transition: width 0.08s linear;
}
.in-tune .level-bar { background: linear-gradient(90deg, #2f7d57, var(--emerald), var(--emerald-glow)); }

/* ---------- Controls ---------- */

.controls { display: flex; flex-direction: column; gap: 12px; }
.ctl-start {
  width: 100%;
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #1a1206;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  background: linear-gradient(180deg, var(--brass-bright), var(--brass) 60%, var(--brass-deep));
  box-shadow: 0 10px 24px -10px rgba(200, 162, 75, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: transform 0.12s, filter 0.15s;
}
.ctl-start:hover { filter: brightness(1.06); }
.ctl-start:active { transform: translateY(1px) scale(0.99); }

.ctl-row { display: flex; gap: 10px; }
.ctl {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 12px;
  border-radius: 13px;
  background: linear-gradient(180deg, #271b10, #1a120a);
  border: 1px solid rgba(0, 0, 0, 0.5);
  box-shadow: inset 0 1px 0 rgba(236, 205, 126, 0.07);
  cursor: pointer;
}
.ctl-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--tan-faint);
  font-weight: 700;
}
.ctl-value, .ctl select {
  font-size: 14px;
  font-weight: 700;
  color: var(--cream);
}
.ctl select {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--cream);
  font-family: var(--font);
  cursor: pointer;
  outline: none;
  width: 100%;
}
.ctl select option { background: #1a120a; color: var(--cream); }
.ctl-toggle { align-items: flex-start; }
.ctl-toggle[aria-pressed="true"] {
  border-color: rgba(200, 162, 75, 0.45);
  background: linear-gradient(180deg, #3a2a16, #241809);
}
.ctl-toggle[aria-pressed="true"] .ctl-value { color: var(--brass-bright); }

/* ---------- Start / permission overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(120% 100% at 50% 0%, rgba(26, 18, 9, 0.86), rgba(8, 5, 2, 0.96));
  backdrop-filter: blur(3px);
  transition: opacity 0.4s ease, visibility 0.4s;
}
.overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.overlay-card {
  text-align: center;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.fork {
  width: 64px; height: 64px;
  fill: none; stroke: var(--brass); stroke-width: 3.4;
  stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 0 16px rgba(200, 162, 75, 0.45));
  animation: forkGlow 3.5s ease-in-out infinite;
}
@keyframes forkGlow {
  50% { filter: drop-shadow(0 0 24px rgba(236, 205, 126, 0.7)); }
}
.overlay-title {
  font-size: 30px; font-weight: 800; letter-spacing: -0.01em;
  color: var(--cream);
}
.overlay-copy { font-size: 15px; line-height: 1.5; color: var(--tan); }
.overlay-copy strong { color: var(--brass-bright); font-weight: 700; }
.overlay-btn {
  margin-top: 6px;
  padding: 15px 30px;
  font-size: 16px; font-weight: 700; letter-spacing: 0.02em;
  color: #1a1206; border: none; border-radius: 999px; cursor: pointer;
  background: linear-gradient(180deg, var(--brass-bright), var(--brass) 60%, var(--brass-deep));
  box-shadow: 0 12px 30px -10px rgba(200, 162, 75, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.12s, filter 0.15s;
}
.overlay-btn:hover { filter: brightness(1.06); }
.overlay-btn:active { transform: translateY(1px) scale(0.99); }
.overlay-error {
  font-size: 13px; line-height: 1.45; color: #f0a892;
  background: rgba(208, 90, 62, 0.14);
  border: 1px solid rgba(208, 90, 62, 0.35);
  padding: 10px 14px; border-radius: 12px;
}
.overlay-foot { font-size: 12px; color: var(--tan-faint); margin-top: 2px; }

/* ---------- Settings sheet ---------- */

.sheet {
  position: fixed; inset: 0; z-index: 60;
  display: grid; align-items: end; justify-items: center;
  background: rgba(8, 5, 2, 0.6);
  backdrop-filter: blur(2px);
  padding: 0 0 env(safe-area-inset-bottom);
}
.sheet[hidden] { display: none; }
.sheet-card {
  width: min(440px, 100%);
  background: linear-gradient(180deg, #2a1d11, #1a120a);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid rgba(236, 205, 126, 0.18);
  padding: 18px 20px 26px;
  box-shadow: 0 -20px 50px -10px rgba(0, 0, 0, 0.7);
  animation: sheetUp 0.28s ease;
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { font-size: 18px; color: var(--cream); font-weight: 700; }
.sheet-head .icon-btn { font-size: 16px; color: var(--tan); }
.sheet-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 2px; font-size: 14px; color: var(--tan);
  border-bottom: 1px solid rgba(0, 0, 0, 0.35);
}
.sheet-val { color: var(--brass-bright); font-weight: 700; font-family: var(--mono); }
.sheet-note { font-size: 12.5px; line-height: 1.55; color: var(--tan-dim); margin-top: 14px; }
.sheet-note strong { color: var(--brass); }

.switch {
  width: 44px; height: 26px; border-radius: 999px; border: none; cursor: pointer;
  background: #1a120a; position: relative; box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6);
  transition: background 0.2s;
}
.switch span {
  position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--tan-dim); transition: transform 0.2s, background 0.2s;
}
.switch.on { background: linear-gradient(90deg, var(--brass-deep), var(--brass)); }
.switch.on span { transform: translateX(18px); background: var(--cream); }

/* idle (no confident pitch): dim the readout so noise never shows a confident number */
.tuner.idle .note { color: var(--tan-dim); opacity: 0.5; }
.tuner.idle .note-sub { opacity: 0.4; }
.tuner.idle .needle-line { opacity: 0.5; }

@media (max-height: 700px) {
  .note { font-size: clamp(46px, 15vw, 70px); }
  .tuner { gap: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .fork { animation: none; }
  * { transition-duration: 0.01ms !important; }
}
