/*
 * vim quest — thème « encre ».
 * Palette dérivée de Kanagawa : fond bleu-nuit, accents sakura / vague / automne.
 * Aucune police externe : la pile monospace tape dans ce que Windows a déjà
 * (Cascadia, installée avec Terminal et VS Code), sinon Consolas.
 */

:root {
  --ink-0: #16161d;
  --ink-1: #1f1f28;
  --ink-2: #2a2a37;
  --ink-3: #363646;
  --ink-4: #54546d;

  --fg: #dcd7ba;
  --fg-dim: #a09b83;
  --fg-mute: #6b6a56;

  --sakura: #d27e99;
  --wave: #7aa89f;
  --autumn: #dca561;
  --spring: #98bb6c;
  --crystal: #7e9cd8;
  --violet: #957fb8;
  --blood: #c34043;
  --select: #2d4f67;

  --mono: "Cascadia Code", "Cascadia Mono", "JetBrains Mono", "Fira Code", Consolas, "DejaVu Sans Mono", monospace;
  --radius: 3px;
}

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

html,
body {
  height: 100%;
}

body {
  background: var(--ink-0);
  /* Deux halos très diffus : le fond n'est jamais tout à fait plat. */
  background-image:
    radial-gradient(ellipse 80% 60% at 15% -10%, rgba(126, 156, 216, 0.07), transparent 60%),
    radial-gradient(ellipse 60% 50% at 90% 110%, rgba(210, 126, 153, 0.06), transparent 60%);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.6;
  overflow: hidden;
}

/* Grain : un bruit fixe, très léger, qui casse l'aplat numérique. */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* --------------------------------------------------------------- écrans */

.screen {
  display: none;
  height: 100vh;
  flex-direction: column;
}
.screen.active {
  display: flex;
  animation: fade 0.3s ease;
}
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

/* ----------------------------------------------------------------- menu */

.menu-wrap {
  margin: auto;
  text-align: center;
  padding: 2rem;
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

.logo {
  font-size: clamp(5px, 1.15vw, 12px);
  line-height: 1;
  color: var(--sakura);
  text-shadow: 0 0 18px rgba(210, 126, 153, 0.22);
  margin-bottom: 1.6rem;
  user-select: none;
}

.tagline {
  color: var(--fg-dim);
  margin-bottom: 2.5rem;
  letter-spacing: 0.02em;
}
.accent {
  color: var(--autumn);
}

.stats {
  display: flex;
  justify-content: center;
  gap: 3rem;
  margin-bottom: 2.5rem;
}
.stat {
  display: flex;
  flex-direction: column;
}
.stat-val {
  font-size: 1.7rem;
  color: var(--wave);
  line-height: 1.2;
}
.stat-val.gold {
  color: var(--autumn);
}
.stat-lbl {
  font-size: 0.72rem;
  color: var(--fg-mute);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 22rem;
  margin: 0 auto 2rem;
}

.btn {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--fg);
  background: var(--ink-1);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius);
  padding: 0.7rem 1.2rem;
  cursor: pointer;
  transition: all 0.14s ease;
  text-align: left;
}
.btn:hover {
  background: var(--ink-2);
  border-color: var(--ink-4);
  transform: translateX(3px);
}
.btn.primary {
  background: var(--sakura);
  border-color: var(--sakura);
  color: var(--ink-0);
  font-weight: 700;
}
.btn.primary:hover {
  background: #e08fa8;
  border-color: #e08fa8;
}
.btn.ghost {
  background: transparent;
}
.btn.small {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.link {
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--fg-mute);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2rem;
  transition: color 0.14s;
}
.link:hover {
  color: var(--fg);
}
.link.danger:hover {
  color: var(--blood);
}
.menu-foot .sep {
  color: var(--ink-3);
  margin: 0 0.5rem;
}
.dim {
  color: var(--fg-mute);
}

