/* ==========================================================================
   Storo Runkeren – stil
   Mobil først: alt er laget for en telefon i portrett, og skalerer opp.
   Palett hentet fra stororunk.no: nyhetsrødt, papirgrått, blekksvart.
   ========================================================================== */

/* Fonter ligger i prosjektet (assets/fonts, SIL Open Font License) – ingen
   kall til Google, raskere på mobil. Variable fonter: én fil dekker alle
   vektene vi bruker. Kun latinsk tegnsett (inkl. æøå). */
@font-face {
  font-family: "Oswald";
  font-style: normal;
  font-weight: 200 700;
  font-display: swap;
  src: url("assets/fonts/oswald-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Open Sans";
  font-style: normal;
  font-weight: 300 800;
  font-display: swap;
  src: url("assets/fonts/open-sans-latin.woff2") format("woff2");
}

:root {
  --red: #ff0000;
  --red-dark: #c40000;
  --red-soft: #d3413f;
  --ink: #1f2020;
  --ink-2: #393939;
  --paper: #f2f2f2;
  --white: #ffffff;
  --muted: #5e5e5e;

  --font-head: "Oswald", Impact, "Arial Narrow", sans-serif;
  --font-body: "Open Sans", Arial, sans-serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

/* Stopp alle vanlige mobil-irritasjoner: scroll, bounce, pull-to-refresh,
   tekstmarkering, long-press-meny, blå tap-markering og dobbelttrykk-zoom. */
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--ink);
}

body {
  position: fixed;
  inset: 0;
  font-family: var(--font-body);
  color: var(--ink);
}

/* 100dvh løser iOS Safari sitt 100vh-problem. script.js setter i tillegg en
   eksplisitt høyde fra window.innerHeight i nettlesere uten dvh-støtte. */
#app {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--paper);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

[hidden] { display: none !important; }

/* ---------------------------------------------------------------- HUD --- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  pointer-events: none; /* trykk i HUD-en teller som hopp */
  z-index: 5;
}

.ticker {
  display: flex;
  align-items: stretch;
  height: calc(28px + var(--safe-t));
  padding-top: var(--safe-t);
  background: var(--red);
  color: var(--white);
  overflow: hidden;
  white-space: nowrap;
}
.ticker-tag {
  display: flex;
  align-items: center;
  padding: 0 10px 0 max(10px, var(--safe-l));
  background: var(--ink);
  font: 700 14px/1 var(--font-head);
  letter-spacing: .06em;
  flex: none;
}
.ticker-window { position: relative; overflow: hidden; flex: 1; }
.ticker-track {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  font: 600 13px/1 var(--font-body);
  will-change: transform;
  animation: ticker 60s linear infinite;
}
.ticker-track span { padding-right: 48px; }
@keyframes ticker {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(-50%, 0, 0); }
}

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 max(8px, var(--safe-r)) 0 max(12px, var(--safe-l));
  background: rgba(242, 242, 242, .88);
  border-bottom: 2px solid var(--ink);
}
.brand {
  font: 500 17px/1 var(--font-head);
  white-space: nowrap;
}
.scores {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 12px;
  font: 500 15px/1 var(--font-head);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.scores .hi { color: var(--muted); font-size: 13px; }
.scores b { font-weight: 700; }
.scores .now b { font-size: 20px; }
.scores .now.blink b { animation: blink .15s steps(1) 4; }
@keyframes blink { 50% { opacity: 0; } }

.icon-btn {
  pointer-events: auto;
  flex: none;
  width: 44px;
  height: 44px;
  margin-right: -4px;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn .ico-off { display: none; }
.icon-btn[aria-pressed="true"] .ico-on { display: none; }
.icon-btn[aria-pressed="true"] .ico-off { display: block; }

/* Veldig smale skjermer: skjul merkenavnet før poengene. */
@media (max-width: 350px) { .brand { display: none; } }

/* ------------------------------------------------ Hopp- og dukk-sone --- */
/* Den stiplede linja skiller sonene: trykk over = hopp, hold under = dukk. */
.zone-hint {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .6s;
  z-index: 2;
}
.zone-hint span {
  font: 500 13px/1 var(--font-head);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(31, 32, 32, .7);
  background: rgba(255, 255, 255, .55);
  padding: 5px 10px;
  border-radius: 3px;
  transition: opacity .6s;
}
.zone-hint.show { opacity: 1; }
/* Etter noen sekunder forsvinner instruksjonstekstene helt; bare den
   stiplede linja blir stående svakt som påminnelse om grensen. */
.zone-hint.faint { opacity: .35; }
.zone-hint.faint span { opacity: 0; }
#jump-zone.faint { opacity: 0; }
.zone-hint.night span { color: rgba(255, 255, 255, .8); background: rgba(0, 0, 0, .35); }

#jump-zone {
  top: 40%;               /* overstyres fra script.js */
  transform: translateY(-50%);
}
#duck-zone {
  bottom: 0;
  top: 70%;               /* overstyres fra script.js */
  align-items: flex-start;
  padding-top: 10px;
  border-top: 2px dashed rgba(31, 32, 32, .35);
}
#duck-zone.night { border-top-color: rgba(255, 255, 255, .25); }

