:root {
  --night: #0d1b2f;
  --night-2: #16294a;
  --red: #b3202a;
  --red-dark: #7d1018;
  --green: #1f5f3f;
  --green-dark: #123d28;
  --gold: #e3b54a;
  --gold-light: #f7dc8b;
  --cream: #fbf3e2;
  --ink: #2b1d14;
  --muted: #7a6a5c;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
html { background: #070f1c; }

body {
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--cream);
  background: radial-gradient(ellipse at top, var(--night-2) 0%, var(--night) 60%, #070f1c 100%) fixed;
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--gold-light); }

h1, h2, .festive {
  font-family: 'Mountains of Christmas', 'Georgia', serif;
  font-weight: 700;
  letter-spacing: 0.5px;
}

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

.page {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.brand {
  font-family: 'Mountains of Christmas', serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--gold-light);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.topbar .who { color: #c9d3e6; font-size: 0.9rem; }

/* ---------- Buttons & forms ---------- */
.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: var(--red);
  color: #fff;
  box-shadow: 0 3px 0 var(--red-dark);
  transition: transform 0.1s, filter 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--red-dark); }
.btn.green { background: var(--green); box-shadow: 0 3px 0 var(--green-dark); }
.btn.gold { background: var(--gold); color: var(--ink); box-shadow: 0 3px 0 #a07a22; }
.btn.ghost { background: transparent; color: var(--cream); box-shadow: inset 0 0 0 2px rgba(255,255,255,0.35); }
.btn.small { padding: 6px 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.6; cursor: wait; }

.card {
  background: var(--cream);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card h2 { margin-top: 0; color: var(--red); font-size: 2rem; }

label { display: block; font-weight: 700; margin: 14px 0 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 2px solid #e2d4bb;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
input:focus, textarea:focus { outline: none; border-color: var(--gold); }
textarea { min-height: 140px; resize: vertical; }
.hint { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }
.error { color: #b3202a; font-weight: 700; min-height: 1.4em; margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- Landing ---------- */
.hero {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 32px;
  align-items: center;
  margin-top: 24px;
}
.hero h1 { font-size: clamp(2.6rem, 6vw, 4.2rem); line-height: 1.05; margin: 0 0 16px; color: var(--gold-light); text-shadow: 0 3px 0 rgba(0,0,0,0.3); }
.hero p { font-size: 1.15rem; color: #dbe3f2; }
.hero ul { padding-left: 1.2em; color: #dbe3f2; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tabs button {
  flex: 1; border: 0; padding: 10px; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer;
  background: #efe3cc; color: var(--muted);
}
.tabs button.active { background: var(--red); color: #fff; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } }

/* ---------- Dashboard ---------- */
.cal-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.cal-item { display: flex; flex-direction: column; gap: 10px; }
.cal-item h3 { margin: 0; font-size: 1.3rem; color: var(--red); }
.progress { height: 10px; background: #eadcc2; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--green), #3c9a68); }

/* ---------- Editor ---------- */
.editor-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
@media (max-width: 800px) { .editor-grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 480px) { .editor-grid { grid-template-columns: repeat(3, 1fr); } }
.edit-tile {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 3px dashed rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.06);
  color: var(--cream);
  font: inherit;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  position: relative; overflow: hidden;
  transition: transform 0.15s, border-color 0.2s;
}
.edit-tile:hover { transform: translateY(-3px); border-color: var(--gold); }
.edit-tile .n { font-family: 'Mountains of Christmas', serif; font-size: 2.2rem; font-weight: 700; line-height: 1; z-index: 1; text-shadow: 0 2px 4px rgba(0,0,0,0.6); }
.edit-tile .s { font-size: 0.75rem; opacity: 0.9; z-index: 1; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.edit-tile.filled { border-style: solid; border-color: var(--gold); background: var(--green); }
.edit-tile .thumb { position: absolute; inset: 0; background-size: cover; background-position: center; opacity: 0.45; }

.share-box { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.share-box input { flex: 1; min-width: 220px; font-family: ui-monospace, monospace; font-size: 0.9rem; }

.settings { display: grid; grid-template-columns: 2fr 2fr 1fr; gap: 0 14px; }
@media (max-width: 700px) { .settings { grid-template-columns: 1fr; } }

.media-preview { margin-top: 10px; }
.media-preview img, .media-preview video { max-width: 100%; max-height: 260px; border-radius: 10px; display: block; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 10, 20, 0.75);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
.modal-backdrop.show { opacity: 1; pointer-events: auto; }
.modal {
  position: relative;
  width: min(640px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--cream);
  color: var(--ink);
  border-radius: 18px;
  padding: 28px 24px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  border: 6px solid var(--gold);
  transform: scale(0.85) translateY(20px);
  transition: transform 0.35s cubic-bezier(.2,1.4,.4,1);
}
.modal-backdrop.show .modal { transform: none; }
.modal .close {
  position: absolute; top: 8px; right: 10px;
  border: 0; background: none; font-size: 1.8rem; cursor: pointer; color: var(--muted); line-height: 1;
}
.modal .day-badge {
  display: inline-block; background: var(--red); color: #fff; border-radius: 999px; padding: 2px 14px;
  font-family: 'Mountains of Christmas', serif; font-weight: 700; font-size: 1.2rem;
}
.modal h2 { color: var(--red); margin: 8px 0 12px; font-size: 2.2rem; line-height: 1.1; }
.modal .media img, .modal .media video { width: 100%; max-height: 65vh; object-fit: contain; border-radius: 12px; background: #000; display: block; }
.modal .message { white-space: pre-wrap; font-size: 1.1rem; margin-top: 14px; }
.modal .message:empty { display: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 60;
  transform: translate(-50%, 30px);
  background: var(--cream); color: var(--ink);
  padding: 12px 20px; border-radius: 999px; font-weight: 700;
  box-shadow: var(--shadow);
  opacity: 0; transition: all 0.3s; pointer-events: none;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* =================================================================
   The Advent calendar
   ================================================================= */
.calendar-header { text-align: center; margin: 8px 0 24px; }
.calendar-header h1 {
  font-size: clamp(2.4rem, 7vw, 4.4rem);
  margin: 0;
  color: var(--gold-light);
  text-shadow: 0 3px 0 #7d1018, 0 6px 18px rgba(0,0,0,0.5);
  line-height: 1.05;
}
.calendar-header p { margin: 8px 0 0; font-size: 1.15rem; color: #dbe3f2; }

.preview-banner {
  background: var(--gold); color: var(--ink); text-align: center; padding: 8px 12px; border-radius: 10px;
  font-weight: 700; margin-bottom: 16px;
}

/* The cardboard board with a wooden/golden frame */
.board {
  position: relative;
  padding: clamp(14px, 3vw, 30px);
  border-radius: 22px;
  background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,0.10) 0 2px, transparent 3px) 0 0 / 46px 46px,
    radial-gradient(circle at 70% 60%, rgba(255,255,255,0.08) 0 1.5px, transparent 2.5px) 0 0 / 38px 38px,
    linear-gradient(160deg, #a01c26 0%, #7a1019 55%, #5e0b13 100%);
  border: 10px solid transparent;
  border-image: linear-gradient(135deg, #f7dc8b, #b98a2b 30%, #f7dc8b 50%, #a07a22 75%, #f7dc8b) 1;
  box-shadow: 0 25px 60px rgba(0,0,0,0.55), inset 0 0 80px rgba(0,0,0,0.35);
}

/* Garland on top */
.garland {
  position: absolute; left: -10px; right: -10px; top: -28px; height: 46px; pointer-events: none; z-index: 3;
}
.garland svg { width: 100%; height: 100%; }

.doors {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-rows: 1fr;
  grid-auto-flow: dense;
  gap: clamp(8px, 1.6vw, 16px);
}
@media (max-width: 820px) { .doors { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 480px) { .doors { grid-template-columns: repeat(3, 1fr); } }

.slot {
  position: relative;
  aspect-ratio: 1;
  perspective: 900px;
  border-radius: 10px;
}
.slot.wide { grid-column: span 2; aspect-ratio: auto; }
.slot.tall { grid-row: span 2; aspect-ratio: auto; }
.slot.big { grid-column: span 2; grid-row: span 2; aspect-ratio: auto; }

/* What's behind the door: a little recess */
.behind {
  position: absolute; inset: 0;
  border-radius: 10px;
  background: #2a0a0d;
  box-shadow: inset 0 4px 14px rgba(0,0,0,0.8);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.behind .thumb { position: absolute; inset: 6px; border-radius: 6px; background-size: cover; background-position: center; }
.behind .icon { font-size: clamp(1.6rem, 4vw, 2.6rem); filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6)); z-index: 1; }
.behind .thumb + .icon { display: none; }

/* The door itself */
.door {
  position: absolute; inset: 0;
  border: 0; padding: 0;
  border-radius: 10px;
  cursor: pointer;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 1.1s cubic-bezier(.3,.1,.2,1), box-shadow 0.3s;
  font: inherit;
  color: inherit;
  background: none;
  z-index: 2;
}
.door .face, .door .back {
  position: absolute; inset: 0;
  border-radius: 10px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.door .face {
  display: flex; align-items: center; justify-content: center;
  background: var(--door-bg, var(--green));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.18), inset 0 -8px 18px rgba(0,0,0,0.25), 0 4px 10px rgba(0,0,0,0.35);
  overflow: hidden;
}
/* perforated edge, like a real cardboard calendar */
.door .face::before {
  content: '';
  position: absolute; inset: 5px;
  border: 2px dashed rgba(255,255,255,0.45);
  border-radius: 7px;
}
/* door knob */
.door .face::after {
  content: '';
  position: absolute; right: 9%; top: 50%;
  width: 7px; height: 7px; margin-top: -3px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff6cf, var(--gold) 60%, #8a6418);
  box-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.door .num {
  position: relative;
  font-family: 'Mountains of Christmas', serif;
  font-weight: 700;
  font-size: clamp(1.8rem, 5vw, 3.2rem);
  color: var(--num-color, #fff);
  text-shadow: 0 2px 0 rgba(0,0,0,0.35), 0 0 10px rgba(0,0,0,0.25);
  line-height: 1;
}
.slot.big .door .num { font-size: clamp(3rem, 9vw, 5.5rem); }
.door .back {
  transform: rotateY(180deg);
  background: linear-gradient(90deg, #e9dcc3, #fbf3e2);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.08);
}
.door .back::before {
  content: ''; position: absolute; inset: 5px; border: 2px dashed rgba(0,0,0,0.12); border-radius: 7px;
}

.slot.open { z-index: 3; }
.slot.open .door { transform: rotateY(-108deg); box-shadow: none; pointer-events: none; }
.slot.open .door .face { box-shadow: none; }
.slot:not(.open) .door:hover { transform: rotateY(-12deg); }
.slot:not(.open) .door:focus-visible { outline: 3px solid var(--gold-light); outline-offset: 2px; }

/* Door styles */
.style-0 { --door-bg: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.18) 0 2px, transparent 3px) 0 0/18px 18px, linear-gradient(145deg, #2c7a50, #18492f); }
.style-1 { --door-bg: repeating-linear-gradient(45deg, rgba(255,255,255,0.10) 0 8px, transparent 8px 16px), linear-gradient(145deg, #c62b36, #8c1520); }
.style-2 { --door-bg: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.25) 0 1.5px, transparent 2px) 0 0/14px 14px, linear-gradient(145deg, #f2c65a, #c4922c); --num-color: #7d1018; }
.style-3 { --door-bg: repeating-linear-gradient(0deg, rgba(0,0,0,0.05) 0 2px, transparent 2px 10px), linear-gradient(145deg, #fbf3e2, #e7d6b4); --num-color: #b3202a; }
.style-4 { --door-bg: radial-gradient(circle at 70% 70%, rgba(255,255,255,0.14) 0 3px, transparent 4px) 0 0/24px 24px, linear-gradient(145deg, #1d3d6e, #0f2245); --num-color: #f7dc8b; }
.style-5 { --door-bg: repeating-linear-gradient(-45deg, rgba(255,255,255,0.16) 0 6px, transparent 6px 18px), linear-gradient(145deg, #e04752, #a51d28); }

/* Today: soft glow */
.slot.today:not(.open) .door .face {
  animation: glow 2.2s ease-in-out infinite;
}
@keyframes glow {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(255,255,255,0.18), 0 0 0 0 rgba(247,220,139,0.0), 0 4px 10px rgba(0,0,0,0.35); }
  50% { box-shadow: inset 0 0 0 2px rgba(255,255,255,0.4), 0 0 22px 6px rgba(247,220,139,0.75), 0 4px 10px rgba(0,0,0,0.35); }
}

/* Locked: a little shake when clicked */
.slot.shake .door { animation: shake 0.5s; }
@keyframes shake {
  0%, 100% { transform: rotateY(0) translateX(0); }
  20% { transform: rotateY(-6deg) translateX(-3px); }
  40% { transform: rotateY(4deg) translateX(3px); }
  60% { transform: rotateY(-4deg) translateX(-2px); }
  80% { transform: rotateY(2deg) translateX(2px); }
}

/* Sparkles when a door opens */
.sparkle {
  position: fixed; z-index: 40; pointer-events: none;
  font-size: 18px;
  animation: sparkle 1s ease-out forwards;
}
@keyframes sparkle {
  from { opacity: 1; transform: translate(0, 0) scale(0.6) rotate(0); }
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.2) rotate(180deg); }
}

.footer-note { text-align: center; color: #9fb0cc; margin-top: 28px; font-size: 0.95rem; }
.center-msg { text-align: center; margin-top: 15vh; }

@media (prefers-reduced-motion: reduce) {
  .door { transition-duration: 0.01s; }
  .slot.today:not(.open) .door .face { animation: none; }
}