kbd {
  font-family: inherit;
  font-size: 0.75em;
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-bottom-width: 2px;
  border-radius: var(--radius);
  padding: 0.05em 0.4em;
  color: var(--fg-dim);
  margin-left: 0.2em;
}

/* ------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--ink-2);
  background: rgba(31, 31, 40, 0.5);
}
.topbar h2 {
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--fg-dim);
}
.topbar-right {
  margin-left: auto;
  display: flex;
  gap: 1rem;
}
.crumb {
  display: flex;
  gap: 0.7rem;
  align-items: baseline;
  font-size: 0.9rem;
  color: var(--wave);
}

/* ---------------------------------------------------------- chapitres */

.chapters {
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 62rem;
  width: 100%;
  margin: 0 auto;
}

.chapter {
  border: 1px solid var(--ink-2);
  border-left: 2px solid var(--ink-3);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(42, 42, 55, 0.4), rgba(31, 31, 40, 0.2));
  padding: 1rem 1.2rem;
  animation: rise 0.4s backwards cubic-bezier(0.2, 0.8, 0.2, 1);
  transition: border-color 0.16s;
}
.chapter:hover {
  border-left-color: var(--sakura);
}
.chapter.locked {
  opacity: 0.42;
}
.chapter.locked:hover {
  border-left-color: var(--ink-3);
}

.chapter-head {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.chapter-idx {
  color: var(--ink-4);
  font-size: 1.3rem;
}
.chapter-titles {
  flex: 1;
}
.chapter-title {
  color: var(--fg);
}
.chapter-sub {
  font-size: 0.78rem;
  color: var(--sakura);
  letter-spacing: 0.08em;
}
.chapter-count {
  font-size: 0.8rem;
  color: var(--fg-mute);
}
.chapter-blurb {
  color: var(--fg-dim);
  font-size: 0.84rem;
  line-height: 1.7;
  margin: 0.8rem 0;
  max-width: 60ch;
}
.locked-msg {
  color: var(--fg-mute);
  font-style: italic;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 0.4rem;
}
.level {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.82rem;
  text-align: left;
  color: var(--fg-dim);
  background: var(--ink-1);
  border: 1px solid var(--ink-2);
  border-radius: var(--radius);
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  transition: all 0.12s;
}
.level:hover {
  color: var(--fg);
  border-color: var(--sakura);
  background: var(--ink-2);
}
.level-medal {
  font-size: 0.7rem;
  color: var(--ink-4);
  letter-spacing: -1px;
}
.level.done {
  color: var(--fg);
}
.level.done.or .level-medal {
  color: var(--autumn);
}
.level.done.argent .level-medal {
  color: var(--fg-dim);
}
.level.done.bronze .level-medal {
  color: #a6704a;
}

/* ----------------------------------------------------------------- jeu */

.game {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 24rem;
  gap: 1.5rem;
  padding: 1.5rem;
  overflow: hidden;
  max-width: 84rem;
  width: 100%;
  margin: 0 auto;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pane-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--fg-mute);
  margin-bottom: 0.5rem;
}

.editor {
  flex: 1;
  border: 1px solid var(--ink-3);
  border-radius: var(--radius);
  background: var(--ink-1);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 16rem;
}
.editor.shake {
  animation: shake 0.24s;
  border-color: var(--blood);
}
@keyframes shake {
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}
.editor.flash {
  animation: flash 0.35s;
}
@keyframes flash {
  from {
    border-color: var(--spring);
    box-shadow: 0 0 0 1px var(--spring), 0 18px 50px rgba(152, 187, 108, 0.15);
  }
}

