:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --text: #1c1c1a;
  --muted: #6b6a65;
  --border: #e4e1da;
  --accent: #0b6b47;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ea;
  --gold: #c8962c;
  --silver: #9aa0a6;
  --bronze: #b06d3c;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 8px 24px rgba(0, 0, 0, .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131412;
    --surface: #1d1f1c;
    --surface-2: #252724;
    --text: #efeee9;
    --muted: #a3a29b;
    --border: #33352f;
    --accent: #3fbf86;
    --accent-ink: #0c1a12;
    --accent-soft: #1d3329;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131412;
  --surface: #1d1f1c;
  --surface-2: #252724;
  --text: #efeee9;
  --muted: #a3a29b;
  --border: #33352f;
  --accent: #3fbf86;
  --accent-ink: #0c1a12;
  --accent-soft: #1d3329;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; text-decoration: none; color: var(--text); letter-spacing: -.01em; white-space: nowrap; }
.topbar-right { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); min-width: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap;
}

.app { max-width: 1120px; margin: 0 auto; padding: 20px 16px 120px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px;
}
.stack { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
h1, h2, h3 { letter-spacing: -.02em; line-height: 1.15; margin: 0; }
h1 { font-size: clamp(32px, 6vw, 52px); font-weight: 800; }
h2 { font-size: 24px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface);
  font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text);
  transition: transform .06s ease, background .15s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { padding: 16px 22px; font-size: 18px; border-radius: 14px; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; }

.field { display: grid; gap: 6px; }
.field label, .label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, select.input {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-weight: 800; font-size: 22px; text-align: center; }

