:root {
  --case: #2d322e;
  --case-2: #3a413c;
  --well: #171b18;
  --well-2: #202621;
  --line: #4a534c;
  --tape: #dcd7c3;
  --tape-ink: #16190f;
  --amber: #ffb23e;
  --alarm: #f2452c;
  --ok: #53d684;
  --paper: #eef1f2;
  --paper-ink: #162033;
  --paper-line: #c3ccd2;
  --stamp: #bb3320;
  --mark: #ffe58a;
  --kw: #1f4fa3;
  --f-ind: "Bahnschrift", "Barlow Condensed", "Roboto Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --f-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-doc: "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --f-lcd: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--f-ui);
  font-size: 16px;
  line-height: 1.45;
  color: #e7e9e4;
  background: radial-gradient(1200px 600px at 50% -10%, #1d2420 0%, #0e110f 60%);
}
body[data-role="manual"] { background: #c5ced3; color: var(--paper-ink); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
h1, h2, h3, h4, p { margin: 0; }

.offline {
  display: none;
  position: fixed; z-index: 50; left: 50%; top: 60px; transform: translateX(-50%);
  background: var(--alarm); color: #fff; padding: 8px 16px; border-radius: 6px; font-weight: 600;
}
body.offline-on .offline { display: block; }

/* ---------- éléments communs ---------- */

.tape {
  display: inline-block;
  background: var(--tape);
  color: var(--tape-ink);
  font-family: var(--f-ind);
  font-weight: 700;
  padding: 0.15em 0.6em;
  border-radius: 2px;
  box-shadow: inset 0 1px 0 #fff8, 0 2px 4px #0007;
}

button.primary, button.secondary, .btn {
  border-radius: 8px; border: 1px solid transparent; padding: 10px 18px; font-weight: 600; min-height: 44px;
}
button.primary { background: var(--amber); color: #1a1200; }
button.primary:hover:not(:disabled) { background: #ffc566; }
button.primary:disabled { background: #4b4a42; color: #9a978a; }
button.secondary { background: transparent; border-color: #5b655d; color: inherit; }
button.secondary:hover { background: #ffffff12; }
button.small { min-height: 34px; padding: 4px 12px; font-size: 0.9rem; }

.toast {
  position: fixed; z-index: 60; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #f3f0e2; color: #16190f; padding: 10px 18px; border-radius: 8px; font-weight: 600;
  box-shadow: 0 6px 24px #0008;
}

/* ---------- accueil ---------- */

.home { max-width: 760px; margin: 0 auto; padding: 48px 20px 64px; }
.hero { margin-bottom: 32px; }
.wordmark { font-size: clamp(2.4rem, 8vw, 4rem); transform: rotate(-1.2deg); padding: 0.05em 0.35em; line-height: 1.1; }
.lede { margin-top: 20px; max-width: 34em; font-size: 1.15rem; color: #c9cec6; }
.join { display: grid; gap: 20px; background: #151a17; border: 1px solid #2c342f; border-radius: 14px; padding: 24px; }
.field { display: grid; gap: 6px; }
.field > span, legend { font-weight: 600; font-size: 0.95rem; color: #c9cec6; }
.field input {
  background: #0d100e; border: 1px solid #46504a; border-radius: 8px; padding: 10px 12px; min-height: 44px; color: #f0f1ec;
}
.field.code input { text-transform: uppercase; letter-spacing: 0.3em; font-family: var(--f-lcd); font-weight: 700; width: 9em; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; }
legend { padding: 0; margin-bottom: 8px; }
.role-card {
  display: grid; gap: 2px; padding: 12px 14px; border: 1px solid #3d4640; border-radius: 10px; cursor: pointer; position: relative;
}
.role-card input { position: absolute; opacity: 0; }
.role-card b { font-size: 1.05rem; }
.role-card span { color: #aab0a7; font-size: 0.95rem; }
.role-card:has(input:checked) { border-color: var(--amber); background: #2a2415; }
.role-card:has(input:focus-visible) { outline: 3px solid var(--amber); outline-offset: 2px; }
.join-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.error { color: #ff8d7b; min-height: 1.4em; }

/* ---------- barre du haut ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 16px; background: #131715; border-bottom: 1px solid #2b332e; color: #e7e9e4;
}
.topbar .tape { font-size: 1.05rem; }
.topbar .where { color: #b8beb5; }
.topbar .where b { color: #fff; font-family: var(--f-lcd); letter-spacing: 0.15em; }
.topbar .grow { flex: 1; }
.topbar .stat { font-variant-numeric: tabular-nums; color: #d6dbd2; }
.topbar .top-timer { font-family: var(--f-lcd); font-weight: 700; color: var(--amber); font-size: 1.2rem; }
.topbar button { min-height: 36px; padding: 4px 12px; font-size: 0.9rem; }

.room { padding: 20px 16px 56px; }
.room-bomb .device, .room-bomb .lobby, .room-bomb .banner { max-width: 980px; margin-left: auto; margin-right: auto; }
.room-spectator { max-width: 1500px; margin: 0 auto; }

/* ---------- salon ---------- */

.lobby { background: #151a17; border: 1px solid #2c342f; border-radius: 14px; padding: 22px; max-width: 980px; margin: 0 auto 20px; color: #e7e9e4; }
.lobby h2 { font-size: 1.4rem; margin-bottom: 4px; }
.lobby .lead { color: #b3b9b0; margin-bottom: 16px; }
.lobby-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 18px; }
.lobby-col { background: #0f1311; border: 1px solid #2c342f; border-radius: 10px; padding: 12px; min-height: 96px; }
.lobby-col h3 { font-size: 0.95rem; color: #aab0a7; margin-bottom: 6px; }
.lobby-col ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.lobby-col li.me { color: var(--amber); font-weight: 600; }
.lobby-col .none { color: #6f776e; font-style: italic; }
.lobby .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.lobby .row > label { display: flex; gap: 8px; align-items: center; color: #c9cec6; }
.lobby select, .lobby input[type="text"] { background: #0d100e; border: 1px solid #46504a; border-radius: 8px; padding: 6px 10px; min-height: 38px; color: #f0f1ec; }
.seg { display: inline-flex; border: 1px solid #46504a; border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 8px 14px; min-height: 38px; }
.seg button[aria-pressed="true"] { background: var(--amber); color: #1a1200; font-weight: 700; }
.hint { color: #aab0a7; font-size: 0.95rem; margin-top: 8px; }

/* ---------- bannière de résultat ---------- */

.banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
  margin: 0 auto 16px; padding: 14px 18px; border-radius: 12px; border: 1px solid; max-width: 980px; color: #f4f5f1;
}
.banner h2 { font-family: var(--f-ind); font-size: 1.6rem; }
.banner p { flex: 1 1 260px; }
.banner.won { background: #123221; border-color: var(--ok); }
.banner.lost { background: #3a1510; border-color: var(--alarm); }
.banner.partial { background: #3a2c0f; border-color: var(--amber); }
.banner.paused { background: #1a2433; border-color: #5a86c4; }
.banner.paused h2 { font-size: 1.2rem; }

/* ---------- la bombe (boîtier de protection) ---------- */

.device {
  position: relative;
  background: linear-gradient(180deg, var(--case-2), var(--case));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: inset 0 1px 0 #ffffff1a, 0 24px 48px #000a;
  color: #e7e9e4;
}
.plate { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.serial { display: grid; gap: 0; transform: rotate(-0.8deg); padding: 6px 14px; }
.serial small { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.03em; }
.serial b { font-size: 1.7rem; letter-spacing: 0.08em; line-height: 1.1; }
.lcd {
  background: #110e07; border: 2px solid #000; border-radius: 8px; padding: 6px 18px;
  box-shadow: inset 0 0 18px #000, 0 1px 0 #ffffff26;
}
.timer { font-family: var(--f-lcd); font-weight: 700; font-size: 2.8rem; line-height: 1.1; color: var(--amber); text-shadow: 0 0 12px #ffb23e88; letter-spacing: 0.06em; }
.timer.is-low { color: #ff7a3d; text-shadow: 0 0 12px #ff7a3d88; }
.timer.is-crit { color: var(--alarm); text-shadow: 0 0 14px #f2452cbb; animation: blink 1s steps(2, jump-none) infinite; }
@keyframes blink { 50% { opacity: 0.45; } }
.strikes { display: flex; align-items: center; gap: 8px; color: #c9cec6; font-size: 0.9rem; }
.led { width: 16px; height: 16px; border-radius: 50%; background: #3a1612; border: 2px solid #000; box-shadow: inset 0 1px 2px #0008; }
.led.on { background: var(--alarm); box-shadow: 0 0 12px var(--alarm); }

.mods { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mod {
  position: relative; background: var(--well); border: 1px solid #0a0c0b; border-radius: 12px; padding: 12px 14px 14px;
  box-shadow: inset 0 2px 8px #000a, 0 1px 0 #ffffff14;
  display: flex; flex-direction: column; gap: 12px; min-height: 230px;
}
.mod-body { flex: 1; display: grid; gap: 12px; align-content: center; }
.mod header { display: flex; align-items: center; justify-content: space-between; }
.mod h3 { font-size: 1rem; padding: 0.05em 0.6em; }
.mod .lock { width: 12px; height: 12px; border-radius: 50%; background: #4a2a24; border: 2px solid #000; }
.mod.is-solved { border-color: #2d6b44; }
.mod.is-solved .lock { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.mod.is-solved .mod-body { opacity: 0.45; }
.done { color: var(--ok); font-weight: 700; font-size: 0.95rem; }

.wires { display: grid; gap: 6px; }
.wire { position: relative; width: 100%; background: transparent; border: 0; padding: 3px 0; border-radius: 6px; }
.wire svg { display: block; width: 100%; height: auto; }
.wire .term { fill: #8d958f; stroke: #000a; stroke-width: 2; }
.wire:hover:not(:disabled) svg { filter: brightness(1.2); }
.wire.is-answer svg { filter: drop-shadow(0 0 6px var(--amber)); }

.tag {
  position: absolute; right: 22px; top: 50%; transform: translateY(-50%);
  background: var(--amber); color: #1a1200; font-size: 0.75rem; font-weight: 700; padding: 1px 8px; border-radius: 4px;
}

.squares, .symbols { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sq, .sym {
  position: relative; aspect-ratio: 1; border-radius: 9px; border: 0; padding: 0;
}
.sq {
  background: var(--c);
  box-shadow: inset 0 -6px 0 #0000004d, inset 0 2px 0 #ffffff55, 0 3px 6px #000a;
}
.sq:hover:not(:disabled), .sym:hover:not(:disabled) { filter: brightness(1.12); }
.sq:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 -2px 0 #0000004d, 0 1px 3px #000a; }
.sq.is-on { outline: 3px solid #fff; outline-offset: -3px; }
.sym {
  background: #2b312c; border: 1px solid #505a52; color: #ebe7d6;
  box-shadow: inset 0 -5px 0 #0000004d, 0 3px 6px #000a;
  display: grid; place-items: center;
}
.sym svg { width: 58%; height: 58%; fill: currentColor; }
.sym.is-on { color: var(--ok); border-color: var(--ok); }
.step {
  position: absolute; top: -7px; right: -7px; min-width: 22px; height: 22px; padding: 0 5px;
  display: grid; place-items: center; border-radius: 11px; background: var(--amber); color: #1a1200; font-weight: 800; font-size: 0.8rem;
  box-shadow: 0 2px 4px #000a; z-index: 1;
}
.pips { display: flex; gap: 5px; min-height: 10px; }
.pip { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 6px var(--ok); }

.lamp-wrap { display: grid; place-items: center; padding: 4px 0; }
.lamp {
  --lamp: transparent;
  width: 82px; height: 82px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #3b423d, #0d100e 75%);
  border: 4px solid #0a0c0b; box-shadow: inset 0 0 14px #000, 0 0 0 3px #3a413c;
}
.lamp.on {
  background: radial-gradient(circle at 35% 30%, #ffffffcc, var(--lamp) 42%, #000a 130%);
  box-shadow: 0 0 34px var(--lamp), 0 0 0 3px #3a413c;
}
.lbtns { display: flex; justify-content: center; gap: 12px; }
.lb {
  width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--c);
  box-shadow: inset 0 -5px 0 #0000004d, inset 0 2px 0 #ffffff55, 0 3px 6px #000a;
}
.lb:hover:not(:disabled) { filter: brightness(1.12); }
.lb:active:not(:disabled) { transform: translateY(2px); }
.lb.is-next { outline: 3px solid var(--amber); outline-offset: 3px; }
.seqchips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 0.9rem; color: #c9cec6; }

.chip { display: inline-block; width: 0.85em; height: 0.85em; border-radius: 50%; background: var(--c); border: 1px solid #0007; vertical-align: -0.05em; margin-right: 0.3em; }

/* ---------- vue du Directeur ---------- */

.director {
  display: flex; flex-wrap: wrap; gap: 10px 24px; align-items: center; justify-content: space-between;
  background: #151a17; border: 1px solid #2c342f; border-radius: 12px; padding: 10px 14px; margin-bottom: 16px; color: #e7e9e4;
}
.d-group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.d-group button { min-height: 38px; padding: 6px 14px; }
.spec-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.spec-col > h2 { font-size: 1rem; color: #aab0a7; font-weight: 600; margin-bottom: 8px; }
.spec-col.js-scroll { max-height: calc(100vh - 150px); overflow: auto; position: sticky; top: 64px; padding-right: 4px; }
.sols { list-style: none; margin: 16px 0 0; padding: 14px 16px; display: grid; gap: 10px; background: #151a17; border: 1px solid #2c342f; border-radius: 12px; }
.sols li { display: grid; gap: 2px; }
.sols li b { color: var(--amber); }
.sols li.done b::after { content: " (résolu)"; color: var(--ok); font-weight: 400; }
.sols li span { color: #aab0a7; font-size: 0.9rem; }

/* ---------- le livret (manuel) ---------- */

.manual {
  position: relative; max-width: 780px; margin: 0 auto;
  background: var(--paper); color: var(--paper-ink); font-family: var(--f-doc); line-height: 1.65;
  padding: 32px 36px 40px; border-radius: 4px;
  box-shadow: 0 1px 0 #fff inset, 0 14px 34px #0007;
}
.m-head { padding-bottom: 18px; margin-bottom: 8px; border-bottom: 3px double var(--paper-line); position: relative; }
.m-head h2 { font-family: var(--f-ind); font-size: 2.1rem; letter-spacing: 0.01em; }
.m-sub { color: #475569; }
.m-how { margin-top: 12px; max-width: 36em; }
.stamp {
  position: absolute; right: 0; top: 4px; transform: rotate(-7deg);
  border: 3px solid var(--stamp); color: var(--stamp); padding: 2px 12px; border-radius: 4px;
  font-family: var(--f-ind); font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.85;
}
.decoy-badge { font-family: var(--f-ui); font-size: 0.8rem; font-weight: 600; color: #8a4b00; border: 1px dashed #c47a00; border-radius: 10px; padding: 0 8px; }
.msec.is-decoy .rules { opacity: 0.6; }
.m-head .ghost { margin-top: 14px; background: transparent; border: 1px solid #8b99a6; color: var(--paper-ink); border-radius: 6px; padding: 5px 14px; font-family: var(--f-ui); }
.m-head .ghost:hover { background: #dde4e8; }
.msec { padding-top: 24px; scroll-margin-top: 70px; }
.msec h3 { font-family: var(--f-ind); font-size: 1.6rem; display: flex; align-items: baseline; gap: 12px; border-bottom: 2px solid var(--paper-ink); padding-bottom: 2px; }
.done-badge { font-family: var(--f-ui); font-size: 0.8rem; font-weight: 600; color: #146c3a; border: 1px solid #146c3a; border-radius: 10px; padding: 0 8px; }
.intro { margin: 10px 0 12px; color: #2c3a50; }
.rules { margin: 0; padding-left: 1.5em; }
.rules li { position: relative; margin: 0 0 10px; padding: 4px 8px 4px 6px; border-radius: 4px; }
.rules li::marker { font-family: var(--f-ind); font-weight: 700; }
.rule.is-match { background: var(--mark); box-shadow: -5px 0 0 #e0a800; }
.now { position: absolute; right: 8px; top: -9px; background: var(--paper-ink); color: #fff; font-family: var(--f-ui); font-size: 0.72rem; padding: 0 8px; border-radius: 8px; }
.kw { font-family: var(--f-ind); color: var(--kw); font-size: 1.02em; letter-spacing: 0.01em; }
.tables { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-top: 14px; }
.tbl { border: 1px solid var(--paper-ink); border-radius: 4px; padding: 8px 12px 10px; background: #fff; }
.tbl h4 { font-family: var(--f-ind); font-size: 1.1rem; margin-bottom: 4px; }
.tbl ul { list-style: none; margin: 0; padding: 0; font-family: var(--f-ui); font-size: 0.95rem; display: grid; gap: 2px; }
.tbl li span { color: #64748b; margin: 0 0.3em; }

/* ---------- adaptation ---------- */

@media (max-width: 1100px) {
  .spec-grid { grid-template-columns: minmax(0, 1fr); }
  .spec-col.js-scroll { position: static; max-height: none; }
}
@media (max-width: 620px) {
  .mods { grid-template-columns: minmax(0, 1fr); }
  .mod { min-height: 0; }
}
@media (max-width: 560px) {
  .manual { padding: 24px 18px 30px; }
  .stamp { position: static; display: inline-block; margin-bottom: 8px; }
  .timer { font-size: 2.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  .timer.is-crit { animation: none; }
  * { scroll-behavior: auto !important; }
}
@media print {
  body, body[data-role] { background: #fff !important; }
  .topbar, .no-print, .offline, .toast, .banner, .director, .lobby, .device, .sols, .spec-col > h2, .stamp + * .x { display: none !important; }
  .room { padding: 0; }
  .spec-grid { display: block; }
  .spec-col:first-child { display: none !important; }
  .spec-col.js-scroll { position: static; max-height: none; overflow: visible; }
  .manual { box-shadow: none; max-width: none; padding: 0; }
  .rule.is-match { background: none; box-shadow: none; }
  .now { display: none; }
  .msec { break-inside: avoid; }
}
