:root {
  --night: #0d1526;
  --night-2: #16223a;
  --gold: #e9c46a;
  --gold-2: #f6dc94;
  --red: #8f1d1d;
  --red-2: #b02a2a;
  --paper: #f8f1e4;
  --paper-2: #efe3cc;
  --ink: #2b2118;
  --ink-soft: #5d4c3c;
  --green: #1f4a32;
  --fs: 19px;
  --head: "Cormorant Garamond", Georgia, serif;
  --body: "Nunito Sans", system-ui, sans-serif;
  --hand: "Caveat", "Segoe Print", cursive;
}
body.big { --fs: 22px; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--night);
  color: var(--paper);
  font-family: var(--body);
  font-size: var(--fs);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }

.backdrop {
  position: fixed; inset: -40px;
  background: url(../scene/night.webp) center / cover no-repeat;
  filter: blur(28px) brightness(.55) saturate(1.1);
  z-index: 0;
}

/* ---------------------------------------------------------------- login */
.login { position: fixed; inset: 0; display: grid; place-items: center; z-index: 5; padding: 16px; }
.login-card {
  width: min(420px, 100%); text-align: center; padding: 36px 28px 28px;
  background: rgba(13, 21, 38, .82); border: 1px solid rgba(233, 196, 106, .35);
  border-radius: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
  backdrop-filter: blur(8px);
}
.login-star { color: var(--gold); font-size: 34px; }
.login-card h1 { font-family: var(--head); font-size: 44px; margin: 4px 0 6px; font-weight: 600; }
.login-card p { margin: 0 0 18px; opacity: .85; }
#pin {
  width: 100%; font-size: 34px; text-align: center; letter-spacing: .4em;
  padding: 12px; border-radius: 14px; border: 1px solid rgba(233,196,106,.5);
  background: rgba(255,255,255,.08); color: #fff; margin-bottom: 16px;
}
.login-err { color: #ffb4a8; min-height: 1.4em; margin: 12px 0 0 !important; }
.shake { animation: shake .45s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }

.btn-gold {
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: #3a2a08; border: 0; border-radius: 999px; padding: 14px 28px;
  font-weight: 700; font-size: 19px; box-shadow: 0 6px 18px rgba(233,196,106,.35);
}
.btn-gold:active { transform: translateY(1px); }
.btn-quiet { background: none; border: 1px solid rgba(43,33,24,.25); color: var(--ink-soft); border-radius: 999px; padding: 10px 18px; }

/* ---------------------------------------------------------------- stage */
.stage {
  position: fixed; inset: 0; z-index: 1;
  overflow: auto; display: flex;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.stage::-webkit-scrollbar { display: none; }
.sizer { margin: auto; position: relative; flex: none; }
.scene { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; -webkit-user-select: none; }
.scene-img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; transition: filter 2s; }
.tint { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 2s; }

/* dagbilledet glider ind og ud over natbilledet (--day sættes fra solens tider) */
body { --day: 0; }
.scene-day, .leaf .ld { opacity: var(--day); transition: opacity 4s ease; }
body[data-phase="dawn"] .tint { opacity: 1; background: linear-gradient(180deg, rgba(255,150,170,.38), rgba(255,200,150,.14) 40%, transparent 65%); mix-blend-mode: screen; }
body[data-phase="dusk"] .tint { opacity: 1; background: linear-gradient(180deg, rgba(90,70,170,.38), rgba(200,110,120,.16) 45%, transparent 70%); mix-blend-mode: screen; }

/* titel, menu og stjerner – ligger i scenen og skalerer med den */
.scene-title { position: absolute; left: 0; right: 0; top: 22px; text-align: center; pointer-events: none; }
.scene-title h1 {
  margin: 0; font-family: var(--head); font-weight: 600; font-size: 76px; line-height: 1;
  color: #fff7e6; text-shadow: 0 2px 4px rgba(0,0,0,.45), 0 0 26px rgba(255,214,120,.45);
}
.scene-title h1 span { color: var(--gold-2); }
.scene-title p { margin: 6px 0 0; font-size: 25px; color: #fff3dc; text-shadow: 0 1px 6px rgba(0,0,0,.7); }
.scene-nav { position: absolute; left: 0; right: 0; top: 150px; display: flex; justify-content: center; gap: 12px; pointer-events: none; }
.scene-nav > * { pointer-events: auto; }
.scene-nav button {
  border: 1.5px solid rgba(233,196,106,.55); background: rgba(13,21,38,.72); color: #fff3dc;
  border-radius: 999px; padding: 9px 22px; font-size: 21px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,.35); backdrop-filter: blur(4px);
}
.scene-nav button.on { background: linear-gradient(180deg, #a82626, #7d1818); border-color: rgba(246,220,148,.8); }
.scene-nav button:hover { border-color: var(--gold-2); }
body.narrow .scene-nav, body.narrow .scene-title { display: none; }
.mtitle { display: none; }
body.narrow .mtitle {
  display: block; position: fixed; left: 0; right: 0; top: max(28px, env(safe-area-inset-top)); z-index: 3;
  text-align: center; pointer-events: none;
}
.mtitle h1 { margin: 0; font-family: var(--head); font-weight: 600; font-size: 40px; color: #fff7e6; text-shadow: 0 2px 4px rgba(0,0,0,.5), 0 0 20px rgba(255,214,120,.45); }
.mtitle h1 span { color: var(--gold-2); }

/* ---------------------------------------------------------------- doors */
.door {
  position: absolute; padding: 0; border: 0; background: none;
  perspective: 700px; border-radius: 6px; outline: none;
}
.door .inside {
  position: absolute; inset: 6% 7% 4%; border-radius: 4px;
  background: radial-gradient(circle at 50% 55%, #fff3c4 0%, #f2b84b 35%, #8a3d10 100%);
  background-size: cover; background-position: center;
  box-shadow: inset 0 0 18px rgba(0,0,0,.55);
  opacity: 0; transition: opacity .4s;
}
.door .inside .spark { position: absolute; inset: 0; display: grid; place-items: center; font-size: 30px; color: #fff8dc; text-shadow: 0 0 12px #ffd76a; }
.door .leaf {
  position: absolute; inset: 0;
  transform-origin: 0% 50%;
  transition: transform 1.1s cubic-bezier(.3,.9,.3,1), box-shadow 1.1s;
  border-radius: 4px;
}
.leaf i { position: absolute; inset: 0; background-repeat: no-repeat; border-radius: 4px; }
.leaf .num {
  position: absolute; left: 0; right: 0; top: 30%; text-align: center;
  font-family: var(--head); font-weight: 700; font-size: 44px; line-height: 1;
  color: #fff1cc; text-shadow: 0 2px 3px rgba(60,10,10,.8), 0 0 12px rgba(255,210,120,.6);
}
.door.is-open .inside { opacity: 1; }
.door.is-open .leaf { transform: rotateY(-72deg); box-shadow: 12px 0 18px rgba(0,0,0,.35); }
.door.unlocked:not(.is-open) .leaf { filter: brightness(1.04); }
.door.today:not(.is-open)::after {
  content: ""; position: absolute; inset: -6px; border-radius: 10px; pointer-events: none;
  box-shadow: 0 0 0 3px rgba(246,220,148,.9), 0 0 28px 8px rgba(246,220,148,.55);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 3px rgba(246,220,148,.5), 0 0 14px 4px rgba(246,220,148,.25); } }
.door.wiggle .leaf { animation: wiggle .5s; }
@keyframes wiggle { 25% { transform: rotateY(-10deg); } 60% { transform: rotateY(-4deg); } }
.door.d25.is-open .leaf { transform: rotateY(-80deg); }
.door.d25.today:not(.is-open)::after { box-shadow: 0 0 0 4px #ffe9a8, 0 0 50px 16px rgba(255,215,120,.7); }
.door:focus-visible { outline: 3px solid var(--gold-2); outline-offset: 3px; }

.stars-pill {
  display: flex; align-items: center; gap: 8px; padding: 0 18px;
  background: rgba(13,21,38,.72); border: 1.5px solid rgba(233,196,106,.55); border-radius: 999px;
  color: #fff3dc; font-size: 21px; font-weight: 700; box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.stars-pill .row { color: var(--gold); letter-spacing: 1px; font-size: 18px; }
.stars-pill .row .off { color: rgba(255,255,255,.22); }

/* røg fra skorstenene */
.puff {
  position: absolute; width: 84px; height: 84px; margin: -42px 0 0 -42px; border-radius: 50%;
  background: radial-gradient(circle, rgba(var(--smoke),1), rgba(var(--smoke),.6) 40%, rgba(var(--smoke),0) 70%);
  opacity: 0; pointer-events: none; animation: puff 8s linear infinite;
}
body { --smoke: 222,226,236; }
body[data-phase="day"], body[data-phase="dawn"] { --smoke: 138,144,160; }
@keyframes puff {
  0% { transform: translate(0,0) scale(.6); opacity: 0; }
  10% { opacity: .9; }
  55% { opacity: .55; }
  100% { transform: translate(var(--drift, 70px), -170px) scale(2.8); opacity: 0; }
}

/* sparkles */
.sparkle { position: fixed; width: 10px; height: 10px; pointer-events: none; z-index: 30; color: #ffe08a; font-size: 16px; line-height: 10px; animation: fly 1s ease-out forwards; text-shadow: 0 0 8px #ffd76a; }
@keyframes fly { to { transform: translate(var(--dx), var(--dy)) scale(.4) rotate(160deg); opacity: 0; } }

/* sky effects */
.snow, .sky { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
.shooting {
  position: absolute; width: 140px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, rgba(255,255,255,0), #fff);
  transform: rotate(-22deg); animation: shoot 1.4s ease-out forwards; opacity: 0;
}
@keyframes shoot { 10% { opacity: 1; } 100% { transform: rotate(-22deg) translateX(-420px); opacity: 0; } }
body.golden::after { content: ""; position: fixed; inset: 0; z-index: 25; pointer-events: none; background: radial-gradient(circle, rgba(255,226,140,.55), transparent 70%); animation: flash 1.8s forwards; }
@keyframes flash { to { opacity: 0; } }

/* ---------------------------------------------------------------- toast / banner */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 30px);
  z-index: 40; max-width: min(560px, calc(100vw - 32px)); padding: 14px 22px;
  background: rgba(248,241,228,.96); color: var(--ink); border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); text-align: center; line-height: 1.4;
  opacity: 0; pointer-events: none; transition: opacity .4s, transform .4s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.preview-banner {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%); z-index: 45;
  background: #6b1a1a; color: #fff; font-size: 14px; padding: 4px 14px; border-radius: 0 0 10px 10px;
}

/* ---------------------------------------------------------------- sheets */
.sheet {
  position: fixed; inset: 0; z-index: 20; display: flex; padding: 16px;
  background: rgba(5, 9, 18, .62); backdrop-filter: blur(3px);
  overflow-y: auto; animation: fade .3s;
}
@keyframes fade { from { opacity: 0; } }
.card {
  position: relative; margin: auto; width: min(680px, 100%);
  background: var(--paper);
  background-image: radial-gradient(circle at 20% 0%, rgba(255,255,255,.7), transparent 40%), linear-gradient(180deg, var(--paper), var(--paper-2));
  color: var(--ink); border-radius: 22px; padding: 30px 30px 26px;
  box-shadow: 0 30px 80px rgba(0,0,0,.55), inset 0 0 0 6px rgba(143,29,29,.12), inset 0 0 0 7px rgba(233,196,106,.5);
  animation: cardIn .55s cubic-bezier(.2,.9,.3,1.2);
  line-height: 1.55;
}
.card-small { width: min(460px, 100%); }
@keyframes cardIn { from { transform: translateY(40px) scale(.94); opacity: 0; } }
.card .x, .book .x {
  position: absolute; top: 12px; right: 12px; width: 46px; height: 46px; border-radius: 50%;
  border: 0; background: rgba(43,33,24,.08); color: var(--ink); font-size: 20px;
}
.card-kicker { font-size: 15px; letter-spacing: .08em; text-transform: uppercase; color: var(--red); font-weight: 700; margin: 0 50px 4px 0; }
.card-title { font-family: var(--head); font-size: 2.1em; line-height: 1.1; margin: 0 50px 6px 0; font-weight: 600; color: var(--ink); }
.card-from { font-family: var(--hand); font-size: 1.35em; color: var(--red); margin: 0 0 14px; }
.card-body { white-space: pre-wrap; margin: 14px 0 6px; }
.gallery { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 10px -6px 6px; padding: 6px; }
.gallery figure { margin: 0; flex: 0 0 100%; scroll-snap-align: center; }
.gallery img, .gallery video {
  width: 100%; max-height: 60vh; object-fit: contain; display: block; border-radius: 10px;
  background: #1b1410; box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.gallery img { cursor: zoom-in; }
.gallery figcaption { font-family: var(--hand); font-size: 1.2em; color: var(--ink-soft); text-align: center; margin-top: 6px; }
.gallery-dots { text-align: center; color: var(--ink-soft); font-size: 14px; }
audio { width: 100%; margin: 8px 0; }

.reply-box { margin-top: 22px; padding-top: 18px; border-top: 1px dashed rgba(43,33,24,.3); }
.reply-box h3 { font-family: var(--head); font-size: 1.5em; margin: 0 0 4px; }
.reply-box .q { margin: 0 0 12px; color: var(--ink-soft); }
.who { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.who button { border: 1px solid rgba(43,33,24,.3); background: #fff8ec; color: var(--ink); border-radius: 999px; padding: 8px 18px; }
.who button[aria-pressed="true"] { background: var(--red); color: #fff; border-color: var(--red); }
.reply-box textarea {
  width: 100%; min-height: 110px; font: inherit; color: var(--ink); padding: 12px 14px;
  border-radius: 12px; border: 1px solid rgba(43,33,24,.3); background: #fffdf8; resize: vertical;
}
.reply-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.photo-btn { border: 1px dashed rgba(43,33,24,.4); background: transparent; color: var(--ink); border-radius: 999px; padding: 10px 16px; }
.photo-name { font-size: 15px; color: var(--ink-soft); }
.replies { margin-top: 16px; display: grid; gap: 12px; }
.reply {
  background: #fffaf0; border-radius: 10px; padding: 12px 16px; box-shadow: 0 2px 8px rgba(0,0,0,.08);
  font-family: var(--hand); font-size: 1.45em; line-height: 1.25; transform: rotate(-.4deg);
}
.reply:nth-child(even) { transform: rotate(.5deg); }
.reply .meta { font-family: var(--body); font-size: 13px; color: var(--ink-soft); margin-bottom: 2px; }
.reply img { max-width: 100%; border-radius: 6px; margin-top: 8px; display: block; }
.card-close { display: flex; justify-content: center; margin-top: 22px; }

.row-toggle, .row-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.row-toggle input { width: 26px; height: 26px; accent-color: var(--red); }
.row-field input, .row-field select { font: inherit; font-size: 16px; padding: 6px 8px; border-radius: 8px; border: 1px solid rgba(43,33,24,.3); }
.muted { color: var(--ink-soft); font-size: 15px; }
.link { color: var(--red); }
hr { border: 0; border-top: 1px solid rgba(43,33,24,.15); margin: 12px 0; }

/* ---------------------------------------------------------------- book */
.sheet-book { padding: 0; }
.book {
  position: relative; margin: auto; width: min(900px, 100%); min-height: 100%;
  background: #f4ead6;
  background-image:
    radial-gradient(circle at 10% 10%, rgba(255,255,255,.6), transparent 30%),
    repeating-linear-gradient(0deg, rgba(120,90,50,.035) 0 2px, transparent 2px 4px);
  color: var(--ink); padding: 0 0 40px;
  box-shadow: 0 0 80px rgba(0,0,0,.6);
}
.book-head {
  position: sticky; top: 0; z-index: 2; padding: 22px 70px 14px 28px;
  background: linear-gradient(180deg, #f4ead6 75%, rgba(244,234,214,0));
}
.book-head h2 { font-family: var(--head); font-size: 2.3em; margin: 0; font-weight: 600; color: var(--red); }
.book-body { padding: 0 28px; display: grid; gap: 34px; }
.page { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 22px; align-items: start; cursor: pointer; }
.page:nth-child(even) .polaroid { order: 2; }
.page-date { font-size: 14px; letter-spacing: .08em; text-transform: uppercase; color: var(--red); font-weight: 700; }
.page h3 { font-family: var(--head); font-size: 1.7em; margin: 2px 0 6px; line-height: 1.1; }
.page p { margin: 0; color: var(--ink-soft); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.page .reply { font-size: 1.25em; margin-top: 10px; }
.polaroid { background: #fff; padding: 10px 10px 34px; box-shadow: 0 6px 18px rgba(0,0,0,.18); transform: rotate(-1.5deg); position: relative; }
.page:nth-child(even) .polaroid { transform: rotate(1.4deg); }
.polaroid::before { content: ""; position: absolute; top: -10px; left: 50%; width: 90px; height: 24px; transform: translateX(-50%) rotate(-3deg); background: rgba(233,196,106,.55); }
.polaroid img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.polaroid .noimg { aspect-ratio: 4/3; display: grid; place-items: center; font-size: 54px; background: linear-gradient(135deg, #8f1d1d, #5d1212); color: var(--gold-2); font-family: var(--head); }
.book-empty { text-align: center; padding: 60px 20px; color: var(--ink-soft); font-family: var(--hand); font-size: 1.6em; }
@media (max-width: 620px) {
  .page { grid-template-columns: 1fr; }
  .page:nth-child(even) .polaroid { order: 0; }
  .card { padding: 26px 18px 22px; }
  .book-body { padding: 0 16px; }
  .book-head { padding: 18px 64px 12px 16px; }
}

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 100vw; max-height: 100vh; object-fit: contain; }

/* ---------------------------------------------------------------- telefon på højkant */
.mnav { display: none; }
body.narrow .mnav {
  display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 6px 6px max(6px, env(safe-area-inset-bottom));
  background: rgba(13,21,38,.9); backdrop-filter: blur(6px);
  border-top: 1px solid rgba(233,196,106,.35);
}
.mnav button {
  flex: 1; background: none; border: 0; color: var(--paper); font-size: 22px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0;
}
.mnav button span { font-size: 12px; opacity: .85; }
.mnav button b { font-size: 16px; color: var(--gold-2); line-height: 26px; }
body.narrow .toast { bottom: calc(78px + env(safe-area-inset-bottom)); }
body.narrow .preview-banner { font-size: 12px; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .door .leaf { transition-duration: .2s; }
  .door.today:not(.is-open)::after { animation: none; }
}
