:root {
  --bg: #07090f;
  --panel: #0e1320;
  --neon: #4dff9f;
  --violet: #a855f7;
  --danger: #ff3b5c;
  --text: #e8f0ff;
  --dim: #7c8aa5;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  /* Dimmig nattbakgrund som ligger kvar bakom alla skärmar. */
  background:
    radial-gradient(90% 55% at 50% 0%, rgba(168, 85, 247, .22), transparent 70%),
    radial-gradient(70% 45% at 50% 100%, rgba(77, 255, 159, .12), transparent 70%),
    var(--bg);
}

/* ---- skärmhantering: body[data-phase] styr vilken sektion som syns ---- */
.screen { display: none; }
body[data-phase="NOKEY"]   [data-screen="NOKEY"],
body[data-phase="IDLE"]    [data-screen="IDLE"],
body[data-phase="LOBBY"]   [data-screen="LOBBY"],
body[data-phase="INTRO"]   [data-screen="INTRO"],
body[data-phase="RUNNING"] [data-screen="RUNNING"],
body[data-phase="FINAL"]   [data-screen="FINAL"] {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  animation: fade .35s ease;
}

@keyframes fade { from { opacity: 0; transform: translateY(8px); } }

.stack { display: flex; flex-direction: column; gap: 16px; margin-top: auto; }
.stack.center { margin: auto 0; align-items: center; text-align: center; }

/* ---- typografi ---- */
.title {
  margin: 0;
  font-size: clamp(34px, 11vw, 56px);
  font-weight: 900;
  letter-spacing: -.02em;
  line-height: .95;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 18px rgba(77, 255, 159, .55), 0 0 48px rgba(168, 85, 247, .45);
}

.lead { margin: 0; color: var(--dim); font-size: 17px; line-height: 1.45; }
.kicker { margin: 0; color: var(--neon); font-size: 13px; font-weight: 800;
          letter-spacing: .18em; text-transform: uppercase; }
.label { color: var(--dim); font-size: 14px; font-weight: 700; margin-bottom: -8px; }

#hero {
  width: 100%;
  max-width: 420px;
  /* Bilden får ta högst drygt en tredjedel av skärmen, annars trycks
     lagnamnet och knappen ur bild på en vanlig telefon. */
  max-height: 38vh;
  object-fit: cover;
  object-position: center 20%;
  margin: 0 auto;
  border-radius: 20px;
  mask-image: linear-gradient(to bottom, #000 62%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 62%, transparent 100%);
}

.bigghost { font-size: clamp(76px, 26vw, 128px); line-height: 1;
            filter: drop-shadow(0 0 26px rgba(77, 255, 159, .6)); }
.spin { animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-14px) rotate(-5deg); } }
.glowpulse { animation: glow 1.5s ease-in-out infinite; }
@keyframes glow { 50% { opacity: .55; } }

/* ---- formulär och knappar ---- */
input {
  width: 100%;
  padding: 18px;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
  color: #fff;
  background: var(--panel);
  border: 2px solid #22304c;
  border-radius: 16px;
}
input:focus { outline: none; border-color: var(--neon); }

