/* Nouki Memory — identité : forêt de nuit douce, cartes magiques en bois aux bordures dorées.
   Même famille que Nouki Pop (encre, crème, corail, rondeur) ; ambiance plus calme et concentrée. */
:root {
  --ink: #3f3350;
  --ink-soft: #6e6380;
  --cream: #fff8ec;
  --paper: #fffdf7;
  --night: #241d3a;
  --night-2: #3a2f5c;
  --moss: #4e9e43;
  --gold: #e8b64a;
  --gold-2: #c8913a;
  --gold-light: #ffe6a6;
  --wood: #9a6a45;
  --wood-dark: #6f4a2f;
  --wood-light: #c08a5e;
  --detente: #ff8c69;
  --detente-dark: #e2694a;
  --chrono: #3d8fe0;
  --chrono-dark: #2a6fba;
  --aventure: #4fae5a;
  --aventure-dark: #36863f;
  --duo: #8e66d6;
  --duo-dark: #6c48b2;
  --ok: #2f9e5b;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(20, 12, 40, 0.28);
  --font: ui-rounded, 'SF Pro Rounded', 'Nunito', 'Varela Round', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --fs: 1;
  --world-sky: #e6f5df;
  --world-accent: #4e9e43;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: radial-gradient(120% 80% at 50% 0%, #4b3d77 0%, #2d2448 45%, #1d1730 100%) fixed;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  font-size: calc(16px * var(--fs));
}
body.grands-textes { --fs: 1.18; }
body.contraste { --ink: #1b1428; --ink-soft: #3a3150; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; border-radius: 10px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden { display: none !important; }

/* Lucioles : décor calme, désactivé si animations réduites. */
#fireflies { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
#fireflies i { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: #fff3b0; box-shadow: 0 0 12px 4px rgba(255, 236, 150, 0.55); opacity: 0; animation: luciole 9s ease-in-out infinite; }
@keyframes luciole { 0%, 100% { opacity: 0; transform: translate(0, 0); } 30% { opacity: 0.9; } 60% { opacity: 0.5; transform: translate(18px, -26px); } }
.reduit #fireflies, .reduit .sparkle { display: none; }

#app { position: relative; z-index: 1; min-height: 100%; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; align-items: center; padding: calc(12px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); width: 100%; max-width: 980px; margin: 0 auto; animation: fondu 0.25s ease; }
@keyframes fondu { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.reduit .screen, .screen.play { animation: none; }

/* ——— Bandeau d'aperçu ——— */
.preview-banner { position: relative; z-index: 2; background: #fff1c9; color: #6b4b00; font-size: 0.8em; text-align: center; padding: 6px 12px; border-bottom: 2px solid #f0c75a; }

/* ——— Logo ——— */
.logo { width: min(520px, 92vw); height: auto; display: block; margin: 4px auto 0; filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.35)); }
.slogan { color: #f6ecff; text-align: center; margin: 2px 0 14px; font-size: 1.02em; letter-spacing: 0.01em; opacity: 0.95; }

/* ——— Accueil ——— */
.topline { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 999px; padding: 8px 14px; background: rgba(255, 255, 255, 0.14); color: #fff; font-weight: 700; font-size: 0.92em; backdrop-filter: blur(4px); }
.chip:hover { background: rgba(255, 255, 255, 0.22); }
.chip img { width: 26px; height: 26px; }
.modes { width: 100%; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 760px) { .modes { grid-template-columns: repeat(4, 1fr); } }
.mode { position: relative; border: 0; border-radius: 22px; padding: 16px 12px 14px; min-height: 128px; color: #fff; text-align: left; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; box-shadow: var(--shadow), inset 0 -6px 0 rgba(0, 0, 0, 0.16); overflow: hidden; transition: transform 0.12s ease; }
.mode:active { transform: scale(0.97); }
.mode b { font-size: 1.3em; letter-spacing: 0.01em; }
.mode span { font-size: 0.86em; opacity: 0.95; line-height: 1.25; }
.mode .ico { position: absolute; top: 8px; right: 10px; font-size: 2.1em; line-height: 1; opacity: 0.95; }
.mode.detente { background: linear-gradient(160deg, #ffa182, var(--detente) 55%, var(--detente-dark)); }
.mode.chrono { background: linear-gradient(160deg, #62a8ee, var(--chrono) 55%, var(--chrono-dark)); }
.mode.aventure { background: linear-gradient(160deg, #6fc47a, var(--aventure) 55%, var(--aventure-dark)); }
.mode.duo { background: linear-gradient(160deg, #a986e6, var(--duo) 55%, var(--duo-dark)); }
.mode .resume { position: absolute; top: 10px; left: 12px; background: rgba(255, 255, 255, 0.92); color: var(--ink); font-size: 0.72em; font-weight: 800; border-radius: 999px; padding: 3px 9px; }
.tiles { width: 100%; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { border: 0; border-radius: 16px; padding: 12px; background: var(--paper); color: var(--ink); display: flex; align-items: center; gap: 10px; text-align: left; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12); font-weight: 700; }
.tile .em { font-size: 1.5em; width: 34px; text-align: center; }
.tile small { display: block; font-weight: 500; color: var(--ink-soft); font-size: 0.78em; }
.tile.daily { grid-column: 1 / -1; background: linear-gradient(90deg, #fff4d6, #fffdf7); border: 2px solid var(--gold); }
.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }

/* ——— Panneaux, feuilles et formulaires ——— */
.panel { width: 100%; background: var(--paper); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 6px; font-size: 1.35em; }
.panel h3 { margin: 16px 0 8px; font-size: 1.02em; color: var(--ink-soft); text-transform: none; }
.panel p { line-height: 1.45; }
.head { width: 100%; display: flex; align-items: center; gap: 10px; margin-bottom: 12px; color: #fff; }
.head h1 { margin: 0; font-size: 1.4em; flex: 1; }
.retour { border: 0; width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, 0.16); color: #fff; font-size: 1.3em; display: grid; place-items: center; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button { border: 2px solid #e5dccd; background: #fff; border-radius: 14px; padding: 10px 14px; font-weight: 700; min-height: 48px; }
.seg button[aria-pressed='true'] { border-color: var(--ink); background: var(--cream); box-shadow: inset 0 0 0 1px var(--ink); }
.seg button small { display: block; font-weight: 500; font-size: 0.75em; color: var(--ink-soft); }
.btn { border: 0; border-radius: 16px; padding: 14px 22px; font-weight: 800; font-size: 1.08em; background: var(--ink); color: #fff; min-height: 52px; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.btn.big { width: 100%; font-size: 1.2em; margin-top: 16px; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px #d9cfbf; }
.btn.detente { background: var(--detente-dark); } .btn.chrono { background: var(--chrono-dark); } .btn.aventure { background: var(--aventure-dark); } .btn.duo { background: var(--duo-dark); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.muted { color: var(--ink-soft); font-size: 0.9em; }
label.switch { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid #eee4d4; }
label.switch input { width: 26px; height: 26px; accent-color: var(--moss); }
input[type='range'] { width: 160px; accent-color: var(--moss); }
input[type='text'], input[type='search'] { font: inherit; border: 2px solid #e5dccd; border-radius: 12px; padding: 10px 12px; width: 100%; }

/* ——— Plateau de jeu ——— */
.play { padding-top: calc(8px + var(--safe-top)); max-width: 1200px; min-height: 0; overflow: hidden; }
body.en-jeu { overflow: hidden; }
body.en-jeu #app { height: calc(100dvh - var(--banner-h, 0px)); min-height: 0; }
.hud { width: 100%; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hud .grow { flex: 1; }
.pill { background: rgba(255, 255, 255, 0.92); color: var(--ink); border-radius: 999px; padding: 6px 12px; font-weight: 800; font-size: 0.9em; display: inline-flex; align-items: center; gap: 6px; }
.pill.player { border: 3px solid transparent; }
.pill.player.active { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(232, 182, 74, 0.35); }
.pill.player img { width: 28px; height: 28px; }
.iconbtn { border: 0; width: 46px; height: 46px; border-radius: 14px; background: rgba(255, 255, 255, 0.92); color: var(--ink); font-size: 1.2em; display: grid; place-items: center; font-weight: 800; }
.iconbtn[disabled] { opacity: 0.45; }
.bar { width: 100%; height: 10px; border-radius: 99px; background: rgba(255, 255, 255, 0.18); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #7fd38b, #ffd36b); transform-origin: left; }
.bar.think { height: 5px; }
.bar.think i { background: #c8b8ff; }
.objective { color: #f3ebff; font-size: 0.88em; margin-top: 6px; text-align: center; min-height: 1.2em; }
.board-wrap { flex: 1; width: 100%; display: grid; place-items: center; min-height: 0; padding: 8px 0; }
.board { display: grid; gap: var(--gap, 8px); }
.toast { position: fixed; left: 50%; bottom: calc(14px + var(--safe-bottom)); transform: translateX(-50%); width: min(560px, 92vw); background: var(--paper); color: var(--ink); border-radius: 16px; padding: 10px 14px; box-shadow: var(--shadow); border-left: 6px solid var(--ok); font-size: 0.95em; z-index: 20; display: flex; gap: 10px; align-items: center; }
.toast img { width: 40px; height: 40px; flex: none; }
.toast.neutral { border-left-color: #b8aacb; }
.announce { position: fixed; top: 38%; left: 50%; transform: translate(-50%, -50%); background: rgba(36, 29, 58, 0.92); color: #fff; padding: 14px 22px; border-radius: 18px; font-weight: 800; z-index: 25; text-align: center; box-shadow: var(--shadow); }

/* ——— Cartes magiques ——— */
.card { position: relative; border: 0; padding: 0; background: transparent; width: var(--cw); height: var(--ch); perspective: 900px; border-radius: 14px; }
.card .inner { position: absolute; inset: 0; transition: transform 0.42s cubic-bezier(0.3, 0.7, 0.3, 1); transform-style: preserve-3d; }
.card.up .inner, .card.hint .inner, .card.matched .inner { transform: rotateY(180deg); }
.card .back, .card .front { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 14px; overflow: hidden; }
.card .back {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 230, 166, 0.35) 0 18%, transparent 19%),
    repeating-linear-gradient(95deg, rgba(0, 0, 0, 0.05) 0 3px, transparent 3px 9px),
    linear-gradient(160deg, var(--wood-light), var(--wood) 55%, var(--wood-dark));
  border: 3px solid var(--gold);
  box-shadow: inset 0 0 0 3px rgba(111, 74, 47, 0.6), inset 0 0 0 6px rgba(255, 230, 166, 0.45), 0 5px 0 rgba(0, 0, 0, 0.25);
  display: grid; place-items: center;
}
.card .back svg { width: 58%; height: 58%; opacity: 0.9; }
.card .front {
  transform: rotateY(180deg);
  background: linear-gradient(170deg, #fffdf7, #fff4dc);
  border: 3px solid var(--gold);
  box-shadow: inset 0 0 0 2px rgba(200, 145, 58, 0.35), 0 5px 0 rgba(0, 0, 0, 0.22);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6%;
  text-align: center;
}
.card .front img { width: 82%; height: 72%; object-fit: contain; }
.card .front .emo { font-size: calc(var(--cw) * 0.48); line-height: 1; }
.card .front .txt { font-weight: 800; line-height: 1.12; overflow-wrap: break-word; hyphens: manual; color: var(--ink); }
.card .front .sub { font-size: 0.72em; font-weight: 700; color: var(--ink-soft); }
.card .front .badge { position: absolute; top: 4px; left: 6px; font-size: 0.8em; }
.card .front.question { background: linear-gradient(170deg, #f4efff, #e9e0ff); }
.card .front.question .txt { font-weight: 700; font-style: italic; }
.card .front .lettre { font-family: 'Andika', 'Comic Sans MS', var(--font); }
.card .front .oeuvre { font-style: italic; }
.card .sil { filter: brightness(0) opacity(0.82); }
.card.matched .front { border-color: #8fd39a; box-shadow: inset 0 0 0 3px rgba(79, 174, 90, 0.35), 0 0 18px rgba(143, 211, 154, 0.7); }
.card.matched { animation: joie 0.5s ease; }
@keyframes joie { 40% { transform: scale(1.07); } }
.card.miss .front { border-color: #b8aacb; }
.card.hint .front { border-color: #ffd36b; box-shadow: 0 0 22px rgba(255, 211, 107, 0.9); }
.card:disabled { cursor: default; }
.card .snd { font-size: calc(var(--cw) * 0.36); }
.card .snd-label { font-size: 0.75em; font-weight: 700; color: var(--ink-soft); }
.card .color-sw { width: 72%; height: 58%; border-radius: 12px; border: 3px solid rgba(0, 0, 0, 0.12); }
.card .shape svg { width: 70%; height: 70%; }
.card .dots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8%; width: 76%; }
.card .dots i { aspect-ratio: 1; border-radius: 50%; background: #e2694a; display: block; }
.board.warn .card.down { animation: brise 0.8s ease-in-out infinite; }
@keyframes brise { 50% { transform: rotate(-2deg) translateY(-2px); } }
.reduit .card .inner { transition: none; }
.reduit .card.up .inner, .reduit .card.hint .inner, .reduit .card.matched .inner { transform: none; }
.reduit .card .front { transform: none; opacity: 0; }
.reduit .card.up .front, .reduit .card.hint .front, .reduit .card.matched .front { opacity: 1; }
.reduit .card.up .back, .reduit .card.hint .back, .reduit .card.matched .back { opacity: 0; }
.reduit .card.matched, .reduit .board.warn .card.down { animation: none; }
.reduit .board.warn .card.down .back { outline: 3px dashed var(--gold-light); }

/* ——— Séquences et positions ——— */
.seq { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(80px, 150px)); gap: 14px; }
.seq button { aspect-ratio: 1; border-radius: 24px; border: 4px solid rgba(255, 255, 255, 0.55); display: grid; place-items: center; font-weight: 900; font-size: 1.3em; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); opacity: 0.62; transition: transform 0.12s, opacity 0.12s, box-shadow 0.12s; background: #777; }
.seq button img { width: 78%; height: 78%; object-fit: contain; }
.seq button svg { width: 46%; height: 46%; }
.seq button.lit { opacity: 1; transform: scale(1.08); box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.8), 0 0 36px rgba(255, 240, 180, 0.95); }
.seq button.ok { box-shadow: 0 0 0 6px #8fd39a; opacity: 1; }
.seq button.no { box-shadow: 0 0 0 6px #b8aacb; }
.seq.input button { opacity: 1; }
.pos { display: grid; grid-template-columns: repeat(var(--cols, 3), var(--cs, 84px)); gap: 10px; }
.pos button { width: var(--cs); height: var(--cs); border-radius: 18px; border: 3px solid var(--gold); background: linear-gradient(160deg, var(--wood-light), var(--wood)); padding: 6px; display: grid; place-items: center; }
.pos button img { width: 92%; height: 92%; object-fit: contain; }
.pos button.found { background: linear-gradient(170deg, #fffdf7, #e9f7ea); border-color: #8fd39a; }
.pos button.miss { background: #eadff7; }
.ask { display: flex; align-items: center; gap: 10px; background: var(--paper); color: var(--ink); border-radius: 18px; padding: 8px 14px; font-weight: 800; margin: 8px 0; }
.ask img { width: 48px; height: 48px; }

/* ——— Aventure ——— */
.worlds { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.world { border: 0; border-radius: 22px; padding: 16px; text-align: left; color: var(--ink); background: linear-gradient(160deg, var(--sky), #fff); box-shadow: var(--shadow); position: relative; min-height: 130px; padding-bottom: 38px; border-bottom: 8px solid var(--accent); }
.world b { font-size: 1.15em; display: block; }
.world .n { font-size: 0.8em; color: var(--ink-soft); font-weight: 800; }
.world .stars { position: absolute; right: 14px; bottom: 10px; font-weight: 800; }
.world.locked { filter: grayscale(0.75) brightness(0.92); }
.path { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lvl { border: 0; border-radius: 18px; padding: 12px; background: var(--paper); color: var(--ink); text-align: left; min-height: 96px; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15); display: flex; flex-direction: column; gap: 4px; border-top: 6px solid var(--world-accent); }
.lvl .num { font-weight: 900; color: var(--world-accent); }
.lvl .st { letter-spacing: 2px; }
.lvl[disabled] { opacity: 0.55; filter: grayscale(0.6); }
.guide { display: flex; gap: 12px; align-items: flex-start; }
.guide img, .guide .ph { width: 76px; height: 76px; flex: none; object-fit: contain; }
.guide .ph { border-radius: 50%; background: #dff0d8; display: grid; place-items: center; font-weight: 900; font-size: 1.6em; color: #4e9e43; border: 3px dashed #9ccc92; }
.bubble { background: var(--cream); border-radius: 16px; padding: 10px 14px; position: relative; line-height: 1.4; }
.stars-big { font-size: 2.6em; letter-spacing: 6px; text-align: center; margin: 6px 0; color: var(--gold); text-shadow: 0 2px 0 var(--gold-2); }
.stars-big .off { color: var(--ink); opacity: 0.18; text-shadow: none; }
.learned { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.learned li { background: var(--cream); border-radius: 12px; padding: 8px 12px; }
.learned li b { color: var(--ink); }
.learned li span { display: block; font-size: 0.9em; color: var(--ink-soft); }
.reward { display: flex; gap: 10px; align-items: center; background: #fff4d6; border: 2px solid var(--gold); border-radius: 14px; padding: 10px; margin-top: 10px; font-weight: 700; }
.collection { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.item { background: var(--cream); border-radius: 16px; padding: 12px; text-align: center; font-size: 0.86em; font-weight: 700; min-height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.item .big { font-size: 2.2em; }
.item img { width: 64px; height: 64px; object-fit: contain; }
.item.locked { opacity: 0.5; }
.item.locked img { filter: brightness(0) opacity(0.35); }
table.rec { width: 100%; border-collapse: collapse; font-size: 0.92em; }
table.rec td, table.rec th { padding: 8px 6px; border-bottom: 1px solid #eee4d4; text-align: left; }
.know { display: grid; gap: 8px; }
.know details { background: var(--cream); border-radius: 12px; padding: 10px 12px; }
.know summary { font-weight: 800; cursor: pointer; }

/* ——— Fenêtres ——— */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 14, 36, 0.6); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--paper); border-radius: 22px; padding: 20px; width: min(460px, 100%); box-shadow: var(--shadow); max-height: 92dvh; overflow: auto; }
.modal h2 { margin-top: 0; }
.avatars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.avatars button { border: 3px solid transparent; border-radius: 14px; background: var(--cream); padding: 4px; aspect-ratio: 1; }
.avatars button[aria-pressed='true'] { border-color: var(--duo); }
.avatars img { width: 100%; height: 100%; object-fit: contain; }

@media (prefers-reduced-motion: reduce) { #fireflies { display: none; } }
@media (max-height: 560px) and (orientation: landscape) { .logo { width: 300px; } .mode { min-height: 92px; } }
