/* ═══════════════════════════════════════════════════════════════
   QUBIT QUEST — Design System
   A quantum-themed dark UI with neon accents
   ═══════════════════════════════════════════════════════════════ */

/* ── Design Tokens ─────────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg-deep:        #060a1a;
  --bg-space:       #0a0e27;
  --bg-surface:     #111633;
  --bg-elevated:    #1a2040;
  --bg-card:        #141838;

  /* Primary palette */
  --cyan:           #00d4ff;
  --cyan-glow:      rgba(0, 212, 255, 0.25);
  --cyan-dim:       #0099bb;
  --magenta:        #ff006e;
  --magenta-glow:   rgba(255, 0, 110, 0.25);
  --purple:         #7b2ff7;
  --purple-glow:    rgba(123, 47, 247, 0.25);

  /* Semantic */
  --success:        #00ff88;
  --success-glow:   rgba(0, 255, 136, 0.2);
  --warning:        #ffaa00;
  --danger:         #ff4466;
  --info:           #00b4d8;

  /* Gate colors */
  --gate-x:         #ff6b6b;
  --gate-h:         #4ecdc4;
  --gate-z:         #45b7d1;
  --gate-y:         #f7b731;
  --gate-s:         #a55eea;
  --gate-t:         #fd9644;
  --gate-cnot:      #fc5c65;
  --gate-swap:      #26de81;

  /* Text */
  --text-primary:   #e8eaf6;
  --text-secondary: #9ba4c8;
  --text-muted:     #5d6494;
  --text-bright:    #ffffff;

  /* Wire */
  --wire-color:     #2a3060;
  --wire-active:    #00d4ff;

  /* Misc */
  --border-subtle:  rgba(255,255,255,0.06);
  --border-glow:    rgba(0,212,255,0.3);
  --radius-sm:      6px;
  --radius-md:      10px;
  --radius-lg:      16px;
  --radius-xl:      24px;

  /* Fonts */
  --font-display:   'Orbitron', sans-serif;
  --font-body:      'Inter', system-ui, sans-serif;
  --font-mono:      'JetBrains Mono', monospace;

  /* Transitions */
  --ease-out:       cubic-bezier(0.16, 1, 0.3, 1);
  --ease-bounce:    cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Reset & Globals ───────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

/* Animated space background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(123,47,247,0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(0,212,255,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(255,0,110,0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* Stars */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 15%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 25% 35%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1.5px 1.5px at 40% 70%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 55% 25%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 70% 55%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.5px 1.5px at 85% 80%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 15% 85%, rgba(255,255,255,0.2), transparent),
    radial-gradient(1px 1px at 60% 10%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 90% 40%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 33% 52%, rgba(255,255,255,0.25), transparent),
    radial-gradient(1px 1px at 78% 68%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 5% 45%, rgba(255,255,255,0.35), transparent);
  pointer-events: none;
  z-index: 0;
  animation: twinkle 8s ease-in-out infinite alternate;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ── Layout ────────────────────────────────────────────────────── */
.game-container {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 20px;
  min-height: 100vh;
}

/* ── Header ────────────────────────────────────────────────────── */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 20px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 20px;
}

.game-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.game-logo h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.game-logo .logo-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  box-shadow: 0 0 20px var(--cyan-glow);
}

.header-stats {
  display: flex;
  gap: 20px;
  align-items: center;
}

.stat-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding: 6px 14px;
  background: var(--bg-surface);
  border-radius: 20px;
  border: 1px solid var(--border-subtle);
}

.stat-badge .stat-value {
  color: var(--cyan);
  font-weight: 600;
}

/* ── Screen System ─────────────────────────────────────────────── */
.screen {
  display: none;
  animation: fadeIn 0.4s var(--ease-out);
}

.screen.active {
  display: block;
}

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

/* ── Level Select Screen ───────────────────────────────────────── */
.level-select-hero {
  text-align: center;
  padding: 40px 0 30px;
}

