:root {
  --bg:          #0A0A0F;
  --surface:     #13131A;
  --card:        #1A1A26;
  --border:      #2D2D42;
  --primary:     #8B5CF6;
  --primary-dim: #6D28D9;
  --success:     #06D6A0;
  --warning:     #FFB703;
  --danger:      #EF476F;
  --text:        #EEEEF4;
  --muted:       #8A8A9E;
  --font-head:   'Space Grotesk', system-ui, sans-serif;
  --font-body:   'Inter', system-ui, sans-serif;
  --font-mono:   'JetBrains Mono', monospace;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Typography ─────────────────────────────────────── */
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 700; line-height: 1.15; }
h1 { font-size: clamp(2rem, 5vw, 3.5rem); }
h2 { font-size: clamp(1.5rem, 3vw, 2.25rem); }
h3 { font-size: 1.25rem; }

a { color: var(--primary); text-decoration: none; }
a:hover { color: #A78BFA; }

.mono { font-family: var(--font-mono); }

/* ── Layout helpers ──────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; } .gap-2 { gap: 1rem; } .gap-3 { gap: 1.5rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-center { text-align: center; }

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.4rem;
  border-radius: 8px;
  border: none;
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dim); color: #fff; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Nav ─────────────────────────────────────────────── */
nav {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  background: rgba(10, 10, 15, 0.85);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}
.logo {
  font-family: var(--font-head);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.logo span { color: var(--primary); }
.nav-links { display: flex; gap: 1.5rem; align-items: center; }
.nav-links a { color: var(--muted); font-size: 0.9rem; transition: color 0.15s; }
.nav-links a:hover { color: var(--text); }

/* ── Badge / chip ────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-head);
  letter-spacing: 0.02em;
}
.badge-primary { background: rgba(139,92,246,0.15); color: var(--primary); border: 1px solid rgba(139,92,246,0.3); }
.badge-success { background: rgba(6,214,160,0.12); color: var(--success); border: 1px solid rgba(6,214,160,0.25); }
.badge-warning { background: rgba(255,183,3,0.12); color: var(--warning); border: 1px solid rgba(255,183,3,0.25); }
.badge-danger  { background: rgba(239,71,111,0.12); color: var(--danger);  border: 1px solid rgba(239,71,111,0.25); }

/* ── Tune page ───────────────────────────────────────── */
.tune-layout {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: calc(100vh - 65px);
  padding: 1.5rem 0;
  gap: 1.5rem;
}

.status-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Listening animation */
.listening-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.listening-dot.active {
  background: var(--success);
  animation: pulse-dot 1s infinite;
}
.listening-dot.detected {
  background: var(--warning);
  animation: none;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.75); }
}

/* Note display */
.current-note {
  font-family: var(--font-head);
  font-size: 2rem;
  font-weight: 700;
  min-width: 3rem;
  color: var(--text);
}
.current-cents {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  min-width: 5rem;
}

/* Confidence bar */
.confidence-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.confidence-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--primary);
  transition: width 0.1s ease;
}

/* Chart wrapper */
.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  position: relative;
  /* Fixed height prevents Chart.js from growing the canvas indefinitely.
     maintainAspectRatio: false means Chart uses this exact pixel height. */
  height: 240px;
  box-sizing: border-box;
}
.chart-card canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  /* Prevent Chart.js resize observer from fighting the fixed height */
  position: absolute;
  top: 1.25rem;
  left: 1.25rem;
  right: 1.25rem;
  bottom: 1.25rem;
}