/* ---------- Start ---------- */
.hero { display: grid; gap: 28px; padding: 24px 0 8px; }
.hero p.lead { font-size: 18px; color: var(--muted); max-width: 560px; margin: 12px 0 0; }
.home-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.home-grid .card { display: grid; gap: 14px; align-content: start; }
.how { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.how div { padding: 14px; border-radius: 12px; background: var(--surface); border: 1px dashed var(--border); font-size: 14px; color: var(--muted); }
.how b { display: block; color: var(--text); margin-bottom: 2px; }

/* ---------- Lobby ---------- */
.lobby { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
@media (max-width: 820px) { .lobby { grid-template-columns: minmax(0, 1fr); } }
.room-code { font-size: clamp(44px, 10vw, 72px); font-weight: 800; letter-spacing: .12em; line-height: 1; }
.qr { background: #fff; padding: 10px; border-radius: 12px; width: max-content; }
.qr img, .qr canvas { display: block; width: 148px; height: 148px; }
.players { display: flex; flex-wrap: wrap; gap: 8px; }
.player-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 600;
}
.player-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.player-chip.off { opacity: .5; }
.player-chip.off .dot { background: var(--muted); }
.player-chip.done { background: var(--accent-soft); border-color: transparent; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 800; color: #fff; flex: none;
}
.settings { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.toggle { display: flex; gap: 10px; align-items: center; font-weight: 500; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- Runda ---------- */
.round { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); align-items: start; }
@media (max-width: 900px) {
  .round { grid-template-columns: minmax(0, 1fr); }
  .round.reveal > aside { order: -1; position: static; }
  .round:not(.reveal) { padding-bottom: 250px; }
  .round:not(.reveal) .guess-panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 20;
    border-radius: 18px 18px 0 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    gap: 10px; box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
  }
  .round:not(.reveal) .guess-panel .field,
  .round:not(.reveal) .guess-panel .players,
  .round:not(.reveal) .guess-panel > .label { display: none; }
  .round:not(.reveal) .guess-panel .guess-amount { font-size: 30px; cursor: pointer; }
  .round:not(.reveal) .guess-panel .btn.big { padding: 12px; font-size: 17px; }
}
.gallery { position: relative; border-radius: var(--radius); overflow: hidden; background: #111; aspect-ratio: 3 / 2; box-shadow: var(--shadow); }
.gallery img.main { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; user-select: none; -webkit-user-drag: none; }
.gallery .nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 22px; cursor: pointer;
  display: grid; place-items: center;
}
.gallery .nav.prev { left: 10px; }
.gallery .nav.next { right: 10px; }
.gallery .counter {
  position: absolute; right: 10px; bottom: 10px; padding: 3px 9px; border-radius: 999px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 13px; font-weight: 600;
}
.thumbs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: thin; }
.thumbs button { flex: none; border: 2px solid transparent; padding: 0; border-radius: 8px; overflow: hidden; cursor: pointer; background: none; opacity: .7; }
.thumbs button.on { border-color: var(--accent); opacity: 1; }
.thumbs img { width: 78px; height: 52px; object-fit: cover; display: block; }

.facts-title { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 14px; }
.fact { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.fact .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.fact .v { font-weight: 700; font-size: 17px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text); font-weight: 600; }

.guess-panel { position: sticky; top: 72px; display: grid; gap: 14px; }
.guess-amount { font-size: clamp(30px, 5vw, 40px); font-weight: 800; letter-spacing: -.02em; text-align: center; }
.guess-amount small { font-size: .5em; color: var(--muted); font-weight: 700; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; }
.adjust { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.adjust .btn { padding: 8px 4px; font-size: 14px; }
.timer { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.timer > div { height: 100%; background: var(--accent); width: 100%; transition: width .25s linear; }
.timer.low > div { background: var(--danger); }
.timer-label { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); font-weight: 600; }
.locked { text-align: center; padding: 14px; border-radius: 12px; background: var(--accent-soft); font-weight: 600; }

/* ---------- Karta & namn ---------- */
.map-card { display: grid; gap: 10px; }
.map-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.map { width: 100%; height: 280px; border: 0; border-radius: 12px; background: var(--surface-2); display: block; }
.rename { display: grid; gap: 6px; padding-top: 4px; border-top: 1px solid var(--border); padding-top: 14px; }
.rename .input { flex: 1; min-width: 0; }

/* ---------- Facit ---------- */
.reveal-price { text-align: center; display: grid; gap: 4px; }
.reveal-price .price { white-space: nowrap; font-size: clamp(34px, 4.6vw, 54px); font-weight: 800; letter-spacing: -.03em; line-height: 1.05; }
.results { display: grid; gap: 8px; }
.result {
  display: grid; grid-template-columns: 28px 26px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
}
.result .place { font-weight: 800; color: var(--muted); text-align: center; }
.result .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .sub { font-size: 13px; color: var(--muted); }
.result .pts { font-weight: 800; text-align: right; }
.result .pts small { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.result.me { outline: 2px solid var(--accent); }
.diff-up { color: #c0392b; }
.diff-down { color: #2471a3; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .diff-up { color: #ff8a7a; } :root:not([data-theme="light"]) .diff-down { color: #7cc3ff; } }

.scale { position: relative; height: 54px; margin: 8px 6px 0; }
.scale .line { position: absolute; left: 0; right: 0; top: 26px; height: 2px; background: var(--border); }
.scale .mark { position: absolute; top: 0; transform: translateX(-50%); display: grid; justify-items: center; gap: 2px; }
.scale .mark .avatar { width: 22px; height: 22px; font-size: 10px; border: 2px solid var(--surface); }
.scale .truth { position: absolute; top: 12px; transform: translateX(-50%); width: 4px; height: 30px; border-radius: 2px; background: var(--text); }

.scoreboard { display: grid; gap: 6px; }
.score-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; }
.score-row:nth-child(odd) { background: var(--surface-2); }
.score-row .name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-row .delta { color: var(--accent); font-weight: 700; font-size: 14px; }

/* ---------- Slut ---------- */
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 20px 0 8px; }
.podium .step { width: min(30%, 160px); text-align: center; display: grid; gap: 6px; justify-items: center; }
.podium .block { width: 100%; border-radius: 12px 12px 4px 4px; display: grid; place-items: center; font-size: 28px; font-weight: 800; color: #fff; }
.podium .p1 .block { height: 150px; background: var(--gold); }
.podium .p2 .block { height: 110px; background: var(--silver); }
.podium .p3 .block { height: 80px; background: var(--bronze); }
.podium .avatar { width: 44px; height: 44px; font-size: 17px; }

.empty { text-align: center; padding: 40px 16px; }

/* ---------- Övrigt ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s ease;
  max-width: calc(100vw - 32px); z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
[hidden] { display: none !important; }
.lightbox { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .92); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.lightbox .nav { position: fixed; top: 50%; transform: translateY(-50%); width: 52px; height: 52px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .15); color: #fff; font-size: 26px; cursor: pointer; }
.lightbox .nav.prev { left: 12px; }
.lightbox .nav.next { right: 12px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.pop { animation: pop .35s ease; }
@keyframes pop { from { transform: translateY(8px) scale(.98); } to { transform: none; } }
.footer-note { font-size: 13px; color: var(--muted); text-align: center; margin-top: 28px; }
@media (max-width: 520px) {
  .brand span { display: none; }
  .card { padding: 16px; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
