:root {
  --bg: #0d1117;
  --panel: #161c26;
  --panel-2: #1f2735;
  --text: #e6e9ef;
  --muted: #9aa4b2;
  --accent: #d9a441;
  --agent: #3d8bfd;
  --danger: #e5484d;
  --ok: #3fb950;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid #2f3a4d;
  border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-big { padding: 12px 24px; font-size: 1.1rem; background: var(--accent); color: #1a1405; border: none; font-weight: 600; }

/* ---------- Vues ---------- */
.view { position: fixed; inset: 0; }
#view-board { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 64px 16px 16px; }
#board-wrap { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 0; }
#board { display: block; cursor: pointer; border-radius: 6px; box-shadow: 0 10px 40px #0008; }
.board-help { color: var(--muted); font-size: .85rem; margin: 10px 0 0; text-align: center; }

#room-canvas, #room-canvas canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#room-canvas { background: #111; overflow: hidden; }
/* Fond figé et flouté quand un objet est tenu devant la caméra */
.room-backdrop { display: none !important; }
.room-backdrop.in, .room-backdrop.out { display: block !important; filter: blur(10px) brightness(.55); transform: scale(1.05); }
.room-backdrop.in { animation: focus-in .45s ease-out; }
.room-backdrop.out { animation: focus-out .3s ease-in forwards; }
@keyframes focus-in { from { filter: none; transform: none; } }
@keyframes focus-out { to { filter: none; transform: none; } }
#room-ui .room-help {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  background: #0009; padding: 6px 12px; border-radius: 6px; font-size: .8rem; color: #cfd6e0; pointer-events: none; white-space: nowrap;
}
.move-pad {
  position: absolute; left: 16px; bottom: 16px; display: grid;
  grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(2, 52px); gap: 6px;
}
.move-pad button {
  background: #000a; color: #fff; border: 1px solid #fff3; border-radius: 10px; font-size: 1.3rem;
  cursor: pointer; user-select: none; touch-action: none;
}
.move-pad button:active { background: #fff3; }
.move-pad .pad-back { grid-column: 2; }
#btn-exit-room { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); }

#tooltip {
  position: fixed; pointer-events: none; background: #000c; color: #fff; padding: 5px 9px;
  border-radius: 6px; font-size: .85rem; border: 1px solid var(--accent); z-index: 15; white-space: nowrap;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; height: 52px; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px;
  background: linear-gradient(#000c, #0000); pointer-events: none;
}
#hud > * { pointer-events: auto; }
#hud-timer { font: 700 1.5rem/1 ui-monospace, Consolas, monospace; letter-spacing: 1px; }
#hud-timer.low { color: var(--danger); animation: blink 1s infinite; }
#hud-place { font-weight: 600; color: var(--accent); }
@keyframes blink { 50% { opacity: .45; } }

#threat {
  position: fixed; top: 58px; right: 16px; z-index: 40; font-size: .85rem; padding: 4px 10px;
  border-radius: 6px; background: #000a; pointer-events: none;
}
#threat.alert { color: #fff; background: var(--danger); animation: blink .6s infinite; }
#threat.near { color: #ffb4b4; }
#minimap {
  position: fixed; right: 16px; bottom: 16px; z-index: 40; border-radius: 6px;
  border: 1px solid #fff4; box-shadow: 0 4px 20px #000a; pointer-events: none;
}
#stress {
  position: fixed; top: 90px; right: 16px; z-index: 40; display: flex; align-items: center; gap: 8px;
  font-size: .75rem; color: #ffb4b4; background: #000a; padding: 4px 10px; border-radius: 6px; pointer-events: none;
}
#stress .bar { width: 110px; height: 8px; background: #fff2; border-radius: 4px; overflow: hidden; }
#stress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #d9a441, var(--danger)); }

/* ---------- Stress ----------
   body[data-stress] : 1 = bord rouge qui bat · 2 = tremblement + flou · 3 = paupières lourdes.
   Uniquement du CSS (transform/opacity/filter) : la 3D n'a pas à être recalculée. */
#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 35; opacity: 0;
  background: radial-gradient(ellipse at center, #0000 55%, #e5484daa 100%); transition: opacity .3s;
}
#vignette::after {
  content: ""; position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(ellipse at center, #0000 35%, #a00c0cbb 100%);
}
body[data-stress="1"] #vignette::after { animation: heartbeat 1.1s infinite; }
body[data-stress="2"] #vignette::after { animation: heartbeat .8s infinite; }
body[data-stress="3"] #vignette::after { animation: heartbeat .55s infinite; }
@keyframes heartbeat { 0%, 60%, 100% { opacity: 0; } 12% { opacity: 1; } 28% { opacity: .25; } 40% { opacity: .75; } }

