/* ============================================================
   Escape Game Éducatif — Thème Spatial
   ============================================================ */

:root {
  --bg-primary: #0a0e27;
  --bg-secondary: #121838;
  --bg-card: #1a2040;
  --text-primary: #e8e8ff;
  --text-secondary: #8888bb;
  --accent: #00d4ff;
  --accent-glow: rgba(0, 212, 255, 0.3);
  --success: #00ff88;
  --warning: #ffaa00;
  --danger: #ff4466;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Starfield background ─────────────────────────────────── */

#stars-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ── Layout ───────────────────────────────────────────────── */

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
}
.screen.active {
  display: flex;
}

/* ── HUD (heads-up display) ───────────────────────────────── */

#hud {
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: rgba(10, 14, 39, 0.9);
  border-bottom: 1px solid rgba(0, 212, 255, 0.2);
  backdrop-filter: blur(8px);
  flex-wrap: wrap;
  gap: 8px;
}
#hud.visible { display: flex; }

.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}
.hud-item .label { color: var(--text-secondary); }
.hud-item .value { font-weight: 700; color: var(--accent); }

#timer.warning .value { color: var(--warning); }
#timer.danger .value { color: var(--danger); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Component indicators */
#components-bar {
  display: flex;
  gap: 4px;
}
.component-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all 0.3s;
}
.component-dot.collected {
  border-color: var(--success);
  background: rgba(0, 255, 136, 0.15);
  box-shadow: 0 0 8px rgba(0, 255, 136, 0.4);
}

/* ── Intro screen ─────────────────────────────────────────── */

#intro-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 40px 20px;
}

.intro-content {
  max-width: 600px;
}

.game-title {
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #ff66ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 8px;
}

.game-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.intro-story {
  background: var(--bg-card);
  border: 1px solid rgba(0, 212, 255, 0.2);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 32px;
  text-align: left;
  line-height: 1.7;
  font-size: 1.05rem;
}

.intro-info {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 32px;
}
.info-badge {
  background: var(--bg-card);
  border: 1px solid rgba(0, 212, 255, 0.15);
  border-radius: 8px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.info-badge .badge-icon { font-size: 1.5rem; }
.info-badge .badge-text { font-size: 0.85rem; color: var(--text-secondary); }
.info-badge .badge-value { font-weight: 700; }

/* ── Buttons ──────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  border: none;
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #0088ff);
  color: #fff;
  box-shadow: 0 4px 16px rgba(0, 212, 255, 0.3);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0, 212, 255, 0.5);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid rgba(0, 212, 255, 0.3);
}
.btn-secondary:hover {
  background: rgba(0, 212, 255, 0.1);
  border-color: var(--accent);
}

.btn-hint {
  background: rgba(255, 170, 0, 0.15);
  color: var(--warning);
  border: 1px solid rgba(255, 170, 0, 0.3);
  padding: 10px 20px;
  font-size: 0.9rem;
}
.btn-hint:hover { background: rgba(255, 170, 0, 0.25); }
.btn-hint:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-success {
  background: linear-gradient(135deg, var(--success), #00cc66);
  color: #000;
  box-shadow: 0 4px 16px rgba(0, 255, 136, 0.3);
}

/* ── Game screen ──────────────────────────────────────────── */

#game-screen {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.room-container {
  max-width: 800px;
  margin: 0 auto;
}

