/* Bakgrunnsfargene byttes per nivå. Registrert som farger, så de kan gli over i hverandre. */
@property --bg { syntax: '<color>'; inherits: true; initial-value: #5b3cc4; }
@property --bg2 { syntax: '<color>'; inherits: true; initial-value: #7a5cf0; }

:root {
  transition: --bg 0.9s ease, --bg2 0.9s ease;
  --bg: #5b3cc4;
  --bg2: #7a5cf0;
  --yellow: #ffd23f;
  --ink: #2a1a6e;
  --white: #ffffff;
  --green: #2ecc71;
  --red: #ff5a5f;
  --pent: #fff7d6;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 30% 0%, var(--bg2), var(--bg) 60%);
  background-color: var(--bg);
  color: var(--white);
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; cursor: pointer; border: 0; touch-action: manipulation; }

.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
}
.screen.active { display: flex; }

h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3.2rem);
  font-weight: 900;
  color: var(--yellow);
  text-shadow: 0 4px 0 rgba(0,0,0,.2);
}
.lead { margin: 0; font-size: 1.2rem; opacity: .9; max-width: 32ch; }
.hint { margin: 0; font-size: .95rem; opacity: .85; max-width: 32ch; }

.choices { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; max-width: 520px; }

.choice {
  background: var(--yellow);
  color: var(--ink);
  font-weight: 900;
  font-size: 1.4rem;
  padding: 18px 26px;
  border-radius: 20px;
  box-shadow: 0 6px 0 #c99a00;
  transition: transform .08s;
  min-width: 140px;
}
.choice:active { transform: translateY(4px); box-shadow: 0 2px 0 #c99a00; }
.choice span { display: block; font-size: 1.1rem; font-weight: 700; }
.choice small { display: block; font-size: .95rem; font-weight: 700; opacity: .75; }
.choices.big .choice { font-size: 4rem; line-height: 1; width: 150px; height: 150px; }
.choice.wide { min-width: 200px; }
.choice.alt { background: var(--white); box-shadow: 0 6px 0 #b7b0d8; }

.install, .back {
  background: rgba(255,255,255,.15);
  color: var(--white);
  font-weight: 800;
  font-size: 1.1rem;
  padding: 12px 22px;
  border-radius: 999px;
}

.countdown {
  font-size: 9rem;
  font-weight: 900;
  color: var(--yellow);
  animation: pop .9s ease-out infinite;
}
@keyframes pop { from { transform: scale(1.4); opacity: 0; } 30% { opacity: 1; } to { transform: scale(1); } }

/* ---------- Spill ---------- */
#screen-game { justify-content: flex-start; gap: 10px; }

.hud {
  width: 100%;
  max-width: 720px;
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.hud-box {
  flex: 1;
  background: rgba(0,0,0,.18);
  border-radius: 16px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  font-size: 1.8rem;
  font-weight: 900;
  line-height: 1.1;
}
.hud-label { font-size: .75rem; font-weight: 700; opacity: .8; text-transform: uppercase; letter-spacing: .05em; }
#time.low { color: var(--red); animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .4; } }
.quit {
  background: rgba(0,0,0,.18);
  color: var(--white);
  font-size: 1.4rem;
  width: 52px;
  border-radius: 16px;
}
.task { margin: 0; font-size: 1.05rem; opacity: .9; min-height: 1.4em; }

.board {
  position: relative;
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 12px;
}

.circle {
  /* vh, ikke dvh: i installert app på iPhone kan dvh bli 0, og da forsvinner sirklene */
  --size: min(43vw, 200px, 28vh);
  position: relative;
  width: var(--size);
  height: var(--size);
  font-size: calc(var(--size) * .12);
  transition: opacity .4s, transform .4s;
}
.circle .shape {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--pent);
  box-shadow: 0 6px 0 rgba(0,0,0,.18), inset 0 -6px 0 rgba(91,60,196,.12);
  transition: background .2s;
}
.circle .op {
  position: absolute;
  left: 50%; top: 52%;
  transform: translate(-50%, -50%);
  font-size: 1.3em;
  font-weight: 900;
  color: var(--bg);
  opacity: .25;
  pointer-events: none;
}
.circle .num {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 2.25em;
  height: 2.25em;
  border-radius: 50%;
  background: var(--white);
  color: var(--ink);
  font-weight: 900;
  font-size: 1em;
  box-shadow: 0 3px 0 rgba(42,26,110,.25);
  display: grid;
  place-items: center;
  padding: 0;
  transition: background .15s, color .15s, opacity .3s, transform .1s;
}
.circle .num:active { transform: translate(-50%, -50%) scale(.92); }
.circle .num.p0 { left: 50%;   top: 19.5%; }
.circle .num.p1 { left: 79.5%; top: 40.5%; }
.circle .num.p2 { left: 68%;   top: 75%; }
.circle .num.p3 { left: 32%;   top: 75%; }
.circle .num.p4 { left: 20.5%; top: 40.5%; }
.circle .num.long { font-size: .82em; }

.circle.wrong .shape { background: #ffd0d1; }
.circle.wrong { animation: shake .4s; }
.circle.wrong .num { pointer-events: none; opacity: .6; }
.circle .num.bad { background: var(--red); color: var(--white); opacity: 1; }
@keyframes shake {
  20% { transform: translateX(-8px); } 40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); } 80% { transform: translateX(5px); }
}

.circle.solved .shape { background: var(--green); }
.circle.solved .num { pointer-events: none; opacity: .25; }
.circle.solved .num.part { opacity: 1; background: var(--white); }
.circle.solved .num.ans { opacity: 1; background: var(--yellow); }
.circle.solved .op { opacity: .6; color: var(--white); }
.circle.solved { animation: bounce .3s; }
@keyframes bounce { 50% { transform: scale(1.08); } }

.circle.gone { opacity: 0; transform: scale(.8); pointer-events: none; }
.circle.hidden { visibility: hidden; }

.board.enter .circle { animation: enter .3s ease-out backwards; }
.board.enter .circle:nth-child(2) { animation-delay: .04s; }
.board.enter .circle:nth-child(3) { animation-delay: .08s; }
.board.enter .circle:nth-child(4) { animation-delay: .12s; }
.board.enter .circle:nth-child(5) { animation-delay: .16s; }
@keyframes enter { from { transform: scale(.5); opacity: 0; } }

/* Superrunden ligger midt over brettet */
.circle.boss {
  --size: min(80vw, 330px, 48vh);
  position: absolute;
  left: 50%;
  top: 50%;
  margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
  animation: none;
}
.circle.boss .shape {
  background: radial-gradient(circle at 50% 40%, #fffbe8, var(--pent));
  box-shadow: 0 0 0 6px var(--yellow), 0 0 40px 10px rgba(255,210,63,.6), 0 8px 0 6px rgba(0,0,0,.18);
  animation: boss-in .5s cubic-bezier(.3,1.6,.5,1);
}
.circle.boss.solved .shape { background: var(--green); }
@keyframes boss-in { from { transform: scale(.2); opacity: 0; } }
.circle.boss.assembling .num { opacity: 0; transition: none; }
.boss-label {
  position: absolute;
  left: 50%;
  top: -.3em;
  transform: translate(-50%, -100%);
  font-size: .9em;
  font-weight: 900;
  letter-spacing: .12em;
  color: var(--yellow);
  text-shadow: 0 3px 0 rgba(0,0,0,.25);
  white-space: nowrap;
}

.fly {
  position: fixed;
  z-index: 50;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--ink);
  font-weight: 900;
  display: grid;
  place-items: center;
  box-shadow: 0 0 20px rgba(255,210,63,.9);
  transform-origin: center;
  transition: transform .75s cubic-bezier(.6,-0.3,.35,1.25);
  pointer-events: none;
}

.float {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  font-weight: 900;
  font-size: 1em;
  color: var(--white);
  text-shadow: 0 2px 0 rgba(0,0,0,.35);
  white-space: nowrap;
  pointer-events: none;
  animation: float-up .9s ease-out forwards;
}
@keyframes float-up { to { transform: translate(-50%, -1.6em); opacity: 0; } }

.banner {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  font-size: clamp(3rem, 16vw, 6rem);
  font-weight: 900;
  color: var(--yellow);
  text-shadow: 0 6px 0 rgba(0,0,0,.25);
  pointer-events: none;
  animation: banner 1.1s ease-out forwards;
}
@keyframes banner {
  0% { transform: scale(.3); opacity: 0; }
  25% { transform: scale(1.15); opacity: 1; }
  40% { transform: scale(1); }
  80% { opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}

.sound-toggles {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  z-index: 40;
}
.sound-toggles button {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0,0,0,.22);
  font-size: 1.25rem;
}
.sound-toggles button.off { opacity: .45; }
.sound-toggles button.off::after {
  content: "";
  position: absolute;
  left: 8px; right: 8px; top: 50%;
  height: 3px;
  background: var(--red);
  transform: rotate(-45deg);
  border-radius: 2px;
}

/* ---------- Resultat ---------- */
.result-score {
  font-size: 7rem;
  font-weight: 900;
  line-height: 1;
  color: var(--yellow);
  display: flex;
  flex-direction: column;
}
.result-score small { font-size: 1.3rem; color: var(--white); }
.record { margin: 0; font-size: 1.3rem; font-weight: 800; }
.record.new { color: var(--yellow); animation: bounce .6s infinite; }

/* ---------- Uendelig bane ---------- */
.choices.big .choice small { margin-top: 4px; font-size: .9rem; min-height: 1.2em; }
.best { margin: 0; font-size: .95rem; font-weight: 800; opacity: .85; min-height: 1.2em; }
.best.new { color: var(--yellow); opacity: 1; }
.result-score small { order: -1; margin-bottom: 6px; }
.banner { text-align: center; }
.banner small { display: block; font-size: .4em; color: var(--white); }
.banner.record { animation-duration: 1.4s; }


/* ---------- Bonusmåler ---------- */
.hud-box { font-size: 1.5rem; min-width: 0; }
.meter {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 0;
}
.meter i {
  flex: 1;
  height: 16px;
  border-radius: 4px;
  background: rgba(255,255,255,.18);
  transition: background .15s, box-shadow .15s;
}
.meter i.on { background: var(--yellow); }
.hud-box.streak.almost .meter i.on { animation: glow .5s ease-in-out infinite alternate; }
@keyframes glow { to { background: #fff3b0; } }
.hud-box.streak.full { animation: full .7s; }
@keyframes full {
  0%, 40% { background: rgba(255,210,63,.55); transform: scale(1.08); }
  100% { transform: scale(1); }
}
.hud-box.streak.lost { animation: fizz .5s; }
@keyframes fizz {
  0% { transform: scale(1.1); background: rgba(120,120,120,.6); }
  100% { transform: scale(1); }
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(max(16px, env(safe-area-inset-top)) + 66px);
  z-index: 55;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font-size: 1.4rem;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  pointer-events: none;
  animation: toast 1.4s ease-out forwards;
}
@keyframes toast {
  0% { transform: translateX(-50%) scale(.4); opacity: 0; }
  15% { transform: translateX(-50%) scale(1.1); opacity: 1; }
  25% { transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { transform: translateX(-50%) translateY(-20px); opacity: 0; }
}

/* ---------- Superrunde-effekter ---------- */
.fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 0;
  pointer-events: none;
}
.fx-canvas.fallback {
  background: conic-gradient(from 0deg at 50% 55%, #ff5a5f, #ffd23f, #2ecc71, #3fa9ff, #9b5cff, #ff5a5f);
  animation: fx-hue 6s linear infinite;
}
@keyframes fx-hue {
  from { filter: hue-rotate(0deg) saturate(.7) brightness(.7); }
  to { filter: hue-rotate(360deg) saturate(.7) brightness(.7); }
}
.screen { position: relative; z-index: 1; }

/* Toppfeltet må være lesbart over regnbuen */
.boss-mode .hud-box, .boss-mode .quit { background: rgba(20,10,60,.55); }
.boss-mode .task { text-shadow: 0 2px 6px rgba(0,0,0,.6); }

/* Snurrende regnbuering rundt superrunden */
.circle.boss .shape { box-shadow: 0 8px 0 rgba(0,0,0,.25); transition: none; }
.circle.boss .rainbow {
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  background: conic-gradient(#ff5a5f, #ff9f1c, #ffd23f, #2ecc71, #3fa9ff, #6c5ce7, #c56cf0, #ff5a5f);
  animation: spin 2.5s linear infinite, fade-in .6s ease-out;
}
.circle.boss .rainbow.glow { inset: -26px; filter: blur(22px); opacity: .85; }
.circle.boss.solved .rainbow { animation-duration: .8s, .6s; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } }

.circle.boss .boss-label {
  background: linear-gradient(90deg, #ff5a5f, #ffd23f, #2ecc71, #3fa9ff, #c56cf0, #ff5a5f);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,.35));
  animation: label-shift 2s linear infinite;
}
@keyframes label-shift { to { background-position: 200% 0; } }

@media (prefers-reduced-motion: reduce) {
  .circle.boss .rainbow, .circle.boss .boss-label, .fx-canvas.fallback { animation: none; }
}

.start-error {
  background: rgba(255,90,95,.25);
  border: 2px solid var(--red);
  border-radius: 14px;
  padding: 10px 14px;
}

/* ---------- Superrunden: tallene roterer jevnt mot klokka ---------- */
/* Hvert tall har sin startvinkel (--a). Hele sirkelen animerer --spin fra 0 til −360°,
   så alle tallene glir rundt sammen. Tallene står oppreist hele veien. */
@property --a { syntax: '<angle>'; inherits: false; initial-value: -90deg; }
@property --spin { syntax: '<angle>'; inherits: true; initial-value: 0deg; }
.circle.boss .num {
  left: calc(50% + 31% * cos(var(--a) + var(--spin)));
  top: calc(50% + 31% * sin(var(--a) + var(--spin)));
}
.circle.boss.spinning { animation: boss-spin var(--spin-time, 2s) linear infinite; }
.circle.boss.spinning.solved { animation-play-state: paused; } /* stopper der den er */
@keyframes boss-spin { to { --spin: -360deg; } }

/* ---------- Spill med venner ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; font-size: 1rem; }
.field input, .code-input {
  font: inherit;
  font-weight: 900;
  font-size: 1.5rem;
  text-align: center;
  color: var(--ink);
  background: var(--white);
  border: 0;
  border-radius: 16px;
  padding: 12px 16px;
  width: min(280px, 80vw);
  user-select: text;
  -webkit-user-select: text;
}
.code-input { width: 150px; letter-spacing: .25em; }
.join-row { display: flex; gap: 12px; align-items: center; }
.join-row .choice { min-width: 0; }
.or { margin: 0; font-weight: 700; opacity: .75; }
.choice:disabled { opacity: .55; }
.back:disabled, .choice:disabled { cursor: default; }

.room-code {
  font-size: clamp(4.5rem, 24vw, 8rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: .08em;
  color: var(--yellow);
  text-shadow: 0 6px 0 rgba(0,0,0,.2);
  user-select: text;
  -webkit-user-select: text;
}
.mp-ops .choice { font-size: 2.2rem; line-height: 1; min-width: 110px; padding: 12px 18px; opacity: .55; }
.mp-ops .choice.selected { opacity: 1; outline: 4px solid var(--white); outline-offset: 3px; }
.mp-ops .choice:disabled { cursor: default; }

.players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 520px;
}
.players li {
  background: rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 800;
  animation: enter .3s ease-out;
}
.players li.me { background: var(--white); color: var(--ink); }
.players li.offline { opacity: .45; }
.players li[data-shown] { animation: none; } /* bare første gang, se patchList i mp.js */

.podium { flex-direction: column; flex-wrap: nowrap; width: min(420px, 100%); }
.podium li { display: flex; gap: 10px; align-items: center; border-radius: 16px; text-align: left; }
.podium .pos { width: 2em; text-align: center; font-size: 1.3rem; }
.podium .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .lvl { opacity: .85; white-space: nowrap; }
.mp-result { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.mp-result h2 { margin: 0; font-size: 1.6rem; font-weight: 900; color: var(--yellow); }

.live {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  font-size: .9rem;
  font-weight: 800;
}
.live span { background: rgba(0,0,0,.18); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.live span.me { background: var(--yellow); color: var(--ink); }
.live b { font-weight: 900; }

[hidden] { display: none !important; }

/* ---------- QR-kode i venterommet ---------- */
.lobby-join { display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap; }
.qr {
  width: clamp(140px, 38vw, 220px);
  aspect-ratio: 1;
  padding: 10px;
  background: var(--white);
  border-radius: 16px;
  box-shadow: 0 6px 0 rgba(0,0,0,.18);
}
.qr svg { display: block; width: 100%; height: 100%; }
.qr:empty { display: none; }
.players li.watcher { background: transparent; border: 2px dashed rgba(255,255,255,.5); }

/* ---------- Lærerens ledertavle ---------- */
#screen-watch { justify-content: flex-start; padding-top: max(28px, env(safe-area-inset-top)); }
.podium.watch { width: min(720px, 100%); }
.podium.watch li { padding: 10px 16px; font-size: clamp(1rem, 2.4vw, 1.4rem); }
.podium.watch .stats { opacity: .85; font-weight: 700; white-space: nowrap; font-size: .85em; }
.podium.watch .stats .many { color: #ffb3b5; font-weight: 900; }
.podium.watch .state { width: 1.6em; text-align: center; }
@media (max-width: 520px) { .podium.watch li { flex-wrap: wrap; } .podium.watch .stats { order: 5; width: 100%; padding-left: 2.6em; } }
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.1rem;
  cursor: pointer;
}
.check input { width: 26px; height: 26px; accent-color: var(--yellow); cursor: pointer; }