#buffer {
  flex: 1;
  padding: 1rem 0.8rem;
  font-size: 1.05rem;
  line-height: 1.75;
  white-space: pre;
  overflow: auto;
}
.ln {
  min-height: 1.75em;
}
.num {
  display: inline-block;
  width: 3ch;
  margin-right: 1.2ch;
  color: var(--ink-4);
  user-select: none;
}
.cur {
  background: var(--sakura);
  color: var(--ink-0);
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink {
  50% {
    background: rgba(210, 126, 153, 0.45);
  }
}
/* Mode insertion : barre fine à gauche, comme un vrai vim en mode insert. */
.cur-bar {
  background: transparent;
  color: inherit;
  box-shadow: inset 2px 0 0 var(--spring);
  animation: blink-bar 1.1s steps(1) infinite;
}
@keyframes blink-bar {
  50% {
    box-shadow: inset 2px 0 0 rgba(152, 187, 108, 0.35);
  }
}
.sel {
  background: var(--select);
}
.sel-line {
  background: linear-gradient(90deg, rgba(45, 79, 103, 0.55), rgba(45, 79, 103, 0.28));
}
.sel-line .num {
  color: var(--wave);
}

.statusline {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.25rem 0.8rem;
  font-size: 0.8rem;
  background: var(--ink-3);
  border-top: 1px solid var(--ink-2);
}
.statusline .mode {
  font-weight: 700;
  letter-spacing: 0.08em;
}
.statusline .spacer {
  flex: 1;
}
.statusline .pending {
  color: var(--autumn);
  letter-spacing: 0.1em;
}
.statusline .pos {
  color: var(--fg-mute);
}
.statusline .recording {
  color: var(--blood);
  font-size: 0.75rem;
}
.mode-normal .mode {
  color: var(--fg-dim);
}
.mode-insert .mode {
  color: var(--spring);
}
.mode-visual .mode,
.mode-vline .mode,
.mode-vblock .mode {
  color: var(--violet);
}
.mode-cmdline .mode,
.mode-replace .mode {
  color: var(--autumn);
}

.cmdline {
  min-height: 1.7rem;
  padding: 0.15rem 0.8rem;
  font-size: 0.82rem;
  color: var(--fg-mute);
  background: var(--ink-1);
}
.cmdline.active {
  color: var(--autumn);
}

.counter {
  margin-top: 0.8rem;
  font-size: 0.85rem;
  color: var(--fg-mute);
}
#keycount {
  font-size: 1.1rem;
  color: var(--fg);
}
#keycount.good {
  color: var(--spring);
}
#keycount.ok {
  color: var(--autumn);
}
#keycount.over {
  color: var(--blood);
}

/* ------------------------------------------------------------- panneau */

.side {
  overflow-y: auto;
  padding-right: 0.3rem;
}
.side h1 {
  font-size: 1.15rem;
  font-weight: 400;
  color: var(--fg);
  margin-bottom: 0.6rem;
  line-height: 1.35;
}
.brief {
  color: var(--fg-dim);
  font-size: 0.88rem;
  line-height: 1.7;
  margin-bottom: 1rem;
}
.keys {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.8rem;
}
.keys kbd {
  margin: 0;
  background: var(--ink-2);
  color: var(--sakura);
  border-color: var(--ink-4);
  font-size: 0.8rem;
  padding: 0.15em 0.5em;
}
.ban {
  font-size: 0.75rem;
  color: var(--blood);
  opacity: 0.75;
  margin-bottom: 1.2rem;
  min-height: 1em;
}

.target {
  border: 1px dashed var(--ink-3);
  border-radius: var(--radius);
  background: rgba(122, 168, 159, 0.05);
  padding: 0.7rem 0.5rem;
  margin-bottom: 1.2rem;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--wave);
  white-space: pre;
  overflow-x: auto;
}
.target .num {
  color: var(--ink-3);
}
.goal-cursor {
  color: var(--fg-mute);
  font-style: italic;
  font-size: 0.85rem;
}