/* Room header */
.room-header {
  text-align: center;
  margin-bottom: 24px;
}
.room-tag {
  display: inline-block;
  padding: 4px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.room-name {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 4px;
}
.room-component {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Narrative box */
.narrative-box {
  background: var(--bg-card);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 20px 24px;
  margin-bottom: 24px;
  line-height: 1.7;
  font-style: italic;
  position: relative;
}
.narrative-box::before {
  content: '🛸';
  position: absolute;
  top: -12px;
  left: -14px;
  font-size: 1.5rem;
}

/* Puzzle card */
.puzzle-card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.puzzle-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.puzzle-instructions {
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.6;
}

/* Puzzle actions bar */
.puzzle-actions {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  flex-wrap: wrap;
}

/* ── Puzzle: Code input ───────────────────────────────────── */

.binary-table {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 24px;
  max-width: 400px;
}
.binary-cell {
  background: rgba(0, 212, 255, 0.08);
  border: 1px solid rgba(0, 212, 255, 0.15);
  border-radius: 6px;
  padding: 8px;
  text-align: center;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
}
.binary-cell .bin { color: var(--accent); font-weight: 700; }
.binary-cell .dec { color: var(--text-secondary); }

.code-display {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.code-group {
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(0, 212, 255, 0.3);
  border-radius: 8px;
  padding: 16px 20px;
  text-align: center;
}
.code-binary {
  font-family: 'Courier New', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 4px;
}
.code-arrow {
  display: block;
  color: var(--text-secondary);
  margin: 6px 0;
}

.code-input-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
}
.code-input {
  width: 60px;
  height: 60px;
  background: var(--bg-secondary);
  border: 2px solid rgba(0, 212, 255, 0.3);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 1.8rem;
  font-weight: 700;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}
.code-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

/* ── Puzzle: Quiz ─────────────────────────────────────────── */

.quiz-question-block {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.quiz-question-block:last-child { border-bottom: none; }

.quiz-question-number {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.quiz-question-text {
  font-size: 1.05rem;
  margin-bottom: 12px;
  line-height: 1.5;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quiz-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.95rem;
}
.quiz-option:hover {
  border-color: rgba(0, 212, 255, 0.3);
  background: rgba(0, 212, 255, 0.05);
}
.quiz-option.selected {
  border-color: var(--accent);
  background: rgba(0, 212, 255, 0.1);
}
.quiz-option.correct {
  border-color: var(--success);
  background: rgba(0, 255, 136, 0.1);
}
.quiz-option.wrong {
  border-color: var(--danger);
  background: rgba(255, 68, 102, 0.1);
}

.quiz-radio {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--text-secondary);
  position: relative;
  flex-shrink: 0;
}
.quiz-option.selected .quiz-radio {
  border-color: var(--accent);
}
.quiz-option.selected .quiz-radio::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

/* ── Puzzle: Geometry ─────────────────────────────────────── */

.geo-challenge {
  margin-bottom: 20px;
  padding: 20px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.geo-question {
  margin-bottom: 12px;
  line-height: 1.5;
}
.geo-formula {
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: rgba(0, 212, 255, 0.05);
  padding: 6px 12px;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 12px;
}
.geo-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.geo-input {
  width: 100px;
  padding: 10px;
  background: var(--bg-secondary);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
  outline: none;
}
.geo-input:focus {
  border-color: var(--accent);
}
.geo-unit {
  color: var(--text-secondary);
  font-weight: 600;
}

/* ── Puzzle: Balance (Chemistry) ──────────────────────────── */

.equation-block {
  margin-bottom: 24px;
  padding: 20px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.equation-display {
  font-family: 'Courier New', monospace;
  font-size: 1.2rem;
  text-align: center;
  margin-bottom: 16px;
  color: var(--text-secondary);
}
.equation-inputs {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
.eq-slot {
  display: flex;
  align-items: center;
  gap: 4px;
}
.eq-coef-input {
  width: 50px;
  height: 50px;
  background: var(--bg-secondary);
  border: 2px solid rgba(255, 170, 0, 0.3);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  outline: none;
}
.eq-coef-input:focus {
  border-color: var(--warning);
  box-shadow: 0 0 8px rgba(255, 170, 0, 0.3);
}
.eq-label {
  font-weight: 600;
  font-size: 1rem;
}
.eq-plus, .eq-arrow {
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 1.2rem;
}

/* ── Puzzle: Sequence ─────────────────────────────────────── */

.sequence-block {
  margin-bottom: 20px;
  padding: 20px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.sequence-numbers {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.seq-num {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 68, 136, 0.1);
  border: 2px solid rgba(255, 68, 136, 0.3);
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: 700;
}
.seq-arrow {
  color: var(--text-secondary);
  font-size: 1.2rem;
}
.seq-input {
  width: 56px;
  height: 56px;
  background: var(--bg-secondary);
  border: 2px solid rgba(255, 68, 136, 0.5);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
  outline: none;
}
.seq-input:focus {
  border-color: var(--danger);
  box-shadow: 0 0 8px rgba(255, 68, 136, 0.3);
}

/* ── Puzzle: Logic gates ──────────────────────────────────── */

.gate-block {
  margin-bottom: 20px;
  padding: 20px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.gate-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(136, 102, 255, 0.08);
  border-radius: 6px;
  line-height: 1.5;
}
.gate-circuit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.gate-input-display {
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.95rem;
}
.gate-input-display.val-true {
  background: rgba(0, 255, 136, 0.15);
  color: var(--success);
  border: 1px solid rgba(0, 255, 136, 0.3);
}
.gate-input-display.val-false {
  background: rgba(255, 68, 102, 0.15);
  color: var(--danger);
  border: 1px solid rgba(255, 68, 102, 0.3);
}
.gate-symbol {
  background: rgba(136, 102, 255, 0.2);
  border: 2px solid rgba(136, 102, 255, 0.5);
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 800;
  color: #aa88ff;
}
.gate-output-choices {
  display: flex;
  gap: 8px;
}
.gate-choice {
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.2s;
  border: 2px solid transparent;
}
.gate-choice-true {
  background: rgba(0, 255, 136, 0.1);
  border-color: rgba(0, 255, 136, 0.2);
  color: var(--success);
}
.gate-choice-true:hover, .gate-choice-true.selected {
  background: rgba(0, 255, 136, 0.2);
  border-color: var(--success);
}
.gate-choice-false {
  background: rgba(255, 68, 102, 0.1);
  border-color: rgba(255, 68, 102, 0.2);
  color: var(--danger);
}
.gate-choice-false:hover, .gate-choice-false.selected {
  background: rgba(255, 68, 102, 0.2);
  border-color: var(--danger);
}

/* ── Puzzle: Final ────────────────────────────────────────── */

.final-challenge {
  margin-bottom: 20px;
  padding: 20px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.final-subject {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.final-question {
  margin-bottom: 12px;
  line-height: 1.5;
}
.final-input {
  width: 120px;
  padding: 10px;
  background: var(--bg-secondary);
  border: 2px solid rgba(255, 51, 51, 0.3);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
  outline: none;
}
.final-input:focus {
  border-color: var(--danger);
  box-shadow: 0 0 8px rgba(255, 51, 51, 0.3);
}

/* ── Feedback ─────────────────────────────────────────────── */

.feedback {
  padding: 16px 20px;
  border-radius: 8px;
  margin-top: 16px;
  font-weight: 600;
  display: none;
  line-height: 1.5;
  animation: slideIn 0.3s ease-out;
}
.feedback.visible { display: block; }
.feedback.success {
  background: rgba(0, 255, 136, 0.1);
  border: 1px solid rgba(0, 255, 136, 0.3);
  color: var(--success);
}
.feedback.error {
  background: rgba(255, 68, 102, 0.1);
  border: 1px solid rgba(255, 68, 102, 0.3);
  color: var(--danger);
}
.feedback .explanation {
  display: block;
  margin-top: 8px;
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 0.9rem;
}

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

/* ── Hint box ─────────────────────────────────────────────── */

.hint-box {
  background: rgba(255, 170, 0, 0.08);
  border: 1px solid rgba(255, 170, 0, 0.2);
  border-radius: 8px;
  padding: 16px;
  margin-top: 16px;
  display: none;
}
.hint-box.visible { display: block; }
.hint-text {
  color: var(--warning);
  line-height: 1.5;
}
.hint-text::before { content: '💡 '; }

/* ── Transition overlay ───────────────────────────────────── */

#transition-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.92);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 100;
  text-align: center;
  padding: 40px;
}
#transition-overlay.visible {
  display: flex;
}

.transition-content {
  max-width: 500px;
  animation: zoomIn 0.5s ease-out;
}

@keyframes zoomIn {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

.transition-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: float 2s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.transition-title {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 8px;
}
.transition-text {
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.6;
}

/* ── Victory screen ───────────────────────────────────────── */

#victory-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 40px 20px;
}

.victory-content {
  max-width: 600px;
  animation: zoomIn 0.5s ease-out;
}

.victory-rocket {
  font-size: 5rem;
  margin-bottom: 16px;
  animation: rocketLaunch 2s ease-in-out infinite;
}
@keyframes rocketLaunch {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(5deg); }
}

.victory-title {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, #ff6600, #ffdd00, var(--success));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 16px;
}
.victory-subtitle {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.victory-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid rgba(0, 212, 255, 0.15);
  border-radius: var(--radius);
  padding: 20px 28px;
  min-width: 140px;
}
.stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
}
.stat-label {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 4px;
}

.victory-components {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 32px;
}
.victory-comp {
  background: var(--bg-card);
  border: 1px solid rgba(0, 255, 136, 0.3);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 1.2rem;
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 600px) {
  .puzzle-card { padding: 20px; }
  .code-display { gap: 8px; }
  .code-group { padding: 12px; }
  .code-binary { font-size: 1.2rem; letter-spacing: 2px; }
  .code-input { width: 48px; height: 48px; font-size: 1.4rem; }
  .binary-table { grid-template-columns: repeat(4, 1fr); }
  .equation-inputs { gap: 6px; }
  .eq-coef-input { width: 40px; height: 40px; font-size: 1.1rem; }
  .seq-num, .seq-input { width: 44px; height: 44px; font-size: 1rem; }
  .gate-circuit { gap: 6px; }
  #hud { padding: 8px 12px; }
  .hud-item { font-size: 0.8rem; }
}
