/* Kontrollrummet – serietidningsestetik helt i CSS/SVG.
   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;
  --danger-level: 0;
  --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;
}

/* Rött raster kryper in när skrovet är illa däran. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  opacity: calc(var(--danger-level) * 0.55);
  background-image: radial-gradient(circle, rgba(255, 59, 59, 0.5) 2px, transparent 2.6px);
  background-size: 10px 10px;
  mask-image: radial-gradient(ellipse at center, transparent 45%, #000 100%);
  -webkit-mask-image: radial-gradient(ellipse at center, transparent 45%, #000 100%);
}

.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, .dial-opt:focus-visible, .lever:focus-visible, .big-btn: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); } }

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); }

/* Väntvyn för den som anslöt mitt i spelet */
.waiting { margin-bottom: 18px; }
.waiting-frame { --fill: var(--white); display: flex; flex-direction: column; gap: 12px; }
.burst.welcome {
  position: relative; left: auto; top: auto; margin: 0 auto;
  width: min(300px, 92%); height: 130px;
  font-size: clamp(24px, 7vw, 32px); text-align: center; line-height: 1;
  background: var(--accent); color: var(--white); text-shadow: 2px 2px 0 var(--ink);
  --rot: -3deg; transform: rotate(-3deg); animation: none;
}
.waiting-text { margin: 0; font-size: 19px; line-height: 1.35; text-align: center; font-weight: 700; }
.waiting-stats { display: flex; gap: 10px; }
.waiting-stats .hull { flex: 1; }
#waiting-hull {
  height: 100%;
  background: repeating-linear-gradient(-45deg, var(--good) 0 8px, #22a75b 8px 16px);
  border-right: var(--line) solid var(--ink);
  transition: width 0.4s;
}
#waiting-hull.low { background: repeating-linear-gradient(-45deg, var(--danger) 0 8px, #c92424 8px 16px); }
#waiting-hull-num { font-family: var(--title); font-size: 22px; min-width: 2.2em; text-align: right; }
.waiting-progress { margin: 0; font-style: italic; text-align: center; min-height: 1.2em; }

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

.hud { display: flex; gap: 10px; margin-top: 4px; }
.hull { flex: 1; display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 4px; }
.level { padding: 6px 12px; border-radius: 4px; --fill: var(--caption); }
.hud-label { font-family: var(--title); letter-spacing: 0.08em; font-size: 18px; }
.level strong { font-family: var(--title); font-weight: 400; font-size: 24px; }
#hull-num { font-family: var(--title); font-size: 22px; min-width: 2.2em; text-align: right; }
/* Skada/lagning: hela mätaren blinkar och siffran för skillnaden flyger upp. */
.hull.hurt { animation: hull-hurt 0.45s ease-out; }
.hull.heal { animation: hull-heal 0.6s ease-out; }
.hull.hurt #hull-num { color: var(--danger); }
.hull.heal #hull-num { color: var(--good); }
.hull.hurt #hull-num, .hull.heal #hull-num { -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; animation: count-pop 0.35s cubic-bezier(.2, 1.8, .5, 1); }
@keyframes hull-hurt {
  0% { transform: translateX(-6px); --fill: #ffc9c9; }
  25% { transform: translateX(6px); }
  50% { transform: translateX(-3px); }
}
@keyframes hull-heal { 0% { transform: scale(1.04); } }
@keyframes count-pop { from { transform: scale(1.7) rotate(-6deg); } }
.delta {
  position: absolute; right: 8px; top: -6px; 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;
  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; }
}
.hull-bar { flex: 1; height: 18px; border: var(--line) solid var(--ink); background: var(--white); overflow: hidden; }
#hull-fill {
  height: 100%;
  background: repeating-linear-gradient(-45deg, var(--good) 0 8px, #22a75b 8px 16px);
  border-right: var(--line) solid var(--ink);
  transition: width 0.4s cubic-bezier(.3, 1.6, .5, 1);
}
#hull-fill.low { background: repeating-linear-gradient(-45deg, var(--danger) 0 8px, #c92424 8px 16px); animation: blink 0.5s steps(2) infinite; }
@keyframes blink { 50% { filter: brightness(1.5); } }

