:root {
  --encre: #272a31; --encre-2: #4b4f58; --parchemin: #f6ecd6; --parchemin-2: #ecdcb9; --bord: #c9a76a;
  --or: #d9a441; --sarcelle: #2f8f83; --sarcelle-2: #23675f; --bon: #2e7d4f; --faux: #a83c3c; --nuit: #181b21;
  --t: 17px; --titre: "Pixelify Sans", ui-monospace, monospace; --texte: "Atkinson Hyperlegible", system-ui, sans-serif;
  color-scheme: light;
}
:root[data-texte="grand"] { --t: 19.5px; }
:root[data-texte="tres-grand"] { --t: 22px; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--nuit); color: var(--encre); font: 400 var(--t)/1.5 var(--texte); -webkit-tap-highlight-color: transparent; }
#jeu { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; image-rendering: pixelated; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--or); outline-offset: 2px; }
[hidden] { display: none !important; }

.btn { background: var(--sarcelle); color: #fff; border: 2px solid var(--encre); border-radius: 6px; padding: .55em 1.1em; font-weight: 700; box-shadow: 0 3px 0 var(--encre); transition: transform .08s; min-height: 44px; }
.btn:hover:not(:disabled) { background: var(--sarcelle-2); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--encre); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.discret { background: var(--parchemin-2); color: var(--encre); }
.btn.discret:hover:not(:disabled) { background: #e3cfa5; }
.btn.petit { padding: .35em .8em; font-size: .9em; min-height: 40px; }
.btn.grand { font-size: 1.15em; padding: .7em 1.6em; }
.btn.fichier { position: relative; display: inline-flex; align-items: center; }
.btn.fichier input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* HUD */
#hud { position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: max(10px, env(safe-area-inset-top)) 12px 0; pointer-events: none; z-index: 2; }
#hud > div { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#hud span, .btn-hud { pointer-events: auto; background: rgba(24, 27, 33, .84); color: #fff7e0; border: 2px solid #000; box-shadow: inset 0 0 0 1px rgba(255,247,224,.22); border-radius: 8px; padding: .2em .6em; font: 600 .85em var(--titre); }
.btn-hud { min-height: 40px; min-width: 40px; }
.btn-hud span { background: none; border: 0; padding: 0; font: inherit; }
#hud-lieu { color: var(--or) !important; }

#banniere { position: fixed; top: 18%; left: 50%; transform: translateX(-50%); text-align: center; color: #fff7e0; background: rgba(24, 27, 33, .88); border: 2px solid var(--or); box-shadow: inset 0 0 0 2px rgba(0,0,0,.6), inset 0 0 0 3px rgba(217,164,65,.45); border-radius: 10px; padding: .6em 1.4em; z-index: 2; pointer-events: none; max-width: calc(100vw - 32px); }
#banniere strong { display: block; font: 700 1.5em var(--titre); color: var(--or); }
#banniere span { font-size: .9em; }
#banniere.anim { animation: ban 2.8s ease forwards; }
@keyframes ban { 0% { opacity: 0; transform: translate(-50%, -8px); } 12%, 75% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

#invite { position: fixed; bottom: max(110px, calc(env(safe-area-inset-bottom) + 110px)); left: 50%; transform: translateX(-50%); z-index: 2; background: var(--parchemin); border: 2px solid var(--encre); border-radius: 999px; padding: .4em 1em; font-weight: 700; box-shadow: 0 3px 0 var(--encre); max-width: calc(100vw - 32px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#invite kbd { font: 700 .85em var(--titre); background: var(--encre); color: #fff; border-radius: 4px; padding: 0 .4em; }
html:not(.tactile) #invite { bottom: 24px; }
html.tactile #invite { bottom: max(176px, calc(env(safe-area-inset-bottom) + 170px)); }

/* Boîte de dialogue : cadre double, onglet du nom et portrait du personnage */
#dialogue { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(720px, calc(100vw - 32px)); background: #fffaf0; border: 3px solid var(--encre); border-radius: 12px; box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px var(--bord), 0 0 0 2px rgba(255,255,255,.35), 0 10px 30px rgba(0,0,0,.45); padding: 20px 20px 12px; z-index: 4; }
#dialogue.avec-portrait { display: grid; grid-template-columns: 64px 1fr; column-gap: 14px; }
#dlg-portrait { grid-row: 1 / span 2; width: 64px; height: 64px; image-rendering: pixelated; background: radial-gradient(circle at 50% 70%, #fff6de, #e6d3a8); border: 2px solid var(--encre); border-radius: 10px; box-shadow: inset 0 0 0 2px #fff; }
#dlg-nom { position: absolute; top: -15px; left: 18px; margin: 0; padding: 1px 12px; background: var(--encre); color: #ffe7a6; border-radius: 8px; box-shadow: 0 0 0 2px var(--bord); font: 700 .95em var(--titre); }
#dlg-texte { margin: 0 0 8px; }
#dlg-suite { float: right; }
#dialogue.avec-portrait #dlg-texte, #dialogue.avec-portrait #dlg-suite { grid-column: 2; }
#dialogue.avec-portrait #dlg-suite { justify-self: end; }
html.tactile #dialogue { bottom: max(150px, calc(env(safe-area-inset-bottom) + 150px)); }

#soustitres { position: fixed; left: 50%; top: max(64px, calc(env(safe-area-inset-top) + 56px)); transform: translateX(-50%); margin: 0; background: rgba(0,0,0,.8); color: #fff; padding: .25em .8em; border-radius: 4px; font-size: .85em; z-index: 6; pointer-events: none; max-width: calc(100vw - 32px); text-align: center; }

/* Tactile */
#tactile { display: none; }
html.tactile #tactile { display: block; }
.croix { position: fixed; left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom)); width: 138px; height: 138px; z-index: 3; display: grid; grid-template: repeat(3, 46px) / repeat(3, 46px); }
.croix button, #btn-a { background: rgba(246, 236, 214, .88); border: 2px solid var(--encre); border-radius: 10px; font-size: 18px; touch-action: none; user-select: none; -webkit-user-select: none; }
.croix .h { grid-area: 1 / 2; } .croix .g { grid-area: 2 / 1; } .croix .d { grid-area: 2 / 3; } .croix .b { grid-area: 3 / 2; }
#btn-a { position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(36px, calc(env(safe-area-inset-bottom) + 20px)); width: 76px; height: 76px; border-radius: 50%; font-size: 30px; z-index: 3; background: var(--or); }

/* Écran titre */
#titre { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 50% 40%, rgba(24,27,33,.55), rgba(24,27,33,.92)); z-index: 5; overflow-y: auto; }
.titre-carte { width: min(620px, 100%); text-align: center; background: var(--parchemin); border: 3px solid var(--encre); border-radius: 14px; box-shadow: 0 0 0 4px var(--bord), 0 20px 60px rgba(0,0,0,.6); padding: 28px 22px 20px; }
#titre-nina { width: 96px; height: 96px; image-rendering: pixelated; }
.sur-titre { margin: 4px 0 0; font: 600 .85em var(--titre); color: var(--sarcelle-2); letter-spacing: .04em; text-transform: uppercase; }
h1 { margin: 6px 0 10px; font: 700 clamp(2rem, 7vw, 3rem)/1.05 var(--titre); color: var(--encre); }
h1 span { display: block; font-size: .55em; color: #8c3b3b; margin-top: 6px; }
.pitch { margin: 0 auto 18px; max-width: 46ch; }
.titre-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.mention { font-size: .8em; color: var(--encre-2); margin: 18px 0 0; }

/* Panneaux */
#voile { position: fixed; inset: 0; background: rgba(12, 14, 18, .6); display: grid; place-items: center; padding: 16px; z-index: 7; }
.panneau { width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--parchemin); border: 3px solid var(--encre); border-radius: 12px; box-shadow: inset 0 0 0 2px #fffaf0, 0 0 0 3px var(--bord), 0 20px 50px rgba(0,0,0,.5); }
.panneau.large { width: min(880px, 100%); }
.p-tete { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 2px dashed var(--bord); background: linear-gradient(#efe0bd, var(--parchemin)); border-radius: 9px 9px 0 0; }
.p-tete h2 { margin: 0; font: 700 1.25em var(--titre); outline: none; }
.p-fermer { background: none; border: 2px solid var(--encre); border-radius: 6px; width: 40px; height: 40px; font-weight: 700; flex: none; }
.p-corps { padding: 14px 16px 16px; overflow-y: auto; overscroll-behavior: contain; }
.p-corps h3 { font: 700 1.05em var(--titre); margin: 1.1em 0 .4em; color: var(--sarcelle-2); }
.p-corps h4 { margin: .8em 0 .3em; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.aide { color: var(--encre-2); font-size: .88em; }
.bon { color: var(--bon); font-weight: 700; }
.faux { color: var(--faux); font-weight: 700; }
.indice { background: #fff6d8; border-left: 4px solid var(--or); padding: .4em .7em; border-radius: 4px; }
.attention { background: #fbe9e0; border-left: 4px solid #c97b3a; padding: .4em .7em; border-radius: 4px; font-size: .88em; }
.ref { font-size: .9em; font-style: italic; }
.grand { font-size: 1.2em; font-weight: 700; }
.ligne { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: .4em 0; }
input[type="text"], select, textarea { font: inherit; border: 2px solid var(--encre); border-radius: 6px; padding: .35em .5em; background: #fffaf0; min-height: 40px; max-width: 100%; }
textarea { width: 100%; font-family: ui-monospace, monospace; font-size: .85em; }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--sarcelle); }
fieldset { border: 2px solid var(--parchemin-2); border-radius: 8px; margin: .6em 0; }
section + section { border-top: 2px dashed var(--bord); margin-top: 1em; }

/* Défis */
.defi-tete { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.etiquette { background: var(--encre); color: #fff; font: 600 .8em var(--titre); padding: .15em .6em; border-radius: 4px; }
.notion { font-size: .88em; color: var(--encre-2); }
.chrono { margin-left: auto; font: 600 .9em var(--titre); }
.enonce { font-style: italic; }
.consigne { font-weight: 700; font-size: 1.05em; }
.choix { display: grid; gap: 8px; }
.choix-btn, .assoc-btn, .slot { text-align: left; background: #fffaf0; border: 2px solid var(--encre); border-radius: 8px; padding: .55em .8em; min-height: 44px; line-height: 1.35; }
.choix-btn:hover:not(:disabled), .assoc-btn:hover:not(:disabled) { background: #fff1cc; }
.choix-btn.ok, .assoc-btn.ok, .slot.ok { background: #d8f0dc; border-color: var(--bon); }
.choix-btn.ko { background: #f6d9d6; border-color: var(--faux); text-decoration: line-through; }
.choix-btn:disabled, .assoc-btn:disabled { cursor: default; opacity: 1; }
.assoc { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0 12px; }
.assoc .col { display: grid; gap: 8px; align-content: start; }
.assoc-btn { position: relative; padding-right: 2.2em; }
.assoc-btn.sel { background: #fff1cc; box-shadow: 0 0 0 3px var(--or); }
.assoc-btn.lie { background: #e3f1ef; }
.assoc-btn[data-n]:not([data-n=""])::after { content: attr(data-n); position: absolute; right: .5em; top: 50%; transform: translateY(-50%); background: var(--sarcelle); color: #fff; font: 700 .8em var(--titre); border-radius: 50%; width: 1.6em; height: 1.6em; display: grid; place-items: center; }
.slots { display: grid; gap: 6px; margin-bottom: 8px; }
.slot { display: flex; gap: 10px; align-items: center; background: rgba(255,255,255,.4); border-style: dashed; }
.slot.plein { border-style: solid; background: #fffaf0; }
.slot.sous { margin-left: 1.6em; }
.slot-lab { font: 700 .9em var(--titre); color: var(--sarcelle-2); min-width: 1.8em; }
.slot:disabled { color: inherit; cursor: default; }
.reserve { display: grid; gap: 6px; margin-bottom: 12px; }
.faits { display: grid; gap: 6px; margin-bottom: 12px; }
.fait { display: flex; gap: 10px; align-items: center; background: #fffaf0; border: 2px solid var(--encre); border-radius: 8px; padding: .45em .7em; cursor: pointer; }
.fait.utile { background: #d8f0dc; border-color: var(--bon); }
.fait.inutile { opacity: .6; }
.retour p { margin: .4em 0; }
.rappel { margin-bottom: 8px; font-size: .9em; }
.bilan-defi { text-align: center; padding: 10px 0; }

.carte-flash { background: #fffaf0; border: 3px double var(--encre); border-radius: 10px; padding: 18px; text-align: center; margin: 8px 0; }
.carte-flash .recto { font: 700 1.3em var(--titre); margin: 0 0 8px; color: var(--sarcelle-2); }
.carte-flash .verso { margin: 0; }

/* Tableau de bord */
.onglets { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; border-bottom: 2px solid var(--parchemin-2); margin-bottom: 10px; }
.onglet { background: none; border: 2px solid transparent; border-radius: 6px; padding: .35em .8em; font-weight: 700; white-space: nowrap; min-height: 40px; }
.onglet[aria-selected="true"] { background: var(--encre); color: #fff; }
.carte-monde { position: relative; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.noeud { background: #fffaf0; border: 2px solid var(--encre); border-left: 8px solid var(--c, var(--or)); border-radius: 8px; padding: 10px; display: grid; gap: 4px; font-size: .9em; }
.noeud strong { font-family: var(--titre); }
.noeud .mat { color: var(--encre-2); font-size: .85em; }
.noeud.fini { background: #f3f9ef; }
.noeud.bloque { opacity: .7; border-style: dashed; }
.noeud.cite { border-left-color: var(--sarcelle); }
@media (min-width: 860px) {
  .carte-monde.cercle { display: block; height: 700px; background: radial-gradient(circle, #f1e3c2 0 30%, transparent 31%), repeating-linear-gradient(45deg, transparent 0 18px, rgba(201,167,106,.12) 18px 19px); border-radius: 12px; }
  .cercle .noeud { position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -50%); width: 180px; }
  .cercle .noeud .mat { display: none; }
}
.barre { height: 10px; background: var(--parchemin-2); border: 1px solid var(--encre); border-radius: 999px; overflow: hidden; }
.barre span { display: block; height: 100%; background: var(--c, var(--sarcelle)); }
.niveau { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; }
.niveau .barre { grid-column: 1 / -1; height: 14px; }
.niveau strong { font: 700 1.3em var(--titre); }
.objectifs { list-style: none; padding: 0; }
.objectifs li.fait { color: var(--bon); font-weight: 700; }
.mat-prog { border: 2px solid var(--parchemin-2); border-radius: 8px; margin: 6px 0; padding: 6px 10px; }
.mat-prog summary { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center; cursor: pointer; }
.mat-prog summary .barre { grid-column: 1 / -1; }
.badge { font-size: 1.2em; color: #b9ad97; }
.badge.obtenu { color: var(--c, var(--or)); text-shadow: 0 0 6px var(--c); }
.notions { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; font-size: .9em; }
.defs dt { font-weight: 700; margin-top: .6em; }
.defs dd { margin: 0 0 0 1em; }
.defs .cache { color: #9b8f7d; font-style: italic; }
.erreurs li { margin-bottom: .3em; }
.mes-erreurs li { margin-bottom: .5em; }
.form { display: flex; flex-wrap: wrap; gap: 12px; }
.form label { display: flex; gap: 8px; align-items: center; }
.menu-pause { display: grid; gap: 10px; }
.fin-chap { text-align: center; }
.fin-chap .puces { text-align: left; display: inline-block; }
.sceau { width: 84px; height: 84px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; font-size: 42px; color: #fff; background: radial-gradient(circle at 35% 35%, #fff6, transparent 40%), var(--c); border: 4px solid var(--encre); box-shadow: 0 0 0 4px var(--bord); }
.tuto-txt { font-size: 1.05em; }

@media (max-width: 560px) {
  #dialogue.avec-portrait { grid-template-columns: 48px 1fr; column-gap: 10px; }
  #dlg-portrait { width: 48px; height: 48px; }
  .assoc { grid-template-columns: 1fr; }
  .assoc .col + .col { border-top: 2px dashed var(--bord); padding-top: 8px; }
  .btn-hud span { display: none; }
  #hud .hud-d { flex-wrap: nowrap; }
  #hud-xp { font-size: .75em !important; }
  #hud { font-size: .9em; }
}
html.calme *, html.calme *::before, html.calme *::after { animation: none !important; transition: none !important; }
