@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

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

:root {
  --bg: #0d1117;
  --card: #161b22;
  --card-hover: #1c2129;
  --border: #30363d;
  --primary: #00d4aa;
  --primary-dim: rgba(0, 212, 170, 0.15);
  --primary-glow: rgba(0, 212, 170, 0.3);
  --warning: #ff6b6b;
  --text: #e6edf3;
  --muted: #7d8590;
  --font: 'IBM Plex Sans', -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', monospace;
  --radius: 8px;
  --radius-lg: 12px;
  /* hearing level colors */
  --hl-normal: #00d4aa;
  --hl-mild: #f0c040;
  --hl-moderate: #f09040;
  --hl-modsevere: #e05040;
  --hl-severe: #d03030;
  --hl-profound: #801818;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ── */
h1 { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.01em; }
h3 { font-size: 1.15rem; font-weight: 600; }
.mono { font-family: var(--mono); }

/* ── Layout ── */
.container { max-width: 800px; margin: 0 auto; padding: 0 20px; width: 100%; }
.page-content { flex: 1; padding: 40px 0; }

/* ── Header ── */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  background: rgba(13, 17, 23, 0.9);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 100;
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; }
.logo { font-family: var(--mono); font-size: 1.25rem; font-weight: 600; color: var(--primary); text-decoration: none; }
.logo span { color: var(--muted); font-weight: 400; }
.header-nav a { color: var(--muted); text-decoration: none; font-size: 0.875rem; margin-left: 20px; transition: color 0.2s; }
.header-nav a:hover { color: var(--text); }

/* ── Footer ── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}
.site-footer a { color: var(--muted); text-decoration: none; transition: color 0.2s; }
.site-footer a:hover { color: var(--primary); }
.footer-links { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  transition: border-color 0.2s;
}
.card:hover { border-color: rgba(0,212,170,0.3); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-family: var(--font);
  font-weight: 600;
  font-size: 1rem;
  border: none; cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn-primary {
  background: var(--primary);
  color: var(--bg);
}
.btn-primary:hover { background: #00e6b8; box-shadow: 0 0 20px var(--primary-glow); }
.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-secondary:hover { background: var(--primary-dim); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-lg { padding: 16px 36px; font-size: 1.1rem; border-radius: var(--radius-lg); }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; }

/* ── Landing ── */
.hero { text-align: center; padding: 48px 0 32px; }
.hero h1 { font-size: 2.5rem; margin-bottom: 12px; }
.hero h1 .accent { color: var(--primary); }
.hero p { color: var(--muted); font-size: 1.1rem; max-width: 520px; margin: 0 auto 32px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.sound-wave-hero {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  height: 60px; margin-bottom: 24px;
}
.sound-wave-hero .bar {
  width: 4px; border-radius: 2px; background: var(--primary);
  animation: wave 1.2s ease-in-out infinite;
}
.sound-wave-hero .bar:nth-child(1) { height: 20px; animation-delay: 0s; }
.sound-wave-hero .bar:nth-child(2) { height: 35px; animation-delay: 0.1s; }
.sound-wave-hero .bar:nth-child(3) { height: 50px; animation-delay: 0.2s; }
.sound-wave-hero .bar:nth-child(4) { height: 40px; animation-delay: 0.3s; }
.sound-wave-hero .bar:nth-child(5) { height: 55px; animation-delay: 0.15s; }
.sound-wave-hero .bar:nth-child(6) { height: 30px; animation-delay: 0.25s; }
.sound-wave-hero .bar:nth-child(7) { height: 45px; animation-delay: 0.35s; }
.sound-wave-hero .bar:nth-child(8) { height: 25px; animation-delay: 0.05s; }
.sound-wave-hero .bar:nth-child(9) { height: 38px; animation-delay: 0.2s; }
@keyframes wave {
  0%, 100% { transform: scaleY(0.5); opacity: 0.5; }
  50% { transform: scaleY(1); opacity: 1; }
}

.last-test-banner {
  display: flex; align-items: center; gap: 12px;
  background: var(--primary-dim);
  border: 1px solid rgba(0,212,170,0.2);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 24px;
  font-size: 0.9rem;
}
.last-test-banner .icon { font-size: 1.2rem; }

.mode-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 32px; }
.mode-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}
.mode-card:hover { border-color: var(--primary); background: var(--card-hover); }
.mode-card h3 { margin-bottom: 6px; }
.mode-card p { color: var(--muted); font-size: 0.85rem; }
.mode-card .duration { font-family: var(--mono); color: var(--primary); font-size: 0.8rem; margin-top: 8px; }

/* ── Calibration ── */
#calibration .instructions {
  color: var(--muted); font-size: 0.95rem; margin-bottom: 20px; line-height: 1.7;
}
#calibration .instructions strong { color: var(--text); }
.calibration-controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.calibration-status { font-family: var(--mono); color: var(--primary); font-size: 0.9rem; }

