/* Advent calendar styles.

   This came from the standalone AdventCalendar app, where it owned the whole
   document. Inside the MFO site it loads alongside site.css, so what used to be
   :root / html / body rules are scoped to .advent-page — otherwise the dark
   background and white text would leak onto every other page. */
.advent-page {
    --door-gap: 14px;
    --door-radius: 6px;
    --accent: #c62828;
    --accent-dark: #7f1414;
    --gold: #e8c34a;

    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    color: #fff;
    min-height: 100vh;
    background-image: var(--bg-image);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-color: #16222a; /* fallback while the image loads */
}

/* Falling snow (js/snowfall.js): fixed over the window like the background it
   falls across, and underneath the calendar so it never covers a door or takes
   a click. */
.snowfall {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* The calendar fills the window below the nav: the heading, then the board
   taking all the height that's left, so the doors spread across the picture
   rather than bunching along the top on a tall window. */
.calendar-wrap {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    /* A definite height, not a min-height: the board below is a size container,
       and Chrome sizes a container in an indefinite-height flex column as zero
       when evaluating its queries. 76px is .page-shell's clearance for the nav;
       the floor keeps doors usable on a short landscape phone (the page scrolls). */
    height: max(calc(100svh - 76px), 520px);
    padding: 6px clamp(10px, 3vw, 48px) 24px;
}

/* The board's heading gets a dark backing: the snowy bandstand pictures have
   bunting strung right where it sits. */
.calendar-title {
    width: fit-content;
    max-width: 100%;
    margin: 0 auto 12px;
    padding: 0.2em 0.8em;
    text-align: center;
    font-size: clamp(1.05rem, 2.1vw, 1.65rem);
    line-height: 1.2;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
    background: rgba(22, 10, 18, 0.62);
    border-radius: 14px;
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}

/* ---- The board the doors are scattered across ----
   A size container, so the grid inside can pick its shape from the board's own
   proportions: a wide window gets 8 across, a square one 5 x 5, a phone 4 x 6.
   Whatever the shape, each door is sized from its grid cell. */
.calendar-board {
    flex: 1;
    min-height: 0;
    position: relative;
    container-type: size;
}

.calendar-grid {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    grid-template-rows: repeat(var(--rows), 1fr);
    --cols: 6;
    --rows: 4;
}

@container (aspect-ratio >= 23 / 10) {
    .calendar-grid { --cols: 8; --rows: 3; }
}
@container (aspect-ratio <= 5 / 4) {
    .calendar-grid { --cols: 5; --rows: 5; }   /* one cell spare, bottom right */
}
@container (aspect-ratio <= 17 / 20) {
    .calendar-grid { --cols: 4; --rows: 6; }
}
@container (aspect-ratio <= 9 / 20) {
    .calendar-grid { --cols: 3; --rows: 8; }
}

/* One grid cell. Also a size container, so the door inside can size itself to
   the cell. Layout containment makes each cell its own stacking context, which
   is why the lift-above-the-neighbours z-index lives here and not on .door. */
.door-slot {
    position: relative;
    container-type: size;
}
.door-slot:hover { z-index: 4; }
.door-slot:has(.door.open) { z-index: 5; }

/* ---- A single door ----
   Square, sized from its cell (and capped, so a huge monitor doesn't get
   dinner-plate doors), then nudged off-centre by --jx / --jy (-0.5 to 0.5, set
   per door by the server) within whatever room the cell has spare. */
.door {
    --size: min(66cqmin, 200px);
    position: absolute;
    width: var(--size);
    height: var(--size);
    left: calc((100cqw - var(--size)) * (0.5 + var(--jx, 0) * 0.85));
    top: calc((100cqh - var(--size)) * (0.5 + var(--jy, 0) * 0.85));
    perspective: calc(var(--size) * 4);
}

/* Content sits behind the door face and is revealed when the door swings open. */
.door-content {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: calc(var(--size) * 0.06);
    /* The video's picture (--thumb, when the door has one), dimmed so the card
       on top of it stands out. */
    background:
        linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)),
        var(--thumb, none) center / cover no-repeat,
        #111;
    border-radius: var(--door-radius);
    text-align: center;
    /* Hidden while the door is shut so a closed door shows only the background
       image through its (semi-transparent) face — never the video preview. */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease 0.25s, visibility 0s linear 0.5s;
}

/* Reveal the sneak-peek preview once the door has been opened. */
.door.open .door-content {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease 0.3s, visibility 0s;
}

/* The face is a hinged panel that rotates on its left edge. */
.door-face {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    cursor: pointer;
    border-radius: var(--door-radius);
    /* Fully see-through so the background image shows through a closed door —
       just a thin gold outline and the day number, like a printed calendar. */
    background: transparent;
    border: 3px solid var(--gold);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
    transform-origin: left center;
    transition: transform 0.6s ease, background-color 0.3s ease;
    transform-style: preserve-3d;
    display: flex;
    align-items: center;
    justify-content: center;
}

.door-number {
    font-size: calc(var(--size) * 0.36);
    font-weight: 700;
    color: var(--gold);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
}

.door-lock {
    position: absolute;
    bottom: 6%;
    right: 7%;
    font-size: calc(var(--size) * 0.11);
    opacity: 0.9;
}

