/* Bilbingo — design: "svensk väg".
   Palett från vägmiljön: skyltgul, skyltblå, bårdröd, asfalt, vägvit.
   Signatur: titeln som gul ortstavla + asfaltsränder med vägmarkering. */

@font-face {
  font-family: "Baloo 2";
  src: url("baloo2.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --skyltgul: #ffcd00;
  --skyltbla: #1e6bb8;
  --bardrod: #d13438;
  --asfalt: #22252d;

  --bg: #eef0ec;
  --surface: #ffffff;
  --text: #23262c;
  --text-dim: #687080;
  --accent: var(--skyltbla);
  --accent-text: #ffffff;
  --marked: #2e9e5b;
  --marked-bg: #d9f2e3;
  --border: #dfe3da;
  --win: #e8a800;
  --plate-text: #23262c;
  --shadow: 0 1px 2px rgb(30 35 45 / 0.08), 0 3px 10px rgb(30 35 45 / 0.07);

  --r-vanlig: #b9bfae;
  --r-ovanlig: #2e9e5b;
  --r-sallsynt: #1e6bb8;
  --r-legendarisk: #e8a800;

  --radius: 14px;
  --radius-sm: 10px;
}

/* Mörkt läge — nattkörning, dämpat så föraren inte bländas */
:root[data-theme="dark"] {
  --bg: #15171d;
  --surface: #22252d;
  --text: #d6d9de;
  --text-dim: #8a90a0;
  --accent: #4a90d9;
  --marked: #4cbd7f;
  --marked-bg: #17382a;
  --border: #33384299;
  --win: #f5c223;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 14px rgb(0 0 0 / 0.35);
  --r-vanlig: #4a5060;
}

html, body { height: 100%; }

body {
  font-family: "Baloo 2", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 500;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  line-height: 1.35;
}

button { font-family: inherit; }

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

.screen {
  display: none;
  min-height: 100dvh;
  padding: max(14px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}
.screen.active { display: flex; flex-direction: column; }

/* ---------- Signatur: ortstavla + väg ---------- */

.plate {
  display: inline-block;
  background: var(--skyltgul);
  color: var(--plate-text);
  border: 3px solid #2a2d33;
  border-radius: 10px;
  padding: 1px 14px 3px;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.25;
  box-shadow: var(--shadow);
}

.road {
  height: 10px;
  border-radius: 999px;
  margin: 10px 0 14px;
  background:
    repeating-linear-gradient(90deg,
      transparent 0 18px, #f4f5f2 18px 34px, transparent 34px 52px) center / 100% 3px no-repeat,
    var(--asfalt);
  background-blend-mode: normal;
}
@media (prefers-reduced-motion: no-preference) {
  .road {
    background:
      repeating-linear-gradient(90deg,
        transparent 0 18px, #f4f5f2 18px 34px, transparent 34px 52px) center / 200% 3px,
      var(--asfalt);
    animation: roadDrift 18s linear infinite;
  }
  @keyframes roadDrift {
    from { background-position: 0 center, 0 0; }
    to { background-position: -104px center, 0 0; }
  }
}

/* ---------- Start ---------- */

.start-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
h1 { font-size: 1.9rem; }
.tagline {
  color: var(--text-dim);
  margin-top: 8px;
  font-size: 0.88rem;
}

.header-btns { display: flex; gap: 8px; }

.icon-btn {
  border: 1.5px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: var(--radius-sm);
  font-size: 1.15rem;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  cursor: pointer;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { transform: scale(0.94); }

.field-row { display: flex; gap: 10px; }
.field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-weight: 700;
  font-size: 0.85rem;
}
.field small { color: var(--text-dim); font-weight: 500; }
.field input {
  padding: 12px 13px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.field input::placeholder { color: var(--text-dim); font-weight: 500; opacity: 0.7; }
.field input:focus { outline: none; border-color: var(--accent); }

.code-row { display: flex; gap: 6px; }
.code-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 0.08em; }
.code-row .icon-btn { height: auto; }

.avatar-row {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.avatar-btn {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
.avatar-btn.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}

.hint {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-dim);
  margin: 8px 0 14px;
}

h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 10px; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.category-card {
  position: relative;
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  padding: 9px 11px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: border-color 0.12s, transform 0.12s;
}
.category-card:active { transform: scale(0.97); }
.category-card.selected { border-color: var(--accent); }
.category-card.selected::after {
  content: "✓";
  position: absolute;
  top: -8px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
.cat-emoji {
  font-size: 1.45rem;
  line-height: 1;
  grid-row: 1 / 3;
  text-align: center;
}
.cat-name { font-weight: 700; font-size: 0.92rem; line-height: 1.2; }
.cat-desc {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-dim);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.option-rows { display: flex; gap: 8px; margin-bottom: 12px; }
.size-row { flex: 2; display: flex; gap: 6px; }
.diff-row { flex: 3; display: flex; gap: 6px; }
.size-btn, .diff-btn {
  flex: 1;
  padding: 10px 4px;
  font-size: 0.82rem;
  font-weight: 700;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.size-btn.selected {
  border-color: var(--accent);
  color: var(--accent);
}
.diff-btn.selected { border-color: var(--accent); color: var(--accent); }
.diff-btn[data-diff="latt"].selected { border-color: var(--marked); color: var(--marked); }
.diff-btn[data-diff="svar"].selected { border-color: var(--bardrod); color: var(--bardrod); }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 12px;
  cursor: pointer;
}
.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.big-btn {
  width: 100%;
  padding: 15px;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.big-btn:active { transform: scale(0.98); }
.big-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

/* Spela-knappen följer med — alltid synlig även när kategorierna scrollar */
#btn-play {
  position: sticky;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 5;
  box-shadow: 0 4px 16px rgb(20 60 120 / 0.35), var(--shadow);
}
.big-btn.secondary {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  font-weight: 700;
}

/* ---------- Spel ---------- */

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.game-title { display: flex; flex-direction: column; min-width: 0; }
.game-title strong {
  font-size: 1.15rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-title span { font-size: 0.78rem; font-weight: 600; color: var(--text-dim); }

.peers {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 10px;
}
.peers[hidden] { display: none; }

.peer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.peer.me { border-color: var(--accent); }
.peer.peer-won { border-color: var(--win); }
.peer-name { font-weight: 700; }
.peer-progress { color: var(--text-dim); }
.peer-waiting { font-size: 0.75rem; font-weight: 500; color: var(--text-dim); }

/* Dagens utmaning — gul bonusskylt */
.challenge {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 13px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 2px solid var(--skyltgul);
  border-left-width: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  text-align: left;
  box-shadow: var(--shadow);
}
.challenge[hidden] { display: none; }
.ch-emoji { font-size: 1.45rem; }
.ch-text { flex: 1; display: flex; flex-direction: column; font-size: 0.85rem; font-weight: 600; line-height: 1.25; }
.ch-text b {
  font-size: 0.66rem;
  font-weight: 800;
  color: var(--win);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.ch-check { font-size: 1.35rem; color: var(--marked); font-weight: 800; min-width: 24px; text-align: center; }
.challenge.done { border-color: var(--marked); background: var(--marked-bg); }

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, minmax(80px, 120px));
  gap: 8px;
  flex: 1;
  min-height: 0;
  align-content: center; /* jämna 8px-mellanrum, ev. överskott delas lika topp/botten */
}

.board.size-5 {
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, minmax(58px, 96px));
  gap: 6px;
}
.board.size-5 .tile { gap: 2px; border-bottom-width: 3px; }
.board.size-5 .tile-emoji { font-size: 1.3rem; }
.board.size-5 .tile-sign .sign-svg { width: 30px; height: 30px; }
.board.size-5 .tile-color { width: 30px; height: 30px; font-size: 0.8rem; }
.board.size-5 .tile-name { font-size: 0.56rem; }
.board.size-5 .tile-check { font-size: 1.7rem; }

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 3px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.1s;
}
.tile:active { transform: scale(0.94); }

.tile.rarity-ovanlig { border-color: var(--r-ovanlig); }
.tile.rarity-sallsynt { border-color: var(--r-sallsynt); }
.tile.rarity-legendarisk {
  border-color: var(--r-legendarisk);
  background: linear-gradient(160deg, var(--surface) 62%, color-mix(in srgb, var(--win) 14%, var(--surface)));
}

.tile-emoji { font-size: 1.7rem; line-height: 1; white-space: nowrap; }
.tile-sign { line-height: 0; }
.tile-sign .sign-svg { width: 40px; height: 40px; }
.tile-color {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  border: 2px solid rgb(0 0 0 / 0.18);
  box-shadow: inset 0 -3px 6px rgb(0 0 0 / 0.15);
}
.tile-name {
  font-size: 0.67rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.15;
  overflow-wrap: break-word;
  hyphens: auto;
  max-width: 100%;
  color: var(--text);
}

.tile-check {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  color: var(--marked);
  background: color-mix(in srgb, var(--marked-bg) 84%, transparent);
  border-radius: 7px;
}
.tile.marked .tile-check { display: flex; }
.tile.marked { border-color: var(--marked); }

.tile.win-tile { border-color: var(--win); }

@media (prefers-reduced-motion: no-preference) {
  .tile.marked .tile-check { animation: pop 0.25s ease-out; }
  .tile.win-tile { animation: winPulse 0.7s ease-in-out infinite alternate; }
  @keyframes pop {
    0% { transform: scale(0.4); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
  }
  @keyframes winPulse {
    from { box-shadow: 0 0 0 0 var(--win); }
    to { box-shadow: 0 0 14px 2px var(--win); }
  }
}

.game-hint {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-top: 10px;
}

/* ---------- Vinst ---------- */

#screen-win { justify-content: center; align-items: center; }

.win-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.win-title { font-size: 2.4rem; padding: 4px 26px 8px; }
@media (prefers-reduced-motion: no-preference) {
  .win-title { animation: winPop 0.5s ease-out; }
  @keyframes winPop {
    0% { transform: scale(0.3) rotate(-4deg); opacity: 0; }
    70% { transform: scale(1.12) rotate(1deg); }
    100% { transform: scale(1) rotate(0); opacity: 1; }
  }
}
.win-player { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.win-total { font-size: 0.95rem; font-weight: 700; color: var(--win); margin-bottom: 4px; }

.win-board, .stats-content { text-align: left; width: 100%; }
.win-board h3, .stats-content h3 { font-size: 0.95rem; font-weight: 800; margin: 14px 0 6px; }
.lb-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.stats-content { flex: 1; margin-bottom: 14px; }

.win-box .big-btn { width: 100%; }

/* ---------- Dela rum-modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgb(10 12 16 / 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--bg);
  border-radius: 18px;
  padding: 20px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.4);
}
.modal h2 { font-size: 1.2rem; margin: 0; }

.share-qr {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 10px;
  margin: 0 auto;
  width: 200px;
  height: 200px;
  border: 2px solid var(--border);
}
.share-qr svg { width: 100%; height: 100%; }

.share-code {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: 0.35em;
  margin-right: -0.35em;
}
.share-link {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-dim);
  word-break: break-all;
}

/* Nedräkning vid revansch */
.countdown {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(10 12 16 / 0.65);
}
.countdown[hidden] { display: none; }
#countdown-num {
  font-size: 6rem;
  font-weight: 800;
  color: var(--skyltgul);
  text-shadow: 0 4px 24px rgb(0 0 0 / 0.5);
}
@media (prefers-reduced-motion: no-preference) {
  #countdown-num.tick { animation: tickPop 0.35s ease-out; }
  @keyframes tickPop {
    0% { transform: scale(1.7); opacity: 0.3; }
    100% { transform: scale(1); opacity: 1; }
  }
}

/* Märken */
.badge-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.badge {
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 8px 10px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.badge.locked { opacity: 0.45; filter: grayscale(0.6); }
.badge-emoji { font-size: 1.4rem; }
.badge-text { display: flex; flex-direction: column; font-size: 0.68rem; color: var(--text-dim); line-height: 1.25; }
.badge-text b { font-size: 0.8rem; color: var(--text); }

.trip-meta { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 8px; text-align: center; }

#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

/* Toast — "X fick BINGO!" */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 150%);
  opacity: 0;
  visibility: hidden;
  background: var(--skyltgul);
  color: #23262c;
  font-weight: 800;
  padding: 11px 20px;
  border-radius: 999px;
  border: 2px solid #2a2d33;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.25);
  transition: transform 0.3s ease-out, opacity 0.3s, visibility 0.3s;
  z-index: 60;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
