:root {
  --bg: #0b281a;
  --bg-deep: #061a11;
  --surface: #12382a;
  --surface-2: #184532;
  --ink: #f3eee4;
  --muted: #b9c5b9;
  --line: rgba(243, 238, 228, .16);
  --gold: #e3bf6e;
  --gold-soft: rgba(227, 191, 110, .35);
  --sage: #8aa989;
  --red: #b4363c;
  --red-deep: #872126;
  --radius: 14px;
  --serif: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg-deep);
}

/* Background picture. To use your own photo: put it into wwwroot/bg/ and change --bg-image below.
   The fixed layer (not background-attachment: fixed) also works on iPhones. */
:root { --bg-image: url("/bg/Kal.jpeg"); }

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(180deg, rgba(7, 30, 20, .62) 0%, rgba(7, 30, 20, .18) 38%, rgba(7, 30, 20, .1) 70%, rgba(7, 30, 20, .5) 100%),
    var(--bg-image) center bottom / cover no-repeat,
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
}

#snow {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.page {
  position: relative;
  z-index: 1;
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px 56px;
}

/* ---------- header ---------- */
.hero { text-align: center; padding: 18px 0 6px; }

.hero .eyebrow {
  letter-spacing: .32em;
  text-transform: uppercase;
  font-size: .72rem;
  color: var(--gold);
  margin: 0 0 6px;
}

.hero h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2rem, 7vw, 3.1rem);
  margin: 0;
  line-height: 1.1;
}

.hero .sub {
  margin: 10px auto 0;
  max-width: 34rem;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.5;
}

.hero .logo { display: block; margin: 0 auto 14px; width: 84px; height: 84px; filter: drop-shadow(0 6px 14px rgba(0,0,0,.45)); }
.hero .star { color: var(--gold); font-size: 1.4rem; display: block; margin-bottom: 4px; }

.progress {
  margin: 16px auto 0;
  max-width: 320px;
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .1);
  overflow: hidden;
}
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), #f6dd9c); border-radius: 99px; transition: width .6s ease; }
.progress-label { margin: 6px 0 0; font-size: .82rem; color: var(--muted); text-align: center; }

/* ---------- test mode banner ---------- */
.banner {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  background: #4a3a10;
  color: #ffe7a3;
  font-size: .9rem;
  border-bottom: 1px solid rgba(255, 231, 163, .3);
}
.banner a { color: #fff; }

/* ---------- grid of doors ---------- */
/* The doors are shuffled and slightly different in size, tilt and height, like on a hand-made calendar.
   The values per door (--f size factor, --ar shape, --rot tilt, --dy offset) are set by app.js. */
.grid {
  --cols: 3;
  --gap: 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 20px var(--gap);
  margin-top: 26px;
  padding: 6px 2px 14px;
  perspective: 1200px;
}
@media (min-width: 560px) { .grid { --cols: 4; --gap: 18px; } }
@media (min-width: 800px) { .grid { --cols: 6; } }

.tile {
  flex: 0 0 calc((100% - (var(--cols) - 1) * var(--gap)) / var(--cols) * var(--f, 1));
  position: relative;
  aspect-ratio: var(--ar, 4 / 5);
  rotate: var(--rot, 0deg);
  translate: 0 var(--dy, 0px);
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.tile .inside {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 60%, #ffe9a8 0%, #f1c15c 45%, #9a6a1c 100%);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, .45);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #5a3a00;
  font-size: 1.6rem;
  /* The doors are see-through, so what is behind them stays hidden until the door opens. */
  opacity: 0;
  transition: opacity .35s ease .2s;
}
.tile.opening .inside,
.tile.opened .inside { opacity: 1; }
.tile.opened .inside { transition-duration: 0s; transition-delay: 0s; }
.tile .inside img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .inside .glyph { font-size: 1.8rem; }

.tile .door {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  /* Frosted glass: the background shines through, a light blur keeps the number readable. */
  background: linear-gradient(155deg, rgba(170, 44, 52, .74) 0%, rgba(120, 28, 34, .7) 100%);
  -webkit-backdrop-filter: blur(3px) saturate(1.15);
  backdrop-filter: blur(3px) saturate(1.15);
  border: 2px solid var(--gold-soft);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .3), inset 0 0 0 1px rgba(255, 255, 255, .06);
  transform-origin: left center;
  transition: transform .7s cubic-bezier(.3, .8, .3, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  backface-visibility: hidden;
}
.tile .door::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 6px;
  border: 1px solid rgba(227, 191, 110, .4);
  pointer-events: none;
}

/* Numbers: bright, bold and with a dark halo, so they stay readable on any background picture. */
.tile .num { font-family: var(--serif); font-size: clamp(1.7rem, 6vw, 2.3rem); font-weight: 700; color: #f6dd9c; text-shadow: 0 1px 2px rgba(0, 0, 0, .9), 0 0 10px rgba(0, 0, 0, .65), 0 0 3px rgba(0, 0, 0, .8); line-height: 1; }
.tile .hint { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: rgba(243, 238, 228, .92); text-shadow: 0 1px 2px rgba(0, 0, 0, .9); }
.tile .badge { position: absolute; top: 6px; right: 8px; font-size: .9rem; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5)); }