/* -------------------------------------------------------------- Toast --- */
#toast {
  position: absolute;
  left: 50%;
  top: 90px;             /* overstyres fra script.js */
  width: max-content;
  max-width: calc(100% - 32px);
  transform: translate(-50%, -8px);
  padding: 7px 12px;
  background: var(--ink);
  color: var(--white);
  font: 600 13px/1.3 var(--font-body);
  text-align: center;
  box-shadow: 3px 3px 0 var(--red);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 4;
}
#toast b { font: 700 13px/1 var(--font-head); color: var(--red); letter-spacing: .05em; margin-right: 6px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------ Skjermer --- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-t) + 84px) max(16px, var(--safe-r)) calc(var(--safe-b) + 16px) max(16px, var(--safe-l));
  background: rgba(31, 32, 32, .38);
  overflow-y: auto;
  touch-action: pan-y;             /* lar kortet scrolle på bittesmå skjermer */
  -webkit-overflow-scrolling: touch;
  animation: fade-in .2s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }

.card {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: auto;
  padding: 18px 18px 16px;
  background: var(--white);
  border: 3px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
}

.kicker {
  display: inline-block;
  padding: 3px 9px;
  background: var(--red);
  color: var(--white);
  font: 700 15px/1 var(--font-head);
  letter-spacing: .06em;
  text-transform: uppercase;
}

.card h1, .card h2 {
  margin: 10px 0 8px;
  font-family: var(--font-head);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .005em;
}
.card h1 { font-size: clamp(34px, 11.5vw, 54px); line-height: 1.02; }
.card h2 { font-size: clamp(24px, 7.4vw, 34px); line-height: 1.02; }
.red { color: var(--red); }

.dek {
  margin: 0 0 14px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-2);
}
#over-quote:empty { display: none; }

.controls {
  list-style: none;
  margin: 0 0 16px;
  padding: 10px 12px;
  background: var(--paper);
  border-left: 4px solid var(--red);
  font-size: 14px;
  line-height: 1.5;
}
.controls li + li { margin-top: 4px; }
.controls small { color: var(--muted); }
.key {
  font: 700 13px/1 var(--font-head);
  letter-spacing: .03em;
  text-transform: uppercase;
}
.desktop-only { display: none; }
@media (hover: hover) and (pointer: fine) { .desktop-only { display: list-item; } }

/* Store, tommelvennlige knapper */
.btn-big, .btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border-radius: 4px;
  font-family: var(--font-head);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}
.btn-big {
  min-height: 68px;
  padding: 10px 16px;
  border: 0;
  background: var(--red);
  color: var(--white);
  font-size: 22px;
  line-height: 1.1;
  box-shadow: 0 5px 0 var(--red-dark);
  transition: transform .06s, box-shadow .06s, opacity .2s;
}
.btn-big:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--red-dark); }
.btn-big:disabled { opacity: .55; }
.btn-big:focus-visible, .btn-secondary:focus-visible, .icon-btn:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}
.btn-secondary {
  min-height: 50px;
  margin-top: 14px;
  border: 2px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  font-size: 17px;
}

/* ---------------------------------------------------------- Toppliste --- */
.player-line {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--ink-2);
}
.player-line b { font: 700 16px/1 var(--font-head); color: var(--ink); letter-spacing: .02em; }

