/* Knopps Julkalender – 1930s rubber-hose cartoon look */
:root {
  --ink: #1b1310;
  --paper: #f3e3c3;
  --paper-dark: #e2c995;
  --sepia: #c9a46a;
  --red: #c8352b;
  --red-dark: #8f2119;
  --green: #2f6b3a;
  --green-dark: #1f4a27;
  --gold: #e0a526;
  --skin: #f6d2a8;
  --night: #2a2f3d;
  --white: #fffaf0;
  --title-font: "Cooper Black", "Rockwell Extra Bold", "Rockwell", "Georgia", serif;
  --body-font: "Trebuchet MS", "Verdana", "Segoe UI", sans-serif;
  --radius: 22px;
  --shadow: 0 6px 0 var(--ink);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--night);
  color: var(--ink);
  font-family: var(--body-font);
  font-size: 20px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
#app { position: fixed; inset: 0; overflow: hidden; }

/* Film grain + vignette */
.grain {
  pointer-events: none; position: fixed; inset: 0; z-index: 900; opacity: .07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.07 0 0 0 0 0.05 0 0 0 1.1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.vignette {
  pointer-events: none; position: fixed; inset: 0; z-index: 901;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(27,19,16,.55) 100%);
}

/* Screens */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  background: var(--paper);
  background-image:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,.35), transparent 40%),
    repeating-linear-gradient(45deg, rgba(27,19,16,.025) 0 2px, transparent 2px 6px);
  animation: screen-in .35s ease-out;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
@keyframes screen-in { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
.screen.dark { background-color: var(--night); color: var(--paper); }

h1, h2, h3, .title-font { font-family: var(--title-font); font-weight: 900; margin: 0; letter-spacing: .5px; }
h1 { font-size: clamp(36px, 8vw, 72px); line-height: 1; }
h2 { font-size: clamp(28px, 5.5vw, 46px); line-height: 1.05; }
h3 { font-size: clamp(22px, 4vw, 30px); }
.outlined { color: var(--red); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 3px 4px 0 var(--ink); }
.outlined.gold { color: var(--gold); }
.outlined.cream { color: var(--paper); }

/* Buttons – chunky cartoon */
.btn {
  font-family: var(--title-font); font-size: clamp(22px, 4.5vw, 32px); color: var(--white);
  background: var(--red); border: 4px solid var(--ink); border-radius: 999px;
  padding: 14px 34px; min-height: 64px; box-shadow: var(--shadow); cursor: pointer;
  transition: transform .08s, box-shadow .08s; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.btn.green { background: var(--green); }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.cream { background: var(--paper); color: var(--ink); }
.btn.small { font-size: 22px; padding: 8px 22px; min-height: 64px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.wiggle { animation: wiggle 2.4s ease-in-out infinite; }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-4deg) scale(1.04); } 75% { transform: rotate(4deg) scale(1.04); } }

