:root {
  --night: #123326;
  --night-deep: #0b241a;
  --cream: #fbf6ec;
  --cream-dark: #efe5d2;
  --red: #b3262e;
  --red-deep: #8c1c23;
  --gold: #e3b65b;
  --ink: #2b2420;
  --muted: #7a6d63;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--cream);
  background:
    radial-gradient(ellipse at top, #1d4a37 0%, transparent 60%),
    linear-gradient(var(--night), var(--night-deep));
  background-attachment: fixed;
  padding: max(2rem, env(safe-area-inset-top)) 1rem max(3rem, env(safe-area-inset-bottom));
}

/* ---------- Snow ---------- */
.snow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.flake {
  position: absolute;
  top: -10px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.8;
  animation: fall linear infinite;
}
@keyframes fall {
  to { transform: translate3d(var(--drift), 105vh, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .flake { display: none; }
}

/* ---------- Header ---------- */
header {
  position: relative;
  z-index: 1;
  text-align: center;
  margin-bottom: 2rem;
}
.eyebrow {
  margin: 0;
  color: var(--gold);
  letter-spacing: 0.25em;
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 500;
}
h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.4rem, 8vw, 4rem);
  margin: 0.3rem 0 0.4rem;
  letter-spacing: -0.01em;
}
.status {
  margin: 0;
  color: rgba(251, 246, 236, 0.7);
  font-size: 0.95rem;
}

/* ---------- Grid ---------- */
main {
  position: relative;
  z-index: 1;
  max-width: 880px;
  margin: 0 auto;
}
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(0.6rem, 2vw, 1rem);
}
@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(6, 1fr); }
}

.door {
  position: relative;
  aspect-ratio: 1;
  perspective: 800px;
}
.door button {
  all: unset;
  position: absolute;
  inset: 0;
  cursor: pointer;
  border-radius: 12px;
}
.door button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* Behind the door */
.inside {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--red), var(--red-deep));
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
  font-size: clamp(1.6rem, 6vw, 2.4rem);
}

/* The door itself */
.front {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: var(--cream);
  color: var(--red);
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  transform-origin: left center;
  transition: transform 0.7s cubic-bezier(0.3, 0.7, 0.3, 1), box-shadow 0.3s;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  backface-visibility: hidden;
}
.front::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1.5px dashed var(--cream-dark);
  border-radius: 8px;
}
/* Little door knob */
.front::after {
  content: "";
  position: absolute;
  right: 12%;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
}

.door.locked .front { color: var(--muted); background: #e9e1d2; }
.door.locked .front::after { background: #c9bfae; }
.door.unlocked:not(.open) button:hover .front { transform: rotateY(-12deg); }
.door.today:not(.open) .front {
  box-shadow: 0 0 0 3px var(--gold), 0 0 24px rgba(227, 182, 91, 0.55);
  animation: glow 2.4s ease-in-out infinite;
}
@keyframes glow {
  50% { box-shadow: 0 0 0 3px var(--gold), 0 0 36px rgba(227, 182, 91, 0.85); }
}
.door.open .front { transform: rotateY(-105deg); box-shadow: none; }

.door.shake .front { animation: shake 0.4s; }
@keyframes shake {
  25% { transform: translateX(-4px) rotate(-2deg); }
  75% { transform: translateX(4px) rotate(2deg); }
}

/* ---------- Dialog ---------- */
dialog {
  border: none;
  border-radius: 20px;
  padding: 2.5rem 2rem 2rem;
  width: min(92vw, 420px);
  background: var(--cream);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
dialog[open] { animation: pop 0.35s cubic-bezier(0.3, 1.4, 0.5, 1); }
dialog::backdrop { background: rgba(5, 20, 14, 0.65); backdrop-filter: blur(3px); }
@keyframes pop {
  from { transform: scale(0.85); opacity: 0; }
}
.close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  border: none;
  background: none;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.dialog-icon { font-size: 4rem; line-height: 1; }
.dialog-day {
  margin: 1rem 0 0;
  color: var(--red);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
dialog h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.8rem;
  margin: 0.3rem 0 0.2rem;
}
.dialog-subtitle { margin: 0; color: var(--muted); }
.dialog-message {
  margin: 1.2rem 0 0;
  padding-top: 1.2rem;
  border-top: 1px dashed var(--cream-dark);
  line-height: 1.6;
  white-space: pre-line;
}
.dialog-message:empty, .dialog-subtitle:empty { display: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  transform: translate(-50%, 1rem);
  opacity: 0;
  visibility: hidden;
  background: var(--cream);
  color: var(--ink);
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s, opacity 0.3s, visibility 0.3s;
  z-index: 10;
  white-space: nowrap;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
