:root {
  --night: #0b1a2c;
  --night-2: #16304d;
  --red: #c8352b;
  --red-dark: #8f1d16;
  --green: #1f6d47;
  --green-dark: #11452c;
  --gold: #f4c452;
  --gold-dark: #c9921f;
  --cream: #fff8ec;
  --paper: #fffdf7;
  --ink: #2a1c14;
  --muted: #6d5c50;
  --radius: 18px;
  --display: 'Mountains of Christmas', 'Georgia', serif;
  --body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.5;
  color: var(--cream);
  background:
    radial-gradient(1200px 600px at 50% -10%, #2a4f7a 0%, transparent 60%),
    radial-gradient(circle at 20% 30%, rgba(255,255,255,.08) 0 1px, transparent 2px) 0 0 / 90px 90px,
    radial-gradient(circle at 70% 60%, rgba(255,255,255,.06) 0 1px, transparent 2px) 0 0 / 130px 130px,
    linear-gradient(180deg, var(--night-2), var(--night) 60%);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* ---------- snow ---------- */
.snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.flake {
  position: absolute;
  top: -20px;
  color: #fff;
  animation-name: fall, sway;
  animation-timing-function: linear, ease-in-out;
  animation-iteration-count: infinite, infinite;
  animation-direction: normal, alternate;
}
@keyframes fall { to { transform: translateY(110vh); } }
@keyframes sway { from { margin-left: -12px; } to { margin-left: 12px; } }

/* ---------- layout ---------- */
.page {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0 14px;
}
.site-title {
  font-family: var(--display);
  font-size: clamp(26px, 7.5vw, 40px);
  line-height: 1.05;
  color: var(--gold);
  text-decoration: none;
  text-shadow: 0 2px 0 rgba(0,0,0,.35), 0 0 22px rgba(244,196,82,.35);
}
.site-title__name { display: block; color: #fff; font-size: .8em; }
.logout button {
  font: inherit;
  font-size: 13px;
  color: rgba(255,255,255,.75);
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

h1, h2 { line-height: 1.2; }
.muted { color: rgba(255,248,236,.72); }
.card .muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }

.flash {
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 14px;
  font-weight: 700;
  background: var(--paper);
  color: var(--ink);
  border-left: 6px solid var(--green);
}
.flash--error { border-left-color: var(--red); }

/* ---------- cards & buttons ---------- */
.card {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 22px 18px;
  margin-bottom: 18px;
  box-shadow: 0 12px 30px rgba(0,0,0,.35), inset 0 0 0 1px rgba(0,0,0,.04);
}
.card h1 { font-family: var(--display); font-size: 32px; margin: 0 0 8px; color: var(--red-dark); }
.card h2 { font-size: 19px; margin: 0 0 10px; }
.card--centered { text-align: center; }
.big-emoji { font-size: 56px; line-height: 1; margin: 6px 0 10px; }

.btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 800;
  border: 0;
  border-radius: 999px;
  padding: 12px 22px;
  min-height: 48px;
  cursor: pointer;
  text-decoration: none;
  background: #eee4d6;
  color: var(--ink);
}
.btn--primary {
  background: linear-gradient(180deg, #e04a3e, var(--red));
  color: #fff;
  box-shadow: 0 4px 0 var(--red-dark), 0 8px 18px rgba(200,53,43,.35);
}
.btn--primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--red-dark); }
.btn--big { width: 100%; font-size: 19px; min-height: 56px; }
.btn:disabled { opacity: .7; cursor: progress; }

.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-weight: 700; }
.field input, .field textarea {
  font: inherit;
  font-size: 18px; /* stops iOS zooming in */
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid #e2d6c6;
  background: #fff;
  color: var(--ink);
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 4px rgba(31,109,71,.15); }
.form-error { color: var(--red); font-weight: 800; margin: 0; }

/* ---------- login ---------- */
.login-card { max-width: 420px; margin: 8vh auto 0; text-align: center; padding-top: 44px; }
.login-card form { text-align: left; margin-top: 18px; }
.login-card__bauble {
  position: absolute; top: -30px; left: 50%; transform: translateX(-50%);
  width: 60px; height: 60px; border-radius: 50%;
  display: grid; place-items: center; font-size: 30px;
  background: var(--gold); box-shadow: 0 6px 16px rgba(0,0,0,.3);
}

