:root {
  --bg: #0f1220;
  --bg2: #171b2e;
  --card: #1d2237;
  --card2: #252b45;
  --ink: #eef1fb;
  --ink-soft: #aab2cf;
  --line: #333a5a;
  --accent: #8b6cf0;
  --accent2: #4bd0c4;
  --ok: #58d58a;
  --warn: #ffb257;
  --danger: #ff6b7d;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eaeef8; --bg2: #f6f8ff; --card: #ffffff; --card2: #f1f4fd;
    --ink: #1a1f33; --ink-soft: #59637f; --line: #d9deef;
    --shadow: 0 10px 30px rgba(30,40,80,.12);
  }
  .chip, .why { color: #1a1f33; background: rgba(255,255,255,.82); }
  .chip .v, .why p { color: #1a1f33; }
}

* { 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(1200px 700px at 80% -10%, rgba(139,108,240,.18), transparent 60%), var(--bg);
  color: var(--ink);
  overflow: hidden;
}

.topbar {
  display: flex; align-items: baseline; gap: 14px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(139,108,240,.10), transparent);
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
.topbar h1 .gem { color: var(--accent2); }
.topbar .tag { color: var(--ink-soft); font-size: 13px; }
.topbtn { margin-left: auto; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--accent2); background: rgba(75,208,196,.14); color: var(--ink); font-weight: 700; font-size: 13px; cursor: pointer; }
.topbtn:hover { filter: brightness(1.1); }

