:root {
  /* Variables locales branchées sur la charte commune (assets/css/tokens.css) */
  --bg-dark: var(--bg);
  --bg-darker: var(--bg-deep);
  --terminal-bg: var(--bg-deep);
  --text-primary: #C9D4DE;
  --text-muted: var(--muted);
  --text-error: #FF8A86;
  --text-success: #6BD47B;
  --border-color: var(--line);
  --prompt-color: #6BD47B;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.terminal-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin: 16px;
  background: var(--bg-deep);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  
}

.terminal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid var(--border-color);
  user-select: none;
}

.terminal-title {
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.terminal-buttons {
  display: flex;
  gap: 8px;
}

.term-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease;
  font-size: 12px;
}

.term-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.term-btn.close:hover {
  background: rgba(255, 68, 68, 0.2);
  color: #ff4444;
}

.terminal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
  background: var(--terminal-bg);
}

.terminal-output {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  margin-bottom: 12px;
  padding-right: 8px;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.7;
}

.terminal-output::-webkit-scrollbar {
  width: 8px;
}

.terminal-output::-webkit-scrollbar-track {
  background: transparent;
}

.terminal-output::-webkit-scrollbar-thumb {
  background: rgba(107, 114, 128, 0.5);
  border-radius: 4px;
}

.terminal-output::-webkit-scrollbar-thumb:hover {
  background: rgba(107, 114, 128, 0.8);
}

.output-line {
  margin-bottom: 2px;
  word-break: break-word;
}

.output-line.error {
  color: var(--text-error);
}

.output-line.success {
  color: var(--text-success);
}

.output-line.prompt {
  color: var(--prompt-color);
  font-weight: 500;
}

.output-line.hint {
  color: var(--accent);
  font-style: italic;
}

.terminal-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(0, 0, 0, 0.2);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.terminal-prompt {
  color: var(--prompt-color);
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.5px;
}

.terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: inherit;
  outline: none;
  caret-color: var(--prompt-color);
}

.terminal-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.game-hud {
  display: flex;
  gap: 12px;
  padding: 0 16px 16px;
  flex-wrap: wrap;
}

.hud-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 16px;
  flex: 1;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-card strong {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.hud-card span {
  color: var(--text-primary);
  font-size: 13px;
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--ok);
  width: 0%;
  transition: width 0.3s ease;
  
}

/* Win/Lose Overlay */
.game-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.overlay-content {
  max-width: 600px;
  text-align: center;
  background: rgba(13, 17, 23, 0.9);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 32px;
}

.overlay-content h1 {
  font-size: 2.5rem;
  margin-bottom: 16px;
}

.overlay-content.victory h1 {
  color: var(--text-success);
}

.overlay-content.defeat h1 {
  color: var(--text-error);
}

.overlay-content p {
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.8;
}

.flag-display {
  background: rgba(77, 255, 77, 0.1);
  border: 1px solid var(--text-success);
  border-radius: 8px;
  padding: 16px;
  margin: 20px 0;
  font-family: "JetBrains Mono", monospace;
  color: var(--text-success);
  word-break: break-all;
  font-size: 13px;
}

.overlay-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

.overlay-btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.overlay-btn.primary {
  background: var(--accent); color: var(--accent-ink);
  color: #000;
}

.overlay-btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(77, 255, 77, 0.3);
}

.overlay-btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.overlay-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

@media (max-width: 768px) {
  .terminal-container {
    margin: 8px;
    border-radius: 12px;
  }

  .terminal-body {
    padding: 12px;
  }

  .terminal-output {
    font-size: 12px;
  }

  .game-hud {
    flex-direction: column;
  }

  .hud-card {
    min-width: 100%;
  }

  .overlay-content {
    padding: 24px;
  }

  .overlay-content h1 {
    font-size: 2rem;
  }
}

/* ---- v2 : mise en page, HUD, kill chain ---- */
html, body { font-family: "IBM Plex Mono", "JetBrains Mono", monospace; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ctf-top { display: flex; align-items: center; gap: 14px; padding: 12px 16px 0; flex-wrap: wrap; }
.ctf-back { color: var(--accent); text-decoration: none; display: inline-flex; gap: 6px; align-items: center; padding: 6px 10px; border: 1px solid var(--border-color); border-radius: 10px; }
.ctf-back:hover { background: rgba(98,208,255,.08); }
.ctf-title { color: #e6edf3; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctf-title i { color: #ff4d6d; }
.sim-badge { font-size: 11px; color: #ffc24b; border: 1px solid rgba(255,194,75,.4); padding: 2px 8px; border-radius: 999px; font-weight: 400; }
.lang-toggle { margin-left: auto; display: flex; gap: 4px; border: 1px solid var(--border-color); border-radius: 999px; padding: 3px; }
.lang-btn { background: none; border: 0; color: var(--text-muted); font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 999px; cursor: pointer; }
.lang-btn.active { background: var(--text-primary); color: #001a09; }
.ctf-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 0; }
.ctf-layout .terminal-container { min-height: 0; margin-right: 8px; }
.terminal-body { min-height: 0; cursor: text; }
.terminal-output { scroll-behavior: auto; }
.terminal-buttons { display: flex; gap: 6px; }
.term-dot { width: 11px; height: 11px; border-radius: 50%; background: #ff5f57; }
.term-dot:nth-child(2) { background: #febc2e; } .term-dot:nth-child(3) { background: #28c840; }
.output-line { white-space: pre-wrap; word-break: break-word; }
.output-line.warn { color: #ffc24b; }
.output-line.muted { color: #7d8590; }
.output-line.prompt { color: #e6edf3; }
.game-hud { flex-direction: column; padding: 16px 16px 16px 8px; overflow-y: auto; flex-wrap: nowrap; }
.hud-card { flex: 0 0 auto; }
.hud-user { font-size: 18px !important; font-weight: 700; }
.hud-user.u-admin { color: #ffc24b !important; } .hud-user.u-root { color: #ff4d6d !important; }
.hud-small { font-size: 12px !important; color: var(--text-muted) !important; }
.progress-bar.danger .progress-fill { background: var(--crit); }
.chain { list-style: none; counter-reset: c; display: grid; gap: 7px; }
.chain li { counter-increment: c; display: flex; gap: 9px; align-items: center; font-size: 12.5px; color: var(--text-muted); }
.chain li::before { content: counter(c); flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--border-color); font-size: 11px; }
.chain li.done { color: #e6edf3; }
.chain li.done::before { content: "✓"; background: var(--text-primary); color: #001a09; border-color: var(--text-primary); }
.hud-tip { font-size: 12px; color: var(--text-muted); padding: 4px 4px 0; }
.hud-tip code { color: var(--text-primary); }
.overlay-content .lesson { font-size: 13px; color: #9fb3c8; border-left: 3px solid var(--accent); padding: 8px 12px; text-align: left; background: rgba(98,208,255,.06); border-radius: 6px; }
.overlay-btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
@media (max-width: 860px) {
  html, body { overflow: auto; height: auto; }
  .ctf-layout { grid-template-columns: 1fr; }
  .ctf-layout .terminal-container { margin: 12px; height: 62vh; }
  .game-hud { padding: 0 12px 16px; }
}