body[data-stress="2"] :is(#view-board, #view-room, #overlay) { animation: shake .3s infinite; filter: blur(.7px); }
body[data-stress="3"] :is(#view-board, #view-room, #overlay) { animation: shake-hard .2s infinite; filter: blur(1.6px) saturate(.7); }
@keyframes shake { 25% { transform: translate(1.5px, -1px); } 50% { transform: translate(-1px, 1.5px); } 75% { transform: translate(-1.5px, -.5px); } }
@keyframes shake-hard { 25% { transform: translate(3px, -2px) rotate(.3deg); } 50% { transform: translate(-2px, 3px); } 75% { transform: translate(-3px, -1px) rotate(-.3deg); } }

#eyelids { position: fixed; inset: 0; pointer-events: none; z-index: 36; display: none; }
body[data-stress="3"] #eyelids { display: block; }
#eyelids::before, #eyelids::after {
  content: ""; position: absolute; left: -10%; right: -10%; height: 42%; background: #000;
  transform: scaleY(0); animation: eyelid 2.6s infinite ease-in-out;
}
#eyelids::before { top: 0; transform-origin: top; border-radius: 0 0 50% 50%; }
#eyelids::after { bottom: 0; transform-origin: bottom; border-radius: 50% 50% 0 0; }
@keyframes eyelid { 0%, 50%, 100% { transform: scaleY(0); } 66%, 76% { transform: scaleY(.85); } }

#hide { z-index: 85; background: radial-gradient(ellipse at center, #1a0606, #000); animation: zoom-in .25s ease-out; }
.hide-card { text-align: center; background: transparent; border: none; box-shadow: none; }
.hide-card h1 { color: var(--danger); }
#hide-loss { font: 700 2rem ui-monospace, Consolas, monospace; color: var(--danger); margin-top: 8px; }

/* ---------- Overlay d'interfaces ---------- */
#overlay { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: #0003; }
#overlay > * { animation: zoom-in .35s ease-out; }
@keyframes zoom-in { from { transform: scale(.35); opacity: 0; } to { transform: none; opacity: 1; } }

/* Interface "document" (modèle réutilisable, première version) */
.paper {
  width: min(520px, 92vw); max-height: 80vh; overflow: auto; padding: 36px 40px 28px;
  background: #f6f0e1; color: #2b2418; border-radius: 3px; box-shadow: 0 20px 60px #000c;
  font-family: "Segoe Print", "Bradley Hand", cursive; line-height: 1.6;
  background-image: repeating-linear-gradient(#f6f0e1 0 27px, #d8e3ee 27px 28px);
}
.paper h3 { margin: 0 0 12px; font-family: Georgia, serif; }
.paper .sig { text-align: right; margin-top: 18px; }
.paper .btn { margin-top: 16px; font-family: "Segoe UI", sans-serif; }

/* Copie modèle du contrôle (pile de copies, Bureau) */
.exam { display: flex; flex-direction: column; align-items: center; gap: 10px; max-height: 94vh; }
.exam-sheet {
  position: relative; width: min(760px, 94vw); max-height: calc(94vh - 50px); overflow: auto;
  background: #fbfaf6; color: #1d1b18; padding: 26px 34px 22px; border-radius: 2px;
  box-shadow: 0 24px 70px #000d, inset 0 0 60px #e9e3d4; transform: rotate(-.6deg);
  font-family: Georgia, "Times New Roman", serif;
}
.exam-head { display: flex; justify-content: space-between; gap: 16px; font-size: .82rem; line-height: 1.45; border-bottom: 1.5px solid #1d1b18; padding-bottom: 10px; margin-bottom: 14px; }
.exam-name { white-space: nowrap; }
.exam-hand { font-family: "Segoe Print", "Bradley Hand", cursive; color: #1f3d8a; margin-left: 8px; }
.exam-text { width: 100%; height: auto; display: block; }
.exam-margin {
  font-family: "Segoe Print", "Bradley Hand", cursive; color: #c0262d; font-size: .9rem;
  border-left: 2px solid #c0262d; padding-left: 10px; margin: 6px 0 12px; transform: rotate(-1deg);
}
.exam-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-top: 6px; }
.exam-box { border: 1.5px solid #1d1b18; padding: 10px 12px; font-size: .9rem; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; max-width: 470px; }
.exam-box-title { width: 100%; font-size: .72rem; text-transform: uppercase; letter-spacing: 1px; color: #555; }
.exam-input {
  width: 90px; font: 1.15rem "Segoe Print", "Bradley Hand", cursive; color: #c0262d;
  border: none; border-bottom: 1.5px dashed #c0262d; background: transparent; outline: none;
}
.exam-btn { font: inherit; background: #c0262d; color: #fff; border: none; border-radius: 3px; padding: 4px 12px; cursor: pointer; }
.exam-btn:disabled { opacity: .45; cursor: default; }
.exam-msg { width: 100%; font-size: .82rem; min-height: 1.1em; color: #555; }
.exam-msg.err { color: #c0262d; }
.exam-msg.ok { color: #1f7a36; font-weight: bold; }
.exam-attach {
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: #1d1b18;
  background: #fff; border: 1px solid #c9c2b0; padding: 10px 14px 8px; box-shadow: 2px 3px 8px #0002;
  transform: rotate(3deg); font: .8rem ui-monospace, Consolas, monospace; cursor: pointer;
}
.exam-attach:hover { box-shadow: 2px 3px 14px #d9a44188; }
.exam-attach small { color: #777; font-family: Georgia, serif; }
.exam-clip { font-size: 1.6rem; }
.exam-stamp {
  position: absolute; top: 90px; right: 40px; font: 900 3rem Georgia, serif; color: #c0262dcc;
  border: 5px solid #c0262dcc; border-radius: 8px; padding: 2px 16px; transform: rotate(-14deg);
  pointer-events: none; animation: zoom-in .3s ease-out;
}

/* Plateau des pièces de collection (Salle à manger) */
.coins { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(240px, 1fr); gap: 14px; width: min(1000px, 96vw); max-height: 94vh; }
.coins-felt {
  background: radial-gradient(ellipse at 50% 40%, #2d6b45, #163a25); border: 10px solid #3a2214; border-radius: 10px;
  box-shadow: 0 20px 60px #000c, inset 0 0 50px #0008; padding: 14px 16px 12px; color: #e9e2cc;
}
.coins-title { font: 600 1rem Georgia, serif; text-align: center; }
.coins-row { display: flex; justify-content: space-around; gap: 8px; margin: 70px 0 10px; }
.coin-slot { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.coin-stage { width: 110px; height: 110px; perspective: 700px; }
.coin { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; }
.coin-face { position: absolute; inset: 0; border-radius: 50%; background-size: cover; backface-visibility: hidden; box-shadow: 0 6px 14px #0007; }
.coin-face.back { transform: rotateX(180deg); }
.coin-name { font: .85rem Georgia, serif; }
.coin-last { font: 700 1rem ui-monospace, Consolas, monospace; min-height: 1.2em; letter-spacing: 2px; color: #ffe9a8; }
.coins-side { display: flex; flex-direction: column; gap: 12px; }
.coins-book {
  background: #f6f0e1; color: #2b2418; padding: 14px 18px; border-radius: 3px; box-shadow: 0 14px 40px #000b;
  background-image: repeating-linear-gradient(#f6f0e1 0 25px, #d8e3ee 25px 26px); font-family: "Segoe Print", "Bradley Hand", cursive;
}
.coins-book h4 { margin: 0 0 6px; font-family: Georgia, serif; }
.coins-book table { width: 100%; border-collapse: collapse; text-align: center; }
.coins-book th, .coins-book td { padding: 2px 6px; }
.coins-form { background: var(--panel); border: 1px solid #2a3446; border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.coins-pick { display: flex; gap: 14px; }
.coins-radio { cursor: pointer; font-weight: 600; }
.coins-plabel { display: flex; align-items: center; gap: 8px; }
.coins-p { width: 90px; font: inherit; background: var(--panel-2); color: var(--text); border: 1px solid #2f3a4d; border-radius: 6px; padding: 4px 8px; }
.coins-msg { font-size: .85rem; min-height: 1.2em; color: var(--muted); }
.coins-msg.err { color: #ff9a9e; }
.coins-msg.ok { color: #7ee787; }
.coins-close { grid-column: 1 / -1; justify-self: center; }
@media (max-width: 760px) { .coins { grid-template-columns: 1fr; overflow: auto; } }

/* ---------- Modales & écrans ---------- */
.modal, .screen { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: #000b; padding: 16px; }
.screen { background: radial-gradient(ellipse at top, #1d2840, #07090d); }
.modal-card, .screen-card {
  background: var(--panel); border: 1px solid #2a3446; border-radius: 14px; padding: 28px 32px;
  max-width: 640px; width: 100%; box-shadow: 0 20px 60px #000a;
}
.screen-card h1 { margin: 6px 0 14px; font-size: 1.7rem; }
.brief { color: #c9d1dc; line-height: 1.55; }
.controls { color: var(--muted); font-size: .9rem; padding-left: 18px; margin-bottom: 22px; }
.badge {
  display: inline-block; background: var(--accent); color: #1a1405; font-weight: 800; letter-spacing: 3px;
  padding: 4px 10px; border-radius: 4px;
}
#dossier-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin: 16px 0; }
.slot { border: 1px dashed #3a4558; border-radius: 8px; padding: 10px; min-height: 64px; font-size: .8rem; color: var(--muted); }
.slot.filled { border: 1px solid var(--accent); color: var(--text); background: #2a2310; }
.slot code { display: block; font-size: 1.05rem; color: var(--accent); margin-top: 4px; }

#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 80; transition: opacity .45s; }
#fade.on { opacity: 1; pointer-events: auto; }
#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 70;
  background: var(--panel-2); border: 1px solid var(--accent); padding: 10px 16px; border-radius: 8px; max-width: 90vw;
}

/* Popup preuve obtenue */
.proof-pop {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 75;
  background: #1d1708; border: 2px solid var(--accent); border-radius: 12px; padding: 22px 28px;
  text-align: center; box-shadow: 0 0 60px #d9a44155; animation: zoom-in .4s ease-out; max-width: 90vw;
}
.proof-pop code { font-size: 1.6rem; color: var(--accent); display: block; margin: 8px 0; }

#dev-panel {
  position: fixed; left: 16px; top: 60px; z-index: 90; background: #300a; border: 1px solid #f55;
  border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; font-size: .8rem;
}
#dev-panel .btn { padding: 4px 8px; font-size: .8rem; }
