:root {
  --red: #c4162f;
  --red-deep: #7a0f1e;
  --gold: #f0c35f;
  --gold-deep: #b9852a;
  --cream: #fff7ec;
  --pine: #1d5b3c;
  --pink: #f6b3c6;
  --ink: #4a1620;
  --panel: rgba(255, 247, 236, 0.92);
  --shadow: 0 10px 30px rgba(60, 5, 15, 0.35);
  --radius: 22px;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #5a0c18; overscroll-behavior: none; }
body { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

#app { position: fixed; inset: 0; }
.bg { position: absolute; inset: 0; }
.bg svg { width: 100%; height: 100%; display: block; }
.bg.fallback { background: radial-gradient(ellipse at 50% 30%, #c4324a, #6a0d1c 70%); }
#snow { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

.screen { position: absolute; inset: 0; display: none; z-index: 2; }
.screen.active { display: flex; }

/* ---------- Knapper ---------- */
.btn {
  font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 1.15rem; letter-spacing: .02em;
  color: #fff; padding: .7em 1.5em; border-radius: 999px; min-height: 48px;
  background: linear-gradient(180deg, #ef3b52 0%, var(--red) 55%, #9a0f24 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.45), inset 0 -3px 0 rgba(0,0,0,.18), 0 6px 14px rgba(120,10,30,.4);
  text-shadow: 0 1px 1px rgba(0,0,0,.25);
  transition: transform .12s ease, filter .12s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.96); }
.btn-ghost {
  color: var(--red-deep); text-shadow: none;
  background: linear-gradient(180deg, #fff, #ffe9d6);
  box-shadow: inset 0 -3px 0 rgba(185,133,42,.25), 0 4px 10px rgba(120,10,30,.18);
}
.btn-big { font-size: 1.6rem; padding: .6em 2.4em; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: #fff; background: linear-gradient(180deg, rgba(255,255,255,.28), rgba(255,255,255,.08));
  border: 2px solid rgba(255,255,255,.55); box-shadow: 0 4px 10px rgba(0,0,0,.2);
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.muted { opacity: .55; }

/* ---------- Startskjerm ---------- */
#screen-menu { align-items: center; justify-content: center; padding: 16px; }
.menu-card { position: relative; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; max-height: 100%; }
.menu-star { font-size: 2rem; color: var(--gold); text-shadow: 0 0 18px rgba(255,220,130,.9); animation: twinkle 2.4s ease-in-out infinite; }
.logo {
  margin: 0; font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: clamp(3rem, 13vw, 5.5rem); line-height: .95;
  color: #fff; text-shadow: 0 3px 0 var(--red-deep), 0 6px 18px rgba(0,0,0,.4);
}
.logo span { color: var(--gold); }
.tagline { margin: 0; color: #fff3df; font-weight: 800; font-size: 1.1rem; text-shadow: 0 2px 6px rgba(0,0,0,.45); }
.menu-figure { height: min(46vh, 430px); aspect-ratio: 1024/1536; overflow: hidden; filter: drop-shadow(0 12px 24px rgba(0,0,0,.35)); }
.menu-figure img { width: 100%; height: 100%; object-fit: contain; animation: bob 4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px); } }
@keyframes twinkle { 50% { opacity: .55; transform: scale(.85) rotate(20deg); } }

/* ---------- Spillskjerm ---------- */
#screen-game { flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 14px 6px; z-index: 6; }
.steps { flex: 1; display: flex; justify-content: center; gap: 6px; margin: 0; padding: 0; list-style: none; }
.steps li {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-weight: 800; font-size: .85rem;
  color: rgba(255,255,255,.85); background: rgba(0,0,0,.18); cursor: pointer; white-space: nowrap;
}
.steps li .n { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.25); font-size: .75rem; }
.steps li.on { color: var(--red-deep); background: linear-gradient(180deg, #fff, #ffe6c7); box-shadow: 0 3px 10px rgba(0,0,0,.2); }
.steps li.on .n { background: var(--red); color: #fff; }
.steps li.done .n { background: var(--gold); color: var(--red-deep); }

.play { flex: 1; min-height: 0; display: flex; }
.stage-wrap { position: relative; flex: 1; min-width: 0; overflow: hidden; touch-action: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.camera { position: absolute; inset: 0; transition: transform .8s cubic-bezier(.65,0,.25,1); transform-origin: 0 0; }
.figure { position: absolute; aspect-ratio: 1024/1536; }
.figure img, .figure svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.figure img { filter: drop-shadow(0 18px 18px rgba(40,0,10,.35)); transition: opacity .25s; }
.figure svg { overflow: visible; }
.figure.swap img { opacity: 0; }
.stage-wrap.clean-mode { cursor: none; }
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 4; pointer-events: none;
  background: rgba(255,247,236,.94); color: var(--red-deep); font-weight: 800; padding: 8px 16px; border-radius: 999px;
  box-shadow: var(--shadow); font-size: .95rem; max-width: 90%; text-align: center; transition: opacity .3s;
}
.hint:empty { opacity: 0; }

/* Panel */
.panel {
  position: relative; z-index: 6; display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow); border: 2px solid rgba(240,195,95,.6);
}
.panel-title { font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 1.3rem; color: var(--red-deep); text-align: center; }
.tabs { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 4px 2px 6px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; width: 70px; padding: 6px 4px;
  border-radius: 16px; font-size: .72rem; font-weight: 800; color: var(--ink);
  background: linear-gradient(180deg, #fff, #fbe8d2); box-shadow: inset 0 -2px 0 rgba(185,133,42,.25);
}
.tab svg, .tab img { width: 40px; height: 40px; }
.tab.on { background: linear-gradient(180deg, #ffd9e2, #f7a9bd); box-shadow: 0 0 0 3px var(--red), 0 4px 10px rgba(196,22,47,.3); }
.tab.set::after { content: ''; position: absolute; }
.tab { position: relative; }
.tab .dot { position: absolute; top: 4px; right: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 2px #fff; }

.options { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; align-content: start; padding: 4px; }
.opt {
  position: relative; aspect-ratio: 1; border-radius: 18px; display: grid; place-items: center; padding: 8px;
  background: radial-gradient(circle at 50% 35%, #fff, #fbe6cf); box-shadow: inset 0 -3px 0 rgba(185,133,42,.25), 0 3px 8px rgba(120,10,30,.12);
  transition: transform .12s;
}
.opt:active { transform: scale(.93); }
.opt.on { box-shadow: 0 0 0 3px var(--red), 0 0 0 6px rgba(240,195,95,.7); }
.opt .sw { width: 70%; height: 70%; border-radius: 50%; box-shadow: inset 0 -4px 8px rgba(0,0,0,.2), inset 0 4px 6px rgba(255,255,255,.5), 0 2px 4px rgba(0,0,0,.2); }
.opt svg { width: 100%; height: 100%; }
.opt img.thumb { width: 100%; height: 100%; object-fit: cover; object-position: top; border-radius: 12px; }
.opt .lbl { position: absolute; bottom: -2px; left: 0; right: 0; font-size: .64rem; font-weight: 800; text-align: center; color: var(--ink); line-height: 1.1; pointer-events: none; }
.opt.has-lbl { padding-bottom: 16px; }
.opt.none { font-size: 1.8rem; color: #b3888f; }
.opt.scene { aspect-ratio: 9/14; padding: 0; overflow: hidden; }
.opt.scene .scene-thumb { position: absolute; inset: 0; }
.opt.scene .scene-thumb svg { width: 100%; height: 100%; }
.opt.scene .lbl { background: rgba(255,247,236,.9); bottom: 0; padding: 3px 0; }
.panel-actions { display: flex; gap: 10px; }
.panel-actions .btn { flex: 1; }

/* Flytende verktøy */
.tool-fly { position: absolute; width: 64px; height: 64px; z-index: 8; pointer-events: none; filter: drop-shadow(0 6px 8px rgba(0,0,0,.3)); }
.tool-fly svg { width: 100%; height: 100%; }
.sparkle { position: absolute; width: 18px; height: 18px; pointer-events: none; z-index: 7;
  background: radial-gradient(circle, #fff 0 20%, rgba(255,230,150,.9) 30%, transparent 70%);
  clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%);
  animation: spark .9s ease-out forwards; }
@keyframes spark { from { transform: translate(0,0) scale(.3) rotate(0); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(1.2) rotate(120deg); opacity: 0; } }
.sponge-cursor { position: absolute; width: 74px; height: 74px; pointer-events: none; z-index: 8; transform: translate(-50%,-50%); display: none; }
.clean-mode .sponge-cursor { display: block; }
.puff { position: absolute; width: 40px; height: 40px; border-radius: 50%; pointer-events: none; z-index: 7; transform: translate(-50%,-50%);
  background: radial-gradient(circle, rgba(255,255,255,.95), rgba(220,240,255,.6) 50%, transparent 70%); animation: puff .6s ease-out forwards; }
@keyframes puff { to { transform: translate(-50%,-50%) scale(2.4); opacity: 0; } }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(60,5,15,.45); backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.modal-card { background: var(--cream); border-radius: 28px; padding: 26px 22px; text-align: center; box-shadow: var(--shadow); border: 3px solid var(--gold); max-width: 380px; width: 100%; animation: pop .45s cubic-bezier(.3,1.6,.5,1); }
.modal-card h2 { font-family: 'Fredoka', sans-serif; color: var(--red); margin: 6px 0; font-size: 1.8rem; }
.modal-card p { margin: 0 0 16px; }
.stars { color: var(--gold); font-size: 2rem; letter-spacing: 4px; text-shadow: 0 2px 0 var(--gold-deep); }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

/* Feiring */
.figure.celebrate { animation: twirl 1s ease-in-out; }
@keyframes twirl { 30% { transform: translateY(-14px) scale(1.02); } 60% { transform: translateY(0) scale(1); } }

/* ---------- Mobil (portrett) ---------- */
@media (max-aspect-ratio: 1/1) {
  .play { flex-direction: column; }
  .panel { height: 42%; min-height: 250px; border-radius: 26px 26px 0 0; padding: 12px 12px max(12px, env(safe-area-inset-bottom)); border-bottom: 0; }
  .panel-title { display: none; }
  .options { grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 8px; }
  .steps li .t { display: none; }
  .steps li.on .t { display: inline; }
}
/* ---------- Desktop / liggende ---------- */
@media (min-aspect-ratio: 1/1) {
  .panel { width: min(400px, 38vw); margin: 0 16px 16px 0; border-radius: 28px; padding: 16px; }
  .tabs { flex-wrap: wrap; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Mobil: hint i panelet så den ikke dekker ansiktet ---------- */
@media (max-aspect-ratio: 1/1) {
  /* Hint ligger i panelet på mobil (flyttes av main.js), ikke over ansiktet */
  .panel .hint { position: static; transform: none; max-width: none; box-shadow: none; padding: 0 4px; min-height: 1.2em;
    background: none; font-size: .85rem; line-height: 1.2; color: var(--red-deep); }
  .panel .hint:empty { display: none; }
}
/* ---------- Liggende telefon / lav skjerm ---------- */
@media (min-aspect-ratio: 1/1) and (max-height: 520px) {
  .topbar { padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: 2px; }
  .icon-btn { width: 38px; height: 38px; }
  .steps li { padding: 4px 10px; }
  .panel { margin: 0 max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) 0; padding: 8px; gap: 6px; border-radius: 20px; }
  .panel-title { display: none; }
  .tabs { flex-wrap: nowrap; justify-content: flex-start; padding: 2px; }
  .tab { width: 58px; font-size: .62rem; padding: 4px 2px; border-radius: 12px; }
  .tab svg, .tab img { width: 28px; height: 28px; }
  .options { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 6px; }
  .panel-actions .btn { min-height: 40px; padding: .4em 1em; font-size: 1rem; }
  .hint { bottom: 8px; font-size: .8rem; padding: 5px 12px; }
  .menu-figure { height: 38vh; }
  .logo { font-size: 2.6rem; }
  .menu-card { gap: 4px; }
}