.tile.locked .door { background: linear-gradient(155deg, rgba(38, 68, 54, .66) 0%, rgba(12, 34, 24, .7) 100%); border-color: rgba(227, 191, 110, .28); box-shadow: 0 4px 12px rgba(0, 0, 0, .25); }
.tile.locked .num { color: rgba(243, 238, 228, .92); }

.tile.available .door { animation: pulse 2.6s ease-in-out infinite; }
.tile.today .door { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(227, 191, 110, .35), 0 0 26px rgba(227, 191, 110, .45); }

.tile.opened .door,
.tile.opening .door { transform: rotateY(-112deg); animation: none; }
.tile.opened .door { transition-duration: 0s; }

.tile:not(.locked):hover .door { transform: rotateY(-18deg); }
.tile.opened:hover .door { transform: rotateY(-112deg); }

.tile:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; border-radius: 12px; }

.tile.shake { animation: shake .45s; }
.tile.pointed .door { animation: point 1.1s ease-in-out 3; border-color: var(--gold); }
@keyframes point { 0%, 100% { transform: scale(1); box-shadow: 0 6px 16px rgba(0, 0, 0, .4); } 50% { transform: scale(1.12); box-shadow: 0 0 34px rgba(227, 191, 110, .9); } }
.find-today { margin: 10px 0 0; }

@keyframes pulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.18); } }
@keyframes shake { 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 30px);
  opacity: 0;
  background: var(--surface-2);
  border: 1px solid var(--gold-soft);
  color: var(--ink);
  padding: 12px 18px;
  border-radius: 99px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  transition: opacity .25s, transform .25s;
  z-index: 30;
  max-width: calc(100% - 32px);
  text-align: center;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  background: rgba(3, 12, 8, .86);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.overlay.show { display: flex; animation: fade .3s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  position: relative;
  width: 100%;
  max-width: 640px;
  margin: auto;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--gold-soft);
  border-radius: 18px;
  padding: 22px 18px 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  animation: rise .45s cubic-bezier(.2, .9, .3, 1);
}
@keyframes rise { from { transform: translateY(24px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }

.card h2 { font-family: var(--serif); font-size: 1.7rem; margin: 0 0 4px; font-weight: 600; text-align: center; }
.card .kicker { text-align: center; color: var(--gold); letter-spacing: .26em; text-transform: uppercase; font-size: .72rem; margin: 0 0 6px; }
.card .close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .25);
  color: var(--ink);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
}
.card .close:hover { background: rgba(0, 0, 0, .45); }