.progress { display: flex; flex-wrap: wrap; gap: 5px; margin: 12px 0 8px; }
.progress span { width: 16px; height: 16px; border: 2px solid var(--ink); border-radius: 50%; background: var(--white); transition: background 0.2s, transform 0.2s; }
.progress span.on { background: var(--accent); transform: scale(1.15); }
.progress span.on.pop { animation: dot-pop 0.45s cubic-bezier(.2, 1.8, .5, 1); }
@keyframes dot-pop { 0% { transform: scale(2.2); box-shadow: 0 0 0 0 var(--caption); } 100% { transform: scale(1.15); box-shadow: 0 0 0 10px #ffe14d00; } }

/* ---------------------------------------------------------------- ordern */

.order { margin: 10px 0 16px; }
.big-bubble { font-size: clamp(22px, 6vw, 32px); min-height: 2.6em; display: flex; align-items: center; margin-bottom: 26px; }
.big-bubble.idle { opacity: 0.6; }
.big-bubble.pop { animation: pop 0.35s cubic-bezier(.2, 1.8, .5, 1); }
.big-bubble.urgent { animation: jitter 0.12s linear infinite; background: #ffe3d1; }
/* Ordern klarad eller missad: bubblan byter färg och studsar, så man ser resultatet direkt. */
.big-bubble.done { background: #d4f7e1; animation: pop 0.35s cubic-bezier(.2, 1.8, .5, 1); }
.big-bubble.failed { background: #ffd2d2; animation: nope 0.35s ease-in-out; }
.big-bubble.done::after { background: #d4f7e1; }
.big-bubble.failed::after { background: #ffd2d2; }
@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); }
}
.fuse { height: 12px; border: var(--line) solid var(--ink); background: var(--white); }
#fuse-fill {
  height: 100%;
  transform-origin: left;
  transform: scaleX(0);
  background: repeating-linear-gradient(90deg, var(--accent) 0 10px, var(--caption) 10px 20px);
}

/* ---------------------------------------------------------------- panelen och reglagen */

.panel {
  --fill: #d9eef9;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 16px;
}
.panel.shuffle .ctrl { animation: shuffle 0.45s ease-out; }
@keyframes shuffle { from { transform: translateY(-30px) rotate(8deg) scale(0.8); opacity: 0.2; } }
@media (min-width: 640px) { .panel[data-count="5"], .panel[data-count="6"] { grid-template-columns: repeat(3, 1fr); } }

.ctrl {
  border-radius: 8px;
  padding: 10px;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  --shadow: 4px 4px 0 var(--ink);
}
.plate {
  font-family: var(--title);
  font-size: 18px;
  letter-spacing: 0.03em;
  line-height: 1.05;
  text-align: center;
  background: var(--caption);
  border: 2px solid var(--ink);
  padding: 4px 6px;
  word-break: break-word;
  hyphens: auto;
}
/* Feedbacklager över reglaget: gul puls när man rör det, grön/röd när servern svarat. */
.ctrl::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 10px;
  border: 4px solid transparent;
  pointer-events: none;
}
.ctrl.acted::after { animation: ctrl-acted 0.4s ease-out; }
.ctrl.good::after { animation: ctrl-good 1s ease-out; }
.ctrl.bad::after { animation: ctrl-bad 1s ease-out; }
.ctrl.bad { animation: nope 0.35s ease-in-out; }
@keyframes ctrl-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 ctrl-good {
  0%, 45% { border-color: var(--good); background: rgba(46, 204, 113, 0.28); 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 ctrl-bad {
  0%, 45% { border-color: var(--danger); background: rgba(255, 59, 59, 0.25); 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); }
}
.ctrl-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; position: relative; }

/* Knapp */
.big-btn {
  width: 84px; height: 84px; border-radius: 50%;
  border: var(--line) solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #fff8 0 14%, transparent 15%), var(--c);
  box-shadow: 0 7px 0 var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.05s, box-shadow 0.05s;
}
.big-btn:active { transform: translateY(6px) scale(0.97); box-shadow: 0 1px 0 var(--ink); filter: brightness(1.15); }
/* Varje tryck: ner, upp igen och en ring sprids ut. Fastnar aldrig i nedtryckt läge. */
.big-btn.hit { animation: big-press 0.3s ease-out; }
@keyframes big-press {
  0% { transform: translateY(7px) scale(0.93); box-shadow: 0 0 0 var(--ink), 0 0 0 0 rgba(255, 225, 77, 0.9); filter: brightness(1.3); }
  60% { transform: translateY(-2px) scale(1.04); box-shadow: 0 8px 0 var(--ink), 0 0 0 18px rgba(255, 225, 77, 0); }
  100% { box-shadow: 0 7px 0 var(--ink), 0 0 0 22px rgba(255, 225, 77, 0); }
}

/* Brytare (spak) */
.lever {
  position: relative;
  width: 110px; height: 52px;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: var(--white);
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 4px 0 #0002;
}
.lever-knob {
  position: absolute; top: 4px; left: 5px;
  width: 38px; height: 38px; border-radius: 50%;
  border: var(--line) solid var(--ink);
  background: #bbb;
  transition: left 0.15s cubic-bezier(.3, 1.6, .5, 1), background 0.15s;
}
.lever.on { background: var(--c); }
.lever:active .lever-knob { transform: scale(0.9); }
.lever.flip { animation: squish 0.3s cubic-bezier(.2, 1.8, .5, 1); }
.lever.flip .lever-knob { animation: knob-squash 0.25s ease-out; }
@keyframes squish { 0% { transform: scale(0.9); } 60% { transform: scale(1.07); } }
@keyframes knob-squash { 0% { transform: scaleX(1.35) scaleY(0.8); } }
.lever.on .lever-knob { left: 60px; background: var(--white); }
.lever-labels { display: flex; justify-content: space-between; width: 110px; font-family: var(--title); font-size: 16px; }

/* Skjutreglage */
.slider-num { font-family: var(--title); font-size: 34px; line-height: 1; color: var(--c); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
.slider-num.nudge { animation: nudge 0.15s ease-out; }
.slider-num.pop { animation: count-pop 0.35s cubic-bezier(.2, 1.8, .5, 1); }
@keyframes nudge { from { transform: scale(1.25); } }
.ctrl-slider input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); background: var(--caption); }
.ctrl-slider input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 16px; padding: 0;
  border: var(--line) solid var(--ink); border-radius: 999px;
  background: repeating-linear-gradient(90deg, #0000 0 calc(10% - 2px), #0003 calc(10% - 2px) 10%), var(--white);
  touch-action: none;
}
.ctrl-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 30px; height: 38px; border-radius: 6px;
  border: var(--line) solid var(--ink); background: var(--c);
  box-shadow: 2px 2px 0 var(--ink);
}
.ctrl-slider input[type="range"]::-moz-range-thumb {
  width: 26px; height: 34px; border-radius: 6px;
  border: var(--line) solid var(--ink); background: var(--c);
}
.ticks { display: flex; justify-content: space-between; width: 100%; font-size: 11px; font-weight: 700; padding: 0 6px; }

