/* ===================================================================
   Apprends Git — thème neutre & sobre
   Palette : slate sombre + un accent bleu, pour rester lisible et pro
   =================================================================== */

:root {
  /* surfaces & fond */
  --bg-1: #0b1120;
  --bg-2: #111827;
  --surface: rgba(30, 41, 59, .55);
  --surface-2: rgba(148, 163, 184, .07);
  --border: rgba(148, 163, 184, .20);

  /* accents */
  --accent: #2563eb;         /* bleu : boutons / liens */
  --accent-clair: #3b82f6;
  --highlight: #f59e0b;      /* ambre : titres, score, étoiles */

  /* texte */
  --text: #e5e7eb;
  --text-fonce: #cbd5e1;
  --text-dim: rgba(226, 232, 240, .62);

  /* terminal */
  --term-bg: #0a0e17;
  --term-fg: #e5e7eb;
  --term-vert: #4ade80;
  --term-rouge: #f87171;
  --term-jaune: #fbbf24;
  --term-bleu: #60a5fa;
  --term-gris: #9ca3af;

  --ok: #22c55e;
  --erreur: #ef4444;

  --ombre: 0 8px 28px rgba(0, 0, 0, .45);
  --rayon: 12px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(circle at 15% -10%, rgba(37, 99, 235, .18), transparent 42%),
    radial-gradient(circle at 100% 0%, rgba(56, 189, 248, .12), transparent 40%),
    var(--bg-1);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.hidden { display: none !important; }

code {
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  background: rgba(148, 163, 184, .14);
  color: #93c5fd;
  padding: .05em .35em;
  border-radius: 5px;
  font-size: .92em;
}

/* ============================ HUD ============================ */
#hud {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--bg-2);
  border-bottom: 2px solid var(--accent);
  box-shadow: var(--ombre);
  flex-wrap: wrap;
}

.hud-brand {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: .3px;
  color: var(--text);
  white-space: nowrap;
}

.hud-center { flex: 1; min-width: 220px; }
.hud-level-label { font-size: 1rem; font-weight: 700; }
.hud-dim { opacity: .6; }

.hud-progress {
  margin-top: 5px;
  height: 9px;
  background: rgba(0, 0, 0, .35);
  border-radius: 999px;
  overflow: hidden;
}
#hud-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-clair));
  transition: width .5s ease;
}

.hud-stats { display: flex; gap: 14px; align-items: center; white-space: nowrap; }
.hud-score { font-size: 1.15rem; font-weight: 700; color: var(--highlight); }
.hud-player { font-size: 1rem; }

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