.link-btn {
  display: inline;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--ink);
  font: 600 14px/1.3 var(--font-body);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  touch-action: manipulation;
}
#btn-name-skip { display: block; margin: 10px auto 0; color: var(--muted); }
.name-note {
  margin: 12px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Tekstfelt: 16px+ så iOS ikke zoomer inn, og tekstmarkering tillatt. */
.name-input {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  border: 3px solid var(--ink);
  border-radius: 4px;
  background: var(--white);
  color: var(--ink);
  font: 700 22px/1.2 var(--font-head);
  letter-spacing: .02em;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}
.name-input:focus { outline: 3px solid var(--red); outline-offset: 2px; }
.form-error {
  min-height: 1.4em;
  margin: 6px 0 10px;
  color: var(--red-dark);
  font-size: 14px;
  font-weight: 600;
}

.board-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  border-top: 2px solid var(--ink);
}
.board-list li {
  display: grid;
  grid-template-columns: 2.4em 1fr auto;
  align-items: baseline;
  gap: 8px;
  padding: 7px 6px;
  border-bottom: 1px solid #d6d6d6;
  font-size: 15px;
}
.board-list .rank { font: 700 15px/1 var(--font-head); color: var(--muted); text-align: right; }
.board-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.board-list .score { font: 700 16px/1 var(--font-head); font-variant-numeric: tabular-nums; }
.board-list li[data-rank="1"] .rank,
.board-list li[data-rank="2"] .rank,
.board-list li[data-rank="3"] .rank { color: var(--red); }
.board-list li.me { background: #fff1c2; box-shadow: inset 4px 0 0 var(--red); }
.board-list li.gap { display: block; padding: 2px 6px; text-align: center; color: var(--muted); }
.board-list.compact li { padding: 5px 6px; font-size: 14px; }
.board-list:empty { display: none; }

.board-dek { margin-bottom: 10px; }
.board-mode {
  display: inline-block;
  padding: 1px 6px;
  background: #ffd400;
  font: 700 11px/1.4 var(--font-head);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.board-mode:empty { display: none; }
.board-status, .over-rank {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--ink-2);
}
.board-status:empty, .over-rank:empty { display: none; }
.over-rank b { color: var(--ink); }

.fineprint {
  margin: 12px 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 4px 0 18px;
}
.stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 6px;
  background: var(--paper);
  border: 2px solid var(--ink);
}
.stats small {
  font: 500 12px/1.2 var(--font-head);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.stats b {
  font: 700 34px/1.1 var(--font-head);
  font-variant-numeric: tabular-nums;
}

.stamp {
  position: absolute;
  top: 14px;
  right: 12px;
  padding: 4px 10px;
  border: 3px solid var(--red);
  color: var(--red);
  font: 700 16px/1 var(--font-head);
  letter-spacing: .06em;
  text-transform: uppercase;
  transform: rotate(8deg);
  background: rgba(255, 255, 255, .9);
  animation: stamp .35s cubic-bezier(.2, 1.6, .5, 1);
}
@keyframes stamp { from { transform: rotate(8deg) scale(2.2); opacity: 0; } }

/* Lav skjerm (telefon i landscape): komprimer kortene. */
@media (max-height: 520px) {
  .screen { padding-top: calc(var(--safe-t) + 78px); padding-bottom: calc(var(--safe-b) + 8px); }
  .card { padding: 12px 14px; max-width: 560px; }
  .card h1 { font-size: 30px; margin: 6px 0; }
  .card h1 br { display: none; }
  .card h2 { font-size: 22px; margin: 6px 0; }
  .dek { font-size: 13px; margin-bottom: 8px; }
  .controls { margin-bottom: 10px; padding: 6px 10px; font-size: 13px; }
  .fineprint { display: none; }
  .stats { margin-bottom: 10px; }
  .stats b { font-size: 26px; }
  .btn-big { min-height: 56px; font-size: 19px; }
  .btn-secondary { min-height: 44px; margin-top: 8px; }
  .name-input { min-height: 48px; font-size: 19px; }
  /* Startkortet: dropp ingressen og legg knappene side om side. */
  #screen-start .dek, #screen-start .desktop-only { display: none; }
  #screen-start .card { display: grid; grid-template-columns: 1fr 1fr; column-gap: 10px; }
  #screen-start .card > :not(#btn-start):not(#btn-board) { grid-column: 1 / -1; }
  #screen-start .card > .kicker { justify-self: start; }
  #btn-board { margin-top: 0; min-height: 56px; }
  .player-line { margin-bottom: 8px; }
  /* Game Over: plassering som tekst holder – listen ligger bak "Se hele topplisten". */
  #over-quote, #over-list { display: none; }
  .stats { gap: 8px; margin-bottom: 8px; }
  .stats div { padding: 4px; }
  .over-rank { margin-bottom: 8px; }
  .board-list li { padding: 4px 6px; }
}

/* Lave portrett-skjermer (f.eks. 375×667): hold Game Over-kortet kompakt. */
@media (max-height: 700px) {
  #over-quote { display: none; }
  .stats b { font-size: 28px; }
}

/* Større skjermer: litt mer luft. */
@media (min-width: 900px) and (min-height: 600px) {
  .card { padding: 24px 26px 20px; max-width: 460px; }
  .bar { height: 50px; }
  .brand { font-size: 20px; }
}

.noscript {
  position: fixed;
  inset: auto 16px 40% 16px;
  padding: 16px;
  background: var(--white);
  font-weight: 700;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .ticker-track { animation-duration: 180s; }
  .screen { animation: none; }
}
