/* ═══════════════════════════════════════════════════
   StringSync — Professional Guitar Tuner
   Aesthetic: Dark-mode industrial with neon precision
   ═══════════════════════════════════════════════════ */

/* ── TOKENS ── */
:root {
  --bg:        #0a0a0f;
  --bg2:       #111118;
  --bg3:       #1a1a24;
  --surface:   #1e1e2e;
  --surface2:  #252538;
  --border:    rgba(255,255,255,0.08);
  --border2:   rgba(255,255,255,0.14);
  --accent:    #00e5ff;
  --accent2:   #7c3aed;
  --green:     #00e676;
  --red:       #ff1744;
  --yellow:    #ffea00;
  --text:      #e8e8f0;
  --text2:     #888899;
  --text3:     #555566;
  --font-display: 'Orbitron', monospace;
  --font-body:    'DM Sans', sans-serif;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 8px 32px rgba(0,0,0,0.5);
  --glow:      0 0 20px rgba(0,229,255,0.25);
  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

[data-theme="light"] {
  --bg:        #f0f0f5;
  --bg2:       #e8e8f0;
  --bg3:       #dcdce8;
  --surface:   #ffffff;
  --surface2:  #f5f5fa;
  --border:    rgba(0,0,0,0.08);
  --border2:   rgba(0,0,0,0.14);
  --text:      #1a1a2e;
  --text2:     #555566;
  --text3:     #888899;
  --shadow:    0 8px 32px rgba(0,0,0,0.12);
  --glow:      0 0 20px rgba(0,180,220,0.2);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

/* ── BACKGROUND TEXTURE ── */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(0,229,255,0.04) 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 80% 100%, rgba(124,58,237,0.05) 0%, transparent 60%);
}

/* ── HEADER ── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
[data-theme="light"] .app-header { background: rgba(240,240,245,0.85); }

.logo { display: flex; align-items: center; gap: 0.5rem; }
.logo-icon { width: 28px; height: 28px; }
.logo-text {
  font-family: var(--font-display);
  font-size: 1.1rem; font-weight: 700;
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-right { display: flex; gap: 0.4rem; }

.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); cursor: pointer;
  transition: all var(--transition);
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--surface2); color: var(--accent); border-color: var(--accent); }

/* ── SETTINGS PANEL ── */
.settings-panel {
  position: fixed; top: 0; right: 0; z-index: 200;
  width: min(360px, 92vw); height: 100dvh;
  background: var(--bg2);
  border-left: 1px solid var(--border2);
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
  display: flex; flex-direction: column;
  box-shadow: -8px 0 40px rgba(0,0,0,0.4);
  overflow: hidden;
}
.settings-panel.open { transform: translateX(0); }
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-header h2 { font-family: var(--font-display); font-size: 0.95rem; letter-spacing: 0.1em; }
.settings-body { flex: 1; overflow-y: auto; padding: 1rem 1.5rem 2rem; }
.settings-section { margin-bottom: 1.75rem; }
.settings-section h3 {
  font-size: 0.7rem; font-weight: 500; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 0.65rem;
}

.settings-overlay {
  position: fixed; inset: 0; z-index: 190;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  transition: opacity var(--transition);
}
.settings-overlay.hidden { display: none; }

/* ── SHARED CONTROLS ── */
.button-group { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.group-btn {
  padding: 0.35rem 0.8rem;
  border-radius: 6px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); font-size: 0.8rem; cursor: pointer;
  transition: all var(--transition); font-family: var(--font-body);
}
.group-btn:hover { border-color: var(--border2); color: var(--text); }
.group-btn.active { background: var(--accent); border-color: var(--accent); color: #000; font-weight: 500; }

.styled-select {
  width: 100%; padding: 0.5rem 0.75rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font-body); font-size: 0.875rem; cursor: pointer;
  outline: none; transition: border-color var(--transition);
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888899' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.75rem center;
  padding-right: 2rem;
}
.styled-select.sm { width: auto; min-width: 80px; }
.styled-select:hover, .styled-select:focus { border-color: var(--accent); }