.icon-btn {
  width: 64px; height: 64px; border-radius: 50%; border: 4px solid var(--ink); background: var(--paper);
  box-shadow: 0 4px 0 var(--ink); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.icon-btn svg { width: 30px; height: 30px; }
.icon-btn.off { opacity: .5; }

/* Card / panel */
.panel {
  background: var(--white); border: 5px solid var(--ink); border-radius: var(--radius);
  box-shadow: 0 8px 0 var(--ink); padding: 22px 26px;
}

/* Speech bubble */
.bubble {
  position: relative; background: var(--white); border: 4px solid var(--ink); border-radius: 26px;
  padding: 14px 20px; font-size: clamp(20px, 3.6vw, 28px); font-weight: bold; line-height: 1.3;
  box-shadow: 0 5px 0 var(--ink); display: flex; align-items: center; gap: 12px; max-width: 640px;
}
.bubble .speak { flex: none; width: 64px; height: 64px; }
.bubble .speak svg { width: 30px; height: 30px; }

/* ---------- Title screen ---------- */
.title-screen { justify-content: center; gap: 18px; text-align: center; background-color: var(--night); color: var(--paper); overflow: hidden; }
.title-screen .sign {
  background: var(--red); border: 6px solid var(--ink); border-radius: 30px; padding: 18px 30px 22px;
  box-shadow: 0 10px 0 var(--ink), inset 0 0 0 6px var(--gold); transform: rotate(-2deg);
}
.title-screen .sign h1 { color: var(--paper); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 4px 5px 0 var(--ink); }
.title-screen .sign .sub { font-family: var(--title-font); color: var(--gold); font-size: clamp(18px, 3.4vw, 26px); margin-top: 6px; -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; }
.title-screen .elf-wrap { width: min(42vw, 230px); height: min(48vh, 300px); }
.snowfall { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.snowfall i { position: absolute; top: -20px; width: 10px; height: 10px; border-radius: 50%; background: var(--paper); opacity: .8; animation: fall linear infinite; }
@keyframes fall { to { transform: translate(var(--drift, 20px), 110vh); } }

/* ---------- Names ---------- */
.names-screen { justify-content: center; gap: 20px; padding: 20px; overflow-y: auto; }
.names-screen .panel { width: min(640px, 100%); display: flex; flex-direction: column; gap: 16px; align-items: stretch; }
.name-row { display: flex; gap: 10px; }
.name-row input {
  flex: 1; min-width: 0; font-size: 28px; font-family: var(--body-font); font-weight: bold; padding: 10px 16px;
  border: 4px solid var(--ink); border-radius: 18px; background: var(--paper); color: var(--ink); outline: none;
}
.name-row input:focus { background: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; min-height: 60px; }
.chip {
  display: inline-flex; align-items: center; gap: 10px; font-size: 26px; font-weight: bold; padding: 8px 10px 8px 18px;
  border: 4px solid var(--ink); border-radius: 999px; color: var(--white); box-shadow: 0 4px 0 var(--ink);
  animation: pop-in .35s cubic-bezier(.3,1.6,.5,1);
}
.chip button { width: 48px; height: 48px; margin-left: 6px; border-radius: 50%; border: 3px solid var(--ink); background: var(--paper); font-weight: bold; font-size: 20px; cursor: pointer; line-height: 1; }
@keyframes pop-in { from { transform: scale(0); } to { transform: scale(1); } }

/* ---------- Map ---------- */
.map-screen { background-color: var(--night); }
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: linear-gradient(var(--night) 60%, transparent);
}
.topbar .grow { flex: 1; min-width: 0; }
.topbar .team { color: var(--paper); font-weight: bold; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .team b { font-family: var(--title-font); color: var(--gold); font-size: 22px; display: block; }
.knopp-badge {
  width: 64px; height: 64px; border-radius: 50%; border: 4px solid var(--ink); background: var(--paper); overflow: hidden;
  box-shadow: 0 4px 0 var(--ink); padding: 0; cursor: pointer; position: relative; flex: none;
}
.knopp-badge svg { width: 100%; height: 130%; margin-top: -2px; }
.count-badge { font-family: var(--title-font); background: var(--gold); border: 3px solid var(--ink); border-radius: 999px; padding: 4px 12px; font-size: 18px; box-shadow: 0 3px 0 var(--ink); }
.map-scroll { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.map-svg { display: block; width: 100%; max-width: 640px; margin: 0 auto; }
.door { cursor: pointer; }
.door.locked { cursor: default; }
.door .door-body { transition: transform .15s; transform-box: fill-box; transform-origin: center; }
.door:active .door-body { transform: scale(.92); }
.door.today .door-body { animation: door-bounce 2.4s ease-in-out infinite; }
@keyframes door-bounce { 0%,100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-8px) scale(1.06, .96); } 55% { transform: translateY(0) scale(.96, 1.05); } }
.banner {
  position: absolute; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  width: min(92%, 560px); text-align: center;
}

/* ---------- Day intro ---------- */
.intro-screen { justify-content: center; gap: 18px; padding: 20px; text-align: center; overflow-y: auto; }
.day-badge {
  width: 120px; height: 120px; border-radius: 50%; background: var(--red); border: 6px solid var(--ink);
  box-shadow: 0 7px 0 var(--ink), inset 0 0 0 6px var(--gold); display: flex; align-items: center; justify-content: center;
  font-family: var(--title-font); font-size: 64px; color: var(--paper); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
}
.intro-row { display: flex; align-items: flex-end; gap: 14px; justify-content: center; flex-wrap: wrap; }
.intro-row .elf-wrap { width: 130px; height: 170px; }
.team-line { font-size: 22px; font-weight: bold; }
.team-line span { display: inline-block; margin: 3px; padding: 2px 12px; border-radius: 999px; border: 3px solid var(--ink); color: var(--white); }

/* ---------- Game ---------- */
.game-screen { padding: 0; }
.game-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 30; display: flex; align-items: flex-start; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 0; pointer-events: none;
}
.game-top > * { pointer-events: auto; }
.game-top .bubble { flex: 1; font-size: clamp(18px, 3.2vw, 26px); padding: 8px 14px; }
.game-area { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.turn-flag {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%) scale(0); z-index: 40;
  font-family: var(--title-font); font-size: clamp(32px, 7vw, 60px); color: var(--white); padding: 18px 34px;
  border: 6px solid var(--ink); border-radius: 30px; box-shadow: 0 8px 0 var(--ink); pointer-events: none; text-align: center;
  -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; white-space: nowrap;
}
.turn-flag.show { animation: flag 1.6s cubic-bezier(.3,1.5,.5,1) forwards; }
@keyframes flag { 0% { transform: translate(-50%,-50%) scale(0) rotate(-8deg); } 20% { transform: translate(-50%,-50%) scale(1) rotate(2deg); } 80% { transform: translate(-50%,-50%) scale(1) rotate(0); opacity: 1; } 100% { transform: translate(-50%,-50%) scale(.9); opacity: 0; } }
.praise {
  position: absolute; z-index: 45; pointer-events: none; font-family: var(--title-font); font-size: clamp(28px, 6vw, 48px);
  color: var(--gold); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 3px 4px 0 var(--ink);
  animation: praise 1.3s ease-out forwards; white-space: nowrap; transform: translate(-50%, -50%);
}
@keyframes praise { 0% { opacity: 0; transform: translate(-50%,-30%) scale(.5); } 20% { opacity: 1; transform: translate(-50%,-50%) scale(1.1); } 100% { opacity: 0; transform: translate(-50%,-120%) scale(1); } }

