/* Paniktangenten – serietidningsestetik, samma grund som lobbyn, Kontrollrummet och Bomben.
   Papper med rasterpunkter, tjock tusch, hårda skuggor och Bangers/Comic Neue. */

: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;
  --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);
  --intensity: 0;
  color-scheme: light;
}

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

body {
  font-family: var(--hand);
  font-size: 17px;
  color: var(--ink);
  background-color: var(--paper);
  /* Rasterpunkter, som i tryckta serietidningar. */
  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;
}

/* Bakgrunden pulserar snabbare och rödare ju längre spelet pågår. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(circle at 50% 40%, rgba(255, 59, 59, calc(var(--intensity) * 0.35)), transparent 65%);
  animation: pulse calc(2.4s - var(--intensity) * 2s) ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; transform: scale(1.06); } }

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

h2, h3 { font-family: var(--title); font-weight: 400; letter-spacing: 0.05em; }

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

/* .ink: tuschkontur som darrar lite. Konturen ligger i ::before så att texten inte förvrängs. */
.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); }
}

.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;
}
.tilt-l { transform: rotate(-1.5deg); }

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

button {
  font-family: var(--title);
  font-weight: 400;
  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: 8px 16px;
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.06s;
}
button:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
button:disabled { opacity: 0.55; cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
button.big {
  font-size: 30px;
  padding: 12px 34px;
  background: var(--accent);
  color: var(--white);
  text-shadow: 2px 2px 0 var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
}

input {
  font: inherit;
  font-size: 18px;
  color: var(--ink);
  background: var(--white);
  border: var(--line) solid var(--ink);
  border-radius: 6px;
  padding: 8px 12px;
  min-width: 0;
}
input::placeholder { color: #8a7a6a; }

.panel { --fill: var(--white); padding: 18px; border-radius: 4px; }
.panel h2 { font-size: 28px; margin: 0 0 10px; }
.panel p { line-height: 1.4; }

/* ---------------------------------------------------------------- start */

#home { max-width: 760px; margin: 0 auto; padding: 18px 16px 48px; }
.title {
  font-family: var(--title);
  font-weight: 400;
  margin: 4px 0 22px;
  line-height: 0.88;
  font-size: clamp(52px, 14vw, 104px);
  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);
}
.title span { display: block; }
.title span + span { color: var(--caption); margin-left: 0.3em; }

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

.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(--danger); -webkit-text-stroke: 1px var(--ink); }

.actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.join { display: flex; gap: 8px; flex: 1 1 260px; }
.join input { flex: 1; text-transform: uppercase; font-family: var(--title); letter-spacing: 0.1em; }
.error {
  display: inline-block;
  color: var(--white);
  background: var(--danger);
  border: var(--line) solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 6px 12px;
  font-weight: 700;
}

/* ---------------------------------------------------------------- rum */

#room { max-width: 1100px; margin: 0 auto; padding: 18px 16px 48px; }

.room-head { display: flex; flex-wrap: wrap; align-items: stretch; gap: 14px; margin-bottom: 22px; }
.code-box { --fill: var(--caption); padding: 6px 14px; border-radius: 4px; display: flex; flex-direction: column; justify-content: center; }
.code-box small { font-family: var(--title); font-size: 15px; letter-spacing: 0.1em; text-transform: uppercase; }
.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; }
.status { margin: 0; width: 100%; font-style: italic; }
.status:empty { display: none; }

.room-body { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 22px; align-items: start; }
@media (max-width: 760px) { .room-body { grid-template-columns: minmax(0, 1fr); } }

