/* ── Lo-Fi Chords Defence ── */

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

body {
  min-height: 100vh;
  overflow: hidden;
  background: var(--db-bg, #1a1a1a);
  color: var(--db-text, #e0e0e0);
}

/* ── Layout ── */
.game-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 40px);
}

/* ── Chord Overlays (on canvas) ── */
.chord-overlay {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 5;
  text-align: center;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.chord-overlay.visible { display: flex; }

.chord-overlay__name {
  font-family: Fraunces, serif;
  font-weight: 700;
}

.chord-overlay__notes {
  display: flex;
  gap: 4px;
  justify-content: center;
  flex-wrap: wrap;
}

.chord-overlay__alt {
  font-size: 0.7rem;
  opacity: 0.6;
}

/* ── Chord Sequence Strip ── */
.chord-sequence {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 10px;
  z-index: 5;
  pointer-events: none;
}

.chord-sequence.visible { display: flex; }

.chord-seq__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
}

.chord-seq__name {
  font-family: Fraunces, serif;
  font-weight: 700;
}

.chord-seq__notes {
  display: flex;
  gap: 4px;
  justify-content: center;
  flex-wrap: wrap;
}

.chord-seq__item--current .chord-seq__name {
  font-size: 2rem;
  color: var(--db-accent, #c2956b);
  text-shadow: 0 0 20px rgba(194,149,107,0.4);
}

.chord-seq__item--next .chord-seq__name {
  font-size: 1.4rem;
  color: var(--db-text-muted, #888);
}

.chord-seq__item--next { opacity: 0.8; }

.chord-seq__item--after .chord-seq__name {
  font-size: 1.1rem;
  color: var(--db-text-muted, #888);
}

.chord-seq__item--after { opacity: 0.5; }

.chord-seq__sep {
  font-size: 1.2rem;
  color: var(--db-text-muted, #555);
  align-self: center;
  line-height: 1;
}

.chord-seq__item--current.chord-preview--match .chord-seq__name {
  color: #7dcea0;
  text-shadow: 0 0 20px rgba(125,206,160,0.5);
}

.chord-overlay--player { bottom: 40px; }
.chord-overlay--player .chord-overlay__name { font-size: 1.2rem; color: var(--db-text, #e0e0e0); }

.chord-overlay--player.chord-preview--match .chord-overlay__name { color: #7dcea0; text-shadow: 0 0 16px rgba(125,206,160,0.5); }
.chord-overlay--player.chord-preview--mismatch .chord-overlay__name { color: #ce7d7d; }

.chord-note-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
}

.chord-note-chip--sm {
  width: 22px;
  height: 22px;
  font-size: 0.6rem;
  border-radius: 4px;
}

.chord-note-chip--root { background: #c2956b; }
.chord-note-chip--third { background: #7dcea0; }
.chord-note-chip--fifth { background: #7db5ce; }
.chord-note-chip--seventh { background: #ceb57d; }
.chord-note-chip--extension { background: #b57dce; }

/* ── Navbar ── */
.game-nav { min-height: 40px; padding: 0 12px; gap: 10px; }
.nav-brand { font-size: 1rem; font-weight: 600; opacity: 0.9; white-space: nowrap; font-family: Fraunces, serif; display: flex; align-items: center; gap: 6px; }
.nav-icon { width: 20px; height: 20px; border-radius: 4px; }

.nav-score {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: Cabin, system-ui, sans-serif;
}

.nav-val { font-size: 1.1rem; font-weight: 700; }
.nav-val--dim { font-size: 0.85rem; opacity: 0.6; }
.nav-sep { opacity: 0.25; font-size: 0.8rem; }

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-midi {
  font-size: 0.65rem;
  opacity: 0.4;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-help {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.05);
  color: var(--db-text-muted, #888);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
  flex-shrink: 0;
}
.nav-help:hover { opacity: 1; background: rgba(255,255,255,0.1); }

/* ── Life Bar (horizontal, top of game area) ── */
.life-bar-wrap {
  height: 4px;
  background: rgba(255,255,255,0.05);
  flex-shrink: 0;
}

.life-bar {
  height: 100%;
  width: 100%;
  background: #7dcea0;
  transition: width 0.15s ease-out, background-color 0.3s;
  box-shadow: 0 0 8px rgba(125, 206, 160, 0.4);
}

.game-main {
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* ── Canvas ── */
.canvas-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.hit-line {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--db-accent, #c2956b);
  box-shadow: 0 0 12px var(--db-accent, #c2956b), 0 0 24px var(--db-accent, #c2956b);
  z-index: 2;
  pointer-events: none;
}

/* ── Melody Guide ── */
.melody-guide {
  display: flex;
  height: 32px;
  border-top: 1px solid var(--db-border, #333);
  border-bottom: 1px solid var(--db-border, #333);
}

.melody-cell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  transition: background 0.2s, color 0.2s;
  border-right: 1px solid var(--db-border, #333);
  background: var(--db-surface, #222);
  color: var(--db-text-muted, #888);
}

.melody-cell:last-child { border-right: none; }

.melody-cell--chord-tone {
  background: #2d5a3d;
  color: #7dcea0;
}

.melody-cell--tension {
  background: #2d3f5a;
  color: #7db5ce;
}

.melody-cell--avoid {
  background: #5a2d2d;
  color: #ce7d7d;
}

.melody-cell--passing {
  background: var(--db-surface, #222);
  color: var(--db-text-muted, #666);
}

/* ── Piano ── */
.piano {
  position: relative;
  display: flex;
  height: 80px;
  background: var(--db-surface, #222);
  border-top: 1px solid var(--db-border, #333);
  user-select: none;
}

.piano-key {
  position: relative;
  flex: 1;
  border: 1px solid var(--db-border, #333);
  border-top: none;
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4px;
  font-size: 0.55rem;
  color: var(--db-text-muted, #666);
}

.piano-key--white {
  background: #f0ece4;
  color: #666;
  z-index: 1;
}

.piano-key--black {
  position: absolute;
  width: 60%;
  height: 55%;
  background: #2a2a2a;
  color: #888;
  border-radius: 0 0 3px 3px;
  z-index: 2;
  border: 1px solid #111;
  font-size: 0;
}

.piano-key--white.active {
  background: var(--db-accent, #c2956b);
  color: #fff;
}

.piano-key--black.active {
  background: var(--db-accent, #c2956b);
  box-shadow: 0 0 8px var(--db-accent, #c2956b);
}

/* Target keys — subtle small dot at bottom */
.piano-key--white.piano-key--target {
  border-bottom: 3px solid rgba(125, 206, 160, 0.4);
}

.piano-key--black.piano-key--target {
  border-bottom: 3px solid rgba(125, 206, 160, 0.35);
}

/* Correct — target key that's being held */
.piano-key--white.piano-key--correct {
  border-bottom: 3px solid #7dcea0;
  box-shadow: inset 0 -4px 8px rgba(125, 206, 160, 0.2);
}

.piano-key--black.piano-key--correct {
  border-bottom: 3px solid #7dcea0;
  box-shadow: inset 0 -4px 8px rgba(125, 206, 160, 0.25);
}

/* ── Sound Picker ── */
.sound-picker {
  display: flex;
  gap: 4px;
  align-items: center;
}

.sound-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid rgba(255,255,255,0.15);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: rgba(255,255,255,0.05);
}

.sound-btn:hover { transform: scale(1.1); background: rgba(255,255,255,0.1); }
.sound-btn.active { border-color: var(--db-accent, #c2956b); background: rgba(194, 149, 107, 0.2); }

/* ── Start modal compact ── */
.start-modal-body { display: flex; flex-direction: column; gap: 0.5rem; }
.start-modal-controls { font-size: 0.8rem; opacity: 0.7; }

/* ── Modal display fallback ── */
.db-modal-overlay[aria-hidden="false"] {
  display: flex !important;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 500;
  visibility: visible !important;
  opacity: 1 !important;
}

.db-modal-overlay[aria-hidden="true"] {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

/* ── Pause Overlay ── */
.pause-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 100;
}

/* ── Lo-fi grain texture ── */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* ── Feedback floaters ── */
/* ── Feedback: main label center ── */
.feedback-floater {
  position: absolute;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  font-weight: 700;
  font-size: 1.2rem;
  pointer-events: none;
  z-index: 10;
  animation: floatUp 0.8s ease-out forwards;
}
.feedback-floater--perfect { color: #7dcea0; }
.feedback-floater--good { color: #7db5ce; }
.feedback-floater--ok { color: #ceb57d; }
.feedback-floater--miss { color: #ce7d7d; }

@keyframes floatUp {
  0% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-60px) scale(1.3); }
}

/* ── Timing hints: left side ── */
.timing-hint {
  position: absolute;
  left: 12px;
  bottom: 40px;
  font-size: 0.75rem;
  font-weight: 600;
  pointer-events: none;
  z-index: 10;
  opacity: 0.8;
  animation: floatUpSide 0.8s ease-out forwards;
}
.timing-hint--ontime { color: #7dcea0; }
.timing-hint--early { color: #ceb57d; }
.timing-hint--late { color: #ce7d7d; }

/* ── Score pop: right side ── */
.score-pop {
  position: absolute;
  right: 12px;
  bottom: 40px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--db-accent, #c2956b);
  pointer-events: none;
  z-index: 10;
  animation: floatUpSide 0.6s ease-out forwards;
}

@keyframes floatUpSide {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-40px); }
}

/* ── Settings Drawer ── */
.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  background: var(--db-surface, #1e1e1e);
  border-left: 1px solid var(--db-border, #333);
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-shadow: -4px 0 20px rgba(0,0,0,0.4);
}

.settings-drawer[aria-hidden="false"] {
  transform: translateX(0);
}

.settings-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--db-border, #333);
}

.settings-drawer__header h2 {
  font-size: 1rem;
  font-weight: 700;
  font-family: Fraunces, serif;
  margin: 0;
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 16px;
}

.setting-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.setting-group label {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.setting-group select,
.setting-group input[type="range"] {
  flex: 1;
  min-width: 0;
  max-width: 140px;
}

.setting-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(45, 90, 61, 0.9);
  color: #7dcea0;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid rgba(125, 206, 160, 0.3);
  backdrop-filter: blur(8px);
  animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in 2.7s forwards;
  pointer-events: auto;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-10px); }
}

.start-midi-alert {
  font-size: 0.8rem;
  padding: 8px 12px;
  text-align: left;
}
.kb-map {
  font-family: monospace;
  font-size: 0.7rem;
  line-height: 1.4;
  margin: 6px 0 4px;
  padding: 0;
  opacity: 0.85;
}

/* ── Mobile ── */
@media (max-width: 600px) {
  .game-nav { padding: 2px 8px; min-height: 36px; }
  .game-layout { height: calc(100vh - 36px); }
  .piano { height: 100px; }
  .melody-guide { height: 24px; }
  .chord-seq__item--current .chord-seq__name { font-size: 1.5rem; }
  .chord-seq__item--next .chord-seq__name { font-size: 1.1rem; }
  .chord-seq__item--after { display: none; }
  .chord-seq__item--after + .chord-seq__sep { display: none; }
  .sound-btn { width: 22px; height: 22px; font-size: 11px; }
  .nav-midi { display: none; }
}

/* ── Mastery chips ── */
.mastery-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
/* ── Mastery Visualizer ── */
.mastery-viz {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  width: 100%;
}

.mastery-stage {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  color: var(--db-text-muted, #555);
  line-height: 1.4;
}

.mastery-stage--past {
  background: rgba(125, 206, 160, 0.1);
  color: rgba(125, 206, 160, 0.45);
  border-color: rgba(125, 206, 160, 0.15);
}

.mastery-stage--current {
  background: rgba(125, 206, 160, 0.22);
  color: #7dcea0;
  border-color: rgba(125, 206, 160, 0.45);
}

/* ── Mastery Picker (start modal) ── */
.mastery-picker {
  display: flex;
  gap: 6px;
  width: 100%;
}

.mastery-pick {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 8px 4px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: var(--db-text-muted, #888);
  cursor: pointer;
  transition: all 0.2s;
}

.mastery-pick:hover {
  border-color: rgba(194, 149, 107, 0.4);
  background: rgba(194, 149, 107, 0.08);
}

.mastery-pick.active {
  border-color: var(--db-accent, #c2956b);
  background: rgba(194, 149, 107, 0.15);
  color: var(--db-text, #e0e0e0);
}

.mastery-pick__icon {
  font-size: 1.4rem;
  font-weight: 800;
  font-family: Fraunces, serif;
  line-height: 1;
  color: var(--db-accent, #c2956b);
}

.mastery-pick__label {
  font-size: 0.75rem;
  font-weight: 700;
}

.mastery-pick__desc {
  font-size: 0.6rem;
  opacity: 0.5;
}

.mastery-viz--sm {
  max-height: 120px;
  overflow-y: auto;
  font-size: 0.85em;
}

.setting-group--full {
  flex-direction: column;
  align-items: flex-start;
}

/* ── Start Modal Footer ── */
.start-modal-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ── Modal Credit ── */
.modal-credit {
  width: 100%;
  text-align: center;
  font-size: 0.65rem;
  color: var(--db-text-muted, #555);
  padding: 0;
}

.modal-credit a {
  color: var(--db-text-muted, #777);
  text-decoration: none;
}

.modal-credit a:hover {
  color: var(--db-accent, #c2956b);
}

.modal-credit .easter-egg {
  display: inline-block;
  transition: transform 0.15s;
  cursor: pointer;
}

.modal-credit .easter-egg:hover {
  transform: scale(1.25);
}

.mastery-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(125, 206, 160, 0.15);
  color: #7dcea0;
  border: 1px solid rgba(125, 206, 160, 0.3);
}

/* ── Game Over Modal (compact) ── */
.gameover-modal { max-width: 380px; }

.gameover-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 16px !important;
}

.gameover-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
}

.gameover-score__val {
  font-family: Fraunces, serif;
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--db-accent, #c2956b);
}

.gameover-score__hi {
  font-size: 0.8rem;
  color: var(--db-text-muted, #888);
}

.gameover-stats {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.gameover-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.gameover-stat__label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--db-text-muted, #888);
}

.gameover-stat__val {
  font-size: 1.2rem;
  font-weight: 700;
}

.gameover-mastery {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gameover-mastery__label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--db-text-muted, #888);
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .feedback-floater, .timing-hint, .score-pop, .toast { animation: none; }
}
