/* ── 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: grid;
  grid-template-columns: 200px 1fr;
  height: calc(100vh - 56px);
}

.game-sidebar {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border-right: 1px solid var(--db-border, #333);
  background: var(--db-surface, #222);
}

/* ── Chord Preview (Tetris-style) ── */
.chord-preview {
  text-align: center;
  padding: 0.5rem;
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
}

.chord-preview--current {
  border: 2px solid var(--db-accent, #c2956b);
  box-shadow: 0 0 12px rgba(194, 149, 107, 0.2);
}

.chord-preview--next {
  opacity: 0.7;
  border: 1px dashed var(--db-border, #444);
}

.chord-preview--player {
  border: 2px solid var(--db-border, #444);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chord-preview--match {
  border-color: #7dcea0 !important;
  box-shadow: 0 0 16px rgba(125, 206, 160, 0.4) !important;
}

.chord-preview--mismatch {
  border-color: #ce7d7d;
  box-shadow: 0 0 12px rgba(206, 125, 125, 0.3);
}

.chord-preview__name {
  font-family: Fraunces, serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--db-accent, #c2956b);
  line-height: 1.1;
  margin: 0.25rem 0;
}

.chord-preview__name--sm {
  font-size: 1.3rem;
}

.chord-preview__notes {
  display: flex;
  gap: 4px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

.chord-preview__notes--sm {
  margin-top: 0.25rem;
}

.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; }

.score-cluster {
  display: flex;
  flex-direction: row;
  gap: 1rem;
  align-items: center;
}

.db-stat--inline {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
}

.db-stat--inline .db-stat__label {
  font-size: 0.6rem;
  text-transform: uppercase;
  opacity: 0.6;
}

.db-stat--inline .db-stat__value {
  font-size: 1rem;
  font-weight: 700;
}

/* ── 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;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: auto;
}

.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); }

/* ── 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: 50;
  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.04;
  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-floater {
  position: absolute;
  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: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-60px) scale(1.3); }
}

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

@keyframes scorePop {
  0% { opacity: 1; transform: translateY(0) scale(0.8); }
  50% { transform: translateY(-20px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-40px) scale(0.9); }
}