/* Vred */
.knob {
  width: 58px; height: 58px; border-radius: 50%;
  border: var(--line) solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #fff9 0 12%, transparent 13%), var(--c);
  position: relative;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform 0.25s cubic-bezier(.3, 1.6, .5, 1);
}
.knob-mark { position: absolute; left: 50%; top: 3px; width: 6px; height: 20px; margin-left: -3px; background: var(--ink); border-radius: 3px; }
.dial-opts { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.dial-opt {
  font-family: var(--title); font-size: 14px; letter-spacing: 0.03em;
  border: 2px solid var(--ink); border-radius: 4px; background: var(--white);
  padding: 3px 6px; cursor: pointer; color: var(--ink);
}
.dial-opt:active { transform: translateY(2px); }
.dial-opt.on { background: var(--c); box-shadow: 2px 2px 0 var(--ink); }
.dial-opt.pop { animation: squish 0.3s cubic-bezier(.2, 1.8, .5, 1); }
.knob.spin { box-shadow: 3px 3px 0 var(--ink), 0 0 0 6px rgba(255, 225, 77, 0.8); }

/* 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.good, .mini-burst.bad { z-index: 3; font-size: 28px; top: 50%; color: var(--white); text-shadow: 2px 2px 0 var(--ink); animation-duration: 0.9s; }
.mini-burst.good { color: var(--good); }
.mini-burst.bad { color: var(--danger); }

.feed { min-height: 1.4em; font-style: italic; margin: 14px 2px 0; }

/* ---------------------------------------------------------------- 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; }
}

/* ---------------------------------------------------------------- mellan nivåer och slut */

.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(340px, 90%); height: 220px;
  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;
}
.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); }