.media { margin: 16px auto 4px; border-radius: 12px; overflow: hidden; background: #000; text-align: center; }
.media img, .media video { display: block; width: 100%; max-height: 70vh; object-fit: contain; background: #000; }
.media audio { width: 100%; display: block; background: var(--surface); }
.media.audio { background: transparent; padding: 8px 0; }

.text { white-space: pre-wrap; line-height: 1.65; font-size: 1.08rem; margin: 18px 4px 6px; text-align: center; font-family: var(--serif); }

.note { text-align: center; color: var(--muted); line-height: 1.55; margin: 14px 0; }

.react { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.react-row { display: flex; gap: 10px; align-items: stretch; }
.react textarea { flex: 1; min-height: 64px; }

.heart {
  width: 56px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .2);
  color: var(--muted);
  font-size: 1.7rem;
  cursor: pointer;
  transition: transform .15s, color .15s, background .15s;
}
.heart:active { transform: scale(.9); }
.heart.on { color: #ff6b78; background: rgba(180, 54, 60, .25); border-color: rgba(255, 107, 120, .5); }
.heart.pop { animation: pop .4s; }
@keyframes pop { 40% { transform: scale(1.35); } }

.status { min-height: 1.3em; font-size: .85rem; color: var(--sage); margin: 6px 2px 0; }

/* ---------- forms and buttons (shared with the admin page) ---------- */
input[type="text"], input[type="password"], input[type="date"], textarea, select {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: rgba(0, 0, 0, .25);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  color: #2a1c00;
  background: linear-gradient(180deg, #f2d588, #d9b25a);
  border: 0;
  border-radius: 10px;
  padding: 12px 20px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { color: var(--ink); background: rgba(255, 255, 255, .08); border: 1px solid var(--line); font-weight: 500; }
.btn.danger { color: #ffd9dc; background: rgba(180, 54, 60, .3); border: 1px solid rgba(255, 107, 120, .4); font-weight: 500; }
.btn.small { padding: 8px 12px; font-size: .9rem; }

.puzzle { margin-top: 14px; text-align: center; }
.puzzle .q { font-family: var(--serif); font-size: 1.25rem; line-height: 1.5; margin: 10px 0 14px; }
.puzzle form { display: flex; gap: 8px; }
.puzzle .feedback { min-height: 1.5em; margin: 10px 0 0; color: var(--gold); }
.puzzle .extra { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; align-items: center; }

.recap-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.recap-grid button {
  position: relative; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--surface); color: var(--ink); cursor: pointer; padding: 0; font: inherit;
}
.recap-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.recap-grid .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 5px; font-size: .74rem; background: linear-gradient(transparent, rgba(0, 0, 0, .75)); text-align: left; }
.recap-grid .glyph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; }

.private { text-align: center; margin: 18vh auto 0; max-width: 28rem; padding: 0 16px; position: relative; z-index: 1; }
.private h1 { font-family: var(--serif); font-weight: 600; }
.private p { color: var(--muted); line-height: 1.6; }

.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- install and reminder card ---------- */
.extras { margin: 30px auto 0; max-width: 520px; text-align: center; color: var(--muted); font-size: .92rem; line-height: 1.55; padding: 14px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }
.extras p { margin: 8px 0; }
.msg { min-height: 1.2em; font-size: .88rem; }
.msg.error { color: #ff9aa3; }
.msg.okay { color: #bfe3be; }

/* ---------- Christmas picture (one piece per opened door) ---------- */
.puzzle-section { position: relative; z-index: 1; margin: 34px auto 0; max-width: 560px; padding: 0 16px; text-align: center; }
.puzzle-section h2 { font-family: var(--serif); font-weight: 600; font-size: 1.5rem; margin: 0 0 6px; text-shadow: 0 1px 3px rgba(0, 0, 0, .7); }
.puzzle-section .lead { color: rgba(243, 238, 228, .92); line-height: 1.55; margin: 0 0 14px; text-shadow: 0 1px 2px rgba(0, 0, 0, .8); }
.picture-board {
  display: grid; grid-template-columns: repeat(var(--pc, 6), minmax(0, 1fr));
  border: 2px solid var(--gold-soft); border-radius: 12px; overflow: hidden; background: rgba(6, 26, 17, .55);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .4);
}
.picture-board .cell { aspect-ratio: 1; position: relative; overflow: hidden; border: 0; padding: 0; margin: 0; background: transparent; }
.picture-board .cell.covered {
  background: linear-gradient(155deg, rgba(38, 68, 54, .72), rgba(12, 34, 24, .78));
  box-shadow: inset 0 0 0 1px rgba(227, 191, 110, .18);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.picture-board .cell.covered::after { content: "✦"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: rgba(227, 191, 110, .35); font-size: 1rem; }
.picture-board .cell img { display: block; width: 100%; height: 100%; object-fit: cover; }
.picture-board .cell.fresh img { animation: piece-in 1.1s cubic-bezier(.2, .8, .2, 1) both; }
.picture-board .cell.fresh { z-index: 1; animation: piece-glow 1.6s ease-out; }
@keyframes piece-in { from { opacity: 0; transform: scale(1.6) rotate(-6deg); filter: brightness(1.8); } to { opacity: 1; transform: none; filter: none; } }
@keyframes piece-glow { 0% { box-shadow: 0 0 0 0 rgba(227, 191, 110, .9); } 100% { box-shadow: 0 0 0 18px rgba(227, 191, 110, 0); } }
.puzzle-section .count { color: var(--muted); font-size: .88rem; margin: 10px 0 0; }
.puzzle-section .btn { margin-top: 10px; }

.piece-reveal { margin: 18px auto 4px; text-align: center; }
.piece-reveal .piece { width: 96px; height: 96px; margin: 0 auto 8px; border: 2px solid var(--gold-soft); border-radius: 10px; overflow: hidden; box-shadow: 0 6px 18px rgba(0, 0, 0, .4); animation: piece-in 1s cubic-bezier(.2, .8, .2, 1) both; }
.piece-reveal .piece img { display: block; width: 100%; height: 100%; object-fit: cover; }
.piece-reveal p { margin: 4px 0; }
.full-picture { margin: 16px auto 4px; border-radius: 12px; overflow: hidden; border: 2px solid var(--gold-soft); }
.full-picture img { display: block; width: 100%; height: auto; }