/* ── Test Screen ── */
#test-screen { text-align: center; }
.test-info {
  display: flex; justify-content: center; gap: 32px;
  margin-bottom: 24px; flex-wrap: wrap;
}
.test-info .info-item { text-align: center; }
.test-info .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.test-info .value { font-family: var(--mono); font-size: 1.5rem; font-weight: 600; }
.ear-left .value { color: #58a6ff; }
.ear-right .value { color: #ff6b6b; }

.progress-bar-wrap {
  background: rgba(48,54,61,0.5);
  border-radius: 4px;
  height: 6px;
  margin-bottom: 32px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s;
}

.hear-btn-wrap { margin: 32px 0; }
.hear-btn {
  width: 180px; height: 180px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--bg);
  font-size: 1.2rem;
  font-weight: 700;
  font-family: var(--font);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 0 0 0 var(--primary-glow);
  position: relative;
}
.hear-btn:hover { transform: scale(1.05); box-shadow: 0 0 40px var(--primary-glow); }
.hear-btn:active { transform: scale(0.95); }
.hear-btn.listening {
  animation: pulse-ring 2s ease-out infinite;
}
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 var(--primary-glow); }
  70% { box-shadow: 0 0 0 30px rgba(0,212,170,0); }
  100% { box-shadow: 0 0 0 0 rgba(0,212,170,0); }
}
.hear-btn-hint { color: var(--muted); font-size: 0.8rem; margin-top: 12px; }

.waiting-text { color: var(--muted); font-size: 0.95rem; min-height: 24px; }

/* ── Sound wave animation during test ── */
.test-wave {
  display: flex; align-items: center; justify-content: center; gap: 3px;
  height: 40px; margin-bottom: 16px;
}
.test-wave .bar {
  width: 3px; border-radius: 2px; background: var(--primary); height: 8px;
  transition: height 0.1s;
}
.test-wave.active .bar { animation: wave 0.8s ease-in-out infinite; }

/* ── Results ── */
#results-screen .result-summary {
  text-align: center;
  padding: 24px 0;
  margin-bottom: 24px;
}
.result-badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 12px;
}
.badge-normal { background: rgba(0,212,170,0.15); color: var(--hl-normal); }
.badge-mild { background: rgba(240,192,64,0.15); color: var(--hl-mild); }
.badge-moderate { background: rgba(240,144,64,0.15); color: var(--hl-moderate); }
.badge-modsevere { background: rgba(224,80,64,0.15); color: var(--hl-modsevere); }
.badge-severe { background: rgba(208,48,48,0.15); color: var(--hl-severe); }
.badge-profound { background: rgba(128,24,24,0.15); color: var(--hl-profound); }

#audiogram-chart { width: 100%; height: 400px; }

.freq-breakdown { margin-top: 16px; }
.freq-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.freq-row:last-child { border-bottom: none; }
.freq-label { font-family: var(--mono); font-weight: 500; min-width: 80px; }
.freq-values { display: flex; gap: 20px; }
.freq-val { font-family: var(--mono); font-size: 0.85rem; }
.freq-val.left { color: #58a6ff; }
.freq-val.right { color: #ff6b6b; }

.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 24px; }

.disclaimer {
  background: rgba(255,107,107,0.08);
  border: 1px solid rgba(255,107,107,0.2);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 24px;
  line-height: 1.6;
}
.disclaimer strong { color: var(--warning); }

/* ── History ── */
#history-chart { width: 100%; height: 350px; }
.history-list { margin-top: 16px; }
.history-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.history-date { font-family: var(--mono); color: var(--muted); }

/* ── Screens ── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Static pages ── */
.static-page h1 { margin-bottom: 24px; }
.static-page h2 { margin-top: 32px; margin-bottom: 12px; }
.static-page p, .static-page li { color: var(--muted); line-height: 1.8; margin-bottom: 12px; }
.static-page ul { padding-left: 24px; }
.static-page a { color: var(--primary); text-decoration: none; }
.static-page a:hover { text-decoration: underline; }

/* ── Headphone warning ── */
.headphone-warning {
  display: flex; align-items: center; gap: 10px;
  background: rgba(240,192,64,0.1);
  border: 1px solid rgba(240,192,64,0.25);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.9rem;
  color: #f0c040;
}

/* ── Age input ── */
.age-input-wrap { margin-bottom: 20px; }
.age-input-wrap label { font-size: 0.9rem; color: var(--muted); margin-right: 10px; }
.age-input-wrap input {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  padding: 8px 12px;
  width: 80px;
  font-size: 0.95rem;
}
.age-input-wrap input:focus { outline: none; border-color: var(--primary); }

/* ── Responsive ── */
@media (max-width: 600px) {
  .hero h1 { font-size: 1.8rem; }
  .hear-btn { width: 150px; height: 150px; font-size: 1rem; }
  .test-info { gap: 16px; }
  .container { padding: 0 16px; }
  .mode-cards { grid-template-columns: 1fr; }
  #audiogram-chart { height: 300px; }
}
