:root,
[data-theme="light"] {
  --bg: #eef1f4;
  --bg-accent: #e2e8f0;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #cbd5e1;
  --surface: #ffffff;
  --accent: #1d4ed8;
  --ok: #15803d;
  --btn-stop: #dc2626;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --plate: #f8fafc;
  --plate-border: #dbe3ee;
  --arc-track: #e2e8f0;
  --tick: #475569;
  --tick-zero: #0f172a;
  --label: #64748b;
  --gauge-bad: #f87171;
  --gauge-warn: #fbbf24;
  --gauge-ok: #4ade80;
  --needle-tip: #fb7185;
  --needle-mid: #e11d48;
  --needle-base: #9f1239;
  --needle-weight: #334155;
  --needle-edge: rgba(255, 255, 255, 0.35);
  --hub-hi: #f8fafc;
  --hub-mid: #94a3b8;
  --hub-lo: #334155;
  --hub-ring: #e2e8f0;
  --hub-core: #0f172a;
}

[data-theme="dark"] {
  --bg: #070a0f;
  --bg-accent: #111827;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: #1f2937;
  --surface: #0f141c;
  --accent: #3b82f6;
  --ok: #22c55e;
  --btn-stop: #ef4444;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --plate: #121821;
  --plate-border: #243041;
  --arc-track: #1f2a3a;
  --tick: #94a3b8;
  --tick-zero: #f8fafc;
  --label: #94a3b8;
  --gauge-bad: #f87171;
  --gauge-warn: #fbbf24;
  --gauge-ok: #4ade80;
  --needle-tip: #fda4af;
  --needle-mid: #fb7185;
  --needle-base: #be123c;
  --needle-weight: #64748b;
  --needle-edge: rgba(255, 255, 255, 0.28);
  --hub-hi: #e2e8f0;
  --hub-mid: #64748b;
  --hub-lo: #1e293b;
  --hub-ring: #334155;
  --hub-core: #f8fafc;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg-accent), transparent 60%),
    var(--bg);
}

