:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1d2327;
  --muted: #5f6b73;
  --border: #d9d5ca;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --demo-bg: #26323a;
  --demo-text: #f1efe8;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181b;
    --surface: #1d2328;
    --text: #ecebe6;
    --muted: #9aa5ac;
    --border: #333c43;
    --accent: #3fb592;
    --accent-text: #0c1512;
    --demo-bg: #0f1417;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { overscroll-behavior: none; }  /* hindrar "dra för att stänga/uppdatera" i appars webbläsare */
body {
  display: flex; flex-direction: column;
  overflow: hidden; overscroll-behavior: none; touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  height: 100vh;                  /* reserv för äldre webbläsare */
  height: 100dvh;
  height: var(--app-h, 100dvh);   /* sätts av game.js till den faktiskt synliga höjden (appars webbläsare ljuger ofta om 100vh) */
  background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.top {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.top h1 { margin: 0; font-size: 1.15rem; letter-spacing: .01em; }
.day { color: var(--muted); font-size: .9rem; flex: 1; }

button {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.icon-btn { width: 34px; height: 34px; padding: 0; border-radius: 50%; font-weight: 600; }

main {
  flex: 1; min-height: 0;
  display: grid; grid-template-rows: 1fr 1fr; gap: 0;
}
@media (min-width: 900px) {
  main { grid-template-rows: none; grid-template-columns: 3fr 2fr; }
}

.pane { position: relative; min-height: 0; min-width: 0; }
#pano { position: absolute; inset: 0; background: #000; }

.demo {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 12px; padding: 24px; text-align: center;
  background: radial-gradient(circle at 30% 20%, #3a4a55, var(--demo-bg) 70%);
  color: var(--demo-text);
}
.demo[hidden] { display: none; }
.demo-tag { margin: 0; padding: 2px 10px; border: 1px solid currentColor; border-radius: 99px; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; opacity: .8; }
.demo-clue { margin: 0; max-width: 34ch; font-size: 1.25rem; line-height: 1.4; }
.demo-note { margin: 0; max-width: 46ch; font-size: .85rem; opacity: .7; }

.float-btn {
  position: absolute; left: 12px; top: 12px; z-index: 3;
  background: rgba(0,0,0,.65); color: #fff; border-color: transparent;
}
.float-btn[hidden] { display: none; }

#mapPane { display: flex; flex-direction: column; border-top: 1px solid var(--border); }
@media (min-width: 900px) { #mapPane { border-top: 0; border-left: 1px solid var(--border); } }
#map { flex: 1; min-height: 0; background: #aad3df; cursor: crosshair; }
#map.locked { cursor: grab; }
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--surface);
  border-top: 1px solid var(--border);
}
.bar span { flex: 1; font-size: .9rem; color: var(--muted); }
.bar [hidden] { display: none; }

.pin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.5); }
.pin.guess { background: #d9382b; }
.pin.target { background: #1f9d55; }

.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,.5); padding: 0;
}
.modal[hidden] { display: none; }
@media (min-width: 600px) { .modal { align-items: center; padding: 16px; } }
.card {
  position: relative; width: 100%; max-width: 460px; max-height: 92dvh; overflow: auto;
  background: var(--surface); color: var(--text);
  border-radius: 16px 16px 0 0; padding: 22px 20px 20px;
}
@media (min-width: 600px) { .card { border-radius: 16px; } }
.card h2 { margin: 0; font-size: 1.5rem; }
.close { position: absolute; right: 10px; top: 10px; width: 34px; height: 34px; padding: 0; border: 0; background: transparent; font-size: 1.6rem; line-height: 1; color: var(--muted); }
.eyebrow { margin: 0 0 2px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.place { margin: 2px 0 14px; color: var(--muted); }
.score-row { display: flex; gap: 12px; margin-bottom: 14px; }
.score-row > div { flex: 1; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.big { display: block; font-size: 1.6rem; font-weight: 700; line-height: 1.15; }
.label { font-size: .8rem; color: var(--muted); }
.fact { margin: 0 0 16px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 16px; text-align: center; }
.stats b { display: block; font-size: 1.25rem; }
.stats span { font-size: .72rem; color: var(--muted); }
.actions { display: flex; gap: 8px; }
.actions button { flex: 1; }
.next { margin: 12px 0 0; text-align: center; font-size: .85rem; color: var(--muted); }
.howto { padding-left: 20px; margin: 12px 0 18px; }
.howto li { margin-bottom: 8px; }

/* ---- Ledtrådsfält ---- */
.cluebar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.cb-label { font-size: .85rem; color: var(--muted); }
.chips { display: flex; gap: 6px; flex: 1; }
.chip { width: 36px; height: 36px; padding: 0; border-radius: 50%; font-weight: 700; }
.chip:disabled { opacity: .35; cursor: not-allowed; }
.chip.viewing { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip.wrong { background: rgba(217, 56, 43, .15); border-color: #d9382b; color: #d9382b; }
.chip.skip { background: var(--bg); color: var(--muted); border-style: dashed; }
.chip.right { background: #1f9d55; border-color: #1f9d55; color: #fff; }
.worth { font-size: .85rem; color: var(--muted); white-space: nowrap; }

.bar { flex-wrap: wrap; }
.bar span { min-width: 140px; }

@media (max-width: 600px) {
  .cluebar { padding: 8px 12px; gap: 8px; }
  .cb-label { display: none; }
  .chip { width: 34px; height: 34px; }
  .worth { font-size: .8rem; }
  .bar { gap: 8px; }
  .bar span { flex: 1 1 100%; min-width: 0; font-size: .85rem; }
  .bar button { flex: 1; }
}

/* ---- Touch: kartan ska hantera alla gester själv ---- */
#map, #map .leaflet-container { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.chip, button { -webkit-tap-highlight-color: transparent; }

/* ---- Tips i appars inbyggda webbläsare ---- */
.inapp {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; font-size: .82rem;
  background: #3a3220; color: #f4e7b8; border-bottom: 1px solid #5c4f2a;
}
.inapp[hidden] { display: none; }
.inapp span { flex: 1; }
.inapp button { padding: 5px 10px; font-size: .8rem; background: transparent; color: inherit; border-color: currentColor; }
.inapp .x { border: 0; font-size: 1.2rem; line-height: 1; padding: 0 4px; }

/* ---- Feedback vid fel gissning ---- */
.toast {
  position: absolute; left: 50%; top: 64px; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 12px;
  max-width: calc(100% - 24px); padding: 12px 18px;
  border-radius: 14px; border: 2px solid #d9382b;
  background: rgba(32, 14, 14, .94); color: #fff;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
  pointer-events: none;
}
.toast[hidden] { display: none; }
.toast.neutral { border-color: #8a949a; background: rgba(25, 30, 34, .94); }
.toast .t-icon {
  flex: none; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%;
  background: #d9382b; font-size: 1.25rem; font-weight: 800;
}
.toast.neutral .t-icon { background: #6c7780; }
.toast b { display: block; font-size: 1.05rem; line-height: 1.25; }
.toast .sub { display: block; font-size: .85rem; opacity: .85; }
.toast.show { animation: toast-in .3s ease-out, toast-out .4s ease-in 2.6s forwards; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(.9); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
@keyframes toast-out { to { opacity: 0; transform: translateX(-50%) translateY(-8px); } }

.pane.shake { animation: shake .45s; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}
.pane.flash-wrong::after {
  content: ""; position: absolute; inset: 0; z-index: 5; pointer-events: none;
  animation: flash-red .8s ease-out;
}
@keyframes flash-red {
  0%   { box-shadow: inset 0 0 0 6px rgba(217, 56, 43, .95), inset 0 0 90px rgba(217, 56, 43, .6); }
  100% { box-shadow: inset 0 0 0 0 rgba(217, 56, 43, 0), inset 0 0 0 rgba(217, 56, 43, 0); }
}
.chip.pulse { animation: chip-fail .9s ease-out; }
@keyframes chip-fail {
  0%   { transform: scale(1.4); box-shadow: 0 0 0 0 rgba(217, 56, 43, .85); }
  60%  { transform: scale(1);   box-shadow: 0 0 0 12px rgba(217, 56, 43, 0); }
  100% { box-shadow: 0 0 0 0 rgba(217, 56, 43, 0); }
}
.worth.drop { animation: worth-drop 1s ease-out; }
@keyframes worth-drop {
  0%   { color: #d9382b; transform: translateY(-8px); opacity: .2; }
  100% { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .toast.show, .pane.shake, .pane.flash-wrong::after, .chip.pulse, .worth.drop { animation: none; }
}

/* ---- Resultatlista ---- */
.places { margin: 0 0 14px; padding-left: 22px; font-size: .92rem; }
.places li { margin-bottom: 8px; }
.places .where { color: var(--muted); }
.places .fact { display: block; color: var(--muted); font-size: .82rem; margin-top: 1px; }
.places li.found::marker { color: #1f9d55; font-weight: 700; }
