/* Bomben – serietidningsestetik helt i CSS/SVG, samma grund som Kontrollrummet.
   Papper med rasterpunkter, tjock tusch, hårda skuggor, pratbubblor och smällstjärnor. */

:root {
  --paper: #fff3cf;
  --paper-dot: rgba(255, 95, 0, 0.16);
  --ink: #141010;
  --white: #fffdf6;
  --accent: #ff5f00;
  --caption: #ffe14d;
  --sky: #8fd6ff;
  --good: #2ecc71;
  --danger: #ff3b3b;
  --theme: #ff5f00;
  --lcd: #1f3a2b;
  --lcd-text: #a6ffb0;
  --title: "Bangers", Impact, Haettenschweiler, "Arial Narrow Bold", "Arial Black", sans-serif;
  --hand: "Comic Neue", "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
  --line: 3px;
  --shadow: 5px 5px 0 var(--ink);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--hand);
  color: var(--ink);
  background-color: var(--paper);
  /* Rasterpunkter, som i tryckta serietidningar. Två förskjutna lager ger ett snyggare raster. */
  background-image:
    radial-gradient(circle, var(--paper-dot) 1.4px, transparent 1.8px),
    radial-gradient(circle, var(--paper-dot) 1.4px, transparent 1.8px);
  background-size: 12px 12px;
  background-position: 0 0, 6px 6px;
  padding-top: var(--panikbar-h, 0);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 16px 48px;
}

/* ---------------------------------------------------------------- tusch */

/* .ink: tuschkontur som darrar lite, som i tecknad film. Konturen ligger i ::before
   så att texten inuti inte förvrängs av filtret. */