/* ---- module flocon de neige ---- */
#snow { position: absolute; inset: 0; z-index: 9; display: none; background: radial-gradient(1000px 700px at 40% 0%, rgba(75,120,220,.22), transparent 60%), #0a0e20; }
#snow.open { display: flex; flex-direction: column; }
#snow .asm-head { position: relative; z-index: 3; }
#snow .asm-title { color: #eaf0ff; }
.snow-body { flex: 1; display: flex; min-height: 0; }
.snow-left { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; padding: 8px 12px 16px; }
#flakeCanvas { max-width: 100%; max-height: calc(100vh - 230px); border-radius: 16px; }
.snow-caption { margin-top: 12px; background: rgba(10,14,32,.82); border: 1px solid var(--accent2); border-radius: 14px; padding: 10px 18px; color: #eaf0ff; font-size: 15px; font-weight: 700; text-align: center; max-width: 620px; }
.snow-panel { width: 486px; flex: none; overflow-y: auto; padding: 12px 16px 20px; border-left: 1px solid var(--line); background: rgba(12,16,34,.55); }
.snow-diag-title { font-size: 13px; font-weight: 700; color: #eaf0ff; margin-bottom: 4px; }
.snow-draw-hint { font-size: 12px; color: var(--accent2); margin-bottom: 8px; }
.snow-draw-hint b { color: #eaf0ff; }
#diagCanvas { width: 440px; max-width: 100%; height: 340px; background: #0c1024; border-radius: 10px; border: 1px solid var(--line); cursor: crosshair; touch-action: none; display: block; }
.snow-tips { margin-top: 12px; background: rgba(139,108,240,.10); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.snow-tips-title { font-size: 13px; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.snow-tips ul { margin: 0; padding-left: 18px; }
.snow-tips li { font-size: 12px; color: var(--ink-soft); line-height: 1.55; margin-bottom: 3px; }
.snow-tips li b { color: #eaf0ff; }
.snow-note { font-size: 11.5px; color: var(--ink-soft); line-height: 1.5; margin-top: 10px; }
.snow-note b { color: #cfe0ff; }
.snow-controls { margin-top: 14px; display: flex; gap: 10px; }

.layout { display: grid; grid-template-columns: 360px 1fr; height: calc(100vh - 52px); }
#sidebar { overflow-y: auto; padding: 16px; border-right: 1px solid var(--line); background: var(--bg2); }
#stage { position: relative; overflow: hidden; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 10px; font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-soft); display: flex; align-items: center; gap: 8px; }
.card h2 .num { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; }

/* ---- sélecteur de formule ---- */
.mini-label { font-size: 12px; color: var(--ink-soft); display: block; margin: 2px 0 6px; }
.ptable-or { margin-top: 12px; }
#formula {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card2); color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer;
  appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px; background-size: 5px 5px; background-repeat: no-repeat;
}
#identified { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 5px; }
#identified .atom { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 8px; background: var(--card2); border: 1px solid var(--accent); }
#identified .atom small { font-weight: 500; color: var(--ink-soft); }

/* ---- tableau périodique ---- */
#ptable { display: grid; grid-template-columns: repeat(18, 1fr); gap: 3px; }
.el {
  aspect-ratio: 1 / 1; border: 1px solid var(--line); border-radius: 6px;
  background: var(--card2); color: var(--ink-soft);
  font-size: 11px; font-weight: 700; cursor: pointer; position: relative;
  display: grid; place-items: center; padding: 0; transition: transform .08s, background .12s;
  user-select: none;
}
.el:hover { transform: translateY(-2px); }
.el .z { position: absolute; top: 2px; left: 3px; font-size: 7px; font-weight: 500; opacity: .6; }
.el.key { color: var(--ink); border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(139,108,240,.35); }
.el.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.el.dim { opacity: .38; }
.legend-cat { font-size: 11px; color: var(--ink-soft); margin-top: 8px; }

#recipe { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--card2); font-size: 13px; min-height: 20px; border: 1px dashed var(--line); }
#recipe.ok { border-color: var(--ok); background: rgba(88,213,138,.12); }
#recipe.indice { border-color: var(--warn); background: rgba(255,178,87,.10); }
#recipe b { color: var(--ink); }

/* ---- curseurs ---- */
.slider { margin: 12px 0; }
.slider label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.slider label .val { color: var(--accent2); font-variant-numeric: tabular-nums; font-weight: 700; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.controls-row { display: flex; gap: 8px; margin-top: 8px; }
button.btn {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card2); color: var(--ink); font-weight: 700; cursor: pointer; font-size: 13px;
}
button.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.btn:hover { filter: brightness(1.08); }
button.btn:disabled { opacity: .4; cursor: default; }
.timeflow { margin-top: 8px; font-size: 12px; color: var(--ink-soft); text-align: center; }

/* ---- scène ---- */
#view { width: 100%; height: 100%; display: block; cursor: grab; }
#view:active { cursor: grabbing; }

.hud { position: absolute; top: 16px; left: 16px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.chip { background: rgba(15,18,32,.72); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; backdrop-filter: blur(6px); color: #fff; }
.chip .k { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; opacity: .7; }
.chip .v { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.chip .v small { font-size: 12px; font-weight: 600; opacity: .8; }

#stab { position: absolute; top: 16px; right: 16px; padding: 8px 12px; border-radius: 12px; font-size: 12px; font-weight: 700; display: none; color: #fff; }
#stab.diamond { display: block; background: rgba(75,208,196,.22); border: 1px solid var(--accent2); }
#stab.graphite { display: block; background: rgba(255,107,125,.2); border: 1px solid var(--danger); }

.hint-rotate { position: absolute; bottom: 14px; right: 16px; font-size: 11px; color: var(--ink-soft); pointer-events: none; }

.mass-chart { position: absolute; top: 16px; right: 16px; width: 296px; background: rgba(15,18,32,.78); border: 1px solid var(--line); border-radius: 14px; padding: 10px 8px 6px; backdrop-filter: blur(8px); display: none; }
.mass-chart.on { display: block; }
.mass-chart .mc-title { font-size: 12px; font-weight: 700; color: #fff; margin: 0 6px 6px; }
.mass-chart canvas { width: 280px; height: 150px; display: block; }
#stab.diamond ~ .mass-chart, #stab.graphite ~ .mass-chart { top: 58px; }

/* ---- panneau explication ---- */
.explain { position: absolute; left: 16px; bottom: 16px; max-width: 520px; }
.why { background: rgba(15,18,32,.78); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; backdrop-filter: blur(8px); color: #fff; }
.why h3 { margin: 0 0 6px; font-size: 14px; color: var(--accent2); }
.why p { margin: 0; font-size: 13px; line-height: 1.5; color: #e6e9f6; }
.more-btn { margin-top: 10px; }

/* ---- tiroir avancé ---- */
#advanced {
  position: absolute; top: 0; right: 0; height: 100%; width: 380px; transform: translateX(102%);
  transition: transform .28s ease; background: var(--bg2); border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(0,0,0,.3); overflow-y: auto; padding: 16px; z-index: 5;
}
#advanced.open { transform: translateX(0); }
#advanced h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-soft); margin: 0 0 10px; }
#advanced .close { float: right; cursor: pointer; border: none; background: none; color: var(--ink-soft); font-size: 20px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; margin: 5px 0; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(255,255,255,.3); flex: none; }
.legend-item .ml { color: var(--ink-soft); }
.formula { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; background: var(--card2); padding: 10px; border-radius: 8px; line-height: 1.7; }
.caveats { font-size: 11.5px; color: var(--ink-soft); line-height: 1.5; }
.caveats li { margin-bottom: 5px; }
.toggle-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 8px 0; }
#ptcanvas { width: 100%; height: 200px; background: var(--card); border-radius: 8px; border: 1px solid var(--line); }
.rate-charts { display: flex; gap: 8px; }
.rate-charts > div { flex: 1; }
.rate-charts canvas { width: 100%; height: 120px; background: var(--card); border-radius: 8px; border: 1px solid var(--line); }
.rate-cap { font-size: 10px; color: var(--ink-soft); text-align: center; margin-bottom: 3px; }
.section { margin-bottom: 18px; }
.section > h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--accent); margin: 0 0 8px; }
.factline { font-size: 12px; color: var(--ink-soft); margin: 3px 0; }
.factline b { color: var(--ink); }

/* ---- overlay animation atomique ---- */
#assembly {
  position: absolute; inset: 0; z-index: 8; display: none;
  background: radial-gradient(1000px 600px at 50% 0%, rgba(139,108,240,.18), transparent 60%), var(--bg);
}
#assembly.open { display: block; }
#atomView { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#atomView:active { cursor: grabbing; }
.asm-head { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; z-index: 2; pointer-events: none; }
.asm-title { font-weight: 800; font-size: 15px; color: var(--ink); }
.asm-head .close { pointer-events: auto; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 18px; border-radius: 10px; width: 36px; height: 36px; }
.asm-overlay { position: absolute; left: 0; right: 0; bottom: 84px; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 20px; pointer-events: none; z-index: 2; }
.asm-caption { background: rgba(15,18,32,.8); color: #fff; border: 1px solid var(--accent); border-radius: 14px; padding: 12px 18px; font-size: 16px; font-weight: 700; max-width: 640px; text-align: center; backdrop-filter: blur(6px); }
.asm-note { color: var(--ink-soft); font-size: 12px; max-width: 560px; text-align: center; }
.asm-breath { margin-top: 6px; font-size: 12px; font-weight: 700; color: #fff; background: rgba(75,208,196,.18); border: 1px solid var(--accent2); border-radius: 10px; padding: 5px 12px; }
.asm-legend { position: absolute; top: 60px; left: 18px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.asm-legend .li { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink); background: rgba(15,18,32,.5); padding: 3px 8px; border-radius: 8px; }
.asm-legend .dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(255,255,255,.4); }
.asm-radii-note { position: absolute; top: 60px; right: 18px; font-size: 11px; color: var(--ink-soft); background: rgba(15,18,32,.5); padding: 4px 8px; border-radius: 8px; z-index: 2; }
.asm-btns { display: flex; gap: 8px; }
.asm-controls { position: absolute; bottom: 20px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 2; }
.asm-dots { display: flex; gap: 10px; }
.asm-dots span { width: 26px; height: 6px; border-radius: 3px; background: var(--line); transition: background .2s; }
.asm-dots span.active { background: var(--accent); }
#assembly .hint-rotate { z-index: 2; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #sidebar { max-height: 42vh; border-right: none; border-bottom: 1px solid var(--line); }
  #advanced { width: 100%; }
  .explain { max-width: calc(100% - 32px); }
}

/* ============================================================
   PARCOURS GUIDÉ « why-are-snowflakes-unique »
   ============================================================ */
.journey-body { height: auto; min-height: 100vh; overflow-y: auto; }
.journey-body .topbar { flex-wrap: wrap; gap: 10px; }
.journey-body .topbar h1 { font-size: 17px; line-height: 1.25; }
.journey-body .topbar .tag { flex-basis: 100%; }

#noDataBar { background: rgba(75,208,196,.12); border-bottom: 1px solid var(--line); color: var(--ink-soft); font-size: 12.5px; padding: 8px 20px; text-align: center; }

#stepper { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding: 14px 16px 4px; }
.step-dot { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card2); color: var(--ink-soft); cursor: pointer; display: grid; place-items: center; font-size: 18px; padding: 0; }
.step-dot.current { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139,108,240,.25); color: var(--ink); }
.step-dot.done { background: rgba(88,213,138,.18); border-color: var(--ok); color: #fff; }
.step-dot.locked { opacity: .4; cursor: default; }

#journey { max-width: 880px; margin: 0 auto; padding: 8px 16px 40px; }
#stepCard { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px 22px; box-shadow: var(--shadow); }
.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.step-emoji { font-size: 30px; }
.step-head h2 { margin: 0; font-size: 20px; }
.step-viz { display: flex; flex-direction: column; align-items: center; margin: 6px 0 14px; }
.viz-canvas { width: 100%; max-width: 620px; height: auto; background: #0d1230; border-radius: 12px; border: 1px solid var(--line); }
.step-intro { font-size: 15px; line-height: 1.6; color: var(--ink); }
.step-comps { margin: 12px 0; font-size: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cc-label { color: var(--ink-soft); font-weight: 700; }
.cchip { display: inline-flex; align-items: center; gap: 6px; background: var(--card2); border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px; font-size: 11.5px; }
.badge { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 8px; }
.badge.fr { background: rgba(139,108,240,.28); color: #cbb8ff; }
.badge.int { background: rgba(75,208,196,.22); color: #9fe9df; }

.step-valid { margin: 16px 0 4px; }
.valid-q { font-weight: 700; margin-bottom: 8px; }
.valid-opts { display: flex; flex-direction: column; gap: 8px; max-width: 560px; }
.opt { text-align: left; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card2); color: var(--ink); cursor: pointer; font-size: 14px; }
.opt:hover { border-color: var(--accent); }
.opt.ok { background: rgba(88,213,138,.22); border-color: var(--ok); }
.opt.bad { background: rgba(255,107,125,.18); border-color: var(--danger); opacity: .7; }
.opt.sel { border-color: var(--accent); background: rgba(139,108,240,.18); }
.valid-explain.ok { color: var(--ok); margin-top: 8px; font-weight: 600; }

.step-nav { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.btn.big { padding: 12px 20px; font-size: 15px; }
.btn.pulse { animation: jpulse 1.1s ease infinite; }
@keyframes jpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(139,108,240,.5); } 50% { box-shadow: 0 0 0 6px rgba(139,108,240,0); } }

.cond-sliders { display: flex; gap: 22px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }
.cond-sliders label { font-size: 13px; display: flex; flex-direction: column; gap: 4px; color: var(--ink); }
.cond-sliders input[type=range] { width: 180px; accent-color: var(--accent); }

.jgrow { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
#jflake { background: #0b1024; border-radius: 12px; max-width: 100%; height: auto; }
.jgrow-side { width: 360px; max-width: 100%; }
#jdiag { width: 360px; max-width: 100%; height: 260px; background: #0c1024; border-radius: 8px; border: 1px solid var(--line); cursor: crosshair; touch-action: none; display: block; }
.jgrow-hint { font-size: 12px; color: var(--accent2); margin-bottom: 6px; }
.jcap { margin: 8px 0; font-weight: 700; font-size: 14px; background: rgba(10,14,32,.5); border-radius: 8px; padding: 6px 10px; }

.quiz { display: flex; flex-direction: column; gap: 16px; margin: 12px 0 18px; }
.quiz-title { font-weight: 700; margin-bottom: 8px; }

#footer { text-align: center; font-size: 12px; color: var(--ink-soft); padding: 16px; border-top: 1px solid var(--line); }

.side-panel { position: fixed; top: 0; right: 0; height: 100%; width: 440px; max-width: 100%; transform: translateX(102%); transition: transform .28s ease; background: var(--bg2); border-left: 1px solid var(--line); box-shadow: -12px 0 40px rgba(0,0,0,.3); overflow-y: auto; padding: 18px 20px 40px; z-index: 20; }
.side-panel.open { transform: translateX(0); }
.side-panel h2 { margin-top: 0; font-size: 18px; }
.side-panel .close { position: absolute; top: 12px; right: 12px; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 18px; border-radius: 10px; width: 34px; height: 34px; }
.panel-note { font-size: 12px; color: var(--ink-soft); line-height: 1.5; }
.about-block { margin-bottom: 16px; }
.about-block h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--accent); margin: 14px 0 6px; }
.about-block p { font-size: 13px; line-height: 1.55; }
.about-block code { background: var(--card2); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.prompt-box { background: #0c1024; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow: auto; color: var(--ink); line-height: 1.5; }
.sources { font-size: 11.5px; color: var(--ink-soft); padding-left: 18px; line-height: 1.5; }
.comp-count { font-weight: 700; margin-bottom: 10px; color: var(--accent2); }
.comp-row { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; padding: 4px 0; color: var(--ink-soft); }
.comp-row.got { color: var(--ink); }
.comp-check { color: var(--ok); font-weight: 700; }
.comp-socle { font-size: 10px; background: var(--card2); padding: 0 5px; border-radius: 6px; color: var(--ink-soft); }
.side-panel h3 { font-size: 13px; margin: 14px 0 6px; }

@media (max-width: 620px) {
  .step-nav { justify-content: stretch; }
  .step-nav .btn { flex: 1; }
}

/* --- corrections parcours : liens boutons + nav non étirée --- */
a.btn { display: inline-block; text-align: center; text-decoration: none; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card2); color: var(--ink); font-weight: 700; font-size: 13px; cursor: pointer; }
a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
a.btn:hover { filter: brightness(1.08); }
.step-nav .btn, .step-valid .btn, #journey .about-block .btn { flex: 0 0 auto; }
.step-viz .btn { flex: 0 0 auto; }