.styled-input {
  width: 100%; padding: 0.5rem 0.75rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font-body); font-size: 0.875rem;
  outline: none; transition: border-color var(--transition);
}
.styled-input:hover, .styled-input:focus { border-color: var(--accent); }

.styled-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px;
  background: var(--surface2); border-radius: 4px; cursor: pointer; outline: none;
}
.styled-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
  box-shadow: 0 0 8px var(--accent);
  transition: transform 0.15s;
}
.styled-range::-webkit-slider-thumb:hover { transform: scale(1.25); }
.styled-range::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg); cursor: pointer;
}

.range-row { display: flex; align-items: center; gap: 0.75rem; font-size: 0.875rem; }
.range-val { font-family: var(--font-display); font-size: 0.8rem; color: var(--accent); min-width: 56px; }

.btn-sm {
  padding: 0.35rem 0.9rem;
  background: var(--accent); color: #000; border: none;
  border-radius: 6px; font-size: 0.8rem; font-weight: 500; cursor: pointer;
  transition: opacity var(--transition);
}
.btn-sm:hover { opacity: 0.85; }

.custom-tuning { margin-top: 0.6rem; display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.8rem; }
.hidden { display: none !important; }

/* ── MAIN ── */
.app-main {
  position: relative; z-index: 1;
  max-width: 700px; margin: 0 auto;
  padding: 0 1rem 4rem;
}

/* ── TAB NAV ── */
.tab-nav {
  display: flex; gap: 0;
  margin: 1.25rem 0 0;
  background: var(--surface); border-radius: var(--radius);
  padding: 4px;
  border: 1px solid var(--border);
}
.tab-btn {
  flex: 1; padding: 0.55rem;
  background: transparent; border: none;
  border-radius: calc(var(--radius) - 4px);
  color: var(--text2); font-family: var(--font-body); font-size: 0.875rem;
  cursor: pointer; transition: all var(--transition); font-weight: 400;
}
.tab-btn.active { background: var(--accent); color: #000; font-weight: 500; box-shadow: 0 2px 12px rgba(0,229,255,0.3); }
.tab-btn:not(.active):hover { color: var(--text); background: var(--surface2); }

/* ── TAB CONTENT ── */
.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── MIC BAR ── */
.mic-bar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem; margin-top: 1rem;
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.mic-btn {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 1.1rem;
  background: linear-gradient(135deg, var(--accent), #00b8d4);
  border: none; border-radius: 8px; color: #000;
  font-family: var(--font-body); font-size: 0.875rem; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
  box-shadow: 0 4px 16px rgba(0,229,255,0.25);
}
.mic-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(0,229,255,0.35); }
.mic-btn.active { background: linear-gradient(135deg, var(--red), #d50000); box-shadow: 0 4px 16px rgba(255,23,68,0.3); }
.mic-icon svg { width: 16px; height: 16px; }

.mic-status { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text2); }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text3); transition: all 0.3s;
}
.status-dot.active { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse-dot 2s infinite; }
.status-dot.error { background: var(--red); }
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 4px var(--green); }
  50% { box-shadow: 0 0 12px var(--green); }
}

.signal-bar {
  flex: 1; min-width: 80px; max-width: 120px;
  height: 6px; border-radius: 3px; background: var(--surface2);
  overflow: hidden;
}
.signal-fill {
  height: 100%; width: 0%; border-radius: 3px;
  background: linear-gradient(90deg, var(--green), var(--accent));
  transition: width 0.1s linear;
}

/* ── STRING SELECTOR ── */
.string-selector {
  display: flex; gap: 0.4rem; justify-content: center;
  margin: 1rem 0 0; flex-wrap: wrap;
}
.string-btn {
  display: flex; flex-direction: column; align-items: center;
  padding: 0.5rem 0.75rem; min-width: 52px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text2);
  cursor: pointer; transition: all var(--transition); font-family: var(--font-body);
}
.string-btn .s-name { font-family: var(--font-display); font-size: 1rem; font-weight: 700; }
.string-btn .s-note { font-size: 0.7rem; margin-top: 2px; }
.string-btn:hover { border-color: var(--accent); color: var(--accent); }
.string-btn.active { background: var(--accent); border-color: var(--accent); color: #000; box-shadow: var(--glow); }
.string-btn.detected { border-color: var(--green); box-shadow: 0 0 12px rgba(0,230,118,0.3); color: var(--green); }

/* ── TUNER DISPLAY ── */
.tuner-display {
  margin-top: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.5);
  overflow: hidden;
}

