:root {
  --night: #0b1730;
  --night-2: #13254a;
  --card: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.16);
  --text: #f4f1ea;
  --muted: #b9c3d6;
  --red: #d7263d;
  --red-dark: #a51b2e;
  --green: #2e8b57;
  --gold: #f2c14e;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(ellipse at top, var(--night-2), var(--night) 70%) fixed;
  background-color: var(--night);
  color: var(--text);
  line-height: 1.45;
  overscroll-behavior: none;
}
#snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
#app {
  position: relative; z-index: 1;
  max-width: 640px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  min-height: 100%;
}
.screen[hidden] { display: none !important; }
.screen { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.35rem; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.big-emoji { font-size: 64px; margin-bottom: 8px; }

.card {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 20px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.screen > .card:first-child { margin-top: 12vh; }

input[type="text"], input[inputmode] {
  width: 100%; font-size: 18px; padding: 14px 16px; border-radius: 12px;
  border: 2px solid var(--card-border); background: rgba(0,0,0,.25); color: var(--text);
  outline: none; margin-bottom: 12px;
}
input:focus { border-color: var(--gold); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px; padding: 12px 18px; font-size: 18px; font-weight: 700;
  color: #fff; background: var(--red); border: 0; border-radius: 12px; cursor: pointer;
  box-shadow: 0 4px 0 var(--red-dark); transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--red-dark); }
.btn.secondary { background: var(--night-2); box-shadow: 0 4px 0 #08101f; }
.btn.gold { background: var(--gold); color: #3a2a00; box-shadow: 0 4px 0 #b88a1d; }
.link-btn { background: none; border: 0; color: var(--gold); font-size: 16px; padding: 8px 0; cursor: pointer; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.title { font-size: 1.5rem; }
.door-badge { background: var(--red); color: #fff; font-weight: 800; padding: 6px 12px; border-radius: 999px; }
.countdown { color: var(--gold); font-weight: 600; margin-bottom: 16px; }

/* Kalendergitter */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(6, 1fr); } }
.door {
  position: relative; aspect-ratio: 1; border-radius: 14px; border: 2px solid var(--card-border);
  font-size: 24px; font-weight: 800; color: var(--text); background: var(--card);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.door.open { background: linear-gradient(160deg, var(--red), var(--red-dark)); border-color: #ff6b7d; }
.door.done { background: linear-gradient(160deg, var(--green), #1d5d3a); border-color: #6fd39b; }
.door.done::after { content: "✓"; position: absolute; top: 4px; right: 8px; font-size: 14px; }
.door.locked { opacity: .45; cursor: default; }
.door.locked::after { content: "🔒"; position: absolute; bottom: 4px; right: 6px; font-size: 12px; }
.door.big { grid-column: span 2; background: linear-gradient(160deg, #caa23a, #8f6b12); border-color: var(--gold); }
.door.big.locked { background: var(--card); border-color: var(--card-border); }
.door.big.done { background: linear-gradient(160deg, var(--green), #1d5d3a); }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }

/* Luke */
.question { font-size: 1.15rem; white-space: pre-line; margin: 12px 0 16px; }
.options { display: grid; gap: 10px; margin-bottom: 12px; }
.options:empty { display: none; }
.option { width: 100%; padding: 14px; font-size: 17px; border-radius: 12px; border: 2px solid var(--card-border); background: rgba(0,0,0,.2); color: var(--text); cursor: pointer; }
.option:active { border-color: var(--gold); }
.feedback { min-height: 1.4em; font-weight: 700; margin-top: 12px; }
.feedback.ok { color: #7ee2a8; }
.feedback.bad { color: #ff8a98; }
.hint { color: var(--muted); font-style: italic; }

/* Finale */
.level-head { margin-bottom: 12px; }
.level-head p { color: var(--muted); }
.progress-dots { display: flex; gap: 6px; justify-content: center; margin: 4px 0 16px; flex-wrap: wrap; }
.progress-dots span { width: 12px; height: 12px; border-radius: 50%; background: var(--card-border); }
.progress-dots span.done { background: var(--green); }
.progress-dots span.now { background: var(--gold); }
.stage { display: flex; flex-direction: column; align-items: center; gap: 14px; }

.maze { touch-action: none; max-width: 100%; border-radius: 10px; background: #0e1d3d; border: 2px solid var(--card-border); }
.dpad { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(2, 56px); gap: 8px; }
.dpad button { font-size: 24px; border-radius: 12px; border: 0; background: var(--night-2); color: var(--text); box-shadow: 0 3px 0 #08101f; }
.dpad button:active { transform: translateY(2px); box-shadow: none; }
.dpad .up { grid-column: 2; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }

.tiles { display: grid; gap: 6px; width: min(86vw, 340px); }
.tile {
  aspect-ratio: 1; border-radius: 12px; border: 0; font-size: clamp(20px, 7vw, 32px); font-weight: 800;
  background: linear-gradient(160deg, var(--red), var(--red-dark)); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; user-select: none;
}
.tile.empty { background: transparent; box-shadow: inset 0 0 0 2px var(--card-border); cursor: default; }
.tile.back { background: var(--night-2); font-size: 0; box-shadow: inset 0 0 0 2px var(--card-border); }
.tile.back::after { content: "❄️"; font-size: clamp(20px, 7vw, 30px); }
.tile.matched { background: linear-gradient(160deg, var(--green), #1d5d3a); }
.tile.off { background: #23314f; }
.tile.on { background: radial-gradient(circle, #ffe9a3, var(--gold) 60%, #b88a1d); color: #3a2a00; }
.tile.given { background: #2a3b60; cursor: default; }
.tile.blank { background: rgba(0,0,0,.25); box-shadow: inset 0 0 0 2px var(--card-border); }
.tile.sel { box-shadow: inset 0 0 0 3px var(--gold); }
.tile.err { box-shadow: inset 0 0 0 3px #ff6b7d; }

.palette { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.palette button { font-size: 28px; width: 58px; height: 58px; border-radius: 12px; border: 2px solid var(--card-border); background: var(--night-2); }

.bells { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; width: min(80vw, 300px); }
.bell { aspect-ratio: 1; border-radius: 20px; border: 0; font-size: 40px; opacity: .55; transition: opacity .1s, transform .1s; }
.bell.lit { opacity: 1; transform: scale(1.06); box-shadow: 0 0 24px rgba(255,255,255,.6); }

.letters { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.letter { min-width: 44px; height: 50px; font-size: 22px; font-weight: 800; border-radius: 10px; border: 0; background: var(--night-2); color: var(--text); box-shadow: 0 3px 0 #08101f; }
.letter.used { visibility: hidden; }
.answer-line { min-height: 54px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.answer-line span { min-width: 36px; height: 50px; border-bottom: 3px solid var(--gold); font-size: 26px; font-weight: 800; display: flex; align-items: center; justify-content: center; }

.clues { width: 100%; display: grid; gap: 8px; }
.clue { display: flex; align-items: center; gap: 12px; background: rgba(0,0,0,.2); padding: 10px 12px; border-radius: 12px; }
.clue b { font-family: ui-monospace, monospace; font-size: 22px; letter-spacing: 6px; color: var(--gold); }
.code-inputs { display: flex; gap: 10px; justify-content: center; }
.code-inputs input { width: 60px; text-align: center; font-size: 28px; font-weight: 800; margin: 0; }

.pegs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; }
.peg { min-height: 170px; border-radius: 12px; border: 2px solid var(--card-border); background: rgba(0,0,0,.2); display: flex; flex-direction: column-reverse; align-items: center; justify-content: flex-start; padding: 8px 4px; gap: 4px; cursor: pointer; }
.peg.sel { border-color: var(--gold); }
.disc { height: 24px; border-radius: 8px; }

/* Binærfinalen */
.reveal { display: flex; gap: 6px; justify-content: center; margin: 8px 0 18px; }
.reveal span { width: 40px; height: 54px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 900; background: rgba(0,0,0,.25); border: 2px dashed var(--card-border); }
.reveal span.space { background: none; border: 0; width: 14px; }
.reveal span.shown { background: linear-gradient(160deg, var(--red), var(--red-dark)); border: 2px solid #ff6b7d; animation: pop .4s; }
@keyframes pop { 0% { transform: scale(.3); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
.bits { font-family: ui-monospace, monospace; font-size: 30px; letter-spacing: 6px; min-height: 44px; text-align: center; color: var(--gold); }
.bitpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(90vw, 340px); }
.bitpad button { min-height: 64px; font-size: 28px; font-weight: 800; border-radius: 14px; border: 0; background: var(--night-2); color: var(--text); box-shadow: 0 4px 0 #08101f; }
.bitpad button.ok { background: var(--green); box-shadow: 0 4px 0 #1d5d3a; font-size: 20px; }
.bitpad button.del { font-size: 20px; }
.bitpad button:active { transform: translateY(3px); box-shadow: none; }
.win-text { font-size: clamp(42px, 14vw, 72px); font-weight: 900; color: var(--gold); text-shadow: 0 0 24px rgba(242,193,78,.6); text-align: center; animation: pop .6s; }
