/* Fretboard trainer — dark neumorphism (matches site theme) */

:root {
  --bg: #1a1d23;
  --bg-deep: #14161b;
  --surface: #1e2229;
  --surface2: #232830;
  --surface-raised: #232830;

  --text: #e6e8ec;
  --text-soft: #c4c8d0;
  --muted: #8b919c;

  --accent: #7eb8a8;
  --accent-dim: #5a8f82;
  --accent-glow: rgba(126, 184, 168, 0.18);

  --correct: #3dd68c;
  --wrong: #e85d5d;

  --nut: #d4c4a8;
  --string: #c0c0c8;
  --inlay: #3a3a48;
  --fret-metal: #c8c8c8;

  --border: transparent;

  --neu-dark: rgba(0, 0, 0, 0.45);
  --neu-light: rgba(255, 255, 255, 0.04);
  --neu-out:
    8px 8px 16px var(--neu-dark),
    -6px -6px 14px var(--neu-light);
  --neu-out-sm:
    4px 4px 10px var(--neu-dark),
    -3px -3px 8px var(--neu-light);
  --neu-in:
    inset 5px 5px 12px var(--neu-dark),
    inset -4px -4px 10px var(--neu-light);
  --neu-in-sm:
    inset 3px 3px 8px var(--neu-dark),
    inset -2px -2px 6px var(--neu-light);

  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --font-display: Georgia, "Times New Roman", serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -20%, #252a33 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(90, 143, 130, 0.06) 0%, transparent 50%);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(0.5rem, var(--safe-top)) 0.5rem max(0.5rem, var(--safe-bottom));
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

.fb-title {
  font-size: clamp(1rem, 4vw, 1.4rem);
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: none;
  margin-bottom: 0.35rem;
  flex-shrink: 0;
  text-align: center;
}

.wrap {
  width: 100%;
  max-width: 1100px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  min-height: 0;
}

/* HUD */
.hud {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.hud-card {
  background: var(--surface);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.65rem;
  flex: 1;
  min-width: 0;
  text-align: center;
  box-shadow: var(--neu-out-sm);
}

.hud-card .label {
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.hud-card .value {
  font-size: clamp(1rem, 4vw, 1.35rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hud-card.accent .value { color: var(--accent); }
.hud-card.good .value { color: var(--correct); }
.hud-card.bad .value { color: var(--wrong); }

/* Prompt */
.prompt {
  background: var(--surface);
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  text-align: center;
  flex-shrink: 0;
  box-shadow: var(--neu-out-sm);
}

.prompt .ask {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.prompt .note-name {
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  font-weight: 700;
  color: var(--accent);
  line-height: 1.15;
  min-height: 1.15em;
}

.prompt .feedback {
  font-size: 0.8rem;
  min-height: 1.2em;
  margin-top: 0.15rem;
  transition: color 0.15s;
}

.prompt .feedback.ok { color: var(--correct); }
.prompt .feedback.nope { color: var(--wrong); }

/* Fretboard */
.board-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  flex-shrink: 0;
  scrollbar-width: none;
}

.board-scroll::-webkit-scrollbar { display: none; }

.board {
  --fret-count: 12;
  --cell-w: 56px;
  --row-h: 34px;
  --open-w: 42px;
  display: grid;
  grid-template-columns: var(--open-w) repeat(var(--fret-count), minmax(var(--cell-w), 1fr));
  grid-template-rows: 22px repeat(6, var(--row-h));
  background: linear-gradient(180deg, #2a1f18 0%, #3d2b1f 40%, #2a1f18 100%);
  border: 2px solid #1a1008;
  border-radius: 12px;
  overflow: hidden;
  user-select: none;
  min-width: 100%;
  width: max(100%, calc(var(--open-w) + var(--fret-count) * var(--cell-w)));
  box-shadow:
    inset 0 2px 8px rgba(255, 255, 255, 0.05),
    10px 12px 28px var(--neu-dark),
    -4px -4px 12px var(--neu-light);
}

.fret-num {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  color: var(--muted);
  background: var(--bg-deep);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.fret-num.open-label { border-right: 3px solid var(--nut); }

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
  min-height: var(--row-h);
}

.cell::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1.5px;
  background: var(--string);
  opacity: 0.55;
  pointer-events: none;
  top: 50%;
  transform: translateY(-50%);
}

.cell[data-string="1"]::after { height: 1px; opacity: 0.4; }
.cell[data-string="2"]::after { height: 1.2px; opacity: 0.45; }
.cell[data-string="3"]::after { height: 1.4px; opacity: 0.5; }
.cell[data-string="4"]::after { height: 1.7px; opacity: 0.55; }
.cell[data-string="5"]::after { height: 2px; opacity: 0.6; }
.cell[data-string="6"]::after { height: 2.3px; opacity: 0.65; }

.cell:not(.open)::before {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(90deg, #666, #bbb, #666);
  pointer-events: none;
  z-index: 1;
}

.cell.open {
  border-right: 4px solid var(--nut);
  background: rgba(0, 0, 0, 0.15);
}

.cell .inlay {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--inlay);
  opacity: 0.7;
  pointer-events: none;
  z-index: 0;
}

.cell .inlay.double-top { transform: translateY(-9px); }
.cell .inlay.double-bot { transform: translateY(9px); }

.cell .dot {
  width: clamp(22px, 6vw, 28px);
  height: clamp(22px, 6vw, 28px);
  border-radius: 50%;
  background: var(--accent);
  color: #0c241f;
  font-size: clamp(0.55rem, 2vw, 0.72rem);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45), inset 0 1px 2px rgba(255, 255, 255, 0.2);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.12s, transform 0.12s, background 0.12s;
}

.cell .dot.show { opacity: 1; transform: scale(1); }
.cell .dot.correct { background: var(--correct); color: #062a18; }
.cell .dot.wrong { background: var(--wrong); color: #fff; }
.cell .dot.hint {
  background: var(--accent-dim);
  color: var(--text);
  opacity: 0.9;
  transform: scale(1);
}

.cell:active { background: rgba(126, 184, 168, 0.12); }

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex-shrink: 0;
}

.btn {
  appearance: none;
  border: none;
  background: var(--surface2);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 42px;
  flex: 1 1 auto;
  white-space: nowrap;
  box-shadow: var(--neu-out-sm);
  transition: box-shadow 0.12s ease, transform 0.12s ease, color 0.12s ease;
}

.btn:active {
  transform: scale(0.97);
  box-shadow: var(--neu-in-sm);
}

.btn.primary {
  background: var(--surface-raised);
  background-image: linear-gradient(
    145deg,
    rgba(126, 184, 168, 0.18),
    transparent 55%
  );
  color: var(--accent);
  border: none;
}

.btn.primary:active {
  color: var(--text);
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.opts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  background: var(--surface);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
  align-items: center;
  box-shadow: var(--neu-out-sm);
}

.opts label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  min-height: 36px;
}

.opts input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.opts select {
  background: var(--bg-deep);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 0.35rem 0.4rem;
  font: inherit;
  font-size: 0.78rem;
  min-height: 36px;
  box-shadow: var(--neu-in-sm);
}

.opts .group-title {
  width: 100%;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: -0.15rem;
}

.strings-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  width: 100%;
}

.strings-picker label {
  background: var(--surface2);
  border: none;
  border-radius: 8px;
  padding: 0.25rem 0.45rem;
  min-height: 34px;
  box-shadow: var(--neu-out-sm);
  transition: box-shadow 0.12s ease, color 0.12s ease;
}

.strings-picker label:has(input:checked) {
  box-shadow: var(--neu-in-sm);
}

.strings-picker input:checked + span {
  color: var(--accent);
  font-weight: 700;
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 14, 18, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
  padding-top: max(1rem, var(--safe-top));
  padding-bottom: max(1rem, var(--safe-bottom));
  backdrop-filter: blur(6px);
}

.overlay.hidden { display: none; }

.overlay-card {
  background: var(--surface);
  border: none;
  border-radius: var(--radius);
  padding: 1.25rem 1.1rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: var(--neu-out);
}

.overlay-card h2 {
  font-size: 1.25rem;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 0.4rem;
}

.overlay-card p {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 1rem;
  line-height: 1.45;
}

.overlay-card .btn {
  width: 100%;
  margin-top: 0.35rem;
}

.final-stats {
  text-align: left;
  background: var(--bg-deep);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  box-shadow: var(--neu-in-sm);
}

.final-stats div {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.final-stats div:last-child { border-bottom: none; }

/* Mobile */
@media (max-width: 700px) {
  .board {
    --cell-w: 44px;
    --row-h: 38px;
    --open-w: 36px;
  }

  .cell .inlay { width: 8px; height: 8px; }
  .cell .inlay.double-top { transform: translateY(-11px); }
  .cell .inlay.double-bot { transform: translateY(11px); }
}

@media (max-width: 420px) {
  .board {
    --cell-w: 48px;
    --row-h: 40px;
    --open-w: 34px;
  }

  .fb-title { margin-bottom: 0.2rem; }
  .opts label { font-size: 0.72rem; }
}

@media (max-height: 450px) and (orientation: landscape) {
  .fb-title { display: none; }
  .wrap { gap: 0.3rem; }
  .prompt { padding: 0.3rem 0.5rem; }
  .prompt .ask { display: none; }
  .prompt .note-name { font-size: 1.35rem; }
  .prompt .feedback { font-size: 0.72rem; min-height: 1em; }
  .hud-card { padding: 0.25rem 0.4rem; }
  .hud-card .label { font-size: 0.5rem; }
  .hud-card .value { font-size: 0.95rem; }
  .board {
    --row-h: 28px;
    --cell-w: 40px;
    --open-w: 32px;
    grid-template-rows: 16px repeat(6, var(--row-h));
  }
  .fret-num { font-size: 0.55rem; }
  .btn { min-height: 34px; padding: 0.35rem 0.6rem; font-size: 0.75rem; }
  .opts { padding: 0.3rem 0.5rem; }
  .opts label { min-height: 28px; font-size: 0.7rem; }
}

@media (max-height: 380px) and (orientation: landscape) {
  .opts { display: none; }
  .opts.force-show { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  .cell .dot {
    transition: none;
  }
  .btn:active {
    transform: none;
  }
}