.note-display {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 1.5rem 1rem 0.5rem;
  position: relative;
}
.note-name {
  font-family: var(--font-display);
  font-size: clamp(4rem, 14vw, 6.5rem);
  font-weight: 900; line-height: 1;
  color: var(--accent);
  text-shadow: 0 0 40px rgba(0,229,255,0.4);
  letter-spacing: -0.02em;
  transition: all 0.15s ease;
}
.note-name.sharp { color: var(--red); text-shadow: 0 0 40px rgba(255,23,68,0.4); }
.note-name.flat  { color: var(--yellow); text-shadow: 0 0 40px rgba(255,234,0,0.4); }
.note-name.in-tune { color: var(--green); text-shadow: 0 0 40px rgba(0,230,118,0.4); }

.note-octave {
  position: absolute; top: 1.75rem; right: calc(50% - 3.5rem - 1.5rem);
  font-family: var(--font-display); font-size: 1.2rem; color: var(--text3);
}

.note-freq {
  font-family: var(--font-display); font-size: 0.9rem; color: var(--text2);
  letter-spacing: 0.05em; margin-top: 0.1rem;
}

/* NEEDLE METER CANVAS */
.meter-wrap {
  position: relative; padding: 0 0.5rem;
}
#meterCanvas { width: 100%; height: auto; display: block; }

.cents-display {
  display: flex; flex-direction: column; align-items: center;
  margin-top: -0.5rem; padding-bottom: 0.75rem;
}
#centsValue {
  font-family: var(--font-display); font-size: 1.4rem; font-weight: 700;
  color: var(--text); transition: color 0.2s;
}
.cents-label { font-size: 0.8rem; color: var(--text3); margin-top: 2px; letter-spacing: 0.06em; }

/* ACCURACY BAR */
.accuracy-bar {
  position: relative; height: 6px;
  background: var(--surface2);
  margin: 0 1rem 1rem;
  border-radius: 3px; overflow: visible;
}
.accuracy-fill {
  position: absolute; top: 0; height: 100%;
  background: var(--green); border-radius: 3px;
  transition: width 0.2s ease, background 0.3s ease;
  left: 50%; transform: translateX(-50%);
  width: 0%;
}
.accuracy-label {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  font-size: 0.7rem; color: var(--text3); white-space: nowrap;
  letter-spacing: 0.05em;
}

/* ── REFERENCE TONE ── */
.ref-tone-section {
  margin-top: 1.25rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
}
.section-title {
  font-size: 0.7rem; font-weight: 500; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 0.75rem;
}
.ref-tone-grid { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.ref-tone-btn {
  display: flex; flex-direction: column; align-items: center;
  padding: 0.5rem 0.65rem; min-width: 52px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition);
  font-family: var(--font-body);
}
.ref-tone-btn .rt-note { font-family: var(--font-display); font-size: 0.95rem; font-weight: 700; color: var(--text); }
.ref-tone-btn .rt-freq { font-size: 0.65rem; color: var(--text3); margin-top: 2px; }
.ref-tone-btn:hover { border-color: var(--accent2); }
.ref-tone-btn.playing { background: var(--accent2); border-color: var(--accent2); animation: tone-pulse 0.8s infinite alternate; }
.ref-tone-btn.playing .rt-note, .ref-tone-btn.playing .rt-freq { color: #fff; }
@keyframes tone-pulse { from { box-shadow: 0 0 8px rgba(124,58,237,0.4); } to { box-shadow: 0 0 20px rgba(124,58,237,0.7); } }

.ref-controls { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; font-size: 0.8rem; color: var(--text2); }

/* ── METRONOME ── */
.metro-container {
  display: flex; flex-direction: column; align-items: center;
  gap: 1.5rem; padding: 1.5rem 0;
}

.bpm-display { text-align: center; }
.bpm-number {
  font-family: var(--font-display); font-size: clamp(4rem, 18vw, 7rem);
  font-weight: 900; line-height: 1; color: var(--accent);
  text-shadow: 0 0 40px rgba(0,229,255,0.3);
  letter-spacing: -0.02em;
}
.bpm-label { font-size: 0.8rem; letter-spacing: 0.2em; color: var(--text3); margin-top: 0.25rem; }

.beat-visual { position: relative; width: 80px; height: 80px; }
.beat-dot {
  position: absolute; top: 50%; left: 50%;
  width: 36px; height: 36px; border-radius: 50%; transform: translate(-50%,-50%);
  background: var(--accent);
  box-shadow: 0 0 20px rgba(0,229,255,0.5);
  transition: transform 0.05s;
}
.beat-dot.flash { transform: translate(-50%,-50%) scale(1.4); background: var(--green); box-shadow: 0 0 30px rgba(0,230,118,0.7); }
.beat-arc {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--border2);
}

