:root {
    --primary-color: #14432f;
    --primary-light: #2b6a4d;
    --accent-gold: #f0b23a;
    --success: #1e7a4f;
    --danger: #a23b2a;
    --bg: #f2f4ee;
    --surface: #ffffff;
    --border: #d8dfcf;
    --text: #1d2a22;
    --muted: #5b6a60;
    --console-bg: #0c1a14;
    --console-text: #7ee2a8;
    --font-display: "Bricolage Grotesque", "Trebuchet MS", system-ui, sans-serif;
    --font-body: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 1.0625rem;
    line-height: 1.6;
}

/* ---------- Header ---------- */
header {
    background: var(--primary-color);
    border-bottom: 4px solid var(--accent-gold);
    padding: 0.9rem 1.25rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1.5rem;
}

header h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: #fff;
}

header nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.1rem;
    margin-left: auto;
}

header nav a {
    color: #dbe7df;
    text-decoration: none;
    font-weight: 600;
    padding: 0.35rem 0;
    border-bottom: 2px solid transparent;
}

header nav a:hover { color: #fff; border-bottom-color: rgba(255, 255, 255, 0.4); }

.xp-pill {
    background: rgba(240, 178, 58, 0.18);
    color: var(--accent-gold);
    font-weight: 700;
    font-size: 0.9rem;
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    border: 1px solid rgba(240, 178, 58, 0.5);
}

/* ---------- Layout ---------- */
main {
    max-width: 760px;
    margin: 0 auto;
    padding: 2rem 1.25rem 3rem;
}

main > h2 {
    font-family: var(--font-display);
    font-size: clamp(1.6rem, 4vw, 2.2rem);
    line-height: 1.15;
    letter-spacing: -0.015em;
    color: var(--primary-color);
    margin: 0 0 1.5rem;
}

.gamification-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 2px rgba(20, 67, 47, 0.06);
}

.gamification-panel h3 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    margin: 0 0 0.6rem;
    color: var(--primary-color);
}

.gamification-panel p { margin: 0 0 1rem; max-width: 62ch; }
.gamification-panel ul { padding-left: 1.2rem; margin: 0 0 1.25rem; }
.gamification-panel li { margin-bottom: 0.4rem; }

/* ---------- Buttons ---------- */
.btn-share, button.btn-share {
    display: inline-block;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    background: var(--primary-color);
    border: 0;
    border-radius: 8px;
    padding: 0.7rem 1.3rem;
    cursor: pointer;
    text-decoration: none;
    transition: filter 0.15s ease, transform 0.1s ease;
}

.btn-share:hover { filter: brightness(1.1); }
.btn-share:active { transform: translateY(1px); }
.btn-share:disabled { opacity: 0.6; cursor: default; filter: none; transform: none; }

.btn-gold { background: var(--accent-gold) !important; color: #2a1d02 !important; }
.btn-ghost {
    background: transparent !important;
    color: var(--muted) !important;
    border: 1px solid var(--border) !important;
}

.btn-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }

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

/* ---------- Console (page Jouer) ---------- */
.console-btn { font-size: 1.15rem; padding: 1rem 2rem; }

#console-logs {
    background: var(--console-bg);
    color: var(--console-text);
    font-family: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.7;
    border-radius: 8px;
    border: 1px solid #1d3a2d;
}

/* ---------- Quiz ---------- */
#options-container label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    background: #fafbf7;
}

#options-container label:hover { border-color: var(--primary-light); }
#options-container label:has(input:checked) {
    border-color: var(--primary-color);
    background: #e6f1ea;
}
#options-container input { accent-color: var(--primary-color); width: 1.1rem; height: 1.1rem; }

/* ---------- Badges ---------- */
.badge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.badge-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    text-align: center;
}

.badge-card .badge-icon { font-size: 2.4rem; display: block; margin-bottom: 0.4rem; }
.badge-card h3 { font-family: var(--font-display); font-size: 1.1rem; margin: 0 0 0.4rem; color: var(--primary-color); }
.badge-card p { font-size: 0.95rem; color: var(--muted); margin: 0 0 0.8rem; }

.badge-status {
    display: inline-block;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 0.2rem 0.75rem;
    border-radius: 999px;
}

