:root {
  --bg1: #15171c;
  --bg2: #222733;
  --wood-a: #8b5a2b;
  --wood-b: #6e431f;
  --wood-c: #9f6b36;
  --fret-metal: linear-gradient(180deg, #d7dbe1 0%, #9ea5ae 45%, #eef1f4 100%);
  --nut: linear-gradient(180deg, #f1e4c9 0%, #d3c2a3 100%);
  --text: #eef2f7;
  --muted: #b9c0ca;
  --accent: #62d0ff;
  --accent-2: #ffd45f;
  --success: #31d07f;
  --danger: #ff6b7a;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
  --label-col: 70px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.08), transparent 35%),
    linear-gradient(160deg, var(--bg2), var(--bg1));
}

.app {
  width: min(96vw, 1320px);
  display: grid;
  gap: 18px;
  padding: 24px;
}

.titlebar {
  text-align: center;
}

.titlebar h1 {
  margin: 0;
  font-size: clamp(1.4rem, 2vw, 2rem);
  letter-spacing: 0.04em;
  font-weight: 700;
}

.titlebar p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.board-wrap {
  position: relative;
  border-radius: 22px;
  padding: 26px 22px 20px;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.03));
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.layout {
  display: grid;
  grid-template-columns: var(--label-col) 1fr;
  align-items: stretch;
  gap: 8px;
}

.string-labels {
  position: relative;
  min-height: 0;
}

.string-label {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--text);
  background: linear-gradient(180deg, rgba(255,255,255,0.15), rgba(255,255,255,0.06));
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 6px 12px rgba(0,0,0,0.18);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.string-label.active-target {
  border-color: rgba(255, 235, 160, 0.95);
  background: radial-gradient(circle at 30% 30%, #fff4a8 0%, #ffd45f 45%, #ff8a00 100%);
  color: #231400;
  transform: translate(-50%, -50%) scale(1.06);
  box-shadow:
    0 0 0 4px rgba(255, 212, 95, 0.22),
    0 0 18px rgba(255, 196, 0, 0.8),
    inset 0 1px 3px rgba(255,255,255,0.75);
  animation: pulseLabel 1.3s ease-in-out infinite;
}

.fretboard-area {
  display: grid;
  grid-template-rows: minmax(132px, 23vh) auto;
  gap: 8px;
  min-width: 0;
}

.fretboard {
  position: relative;
  min-width: 0;
  border-radius: 0;
  overflow: visible;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.1), transparent 10%, transparent 90%, rgba(0,0,0,0.16)),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.045), rgba(255,255,255,0.045) 2px, rgba(0,0,0,0.03) 2px, rgba(0,0,0,0.03) 6px),
    linear-gradient(180deg, var(--wood-c), var(--wood-a) 38%, var(--wood-b));
  box-shadow:
    inset 0 2px 10px rgba(255,255,255,0.08),
    inset 0 -10px 18px rgba(0,0,0,0.18),
    0 18px 26px rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.08);
}

.fretboard::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.06), transparent 18%, transparent 82%, rgba(0,0,0,0.08));
  pointer-events: none;
}

.nut {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: clamp(12px, 1.6vw, 18px);
  transform: translateX(calc(-100% - 2px));
  background: var(--nut);
  border-radius: 4px 0 0 4px;
  box-shadow:
    inset -2px 0 4px rgba(0,0,0,0.18),
    2px 0 8px rgba(255,255,255,0.12),
    6px 0 14px rgba(0,0,0,0.22);
  z-index: 7;
  pointer-events: none;
}

.frets,
.markers,
.strings,
.targets {
  position: absolute;
  inset: 0;
}

.fret {
  position: absolute;
  top: 0;
  bottom: 0;
  width: clamp(4px, 0.55vw, 7px);
  background: var(--fret-metal);
  transform: translateX(-50%);
  box-shadow:
    inset 0 0 1px rgba(255,255,255,0.9),
    0 0 0 1px rgba(90,98,110,0.35),
    1px 0 4px rgba(0,0,0,0.24);
  z-index: 3;
}

.marker {
  position: absolute;
  width: clamp(14px, 1.5vw, 20px);
  height: clamp(14px, 1.5vw, 20px);
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff7dd, #d9c7a2 60%, #a69270 100%);
  box-shadow:
    inset 0 1px 2px rgba(255,255,255,0.5),
    0 4px 10px rgba(0,0,0,0.22);
  opacity: 0.95;
  z-index: 2;
  transform: translate(-50%, -50%);
}

