/* Thème « Nuit Braise » : noir pur (OLED), aucune lumière froide, texte blanc chaud. */

@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/space-grotesk-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/space-grotesk-latin-700-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/inter-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/inter-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/jetbrains-mono-latin-500-normal.woff2") format("woff2");
}

:root {
  --bg: #000000;
  --text: #F1E4D4;
  --text-muted: #CDB9A2;
  --text-subtle: #A8957F;
  --accent: #FF7A45;
  --on-accent: #1A0802;
  --line: #33241C;
  --line-strong: #4A2A1A;
  --line-danger: #6B3A26;
  --track: #2A1C14;
  --card-bg: linear-gradient(180deg, #24130A 0%, #0A0503 55%);
  --code-bg: #000000;
  --code-lineno: #6F5A4A;
  --code-string: #F2C46D;
  --code-number: #FF9D75;
  --code-keyword: var(--accent);

  --font-title: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;

  --gap: 22px;
  --pad-x: 20px;
  --max-w: 560px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--bg); }

body {
  color: var(--text);
  font: 400 16px/1.5 var(--font-body);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: var(--font-title); font-weight: 700; margin: 0; }

button, input, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.muted { color: var(--text-muted); font-size: 14px; }

.label {
  font: 700 12px/1.2 var(--font-title);
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-subtle);
}

/* --- Vues --- */

.view {
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding:
    calc(20px + env(safe-area-inset-top))
    calc(var(--pad-x) + env(safe-area-inset-right))
    calc(28px + env(safe-area-inset-bottom))
    calc(var(--pad-x) + env(safe-area-inset-left));
}

/* --- Boutons --- */

.icon-btn {
  position: relative;
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--text);
}

.icon-btn-quiet { border-color: transparent; background: transparent; color: var(--text-subtle); }
.icon-btn-quiet:hover { color: var(--text); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 60px;
  padding: 0 24px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: 700 17px/1.2 var(--font-title);
  letter-spacing: .01em;
  text-align: center;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 0 30px -8px var(--accent);
}

.btn-ghost {
  background: var(--bg);
  border-color: var(--line-strong);
  color: var(--text);
}

.btn-wrong {
  background: var(--bg);
  border: 1.5px solid var(--line-danger);
  color: var(--text);
}

.btn:disabled { opacity: .5; cursor: default; box-shadow: none; }

/* --- Accueil --- */

.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.home-head h1 { font-size: 30px; line-height: 1.1; letter-spacing: -0.02em; }

#start { width: 100%; }

.panel {
  background: var(--card-bg);
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  padding: 20px 22px;
}

.acq-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.acq-value { font: 700 28px/1 var(--font-title); color: var(--text); }

.bar {
  height: 6px;
  border-radius: 3px;
  background: var(--track);
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--accent);
  transition: width .3s ease;
}

.section-title { font-size: 20px; margin-bottom: -8px; }

.theme-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.theme-item {
  width: 100%;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 20px 18px;
  text-align: left;
  background: var(--card-bg);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
}

.theme-item:hover { border-color: var(--line-danger); }

.ti-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.ti-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font: 600 18px/1.3 var(--font-title);
}

.ti-pct { flex: none; font: 500 14px/1 var(--font-mono); color: var(--accent); }

.ti-meta { font-size: 14px; color: var(--text-muted); }

.ti-meta .due { color: var(--text); font-weight: 500; }

/* Bouton compte : pastille d'état de la synchro. */
#account-btn { color: var(--text-subtle); }
#account-btn.signed-in { color: var(--text); }

#account-btn::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: transparent;
  display: none;
}

#account-btn[data-sync="ok"]::after { display: block; background: var(--accent); }
#account-btn[data-sync="pending"]::after { display: block; background: var(--text-subtle); }
#account-btn[data-sync="error"]::after {
  display: block;
  background: var(--bg);
  box-shadow: inset 0 0 0 1.5px var(--text-muted);
}

/* --- Révision --- */

#review {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.review-head {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: none;
}