body {
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(720px, 100%);
  margin: 0 auto;
  padding:
    max(0.85rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1.5rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: clamp(0.85rem, 2.5vw, 1.4rem);
}

.brand {
  margin: 0;
  font-size: clamp(1.15rem, 3.5vw, 1.55rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.theme-btn {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}

.theme-icon::before {
  content: "☾";
  font-size: 1rem;
  line-height: 1;
}

[data-theme="dark"] .theme-icon::before {
  content: "☀";
}

.main {
  display: grid;
  gap: clamp(0.75rem, 2vw, 1.1rem);
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
}

.controls select {
  appearance: none;
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E")
    no-repeat right 0.9rem center;
  color: var(--ink);
  border-radius: 12px;
  padding: 0.75rem 2.2rem 0.75rem 0.9rem;
  font-size: clamp(0.9rem, 2.6vw, 1rem);
  box-shadow: var(--shadow);
}

.controls select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.stage {
  display: grid;
  gap: clamp(0.75rem, 2vw, 1rem);
}

.meter {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: clamp(16px, 3vw, 24px);
  padding: clamp(0.65rem, 2vw, 1.15rem);
  text-align: center;
  box-shadow: var(--shadow);
}

.dial {
  width: min(100%, 520px);
  margin: 0 auto;
}

.dial-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.dial-svg .g-bad { stop-color: var(--gauge-bad); }
.dial-svg .g-warn { stop-color: var(--gauge-warn); }
.dial-svg .g-ok { stop-color: var(--gauge-ok); }
.dial-svg .n-tip { stop-color: var(--needle-tip); }
.dial-svg .n-mid { stop-color: var(--needle-mid); }
.dial-svg .n-base { stop-color: var(--needle-base); }
.dial-svg .h-hi { stop-color: var(--hub-hi); }
.dial-svg .h-mid { stop-color: var(--hub-mid); }
.dial-svg .h-lo { stop-color: var(--hub-lo); }

.dial-plate {
  fill: var(--plate);
  stroke: var(--plate-border);
  stroke-width: 1.5;
}

.arc-track {
  stroke: var(--arc-track);
}

.ticks .tick {
  stroke: var(--tick);
  stroke-linecap: round;
}

.ticks .tick.major {
  stroke-width: 3;
}

.ticks .tick.minor {
  stroke-width: 1.6;
  opacity: 0.7;
}

.ticks .tick.zero {
  stroke: var(--tick-zero);
  stroke-width: 3.5;
}

.dial-label {
  fill: var(--label);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.02em;
}

.dial-label.center {
  font-size: 15px;
  font-weight: 700;
  fill: var(--ink);
}

.dial-unit {
  fill: var(--muted);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-family: inherit;
}

.needle-blade {
  stroke: none;
}

.needle-edge {
  stroke: var(--needle-edge);
  stroke-width: 1;
  stroke-linecap: round;
}

.needle-weight {
  fill: var(--needle-weight);
}

.hub-outer {
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 1;
}

.hub-ring {
  fill: var(--hub-ring);
  stroke: rgba(0, 0, 0, 0.18);
  stroke-width: 1;
}

.hub-core {
  fill: var(--hub-core);
}

.readout {
  margin-top: clamp(0.15rem, 1vw, 0.35rem);
}

.note-name {
  margin: 0;
  font-size: clamp(2.6rem, 12vw, 4.6rem);
  line-height: 1;
  font-weight: 750;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s ease;
}

.note-name.in-tune {
  color: var(--ok);
}

.meta {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: clamp(0.85rem, 2.5vw, 1rem);
  font-variant-numeric: tabular-nums;
  min-height: 1.25em;
}

.string-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin-top: clamp(0.7rem, 2vw, 1rem);
}

.string-chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  font-size: clamp(0.72rem, 2vw, 0.85rem);
  font-weight: 600;
}

.string-chip.active {
  color: var(--ink);
  border-color: var(--ink);
}

.string-chip.in-tune {
  color: var(--ok);
  border-color: var(--line);
}

.actions {
  display: grid;
  gap: 0.55rem;
  text-align: center;
}

.mic-btn {
  border: 0;
  border-radius: 14px;
  min-height: 3rem;
  padding: 0.9rem 1rem;
  font-size: clamp(0.95rem, 2.6vw, 1.05rem);
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  width: 100%;
}

.mic-btn:active {
  transform: translateY(1px);
}

.mic-btn[aria-pressed="true"] {
  background: var(--btn-stop);
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.78rem, 2.2vw, 0.88rem);
}

.ad-slot {
  margin-top: clamp(1rem, 3vw, 1.5rem);
}

.ad-frame {
  min-height: 90px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 80%, var(--bg));
  display: grid;
  place-content: center;
  gap: 0.2rem;
  text-align: center;
  padding: 0.85rem 1rem;
}

.ad-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ad-soon {
  color: var(--muted);
  font-size: 0.78rem;
  opacity: 0.8;
}

/* Phones landscape / short height */
@media (max-height: 560px) and (orientation: landscape) {
  .app {
    width: min(960px, 100%);
  }

  .main {
    grid-template-columns: minmax(180px, 240px) 1fr;
    align-items: start;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .stage {
    grid-template-columns: 1.4fr 0.7fr;
    align-items: center;
  }

  .note-name {
    font-size: clamp(2rem, 8vh, 3rem);
  }
}

/* Tablet+ */
@media (min-width: 600px) {
  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .app {
    padding-top: 1.5rem;
  }
}

/* Desktop */
@media (min-width: 900px) {
  .app {
    width: min(820px, 100%);
    padding-top: 2rem;
  }

  .dial {
    width: min(100%, 560px);
  }
}

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .meter,
  .note-name {
    transition: none;
  }
}