/* ---------- Reward ---------- */
.reward-screen { justify-content: center; gap: 14px; padding: 20px; text-align: center; background-color: var(--night); color: var(--paper); overflow-y: auto; }
.reward-stage { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.item-reveal { width: 150px; height: 150px; animation: item-in 1.2s cubic-bezier(.3,1.4,.5,1) both; filter: drop-shadow(0 0 18px rgba(224,165,38,.7)); }
@keyframes item-in { 0% { transform: scale(0) rotate(-180deg); } 100% { transform: scale(1) rotate(0); } }
.reward-screen .elf-wrap { width: 180px; height: 240px; }
.heroes { font-size: 24px; font-weight: bold; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -30px; width: 14px; height: 14px; animation: confetti-fall linear forwards; }
@keyframes confetti-fall { to { transform: translate(var(--dx), 110vh) rotate(var(--rot)); } }

/* ---------- Modal ---------- */
.modal-back { position: absolute; inset: 0; z-index: 100; background: rgba(27,19,16,.6); display: flex; align-items: center; justify-content: center; padding: 16px; animation: screen-in .2s; }
.modal-back .panel { width: min(640px, 100%); max-height: 90vh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.wardrobe { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.wardrobe .slot { aspect-ratio: 1; border: 3px solid var(--ink); border-radius: 14px; background: var(--paper); display: flex; align-items: center; justify-content: center; position: relative; }
.wardrobe .slot.empty { background: var(--paper-dark); color: rgba(27,19,16,.4); font-family: var(--title-font); font-size: 20px; }
.wardrobe .slot svg { width: 85%; height: 85%; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 22px; font-weight: bold; }
.toggle { width: 96px; height: 56px; border-radius: 999px; border: 4px solid var(--ink); background: var(--paper-dark); position: relative; cursor: pointer; flex: none; }
.toggle::after { content: ""; position: absolute; top: 4px; left: 4px; width: 40px; height: 40px; border-radius: 50%; background: var(--white); border: 3px solid var(--ink); transition: left .15s; }
.toggle.on { background: var(--green); }
.toggle.on::after { left: 44px; }
.test-badge { position: fixed; bottom: 8px; left: 8px; z-index: 950; background: var(--gold); border: 3px solid var(--ink); border-radius: 10px; padding: 2px 10px; font-weight: bold; font-size: 14px; }

/* ---------- Elf animation ---------- */
.elf { width: 100%; height: 100%; overflow: visible; }
.elf .bob { animation: bob 1.1s ease-in-out infinite; transform-origin: 100px 250px; }
@keyframes bob { 0%,100% { transform: scale(1,1); } 50% { transform: scale(1.03,.96) translateY(4px); } }
.elf .wave { animation: wave 1.1s ease-in-out infinite; transform-origin: 128px 150px; }
@keyframes wave { 0%,100% { transform: rotate(0); } 50% { transform: rotate(-22deg); } }
.elf .sway { animation: sway 1.1s ease-in-out infinite; transform-origin: 72px 150px; }
@keyframes sway { 0%,100% { transform: rotate(0); } 50% { transform: rotate(10deg); } }
.elf.cheer .bob { animation: jump .7s cubic-bezier(.3,1.6,.5,1) 3; }
@keyframes jump { 0%,100% { transform: translateY(0) scale(1); } 30% { transform: translateY(-26px) scale(.95,1.06); } 60% { transform: translateY(0) scale(1.08,.92); } }
.elf .blink { animation: blink 4s infinite; transform-origin: 100px 90px; }
@keyframes blink { 0%,94%,100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }

/* Persistent turn chip (whose turn it is stays visible) */
.turn-chip {
  position: absolute; left: 50%; bottom: calc(10px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 35;
  font-family: var(--title-font); font-size: clamp(22px, 4vw, 30px); color: var(--white); padding: 6px 22px;
  border: 4px solid var(--ink); border-radius: 999px; box-shadow: 0 5px 0 var(--ink); pointer-events: none; white-space: nowrap;
  -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; transition: background .3s;
}
.turn-chip.top { bottom: auto; top: calc(92px + env(safe-area-inset-top)); }

/* Adult hold button: fills while held */
.hold { position: relative; overflow: hidden; }
.hold .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(224,165,38,.6); pointer-events: none; }
.hold > span { position: relative; }

/* Lugnt läge (calm mode): no looping motion, no grain, gentle confetti only */
body.calm .elf *, body.calm .door.today .door-body, body.calm .btn.wiggle, body.calm .snowfall i,
body.calm .d2-pal button.hint, body.calm .d3-card.nudge { animation: none !important; }
body.calm .grain { display: none; }
body.calm .snowfall { display: none; }
body.calm .d2-pal button.hint, body.calm .d3-card.nudge { outline: 6px solid #e0a526; outline-offset: 3px; border-radius: 18px; }
body.calm .confetti i { animation-duration: 6s !important; }
body.calm .praise { animation-duration: 2s; }

@media (prefers-reduced-motion: reduce) {
  .elf *, .door.today .door-body, .btn.wiggle, .snowfall i, .confetti i, .praise, .turn-flag.show, .item-reveal { animation: none !important; }
  .turn-flag.show { transform: translate(-50%,-50%); }
  .confetti { display: none; }
}
