:root {
  --night: #0f2a1d;
  --night-2: #16392a;
  --paper: #fdf8ee;
  --ink: #2a2118;
  --muted: #7b6f60;
  --red: #b3262e;
  --red-dark: #8c1c23;
  --gold: #d9b45a;
  --green: #2f7a4f;
  --radius: 14px;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  font: 16px/1.5 var(--sans);
  color: var(--paper);
  background: radial-gradient(ellipse at top, #1f4a35 0%, var(--night) 60%) fixed, var(--night);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.2; margin: 0 0 .5em; }
a { color: var(--gold); }
button {
  font: 600 1rem var(--sans);
  border: 0;
  border-radius: 999px;
  padding: .7em 1.4em;
  background: var(--red);
  color: #fff;
  cursor: pointer;
}
button:hover { background: var(--red-dark); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: inherit; border: 1px solid currentColor; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
input, textarea, select {
  font: inherit;
  width: 100%;
  padding: .65em .8em;
  border: 1px solid #d6cbb8;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 6em; resize: vertical; }
label { display: grid; gap: .3em; font-weight: 600; font-size: .9rem; }

/* snow: three layers of dots drifting down */
.snow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(2px 2px at 20px 30px, #fff9, transparent),
    radial-gradient(2px 2px at 140px 80px, #fff8, transparent),
    radial-gradient(3px 3px at 90px 150px, #fff7, transparent),
    radial-gradient(2px 2px at 200px 200px, #fff6, transparent);
  background-size: 240px 240px;
  animation: snow 18s linear infinite;
  z-index: 0;
}
@keyframes snow { to { background-position: 60px 240px, -40px 240px, 30px 240px, -20px 240px; } }
@media (prefers-reduced-motion: reduce) { .snow { animation: none; } }

main { position: relative; z-index: 1; max-width: 860px; margin: 0 auto; padding: 16px 16px 48px; }
main.center { min-height: 100vh; display: grid; place-items: center; }

.card {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: 0 20px 50px #0006;
  width: min(420px, 100%);
  text-align: center;
}
.card form, form.login { display: grid; gap: 16px; text-align: left; }
.card h1 { font-size: 2rem; }
.msg { min-height: 1.5em; margin: 0; color: var(--red); font-size: .9rem; }

/* header */
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 4px; }
.top h1 { font-size: clamp(1.6rem, 6vw, 2.4rem); margin: 0; }
.top h1 span { color: var(--gold); }
.top nav { display: flex; gap: 8px; flex-wrap: wrap; }
.top nav button { padding: .45em 1em; font-size: .85rem; }
.countdown { color: #e9dfc8; margin: 4px 0 20px; min-height: 1.5em; }

/* door grid */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-flow: dense;
  gap: 10px;
}
@media (min-width: 640px) { .grid { grid-template-columns: repeat(6, 1fr); gap: 14px; } }
.door {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  padding: 0;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: clamp(1.4rem, 6vw, 2rem);
  color: var(--paper);
  background: linear-gradient(145deg, var(--red), var(--red-dark));
  border: 2px solid #ffffff22;
  box-shadow: inset 0 0 0 4px #00000018, 0 6px 14px #0004;
  transition: transform .15s ease;
}
.door:nth-child(3n) { background: linear-gradient(145deg, var(--green), #1f5a39); }
.door:nth-child(4n) { background: linear-gradient(145deg, #c9993a, #9c7424); }
.door:hover { transform: translateY(-2px); background-blend-mode: normal; }
.door.big { grid-column: span 2; grid-row: span 2; font-size: clamp(2.4rem, 12vw, 3.6rem); }
.door.locked { filter: saturate(.55) brightness(.8); }
.door.locked::after { content: "🔒"; position: absolute; bottom: 6px; right: 8px; font-size: .9rem; opacity: .8; }
.door.ready { animation: glow 2s ease-in-out infinite; }
.door.opened { background: var(--paper); color: var(--ink); }
.door .emoji { font-size: 1.4em; line-height: 1; }
.door .num { position: absolute; top: 6px; left: 9px; font-size: .55em; opacity: .9; }
.door:not(.opened) .num { position: static; font-size: 1em; }
@keyframes glow { 50% { box-shadow: inset 0 0 0 4px #00000018, 0 0 22px var(--gold); } }
.door.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-4px) rotate(-2deg); } 75% { transform: translateX(4px) rotate(2deg); } }
@media (prefers-reduced-motion: reduce) { .door.ready, .door.shake { animation: none; } }

/* door dialog */
dialog {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 80px #000a;
}
dialog::backdrop { background: #071a10cc; backdrop-filter: blur(3px); }
dialog .close {
  /* Sticky so it stays reachable on long doors; the negative margin keeps it from taking layout space. */
  position: sticky; top: 8px; display: block; margin: 8px 8px -48px auto; z-index: 3;
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  background: #0000000f; color: var(--ink);
}
.scratch-wrap { position: relative; }
.door-body { padding: 24px; display: grid; gap: 16px; }
.door-body > * { margin: 0; }
.day { font-size: .8rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.door-body h2 { font-size: 1.6rem; }
.text { white-space: pre-line; }
.muted { color: var(--muted); font-size: .9rem; }
.done { color: var(--green); font-weight: 600; }

.choices { display: grid; gap: 10px; }
.choice { text-align: left; border-radius: 12px; background: #fff; color: var(--ink); border: 2px solid #e5dccb; }
.choice:hover { background: #fff; border-color: var(--gold); }
.choice:disabled { opacity: 1; }
.choice.right { border-color: var(--green); background: #e7f4ec; }
.choice.wrong { border-color: var(--red); background: #fbe9ea; }

.embed { width: 100%; height: 152px; border: 0; border-radius: 12px; }
.embed.video { height: auto; aspect-ratio: 16/9; }
.photo { width: 100%; border-radius: 12px; display: block; transition: filter .5s; }
.photo-placeholder { font-size: 4rem; text-align: center; background: #efe6d4; border-radius: 12px; padding: 40px 0; }
video { width: 100%; border-radius: 12px; background: #000; }

.letter {
  background: repeating-linear-gradient(#fffdf7 0 31px, #e9dfc9 31px 32px);
  padding: 20px;
  border-radius: 8px;
  font-family: var(--serif);
  font-size: 1.1rem;
  line-height: 32px;
  white-space: pre-line;
  box-shadow: inset 0 0 0 1px #e9dfc9;
}

.voucher {
  border: 2px dashed var(--gold);
  border-radius: 14px;
  padding: 20px;
  background: linear-gradient(135deg, #fff8e6, #fdf0cf);
  text-align: center;
  display: grid;
  gap: 12px;
}
.voucher .code { font: 600 1.2rem ui-monospace, monospace; letter-spacing: .1em; }

/* memory */
.memory { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.memory button {
  aspect-ratio: 1; padding: 0; border-radius: 10px; font-size: 1.8rem;
  background: var(--green); overflow: hidden;
}
.memory button.up { background: #fff; border: 2px solid #e5dccb; }
.memory button.matched { background: #e7f4ec; border: 2px solid var(--green); }
.memory img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* scramble */
.scramble-item { display: grid; gap: 6px; }
.scramble-item .letters { font: 700 1.4rem var(--serif); letter-spacing: .25em; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; text-transform: uppercase; }

/* word guess */
.board { display: grid; gap: 6px; justify-content: center; }
.board .line { display: flex; gap: 6px; }
.board .cell {
  width: 46px; height: 46px; display: grid; place-items: center;
  font: 700 1.3rem var(--sans); border-radius: 8px; border: 2px solid #ddd2bf; background: #fff;
}
.cell.hit { background: var(--green); border-color: var(--green); color: #fff; }
.cell.near { background: var(--gold); border-color: var(--gold); color: #fff; }
.cell.miss { background: #a59a8a; border-color: #a59a8a; color: #fff; }

/* scratch card */
canvas.scratch { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; z-index: 2; border-radius: var(--radius); cursor: grab; transition: opacity .6s; }
canvas.scratch.gone { opacity: 0; pointer-events: none; }
.scratch-skip { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 3; background: #00000055; font-size: .8rem; padding: .4em .9em; }

/* admin */
.panel { background: var(--paper); color: var(--ink); border-radius: var(--radius); padding: 20px; display: grid; gap: 12px; }
.panel table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.panel td, .panel th { text-align: left; padding: 8px 6px; border-bottom: 1px solid #e9dfc9; vertical-align: top; }
.panel td.answer { white-space: pre-wrap; word-break: break-word; }
.editor-list { display: grid; gap: 8px; }
.editor-list button { text-align: left; background: #fff; color: var(--ink); border: 1px solid #e5dccb; border-radius: 10px; }
.editor-list button:hover { border-color: var(--gold); background: #fff; }
form.editor { display: grid; gap: 14px; padding: 24px; }
form.editor .hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
form.editor .check { display: flex; align-items: center; gap: 8px; }
form.editor .check input { width: auto; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--paper); color: var(--ink); padding: .7em 1.2em; border-radius: 999px;
  box-shadow: 0 10px 30px #0006; opacity: 0; transition: .3s; z-index: 10; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