/* ---------- calendar ---------- */
.intro { text-align: center; margin: 0 0 16px; }
.intro__big { font-family: var(--display); font-size: 28px; color: #fff; margin: 0 0 4px; }
.intro .muted { margin: 0 auto; max-width: 34em; font-size: 15px; }

.board {
  padding: 14px;
  border-radius: 22px;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.035) 0 10px, transparent 10px 20px),
    linear-gradient(160deg, #2a8059, var(--green-dark));
  border: 4px solid var(--gold-dark);
  box-shadow: 0 0 0 3px var(--green-dark), 0 20px 40px rgba(0,0,0,.45);
}
.doors {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (min-width: 640px) {
  .doors { grid-template-columns: repeat(6, 1fr); gap: 14px; }
}

.door {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1.18;
  padding: 0;
  border: 0;
  background: none;
  perspective: 500px;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}
.door__inside {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-size: 30px;
  background: radial-gradient(circle at 50% 40%, #5a3b25, #2b1a0f);
  box-shadow: inset 0 3px 10px rgba(0,0,0,.6);
}
.door__front {
  --c1: var(--red); --c2: var(--red-dark);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  transform-origin: left center;
  transition: transform .55s cubic-bezier(.3,.9,.4,1.1);
  background:
    radial-gradient(circle at 84% 52%, var(--gold) 0 3px, transparent 4px),
    linear-gradient(150deg, var(--c1), var(--c2));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18), 0 4px 8px rgba(0,0,0,.35);
  backface-visibility: hidden;
}
.door__front::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px dashed rgba(255,255,255,.35);
  border-radius: 6px;
}
.door__num {
  font-family: var(--display);
  font-size: clamp(30px, 9vw, 42px);
  color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,.3);
}
.door--c1 .door__front { --c1: #2f8a5c; --c2: var(--green-dark); }
.door--c2 .door__front { --c1: #f6cf6b; --c2: var(--gold-dark); }
.door--c2 .door__num { color: #6b3f05; text-shadow: 0 1px 0 rgba(255,255,255,.5); }
.door--c3 .door__front { --c1: #3c6ea8; --c2: #1d3e66; }
.door--c4 .door__front { --c1: #a8323e; --c2: #5e1420; }

/* Doors that have been answered or missed hang partly open. */
.door--answered .door__front,
.door--missed .door__front { transform: rotateY(-68deg); }
.door--answered .door__inside { background: radial-gradient(circle at 50% 40%, #fff3c9, #e7b84a); }
.door--missed .door__inside { background: radial-gradient(circle at 50% 40%, #47617f, #22344b); }
.door--missed { opacity: .72; }

/* Today's door glows. */
.door--open .door__front { animation: glow 1.8s ease-in-out infinite alternate; }
.door--open::after {
  content: 'Open me!';
  position: absolute;
  left: 50%;
  bottom: -9px;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .02em;
  color: var(--ink);
  background: var(--gold);
  padding: 2px 8px;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  z-index: 2;
}
.door--open.is-opening .door__front { transform: rotateY(-105deg); animation: none; }
@keyframes glow {
  from { box-shadow: inset 0 0 0 2px rgba(255,255,255,.3), 0 0 0 0 rgba(244,196,82,.0); }
  to   { box-shadow: inset 0 0 0 2px rgba(255,255,255,.3), 0 0 18px 6px rgba(244,196,82,.85); }
}

.door--locked.is-wiggling .door__front { animation: wiggle .45s ease; }
@keyframes wiggle {
  20% { transform: rotate(-4deg); }
  40% { transform: rotate(4deg); }
  60% { transform: rotate(-3deg); }
  80% { transform: rotate(2deg); }
}

.door:focus-visible { outline: 3px solid #fff; outline-offset: 3px; border-radius: 10px; }

.legend {
  list-style: none;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 0;
  margin: 18px 0 0;
  font-size: 14px;
  color: rgba(255,248,236,.8);
}
.legend li { display: flex; align-items: center; gap: 6px; }
.legend__swatch { width: 14px; height: 14px; border-radius: 4px; background: var(--red); box-shadow: 0 0 8px 2px rgba(244,196,82,.9); }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 10;
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  transform: translateY(20px);
  opacity: 0;
  transition: transform .25s, opacity .25s;
}
.toast.is-visible { transform: none; opacity: 1; }

/* ---------- day page ---------- */
.back-link {
  display: inline-block;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  margin: 0 0 14px;
  padding: 6px 0;
}
.preview-banner {
  background: var(--gold);
  color: var(--ink);
  font-weight: 800;
  border-radius: 12px;
  padding: 10px 14px;
}

.challenge { padding-top: 40px; margin-top: 18px; }
.ribbon {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--display);
  font-size: 26px;
  color: #fff;
  background: linear-gradient(180deg, #e04a3e, var(--red));
  padding: 4px 26px;
  border-radius: 8px;
  box-shadow: 0 6px 14px rgba(0,0,0,.3);
  white-space: nowrap;
}
.ribbon::before, .ribbon::after {
  content: '';
  position: absolute;
  top: 8px;
  width: 18px;
  height: 100%;
  background: var(--red-dark);
  z-index: -1;
}
.ribbon::before { left: -12px; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 40% 50%); }
.ribbon::after { right: -12px; clip-path: polygon(0 0, 100% 0, 60% 50%, 100% 100%, 0 100%); }

.challenge__title { text-align: center; }
.challenge__image {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 12px;
  margin: 8px 0 14px;
  background: #f3ece1;
}
.challenge__body { font-size: 18px; margin-bottom: 18px; overflow-wrap: anywhere; }
.hint { font-weight: 800; color: var(--green); margin: 0 0 8px; }

.answer-form { display: grid; gap: 14px; }
.choices { display: grid; gap: 10px; }
.choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 12px 14px;
  border: 2px solid #e6dacb;
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  font-weight: 700;
  transition: border-color .15s, background .15s, transform .1s;
}
.choice:active { transform: scale(.98); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice__mark {
  flex: none;
  width: 26px;
  height: 26px;
  border: 2px solid #c9b8a4;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff;
}
.choice input[type="checkbox"] ~ .choice__row .choice__mark { border-radius: 7px; }
.choice input:checked ~ .choice__row .choice__mark { background: var(--green); border-color: var(--green); }
.choice input:checked ~ .choice__row .choice__mark::after { content: '✓'; color: #fff; font-weight: 900; font-size: 16px; line-height: 1; }
.choice:has(input:checked) { border-color: var(--green); background: #eef8f1; }
.choice:has(input:focus-visible) .choice__mark { outline: 3px solid var(--gold-dark); outline-offset: 2px; }
.choice__row { display: flex; align-items: center; gap: 12px; }
.choices--pictures { grid-template-columns: 1fr 1fr; }
.choices--pictures .choice { flex-direction: column; align-items: stretch; padding: 8px; }
.choice__img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: #f3ece1; }
.chosen__img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; vertical-align: middle; margin-right: 8px; }

.photo-picker {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 200px;
  border: 3px dashed #d7c6b1;
  border-radius: 16px;
  background: #fbf6ee;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
}
.photo-picker input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-picker__empty { font-size: 40px; line-height: 1.4; color: var(--muted); }
.photo-picker__empty strong { font-size: 16px; }
.photo-picker__preview { width: 100%; max-height: 50vh; object-fit: contain; display: block; }
.photo-picker__preview[hidden], .photo-picker__empty[hidden] { display: none; }

.your-answer {
  position: relative;
  background: #eef8f1;
  border: 2px solid #bfe1cb;
  border-radius: 14px;
  padding: 14px 16px;
}
.your-answer h2 { color: var(--green); margin-bottom: 6px; }
.your-answer--missed { background: #eef2f7; border-color: #cdd8e5; text-align: center; font-weight: 700; }
.your-answer p:last-child { margin-bottom: 0; }
.chosen { list-style: none; padding: 0; margin: 0 0 6px; font-weight: 800; display: grid; gap: 4px; }
.written { margin: 0 0 6px; font-size: 18px; overflow-wrap: anywhere; }
.uploaded { display: block; width: 100%; max-height: 60vh; object-fit: contain; border-radius: 10px; }
.answered { position: relative; text-align: center; padding: 12px 0 4px; }
.answered .challenge__title { margin-bottom: 8px; }
.answered__time { font-size: 20px; font-weight: 800; color: var(--green); margin: 0; }
.celebrate { font-family: var(--display); font-size: 28px; text-align: center; color: var(--red); margin: 0 0 6px; }

.burst { position: absolute; left: 50%; top: 30px; width: 0; height: 0; pointer-events: none; }
.burst span {
  position: absolute;
  font-size: 22px;
  animation: pop 1.8s cubic-bezier(.2,.7,.3,1) forwards;
}
@keyframes pop {
  0% { transform: translate(0, 0) scale(.3); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--x), calc(var(--y) + 220px)) rotate(var(--r)) scale(1); opacity: 0; }
}

.others__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.others__list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #f5efe5;
}
.others__list li.is-done { background: #eef8f1; }
.others__name { font-weight: 800; }
.others__time { font-size: 15px; color: var(--muted); white-space: nowrap; }

.confirm {
  border: 0;
  border-radius: 20px;
  padding: 22px;
  width: min(92vw, 380px);
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.confirm::backdrop { background: rgba(5,12,22,.7); }
.confirm__title { font-family: var(--display); font-size: 28px; color: var(--red-dark); margin: 0 0 6px; }
.confirm__buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }

/* ---------- misc ---------- */
.unknown { max-width: 420px; margin: 20vh auto 0; text-align: center; }

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