.level-select-hero h2 {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--cyan), var(--magenta));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.level-select-hero p {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 500px;
  margin: 0 auto;
}

.worlds-grid {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding-bottom: 40px;
}

.world-section {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  padding: 24px;
  transition: border-color 0.3s;
}

.world-section:hover {
  border-color: var(--border-glow);
}

.world-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.world-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.world-header h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.world-header .world-desc {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.levels-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.level-btn {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 2px solid var(--border-subtle);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: var(--font-display);
  color: var(--text-secondary);
  transition: all 0.25s var(--ease-out);
  position: relative;
  overflow: hidden;
}

.level-btn:hover {
  border-color: var(--cyan);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px var(--cyan-glow);
  color: var(--text-bright);
}

.level-btn .level-num {
  font-size: 1.3rem;
  font-weight: 700;
}

.level-btn .level-stars {
  font-size: 0.6rem;
  letter-spacing: 1px;
}

.level-btn.completed {
  border-color: var(--success);
  background: rgba(0, 255, 136, 0.08);
}

.level-btn.completed .level-num {
  color: var(--success);
}

.level-btn.locked {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Game Screen Layout ────────────────────────────────────────── */
.game-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  grid-template-rows: auto auto auto;
  gap: 16px;
}

.game-top-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.level-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.level-title h3 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 1px;
}

.level-title .level-tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--cyan-glow);
  color: var(--cyan);
  border: 1px solid rgba(0,212,255,0.3);
}

.top-bar-actions {
  display: flex;
  gap: 8px;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.btn:hover {
  border-color: var(--cyan);
  color: var(--text-bright);
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--cyan-dim));
  color: var(--bg-deep);
  border-color: var(--cyan);
  font-weight: 700;
}

.btn-primary:hover {
  box-shadow: 0 4px 20px var(--cyan-glow);
  color: var(--bg-deep);
}

.btn-success {
  background: linear-gradient(135deg, var(--success), #00cc6a);
  color: var(--bg-deep);
  border-color: var(--success);
  font-weight: 700;
}

.btn-danger {
  background: rgba(255,68,102,0.15);
  color: var(--danger);
  border-color: rgba(255,68,102,0.3);
}

.btn-danger:hover {
  background: rgba(255,68,102,0.25);
  border-color: var(--danger);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

/* ── Circuit Board ─────────────────────────────────────────────── */
.circuit-panel {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.circuit-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--purple), var(--magenta));
}

.circuit-label {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 16px;
}

.circuit-board {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 12px 0;
}

.circuit-row {
  display: flex;
  align-items: center;
  height: 64px;
  position: relative;
}

.qubit-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--cyan);
  width: 48px;
  text-align: center;
  flex-shrink: 0;
}

.qubit-label span {
  display: block;
  font-size: 0.6rem;
  color: var(--text-muted);
}

.circuit-wire {
  flex: 1;
  display: flex;
  align-items: center;
  position: relative;
  height: 100%;
}

/* The wire line */
.circuit-wire::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: var(--wire-color);
  transform: translateY(-1px);
}

.circuit-wire.wire-active::before {
  background: var(--wire-active);
  box-shadow: 0 0 8px var(--cyan-glow);
  animation: wirePulse 1.5s ease-in-out infinite;
}

@keyframes wirePulse {
  0%, 100% { box-shadow: 0 0 4px var(--cyan-glow); }
  50% { box-shadow: 0 0 16px var(--cyan-glow); }
}

.wire-cells {
  display: flex;
  gap: 8px;
  position: relative;
  z-index: 1;
  padding: 0 12px;
}

.circuit-cell {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  border: 2px dashed rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  position: relative;
  background: transparent;
}

.circuit-cell:hover {
  border-color: var(--cyan);
  border-style: solid;
  background: var(--cyan-glow);
}

.circuit-cell.has-gate {
  border-color: transparent;
  border-style: solid;
}