.beat-indicators { display: flex; gap: 0.5rem; }
.beat-ind {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  transition: all 0.05s;
}
.beat-ind.active { background: var(--green); box-shadow: 0 0 10px rgba(0,230,118,0.5); }
.beat-ind.accent { background: var(--accent); box-shadow: 0 0 10px rgba(0,229,255,0.5); }

.bpm-controls { display: flex; align-items: center; gap: 1rem; width: 100%; max-width: 360px; }
.bpm-step {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); font-size: 1.4rem; cursor: pointer;
  transition: all var(--transition); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.bpm-step:hover { background: var(--accent); color: #000; border-color: var(--accent); }
.bpm-range { flex: 1; }

.metro-row {
  display: flex; align-items: center; gap: 1rem; width: 100%; max-width: 360px;
  justify-content: space-between;
}
.time-sig-group { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.75rem; color: var(--text3); }

.tap-btn {
  padding: 0.65rem 1.5rem;
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font-display); font-size: 0.8rem; font-weight: 700;
  letter-spacing: 0.1em; cursor: pointer; transition: all var(--transition);
}
.tap-btn:hover { background: var(--surface2); border-color: var(--accent); color: var(--accent); }
.tap-btn:active { transform: scale(0.96); }

.metro-start-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  flex: 1; padding: 0.75rem;
  background: linear-gradient(135deg, var(--accent), #00b8d4);
  border: none; border-radius: var(--radius-sm); color: #000;
  font-family: var(--font-display); font-size: 0.85rem; font-weight: 700;
  letter-spacing: 0.08em; cursor: pointer; transition: all var(--transition);
  box-shadow: 0 4px 20px rgba(0,229,255,0.25);
}
.metro-start-btn svg { width: 18px; height: 18px; }
.metro-start-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(0,229,255,0.4); }
.metro-start-btn.active { background: linear-gradient(135deg, var(--red), #c62828); box-shadow: 0 4px 20px rgba(255,23,68,0.3); }

/* ── CHORDS ── */
.chords-container { padding: 1rem 0; }
.chord-search-row { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }

.chord-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.75rem;
}

.chord-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.75rem;
  cursor: pointer; transition: all var(--transition);
  display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
}
.chord-card:hover { border-color: var(--accent2); box-shadow: 0 4px 20px rgba(124,58,237,0.15); transform: translateY(-2px); }
.chord-card .chord-name {
  font-family: var(--font-display); font-size: 0.9rem; font-weight: 700; color: var(--text);
}
.chord-card svg { width: 100%; height: auto; }

/* ── SCROLLBARS ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── RESPONSIVE ── */
@media (max-width: 480px) {
  .app-header { padding: 0.6rem 1rem; }
  .app-main { padding: 0 0.75rem 4rem; }
  .string-selector { gap: 0.3rem; }
  .string-btn { min-width: 44px; padding: 0.4rem 0.55rem; }
  .chord-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .metro-row, .bpm-controls { max-width: 100%; }
  .note-octave { right: calc(50% - 3rem - 1rem); }
}

@media (min-width: 640px) {
  .chord-search-row { flex-direction: row; align-items: center; }
  .chord-search-row .styled-input { max-width: 220px; }
}