.main-area { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.controls { text-align: center; }
.hint { font-style: italic; }

.players h3 { margin: 0 0 10px; font-size: 24px; }
.players ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.players li {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 4px 10px; border: 2px solid var(--ink); border-radius: 999px;
  background: var(--white); font-weight: 700; font-size: 15px;
}
.players li.me { background: var(--caption); }
.players li.out { background: #e9e2d0; }
.players li.out .name { text-decoration: line-through; }
.players li.offline { opacity: 0.45; }
.players .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .score { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- scen */

.stage { text-align: center; display: flex; flex-direction: column; gap: 18px; min-height: 420px; }
.stage-top { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-family: var(--title); font-size: 20px; letter-spacing: 0.05em; }
.stage-top span:not(:empty) { background: var(--caption); border: 2px solid var(--ink); padding: 0 8px; box-shadow: 2px 2px 0 var(--ink); }

/* Kommandot: färgen kan sättas av servern (Stroop), så texten får alltid tuschkontur för att synas. */
.command {
  font-family: var(--title);
  font-size: clamp(40px, 9vw, 76px);
  letter-spacing: 0.03em;
  line-height: 1.05;
  min-height: 1.2em;
  word-break: break-word;
  color: var(--white);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 4px 4px 0 var(--ink);
}
.command.pop { animation: pop 0.25s ease-out; }
@keyframes pop { from { transform: scale(1.4) rotate(-3deg); opacity: 0; } }

/* Ledtråd under färgkommandot: förklarar att det är knappens FÄRG som räknas. */
.cmd-hint {
  align-self: center;
  margin: -6px 0 0;
  padding: 4px 14px;
  font-family: var(--title);
  font-size: 22px;
  letter-spacing: 0.04em;
  background: var(--caption);
  border: var(--line) solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  rotate: -1deg;
}
.cmd-hint.trap { background: var(--danger); color: var(--white); text-shadow: 2px 2px 0 var(--ink); rotate: 1.5deg; }
.cmd-hint.pop { animation: hint-pop 0.3s cubic-bezier(.2, 1.8, .5, 1); }
.cmd-hint.trap.pop { animation: hint-pop 0.3s cubic-bezier(.2, 1.8, .5, 1), wobble 0.5s 0.3s ease-in-out 2; }
@keyframes hint-pop { from { transform: scale(0.4); opacity: 0; } }
@keyframes wobble { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }

.timer { height: 18px; background: var(--white); border: var(--line) solid var(--ink); border-radius: 999px; overflow: hidden; box-shadow: 3px 3px 0 var(--ink); }
#timer-bar { height: 100%; background: var(--accent); border-right: var(--line) solid var(--ink); transform-origin: left; }

/* Den stora röda knappen, i tusch. */
.panic-btn {
  width: min(240px, 60vw);
  aspect-ratio: 1;
  border-radius: 50%;
  font-family: var(--title);
  font-size: 44px;
  letter-spacing: 0.05em;
  color: var(--white);
  text-shadow: 3px 3px 0 var(--ink);
  background: radial-gradient(circle at 35% 30%, #ff8a8a 0 18%, var(--danger) 19% 70%, #c4161c 71%);
  border: 5px solid var(--ink);
  box-shadow: 0 12px 0 var(--ink);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.panic-btn:active:not(:disabled) { transform: translateY(8px) scale(0.97); box-shadow: 0 4px 0 var(--ink); filter: brightness(1.15); }
/* Varje tryck: knappen trycks ner, studsar tillbaka och en tuschring sprids ut. */
.panic-btn.hit { animation: press 0.22s ease-out; }
@keyframes press {
  0% { transform: translateY(10px) scale(0.94); box-shadow: 0 2px 0 var(--ink), 0 0 0 0 rgba(255, 225, 77, 0.9); filter: brightness(1.3); }
  60% { transform: translateY(-2px) scale(1.03); box-shadow: 0 14px 0 var(--ink), 0 0 0 22px rgba(255, 225, 77, 0); }
  100% { transform: none; box-shadow: 0 12px 0 var(--ink), 0 0 0 26px rgba(255, 225, 77, 0); }
}

#inputs { position: relative; }

.press-count {
  position: absolute;
  top: -6px;
  left: calc(50% + min(120px, 30vw) - 30px);
  font-family: var(--title);
  font-size: 30px;
  letter-spacing: 0.04em;
  background: var(--caption);
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 0 12px;
  pointer-events: none;
}
.press-count.pop { animation: count-pop 0.25s cubic-bezier(.2, 1.8, .5, 1); }
@keyframes count-pop { from { transform: scale(1.6) rotate(8deg); } }

/* "POW!"-bubbla vid varje klick. */
.burst {
  position: absolute;
  z-index: 5;
  translate: -50% -50%;
  rotate: var(--rot, 0deg);
  font-family: var(--title);
  font-size: 34px;
  letter-spacing: 0.04em;
  color: var(--caption);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 3px 3px 0 var(--ink);
  white-space: nowrap;
  pointer-events: none;
  animation: burst 0.7s ease-out forwards;
}
@keyframes burst {
  0% { transform: scale(0.3); opacity: 0; }
  20% { transform: scale(1.25); opacity: 1; }
  45% { transform: scale(1); opacity: 1; }
  100% { transform: translateY(-40px) scale(1.05); opacity: 0; }
}

.colors { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; max-width: 420px; margin: 0 auto; width: 100%; }
.color-btn {
  font-size: 28px;
  padding: 20px 8px;
  color: var(--white);
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 2px 2px 0 var(--ink);
}
/* Valt svar: knappen poppar och resten bleknar, så man ser direkt vad man valde. */
.colors.answered .color-btn { opacity: 0.3; filter: grayscale(0.6); }
.colors.answered .color-btn.chosen {
  opacity: 1;
  filter: none;
  outline: 4px solid var(--ink);
  outline-offset: 4px;
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--ink);
  animation: chosen 0.3s cubic-bezier(.2, 1.8, .5, 1);
}
@keyframes chosen { 0% { transform: scale(0.9); } 60% { transform: scale(1.08); } }

.type-form { position: relative; display: flex; gap: 8px; max-width: 420px; margin: 0 auto; width: 100%; }
.type-form input { flex: 1; font-family: var(--title); font-size: 28px; text-transform: uppercase; text-align: center; letter-spacing: 0.1em; }
.type-form input:focus { background: #fffbe6; border-color: var(--accent); box-shadow: 0 0 0 3px var(--caption); outline: none; }

/* Skickat ord: fältet blir gult och en "SKICKAT!"-stämpel slås ner över det. */
.type-form.sent input:disabled, .type-form.sent button { opacity: 1; }
.type-form.sent input { background: var(--caption); border-color: var(--ink); box-shadow: 4px 4px 0 var(--ink); color: var(--ink); -webkit-text-fill-color: var(--ink); }
.type-form.sent button { background: var(--good); color: var(--white); text-shadow: 2px 2px 0 var(--ink); transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.type-form.sent::after {
  content: "SKICKAT!";
  position: absolute;
  right: -14px;
  top: -16px;
  font-family: var(--title);
  font-size: 22px;
  letter-spacing: 0.06em;
  color: var(--white);
  background: var(--good);
  border: var(--line) solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 0 10px;
  rotate: 8deg;
  pointer-events: none;
}
.type-form.stamp input { animation: stamp-in 0.3s cubic-bezier(.2, 1.8, .5, 1); }
.type-form.stamp::after { animation: stamp 0.35s cubic-bezier(.2, 1.6, .5, 1); }
@keyframes stamp-in { 0% { transform: scale(1.12); } 50% { transform: scale(0.96); } }
@keyframes stamp { 0% { transform: scale(2.4); opacity: 0; } 60% { opacity: 1; } }
.type-form.nope { animation: nope 0.3s ease-in-out; }
@keyframes nope { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }

.feedback { font-family: var(--title); font-size: 30px; letter-spacing: 0.04em; min-height: 1.3em; margin: 0; }
.feedback.ok, .feedback.bad { color: var(--white); -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; text-shadow: 2px 2px 0 var(--ink); }
.feedback.ok { color: var(--good); }
.feedback.bad { color: var(--danger); }
.feedback.pending { font-size: 24px; color: var(--ink); }
.round-summary { margin: 0; min-height: 1.3em; font-style: italic; }

/* ---------------------------------------------------------------- resultat */

.ranking { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ranking li {
  display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 8px; align-items: center;
  padding: 8px 12px; border: 2px solid var(--ink); border-radius: 4px; background: var(--white);
  font-size: 18px; font-weight: 700;
}
.ranking li:first-child { background: #ffc72c; border-width: var(--line); box-shadow: 4px 4px 0 var(--ink); font-size: 22px; }
.ranking li.me { outline: 3px solid var(--accent); outline-offset: 2px; }
.ranking .place { font-family: var(--title); font-weight: 400; font-size: 1.3em; }
.ranking .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .score { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- effekter */

/* Nedräkningen: stora serieversaler mitt på skärmen. */
.overlay {
  position: fixed;
  inset: 0;
  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);
  z-index: 50;
  pointer-events: none;
}
.overlay.pop { animation: pop 0.4s cubic-bezier(.2, 1.8, .5, 1); }

.flash { position: fixed; inset: 0; background: var(--danger); opacity: 0; pointer-events: none; z-index: 60; }
.flash.on { animation: flash 0.5s ease-out; }
@keyframes flash { from { opacity: 0.55; } to { opacity: 0; } }

body.shake main { animation: shake calc(0.15s + var(--intensity) * 0.25s) ease-in-out; }
@keyframes shake {
  20% { transform: translate(calc(-2px - var(--intensity) * 6px), 1px) rotate(calc(var(--intensity) * -0.6deg)); }
  40% { transform: translate(calc(2px + var(--intensity) * 6px), -1px); }
  60% { transform: translate(calc(-1px - var(--intensity) * 4px), 2px) rotate(calc(var(--intensity) * 0.6deg)); }
  80% { transform: translate(calc(1px + var(--intensity) * 3px), -1px); }
}

@media (prefers-reduced-motion: reduce) {
  body::before, body.shake main, .command.pop, .overlay.pop, .ink::before,
  .panic-btn.hit, .press-count.pop, .burst, .colors .color-btn.chosen,
  .type-form.stamp input, .type-form.stamp::after, .type-form.nope, .cmd-hint.pop, .cmd-hint.trap.pop { animation: none; }
  .burst { display: none; }
}

/* Spelarens val "mindre skakande/blinkande" */
:root[data-reduced-motion] body::before,
:root[data-reduced-motion] body.shake main,
:root[data-reduced-motion] .command.pop,
:root[data-reduced-motion] .overlay.pop,
:root[data-reduced-motion] .ink::before,
:root[data-reduced-motion] .panic-btn.hit,
:root[data-reduced-motion] .press-count.pop,
:root[data-reduced-motion] .colors .color-btn.chosen,
:root[data-reduced-motion] .type-form.stamp input,
:root[data-reduced-motion] .type-form.stamp::after,
:root[data-reduced-motion] .type-form.nope,
:root[data-reduced-motion] .cmd-hint.pop,
:root[data-reduced-motion] .cmd-hint.trap.pop { animation: none; }
:root[data-reduced-motion] .burst { display: none; }
:root[data-reduced-motion] .flash.on { animation: none; opacity: 0; }
