:root {
  --bg: #f4f2ec; --land: #e6e2d6; --ink: #1d1c1a; --muted: #77736a; --card: #fffefb; --line: #d9d5c9;
  --accent: #d2452c; --good: #2f8f5b; --peak: #5b3a1e; --range: #4a3f35;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121418; --land: #2c3039; --ink: #ecebe6; --muted: #8b8f99; --card: #1c1f25; --line: #343842;
          --accent: #ff6a4d; --good: #4cc488; }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font: 16px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; border: 0; }
button { cursor: pointer; background: none; }
[hidden] { display: none !important; }

/* map: the Kartverket tiles stay light in dark mode (it's a paper map); Sweden etc. show the background */
#map { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; background: var(--bg); }
#outline { fill: var(--land); stroke: none; }
/* day map: paper under and around Kartverket's tiles, also in dark mode, so land a map leaves transparent
   (Relief's lowlands, small islands) isn't a dark hole. Night (below) has its own dark version. */
body:not(.night) #map { background: #f4f2ec; }
body:not(.night) #outline { fill: #fbf7e4; }
#tiles image { image-rendering: auto; }
#marks line { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
#marks circle { fill: var(--ink); stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; }

/* screen-space labels over the map (re-placed on every move); --mink/--mhalo flip at night */
body { --mink: #1d1c1a; --mhalo: #fffef8; }
body.night, body[data-map="sat"] { --mink: #f2f0ea; --mhalo: #15171c; }
#over text { font-family: inherit; paint-order: stroke; stroke: var(--mhalo); stroke-width: 3px; stroke-linejoin: round; fill: var(--mink); }
#over .city text { font-size: 12px; font-weight: 600; }
#over .city circle { fill: var(--mink); stroke: var(--mhalo); stroke-width: 1.5; }
#over .peak path { fill: var(--peak); stroke: #fff; stroke-width: 1.5; stroke-linejoin: round; }
#over .peak text { font-size: 12px; font-weight: 650; }
#over .peak.sel path { fill: var(--accent); }
#over .range text { font-size: 13px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; fill: var(--range); font-style: italic; }
body.night #over .range text, body[data-map="sat"] #over .range text { fill: #e9dcc8; }
body.night #over .peak path, body[data-map="sat"] #over .peak path { fill: #f0b37a; stroke: #15171c; }
#over .ans path { stroke: #fff; stroke-width: 2; }
#over .ans.hit path { fill: var(--good); } #over .ans.miss path { fill: var(--accent); }
#over .ans text { font-size: 15px; font-weight: 700; }

/* top bar in a game */
#bar { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
#quit { font-size: 18px; color: var(--muted); width: 28px; }
#target { flex: 1; min-width: 0; text-align: center; font-size: 20px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity .2s; }
#score { min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
#time { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--ink); transform-origin: left; }
#time.low { background: var(--accent); }
#bar.cool #target { opacity: .35; }
#bar.explore #target { font-size: 17px; color: var(--muted); font-weight: 600; }
#bar.explore #score, #bar.explore #time { display: none; }

.pop { position: fixed; transform: translate(-50%, -130%); font-weight: 700; font-size: 20px; pointer-events: none;
  animation: pop 1.2s ease-out forwards; font-variant-numeric: tabular-nums; text-shadow: 0 0 6px #fff, 0 0 2px #fff; }
.pop.hit { color: var(--good); } .pop.miss { color: var(--accent); }
@keyframes pop { to { opacity: 0; transform: translate(-50%, -260%); } }

/* menu and end screen */
#menu, #end { position: fixed; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 12px; padding: calc(env(safe-area-inset-top) + 24px) 16px calc(env(safe-area-inset-bottom) + 40px);
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); text-align: center; }
h1 { font-size: 34px; letter-spacing: -.01em; }
.pill { padding: 7px 16px; border-radius: 99px; font-size: 15px; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
/* "Slik spiller du": the rules over everything, nothing underneath moves. ✕, a tap outside, or Escape closes it. */
#info { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  background: rgba(0,0,0,.45); animation: fade .2s ease-out; }
@keyframes fade { from { opacity: 0; } }
#info .sheet { position: relative; width: 100%; max-width: 400px; max-height: 100%; overflow-y: auto; display: flex; flex-direction: column;
  align-items: center; gap: 12px; padding: 20px 18px 18px; border-radius: 18px; background: var(--card); color: var(--ink);
  box-shadow: 0 10px 40px rgba(0,0,0,.3); animation: up .22s ease-out; }
#info h3 { font-size: 21px; }
#info ul { text-align: left; font-size: 15px; line-height: 1.45; padding-left: 20px; }
#info li + li { margin-top: 7px; }
#infoClose { position: absolute; top: 6px; right: 6px; width: 44px; height: 44px; font-size: 20px; color: var(--muted); }
.big { width: 260px; padding: 18px; font-size: 22px; font-weight: 700; border-radius: 14px; background: var(--accent); color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.big:active { transform: scale(.97); }
.link { color: var(--muted); font-size: 15px; padding: 8px 12px; text-decoration: underline; text-underline-offset: 3px; }
#me { font-size: 15px; }
#me .link { padding: 4px 6px; font-size: 15px; }
#nameForm { display: flex; width: 260px; gap: 6px; }
#playForm { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#menuName { width: 260px; padding: 13px 14px; font-size: 18px; text-align: center; background: var(--card); color: var(--ink); outline: none;
  border: 1.5px solid var(--line); border-radius: 12px; -webkit-user-select: text; user-select: text; }
#menuName:focus { border-color: var(--ink); }
/* a pretend cursor after the name (the real one only shows once you tap): the name types itself in, then it blinks.
   #ghost lies over the box with the same text, invisible, so the cursor lands right after the name. */
#nameWrap { position: relative; }
#ghost { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
  font-size: 18px; padding: 0 14px; white-space: pre; overflow: hidden; }
#ghostText { visibility: hidden; }
#ghost i { width: 2px; height: 22px; margin-left: 1px; background: var(--accent); animation: caret 1.1s steps(1) infinite; }
#ghost.typing i { animation: none; }
@keyframes caret { 50% { opacity: 0; } }
#menuName:focus + #ghost, #menuName:placeholder-shown + #ghost:not(.typing) { display: none; }
#menuName.no { border-color: #c0392b; animation: no .35s; }
#name { flex: 1; min-width: 0; padding: 12px; font-size: 17px; background: var(--card); color: var(--ink); outline: none;
  border: 1.5px solid var(--ink); border-radius: 10px; -webkit-user-select: text; user-select: text; }
