/* Kartongen – serietidningsestetik, samma grund som Paniktangenten och de andra spelen. */
/* Gemensamma färger och mått finns i /api/ui/comic.css. */
:root {
  --intensity: 0;
}

* { 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 på slutet (sista 30 sekunderna). */
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); } }


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

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

/* .ink (darrande tuschkant) finns i /api/ui/comic.css, och edges.js ritar kanterna. */

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

/* Pratbubblan finns i /api/ui/comic.css. */
.bubble { --bubble-shout: var(--danger); }

.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; white-space: nowrap; }
@keyframes pop { from { transform: scale(1.4) rotate(-3deg); opacity: 0; } }
.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 0.2s ease-in-out; }
@keyframes shake {
  25% { transform: translate(-3px, 1px); }
  50% { transform: translate(3px, -1px); }
  75% { transform: translate(-2px, 2px); }
}

/* ---------------------------------------------------------------- spelplanen */

.stage { display: flex; flex-direction: column; gap: 12px; padding: 12px; }
.hud { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; font-family: var(--title); font-size: 22px; letter-spacing: 0.05em; }
.hud > span { background: var(--caption); border: 2px solid var(--ink); padding: 0 10px; box-shadow: 2px 2px 0 var(--ink); }
.hud .clock { min-width: 4.2em; text-align: center; font-variant-numeric: tabular-nums; }
.hud .clock.final { background: var(--danger); color: var(--white); text-shadow: 1px 1px 0 var(--ink); animation: tick-pulse 1s ease-in-out infinite; }
.hud .double { background: var(--danger); color: var(--white); text-shadow: 1px 1px 0 var(--ink); }
@keyframes tick-pulse { 50% { transform: scale(1.08); } }

.board-wrap { position: relative; width: 100%; max-width: 720px; margin: 0 auto; touch-action: none; }
#board { display: block; width: 100%; height: auto; border: var(--line) solid var(--ink); box-shadow: var(--shadow); background: #f4dfb5; border-radius: 4px; }

.tools { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }
.tools button { display: flex; align-items: center; gap: 8px; min-width: 150px; justify-content: center; }
.tools button .key { font-family: var(--hand); font-size: 14px; border: 2px solid var(--ink); border-radius: 4px; padding: 0 5px; background: var(--paper); }
.tools button:disabled { opacity: 0.4; cursor: default; }
.tools button.ready { background: var(--caption); }
.touch-only .tools button .key { display: none; }
.touch-only .tools button { min-height: 56px; flex: 1 1 140px; font-size: 22px; }
.hint-line { text-align: center; margin: 0; font-style: italic; }
.touch-only .keys-hint { display: none; }
.mouse-only { display: inline; }
.touch-only .mouse-only { display: none; }

.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px 14px; margin: 10px 0 0; padding: 0; list-style: none; font-size: 15px; }
.legend b { font-family: var(--title); font-weight: 400; letter-spacing: 0.04em; font-size: 17px; }

.players li .dot { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--ink); border-radius: 3px; margin-right: 6px; vertical-align: -2px; }

/* Reaktionsrutan: en serieruta med Dexter som fräser, i ett hörn av brädet. */
.reaction {
  --tilt: -3deg;
  position: absolute;
  top: 6%;
  right: 3%;
  width: 34%;
  max-width: 220px;
  margin: 0;
  pointer-events: none;
  background-color: var(--sky);
  background-image: radial-gradient(circle, rgba(20, 16, 16, 0.14) 1.2px, transparent 1.6px);
  background-size: 8px 8px;
  border: var(--line) solid var(--ink);
  box-shadow: var(--shadow);
  transform: rotate(var(--tilt));
  z-index: 5;
}
.reaction.left { right: auto; left: 3%; }
.reaction.bottom { top: auto; bottom: 4%; }
.reaction img { display: block; width: 100%; height: auto; }
.reaction figcaption {
  position: absolute;
  top: -14px;
  left: -10px;
  font-family: var(--title);
  font-size: clamp(20px, 4.5vw, 34px);
  letter-spacing: 0.04em;
  color: var(--white);
  background: var(--danger);
  border: var(--line) solid var(--ink);
  border-radius: 4px;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 0 10px;
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
  transform: rotate(-6deg);
}
.reaction.pop { animation: reaction-in 1.1s ease-out both; }
@keyframes reaction-in {
  0% { transform: rotate(var(--tilt)) scale(0.2); opacity: 0; }
  12% { transform: rotate(calc(var(--tilt) * -1)) scale(1.12); opacity: 1; }
  18% { transform: rotate(var(--tilt)) scale(1) translateX(-4px); }
  24% { transform: rotate(var(--tilt)) translateX(4px); }
  30% { transform: rotate(var(--tilt)) translateX(0); }
  80% { opacity: 1; transform: rotate(var(--tilt)); }
  100% { opacity: 0; transform: rotate(var(--tilt)) scale(0.95); }
}

/* Liten Dexter som undrar, bredvid en katt som funderar på att kliva in i din kartong. */
.hmm {
  position: absolute;
  width: clamp(38px, 9%, 60px);
  height: auto;
  border: 2px solid var(--ink);
  border-radius: 3px;
  box-shadow: 2px 2px 0 var(--ink);
  transform: rotate(4deg);
  pointer-events: none;
  z-index: 4;
}
.hmm.pop { animation: hmm-in 0.35s cubic-bezier(.2, 1.8, .5, 1) both; }
@keyframes hmm-in { from { transform: rotate(4deg) scale(0); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  body::before, body.shake main, .overlay.pop, .ink::before, .hud .clock.final, .reaction.pop, .hmm.pop { animation: none; }
}
:root[data-reduced-motion] body::before,
:root[data-reduced-motion] body.shake main,
:root[data-reduced-motion] .overlay.pop,
:root[data-reduced-motion] .ink::before,
:root[data-reduced-motion] .hud .clock.final,
:root[data-reduced-motion] .reaction.pop,
:root[data-reduced-motion] .hmm.pop { animation: none; }
:root[data-reduced-motion] .flash.on { animation: none; opacity: 0; }
