/* ============ Open Tuner — styles ============ */

:root {
  --bg: #0b0f1a;
  --bg-2: #101828;
  --card: rgba(255, 255, 255, 0.045);
  --card-border: rgba(255, 255, 255, 0.09);
  --text: #e7ecf5;
  --text-dim: #8b95a7;
  --accent-1: #38bdf8;
  --accent-2: #a78bfa;
  --good: #22c55e;
  --warn: #fbbf24;
  --radius: 20px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  font-family: var(--sans);
  background:
    radial-gradient(1100px 700px at 85% -10%, rgba(167, 139, 250, 0.13), transparent 60%),
    radial-gradient(1000px 700px at -10% 20%, rgba(56, 189, 248, 0.12), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 45%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.bg-glow {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(600px 400px at 50% 30%, rgba(56, 189, 248, 0.06), transparent 70%);
  transition: opacity 0.6s ease;
  opacity: 0.6;
}
body.is-in-tune .bg-glow { opacity: 1; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

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

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) 20px 14px;
  max-width: 720px; width: 100%; margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 28px; height: 28px; }
.brand-name {
  font-size: 18px; font-weight: 700; letter-spacing: 0.2px;
  background: linear-gradient(90deg, var(--accent-1), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.a4-control {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--card-border);
  padding: 8px 14px; border-radius: 999px;
  backdrop-filter: blur(12px);
}
.a4-control label {
  font-size: 11px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text-dim);
}
.a4-control output { font-family: var(--mono); font-size: 13px; min-width: 56px; color: var(--text); }
.a4-control input[type="range"] { width: 90px; accent-color: var(--accent-1); }

/* ---------- Layout ---------- */

.shell {
  width: 100%; max-width: 720px;
  margin: 0 auto; padding: 4px 20px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 18px;
  flex: 1;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* ---------- Instrument tabs ---------- */

.instrument-tabs {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 4px; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.instrument-tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  font: inherit; font-size: 14px; font-weight: 600;
  color: var(--text-dim);
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: 999px; padding: 9px 18px;
  cursor: pointer;
  transition: all 0.22s ease;
  user-select: none;
}
.tab:active { transform: scale(0.95); }
.tab.is-active {
  color: #fff;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.25), rgba(167, 139, 250, 0.25));
  border-color: rgba(56, 189, 248, 0.5);
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.18);
}
.tab.is-active {
  color: #fff;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.25), rgba(167, 139, 250, 0.25));
  border-color: rgba(56, 189, 248, 0.5);
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.18);
}

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

.gauge-card {
  padding: 18px 18px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  position: relative; overflow: hidden;
  transition: border-color 0.4s ease, box-shadow 0.4s ease;
}
body.is-in-tune .gauge-card {
  border-color: rgba(34, 197, 94, 0.55);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), 0 0 40px rgba(34, 197, 94, 0.15), inset 0 1px 0 rgba(255,255,255,0.06);
}

.gauge-wrap { width: min(94%, 380px); }
.gauge { display: block; width: 100%; height: auto; overflow: visible; }

.arc-good { filter: drop-shadow(0 0 6px rgba(34, 197, 94, 0.6)); }

.needle { color: var(--warn); transform-origin: 150px 150px; transition: color 0.3s ease; }
body.is-in-tune .needle { color: var(--good); }

