:root {
  --bg: #0a0a0a;
  --card: #141414;
  --card-2: #1d1d1d;
  --line: rgba(255, 255, 255, .14);
  --text: #fff;
  --muted: rgba(255, 255, 255, .62);
  --red: #ef4444;
  --red-dark: #b91c1c;
  --yellow: #facc15;
  --green: #22c55e;
  --display: 'Anton', Impact, 'Arial Black', sans-serif;
  --body: 'Poppins', system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--body); }
body { min-height: 100dvh; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
a { color: inherit; }

.display { font-family: var(--display); letter-spacing: .02em; text-transform: uppercase; line-height: .95; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; font-weight: 800; }

/* ---------- sidor ---------- */
.page { max-width: 560px; margin: 0 auto; padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 112px); }
.section { margin-top: 28px; }
.section > h2 { font-family: var(--display); font-weight: 400; text-transform: uppercase; font-size: 22px; letter-spacing: .03em; margin: 0 0 12px; }

.card { background: var(--card); border: 3px solid #fff; border-radius: 22px; padding: 18px; }
.card.soft { border-color: var(--line); border-width: 2px; }

/* ---------- knappar ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 56px; padding: 0 22px; border-radius: 18px;
  background: var(--red); border: 3px solid #fff; color: #fff;
  font-family: var(--display); font-size: 22px; letter-spacing: .04em; text-transform: uppercase;
  box-shadow: 0 5px 0 #7f1d1d; transition: transform .08s, box-shadow .08s;
  width: 100%; text-decoration: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #7f1d1d; }
.btn.yellow { background: var(--yellow); color: #111; box-shadow: 0 5px 0 #a16207; }
.btn.ghost { background: transparent; border-color: var(--line); box-shadow: none; font-size: 18px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.fab { position: fixed; left: 16px; right: 16px; bottom: calc(var(--safe-bottom) + 16px); width: auto; max-width: 528px; margin: 0 auto; z-index: 20; }

/* ---------- avatar ---------- */
.avatar {
  position: relative; flex: none; display: grid; place-items: center;
  width: var(--s, 48px); height: var(--s, 48px); border-radius: 50%;
  background: var(--c, var(--red)); border: 3px solid #fff; font-size: calc(var(--s, 48px) * .5);
}
.avatar .rank {
  position: absolute; top: -6px; left: -6px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--red); border: 2px solid #fff; font: 800 12px/20px var(--body); text-align: center;
}
.avatar .rank.r1 { background: var(--yellow); color: #111; }

/* ---------- topp ---------- */
.top { display: flex; align-items: center; gap: 12px; }
.top .who { flex: 1; min-width: 0; }
.top .name { font-weight: 800; font-size: 18px; }
.top .title { font-size: 13px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--card-2); border: 2px solid var(--line); font-weight: 800; font-size: 15px; white-space: nowrap; }
.pill.hot { border-color: var(--yellow); color: var(--yellow); }
.pill.red { background: var(--red); border-color: #fff; }
.xp { margin-top: 12px; height: 10px; border-radius: 99px; background: var(--card-2); overflow: hidden; border: 2px solid var(--line); }
.xp > i { display: block; height: 100%; background: linear-gradient(90deg, var(--red), var(--yellow)); border-radius: 99px; transition: width .8s; }
.xp-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- dagens resa ---------- */
.daily { position: relative; overflow: hidden; margin-top: 22px; background: radial-gradient(120% 90% at 100% 0%, #7f1d1d 0%, var(--card) 60%); }
.daily .big-emoji { position: absolute; right: -8px; top: -14px; font-size: 110px; opacity: .9; transform: rotate(8deg); }
.daily .kicker { font-weight: 800; font-size: 13px; letter-spacing: .12em; color: var(--yellow); text-transform: uppercase; }
.daily h1 { font-family: var(--display); font-weight: 400; font-size: 46px; margin: 4px 0 2px; text-transform: uppercase; line-height: .95; }
.daily .sub { color: var(--muted); margin-bottom: 16px; }
.daily .score { font-family: var(--display); font-size: 40px; color: var(--yellow); }

/* ---------- listor ---------- */
.list { display: grid; gap: 10px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 18px; background: var(--card); border: 2px solid var(--line); text-align: left; width: 100%; text-decoration: none; }
.row.me { border-color: var(--red); background: rgba(239, 68, 68, .1); }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 700; }
.row .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { text-align: right; }
.quote { margin-top: 6px; font-style: italic; color: #fff; font-size: 14px; }
.challenge { border-color: var(--yellow); }
.empty { color: var(--muted); padding: 14px; text-align: center; border: 2px dashed var(--line); border-radius: 18px; }

/* ---------- medaljer ---------- */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.badge { text-align: center; padding: 12px 6px; border-radius: 18px; background: var(--card); border: 2px solid var(--line); }
.badge .e { font-size: 34px; }
.badge .n { font-weight: 700; font-size: 13px; margin-top: 4px; hyphens: auto; overflow-wrap: anywhere; }
.badge .d { font-size: 11px; color: var(--muted); margin-top: 2px; }
.badge.locked .e { filter: grayscale(1); opacity: .3; }
.badge.locked .n { color: var(--muted); }
.badge.got { border-color: var(--yellow); }

/* ---------- formulär ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { padding: 14px 10px; border-radius: 18px; background: var(--card); border: 3px solid var(--line); text-align: center; }
.tile .e { font-size: 34px; }
.tile .n { font-weight: 800; margin-top: 4px; }
.tile[aria-pressed="true"] { border-color: #fff; background: var(--red); }
.seg { display: flex; gap: 6px; padding: 5px; border-radius: 16px; background: var(--card); border: 2px solid var(--line); }
.seg button { flex: 1; min-height: 44px; border-radius: 12px; font-weight: 800; }
.seg button[aria-pressed="true"] { background: #fff; color: #111; }
.field { width: 100%; min-height: 52px; padding: 12px 16px; border-radius: 16px; background: var(--card); border: 2px solid var(--line); font-size: 17px; }
.field:focus { outline: none; border-color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 72px; font-weight: 700; font-size: 13px; }
.chip .avatar { opacity: .4; transition: opacity .15s, transform .15s; }
.chip[aria-pressed="true"] .avatar { opacity: 1; transform: scale(1.08); box-shadow: 0 0 0 3px var(--red); }
.emojis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.emojis button { font-size: 30px; aspect-ratio: 1; border-radius: 14px; background: var(--card); border: 2px solid var(--line); }
.emojis button[aria-pressed="true"] { border-color: #fff; background: var(--card-2); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatches button { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; }
.swatches button[aria-pressed="true"] { border-color: #fff; }
label.lbl { display: block; font-weight: 800; margin: 20px 0 8px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-radius: 16px; background: var(--card); border: 2px solid var(--line); font-weight: 700; }
.switch input { width: 24px; height: 24px; accent-color: var(--red); }

/* ---------- spelvyn ---------- */
.play { position: fixed; inset: 0; background: #000; overflow: hidden; }
#pano { position: absolute; inset: 0; }
.mock-pano { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; background: linear-gradient(160deg, #1e3a8a, #0f766e 60%, #365314); }
.mock-pano .display { font-size: 34px; }

.hud { position: absolute; left: 0; right: 0; top: 0; padding: calc(var(--safe-top) + 10px) 12px 10px; display: flex; gap: 8px; align-items: center; z-index: 5; pointer-events: none; background: linear-gradient(#000a, #0000); }
.hud > * { pointer-events: auto; }
.hud .spacer { flex: 1; }
.hud .pill { background: rgba(0, 0, 0, .7); backdrop-filter: blur(8px); border-color: rgba(255, 255, 255, .35); }
.hud .quit { width: 40px; height: 40px; border-radius: 50%; background: rgba(0, 0, 0, .7); border: 2px solid rgba(255, 255, 255, .35); font-size: 18px; }
.timer { position: absolute; left: 0; top: 0; height: 5px; background: var(--yellow); z-index: 6; transition: width 1s linear; }
.timer.urgent { background: var(--red); animation: blink .5s infinite alternate; }
@keyframes blink { to { opacity: .4; } }

/* Kartan: bottenark på mobil, hörnruta på dator */
.guessbox { position: absolute; z-index: 8; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; background: var(--bg); border-top: 3px solid #fff; border-radius: 24px 24px 0 0; height: 62dvh; transform: translateY(100%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); padding-bottom: var(--safe-bottom); }
.guessbox.open { transform: none; }
.guessbox .handle { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; }
.guessbox .grip { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto; }
.guessbox .close { width: 40px; height: 40px; border-radius: 50%; background: var(--card-2); font-size: 18px; }
#guessmap { flex: 1; margin: 0 10px; border-radius: 16px; overflow: hidden; }
.guessbox .actions { padding: 12px; }
.open-map { position: absolute; z-index: 7; right: 16px; bottom: calc(var(--safe-bottom) + 18px); left: 16px; }

.pin { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; font-size: 20px; box-shadow: 0 4px 10px #0008; }
.pin.small { width: 30px; height: 30px; font-size: 15px; border-width: 2px; }
.pin.goal { background: var(--green); }

@media (min-width: 900px) {
  .guessbox { left: auto; right: 20px; bottom: 20px; width: 360px; height: 280px; border: 3px solid #fff; border-radius: 22px; transform: none; opacity: .85; transition: width .2s, height .2s, opacity .2s; }
  .guessbox:hover, .guessbox.pinned { width: 640px; height: 480px; opacity: 1; }
  .guessbox .handle { display: none; }
  #guessmap { margin: 8px 8px 0; }
  .open-map { display: none; }
}

/* ---------- resultat per runda ---------- */
.reveal { position: absolute; inset: 0; z-index: 10; display: flex; flex-direction: column; background: var(--bg); }
#revealmap { flex: 1; min-height: 38dvh; }
.reveal .panel { padding: 18px 16px calc(var(--safe-bottom) + 16px); border-top: 3px solid #fff; background: var(--bg); max-height: 62dvh; overflow-y: auto; }
.reveal .verdict { font-family: var(--display); font-size: 30px; text-transform: uppercase; line-height: 1; }
.reveal .points { font-family: var(--display); font-size: 64px; color: var(--yellow); line-height: 1; margin-top: 6px; }
.reveal .meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.others { display: grid; gap: 6px; margin-bottom: 14px; }
.others .row { padding: 8px 10px; }
@media (min-width: 900px) {
  .reveal { flex-direction: row; }
  .reveal .panel { width: 420px; max-height: none; border-top: 0; border-left: 3px solid #fff; display: flex; flex-direction: column; justify-content: center; }
}

/* ---------- slutresultat ---------- */
.final-total { font-family: var(--display); font-size: 84px; color: var(--yellow); line-height: 1; text-align: center; }
.final-head { text-align: center; }
.final-head .display { font-size: 44px; }
#finalmap { height: 280px; border-radius: 20px; border: 3px solid #fff; overflow: hidden; }
.round-row .n { width: 28px; height: 28px; border-radius: 50%; background: var(--card-2); display: grid; place-items: center; font-weight: 800; font-size: 13px; flex: none; }

/* ---------- laddning, toasts ---------- */
.loading { position: fixed; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; z-index: 50; background: var(--bg); }
.globe { font-size: 88px; animation: spin 2.4s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
#toasts { position: fixed; left: 0; right: 0; top: calc(var(--safe-top) + 64px); z-index: 100; display: grid; gap: 8px; justify-items: center; pointer-events: none; padding: 0 16px; }
.toast { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 18px; background: var(--card); border: 3px solid var(--yellow); box-shadow: 0 10px 30px #000c; animation: pop .4s cubic-bezier(.2, 1.6, .4, 1) both; max-width: 420px; width: 100%; }
.toast .e { font-size: 34px; }
.toast .k { font-size: 11px; font-weight: 800; letter-spacing: .12em; color: var(--yellow); text-transform: uppercase; }
.toast.error { border-color: var(--red); }
@keyframes pop { from { transform: translateY(-20px) scale(.8); opacity: 0; } }

.leaflet-container { background: #aad3df; font-family: var(--body); }
.leaflet-control-attribution { font-size: 9px; }
