:root {
  --bg: #14100e;
  --bg-panel: #1e1815;
  --bg-panel-raised: #241d19;
  --border: #352b24;
  --text: #f4ede4;
  --text-dim: #b9ab9c;
  --accent: #6c5ce7;
  --accent-strong: #9b8bf9;
  --accent-hover: #5949d1;
  --finger-a: #9b8bf9;
  --finger-b: #4fc3d9;
  --good: #5ec98a;
  --bad: #e05d5d;
  --radius: 14px;
  --max-width: 720px;
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must always win over any `display` set by a
   component's own class (several panels below use display:flex once
   shown), otherwise a "hidden" panel can still render. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding-bottom: 2rem;
}

main {
  width: 100%;
  max-width: var(--max-width);
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ad-slot {
  width: 100%;
  max-width: var(--max-width);
  min-height: 60px;
  margin: 0.75rem auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.site-header {
  text-align: center;
  padding: 1.75rem 1rem 0.5rem;
}

.site-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.95rem;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
}

/* difficulty */

.difficulty-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.difficulty-tab {
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-dim);
  padding: 0.6rem 0.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.difficulty-tab small {
  font-weight: 400;
  font-size: 0.72rem;
  color: inherit;
  opacity: 0.8;
}

.difficulty-tab[aria-selected="true"] {
  border-color: var(--accent);
  color: var(--text);
  background: #2c2018;
}

.difficulty-explainer {
  margin: 0.75rem 0 0;
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
}

/* best score */

.best-score {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.best-score-label {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.best-score-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent-strong);
}

/* record panel */

.record-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}

.record-button {
  width: 100%;
  max-width: 320px;
  padding: 0.9rem 1.5rem;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #f4ede4;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: transform 0.1s ease, background 0.15s ease;
}

.record-button:hover {
  background: var(--accent-hover);
}

.record-button:active {
  transform: scale(0.98);
}

.record-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.record-button-icon {
  color: var(--bad);
}

.status-area {
  min-height: 1.4rem;
}

.status-hint {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.status-hint--error {
  color: var(--bad);
}

.countdown-display {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent-strong);
}

.recording-progress {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.recording-progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--bg-panel-raised);
  overflow: hidden;
  border: 1px solid var(--border);
}

.recording-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--finger-a), var(--bad));
  transition: width 0.2s linear;
}

#recording-time-label {
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* playback */

.playback-panel audio {
  width: 100%;
}

/* waveform */

.waveform-panel {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#waveform-canvas {
  width: 100%;
  height: auto;
  display: block;
  background: var(--bg-panel-raised);
  border-radius: 10px;
}

.waveform-legend {
  display: flex;
  gap: 1.25rem;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend-swatch--a {
  background: var(--finger-a);
}

.legend-swatch--b {
  background: var(--finger-b);
}

/* results */

.results-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}

.overall-score {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
}

.overall-score-value {
  font-size: 3.2rem;
  font-weight: 800;
  color: var(--accent-strong);
}

.overall-score-max {
  font-size: 1.2rem;
  color: var(--text-dim);
}

.results-comparison {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-dim);
}

.results-comparison--best {
  color: var(--good);
  font-weight: 600;
}

.metric-breakdown {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.metric-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
}

.metric-row-label {
  width: 90px;
  text-align: left;
  color: var(--text-dim);
  flex-shrink: 0;
}

.metric-row-bar {
  display: block;
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--bg-panel-raised);
  overflow: hidden;
  border: 1px solid var(--border);
}

.metric-row-fill {
  display: block;
  height: 100%;
  background: var(--accent);
}

.metric-row-value {
  width: 34px;
  text-align: right;
  color: var(--text-dim);
  flex-shrink: 0;
}

.retry-button {
  margin-top: 0.25rem;
  padding: 0.55rem 1.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}

.retry-button:hover {
  border-color: var(--accent);
}

/* footer */

.site-footer {
  color: var(--text-dim);
  font-size: 0.75rem;
  text-align: center;
  padding: 1rem;
}

/* reward overlay */

.reward-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

#confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.reward-message {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 2rem;
}

.reward-title {
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  color: var(--accent-strong);
  text-shadow: 0 0 24px rgba(139, 124, 246, 0.6);
}

.reward-subtitle {
  margin-top: 0.5rem;
  color: var(--text);
  font-size: 1rem;
}

.reward-close-button {
  margin-top: 1.5rem;
  padding: 0.6rem 1.6rem;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #f4ede4;
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 480px) {
  .overall-score-value {
    font-size: 2.6rem;
  }
  .reward-title {
    font-size: 1.8rem;
  }
}
