:root {
  --bg: #0f0f10;
  --surface: #151516;
  --surface-2: #1a1a1c;
  --terminal: #0a0a0b;
  --ink: #f1efe9;
  --soft: #c2bfb8;
  --dim: #a19e97;
  --faint: #66635e;
  --line: #2b2b2d;
  --accent: #ff5a3c;
  --danger: #ff7474;
  --sans: "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --mono: "Fragment Mono", "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

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

html,
body {
  min-height: 100%;
}

body {
  background: radial-gradient(64rem 44rem at 92% -8%, rgb(255 90 60 / 7%), transparent 62%) var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

::selection {
  background: var(--accent);
  color: var(--bg);
}

* {
  scrollbar-color: var(--line) transparent;
  scrollbar-width: thin;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: flex;
  flex-direction: column;
  animation: enter 220ms ease-out;
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.sitebar,
.topbar {
  width: min(calc(100% - 3.5rem), 74rem);
  min-height: 5.5rem;
  margin: 0 auto;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.sitebar .mark {
  color: var(--accent);
}

.sitebar a {
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  padding-bottom: 2px;
  text-decoration: none;
  transition: 150ms ease;
}

.sitebar a:hover,
.sitebar a:focus-visible {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  outline: none;
}

.menu-wrap {
  width: min(calc(100% - 3.5rem), 74rem);
  min-height: calc(100vh - 5.5rem);
  margin: auto;
  padding: 4rem 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(20rem, 22rem);
  align-items: center;
  column-gap: clamp(4rem, 10vw, 10rem);
}

.logo {
  max-width: 50rem;
  color: var(--ink);
  font-size: clamp(3.5rem, 8vw, 6.4rem);
  font-weight: 650;
  letter-spacing: -0.075em;
  line-height: 0.88;
}

.caret {
  display: inline-block;
  width: 0.34em;
  height: 0.7em;
  margin-left: 0.14em;
  background: var(--accent);
  transform: translateY(0.04em);
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.tagline {
  margin-top: 1.8rem;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.94rem;
  letter-spacing: 0.01em;
}

.accent {
  color: var(--accent);
}

.why {
  max-width: 34rem;
  margin-top: 2.4rem;
  color: var(--soft);
  font-size: 1.05rem;
}

.stats {
  display: flex;
  gap: clamp(1.8rem, 5vw, 3.5rem);
  margin-top: 3rem;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat strong {
  color: var(--ink);
  font-size: 1.65rem;
  font-weight: 620;
  letter-spacing: -0.04em;
  line-height: 1.2;
}

.stat span,
.eyebrow {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.menu-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.menu-actions .eyebrow {
  margin-bottom: 0.55rem;
}

.btn {
  min-height: 2.9rem;
  padding: 0.72rem 1rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.93rem;
  font-weight: 600;
  text-align: left;
  transition: 140ms ease;
}

.btn > span {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.btn:hover,
.btn:focus-visible {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  outline: none;
}

.btn:hover > span,
.btn:focus-visible > span {
  color: var(--bg);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.btn.primary:hover,
.btn.primary:focus-visible {
  background: var(--ink);
  border-color: var(--ink);
}

.progress-note {
  margin-top: 0.8rem;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.text-button {
  width: fit-content;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0 0 2px;
}

.text-button:hover,
.text-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

.menu-actions > .text-button {
  margin-top: 0.2rem;
}

.hidden {
  display: none !important;
}

.dim {
  color: var(--dim);
}

/* Chapters */

.topbar {
  position: relative;
}

.topbar h2 {
  position: absolute;
  left: 50%;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  transform: translateX(-50%);
}

.chapter-list {
  width: min(calc(100% - 3.5rem), 74rem);
  margin: 0 auto;
  padding: 4rem 0 6rem;
}

.chapter-card {
  display: grid;
  grid-template-columns: 4rem minmax(13rem, 0.75fr) minmax(15rem, 1fr);
  gap: 2rem;
  padding: 2rem 0;
  border-bottom: 1px solid var(--line);
}

.chapter-card:first-child {
  border-top: 1px solid var(--line);
}

.chapter-number {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.chapter-copy h3 {
  color: var(--ink);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.chapter-copy p {
  margin-top: 0.6rem;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.75rem;
}

.level-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.level-button {
  min-width: 0;
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  color: var(--soft);
  cursor: pointer;
  overflow: hidden;
  padding: 0.55rem 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.8rem;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-button span {
  flex: 0 0 auto;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.68rem;
}

.level-button:hover:not(:disabled),
.level-button:focus-visible:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  outline: none;
}

.level-button:hover:not(:disabled) span,
.level-button:focus-visible:not(:disabled) span {
  color: var(--bg);
}

.level-button.done {
  border-color: var(--faint);
  color: var(--ink);
}

.level-button.done span {
  color: var(--accent);
}

.level-button.boss:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
}

.level-button.boss span {
  color: var(--accent);
}

.level-button:disabled {
  cursor: not-allowed;
  opacity: 0.34;
}

/* Game */

#screen-game {
  height: 100vh;
  overflow: hidden;
}

.crumb {
  display: flex;
  gap: 0.75rem;
}

.game-layout {
  width: min(calc(100% - 3.5rem), 74rem);
  min-height: 0;
  margin: 0 auto;
  padding: 2.25rem 0 2.75rem;
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(19rem, 0.7fr);
  gap: 2rem;
  flex: 1 1 auto;
}

.terminal-pane {
  min-width: 0;
  min-height: 28rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--terminal);
  box-shadow: 0 22px 60px rgb(0 0 0 / 24%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.terminal-head {
  min-height: 2.7rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.7rem;
}

.terminal-head .safe {
  color: var(--faint);
}

.terminal {
  min-height: 0;
  padding: 1.2rem 1.2rem 0;
  flex: 1 1 auto;
  overflow-y: auto;
  color: var(--soft);
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.terminal-entry {
  margin-bottom: 0.85rem;
}

.terminal-command {
  color: var(--ink);
}

.terminal-command .user,
.prompt .user {
  color: var(--accent);
}

.terminal-command .path,
.prompt .path {
  color: var(--ink);
}

.terminal-output {
  color: var(--soft);
}

.terminal-error {
  color: var(--danger);
}

.terminal-suggestions {
  color: var(--dim);
  word-spacing: 0.45rem;
}

.terminal-welcome {
  color: var(--faint);
}

.command-line {
  padding: 0.65rem 1.2rem 1.2rem;
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.88rem;
}

.prompt {
  display: flex;
  flex: 0 0 auto;
  gap: 0;
  cursor: text;
}

.command-line input {
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  caret-color: var(--accent);
  flex: 1 1 auto;
  font-family: var(--mono);
  font-size: 0.88rem;
  outline: none;
}

.mission-pane {
  min-width: 0;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.mission-pane h1 {
  margin-top: 0.8rem;
  color: var(--ink);
  font-size: clamp(2rem, 3vw, 2.7rem);
  font-weight: 620;
  letter-spacing: -0.055em;
  line-height: 0.98;
}

.brief {
  margin-top: 1.2rem;
  color: var(--ink);
  font-size: 1rem;
}

.prompt-copy {
  margin-top: 0.65rem;
  color: var(--dim);
  font-size: 0.88rem;
}

.command-chips {
  margin-top: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.command-chips code,
.success-card code {
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface-2);
  color: var(--accent);
  font-family: var(--mono);
}

.command-chips code {
  padding: 0.24rem 0.48rem;
  font-size: 0.74rem;
}

.lesson {
  margin-top: 1.5rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--dim);
  padding: 0.85rem 0;
}

.lesson summary {
  color: var(--soft);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.72rem;
  list-style: none;
}

.lesson summary::before {
  content: "+ ";
  color: var(--accent);
}

.lesson[open] summary::before {
  content: "− ";
}

.lesson p {
  margin-top: 0.75rem;
  font-size: 0.82rem;
}

.workspace {
  margin-top: 1.5rem;
  border: 1px solid var(--line);
  background: var(--surface);
}

.workspace-head {
  min-height: 2.15rem;
  padding: 0 0.7rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.tree {
  max-height: 8rem;
  overflow-y: auto;
  padding: 0.55rem 0.7rem;
  color: var(--soft);
  font-family: var(--mono);
  font-size: 0.7rem;
  line-height: 1.65;
}

.tree-row {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-row.dir {
  color: var(--accent);
}

.tree-empty {
  color: var(--faint);
}

.hint-button {
  width: 100%;
  margin-top: 0.8rem;
  min-height: 2.45rem;
  background: transparent;
  font-size: 0.8rem;
}

.hint {
  margin-top: 0.65rem;
  color: var(--soft);
  font-family: var(--mono);
  font-size: 0.72rem;
}

/* Validation non bloquante + overlay de l'aide */

.completion-panel {
  display: none;
  margin-top: 1.25rem;
}

.completion-panel.show {
  display: block;
  animation: overlay-in 180ms ease-out;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgb(6 6 7 / 84%);
  backdrop-filter: blur(5px);
}

.overlay.show {
  display: flex;
  animation: overlay-in 180ms ease-out;
}

@keyframes overlay-in {
  from {
    opacity: 0;
  }
}

.success-card,
.cheat-card {
  border: 1px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 2px;
  background: var(--surface);
}

.success-card {
  width: 100%;
  padding: 1.2rem;
}

.success-card h2 {
  margin-top: 0.5rem;
  color: var(--ink);
  font-size: 1.3rem;
  font-weight: 620;
  letter-spacing: -0.035em;
  line-height: 1.15;
}

.success-card code {
  display: block;
  margin-top: 0.9rem;
  padding: 0.55rem 0.65rem;
  overflow-x: auto;
  font-size: 0.8rem;
  white-space: nowrap;
}

.success-actions {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: 0.7fr 1.3fr;
  gap: 0.55rem;
}

.cheat-card {
  width: min(100%, 70rem);
  max-height: calc(100vh - 3rem);
  padding: 2rem;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgb(0 0 0 / 40%);
}

.cheat-card > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2rem;
}

.cheat-card h2 {
  margin-top: 0.55rem;
  color: var(--ink);
  font-size: 2rem;
  font-weight: 620;
  letter-spacing: -0.045em;
}

.cheat-grid {
  margin-top: 2rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.8rem 2.4rem;
}

.cheat-grid section {
  border-top: 1px solid var(--line);
  padding-top: 0.8rem;
}

.cheat-grid h3 {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 400;
  text-transform: lowercase;
}

.cheat-grid dl {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: minmax(5.5rem, 0.8fr) 1.2fr;
  gap: 0.4rem 0.8rem;
}

.cheat-grid dt {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.cheat-grid dd {
  color: var(--dim);
  font-size: 0.76rem;
}

@media (max-width: 860px) {
  .menu-wrap {
    grid-template-columns: 1fr;
    align-content: center;
    gap: 3.5rem;
  }

  .menu-actions {
    width: min(100%, 27rem);
  }

  .chapter-card {
    grid-template-columns: 3rem 1fr;
  }

  .level-list {
    grid-column: 2;
    margin-top: 0.3rem;
  }

  #screen-game {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .terminal-pane {
    min-height: 31rem;
  }

  .mission-pane {
    overflow: visible;
    padding-bottom: 3rem;
  }

  .cheat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .sitebar,
  .topbar,
  .menu-wrap,
  .chapter-list,
  .game-layout {
    width: min(calc(100% - 2rem), 74rem);
  }

  .sitebar,
  .topbar {
    min-height: 4.5rem;
  }

  .sitebar {
    font-size: 0.65rem;
  }

  .menu-wrap {
    min-height: calc(100vh - 4.5rem);
    padding: 3rem 0;
    gap: 3rem;
  }

  .logo {
    font-size: clamp(3.1rem, 16vw, 4.5rem);
  }

  .tagline br {
    display: none;
  }

  .why {
    margin-top: 1.8rem;
    font-size: 0.95rem;
  }

  .stats {
    gap: 1.5rem;
  }

  .stat strong {
    font-size: 1.35rem;
  }

  .stat span {
    font-size: 0.6rem;
  }

  .topbar h2 {
    display: none;
  }

  .chapter-list {
    padding: 2rem 0 4rem;
  }

  .chapter-card {
    grid-template-columns: 2rem minmax(0, 1fr);
    gap: 1rem;
    padding: 1.5rem 0;
  }

  .level-list {
    grid-template-columns: 1fr;
  }

  .game-layout {
    padding: 1rem 0 0;
    gap: 1.75rem;
  }

  .terminal-pane {
    min-height: 27rem;
  }

  .terminal-head {
    padding: 0 0.75rem;
  }

  .terminal,
  .command-line {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    font-size: 0.78rem;
  }

  .prompt .user {
    font-size: 0;
  }

  .prompt .user::after {
    content: "guest";
    font-size: 0.78rem;
  }

  .success-card,
  .cheat-card {
    padding: 1.4rem;
  }

  .success-actions {
    grid-template-columns: 1fr;
  }

  .cheat-card h2 {
    font-size: 1.55rem;
  }

  .cheat-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
