/* ─────────────────────────────────────────────
   styles.css  –  Tuner visual design
   ───────────────────────────────────────────── */

/* ── Fonts ────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,500;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Custom properties ────────────────────── */
:root {
  --bg:          #111113;
  --bg-card:     #1a1a1e;
  --bg-surface:  #222228;
  --text:        #f0eff4;
  --text-dim:    #8b8a94;
  --text-muted:  #55545e;
  --accent:      #44FF88;
  --red:         #FF4444;
  --amber:       #FFB84D;
  --yellow:      #FFE44D;
  --green:       #44FF88;
  --radius:      16px;
  --radius-lg:   30px;
  --font:        'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono:        'JetBrains Mono', ui-monospace, monospace;
  --meter-h:     56px;
  --indicator-d: 42px;
  --transition:  220ms ease-out;
}

/* Light theme */
[data-theme="light"] {
  --bg:         #f4f3f8;
  --bg-card:    #ffffff;
  --bg-surface: #eae9f0;
  --text:       #18171c;
  --text-dim:   #6e6d78;
  --text-muted: #a5a4ae;
}

/* ── Retro (Konami) theme ─────────────────── */
[data-theme="retro"] {
  --bg:         #0c0820;
  --bg-card:    #1a1440;
  --bg-surface: #241c58;
  --text:       #44ff88;
  --text-dim:   #a088ff;
  --text-muted: #5040a0;
  --accent:     #ff44aa;
  --green:      #44ff88;
  --red:        #ff4444;
  --amber:      #ffb84d;
  --yellow:     #ffe44d;
}
[data-theme="retro"] body {
  font-family: 'Courier New', monospace !important;
  image-rendering: pixelated;
}
[data-theme="retro"] .radial-note {
  text-shadow: 0 0 20px var(--accent), 0 0 60px var(--accent);
  letter-spacing: 8px;
}
[data-theme="retro"] #arc-segments path {
  opacity: 0.8 !important;
}
[data-theme="retro"] .needle {
  fill: var(--accent);
}
[data-theme="retro"] .start-btn {
  border: 2px solid var(--accent);
  border-radius: 4px !important;
  text-transform: uppercase;
  letter-spacing: 6px;
}
[data-theme="retro"] .start-btn:hover {
  box-shadow: 0 0 30px var(--accent);
}

/* ── Reset / base ─────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  transition: background var(--transition), color var(--transition);
}

/* ── Layout ───────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  position: relative;
  transition: opacity 0.8s ease;
}
.app.ambient { opacity: 0.45; }

/* ── Start screen ─────────────────────────── */
.start-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  animation: fadeUp 0.5s ease-out both;
}
.start-screen.hidden { display: none; }

.start-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: var(--text-dim);
  border: 2px solid var(--bg-surface);
}

.start-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.start-sub {
  font-size: 15px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
  max-width: 320px;
}

.start-btn {
  padding: 18px 56px;
  font-size: 18px;
  font-weight: 600;
  font-family: var(--font);
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #111;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
.start-btn:hover  { transform: scale(1.04); box-shadow: 0 8px 30px rgba(68,255,136,.25); }
.start-btn:active { transform: scale(0.97); }
.start-btn:focus-visible {
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--accent);
}

/* ── Tuner screen ─────────────────────────── */
.tuner-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 640px;
  animation: fadeUp 0.4s ease-out both;
}
.tuner-screen.active { display: flex; }

/* ── Status line ──────────────────────────── */
.status {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  height: 20px;
  transition: color var(--transition);
}

/* ── Note display ─────────────────────────── */
.note-octave {
  font-size: 0.4em;
  font-weight: 500;
  vertical-align: sub;
  opacity: 0.6;
  letter-spacing: 0;
  margin-left: 1px;
}

.note-freq {
  font-family: var(--mono);
  font-size: clamp(16px, 3vw, 22px);
  font-weight: 400;
  color: var(--text-dim);
  transition: color var(--transition);
}

/* ── Radial meter ─────────────────────────── */
.radial-meter {
  position: relative;
  width: min(80vw, 380px);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  margin: -12px 0;
}

.radial-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

#arc-segments path {
  transition: opacity 0.1s ease;
}

.needle-group {
  transform-origin: 200px 200px;
  transition: transform 0.12s cubic-bezier(.22,.68,.36,1.2);
  will-change: transform;
}

.needle {
  filter: drop-shadow(0 0 6px rgba(45, 212, 168, 0.4));
}