.chart-legend {
  display: flex;
  gap: 1.25rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.legend-dot {
  width: 10px; height: 10px; border-radius: 50%;
}

/* Mini piano keyboard */
.piano-keyboard {
  display: flex;
  align-items: flex-start;
  height: 56px;
  gap: 1px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.piano-key {
  border-radius: 0 0 4px 4px;
  flex-shrink: 0;
  cursor: default;
  transition: background 0.2s;
  position: relative;
}
.piano-key.white {
  width: 14px;
  height: 52px;
  background: #e8e8e0;
  border: 1px solid #bbb;
  z-index: 1;
}
.piano-key.black {
  width: 9px;
  height: 34px;
  background: #1a1a1a;
  border: 1px solid #000;
  margin: 0 -4.5px;
  z-index: 2;
}
.piano-key.done-good  { background: var(--success) !important; opacity: 0.85; }
.piano-key.done-warn  { background: var(--warning) !important; opacity: 0.85; }
.piano-key.done-bad   { background: var(--danger)  !important; opacity: 0.85; }
.piano-key.active     { background: var(--primary)  !important; }

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
}
.stat-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.25rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-family: var(--font-head); font-size: 1.5rem; font-weight: 700; }

/* Controls row */
.controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

/* Progress text */
.progress-text {
  font-size: 0.85rem;
  color: var(--muted);
  margin-left: auto;
}

/* ── Landing page ────────────────────────────────────── */
.hero {
  padding: 5rem 0 4rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 50% at 50% 0%, rgba(139,92,246,0.12) 0%, transparent 70%);
  pointer-events: none;
}
.hero-eyebrow {
  margin-bottom: 1.25rem;
}
.hero h1 {
  letter-spacing: -0.03em;
  margin-bottom: 1.25rem;
}
.hero h1 em {
  font-style: normal;
  background: linear-gradient(135deg, #8B5CF6, #06D6A0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero p {
  font-size: 1.15rem;
  color: var(--muted);
  max-width: 560px;
  margin: 0 auto 2rem;
  line-height: 1.75;
}
.hero-cta { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.btn-lg { padding: 0.85rem 2rem; font-size: 1.05rem; border-radius: 10px; }

/* Fake chart preview on landing */
.preview-card {
  max-width: 800px;
  margin: 4rem auto 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 0 60px rgba(139,92,246,0.08);
}

/* Feature grid */
.features {
  padding: 5rem 0;
}
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-top: 3rem;
}
.feature-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem;
  transition: border-color 0.2s;
}
.feature-card:hover { border-color: var(--primary); }
.feature-icon {
  font-size: 1.75rem;
  margin-bottom: 1rem;
}
.feature-card h3 { margin-bottom: 0.5rem; }
.feature-card p { color: var(--muted); font-size: 0.9rem; line-height: 1.7; }

/* How it works */
.steps {
  padding: 5rem 0;
  background: linear-gradient(180deg, var(--bg) 0%, var(--surface) 100%);
}
.steps-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 2rem;
  margin-top: 3rem;
}
.step {
  text-align: center;
}
.step-number {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: rgba(139,92,246,0.15);
  border: 2px solid var(--primary);
  color: var(--primary);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
}
.step h3 { margin-bottom: 0.5rem; }
.step p { color: var(--muted); font-size: 0.9rem; }

/* Callout banner */
.callout {
  background: linear-gradient(135deg, rgba(139,92,246,0.1), rgba(6,214,160,0.07));
  border: 1px solid rgba(139,92,246,0.25);
  border-radius: 16px;
  padding: 3rem;
  text-align: center;
  margin: 4rem 0;
}
.callout h2 { margin-bottom: 1rem; }
.callout p { color: var(--muted); margin-bottom: 1.5rem; max-width: 520px; margin-left: auto; margin-right: auto; }

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0;
  margin-top: 4rem;
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 640px) {
  .nav-links .hide-mobile { display: none; }
  .hero { padding: 3rem 0 2.5rem; }
  .callout { padding: 2rem; }
  .tune-layout { padding: 1rem 0; gap: 1rem; }
  .current-note { font-size: 1.5rem; }
}

/* ── Animations ──────────────────────────────────────── */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fade-in 0.4s ease both; }

/* Glow effect on detected note */
.glow-success { text-shadow: 0 0 20px rgba(6,214,160,0.6); }
.glow-warning { text-shadow: 0 0 20px rgba(255,183,3,0.6); }
.glow-danger  { text-shadow: 0 0 20px rgba(239,71,111,0.6); }

/* Tooltip */
[data-tooltip] { position: relative; cursor: help; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.78rem;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 99;
}
[data-tooltip]:hover::after { opacity: 1; }