.pivot { fill: #1c2740; stroke: rgba(255,255,255,0.25); stroke-width: 2; }

.gauge .tick { stroke: rgba(255,255,255,0.28); stroke-width: 2; stroke-linecap: round; }
.gauge .tick.is-major { stroke: rgba(255,255,255,0.5); }
.gauge .tick-label {
  fill: var(--text-dim); font-size: 12px; font-family: var(--mono);
  text-anchor: middle;
}

/* ---------- Readout ---------- */

.readout { text-align: center; margin-top: -4px; }

.note-block { line-height: 1; display: flex; align-items: baseline; justify-content: center; gap: 6px; }

.note-name {
  font-size: clamp(64px, 18vw, 108px);
  font-weight: 800; letter-spacing: -2px;
  background: linear-gradient(180deg, #fff, #c9d6ee);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  transition: opacity 0.3s ease;
}
body.is-silent .note-name { opacity: 0.35; }

.note-octave {
  font-size: clamp(18px, 4.5vw, 24px); font-weight: 600; color: var(--text-dim);
  font-family: var(--mono);
}

.tune-status { min-height: 26px; margin-top: 6px; }

.status-text {
  font-size: 15px; font-weight: 700; letter-spacing: 0.4px;
  color: var(--text-dim);
  transition: color 0.3s ease;
}
.status-text.is-flat, .status-text.is-sharp { color: var(--warn); }
.status-text.is-good {
  color: var(--good);
  text-shadow: 0 0 18px rgba(34, 197, 94, 0.5);
}

.freq-row {
  display: flex; justify-content: center; gap: 22px; margin-top: 8px;
  color: var(--text-dim); font-size: 14px;
}
.freq-row .cents { min-width: 64px; }

/* ---------- Waveform ---------- */

.waveform {
  width: 100%; height: 56px; border-radius: 12px;
  background: rgba(8, 12, 22, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: 10px;
}

/* ---------- Strings card ---------- */

.strings-card { padding: 16px; }

.strings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.strings-head h2 { font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.2px; color: var(--text-dim); }

.strings { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.strings::-webkit-scrollbar { display: none; }

.string-chip {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 86px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 10px 14px;
  cursor: pointer; font: inherit; color: var(--text);
  transition: all 0.2s ease;
  user-select: none;
}
.string-chip:active { transform: scale(0.95); }
.string-chip .chip-note { font-size: 22px; font-weight: 800; }
.string-chip .chip-freq { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.string-chip .chip-play {
  margin-top: 4px;
  font-size: 11px; font-weight: 600; color: var(--accent-1);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 999px; padding: 3px 12px; cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}
.string-chip .chip-play.is-playing { background: rgba(56, 189, 248, 0.3); color: #fff; }
.string-chip.is-active {
  background: linear-gradient(135deg, rgba(56,189,248,0.18), rgba(167,139,250,0.18));
  border-color: rgba(56, 189, 248, 0.5);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.15);
}
.string-chip.is-active .chip-note { color: var(--accent-1); }

.chromatic-note { color: var(--text-dim); font-size: 14px; line-height: 1.5; padding: 6px 2px; }
/* ---------- Buttons ---------- */

.btn {
  font: inherit; font-weight: 600; color: var(--text);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--card-border);
  border-radius: 999px; padding: 8px 18px; cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}
.btn:active { transform: scale(0.96); }

.btn.primary {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border: none; color: #fff;
  box-shadow: 0 6px 24px rgba(56, 189, 248, 0.35);
}
.btn.primary:hover { filter: brightness(1.1); }

.btn.big { padding: 14px 34px; font-size: 17px; }

.auto-btn.is-active {
  background: linear-gradient(135deg, rgba(56,189,248,0.25), rgba(167,139,250,0.25));
  border-color: rgba(56, 189, 248, 0.5); color: #fff;
}

/* ---------- Overlay ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(7, 10, 18, 0.82);
  backdrop-filter: blur(10px);
  padding: 24px;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
.overlay.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.overlay-card {
  max-width: 400px; width: 100%;
  padding: 36px 30px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
}
.overlay-icon { opacity: 0.9; }
.overlay-card h1 { font-size: 26px; letter-spacing: -0.3px; }
.overlay-card p { color: var(--text-dim); font-size: 15px; line-height: 1.55; }
.overlay-card .hint { font-size: 13px; }

.overlay .error { color: #f87171; }

/* ---------- Footer ---------- */

.footer {
  text-align: center; padding: 8px 20px calc(18px + env(safe-area-inset-bottom));
  color: var(--text-dim); font-size: 12px; opacity: 0.75;
}

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
  .a4-control input[type="range"] { width: 64px; }
  .a4-control output { min-width: 52px; }
  .freq-row { gap: 16px; font-size: 13px; }
  .string-chip { min-width: 76px; padding: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