.string {
  position: absolute;
  left: 0;
  right: 0;
  border-radius: 999px;
  transform: translateY(-50%);
  z-index: 5;
  background: linear-gradient(180deg, #f8fafc, #b5bcc6 50%, #7f8792);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.6),
    0 0 6px rgba(0,0,0,0.2);
}

.target {
  position: absolute;
  width: clamp(22px, 2.1vw, 30px);
  height: clamp(22px, 2.1vw, 30px);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  border: 3px solid rgba(255,255,255,0.95);
  background: radial-gradient(circle at 30% 30%, #fff4a8 0%, #ffd45f 45%, #ff8a00 100%);
  box-shadow:
    0 0 0 4px rgba(255, 212, 95, 0.22),
    0 0 18px rgba(255, 196, 0, 0.8),
    inset 0 1px 3px rgba(255,255,255,0.75);
  animation: pulse 1.3s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(255, 212, 95, 0.18), 0 0 18px rgba(255, 196, 0, 0.7), inset 0 1px 3px rgba(255,255,255,0.75); }
  50% { box-shadow: 0 0 0 9px rgba(255, 212, 95, 0.10), 0 0 28px rgba(255, 196, 0, 0.95), inset 0 1px 3px rgba(255,255,255,0.75); }
}

@keyframes pulseLabel {
  0%, 100% { box-shadow: 0 0 0 4px rgba(255, 212, 95, 0.18), 0 0 18px rgba(255, 196, 0, 0.7), inset 0 1px 3px rgba(255,255,255,0.75); }
  50% { box-shadow: 0 0 0 9px rgba(255, 212, 95, 0.10), 0 0 28px rgba(255, 196, 0, 0.95), inset 0 1px 3px rgba(255,255,255,0.75); }
}

.bottom-labels {
  display: grid;
  grid-template-columns: var(--label-col) 1fr;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: clamp(0.75rem, 1vw, 0.95rem);
  user-select: none;
}

.open-label {
  text-align: center;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #e7dbc4;
}

.fret-labels-area {
  position: relative;
  height: 22px;
  min-width: 0;
}

.fret-number {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.controls {
  margin-top: 18px;
  display: grid;
  gap: 16px;
}

.control-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: stretch;
}

.control-buttons {
  display: grid;
  gap: 10px;
  align-content: start;
}

.start-btn {
  border: 0;
  border-radius: 14px;
  padding: 14px 22px;
  min-width: 140px;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: #08131a;
  background: linear-gradient(180deg, #7ae0ff, #3ab8ea);
  box-shadow: 0 10px 20px rgba(0,0,0,0.22), inset 0 1px 0 rgba(255,255,255,0.5);
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.16s ease;
}

.start-btn.stop-mode {
  background: linear-gradient(180deg, #ff9fa8, #f06b78);
  color: #21080c;
}

.mic-btn {
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 14px;
  padding: 12px 18px;
  min-width: 140px;
  font-size: 0.96rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text);
  background: linear-gradient(180deg, rgba(255,255,255,0.14), rgba(255,255,255,0.06));
  box-shadow: 0 10px 20px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.12);
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.mic-btn.active {
  border-color: rgba(98, 208, 255, 0.75);
  background: linear-gradient(180deg, rgba(98,208,255,0.32), rgba(58,184,234,0.18));
  color: #f4fcff;
}

.mic-btn.unsupported {
  opacity: 0.45;
  cursor: not-allowed;
}

.start-btn:hover,
.note-btn:hover,
.mic-btn:hover {
  filter: brightness(1.04);
}

.start-btn:active,
.note-btn:active,
.mic-btn:active {
  transform: translateY(1px) scale(0.995);
}

.start-btn:focus-visible,
.note-btn:focus-visible,
.mic-btn:focus-visible {
  outline: 3px solid rgba(255,255,255,0.85);
  outline-offset: 2px;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.score-card,
.status-panel {
  background: linear-gradient(180deg, rgba(255,255,255,0.09), rgba(255,255,255,0.04));
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
}

.score-card .label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.score-card .value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
}

.status-panel {
  min-height: 68px;
  display: grid;
  align-content: center;
  gap: 6px;
}

.status-line {
  font-weight: 700;
  font-size: 1rem;
}

.status-line.success { color: var(--success); }
.status-line.error { color: var(--danger); }
.status-line.info { color: var(--accent-2); }

.status-subtext {
  color: var(--muted);
  font-size: 0.95rem;
}

.voice-status.listening {
  color: var(--accent);
}

.voice-status.error {
  color: var(--danger);
}

.voice-status.success {
  color: var(--success);
}

.prompt {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  padding: 0 2px;
  color: var(--text);
  font-size: 0.98rem;
}

.prompt strong { color: #fff6cf; }

.note-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 10px;
}

.note-btn {
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 12px 8px;
  color: var(--text);
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.05));
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, opacity 0.16s ease;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 8px 14px rgba(0,0,0,0.12);
}

.note-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.note-btn.correct-choice {
  background: linear-gradient(180deg, rgba(49,208,127,0.35), rgba(49,208,127,0.18));
  border-color: rgba(49,208,127,0.7);
  color: #eafff3;
}

.note-btn.wrong-choice {
  background: linear-gradient(180deg, rgba(255,107,122,0.35), rgba(255,107,122,0.16));
  border-color: rgba(255,107,122,0.75);
  color: #fff0f2;
}

.note-btn.reveal-answer {
  background: linear-gradient(180deg, rgba(255,212,95,0.34), rgba(255,212,95,0.15));
  border-color: rgba(255,212,95,0.7);
  color: #fff8df;
}

.fallback {
  display: none;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 120, 120, 0.12);
  border: 1px solid rgba(255, 120, 120, 0.25);
  color: #ffd7d7;
  font-size: 0.95rem;
}

@media (max-width: 1020px) {
  .note-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  :root { --label-col: 48px; }
  .app { padding: 14px; }
  .board-wrap { padding: 18px 12px 18px; }
  .layout,
  .bottom-labels {
    gap: 8px;
  }
  .string-label {
    width: 30px;
    height: 30px;
    font-size: 0.85rem;
  }
  .fretboard-area {
    grid-template-rows: minmax(120px, 22vh) auto;
  }
  .titlebar p { font-size: 0.9rem; }
  .control-row {
    grid-template-columns: 1fr;
  }
  .control-buttons {
    grid-template-columns: 1fr 1fr;
  }
  .scoreboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .note-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 460px) {
  .scoreboard,
  .note-grid,
  .control-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