.btn-hint {
  background: var(--highlight);
  color: #422006;
  border: none;
  font-weight: 700;
}
.btn-hint:hover { background: #fbbf24; color: #422006; }

.btn-ghost {
  background: rgba(148, 163, 184, .12);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: rgba(148, 163, 184, .22); color: #fff; }

.btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
  font-weight: 700;
}
.btn-primary:hover { background: var(--accent-clair); color: #fff; }

.btn-danger-soft { color: #fecaca; border-color: rgba(248, 113, 113, .4); }
.btn-danger-soft:hover { background: rgba(239, 68, 68, .3); color: #fff; }

/* ============================ ZONE DE JEU ============================ */
#game {
  flex: 1;
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
  padding: 18px;
  align-items: stretch;
  min-height: 0;
}

/* ---- Terminal ---- */
#terminal-col { display: flex; flex-direction: column; min-width: 0; }

#terminal {
  flex: 1;
  background: var(--term-bg);
  border: 1px solid var(--border);
  border-radius: var(--rayon);
  box-shadow: var(--ombre), inset 0 0 0 1px rgba(255, 255, 255, .02);
  padding: 14px 16px;
  font-family: "SFMono-Regular", Menlo, Consolas, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.55;
  color: var(--term-fg);
  overflow-y: auto;
  overflow-x: hidden;
  cursor: text;
  display: flex;
  flex-direction: column;
  min-height: 320px;
}

#term-output { white-space: pre-wrap; word-break: break-word; }

.term-line { white-space: pre-wrap; }
.t-cmd     { color: #fff; }
.t-prompt  { color: var(--term-vert); }
.t-ok      { color: var(--term-vert); }
.t-err     { color: var(--term-rouge); }
.t-warn    { color: var(--term-jaune); }
.t-info    { color: var(--term-bleu); }
.t-dim     { color: var(--term-gris); }
.t-tip     { color: var(--term-jaune); font-style: italic; }
.t-branch  { color: var(--term-jaune); }

#term-input-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin-top: 2px; }
.term-prompt { color: var(--term-vert); white-space: pre-wrap; word-break: break-word; }
#term-input {
  flex: 1;
  min-width: 8ch;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-family: inherit;
  font-size: inherit;
  caret-color: var(--term-vert);
}

.term-hint-os {
  margin: 8px 2px 0;
  font-size: .82rem;
  color: var(--text-dim);
}

/* ---- Panneaux latéraux ---- */
#side-col { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; min-width: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rayon);
  padding: 14px 16px;
  box-shadow: var(--ombre);
}
.panel-head {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.quest-objective { font-weight: 700; font-size: 1.02rem; margin: 0 0 8px; }
.quest-why {
  font-size: .9rem;
  color: var(--text-fonce);
  background: rgba(37, 99, 235, .12);
  border-left: 3px solid var(--accent);
  padding: 8px 10px;
  border-radius: 6px;
}
.quest-why b { color: var(--accent-clair); }

/* ---- Visualiseur de dépôt ---- */
.repo-state { font-size: .88rem; }
.repo-empty { color: var(--term-gris); font-style: italic; margin: 0; }

.repo-line { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.repo-key { color: var(--text-dim); min-width: 96px; }
.repo-val { font-family: monospace; }

.badge-zone {
  display: inline-block;
  font-family: monospace;
  font-size: .8rem;
  padding: 2px 8px;
  border-radius: 999px;
  margin: 2px 4px 2px 0;
}
.zone-untracked { background: rgba(239, 68, 68, .22);  color: #fca5a5; border: 1px solid rgba(248, 113, 113, .4); }
.zone-staged    { background: rgba(34, 197, 94, .20);  color: #86efac; border: 1px solid rgba(74, 222, 128, .45); }
.zone-committed { background: rgba(37, 99, 235, .22);  color: #93c5fd; border: 1px solid rgba(96, 165, 250, .4); }
.zone-clean     { background: rgba(148, 163, 184, .1); color: #cbd5e1; border: 1px solid var(--border); }

.repo-flow {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin: 10px 0;
}
.flow-box {
  flex: 1;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 6px 4px;
  font-size: .72rem;
}
.flow-box .fb-title { display: block; color: var(--highlight); font-weight: 700; margin-bottom: 3px; }
.flow-box .fb-count { font-size: 1.1rem; font-weight: 700; }
.flow-arrow { align-self: center; color: var(--term-gris); }

.commit-log { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 6px; }
.commit-item { font-size: .82rem; margin: 3px 0; }
.commit-hash { color: var(--highlight); font-family: monospace; }
.commit-author { color: var(--term-gris); }

/* ---- Panneau GitHub ---- */
.gh-repo { font-family: monospace; font-size: .95rem; }
#github-content { font-size: .9rem; }
.gh-branch-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 8px 0;
}
.gh-pr-card {
  background: rgba(34, 197, 94, .12);
  border: 1px solid rgba(74, 222, 128, .4);
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
}
.gh-pr-title { font-weight: 700; color: #86efac; }
.gh-pr-meta { font-size: .8rem; color: var(--text-fonce); margin-top: 4px; }
.gh-pr-state {
  display: inline-block; font-size: .75rem; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; margin-top: 6px;
}
.pr-open   { background: #238636; color: #fff; }
.pr-review { background: var(--highlight); color: #422006; }
.pr-merged { background: #8957e5; color: #fff; }

.gh-form label { display: block; font-size: .82rem; margin: 8px 0 3px; color: var(--text-fonce); }
.gh-form input, .gh-form textarea {
  width: 100%;
  background: var(--term-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #fff;
  padding: 6px 8px;
  font-family: inherit;
}
.gh-form textarea { min-height: 60px; resize: vertical; }
.gh-check { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: .85rem; }
.gh-check input { width: auto; }
.gh-btn-pr { margin-top: 10px; width: 100%; background: #238636; border: none; color: #fff; font-weight: 700; }
.gh-btn-pr:hover { background: #2ea043; color: #fff; }

/* ============================ OVERLAYS / MODALES ============================ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(2, 6, 23, .74);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 18px;
  overflow-y: auto;
}
.modal-box {
  background: linear-gradient(160deg, #1e293b, #111827);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--ombre);
  padding: 24px 26px;
  max-width: 620px;
  width: 100%;
  animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.game-title {
  font-size: 2.1rem;
  font-weight: 800;
  text-align: center;
  color: var(--text);
  margin: 0 0 6px;
}
.game-subtitle { text-align: center; font-size: 1.1rem; color: var(--text-fonce); margin: 0 0 14px; }
.char-intro { text-align: center; color: var(--text-fonce); margin-bottom: 18px; }

/* ---- Formulaire de démarrage (saisie du nom) ---- */
.setup-form { display: flex; flex-direction: column; gap: 8px; max-width: 420px; margin: 0 auto; }
.setup-form label { font-size: .9rem; color: var(--text-fonce); }
.setup-form input {
  width: 100%;
  background: var(--term-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #fff;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 1.05rem;
}
.setup-form input:focus { outline: none; border-color: var(--accent); }
.setup-form button { margin-top: 8px; padding: 10px 18px; font-size: 1.02rem; }

.resume-row { text-align: center; margin-top: 16px; }
.btn-resume { background: var(--accent); color: #fff; border: none; font-weight: 700; padding: 8px 18px; }
.btn-resume:hover { background: var(--accent-clair); color: #fff; }
.char-foot { text-align: center; font-size: .8rem; color: var(--text-dim); margin: 16px 0 0; }

/* ---- Éditeur ---- */
.modal-editor { max-width: 760px; }
.editor-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 1.15rem; font-weight: 700; color: var(--text);
  margin-bottom: 6px;
}
.editor-help { font-size: .88rem; color: var(--text-fonce); margin-bottom: 8px; }
.editor-tools { margin-bottom: 8px; }
#editor-area {
  width: 100%; min-height: 280px;
  background: var(--term-bg); color: var(--term-fg);
  border: 1px solid var(--border); border-radius: 8px;
  font-family: monospace; font-size: 13px; line-height: 1.5;
  padding: 10px; resize: vertical;
}
.editor-feedback { font-size: .88rem; margin: 8px 0; min-height: 1.2em; }
.editor-feedback.err { color: var(--term-rouge); }
.editor-feedback.ok  { color: var(--term-vert); }
.editor-actions { text-align: right; }

/* ---- Indice / menu / cheatsheet ---- */
.modal-hint, .modal-menu { max-width: 520px; }
.hint-head {
  font-size: 1.25rem; font-weight: 700; color: var(--text); margin-bottom: 10px;
}
.hint-body { font-size: 1rem; line-height: 1.6; }
.hint-body .hint-step { margin: 6px 0; padding-left: 6px; border-left: 3px solid var(--accent); }
.hint-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.menu-actions { display: flex; flex-direction: column; gap: 10px; }

.cheatsheet-body { font-size: .9rem; max-height: 60vh; overflow-y: auto; }
.cheatsheet-body h5 { color: var(--highlight); font-weight: 700; margin: 14px 0 6px; }
.cheatsheet-body table { width: 100%; border-collapse: collapse; }
.cheatsheet-body td { padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.cheatsheet-body td:first-child { white-space: nowrap; }

/* ---- Victoire ---- */
.modal-victory { text-align: center; max-width: 560px; }
.victory-confetti { font-size: 2.6rem; }
.victory-text { font-size: 1.1rem; margin: 10px 0; }
.victory-stats { display: flex; justify-content: center; gap: 24px; margin: 16px 0; }
.vstat { background: var(--surface-2); border-radius: 10px; padding: 10px 16px; }
.vstat .vnum { font-size: 1.8rem; font-weight: 700; color: var(--highlight); display: block; }
.vstat .vlabel { font-size: .82rem; color: var(--text-fonce); }

/* ---- Toast de fin de niveau ---- */
.levelup-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(120%);
  background: linear-gradient(90deg, var(--ok), #16a34a);
  color: #fff; padding: 14px 22px; border-radius: 12px;
  box-shadow: var(--ombre); font-weight: 700; font-size: 1.05rem;
  z-index: 150; max-width: 90vw; text-align: center;
  transition: transform .4s cubic-bezier(.2, 1.2, .4, 1);
}
.levelup-toast.show { transform: translateX(-50%) translateY(0); }
.levelup-toast .stars { color: var(--highlight); font-size: 1.2rem; }

/* étoiles dans le HUD/toast */
.stars-inline { letter-spacing: 2px; }

/* ---- Quiz de compréhension ---- */
.modal-quiz { max-width: 520px; }
.quiz-question { font-size: 1.05rem; font-weight: 700; margin: 0 0 14px; }
.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.quiz-option {
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: .98rem;
  font-family: inherit;
  transition: background .15s, border-color .15s;
}
.quiz-option:hover:not(:disabled) { background: rgba(148, 163, 184, .16); border-color: var(--accent); }
.quiz-option:disabled { cursor: default; }
.quiz-option.correct { background: rgba(34, 197, 94, .18); border-color: rgba(74, 222, 128, .5); color: #86efac; }
.quiz-option.wrong   { background: rgba(239, 68, 68, .16); border-color: rgba(248, 113, 113, .5); color: #fca5a5; }
.quiz-explain { font-size: .92rem; margin: 12px 0 0; min-height: 1.2em; color: var(--text-fonce); }
.quiz-explain.ok { color: var(--term-vert); }
#quiz-continue:disabled { opacity: .45; cursor: default; }

/* ---- Surlignage contextuel de l'aide-mémoire ---- */
.cheat-highlight {
  background: rgba(37, 99, 235, .18);
  border-left: 3px solid var(--accent);
  padding-left: 8px;
  border-radius: 4px;
}

/* ---- Bandeau mode bac à sable ---- */
.sandbox-tag {
  display: inline-block;
  background: rgba(245, 158, 11, .18);
  border: 1px solid rgba(245, 158, 11, .5);
  color: var(--highlight);
  font-size: .8rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 6px;
}

/* ============================ RESPONSIVE ============================ */
@media (max-width: 880px) {
  #game { grid-template-columns: 1fr; }
  #terminal { min-height: 260px; }
  .hud-brand { font-size: 1.15rem; }
  .hud-center { order: 3; flex-basis: 100%; }
  .game-title { font-size: 1.7rem; }
}