/* ---------------------------------------------------------------- krisstörningar */

.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); }
}
body.quake #panel { animation: quake 0.09s linear infinite; }
@keyframes quake {
  25% { transform: translate(-4px, 3px) rotate(-0.8deg); }
  50% { transform: translate(4px, -2px) rotate(0.6deg); }
  75% { transform: translate(-2px, -3px) rotate(0.4deg); }
}

/* Svartvitt med glitchande ordertext. */
body.mono #game { filter: grayscale(1) contrast(1.6); }
body.mono #order-text { animation: glitch 0.25s steps(2) infinite; }
@keyframes glitch {
  0% { transform: translate(0); text-shadow: 3px 0 #0008, -3px 0 #0004; clip-path: inset(0 0 40% 0); }
  50% { transform: translate(-3px, 1px) skewX(-8deg); text-shadow: -3px 0 #0008, 3px 0 #0004; clip-path: inset(30% 0 0 0); }
  100% { transform: translate(2px, -1px); clip-path: none; }
}

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

@media (max-width: 560px) {
  .big-bubble { min-height: 2.3em; padding: 10px 14px; margin-bottom: 22px; }
  .order { margin: 6px 0 12px; }
  .panel { gap: 12px; padding: 12px; }
  .ctrl { min-height: 0; padding: 8px; }
  .plate { font-size: 16px; }
  .big-btn { width: 70px; height: 70px; }
  .knob { width: 46px; height: 46px; }
  .lever { width: 96px; height: 46px; }
  .lever-knob { width: 32px; height: 32px; }
  .lever.on .lever-knob { left: 52px; }
  .lever-labels { width: 96px; }
}

/* ---------------------------------------------------------------- mindre skakigt och blinkigt (spelarens val) */

:root[data-reduced-motion] .ink::before,
:root[data-reduced-motion] #hull-fill.low,
:root[data-reduced-motion] .shake,
:root[data-reduced-motion] .panel.shuffle .ctrl,
:root[data-reduced-motion] body.quake #panel,
:root[data-reduced-motion] body.mono #order-text,
:root[data-reduced-motion] .btn.pressed,
:root[data-reduced-motion] .nope,
:root[data-reduced-motion] .hull.hurt,
:root[data-reduced-motion] .hull.heal,
:root[data-reduced-motion] .ctrl.bad,
:root[data-reduced-motion] .big-bubble.done,
:root[data-reduced-motion] .big-bubble.failed,
:root[data-reduced-motion] .big-btn.hit,
:root[data-reduced-motion] .lever.flip,
:root[data-reduced-motion] .lever.flip .lever-knob,
:root[data-reduced-motion] .dial-opt.pop { animation: none; }
/* Brådskan syns på färgen i stället för skakningen. */
:root[data-reduced-motion] .big-bubble.urgent { animation: none; background: #ffe3d1; outline: 4px solid var(--danger); }
:root[data-reduced-motion] body.mono #order-text { clip-path: none; text-shadow: none; }

@media (prefers-reduced-motion: reduce) {
  .btn.pressed, .nope, .hull.hurt, .hull.heal, .ctrl.bad, .big-bubble.done, .big-bubble.failed,
  .big-btn.hit, .lever.flip, .lever.flip .lever-knob, .dial-opt.pop, .progress span.on.pop { animation: none; }
}