/* ── Gate Chips (on circuit) ───────────────────────────────────── */
.gate-chip {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--bg-deep);
  position: relative;
  cursor: pointer;
  animation: gatePlaced 0.3s var(--ease-bounce);
  transition: transform 0.15s;
}

.gate-chip:hover {
  transform: scale(1.1);
}

@keyframes gatePlaced {
  from { transform: scale(0) rotate(-45deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

.gate-chip.gate-X  { background: var(--gate-x); box-shadow: 0 0 12px rgba(255,107,107,0.4); }
.gate-chip.gate-H  { background: var(--gate-h); box-shadow: 0 0 12px rgba(78,205,196,0.4); }
.gate-chip.gate-Z  { background: var(--gate-z); box-shadow: 0 0 12px rgba(69,183,209,0.4); }
.gate-chip.gate-Y  { background: var(--gate-y); box-shadow: 0 0 12px rgba(247,183,49,0.4); }
.gate-chip.gate-S  { background: var(--gate-s); box-shadow: 0 0 12px rgba(165,94,234,0.4); }
.gate-chip.gate-T  { background: var(--gate-t); box-shadow: 0 0 12px rgba(253,150,68,0.4); }

/* CNOT specific */
.gate-chip.gate-CNOT-ctrl {
  background: transparent;
  border: none;
  box-shadow: none;
}

.gate-chip.gate-CNOT-ctrl::after {
  content: '';
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gate-cnot);
  box-shadow: 0 0 10px rgba(252,92,101,0.5);
}

.gate-chip.gate-CNOT-tgt {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: 3px solid var(--gate-cnot);
  box-shadow: 0 0 10px rgba(252,92,101,0.3);
  font-size: 1.2rem;
  color: var(--gate-cnot);
}

/* CNOT vertical connector line */
.cnot-connector {
  position: absolute;
  width: 3px;
  background: var(--gate-cnot);
  left: 50%;
  transform: translateX(-50%);
  z-index: 0;
  box-shadow: 0 0 6px rgba(252,92,101,0.3);
}

/* ── Gate Toolbox ──────────────────────────────────────────────── */
.toolbox-panel {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  padding: 16px 20px;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.toolbox-label {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text-muted);
  text-transform: uppercase;
  white-space: nowrap;
}

.toolbox-gates {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

.gate-btn {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-subtle);
  background: var(--bg-elevated);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all 0.2s var(--ease-out);
  position: relative;
}

.gate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}

.gate-btn.selected {
  border-color: var(--cyan);
  box-shadow: 0 0 16px var(--cyan-glow);
  transform: scale(1.08);
}

.gate-btn .gate-symbol {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
}

.gate-btn .gate-name {
  font-size: 0.5rem;
  font-family: var(--font-body);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Gate button colors */
.gate-btn[data-gate="X"] .gate-symbol { color: var(--gate-x); }
.gate-btn[data-gate="H"] .gate-symbol { color: var(--gate-h); }
.gate-btn[data-gate="Z"] .gate-symbol { color: var(--gate-z); }
.gate-btn[data-gate="Y"] .gate-symbol { color: var(--gate-y); }
.gate-btn[data-gate="S"] .gate-symbol { color: var(--gate-s); }
.gate-btn[data-gate="T"] .gate-symbol { color: var(--gate-t); }
.gate-btn[data-gate="CNOT"] .gate-symbol { color: var(--gate-cnot); }
.gate-btn[data-gate="SWAP"] .gate-symbol { color: var(--gate-swap); }

.gate-btn[data-gate="X"]:hover,
.gate-btn[data-gate="X"].selected { border-color: var(--gate-x); box-shadow: 0 0 16px rgba(255,107,107,0.3); }
.gate-btn[data-gate="H"]:hover,
.gate-btn[data-gate="H"].selected { border-color: var(--gate-h); box-shadow: 0 0 16px rgba(78,205,196,0.3); }
.gate-btn[data-gate="Z"]:hover,
.gate-btn[data-gate="Z"].selected { border-color: var(--gate-z); box-shadow: 0 0 16px rgba(69,183,209,0.3); }
.gate-btn[data-gate="Y"]:hover,
.gate-btn[data-gate="Y"].selected { border-color: var(--gate-y); box-shadow: 0 0 16px rgba(247,183,49,0.3); }
.gate-btn[data-gate="S"]:hover,
.gate-btn[data-gate="S"].selected { border-color: var(--gate-s); box-shadow: 0 0 16px rgba(165,94,234,0.3); }
.gate-btn[data-gate="T"]:hover,
.gate-btn[data-gate="T"].selected { border-color: var(--gate-t); box-shadow: 0 0 16px rgba(253,150,68,0.3); }
.gate-btn[data-gate="CNOT"]:hover,
.gate-btn[data-gate="CNOT"].selected { border-color: var(--gate-cnot); box-shadow: 0 0 16px rgba(252,92,101,0.3); }

.toolbox-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

/* ── Right Sidebar ─────────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  padding: 18px;
}

.panel-title {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Target State Visualization ────────────────────────────────── */
.state-viz {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.state-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.state-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  width: 44px;
  text-align: right;
}

.state-bar-track {
  flex: 1;
  height: 24px;
  background: var(--bg-elevated);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.state-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s var(--ease-out);
  position: relative;
}

.state-bar-fill.target-bar {
  background: linear-gradient(90deg, var(--purple), var(--magenta));
  opacity: 0.8;
}

.state-bar-fill.result-bar {
  background: linear-gradient(90deg, var(--cyan), var(--success));
}

.state-bar-value {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
}

/* ── Info Panel ────────────────────────────────────────────────── */
.info-content {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.info-content .highlight {
  color: var(--cyan);
  font-weight: 600;
}

.hint-box {
  background: rgba(0,212,255,0.06);
  border: 1px solid rgba(0,212,255,0.15);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 10px;
}

.hint-box::before {
  content: '💡 ';
}

.qiskit-tip {
  background: rgba(123,47,247,0.08);
  border: 1px solid rgba(123,47,247,0.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 10px;
  font-family: var(--font-mono);
}

.qiskit-tip::before {
  content: '🐍 Qiskit: ';
  color: var(--purple);
  font-weight: 600;
}

/* ── Result Overlay ────────────────────────────────────────────── */
.result-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(6,10,26,0.85);
  backdrop-filter: blur(12px);
  align-items: center;
  justify-content: center;
}

.result-overlay.visible {
  display: flex;
  animation: fadeIn 0.3s var(--ease-out);
}

.result-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  border: 2px solid var(--border-subtle);
  padding: 40px 50px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  animation: resultPop 0.5s var(--ease-bounce);
}

@keyframes resultPop {
  from { transform: scale(0.6) translateY(30px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.result-card.success {
  border-color: var(--success);
  box-shadow: 0 0 60px var(--success-glow);
}

.result-card.fail {
  border-color: var(--danger);
  box-shadow: 0 0 40px rgba(255,68,102,0.15);
}

.result-icon {
  font-size: 3.5rem;
  margin-bottom: 12px;
}

.result-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.result-card.success .result-title {
  color: var(--success);
}

.result-card.fail .result-title {
  color: var(--danger);
}

.result-detail {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.fidelity-score {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--cyan);
  margin: 16px 0;
}

.result-stars {
  font-size: 1.8rem;
  letter-spacing: 6px;
  margin-bottom: 20px;
}

.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ── Particles ─────────────────────────────────────────────────── */
.particle {
  position: fixed;
  pointer-events: none;
  z-index: 200;
  border-radius: 50%;
  animation: particleFly 1s var(--ease-out) forwards;
}

@keyframes particleFly {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0);
  }
}

/* ── Running animation ─────────────────────────────────────────── */
.circuit-running .circuit-wire::before {
  background: var(--wire-active) !important;
  animation: wirePulse 0.4s ease-in-out infinite;
}

.circuit-running .gate-chip {
  animation: gateGlow 0.5s ease-in-out infinite alternate;
}

@keyframes gateGlow {
  from { filter: brightness(1); }
  to   { filter: brightness(1.4); }
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar .panel {
    flex: 1;
    min-width: 200px;
  }

  .game-header {
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }

  .header-stats {
    flex-wrap: wrap;
    justify-content: center;
  }
}

@media (max-width: 600px) {
  .game-container {
    padding: 10px;
  }

  .circuit-cell {
    width: 44px;
    height: 44px;
  }

  .gate-chip {
    width: 38px;
    height: 38px;
    font-size: 0.85rem;
  }

  .gate-btn {
    width: 44px;
    height: 44px;
  }

  .level-btn {
    width: 56px;
    height: 56px;
  }
}

/* ── Eraser cursor when eraser tool is selected ──────────────── */
.eraser-mode .circuit-cell {
  cursor: crosshair;
}

/* ── Tooltip ───────────────────────────────────────────────────── */
.gate-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-deep);
  color: var(--text-primary);
  font-size: 0.7rem;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 10;
}

.gate-btn:hover .gate-tooltip {
  opacity: 1;
}

/* ── Scroll bar ────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-deep);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Music Player Widget ───────────────────────────────────────── */
.music-player {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.music-toggle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--border-subtle);
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  transition: all 0.3s var(--ease-out);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
}