.ink { position: relative; isolation: isolate; }
.ink::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border: var(--line) solid var(--ink);
  border-radius: inherit;
  background: var(--fill, var(--white));
  box-shadow: var(--shadow);
  filter: url(#rough0);
  animation: boil 0.36s steps(1) infinite;
}
@keyframes boil {
  0% { filter: url(#rough0); }
  33% { filter: url(#rough1); }
  66% { filter: url(#rough2); }
}
@media (prefers-reduced-motion: reduce) {
  .ink::before { animation: none; }
}

.frame { padding: 16px; border-radius: 4px; }

.caption {
  display: inline-block;
  background: var(--caption);
  border: var(--line) solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 6px 12px;
  font-family: var(--title);
  font-size: 18px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 8px 0 12px;
}
.caption.voice {
  display: block;
  font-family: var(--hand);
  text-transform: none;
  letter-spacing: 0;
  font-size: 16px;
  background: var(--sky);
  margin: 18px 0;
}
.caption.voice b { font-family: var(--title); font-weight: 400; font-size: 20px; letter-spacing: 0.04em; }
.tilt-l { transform: rotate(-1.5deg); }

/* ---------------------------------------------------------------- knappar och fält */

.btn {
  font-family: var(--title);
  font-size: 20px;
  letter-spacing: 0.05em;
  color: var(--ink);
  background: var(--white);
  border: var(--line) solid var(--ink);
  border-radius: 6px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 10px 18px;
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.big { font-size: 30px; padding: 12px 34px; background: var(--accent); color: var(--white); text-shadow: 2px 2px 0 var(--ink); }
.btn.small { font-size: 16px; padding: 6px 12px; }
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:focus-visible, .code-btn:focus-visible, .diff:focus-visible, .tab:focus-visible, .hose:focus-visible { outline: 4px solid var(--sky); outline-offset: 3px; }
/* Varje tryck: knappen trycks ner och studsar tillbaka. */
.btn.pressed { animation: btn-press 0.28s cubic-bezier(.2, 1.8, .5, 1); }
@keyframes btn-press {
  0% { transform: translate(3px, 3px) scale(0.94); box-shadow: 1px 1px 0 var(--ink); }
  60% { transform: translate(-1px, -1px) scale(1.04); }
}
.btn.busy, .btn:disabled { cursor: progress; opacity: 0.85; transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.done { background: var(--good); color: var(--white); text-shadow: 2px 2px 0 var(--ink); }
.nope { animation: nope 0.3s ease-in-out; }
@keyframes nope { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }
@keyframes squish { 0% { transform: scale(0.9); } 60% { transform: scale(1.06); } }
@keyframes count-pop { from { transform: scale(1.7) rotate(-6deg); } }

/* Siffra som flyger upp vid en händelse ("−15 s"). */
.delta {
  position: absolute; right: 8px; top: -10px; z-index: 5;
  font-family: var(--title); font-size: 26px; letter-spacing: 0.04em;
  -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 2px 2px 0 var(--ink);
  pointer-events: none; white-space: nowrap;
  animation: delta 1s ease-out forwards;
}
.delta.bad { color: var(--danger); }
.delta.good { color: var(--good); }
@keyframes delta {
  0% { transform: scale(0.4); opacity: 0; }
  20% { transform: scale(1.3); opacity: 1; }
  100% { transform: translateY(-34px); opacity: 0; }
}

input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--caption); }
input {
  font: inherit;
  font-size: 18px;
  color: var(--ink);
  background: var(--white);
  border: var(--line) solid var(--ink);
  border-radius: 6px;
  padding: 9px 12px;
  min-width: 0;
}

.error { color: var(--danger); font-weight: 700; }
.hint { font-style: italic; }
.status { min-height: 1.2em; margin: 6px 0; font-style: italic; }

/* ---------------------------------------------------------------- startsidan */

.logo {
  font-family: var(--title);
  font-weight: 400;
  margin: 4px 0 18px;
  line-height: 0.88;
  font-size: clamp(56px, 17vw, 112px);
  letter-spacing: 0.02em;
  color: var(--accent);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 6px 6px 0 var(--ink);
  transform: rotate(-3deg);
}
.logo span { display: block; }
.logo span + span { color: var(--caption); margin-left: 0.4em; }

.cover { margin-bottom: 8px; }
.lead { font-size: 18px; line-height: 1.4; margin: 12px 0 0; }

.actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 8px; }
.join { display: flex; gap: 8px; flex: 1 1 260px; }
.join input { flex: 1; text-transform: uppercase; font-family: var(--title); letter-spacing: 0.1em; }

/* ---------------------------------------------------------------- pratbubblor */

.bubble {
  position: relative;
  background: var(--white);
  border: var(--line) solid var(--ink);
  border-radius: 28px;
  padding: 14px 18px;
  margin: 0 0 22px;
  font-size: 19px;
  line-height: 1.3;
  box-shadow: 3px 3px 0 var(--ink);
}
.bubble::after {
  /* Pratbubblans pip, i tusch. */
  content: "";
  position: absolute;
  left: 36px;
  bottom: -20px;
  width: 22px;
  height: 22px;
  background: var(--white);
  border-right: var(--line) solid var(--ink);
  border-bottom: var(--line) solid var(--ink);
  transform: skewX(35deg) rotate(20deg);
}
.bubble b { font-family: var(--title); font-weight: 400; font-size: 1.2em; letter-spacing: 0.04em; color: var(--accent); -webkit-text-stroke: 1px var(--ink); }

/* ---------------------------------------------------------------- rummet */

.room-head { display: flex; gap: 12px; align-items: stretch; flex-wrap: wrap; }
.code-box { padding: 6px 14px; border-radius: 4px; --fill: var(--caption); display: flex; flex-direction: column; justify-content: center; }
.code-box small { font-family: var(--title); letter-spacing: 0.1em; }
.code-box strong { font-family: var(--title); font-weight: 400; font-size: 30px; letter-spacing: 0.12em; }
.share { display: flex; gap: 8px; flex: 1 1 240px; align-items: center; }
.share input { flex: 1; font-size: 14px; }
body.in-game .room-head { display: none; }
body.in-game .page { padding-top: 10px; }


.strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.mini { padding: 30px 12px 12px; }
.mini p { margin: 0; font-size: 15px; line-height: 1.35; }
.mini .num {
  position: absolute; top: -8px; left: -8px;
  width: 34px; height: 34px; display: grid; place-items: center;
  background: var(--accent); color: var(--white);
  font-family: var(--title); font-size: 22px;
  border: var(--line) solid var(--ink); border-radius: 50%;
}
@media (max-width: 560px) { .strip { grid-template-columns: 1fr; } }

.crew h3 { font-family: var(--title); font-weight: 400; font-size: 24px; letter-spacing: 0.05em; margin: 0 0 8px; }
.crew ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.crew li { border: 2px solid var(--ink); border-radius: 999px; padding: 4px 12px; background: var(--white); font-weight: 700; }
.crew li.me { background: var(--caption); }
.crew li.offline { opacity: 0.45; text-decoration: line-through; }
.controls-row { margin-top: 22px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.crew li.waiting { background: var(--sky); }

/* Ljudord på reglaget */
.mini-burst {
  position: absolute; top: 38%; left: 50%;
  font-family: var(--title); font-size: 22px; color: var(--caption);
  -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(var(--rot));
  animation: fly 0.6s ease-out forwards;
}
@keyframes fly { to { transform: translate(-50%, -160%) rotate(var(--rot)) scale(1.4); opacity: 0; } }
.mini-burst { z-index: 4; }
.mini-burst.good, .mini-burst.bad { font-size: 28px; top: 50%; text-shadow: 2px 2px 0 var(--ink); animation-duration: 0.9s; }
.mini-burst.good { color: var(--good); }
.mini-burst.bad { color: var(--danger); }

/* ---------------------------------------------------------------- smällstjärnor */

.bursts { position: fixed; inset: 0; pointer-events: none; z-index: 100; overflow: hidden; }
.burst {
  position: absolute;
  display: grid; place-items: center;
  width: 210px; height: 150px;
  margin: -75px 0 0 -105px;
  font-family: var(--title);
  font-size: 34px;
  letter-spacing: 0.03em;
  color: var(--ink);
  background: var(--caption);
  /* Stjärnform */
  clip-path: polygon(50% 0%, 61% 22%, 84% 8%, 76% 34%, 100% 40%, 79% 55%, 95% 80%, 67% 72%, 60% 100%, 47% 77%, 26% 96%, 27% 70%, 0% 72%, 18% 52%, 2% 28%, 29% 31%, 22% 6%, 42% 21%);
  filter: drop-shadow(4px 4px 0 var(--ink));
  transform: rotate(var(--rot)) scale(0);
  animation: burst 1.1s cubic-bezier(.2, 1.8, .4, 1) forwards;
}
.burst.good { background: var(--good); color: var(--white); text-shadow: 2px 2px 0 var(--ink); }
.burst.bad { background: var(--danger); color: var(--white); text-shadow: 2px 2px 0 var(--ink); }
.burst.wild { background: var(--sky); }
.burst.small { width: 160px; height: 115px; margin: -57px 0 0 -80px; font-size: 26px; }
.burst.big { width: 300px; height: 210px; margin: -105px 0 0 -150px; font-size: 52px; background: var(--accent); color: var(--white); text-shadow: 3px 3px 0 var(--ink); }
@keyframes burst {
  0% { transform: rotate(var(--rot)) scale(0); }
  18% { transform: rotate(var(--rot)) scale(1.1); }
  75% { transform: rotate(var(--rot)) scale(1); opacity: 1; }
  100% { transform: rotate(var(--rot)) scale(1.25); opacity: 0; }
}

/* ---------------------------------------------------------------- omslag och resultat */

.splash-frame { text-align: center; padding: 28px 16px; --fill: var(--white); }
.big-burst {
  position: relative; margin: 0 auto 16px; left: auto; top: auto;
  width: min(420px, 92%); height: 250px;
  font-size: clamp(32px, 9vw, 48px);
  background: var(--accent); color: var(--white); text-shadow: 3px 3px 0 var(--ink);
  transform: rotate(-4deg); animation: none; --rot: -4deg;
}
.burst-text { display: block; max-width: 52%; text-align: center; line-height: 1.02; }
.big-burst.pop { animation: pop 0.5s cubic-bezier(.2, 1.8, .5, 1); }
#splash-text { font-size: 20px; line-height: 1.4; margin: 0; }

/* ---------------------------------------------------------------- nedräkning */

.overlay {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center;
  font-family: var(--title);
  font-size: min(36vw, 240px);
  color: var(--caption);
  -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill;
  text-shadow: 10px 10px 0 var(--ink);
  background: rgba(255, 243, 207, 0.6);
  pointer-events: none;
}
.overlay.pop { animation: pop 0.4s cubic-bezier(.2, 1.8, .5, 1); }

/* ---------------------------------------------------------------- skak och smäll */

.shake { animation: shake 0.4s; }
@keyframes shake {
  20% { transform: translate(-8px, 3px) rotate(-1deg); }
  40% { transform: translate(7px, -4px) rotate(1deg); }
  60% { transform: translate(-5px, 2px); }
  80% { transform: translate(3px, -1px); }
}
@keyframes pop { from { transform: scale(0.6) rotate(-4deg); } to { transform: none; } }
@keyframes jitter {
  25% { transform: translate(1px, -1px) rotate(0.6deg); }
  75% { transform: translate(-1px, 1px) rotate(-0.6deg); }
}
.big-burst.good { background: var(--good); }
.big-burst.bad { background: var(--danger); }

/* Hela skärmen skakar och blixtrar till när maskinen smäller. */
body.boom { animation: boom 0.9s ease-out; }
@keyframes boom {
  0% { background-color: #fff; }
  10% { transform: translate(-12px, 6px) rotate(-1deg); background-color: var(--caption); }
  25% { transform: translate(10px, -8px) rotate(1deg); background-color: var(--accent); }
  45% { transform: translate(-6px, 4px); }
  70% { transform: translate(3px, -2px); }
}

/* ---------------------------------------------------------------- lobbyn */

.crew { margin-top: 16px; }
.crew li { display: inline-flex; align-items: center; gap: 8px; }
.crew li.defuser { background: var(--accent); color: var(--white); }
.crew li .role {
  font-family: var(--title); font-weight: 400; letter-spacing: 0.06em; font-size: 13px;
  border: 2px solid var(--ink); border-radius: 4px; padding: 0 5px; background: var(--white); color: var(--ink);
}
.crew .hint { margin: 10px 0 0; }

.diff-row { display: flex; gap: 10px; flex-wrap: wrap; }
.diff {
  flex: 1 1 140px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  font: inherit; color: var(--ink); text-align: left;
  background: var(--white); border: var(--line) solid var(--ink); border-radius: 6px;
  padding: 8px 12px; cursor: pointer; box-shadow: 3px 3px 0 var(--ink);
}
.diff b { font-family: var(--title); font-weight: 400; font-size: 22px; letter-spacing: 0.04em; }
.diff:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.diff.on { background: var(--caption); box-shadow: 3px 3px 0 var(--ink), inset 0 0 0 2px var(--ink); }
.diff.on b::after { content: " ✓"; }
.diff.pressed, .diff.pop { animation: squish 0.3s cubic-bezier(.2, 1.8, .5, 1); }
.diff:disabled { cursor: default; }
.diff:disabled:not(.on) { opacity: 0.55; }

/* ---------------------------------------------------------------- HUD */

body.in-game .page { max-width: 1180px; }
.hud { display: flex; gap: 10px; flex-wrap: wrap; }
.hud > div { padding: 6px 12px; border-radius: 4px; display: flex; align-items: center; gap: 8px; }
.hud-label { font-family: var(--title); letter-spacing: 0.08em; font-size: 18px; }
.hud strong { font-family: var(--title); font-weight: 400; font-size: 28px; letter-spacing: 0.04em; }
.timer-box { --fill: var(--caption); }
.timer-box.urgent { --fill: var(--danger); color: var(--white); animation: jitter 0.15s linear infinite; }
/* Fel kostar tid: klockan blinkar rött och skakar till. */
.timer-box.penalty, .machine-timer.penalty { animation: nope 0.4s ease-in-out; }
.timer-box.penalty strong, .machine-timer.penalty strong { color: var(--danger); -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; animation: count-pop 0.35s cubic-bezier(.2, 1.8, .5, 1); }
.timer-box.urgent.penalty strong { color: var(--white); }
.solved-box.win { animation: squish 0.4s cubic-bezier(.2, 1.8, .5, 1); --fill: #c8f5d8; }
.solved-box.win strong { color: var(--good); -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; animation: count-pop 0.35s cubic-bezier(.2, 1.8, .5, 1); }
.strikes { display: flex; gap: 4px; }
.strikes span {
  width: 28px; height: 28px; display: grid; place-items: center;
  border: 2px solid var(--ink); border-radius: 50%; background: var(--white);
  font-weight: 900; color: transparent;
}
.strikes span.on { background: var(--danger); color: var(--white); }
.strikes span.pop { animation: strike-pop 0.5s cubic-bezier(.2, 1.8, .5, 1); }
@keyframes strike-pop { 0% { transform: scale(2.4) rotate(-20deg); box-shadow: 0 0 0 0 rgba(255, 59, 59, 0.9); } 100% { box-shadow: 0 0 0 12px rgba(255, 59, 59, 0); } }
.role-line { font-style: italic; margin: 10px 2px; }

.play-grid { display: grid; gap: 20px; align-items: start; }
.play-grid > * { min-width: 0; }
@media (min-width: 980px) { .play-grid.both { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); } }

/* ---------------------------------------------------------------- maskinen */

.machine-timer {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
  margin: 0 0 26px; max-width: 520px;
}
.machine-timer strong { font-family: var(--title); font-weight: 400; font-size: 40px; letter-spacing: 0.05em; }
.machine-timer span { font-size: 18px; }
.machine-timer.urgent { background: #ffe0d6; animation: jitter 0.12s linear infinite; }
.machine-timer.urgent strong { color: var(--danger); -webkit-text-stroke: 1px var(--ink); }

.machine {
  --fill: color-mix(in srgb, var(--theme) 22%, var(--white));
  border-radius: 14px;
  padding: 18px 16px 16px;
}
/* Sprickor och rök när felen blir fler. */
.machine[data-strikes="1"] { --fill: #ffe1cc; }
.machine[data-strikes="2"] { --fill: #ffbfa3; animation: jitter 0.3s linear infinite; }
.machine-name {
  position: absolute; top: -18px; left: 18px;
  font-family: var(--title); font-size: 26px; letter-spacing: 0.08em;
  background: var(--theme); color: var(--white); text-shadow: 2px 2px 0 var(--ink);
  border: var(--line) solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
  padding: 2px 14px; transform: rotate(-2deg);
}
.machine-head { display: flex; gap: 14px; flex-wrap: wrap; align-items: stretch; margin: 8px 0 16px; }

.type-plate {
  flex: 1 1 240px;
  display: grid; grid-template-columns: repeat(3, auto); gap: 4px 16px; justify-content: start;
  padding: 10px 14px;
  background: linear-gradient(160deg, #e9e9e3, #c9cac2);
  border: var(--line) solid var(--ink); border-radius: 6px;
  box-shadow: 3px 3px 0 var(--ink), inset 0 0 0 4px #fff6;
  position: relative;
}
/* Nitar i hörnen */
.type-plate::before, .type-plate::after {
  content: ""; position: absolute; top: 6px; width: 8px; height: 8px; border-radius: 50%;
  background: #888; border: 2px solid var(--ink);
}
.type-plate::before { left: 6px; }
.type-plate::after { right: 6px; }
.plate-row { display: flex; flex-direction: column; }
.plate-row small { font-family: var(--title); letter-spacing: 0.1em; font-size: 13px; }
.plate-row strong { font-family: var(--title); font-weight: 400; font-size: 26px; letter-spacing: 0.08em; }

.lamps { display: flex; gap: 12px; align-items: center; padding: 6px 8px; }
.lamp { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 64px; }
.lamp i {
  width: 30px; height: 30px; border-radius: 50%;
  border: var(--line) solid var(--ink); background: #5a5a55;
  box-shadow: inset 4px -4px 0 #0004;
}
.lamp.on i { background: radial-gradient(circle at 35% 30%, #fff 0 18%, #ffe14d 20%); box-shadow: 0 0 0 4px #ffe14d88, 0 0 18px #ffe14d; }
.lamp span { font-family: var(--title); letter-spacing: 0.06em; font-size: 15px; }
/* Tänd eller släckt syns även utan färg: släckt lampa får ett kryss. */
.lamp:not(.on) i { background-image: linear-gradient(45deg, transparent 44%, #0008 45% 55%, transparent 56%), linear-gradient(-45deg, transparent 44%, #0008 45% 55%, transparent 56%); }

.modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }

.module {
  --fill: var(--white);
  --shadow: 4px 4px 0 var(--ink);
  border-radius: 8px;
  padding: 10px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 220px;
}
.module .plate {
  font-family: var(--title); font-size: 19px; letter-spacing: 0.05em; text-align: center;
  background: var(--caption); border: 2px solid var(--ink); padding: 3px 6px;
}
.module-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 10px; position: relative; }
.module.solved { --fill: #d9f7e3; }
/* Feedbacklager över modulen: gul puls när man gör något, grön/röd när maskinen svarat. */
.module::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 10px;
  border: 4px solid transparent;
  pointer-events: none;
  z-index: 3;
}
.module.acted::after { animation: mod-acted 0.4s ease-out; }
.module.good::after { animation: mod-good 1s ease-out; }
.module.bad::after { animation: mod-bad 1s ease-out; }
@keyframes mod-acted {
  0% { border-color: var(--caption); box-shadow: 0 0 0 0 rgba(255, 225, 77, 0.9); }
  100% { border-color: transparent; box-shadow: 0 0 0 16px rgba(255, 225, 77, 0); }
}
@keyframes mod-good {
  0%, 45% { border-color: var(--good); background: rgba(46, 204, 113, 0.22); box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.9); }
  100% { border-color: transparent; background: transparent; box-shadow: 0 0 0 20px rgba(46, 204, 113, 0); }
}
@keyframes mod-bad {
  0%, 45% { border-color: var(--danger); background: rgba(255, 59, 59, 0.22); box-shadow: 0 0 0 0 rgba(255, 59, 59, 0.9); }
  100% { border-color: transparent; background: transparent; box-shadow: 0 0 0 20px rgba(255, 59, 59, 0); }
}
.module.solved .module-body { opacity: 0.55; pointer-events: none; }
.stamp {
  position: absolute; top: 46%; left: 50%;
  font-family: var(--title); font-size: 46px; letter-spacing: 0.06em;
  color: var(--good); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  border: 5px solid var(--good); border-radius: 10px; padding: 0 14px; background: #fffc;
  transform: translate(-50%, -50%) rotate(-12deg);
  animation: stamp 0.35s cubic-bezier(.2, 1.8, .5, 1);
  pointer-events: none;
}
@keyframes stamp { from { transform: translate(-50%, -50%) rotate(-12deg) scale(2.4); opacity: 0; } }

/* Slangarna */
.hose-row { display: flex; align-items: center; gap: 0; }
.terminal { width: 14px; height: 26px; background: #555; border: 2px solid var(--ink); border-radius: 3px; flex: none; }
.hose {
  flex: 1; height: 26px; padding: 0; margin: 0 -1px;
  display: flex; gap: 0; background: none; border: 0; cursor: pointer;
  position: relative;
}
.hose .half {
  flex: 1; height: 100%;
  background-color: var(--c);
  border: var(--line) solid var(--ink);
  transition: transform 0.25s cubic-bezier(.3, 1.6, .5, 1), margin 0.25s;
}
.hose .left { border-right: 0; border-radius: 0; }
.hose .right { border-left: 0; }
.hose:hover:not(.cut) .half { filter: brightness(1.1); }
.hose:hover:not(.cut) { transform: scaleY(1.12); }
/* Klippet skickat: slangen spänns och blinkar tills maskinen svarat. */
.hose.snipping .half { filter: brightness(1.25); animation: snip-wait 0.25s ease-in-out infinite alternate; }
@keyframes snip-wait { to { transform: scaleY(0.8); } }
.hose.wrong .half { animation: nope 0.35s ease-in-out; box-shadow: 0 0 0 3px var(--danger); }
/* Mönstren ritas tydligt, i kontrastfärg, och är aldrig skuggning. */
.hose.p-striped .half { background-image: repeating-linear-gradient(90deg, transparent 0 12px, var(--stripe, var(--ink)) 12px 18px); }
.hose.p-dotted .half { background-image: radial-gradient(circle, var(--stripe, var(--ink)) 3.5px, transparent 4.5px); background-size: 16px 100%; }
.hose.c-black, .hose.c-blue { --stripe: var(--white); }
.hose.cut .left { transform: rotate(4deg) translateY(4px); margin-right: 14px; border-right: var(--line) solid var(--ink); border-radius: 0 6px 6px 0; }
.hose.cut .right { transform: rotate(-5deg) translateY(5px); margin-left: 14px; border-left: var(--line) solid var(--ink); border-radius: 6px 0 0 6px; }
.hose.cut { cursor: default; }

/* Felkoden */
.lcd {
  background: var(--lcd); color: var(--lcd-text);
  border: var(--line) solid var(--ink); border-radius: 6px;
  padding: 10px 12px; min-height: 86px;
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  box-shadow: inset 0 0 0 3px #0006;
  text-shadow: 0 0 6px #a6ffb099;
}
.lcd-code { font-family: var(--title); font-weight: 400; font-size: 38px; letter-spacing: 0.12em; line-height: 1; }
.lcd-text { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; font-weight: 700; letter-spacing: 0.04em; }
.dots { display: flex; gap: 6px; justify-content: center; }
.dots span { width: 14px; height: 14px; border: 2px solid var(--ink); border-radius: 50%; background: var(--white); }
.dots span.on { background: var(--good); }
.dots span.pop { animation: strike-pop-good 0.45s cubic-bezier(.2, 1.8, .5, 1); }
@keyframes strike-pop-good { 0% { transform: scale(2.2); box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.9); } 100% { box-shadow: 0 0 0 10px rgba(46, 204, 113, 0); } }
.code-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.code-btn {
  font-family: var(--title); font-size: 18px; letter-spacing: 0.05em; color: var(--ink);
  background: var(--white); border: var(--line) solid var(--ink); border-radius: 6px;
  box-shadow: 0 4px 0 var(--ink); padding: 8px 4px; cursor: pointer;
  touch-action: manipulation;
}
.code-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); filter: brightness(1.1); }
/* Varje tryck studsar; rätt blinkar grönt, fel rött. Fastnar aldrig i nedtryckt läge. */
.code-btn.hit { animation: code-press 0.25s ease-out; }
@keyframes code-press {
  0% { transform: translateY(4px) scale(0.94); box-shadow: 0 0 0 var(--ink), 0 0 0 0 rgba(255, 225, 77, 0.9); filter: brightness(1.25); }
  60% { transform: translateY(-1px) scale(1.04); box-shadow: 0 5px 0 var(--ink), 0 0 0 12px rgba(255, 225, 77, 0); }
}
.code-btn.right { animation: code-right 0.7s ease-out; }
.code-btn.wrong { animation: code-wrong 0.7s ease-out; }
@keyframes code-right { 0%, 50% { background: var(--good); color: var(--white); text-shadow: 2px 2px 0 var(--ink); transform: scale(1.06); } }
@keyframes code-wrong {
  0%, 50% { background: var(--danger); color: var(--white); text-shadow: 2px 2px 0 var(--ink); }
  10% { transform: translateX(-5px); } 20% { transform: translateX(5px); } 30% { transform: translateX(-3px); } 40% { transform: none; }
}
.code-btn.pump { background: var(--sky); font-size: 22px; }
.code-btn.lock { background: var(--accent); color: var(--white); text-shadow: 2px 2px 0 var(--ink); font-size: 22px; }

/* Trycket */
.gauge { width: 100%; max-width: 260px; margin: 0 auto; display: block; overflow: visible; }
.gauge-face { fill: var(--white); stroke: var(--ink); stroke-width: 4; }
.gauge-tick { stroke: var(--ink); stroke-width: 3; }
.gauge-num { font-family: var(--title); font-size: 17px; text-anchor: middle; fill: var(--ink); }
.gauge-unit { font-family: var(--title); font-size: 13px; letter-spacing: 1px; text-anchor: middle; fill: var(--ink); opacity: 0.7; }
.gauge-needle {
  stroke: var(--danger); stroke-width: 5; stroke-linecap: round;
  transform-origin: 100px 105px; transform-box: view-box;
  transition: transform 0.25s cubic-bezier(.3, 1.6, .5, 1);
}
.gauge-hub { fill: var(--ink); }
.gauge.bump { animation: gauge-bump 0.2s ease-out; }
@keyframes gauge-bump { 0% { transform: translateY(2px) scale(0.98); } }

/* ---------------------------------------------------------------- manualen */

.manual-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tab {
  font-family: var(--title); font-size: 16px; letter-spacing: 0.04em; color: var(--ink);
  background: var(--white); border: 2px solid var(--ink); border-radius: 6px 6px 0 0;
  padding: 6px 12px; cursor: pointer;
}
.tab:hover:not(.on) { background: #fff7d6; }
.tab:active { transform: translateY(2px); }
.tab.on { background: var(--caption); box-shadow: 0 3px 0 var(--ink); transform: translateY(-3px); }
/* Ny sida i manualen bläddras fram. */
.manual-page.flip { animation: flip 0.3s ease-out; transform-origin: left center; }
@keyframes flip { from { transform: perspective(900px) rotateY(-22deg) translateX(-12px); opacity: 0.2; } }

/* Ett slitet instruktionshäfte: kaffefläck och hundöra, men aldrig ovanpå texten. */
.manual-page {
  --fill: #fffaf0;
  border-radius: 4px;
  padding: 18px 16px 20px;
  font-size: 17px;
  line-height: 1.45;
}
.manual-page::after {
  content: ""; position: absolute; right: -6px; top: -10px; width: 90px; height: 90px; z-index: -1;
  border-radius: 50%;
  border: 7px solid #8a5a3b33;
  pointer-events: none;
}
.page-num { position: absolute; top: 10px; right: 14px; font-family: var(--title); letter-spacing: 0.1em; font-size: 14px; opacity: 0.6; }
.page-title {
  font-family: var(--title); font-weight: 400; font-size: 32px; letter-spacing: 0.05em; margin: 0 0 6px;
  color: var(--theme); -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; text-shadow: 3px 3px 0 var(--ink);
}
.look { margin: 0 0 14px; font-size: 15px; }
.look b { font-family: var(--title); font-weight: 400; letter-spacing: 0.05em; }
.tech { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
/* Teknikern: en enkel tecknad gubbe med keps, ritad i CSS. */
.tech-face {
  flex: none; width: 54px; height: 54px; border-radius: 50%; margin-top: 6px;
  border: var(--line) solid var(--ink); background: #ffd9b3;
  background-image:
    radial-gradient(circle at 34% 52%, var(--ink) 0 3px, transparent 3.5px),
    radial-gradient(circle at 66% 52%, var(--ink) 0 3px, transparent 3.5px),
    radial-gradient(ellipse at 50% 74%, transparent 0 7px, var(--ink) 7.5px 9px, transparent 9.5px),
    linear-gradient(var(--theme) 0 34%, var(--ink) 34% 39%, transparent 39%);
  box-shadow: 2px 2px 0 var(--ink);
}
.tech-bubble { flex: 1; font-size: 16px; margin: 0 0 12px; border-radius: 18px; padding: 10px 14px; }
.tech-bubble::after { left: -14px; bottom: auto; top: 16px; transform: rotate(100deg) skewX(30deg); }
.tech-bubble b { font-size: 1em; color: var(--ink); -webkit-text-stroke: 0; }

.m-p { margin: 10px 0; }
.m-block h4 { font-family: var(--title); font-weight: 400; font-size: 22px; letter-spacing: 0.05em; margin: 16px 0 6px; border-bottom: 3px solid var(--ink); }
.m-rules, .m-steps { margin: 0; padding-left: 0; list-style: none; counter-reset: rule; }
.m-rules li, .m-steps li {
  counter-increment: rule;
  position: relative; padding: 6px 8px 6px 40px; margin: 4px 0;
  border: 2px solid var(--ink); border-radius: 4px; background: var(--white);
}
.m-rules li::before, .m-steps li::before {
  content: counter(rule);
  position: absolute; left: 6px; top: 6px;
  width: 24px; height: 24px; display: grid; place-items: center;
  font-family: var(--title); font-size: 15px;
  background: var(--caption); border: 2px solid var(--ink); border-radius: 50%;
}
.manual-page b { font-weight: 900; }
.m-table-wrap { overflow-x: auto; margin: 12px 0; border: var(--line) solid var(--ink); background: var(--white); }
.m-table { border-collapse: collapse; width: 100%; font-size: 15px; }
.m-table th { font-family: var(--title); font-weight: 400; letter-spacing: 0.05em; font-size: 17px; text-align: left; background: var(--caption); }
.m-table th, .m-table td { border: 1.5px solid var(--ink); padding: 6px 8px; vertical-align: top; }
.m-table tbody tr:nth-child(even) td { background: #fff3cf; }
.m-table td:first-child { font-family: var(--title); font-size: 18px; letter-spacing: 0.06em; white-space: nowrap; }

/* ---------------------------------------------------------------- mobil */

@media (max-width: 560px) {
  .modules { grid-template-columns: 1fr; }
  .hud strong { font-size: 22px; }
  .machine-timer strong { font-size: 32px; }
  .type-plate { grid-template-columns: repeat(2, auto); }
  .lamp { min-width: 0; }
  .manual-page { padding: 14px 12px 16px; font-size: 16px; }
  .m-table { font-size: 14px; }
  /* Felkodstabellen: meddelandet är bara kul extra. Koden räcker för att slå upp, så kolumnen göms på smal skärm. */
  .m-table.wide th:nth-child(2), .m-table.wide td:nth-child(2) { display: none; }
}

/* Spelaren har valt "mindre skakning/blixtar": inga skak, blixtar eller darr. Spelet funkar lika bra utan. */
:root[data-reduced-motion] .shake,
:root[data-reduced-motion] body.boom,
:root[data-reduced-motion] .timer-box.urgent,
:root[data-reduced-motion] .machine-timer.urgent,
:root[data-reduced-motion] .machine[data-strikes="2"],
:root[data-reduced-motion] .ink::before { animation: none; }
:root[data-reduced-motion] body.boom { background-color: var(--caption); }
:root[data-reduced-motion] .big-burst.pop,
:root[data-reduced-motion] .overlay.pop,
:root[data-reduced-motion] .btn.pressed,
:root[data-reduced-motion] .nope,
:root[data-reduced-motion] .diff.pressed,
:root[data-reduced-motion] .diff.pop,
:root[data-reduced-motion] .timer-box.penalty,
:root[data-reduced-motion] .machine-timer.penalty,
:root[data-reduced-motion] .solved-box.win,
:root[data-reduced-motion] .strikes span.pop,
:root[data-reduced-motion] .hose.snipping .half,
:root[data-reduced-motion] .hose.wrong .half,
:root[data-reduced-motion] .code-btn.hit,
:root[data-reduced-motion] .gauge.bump,
:root[data-reduced-motion] .manual-page.flip { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .btn.pressed, .nope, .diff.pressed, .diff.pop, .timer-box.penalty, .machine-timer.penalty, .solved-box.win,
  .strikes span.pop, .hose.snipping .half, .hose.wrong .half, .code-btn.hit, .gauge.bump, .manual-page.flip { animation: none; }
}