.inner-ring {
  transition: stroke 0.3s ease, opacity 0.3s ease, filter 0.3s ease;
}
.inner-ring.glow {
  stroke: #44FF88;
  opacity: 0.9;
  filter: drop-shadow(0 0 10px rgba(68, 255, 136, 0.5));
}

.arc-label {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  fill: var(--text-muted);
}

.radial-note {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(56px, 12vw, 80px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -2px;
  transition: color var(--transition);
  pointer-events: none;
}

/* Frozen overlay */
.meter-frozen-badge {
  position: absolute;
  top: 6%;
  right: 6%;
  background: var(--amber);
  color: #111;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  z-index: 3;
}
.radial-meter.frozen .meter-frozen-badge { opacity: 1; }
.radial-meter.frozen .needle { fill: var(--amber); }

/* Out-of-range state */
.radial-meter.out-of-range .needle {
  fill: var(--text-muted);
  opacity: 0.3;
  filter: none;
}
.radial-meter.out-of-range .inner-ring {
  stroke: var(--red);
  opacity: 0.4;
}

/* ── Cents readout ────────────────────────── */
.cents-display {
  font-family: var(--mono);
  font-size: clamp(14px, 2.5vw, 18px);
  font-weight: 500;
  min-width: 70px;
  text-align: center;
  transition: color var(--transition);
  height: 24px;
}

/* ── Message toast ────────────────────────── */
.message-toast {
  font-size: 15px;
  font-weight: 500;
  color: var(--green);
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
  transform: translateY(4px);
  height: 24px;
  pointer-events: none;
}
.message-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Streak ───────────────────────────────── */
.streak {
  font-size: 13px;
  color: var(--text-muted);
  height: 20px;
  transition: opacity 0.3s ease;
}
.streak.hidden { opacity: 0; }

/* ── Settings toggle ──────────────────────── */
.settings-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--bg-surface);
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform 0.15s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  z-index: 10;
}
.settings-toggle:hover { background: var(--bg-card); transform: rotate(30deg); }
.settings-toggle:focus-visible {
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--accent);
}

/* ── Settings panel ───────────────────────── */
.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  z-index: 90;
}
.settings-backdrop.open { opacity: 1; visibility: visible; }

.settings-panel {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: min(360px, 88vw);
  background: var(--bg-card);
  padding: 32px 28px;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(.22,.68,.36,1);
  z-index: 100;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.settings-panel.open { transform: translateX(0); }

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.settings-title {
  font-size: 20px;
  font-weight: 700;
}
.settings-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--bg-surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.settings-close:hover { background: var(--bg); }

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.setting-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-select, .setting-input {
  padding: 10px 14px;
  font-size: 15px;
  font-family: var(--font);
  border: 1px solid var(--bg-surface);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
  width: 100%;
}
.setting-select:focus, .setting-input:focus {
  border-color: var(--accent);
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-surface);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.2s ease;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle-knob {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
  pointer-events: none;
}
.toggle input:checked ~ .toggle-knob { transform: translateX(20px); }
.toggle input:focus-visible + .toggle-track {
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--accent);
}

/* ── Celebration particles ────────────────── */
.particle-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}
.particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  opacity: 0;
  animation: particleFly 1.2s ease-out forwards;
}

/* ── Error screen ─────────────────────────── */
.error-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
  animation: fadeUp 0.4s ease-out both;
}
.error-screen.active { display: flex; }
.error-icon { font-size: 48px; }
.error-title { font-size: 22px; font-weight: 700; }
.error-message {
  font-size: 15px;
  color: var(--text-dim);
  line-height: 1.6;
  max-width: 360px;
}
.error-retry {
  padding: 12px 32px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  border: 1px solid var(--bg-surface);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease;
}
.error-retry:hover { background: var(--bg-surface); }

/* ── Animations ───────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes particleFly {
  0%   { opacity: 1; transform: translate(0,0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}

/* ── Reduced motion ───────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .needle-group { transition: none !important; }
}

/* ── High contrast ────────────────────────── */
@media (prefers-contrast: more) {
  :root {
    --bg-surface: #333;
    --text-dim: #ccc;
    --text-muted: #999;
  }
  #arc-segments path { opacity: 0.6 !important; }
}

/* ── Mobile adjustments ───────────────────── */
@media (max-width: 480px) {
  .app { padding: 16px; }
  .radial-meter { width: min(90vw, 380px); }
  .start-btn { padding: 16px 44px; font-size: 17px; }
  .settings-toggle { bottom: 16px; right: 16px; }
}

@media (max-height: 560px) {
  .radial-meter { width: min(65vw, 300px); margin: -16px 0; }
  .radial-note { font-size: clamp(40px, 10vw, 56px); }
}
