:root {
  --bg: #ffe14d;
  --ink: #1a1a1a;
  --paper: #fff;
  --soft: rgba(255, 255, 255, 0.55);
  --ok: #22c55e;
  --bad: #b4123f;
  --shadow: 3px 3px 0 var(--ink);
  --shadow-lg: 4px 4px 0 var(--ink);
  --radius: 16px;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 500 17px/1.4 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

#app {
  max-width: 460px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-width: 0;
  animation: enter 0.28s ease-out;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.grow {
  flex: 1;
}
.push {
  margin-top: auto;
}
.spacer {
  flex: 1;
}
.center {
  text-align: center;
}

/* Typografi */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 32px;
}

.brand {
  font-weight: 900;
  font-size: 16px;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 8.4vw, 36px);
  line-height: 1.08;
  font-weight: 900;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}

.kicker {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  opacity: 0.78;
  overflow-wrap: anywhere;
}

.lead,
.hint {
  margin: 0;
  font-size: 15px;
  opacity: 0.85;
}

.small {
  font-size: 14px;
  margin: 0;
}

.chip {
  flex: none;
  background: var(--ink);
  color: var(--bg);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 5px 11px;
  border-radius: 99px;
  white-space: nowrap;
}

/* Formulär */

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.field label,
.label {
  font-weight: 800;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.count-hint {
  font-weight: 700;
  opacity: 0.6;
  font-variant-numeric: tabular-nums;
}
.count-hint.over {
  opacity: 1;
  color: var(--bad);
}

input[type="text"] {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 18px; /* minst 16px så att iOS inte zoomar */
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  outline: none;
  transition: box-shadow 0.12s, transform 0.12s;
}
input[type="text"]::placeholder {
  color: rgba(26, 26, 26, 0.38);
}
input[type="text"]:focus-visible {
  box-shadow: var(--shadow-lg);
  transform: translate(-1px, -1px);
}
input[aria-invalid="true"] {
  border-color: var(--bad);
  box-shadow: 3px 3px 0 var(--bad);
}

/* Knappar */

button {
  font: inherit;
  color: inherit;
}

.btn,
.btn2,
.seg button,
.move {
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  cursor: pointer;
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out, background-color 0.15s, color 0.15s;
}

.btn,
.btn2 {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  padding: 14px 18px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  font-weight: 900;
  font-size: 18px;
  text-align: center;
  text-decoration: none;
}

.btn {
  background: var(--ink);
  color: var(--bg);
  box-shadow: 4px 4px 0 rgba(26, 26, 26, 0.35);
}

.btn2 {
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.btn2.small {
  min-height: 44px;
  font-size: 15px;
  padding: 8px 14px;
}

.btn:active:not(:disabled),
.btn2:active:not(:disabled),
.seg button:active,
.move:active:not(:disabled) {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 var(--ink);
}

.btn:disabled,
.btn2:disabled {
  cursor: default;
  opacity: 0.45;
}
.btn[aria-busy="true"] {
  opacity: 0.8;
}

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
  padding-top: 8px;
}
.actions.tight {
  margin-top: 0;
  padding-top: 0;
}

/* Segmentväljare för format */

.seg {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.seg button {
  min-height: 48px;
  padding: 8px 4px;
  font-weight: 800;
  font-size: 14px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.seg button[aria-checked="true"] {
  background: var(--ink);
  color: var(--bg);
}

/* Dragknappar */

.moves {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.move {
  aspect-ratio: 1;
  min-height: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 0;
}
.move .e {
  font-size: clamp(38px, 12vw, 52px);
  line-height: 1;
  transition: transform 0.18s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.move .l {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.move[aria-checked="true"] {
  background: var(--ink);
  color: var(--bg);
}
.move[aria-checked="true"] .e {
  transform: scale(1.12) rotate(-6deg);
}
.move:disabled {
  cursor: default;
}
.moves:has(.move:disabled) .move[aria-checked="false"] {
  opacity: 0.45;
}

/* Meddelanden */

.error {
  margin: 0;
  background: var(--paper);
  border: 3px solid var(--bad);
  color: var(--bad);
  font-weight: 800;
  font-size: 15px;
  border-radius: 12px;
  padding: 10px 12px;
}

.warn {
  margin: 0;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 15px;
}

.tie {
  margin: 0;
  background: var(--ink);
  color: var(--bg);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 15px;
  animation: enter 0.3s ease-out;
}

.locked {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.waiting {
  margin: 0;
  font-weight: 800;
}
.waiting .dot {
  vertical-align: -1px;
  margin-right: 2px;
}

.ellipsis::after {
  content: "…";
  display: inline-block;
  animation: breathe 1.4s ease-in-out infinite;
}

.banner {
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--ink);
  color: var(--bg);
  text-align: center;
  font-weight: 800;
  font-size: 15px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 70;
  max-width: 428px;
  margin: 0 auto;
  background: var(--ink);
  color: var(--bg);
  font-weight: 800;
  font-size: 15px;
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 4px 4px 0 rgba(26, 26, 26, 0.35);
  animation: enter 0.2s ease-out;
}

.offscreen {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  left: -9999px;
}

/* Dela */

.share-link {
  margin: 0;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px;
  font-weight: 900;
  font-size: clamp(18px, 5.6vw, 22px);
  text-align: center;
  overflow-wrap: anywhere;
}

/* Dela och Kopiera direkt under länken, så att de syns utan att skrolla på en telefon. */
.share-buttons {
  display: flex;
  gap: 10px;
  margin-top: -4px;
}
.share-buttons > button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  padding: 10px 12px;
}

.qr {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.qr img {
  display: block;
  width: min(200px, 56vw);
  height: auto;
  aspect-ratio: 1;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 6px;
}
.qr figcaption {
  font-size: 14px;
  font-weight: 700;
  opacity: 0.8;
  text-align: center;
}

details.private {
  background: var(--soft);
  border: 2px dashed var(--ink);
  border-radius: 14px;
  padding: 0 14px;
  font-size: 14px;
}
details.private summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
  gap: 8px;
}
details.private summary::-webkit-details-marker {
  display: none;
}
details.private summary::before {
  content: "🔑";
}
details.private[open] {
  padding-bottom: 14px;
}
details.private > :not(summary) {
  margin-bottom: 10px;
}
details.private .private-url {
  font-size: 16px;
  font-weight: 500;
  padding: 10px;
  box-shadow: none;
}
details.private .warn {
  border-color: var(--bad);
}

/* Spelare */

.players {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}
.player {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  transition: background-color 0.2s;
}
.player.ready {
  background: #fff7c2;
}
.prow {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.pname {
  font-weight: 900;
  overflow-wrap: anywhere;
  min-width: 0;
}
.you-tag {
  flex: none;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--ink);
  color: var(--bg);
  border-radius: 99px;
  padding: 1px 7px;
}
.pscore {
  font-size: 34px;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.psub {
  font-size: 13px;
  font-weight: 700;
  opacity: 0.7;
  min-height: 1.2em;
}
.vs {
  font-weight: 900;
  font-size: 18px;
}

.dot {
  flex: none;
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: #c9c2a0;
}
.dot.on {
  background: var(--ok);
  animation: pulse 1.8s ease-out infinite;
}

/* Eget låst drag */

.mine {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 16px;
  animation: enter 0.3s ease-out;
}
.mine .big {
  font-size: 64px;
  line-height: 1.1;
}

/* Avslöjande */

.reveal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  overflow: hidden;
}
.reveal .kicker {
  max-width: 428px;
  text-align: center;
}
.count {
  font-size: clamp(110px, 38vw, 170px);
  font-weight: 900;
  line-height: 1;
  min-height: 1em;
  font-variant-numeric: tabular-nums;
}
.count.gone {
  min-height: 0;
  height: 0;
}

.duel {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 428px;
}
.duel .vs {
  align-self: center;
  font-size: 22px;
}
.side {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: opacity 0.3s;
}
.side .big {
  display: inline-block;
  font-size: clamp(76px, 25vw, 110px);
  line-height: 1.05;
}
.side .flip {
  display: inline-block;
}
.side.r .flip {
  transform: scaleX(-1);
}
.mlabel {
  font-weight: 900;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  min-height: 1.2em;
}
.side .nm {
  font-weight: 800;
  text-align: center;
  overflow-wrap: anywhere;
}
.side.lose {
  opacity: 0.5;
}

.duel.small .big {
  font-size: clamp(56px, 18vw, 76px);
}

.outcome,
.winner {
  margin: 0;
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-weight: 900;
  font-size: 22px;
  text-align: center;
  overflow-wrap: anywhere;
}
.outcome {
  min-width: 60%;
}

/* Resultat */

.winner {
  font-size: clamp(22px, 7vw, 28px);
  line-height: 1.15;
  animation: enter 0.35s ease-out;
}
.personal {
  margin: 0;
  text-align: center;
  font-weight: 800;
}

.tally {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.final-score {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
}
.final-score .nm {
  font-weight: 800;
  overflow-wrap: anywhere;
}
.final-score .nm:last-child {
  text-align: right;
}
.final-score strong {
  font-size: 40px;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.rounds {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rounds li {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  background: var(--soft);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 15px;
}
.rn {
  font-weight: 800;
}
.rm {
  font-size: 22px;
}
.rw {
  text-align: right;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.loading {
  align-items: center;
  justify-content: center;
}
.loader {
  font-size: 56px;
  margin: 0;
  animation: bob 0.9s ease-in-out infinite;
}

/* Rörelse: bara när användaren inte bett om mindre */

@media (prefers-reduced-motion: no-preference) {
  .count.pop {
    animation: pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
  }
  .outcome.pop {
    animation: pop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
  }
  .side .big.pump {
    animation: pump 0.6s cubic-bezier(0.4, 0, 0.3, 1);
  }
  .side.r .big.pump {
    animation-name: pump-r;
  }
  .side .big.slam {
    animation: slam 0.42s cubic-bezier(0.2, 1.5, 0.4, 1);
  }
  .side.win .big.slam {
    animation: slam 0.42s cubic-bezier(0.2, 1.5, 0.4, 1), wiggle 0.6s 0.45s ease-in-out 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
@keyframes pop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  60% {
    transform: scale(1.12);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}
@keyframes pump {
  0%,
  100% {
    transform: translateY(0) rotate(0);
  }
  45% {
    transform: translateY(-34px) rotate(-14deg);
  }
}
@keyframes pump-r {
  0%,
  100% {
    transform: translateY(0) rotate(0);
  }
  45% {
    transform: translateY(-34px) rotate(14deg);
  }
}
@keyframes slam {
  0% {
    transform: scale(0.3);
  }
  70% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes wiggle {
  0%,
  100% {
    transform: rotate(0);
  }
  25% {
    transform: rotate(-8deg);
  }
  75% {
    transform: rotate(8deg);
  }
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  }
  100% {
    box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
  }
}
@keyframes breathe {
  50% {
    opacity: 0.25;
  }
}
@keyframes bob {
  50% {
    transform: translateY(-12px) rotate(-10deg);
  }
}

/* Webbnotiser */

.notify {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
p.notify,
.notify-on {
  margin: 0;
  font-size: 15px;
}
.stack .notify {
  align-items: center;
  text-align: center;
}

.rematch-slot .stack {
  gap: 12px;
}