#name.no { border-color: #c0392b; animation: no .35s; }
@keyframes no { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
#saveName { padding: 0 16px; border-radius: 10px; background: var(--ink); color: var(--bg); font-weight: 600; }

.board { list-style: none; width: 260px; font-size: 14px; font-variant-numeric: tabular-nums; }
.board:empty { display: none; }
.board li { display: flex; gap: 8px; padding: 5px 4px; border-bottom: 1px solid var(--line); }
.board li:last-child { border-bottom: 0; }
.board li b { width: 22px; text-align: right; color: var(--muted); font-weight: 500; }
.board li span { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li i { font-style: normal; font-weight: 600; }
.board li.me { color: var(--accent); }
.board li.gap { justify-content: center; color: var(--muted); border: 0; padding: 0; }
.board::before { content: "🏆"; display: block; margin-bottom: 4px; font-size: 18px; }

h2 { font-size: 52px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
#endParts { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; margin-top: -6px; }
footer { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 12px); font-size: 11px; color: var(--muted); }

/* explore: the card about a mountain or a range */
#card { position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px); max-width: 480px; margin: 0 auto;
  background: var(--card); color: var(--ink); border-radius: 14px; padding: 14px 16px 16px; box-shadow: 0 6px 30px rgba(0,0,0,.18);
  animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
#card h3 { font-size: 21px; }
#card .sub { color: var(--muted); font-size: 14px; margin: 2px 0 8px; }
#card .sub button { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
#card p { font-size: 15px; line-height: 1.4; }
#card .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
#card .chips button { padding: 6px 10px; border-radius: 99px; font-size: 14px; box-shadow: inset 0 0 0 1px var(--line); }
#card .chips button::before { content: "▲ "; color: var(--peak); font-size: 10px; }

/* night: Kartverket's paper map inverted and dimmed (hue turned back so water stays blue); satellite only dimmed */
body.night #map { background: #0e1014; }
body.night #outline { fill: #252a33; }
body.night #tiles { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.7); }
body.night[data-map="sat"] #tiles { filter: brightness(.7); }
body.night #marks line { stroke: #f2f0ea; }

/* map menu: a round button under the top bar, the choices drop down below it */
#mapBtn { position: fixed; right: 12px; top: calc(env(safe-area-inset-top) + 64px); width: 42px; height: 42px; border-radius: 50%;
  background: var(--card); box-shadow: 0 2px 10px rgba(0,0,0,.2); font-size: 20px; }
#mapMenu { position: fixed; right: 12px; top: calc(env(safe-area-inset-top) + 112px); display: flex; flex-direction: column; gap: 2px;
  background: var(--card); border-radius: 14px; padding: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.22); animation: up .15s ease-out; }
#mapMenu button { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 8px; border-radius: 9px; font-size: 15px; text-align: left; }
#mapMenu button span { font-size: 20px; width: 26px; text-align: center; }
#mapMenu button.on { background: color-mix(in srgb, var(--ink) 10%, transparent); font-weight: 650; }
#nightBtn { border-top: 1px solid var(--line) !important; margin-top: 4px; border-radius: 0 0 9px 9px !important; }
#credit { position: fixed; left: 8px; bottom: calc(env(safe-area-inset-bottom) + 4px); font-size: 10px; color: #fff; text-shadow: 0 0 3px #000; pointer-events: none; }