.progress {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.seg {
  flex: 1;
  min-width: 2px;
  height: 6px;
  border-radius: 3px;
  background: var(--track);
}

.seg.done { background: var(--accent); }

.seg.current {
  background: var(--text);
  box-shadow: 0 0 10px var(--accent);
}

.progress .bar { flex: 1; }

.bonus {
  flex: none;
  margin: -10px 0 -6px;
  font-size: 14px;
  color: var(--text-muted);
}

.bonus strong {
  font: 700 14px/1.3 var(--font-title);
  color: var(--accent);
}

.empty { text-align: center; margin: auto 0; }

.card {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 26px 22px;
  background: var(--card-bg);
  border: 1px solid var(--line-strong);
  border-radius: 28px;
  box-shadow: 0 0 60px -24px var(--accent);
  touch-action: pan-y;
  transition: transform .28s ease, opacity .28s ease;
}

.card.dragging { transition: none; }

.card.revealed { user-select: none; }

.card > :not(.deco):not(.stamp) { position: relative; }

.deco {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

.deco-big { width: 200px; height: 200px; top: -80px; right: -70px; border: 1px solid var(--line-strong); }
.deco-small { width: 120px; height: 120px; top: -30px; right: -30px; border: 1px solid var(--line); }

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: -10px 0 -8px;
}

.theme-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.card-theme {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font: 600 14px/1.3 var(--font-title);
}

.card-type { flex: none; font: 400 12px/1.3 var(--font-mono); color: var(--text-subtle); }

.card-head #delete { margin-left: auto; margin-right: -10px; }

/* Étapes d'une procédure chaînée. */
.steps { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.steps-label { font: 400 12px/1.3 var(--font-mono); color: var(--text-subtle); margin-right: 4px; }

.step {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font: 700 12px/1 var(--font-title);
  background: var(--track);
  color: var(--text-subtle);
}

.step.done { background: var(--accent); color: var(--on-accent); }

.step.current {
  background: var(--bg);
  color: var(--accent);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

/* Question. */
.question { display: flex; flex-direction: column; gap: 14px; }

.q-text {
  margin: 0;
  font: 700 34px/38px var(--font-title);
  letter-spacing: -0.02em;
  text-wrap: pretty;
  overflow-wrap: anywhere;
}

.question.long .q-text { font-size: 28px; line-height: 32px; }

/* Bloc de code : gouttière de numéros à part, pour ne pas couper les balises hljs. */
.code-block {
  display: flex;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  font: 400 15px/26px var(--font-mono);
  color: var(--text);
  touch-action: pan-x pan-y;
}

.code-gutter {
  flex: none;
  padding-right: 14px;
  text-align: right;
  color: var(--code-lineno);
  user-select: none;
}

.code-gutter span { display: block; }

.code-block pre {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow-x: auto;
  font: inherit;
}

.code-block code, .code-line code { font: inherit; background: none; padding: 0; }

/* Coloration highlight.js avec les tokens de la charte. */
.hljs-keyword, .hljs-built_in, .hljs-literal, .hljs-selector-tag, .hljs-type { color: var(--code-keyword); }
.hljs-string, .hljs-regexp, .hljs-template-variable, .hljs-symbol { color: var(--code-string); }
.hljs-number { color: var(--code-number); }
.hljs-comment, .hljs-quote { color: var(--text-subtle); }
.hljs-title, .hljs-function, .hljs-params, .hljs-attr, .hljs-variable, .hljs-meta { color: var(--text-muted); }

/* Champ « Ta réponse » : un bloc de la carte. */
.typed-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#typed {
  width: 100%;
  min-height: 52px;
  resize: vertical;
  padding: 12px 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  font: 400 15px/1.5 var(--font-mono);
  user-select: text;
}

#typed::placeholder { color: var(--text-subtle); }

#typed:read-only { border-style: dashed; color: var(--text-muted); }

/* Réponse, en bas de la carte. */
.answer-box {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 16px;
  animation: reveal .28s ease;
}

.answer-label {
  font: 700 12px/1.2 var(--font-title);
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--accent);
}

.answer { display: flex; flex-direction: column; gap: 10px; }

.a-text { margin: 0; font: 400 18.5px/1.5 var(--font-body); overflow-wrap: anywhere; }

.comment { margin: 0; font: 400 14px/1.5 var(--font-body); color: var(--text-muted); overflow-wrap: anywhere; }

.code-line {
  margin: 0;
  font: 500 22px/1.35 var(--font-mono);
  overflow-wrap: anywhere;
}

.answer .code-block { padding: 14px; }

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

/* Tampon de swipe. */
.stamp {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) rotate(-6deg);
  padding: 4px 14px;
  border: 2px solid currentColor;
  border-radius: 10px;
  font: 700 22px/1.2 var(--font-title);
  letter-spacing: .08em;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}

.stamp.right { color: var(--accent); }
.stamp.wrong { color: var(--text-muted); }

/* Actions. */
.actions { flex: none; }

#reveal { width: 100%; }

.grades { display: flex; gap: 12px; }

.grades .btn { flex: 1; padding: 0 12px; }

/* --- Compte --- */

.dialog {
  width: min(26rem, calc(100% - 2 * var(--pad-x)));
  padding: 26px 22px 22px;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 28px;
  box-shadow: 0 0 60px -24px var(--accent);
}

.dialog::backdrop { background: rgb(0 0 0 / .85); }

.dialog h2 { font-size: 22px; margin: 0 0 12px; }

.dialog p { margin: 0 0 14px; }

.dialog label {
  display: block;
  margin-bottom: 14px;
  font: 600 14px/1.3 var(--font-title);
  color: var(--text-subtle);
}

.dialog input {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 6px;
  padding: 0 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  font: 400 16px/1.4 var(--font-body);
}

.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.dialog-actions .btn { flex: 1 1 10rem; min-height: 52px; }

.dialog-close { position: absolute; top: 12px; right: 12px; }

.form-error {
  color: var(--text);
  font-size: 14px;
  padding-left: 10px;
  border-left: 2px solid var(--accent);
}

/* --- Mouvement réduit --- */

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