.music-toggle:hover {
  border-color: var(--cyan);
  transform: scale(1.08);
  box-shadow: 0 4px 28px var(--cyan-glow);
}

.music-toggle.playing {
  border-color: var(--success);
  box-shadow: 0 0 20px var(--success-glow);
}

.music-toggle.playing::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--success);
  opacity: 0;
  animation: musicPulse 2s ease-out infinite;
}

@keyframes musicPulse {
  0% {
    opacity: 0.6;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.6);
  }
}

/* Sound wave bars animation when playing */
.music-toggle.playing::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: var(--success);
  border-radius: 2px;
  animation: soundWave 0.8s ease-in-out infinite alternate;
}

@keyframes soundWave {
  0% { width: 12px; opacity: 0.5; }
  100% { width: 24px; opacity: 1; }
}

.music-panel {
  position: absolute;
  bottom: 64px;
  right: 0;
  width: 280px;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.95);
  transition: all 0.3s var(--ease-out);
  pointer-events: none;
}

.music-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

.music-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.music-panel-title {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.music-status {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: color 0.3s;
}

.music-channels {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.channel-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  color: var(--text-secondary);
  text-align: left;
}

.channel-btn:hover {
  border-color: var(--cyan);
  background: rgba(0, 212, 255, 0.06);
  color: var(--text-bright);
  transform: translateX(3px);
}

.channel-btn.active {
  border-color: var(--success);
  background: rgba(0, 255, 136, 0.06);
}

.channel-btn.active .channel-name {
  color: var(--success);
}

.channel-icon {
  font-size: 1.15rem;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}

.channel-name {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.channel-desc {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.music-volume-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.volume-label {
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* Custom range slider */
.music-volume {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-elevated);
  outline: none;
  cursor: pointer;
}

.music-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cyan);
  border: 2px solid var(--bg-deep);
  cursor: pointer;
  box-shadow: 0 0 8px var(--cyan-glow);
  transition: transform 0.15s;
}

.music-volume::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.music-volume::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cyan);
  border: 2px solid var(--bg-deep);
  cursor: pointer;
  box-shadow: 0 0 8px var(--cyan-glow);
}

.music-credit {
  text-align: center;
  font-size: 0.6rem;
  color: var(--text-muted);
}

.music-credit a {
  color: var(--cyan-dim);
  text-decoration: none;
  transition: color 0.2s;
}

.music-credit a:hover {
  color: var(--cyan);
}

/* Responsive adjustments */
@media (max-width: 600px) {
  .music-player {
    bottom: 12px;
    right: 12px;
  }

  .music-toggle {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }

  .music-panel {
    width: 250px;
    right: -8px;
  }
}