.btn {
  width: 100%;
  padding: 22px;
  font-size: 20px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #04120b;
  background: var(--neon);
  border: 0;
  border-radius: 18px;
  box-shadow: 0 0 28px rgba(77, 255, 159, .45);
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .35; box-shadow: none; }
.btn-go { padding: 28px; font-size: 24px; animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe { 50% { box-shadow: 0 0 46px rgba(77, 255, 159, .8); } }
.btn-ghost { color: var(--text); background: transparent; border: 2px solid #22304c;
             box-shadow: none; }

.boxcount { margin: 0; text-align: center; color: var(--dim); font-size: 15px; font-weight: 700; }
.boxcount.warn { color: var(--danger); }

.rules { margin: 0; padding-left: 22px; color: var(--dim); font-size: 16px; line-height: 1.9; }
.rules b { color: var(--text); }

/* ---- jakten ---- */
.hud { display: flex; gap: 12px; }
.hudcell { flex: 1; padding: 14px; text-align: center;
           background: var(--panel); border-radius: 16px; }
.hudlabel { display: block; color: var(--dim); font-size: 12px;
            font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.hudvalue { display: block; margin-top: 4px; font-size: 34px; font-weight: 900;
            font-variant-numeric: tabular-nums; }
#score { color: var(--neon); }

.clockwrap { margin: auto 0; text-align: center; }
.clock {
  font-size: clamp(76px, 28vw, 150px);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 30px rgba(77, 255, 159, .45);
}
.clock.hurry { color: var(--danger); text-shadow: 0 0 34px rgba(255, 59, 92, .7);
               animation: tick 1s steps(2) infinite; }
@keyframes tick { 50% { opacity: .5; } }

.clockbar { height: 8px; margin-top: 18px; background: #16203a;
            border-radius: 99px; overflow: hidden; }
.clockbar i { display: block; height: 100%; width: 100%;
              background: linear-gradient(90deg, var(--violet), var(--neon));
              transition: width .3s linear; }

.ghosts { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-bottom: 14px; }
.gh { font-size: 40px; opacity: .18; filter: grayscale(1); transition: all .25s; }
.gh.screaming {
  opacity: 1;
  filter: none;
  animation: shake .35s ease-in-out infinite;
  text-shadow: 0 0 20px var(--neon);
}
@keyframes shake {
  25% { transform: translateX(-4px) rotate(-8deg); }
  75% { transform: translateX(4px) rotate(8deg); }
}

.hint { margin: 0 0 8px; text-align: center; color: var(--dim); font-size: 15px; }

.btn-scan {
  margin-bottom: 10px;
  color: var(--text);
  background: #241a3d;
  border: 2px solid var(--violet);
  box-shadow: 0 0 22px rgba(168, 85, 247, .35);
}

/* ---- kameravyn ---- */
#scanner {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px; background: #000;
}
#scanner[hidden] { display: none; }
#scanVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanframe {
  position: relative;
  width: min(70vw, 280px); aspect-ratio: 1;
  border: 4px solid var(--neon); border-radius: 24px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .55), 0 0 30px rgba(77, 255, 159, .6);
}
.scanmsg {
  position: relative; margin: 0; padding: 12px 18px;
  font-size: 20px; font-weight: 800; text-align: center;
  background: rgba(10, 14, 24, .85); border-radius: 14px;
}
.scanmsg.candy { color: #04120b; background: var(--neon); }
.scanmsg.poo { color: #fff; background: var(--danger); }
#scanClose { position: relative; width: auto; padding: 16px 32px; }

.burst {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  font-size: clamp(80px, 30vw, 170px); font-weight: 900; color: var(--neon);
  text-shadow: 0 0 40px rgba(77, 255, 159, .9);
  pointer-events: none; opacity: 0;
}
.burst.go { animation: burst .9s ease-out; }
@keyframes burst {
  0% { opacity: 0; transform: scale(.4); }
  25% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 0; transform: scale(1.5); }
}

/* ---- slutskärm ---- */
.finalscore {
  font-size: clamp(90px, 34vw, 180px); font-weight: 900; line-height: 1; color: var(--neon);
  text-shadow: 0 0 40px rgba(77, 255, 159, .6);
}
.highscore { width: 100%; max-width: 360px; margin: 0; padding-left: 26px;
             color: var(--dim); font-size: 16px; line-height: 2; text-align: left; }
.highscore b { color: var(--text); }
.highscore .me { color: var(--neon); }

/* ---- banner för tappad kontakt ---- */
#banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  padding: 10px; text-align: center;
  font-size: 14px; font-weight: 800;
  color: #1a0008; background: var(--danger);
}
