
        
        :root {
            --bg: #f1f3ee;
            --surface: #ffffff;
            --ink: #1e2421;
            --muted: #5f6b64;
            --line: #d8ddd5;
            --grid: #9aa49c;            /* les lignes du goban, reprises dans les listes */
            --accent: #1f4d8f;
            --accent-soft: #e3ebf6;
            --kaya: #ddb675;
            --kaya-edge: #b38a4a;
            --ok: #2f7a55;
            --ok-soft: #e6f2ea;
            --ko: #b8452e;
            --ko-soft: #f8e9e4;
            --stone-black: radial-gradient(circle at 35% 30%, #59606a 0%, #22262b 45%, #0f1113 100%);
            --stone-white: radial-gradient(circle at 35% 30%, #ffffff 0%, #f1f1ec 55%, #cfd0c8 100%);
            --display: "Spectral", Georgia, serif;
            --body: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
            --navh: 0px;
            color-scheme: light;
        }
        @media (prefers-color-scheme: dark) {
            :root:not([data-theme="light"]) {
                --bg: #151a17; --surface: #1d2420; --ink: #e6ebe6; --muted: #9eaaa2; --line: #2f3a34; --grid: #56625a;
                --accent: #8fb4ec; --accent-soft: #1f2c3d; --ok: #7cc49c; --ok-soft: #1c2e24; --ko: #ec9a86; --ko-soft: #35211c;
                color-scheme: dark;
            }
        }
        :root[data-theme="dark"] {
            --bg: #151a17; --surface: #1d2420; --ink: #e6ebe6; --muted: #9eaaa2; --line: #2f3a34; --grid: #56625a;
            --accent: #8fb4ec; --accent-soft: #1f2c3d; --ok: #7cc49c; --ok-soft: #1c2e24; --ko: #ec9a86; --ko-soft: #35211c;
            color-scheme: dark;
        }

        * { box-sizing: border-box; }
        html { -webkit-text-size-adjust: 100%; }
        body {
            margin: 0;
            background: var(--bg);
            color: var(--ink);
            font-family: var(--body);
            font-size: 15px;
            line-height: 1.55;
            padding: 0 16px 48px;
        }
        .shell { max-width: 1080px; margin: 0 auto; }
        h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -0.005em; text-wrap: balance; }
        h2 { font-size: 1.35rem; line-height: 1.25; margin: 0; }
        p { margin: 0; }
        a { color: var(--accent); }
        .hidden { display: none !important; }
        .small { font-size: 0.85rem; color: var(--muted); }
        :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

        /* ---------- En-tête ---------- */
        .top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 0 14px; }
        .brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
        .brand svg { flex: none; width: 38px; height: 38px; }
        .brand h1 { font-size: 1.6rem; margin: 0; line-height: 1.1; }
        .subtitle { color: var(--muted); font-size: 0.92rem; }

        /* ---------- Boutons ---------- */
        .btn {
            font: 500 0.95rem/1.2 var(--body);
            border-radius: 8px; padding: 9px 15px; cursor: pointer;
            background: var(--accent); color: #fff; border: 1px solid var(--accent);
        }
        :root[data-theme="dark"] .btn:not(.secondary) { color: #10151a; }
        @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn:not(.secondary) { color: #10151a; } }
        .btn.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
        .btn.secondary:hover:not(:disabled) { border-color: var(--grid); }
        .btn:disabled { opacity: 0.4; cursor: default; }
        .actions { display: flex; flex-wrap: wrap; gap: 8px; }
        .back { align-self: flex-start; background: none; border: 0; padding: 0; font: 500 0.9rem var(--body); color: var(--muted); cursor: pointer; }
        .back:hover { color: var(--accent); }

        /* ---------- Navigation : onglets soulignés, barre du bas sur téléphone ---------- */
        nav.tabs { display: flex; gap: 26px; border-bottom: 1px solid var(--line); margin-bottom: 26px; }
        nav.tabs button, nav.tabs a.nav-home {
            display: flex; align-items: center; gap: 7px;
            background: none; border: 0; padding: 10px 0 11px; margin-bottom: -1px; cursor: pointer;
            font: 500 0.98rem var(--body); color: var(--muted); border-bottom: 2px solid transparent;
        }
        nav.tabs button:hover, nav.tabs a.nav-home:hover { color: var(--ink); }
        nav.tabs a.nav-home { text-decoration: none; }
        
        body.app-enigmes nav.tabs [data-mode="go"], body:not(.app-enigmes) nav.tabs [data-mode="enigmes"] { display: none; }
        nav.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
        nav.tabs svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

        
        nav.tabs button.more-btn { margin-left: auto; }
        nav.tabs button.more-btn[aria-expanded="true"] { color: var(--accent); }
        .more-menu { position: fixed; z-index: 60; min-width: 250px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.14); padding: 6px; }
        .more-menu a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 9px; color: var(--ink); text-decoration: none; }
        .more-menu a:hover, .more-menu a:focus-visible, .more-menu a[aria-current] { background: var(--accent-soft); outline: none; }
        .more-menu .mi { width: 30px; height: 30px; border-radius: 8px; background: var(--bg); display: grid; place-items: center; flex: none; font-size: 1.05rem; }
        .more-menu .mi svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
        .more-menu b { display: block; font: 600 0.92rem var(--body); }
        .more-menu small { display: block; color: var(--muted); font-size: 0.8rem; line-height: 1.3; }
        .more-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }

        /* ---------- Pierres : l'unité de progression ---------- */
        .stone {
            flex: none; width: 30px; height: 30px; border-radius: 50%;
            display: grid; place-items: center; position: relative; z-index: 1;
            font: 600 0.78rem var(--body); color: var(--muted);
            background: var(--bg); border: 1.5px solid var(--grid);
        }
        .done > .stone, .stone.black { background: var(--stone-black); border-color: transparent; color: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.35); }
        .next > .stone, .stone.white { background: var(--stone-white); border-color: transparent; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }

        /* Listes en « lignes du goban » : chaque chapitre est une ligne verticale, chaque leçon une pierre */
        .chapters { display: grid; gap: 0 36px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
        /* Titre, introduction, liste, note : alignés d'une colonne à l'autre */
        .chapter { display: grid; grid-row: span 4; grid-template-rows: subgrid; align-content: start; padding-bottom: 30px; }
        .chapter h2 { font-size: 1.2rem; }
        .level-intro { color: var(--muted); font-size: 0.9rem; margin-top: 4px; max-width: 46ch; }
        .lessons { list-style: none; margin: 14px 0 0; padding: 0; position: relative; align-self: start; }
        .lessons::before { content: ""; position: absolute; left: 14.25px; top: 16px; bottom: 16px; width: 1.5px; background: var(--grid); }
        .lesson-btn {
            display: flex; align-items: center; gap: 12px; width: 100%;
            background: none; border: 0; padding: 6px 0; cursor: pointer; text-align: left;
            font: 400 0.98rem var(--body); color: var(--ink);
        }
        .lesson-btn:hover .lesson-title { color: var(--accent); }
        .lesson-btn.next .lesson-title { font-weight: 700; }
        .lesson-num { /* alias historique */ }
        .progress-line { color: var(--muted); font-size: 0.92rem; margin: 0 0 22px; }
        .chapter .feedback { margin-top: 14px; align-self: start; }

        /* ---------- Parcours : la prochaine leçon, avec son plateau ---------- */
        .hero { display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: center; margin: 0 0 36px; }
        .hero-board { width: 190px; }
        .hero h2 { font-size: 1.9rem; margin-top: 2px; }
        .hero .where { color: var(--muted); font-size: 0.92rem; }
        .hero p.what { margin: 8px 0 16px; max-width: 52ch; color: var(--ink); }

        /* ---------- Vue plateau (leçon, problème, partie) ---------- */
        .lesson-view { display: grid; grid-template-columns: minmax(0, 480px) minmax(0, 1fr); gap: 32px; align-items: start; }
        .board-wrap { width: 100%; }
        .board-wrap .wgo-board, .hero-board .wgo-board {
            border-radius: 4px;
            box-shadow: 0 3px 0 var(--kaya-edge), 0 14px 28px rgba(40, 28, 8, 0.18);
        }
        #lesson-board, #probleme-board, #partie-board { width: 100%; max-width: 480px; }
        .lesson-panel { display: flex; flex-direction: column; gap: 14px; max-width: 520px; padding-top: 2px; }
        .step-dots { display: flex; gap: 6px; align-items: center; }
        .step-dots span { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid var(--grid); background: var(--bg); }
        .step-dots span.done { background: var(--stone-black); border-color: transparent; }
        .step-dots span.current { background: var(--stone-white); border-color: transparent; box-shadow: 0 0 0 2px var(--accent); }
        .step-text { font-size: 1.06rem; line-height: 1.6; max-width: 58ch; }
        .to-play { font-size: 0.88rem; color: var(--muted); display: flex; align-items: center; gap: 8px; }
        .stone-icon { width: 14px; height: 14px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 1px rgba(0,0,0,0.25); }
        .options { display: grid; gap: 8px; }
        .options button {
            text-align: left; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px;
            background: var(--surface); color: var(--ink); font: 400 1rem var(--body); cursor: pointer;
        }
        .options button:hover { border-color: var(--grid); }
        .options button.right { border-color: var(--ok); background: var(--ok-soft); }
        .options button.wrong { border-color: var(--ko); background: var(--ko-soft); }

        /* Retours : un trait coloré à gauche, comme une annotation en marge */
        .feedback { border-left: 3px solid; padding: 8px 12px; line-height: 1.5; border-radius: 0 6px 6px 0; }
        .feedback.ok { border-color: var(--ok); background: var(--ok-soft); }
        .feedback.ko { border-color: var(--ko); background: var(--ko-soft); }
        .feedback.note { border-color: var(--accent); background: var(--accent-soft); }
        .hints { display: grid; gap: 8px; }
        .hints:empty { display: none; }
        .actions.nav { justify-content: space-between; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 4px; }

        /* ---------- Énigmes ---------- */
        .rules { max-width: 68ch; margin: 0 0 30px; }
        .rules h2 { margin-bottom: 6px; }
        .rules dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0; }
        .rules dt { font-weight: 700; }
        .rules dd { margin: 0; }
        .enigme { max-width: 780px; display: flex; flex-direction: column; gap: 16px; }
        .people { display: grid; gap: 0 28px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
        .person { border-top: 1px solid var(--line); padding: 14px 0; display: flex; flex-direction: column; gap: 10px; }
        .person-name { font: 600 1.2rem var(--display); }
        .says { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
        .says li { border-left: 2px solid var(--grid); padding: 2px 0 2px 12px; line-height: 1.45; }
        .tv { font-size: 0.75rem; font-weight: 700; padding: 1px 6px; border-radius: 4px; margin-left: 4px; }
        .tv.v { background: var(--ok-soft); color: var(--ok); }
        .tv.f { background: var(--ko-soft); color: var(--ko); }
        .type-choices { display: flex; flex-wrap: wrap; gap: 6px; }
        .type-choices button {
            border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; background: var(--surface);
            color: var(--ink); cursor: pointer; font: 400 0.9rem var(--body);
        }
        .type-choices button:hover:not(:disabled) { border-color: var(--grid); }
        .type-choices button.picked { background: var(--accent); border-color: var(--accent); color: #fff; }
        .type-choices button:disabled { cursor: default; }


        /* ---------- Défis de logique (rivière, pesées, grilles, chiffres) ---------- */
        .genres { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 22px; }
        .genres button { border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; background: var(--surface); color: var(--ink); cursor: pointer; font: 500 0.92rem var(--body); }
        .genres button:hover { border-color: var(--grid); }
        .genres button.picked { background: var(--accent); border-color: var(--accent); color: #fff; }
        :root[data-theme="dark"] .genres button.picked { color: #10151a; }
        @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .genres button.picked { color: #10151a; } }
        #defis .enigme { max-width: 820px; }
        #defis .enigme h3 { margin: 6px 0; font-size: 1.05rem; }
        .river { display: grid; grid-template-columns: 1fr 120px 1fr; gap: 10px; align-items: stretch; margin: 10px 0; }
        .bank { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--surface); min-height: 140px; }
        .bank h3 { color: var(--muted); font: 500 0.85rem var(--body); margin: 0 0 8px; }
        .water { border-radius: 12px; background: linear-gradient(180deg, #cfe3f3, #a9c9e4); display: flex; align-items: center; position: relative; min-height: 140px; padding: 6px; }
        :root[data-theme="dark"] .water { background: linear-gradient(180deg, #24405a, #1a3148); }
        @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .water { background: linear-gradient(180deg, #24405a, #1a3148); } }
        .water .boat { font-size: 1.8rem; text-align: center; width: 100%; }
        .water.boat-left .boat { text-align: left; } .water.boat-right .boat { text-align: right; }
        .chips { display: flex; flex-wrap: wrap; gap: 6px; }
        .chip { border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: var(--surface); color: var(--ink); cursor: pointer; font: 400 0.9rem var(--body); text-align: left; }
        .chip:hover { border-color: var(--grid); } .chip.inboat { background: var(--accent-soft); border-color: var(--accent); } .chip.fixed { cursor: default; opacity: .85; }
        .water .chip { font-size: 0.78rem; padding: 4px 6px; }
        @media (max-width: 640px) { .river { grid-template-columns: 1fr; } .water { min-height: 90px; } }
        .scale { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 10px 0; }
        .pan { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--surface); }
        .pan.aside { margin-bottom: 8px; } .pan h3 { color: var(--muted); font: 500 0.85rem var(--body) !important; margin: 0 0 8px !important; }
        .coins { display: flex; flex-wrap: wrap; gap: 6px; min-height: 40px; }
        .coin { width: 42px; height: 42px; border-radius: 50%; border: 2px solid #b89a3c; background: radial-gradient(circle at 35% 30%, #fff3bf, #e0b93f 70%); color: #3a2c00; font: 700 0.95rem var(--body); cursor: pointer; }
        .coin.guess { box-shadow: 0 0 0 3px var(--accent); } .coin:disabled { cursor: default; opacity: .7; }
        .guess-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
        .guess-row select, .gridtab select, .numin input { padding: 7px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 400 0.95rem var(--body); }
        .clues { margin: 6px 0 12px; padding-left: 1.3em; display: grid; gap: 4px; line-height: 1.45; }
        .gridwrap { overflow-x: auto; } .gridtab { border-collapse: collapse; }
        .gridtab th, .gridtab td { border: 1px solid var(--line); padding: 6px; text-align: center; font-weight: 500; font-size: 0.9rem; }
        .gridtab th:first-child { text-align: left; background: var(--accent-soft); } .gridtab select { width: 100%; min-width: 118px; }
        .gridtab select.bad, .mcell.bad { border-color: var(--ko); background: var(--ko-soft); }
        .seqline { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
        .term { min-width: 46px; padding: 10px 12px; text-align: center; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font: 600 1.15rem var(--display); }
        .term.q { background: var(--accent-soft); border-color: var(--accent); }
        .numin { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; } .numin input { width: 140px; }
        .magic { display: grid; grid-template-columns: repeat(3, 64px); gap: 6px; margin: 10px 0; }
        .mcell { width: 64px; height: 64px; display: flex; align-items: center; justify-content: center; text-align: center; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: 600 1.3rem var(--display); }
        .mcell.fixed { background: var(--accent-soft); border-color: var(--accent); } input.mcell { padding: 0; }

        /* ---------- Partie ---------- */
        .partie-settings { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
        .partie-settings label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
        .partie-settings select { padding: 8px; border-radius: 8px; border: 1px solid var(--line); font: 400 0.95rem var(--body); background: var(--surface); color: var(--ink); }

        /* ---------- Installation ---------- */
        .install-dlg { border: 0; border-radius: 14px; padding: 22px; max-width: min(92vw, 440px); color: var(--ink); background: var(--surface); line-height: 1.55; position: fixed; }
        .install-dlg::backdrop { background: rgba(0,0,0,0.4); }
        .install-dlg h2 { margin: 0 0 8px; font-size: 1.25rem; padding-right: 24px; }
        .install-dlg .steps { padding-left: 1.2em; display: grid; gap: 8px; }
        .install-x { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 1.6rem; cursor: pointer; color: var(--muted); }
        .ios-ic { width: 20px; height: 20px; vertical-align: -4px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

        /* ---------- Téléphone ---------- */
        @media (max-width: 760px) {
            html, body { overscroll-behavior-y: none; }
            body { padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) calc(var(--navh) + 28px) max(16px, env(safe-area-inset-left)); }
            .top { padding: 14px 0 12px; }
            .brand h1 { font-size: 1.35rem; }
            .subtitle { display: none; }
            
            nav.tabs {
                position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; margin: 0;
                display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0;
                background: var(--surface); border-top: 1px solid var(--line); border-bottom: 0;
                padding: 4px max(6px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
                transform: translateZ(0);
            }
            nav.tabs button, nav.tabs a.nav-home { flex-direction: column; gap: 3px; font-size: 0.7rem; padding: 7px 0; border-bottom: 0; border-radius: 10px; min-height: 52px; justify-content: center; }
            nav.tabs button.active { background: var(--accent-soft); color: var(--accent); }
            nav.tabs svg { width: 22px; height: 22px; }
            nav.tabs button.more-btn { margin-left: 0; }
            .more-menu { left: 8px !important; right: 8px; top: auto !important; bottom: calc(var(--navh) + 8px); min-width: 0; }
            .hero { grid-template-columns: 1fr; gap: 16px; }
            .hero-board { width: 150px; }
            .hero h2 { font-size: 1.55rem; }
            .lesson-view { grid-template-columns: 1fr; gap: 18px; }
            .chapters { gap: 26px; }
            .actions.nav { font-size: 0.9rem; }
        }
        @media (prefers-reduced-motion: no-preference) {
            .next > .stone { transition: box-shadow 0.2s; }
        }
    