.badge-card.locked { background: #eef0ea; }
.badge-card.locked .badge-icon { filter: grayscale(1); opacity: 0.45; }
.badge-card.locked .badge-status { background: #dfe3d8; color: var(--muted); }

.badge-card.unlocked { border-color: var(--accent-gold); background: #fffaf0; }
.badge-card.unlocked .badge-status { background: var(--success); color: #fff; }

.xp-total {
    font-family: var(--font-display);
    font-size: 2.4rem;
    font-weight: 800;
    color: var(--primary-color);
    margin: 0;
    line-height: 1;
}

@media (max-width: 560px) {
    header nav { margin-left: 0; width: 100%; }
    .gamification-panel { padding: 1.15rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* ---------- Footer & pages légales ---------- */
footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 1.25rem 2.5rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.95rem;
}
footer nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem 1.25rem; margin-bottom: 0.6rem; }
footer a { color: var(--primary-light); font-weight: 600; text-decoration: none; }
footer a:hover { text-decoration: underline; }
footer p { margin: 0; }

.legal h3 { margin-top: 1.5rem; }
.legal h3:first-child { margin-top: 0; }
.legal .maj { color: var(--muted); font-size: 0.95rem; }

/* ---------- Mots cachés ---------- */
.mc-grid {
    display: grid;
    grid-template-columns: repeat(var(--n, 12), 1fr);
    gap: 3px;
    max-width: 480px;
    margin: 1rem auto 0.5rem;
    user-select: none;
    -webkit-user-select: none;
}
.mc-cell {
    aspect-ratio: 1;
    padding: 0;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(0.8rem, 3.6vw, 1.15rem);
    color: var(--primary-color);
    background: #f4f6ef;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}
.mc-cell:hover { background: #e6f1ea; }
.mc-cell.start { background: var(--accent-gold); border-color: var(--accent-gold); color: #2a1d02; }
.mc-cell.found { background: var(--success); border-color: var(--success); color: #fff; }
.mc-msg { min-height: 1.6em; text-align: center; font-weight: 600; color: var(--primary-color); margin: 0.5rem 0 0 !important; }
.mc-progress { text-align: center; margin-bottom: 0 !important; }
.mc-clues { list-style: none; padding: 0 !important; margin: 0 !important; }
.mc-clues li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.mc-clues li:last-child { border-bottom: 0; }
.mc-clues li.done { color: var(--success); font-weight: 700; }

.mc-tabs { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.mc-tab {
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 700;
    padding: 0.5rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #fafbf7;
    color: var(--primary-color);
    cursor: pointer;
}
.mc-tab.active { background: var(--primary-color); border-color: var(--primary-color); color: #fff; }
.mc-hint { text-align: center; color: var(--muted); font-size: 0.95rem; margin-bottom: 0 !important; }

/* ---------- Hub des jeux ---------- */
.back-link { color: var(--primary-light); font-weight: 600; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.jeux-score { text-align: center; margin-bottom: 0 !important; }
.jeu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.jeu-card {
    display: flex; flex-direction: column; gap: 0.35rem;
    background: var(--surface); border: 2px solid var(--border); border-radius: 12px;
    padding: 1.25rem; text-decoration: none; color: var(--text);
}
.jeu-card:hover { border-color: var(--primary-light); }
.jeu-card.done { border-color: var(--accent-gold); background: #fffaf0; }
.jeu-icon { font-size: 2rem; }
.jeu-name { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; color: var(--primary-color); }
.jeu-desc { font-size: 0.95rem; color: var(--muted); flex: 1; }
.jeu-status { font-weight: 700; font-size: 0.85rem; color: var(--muted); }
.jeu-card.done .jeu-status { color: var(--success); }

/* ---------- Mémoire ---------- */
.memo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-width: 520px; margin: 1rem auto; }
.memo-card {
    position: relative; aspect-ratio: 3 / 4; padding: 0; border: 0; background: none; cursor: pointer;
    perspective: 600px; font-family: var(--font-body);
}
.memo-card .face {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
    border-radius: 8px; padding: 4px; backface-visibility: hidden; transition: transform 0.35s ease;
    font-weight: 700; line-height: 1.15; overflow: hidden;
}
.memo-card .back { background: var(--primary-color); color: var(--accent-gold); font-size: 1.6rem; border: 2px solid var(--primary-light); }
.memo-card .front { background: #fff; color: var(--primary-color); border: 2px solid var(--border); font-size: clamp(0.6rem, 2.6vw, 0.85rem); transform: rotateY(180deg); }
.memo-card.def .front { background: #fffaf0; color: #5a4310; font-weight: 600; }
.memo-card.open .back, .memo-card.matched .back { transform: rotateY(180deg); }
.memo-card.open .front, .memo-card.matched .front { transform: rotateY(0); }
.memo-card.matched .front { border-color: var(--success); background: #e6f1ea; }

/* ---------- Vrai ou faux ---------- */
.tf-q { font-family: var(--font-display); font-size: 1.3rem; line-height: 1.35; text-align: center; margin: 1.25rem auto !important; color: var(--text); }
.tf-explain { margin: 1.25rem 0 !important; padding: 0.9rem 1rem; border-radius: 8px; text-align: left; min-height: 0; }
.tf-explain:empty { display: none; }
.tf-explain.ok { background: #e6f1ea; border: 1px solid var(--success); }
.tf-explain.ko { background: #f7e8e4; border: 1px solid var(--danger); }

/* ---------- Pendu ---------- */
.pd-lives { color: var(--danger); font-size: 1.2rem; letter-spacing: 0.15em; }
.pd-word { font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace; font-size: clamp(1.3rem, 6vw, 2rem); letter-spacing: 0.1em; text-align: center; margin: 1rem 0 !important; word-break: break-all; font-weight: 700; color: var(--primary-color); }
.pd-keys { display: grid; grid-template-columns: repeat(auto-fit, minmax(38px, 1fr)); gap: 5px; max-width: 480px; margin: 0 auto 0.75rem; }
.pd-key { font-family: var(--font-body); font-weight: 700; font-size: 1rem; padding: 0.55rem 0; border-radius: 6px; border: 1px solid var(--border); background: #fafbf7; color: var(--primary-color); cursor: pointer; }
.pd-key:disabled { cursor: default; }
.pd-key.good { background: var(--success); border-color: var(--success); color: #fff; }
.pd-key.bad { background: #e9d5d0; border-color: #d9b6ae; color: #8a3b2b; }

/* ---------- Remets dans l'ordre ---------- */
.or-list { display: flex; flex-direction: column; gap: 0.5rem; margin: 1rem 0; }
.or-step { text-align: left; font-family: var(--font-body); font-size: 1rem; padding: 0.8rem 1rem; border-radius: 8px; border: 1px solid var(--border); background: #fafbf7; color: var(--text); cursor: pointer; }
.or-step:hover { border-color: var(--primary-light); }
.or-step.wrong { border-color: var(--danger); background: #f7e8e4; }
.or-done { padding-left: 1.4rem; margin: 0 0 0.5rem; color: var(--success); font-weight: 600; }
.or-done li { margin-bottom: 0.3rem; }

/* ---------- Cacao Tycoon ---------- */
.tycoon-count { font-family: var(--font-display); font-size: 2.2rem; font-weight: 800; color: var(--primary-color); margin: 0 !important; line-height: 1.1; }
.ty-pod { width: 140px; height: 140px; border-radius: 50%; border: 4px solid var(--accent-gold); background: #fffaf0; font-size: 4rem; cursor: pointer; transition: transform 0.08s ease; }
.ty-pod:active { transform: scale(0.94); }
.ty-shop { display: flex; flex-direction: column; gap: 0.6rem; }
.ty-up { display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 1rem; text-align: left; font-family: var(--font-body); padding: 0.8rem 1rem; border-radius: 10px; border: 1px solid var(--border); background: #fafbf7; color: var(--text); cursor: pointer; }
.ty-up:disabled { opacity: 0.55; cursor: default; }
.ty-up:not(:disabled) { border-color: var(--success); background: #eef7f1; }
.ty-up-name { font-weight: 700; color: var(--primary-color); }
.ty-up-cost { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-weight: 700; color: #7a5a10; white-space: nowrap; }
.ty-up-desc { font-size: 0.9rem; color: var(--muted); }

@media (max-width: 420px) { .memo-grid { gap: 4px; } }