/* ---- Ready to open: left very slightly ajar ----
   What a door that can be opened looks like before anyone opens it:

   - The frame. ::before draws the opening the door sits in — a gold surround
     with a shadowed recess — so there is something for the door to stand off.
   - The gap. The face swings a few degrees on its hinge. The view is set from
     off to the right (perspective-origin), which is what makes the free edge
     pull back from the frame rather than grow towards you.
   - The glimpse. What's behind the door is shown, but clipped to a sliver down
     the gap (--peek), so you catch the edge of the video thumbnail and no more.
     Only unlocked doors are ever ajar, and a locked door's video is never sent
     to the browser, so nothing can be seen early.

   Hovering opens it a little further, and the sliver widens with it. */
.door:not(.locked) {
    --peek: 10%;     /* matched to the gap the -10deg swing opens, measured */
    perspective-origin: 260% 50%;
}
.door:not(.locked):not(.open):hover,
.door:not(.locked):not(.open):has(.door-face:focus-visible) {
    --peek: 21%;     /* and the -19deg hover swing */
}

.door:not(.locked)::before {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: calc(var(--door-radius) + 3px);
    border: 4px solid rgba(232, 195, 74, 0.75);
    background: rgba(8, 5, 10, 0.25);
    box-shadow:
        inset 0 0 0 1px rgba(0, 0, 0, 0.55),
        inset 4px 4px 12px rgba(0, 0, 0, 0.75),
        0 2px 8px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}

/* The glimpse: the content behind, clipped to the strip the gap uncovers, with
   warm light spilling down its inner edge. */
.door:not(.locked):not(.open) .door-content {
    opacity: 1;
    visibility: visible;
    pointer-events: none;
    clip-path: inset(0 0 0 calc(100% - var(--peek)));
    /* Undimmed picture, with warm light falling down the gap's inner edge. */
    background:
        linear-gradient(to right,
            rgba(255, 205, 120, 0) calc(100% - var(--peek)),
            rgba(255, 205, 120, 0.7) calc(100% - var(--peek)),
            rgba(255, 205, 120, 0) calc(100% - var(--peek) + 7%)),
        var(--thumb, none) center / cover no-repeat,
        #1a1014;
    transition: clip-path 0.6s ease, opacity 0s, visibility 0s;
}

.door:not(.locked):not(.open) .door-face {
    transform: rotateY(-10deg);
    /* Tinted, so the door reads as a panel in front of the sliver. */
    background-color: rgba(20, 12, 20, 0.42);
}

.door:not(.locked):not(.open):hover .door-face,
.door:not(.locked):not(.open) .door-face:focus-visible {
    transform: rotateY(-19deg);
}

/* Fully open: the whole of what's behind, no clipping. */
.door.open .door-content {
    clip-path: inset(0 0 0 0);
    transition: clip-path 0.6s ease, opacity 0.3s ease 0.3s, visibility 0s;
}

/* Open state: swing the face open on its hinge, then let it fall away. Once a
   door has been opened it's gone for good — like tearing the flap off a paper
   calendar — and it stays gone on later visits (calendar.js remembers, and adds
   .gone straight away so the door doesn't swing again on every load). */
.door.open .door-face {
    transform: rotateY(-115deg);
    /* Solid once open, so the swinging panel isn't see-through. */
    background: linear-gradient(145deg, var(--accent), var(--accent-dark));
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.6s ease, opacity 0.45s ease 0.5s, visibility 0s linear 0.95s;
}
.door.gone .door-face,
.door.gone .door-content { transition: none; }

/* The day, small in the corner, now the big number has gone with the door. */
.door-content-day {
    position: absolute;
    top: 4%;
    left: 6%;
    font-size: max(0.7rem, calc(var(--size) * 0.11));
    font-weight: 700;
    line-height: 1;
    color: var(--gold);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

/* Locked doors: shut flush, dimmer gold outline, faint tint, not clickable. */
.door.locked .door-face {
    background: rgba(0, 0, 0, 0.3);
    border-color: rgba(232, 195, 74, 0.4);
    cursor: not-allowed;
}

.door.locked .door-number {
    color: rgba(232, 195, 74, 0.55);
}

.door:not(.locked) .door-face:hover {
    border-color: #ffe08a;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.55);
}

@media (prefers-reduced-motion: reduce) {
    .door-face { transition: none; }
}

/* ---- Video thumbnail inside an open door ---- */
.video-thumb {
    position: relative;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.7);
    border-radius: 6px;
    background: #000;
    cursor: pointer;
    overflow: hidden;
    line-height: 0;
    max-width: 100%;
}

.video-thumb img {
    display: block;
    width: 100%;
    height: auto;
}

.play-badge {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(198, 40, 40, 0.9);
    color: #fff;
    font-size: 0.9rem;
    padding-left: 3px;
}

.video-caption {
    font-size: 0.72rem;
    line-height: 1.2;
    opacity: 0.9;
}

.no-video {
    font-size: 0.72rem;
    opacity: 0.7;
}

/* ---- Expanded video modal ---- */
.modal[hidden] { display: none; }

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
}

.modal-body {
    position: relative;
    width: min(90vw, 960px);
    background: #000;
    border-radius: 10px;
    padding: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.modal-video {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
}

.modal-video iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 6px;
}

.modal-close {
    position: absolute;
    top: -20px;
    right: -20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.15);
    background: #fff;
    color: #000;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
    /* Sits above the YouTube iframe (which comes later in the DOM). */
    z-index: 10;
}
