:root{
    --ink:#12101f;
    --ink-2:#1b1830;
    --parchment:#e8ddc8;
    --parchment-dim:#a99e8a;
    --candle:#e8b34b;
    --glass:#cfe4ef;
    --danger:#c0564b;
    --unit-h:43px; /* hauteur d'une unité de fiole ; la hauteur totale suit --cap (capacité du monde) */
    --anim-speed:1; /* multiplicateur de durée du versement ; un peu plus rapide à chaque monde */
  }
  *{ box-sizing:border-box; margin:0; padding:0; -webkit-tap-highlight-color:transparent; }
  html,body{ min-height:100%; }
  body{
    font-family:'Jost',sans-serif;
    background:
      radial-gradient(1200px 600px at 50% -10%, rgba(232,179,75,.14), transparent 60%),
      radial-gradient(900px 500px at 15% 110%, rgba(90,60,140,.20), transparent 60%),
      var(--ink);
    color:var(--parchment);
    min-height:100%;
    display:flex; flex-direction:column; align-items:center;
    overflow-x:hidden;
    user-select:none;
    transition:background .5s ease;
  }

  /* ---------- décors des cinq mondes ----------
     Chaque monde a sa PROPRE couleur de fond de base (pas var(--ink) partagé) :
     les dégradés radiaux, en grande partie hors écran, ne suffisaient pas à
     rendre la différence visible — c'est cette base pleine qui porte la teinte. */
  body.world-1{ background:
    radial-gradient(1200px 600px at 50% -10%, rgba(70,210,150,.22), transparent 60%),
    radial-gradient(900px 500px at 15% 110%, rgba(25,110,70,.28), transparent 60%),
    #0e1f16;
  }
  body.world-2{ background:
    radial-gradient(1200px 600px at 50% -10%, rgba(195,95,215,.22), transparent 60%),
    radial-gradient(900px 500px at 15% 110%, rgba(110,30,130,.30), transparent 60%),
    #1c1128;
  }
  body.world-3{ background:
    radial-gradient(1200px 600px at 50% -10%, rgba(235,110,50,.24), transparent 60%),
    radial-gradient(900px 500px at 15% 110%, rgba(150,40,25,.30), transparent 60%),
    #23120c;
  }
  body.world-4{ background:
    radial-gradient(1200px 600px at 50% -10%, rgba(60,150,235,.24), transparent 60%),
    radial-gradient(900px 500px at 15% 110%, rgba(20,65,150,.30), transparent 60%),
    #0b1a2c;
  }
  body.world-5{ background:
    radial-gradient(1200px 600px at 50% -10%, rgba(255,213,120,.30), transparent 60%),
    radial-gradient(900px 500px at 15% 110%, rgba(190,150,60,.24), transparent 60%),
    #241c0a;
  }

  /* ---------- entête ---------- */
  header{
    text-align:center; padding:22px 16px 6px;
    flex-shrink:0;
  }
  h1{
    font-family:'IM Fell English SC',serif;
    font-weight:400;
    font-size:clamp(1.7rem, 5vw, 2.6rem);
    letter-spacing:.06em;
    color:var(--candle);
    text-shadow:0 0 24px rgba(232,179,75,.35);
  }
  .subtitle{
    color:var(--parchment-dim);
    font-weight:300; font-size:.95rem; letter-spacing:.04em;
    margin-top:2px;
  }

  /* ---------- barre d'état ---------- */
  .hud{
    display:flex; gap:18px 22px; align-items:baseline; flex-wrap:wrap; justify-content:center;
    margin:14px 12px 4px; font-size:.95rem;
    flex-shrink:0;
  }
  .hud .stat{ color:var(--parchment-dim); letter-spacing:.05em; }
  .hud .stat b{ color:var(--parchment); font-weight:600; font-size:1.1rem; margin-left:6px; }

  /* ---------- plateau ---------- */
  #board{
    display:flex; flex-wrap:wrap; justify-content:center; align-content:center;
    gap:24px 10px;
    padding:34px 14px 20px;
    max-width:760px;
    min-height:340px;
    flex-shrink:0;
    /* Largeur de fiole calculée pour que --cols colonnes tiennent toujours sur
       une ligne, quel que soit le nombre de fioles du niveau : au pire (2
       lignes max), --cols = ceil(total / 2) est fourni par JS (voir render()).
       40px = marges de sécurité (padding du plateau + garde anti-scrollbar),
       10px = l'écart horizontal entre fioles ci-dessus (doit rester égal). */
    --vial-w: clamp(20px, calc((100vw - 40px - (var(--cols, 5) - 1) * 10px) / var(--cols, 5)), 58px);
  }

  .vial{
    position:relative;
    width:var(--vial-w, 58px); height:calc(var(--unit-h) * var(--cap, 4) + 18px);
    cursor:pointer;
    transition:transform .22s cubic-bezier(.34,1.56,.64,1), width .2s ease;
    filter:drop-shadow(0 10px 14px rgba(0,0,0,.45));
  }
  .vial.selected{ transform:translateY(-16px); }
  .vial.selected .tube{
    box-shadow:0 0 0 2px var(--candle), 0 0 26px rgba(232,179,75,.45);
  }
  .vial.pour-shake{ animation:shake .3s; }
  @keyframes shake{
    25%{ transform:translateX(-4px);} 50%{ transform:translateX(4px);}
    75%{ transform:translateX(-3px);}
  }

  /* fiole volante pendant le versement */
  .vial.ghost{
    position:fixed; z-index:9; margin:0;
    pointer-events:none;
    transition:left calc(.34s * var(--anim-speed, 1)) ease, top calc(.34s * var(--anim-speed, 1)) ease,
               transform calc(.3s * var(--anim-speed, 1)) cubic-bezier(.45,0,.35,1);
    transform-origin:50% 4px; /* pivote autour du goulot */
  }
  /* filet de liquide versé */
  .stream{
    position:fixed; width:5px; z-index:8;
    border-radius:3px;
    transform-origin:50% 0;
    animation:streamIn calc(.18s * var(--anim-speed, 1)) ease;
    box-shadow:0 0 8px rgba(255,255,255,.25);
  }
  .stream.ending{ transform:scaleY(0); transition:transform calc(.16s * var(--anim-speed, 1)) ease-in; }
  @keyframes streamIn{ from{ transform:scaleY(0);} }
  .splash{
    position:fixed; z-index:8; width:5px; height:5px; border-radius:50%;
    pointer-events:none;
    animation:splash calc(.5s * var(--anim-speed, 1)) ease-out forwards;
  }
  @keyframes splash{
    to{ transform:translate(var(--dx), var(--dy)) scale(.2); opacity:0; }
  }

  .neck{
    position:absolute; top:0; left:50%; transform:translateX(-50%);
    width:calc(var(--vial-w, 58px) * 0.586); height:16px;
    border:2px solid rgba(207,228,239,.55); border-bottom:none;
    border-radius:8px 8px 0 0;
    background:rgba(207,228,239,.06);
  }
  .lip{
    position:absolute; top:-4px; left:50%; transform:translateX(-50%);
    width:calc(var(--vial-w, 58px) * 0.759); height:7px;
    border-radius:5px;
    background:linear-gradient(180deg, rgba(207,228,239,.5), rgba(207,228,239,.15));
  }
  .tube{
    position:absolute; top:14px; left:50%; transform:translateX(-50%);
    width:calc(var(--vial-w, 58px) * 0.897); height:calc(var(--unit-h) * var(--cap, 4));
    border:2px solid rgba(207,228,239,.5);
    border-radius:14px 14px 26px 26px;
    background:rgba(207,228,239,.05);
    overflow:hidden;
    transition:box-shadow .2s, width .2s ease;
  }
  /* reflet de verre */
  .tube::after{
    content:""; position:absolute; inset:0;
    background:linear-gradient(105deg,
      transparent 12%, rgba(255,255,255,.20) 18%, rgba(255,255,255,.05) 26%,
      transparent 34%);
    pointer-events:none;
  }
  .liquids{
    position:absolute; left:0; right:0; bottom:0; top:0;
    display:flex; flex-direction:column; justify-content:flex-end;
  }
  .seg{
    width:100%;
    height:0%;
    transition:height calc(.32s * var(--anim-speed, 1)) ease;
    position:relative;
    display:flex; align-items:center; justify-content:center;
  }
  .seg .glyph{
    font-size:.82rem; line-height:1;
    color:rgba(255,255,255,.92);
    text-shadow:0 1px 1px rgba(0,0,0,.55);
    opacity:0; transition:opacity .15s;
    pointer-events:none;
  }
  /* fond très clair (ex. nacre) : un glyphe blanc y serait illisible */
  .seg .glyph.dark{
    color:#2a2010;
    text-shadow:0 1px 2px rgba(255,255,255,.6);
  }
  body.symbols .seg .glyph{ opacity:1; }
  .seg.topmost::before{
    content:""; position:absolute; top:0; left:0; right:0; height:5px;
    background:rgba(255,255,255,.28);
    border-radius:50% 50% 0 0 / 100% 100% 0 0;
  }
  .vial.done .tube{
    box-shadow:0 0 0 2px rgba(232,179,75,.65), 0 0 18px rgba(232,179,75,.35);
  }
  .vial.done::after{
    content:"✦";
    position:absolute; top:-22px; left:50%; transform:translateX(-50%);
    color:var(--candle); font-size:.9rem;
    animation:twinkle 1.6s infinite;
  }
  @keyframes twinkle{ 50%{ opacity:.3; transform:translateX(-50%) scale(.8);} }

  /* fiole d'appoint (monde 2+) : capacité croissante (1 à 4 selon le monde),
     hors solveur et hors condition de victoire — juste un outil optionnel
     pour le joueur. */
  .vial.bonus .tube{
    border-style:dashed;
    border-color:rgba(232,179,75,.75);
    box-shadow:0 0 16px rgba(232,179,75,.18);
  }
  .bonus-tag{
    position:absolute; top:-34px; left:50%; transform:translateX(-50%);
    font-size:.62rem; letter-spacing:.08em; text-transform:uppercase;
    color:var(--candle); white-space:nowrap;
  }

  /* ---------- panneau solution ---------- */
  #solutionPanel{
    display:none;
    max-width:680px; margin:0 auto; padding:10px 18px;
    text-align:center; color:var(--parchment-dim);
    font-size:.85rem; letter-spacing:.02em; line-height:1.6;
    flex-shrink:0;
  }
  #solutionPanel.show{ display:block; }
  #solutionPanel b{ color:var(--candle); font-weight:600; }
  .vial.sol-from .tube, .vial.sol-to .tube{
    box-shadow:0 0 0 2px var(--candle), 0 0 22px rgba(232,179,75,.5);
  }
  .vial.sol-from{ transform:translateY(-10px); }

  /* ---------- boutons ---------- */
  .controls{
    display:flex; gap:12px; padding:6px 0 30px; flex-wrap:wrap; justify-content:center;
    flex-shrink:0;
  }
  .level-nav{ gap:10px; align-items:center; padding-top:0; }
  .level-nav label{
    color:var(--parchment-dim); font-size:.9rem; letter-spacing:.05em;
  }
  #levelInput{
    width:64px; text-align:center;
    font-family:'Jost',sans-serif; font-size:.95rem; font-weight:500;
    color:var(--parchment); background:var(--ink-2);
    border:1px solid rgba(232,221,200,.28); border-radius:10px;
    padding:9px 4px;
  }
  #levelInput:focus-visible{ outline:2px solid var(--candle); outline-offset:2px; }
  button{
    font-family:'Jost',sans-serif;
    font-size:.95rem; font-weight:500; letter-spacing:.05em;
    padding:10px 22px;
    color:var(--parchment);
    background:var(--ink-2);
    border:1px solid rgba(232,221,200,.28);
    border-radius:10px;
    cursor:pointer;
    transition:border-color .15s, background .15s, transform .1s;
  }
  button:hover{ border-color:var(--candle); background:#241f3e; }
  button:active{ transform:scale(.96); }
  button:disabled{ opacity:.35; cursor:default; }
  button.primary{
    background:linear-gradient(180deg, #e8b34b, #c98f2c);
    color:#241a05; border-color:transparent; font-weight:600;
  }
  button.primary:hover{ filter:brightness(1.07); }
  button:focus-visible{ outline:2px solid var(--candle); outline-offset:2px; }

  /* ---------- victoire ---------- */
  #overlay{
    position:fixed; inset:0;
    background:rgba(10,8,20,.78);
    backdrop-filter:blur(4px);
    display:none; align-items:center; justify-content:center;
    z-index:10;
  }
  #overlay.show{ display:flex; }
  .scroll-card{
    background:linear-gradient(180deg, #221d3a, #171331);
    border:1px solid rgba(232,179,75,.5);
    border-radius:16px;
    padding:38px 46px;
    text-align:center;
    box-shadow:0 0 60px rgba(232,179,75,.18);
    animation:pop .4s cubic-bezier(.34,1.56,.64,1);
  }
  @keyframes pop{ from{ transform:scale(.7); opacity:0; } }
  .scroll-card h2{
    font-family:'IM Fell English SC',serif; font-weight:400;
    font-size:2rem; color:var(--candle); margin-bottom:6px;
  }
  .scroll-card p{ color:var(--parchment-dim); margin-bottom:22px; }

  .spark{
    position:fixed; width:8px; height:8px; border-radius:50%;
    pointer-events:none; z-index:11;
    animation:fall linear forwards;
  }
  @keyframes fall{
    to{ transform:translateY(110vh) rotate(540deg); opacity:.1; }
  }

  @media (max-width:480px){
    :root{ --unit-h:37px; }
    .vial{ height:calc(var(--unit-h) * var(--cap, 4) + 16px); }
    .tube{ height:calc(var(--unit-h) * var(--cap, 4)); }
    #board{ padding-top:28px; }
  }
  @media (prefers-reduced-motion: reduce){
    *{ animation-duration:.01ms !important; transition-duration:.01ms !important; }
  }