.lesson {
  border-left: 2px solid var(--crystal);
  background: rgba(126, 156, 216, 0.06);
  border-radius: var(--radius);
  padding: 0.5rem 0.9rem;
  margin-bottom: 1.2rem;
}
.lesson summary {
  cursor: pointer;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--crystal);
  list-style: none;
}
.lesson summary::-webkit-details-marker {
  display: none;
}
.lesson summary::before {
  content: "▸ ";
}
.lesson[open] summary::before {
  content: "▾ ";
}
.lesson p {
  color: var(--fg-dim);
  font-size: 0.84rem;
  line-height: 1.75;
  margin-top: 0.6rem;
}

.mode-tip {
  font-size: 0.72rem;
  color: var(--fg-mute);
}

.solved-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}
.solved-actions .btn {
  text-align: center;
}

.hint {
  margin-top: 0.7rem;
  padding: 0.7rem 0.9rem;
  border-left: 2px solid var(--autumn);
  background: rgba(220, 165, 97, 0.07);
  color: var(--fg-dim);
  font-size: 0.85rem;
  line-height: 1.65;
  animation: fade 0.25s;
}
.hidden {
  display: none !important;
}

.dojo-stats {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
}
.dojo-stats > div {
  display: flex;
  flex-direction: column;
}
.dojo-val {
  font-size: 1.5rem;
  color: var(--wave);
  line-height: 1.2;
}
.dojo-val.gold {
  color: var(--autumn);
}

/* -------------------------------------------------------------- victoire */

.solved {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(22, 22, 29, 0.82);
  backdrop-filter: blur(3px);
  z-index: 50;
}
.solved.show {
  display: grid;
  animation: fade 0.2s;
}
.solved-card {
  text-align: center;
  padding: 2.5rem 3rem;
  border: 1px solid var(--ink-3);
  border-radius: var(--radius);
  background: var(--ink-1);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  animation: pop 0.32s cubic-bezier(0.2, 1.2, 0.3, 1);
}
@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(8px);
  }
}
.medal {
  font-size: 2rem;
  letter-spacing: 0.15em;
  margin-bottom: 0.5rem;
}
.medal.or {
  color: var(--autumn);
  text-shadow: 0 0 24px rgba(220, 165, 97, 0.4);
}
.medal.argent {
  color: var(--fg-dim);
}
.medal.bronze {
  color: #a6704a;
}
.score {
  font-size: 1.05rem;
  color: var(--fg);
  margin-bottom: 0.4rem;
}
.verdict {
  color: var(--fg-dim);
  font-size: 0.85rem;
  max-width: 32ch;
  margin: 0 auto 1.5rem;
  line-height: 1.65;
}

/* --------------------------------------------------------- aide-mémoire */

.cheatsheet {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(22, 22, 29, 0.85);
  backdrop-filter: blur(3px);
  z-index: 60;
  padding: 2rem;
}
.cheatsheet.show {
  display: grid;
  animation: fade 0.2s;
}
.cheat-card {
  width: 100%;
  max-width: 66rem;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--ink-1);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius);
  padding: 1.5rem 2rem 2rem;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.cheat-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.2rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--ink-2);
}
.cheat-card h2 {
  font-size: 1rem;
  font-weight: 400;
  color: var(--sakura);
}
.cheat-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: 2rem;
}
.cheat-cols h3 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--wave);
  margin: 1.2rem 0 0.5rem;
}
.cheat-cols h3:first-child {
  margin-top: 0;
}
.cheat-cols dl {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  gap: 0.15rem 0.6rem;
  font-size: 0.82rem;
}
.cheat-cols dt {
  color: var(--autumn);
}
.cheat-cols dd {
  color: var(--fg-dim);
}
.cheat-note {
  font-size: 0.78rem;
  color: var(--fg-mute);
  margin-top: 0.6rem;
  line-height: 1.6;
}
.cheat-note b {
  color: var(--fg-dim);
  font-weight: 400;
}

/* Sous 1000px la colonne latérale passe au-dessus de l'éditeur. */
@media (max-width: 1000px) {
  .game {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .side {
    order: -1;
    max-height: 40vh;
  }
}
