/* Advent of Security (/advent-of-security). Page-only styles, loaded from adventPage's head. */

.adv {
  --pine: #17402f;
  --pine-deep: #0f2c20;
  --paper: #f8efdc;
  --paper-edge: #e6d6b6;
  --cranberry: #c8384b;
  --gold: #e0a83a;
  position: relative;
  z-index: 2;
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px var(--gutter) 72px;
  /* The board's width, shared with the hero so the title lines up with the painting's left edge (see .adv-board). */
  --board-w: min(calc(100vw - 32px), calc((100dvh - 32px) * 1.5), 1800px);
}
:root[data-theme="dark"] .adv { --paper: #efe3c8; --paper-edge: #d8c59f; --pine: #133628; }

.adv-preview { margin: 0 0 16px; padding: 8px 12px; border-radius: 10px; background: var(--amber-bg); color: var(--amber); font-size: 13px; }
.adv-preview a { color: inherit; }
.adv-preview button { padding: 1px 8px; border: 1px solid currentColor; border-radius: 99px; background: none; color: inherit; font: inherit; cursor: pointer; }
.adv-preview button[aria-pressed="true"] { background: var(--amber); color: #fff; border-color: var(--amber); }

/* Snow across the whole page; flakes are made by advent.js. */
.adv-snow { position: fixed; inset: 0; pointer-events: none; z-index: -1; overflow: hidden; } /* behind the page, inside .adv's layer */
.adv-flake {
  position: absolute; top: -12px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 6px rgba(160, 180, 210, .7);
  animation: adv-fall linear infinite;
}
:root:not([data-theme="dark"]) .adv-flake { background: #dfe7f2; box-shadow: none; }
@keyframes adv-fall {
  to { transform: translate3d(var(--dx, 30px), 105vh, 0) rotate(360deg); }
}

/* ---------- Hero ---------- */
/* Same width as the board, so the title starts where the painting does and Plango ends where it ends. */
.adv-hero {
  position: relative; display: grid; grid-template-columns: 1fr auto; grid-template-rows: 1fr auto; column-gap: 24px;
  align-items: start; width: var(--board-w); margin: 0 0 14px calc(50% - var(--board-w) / 2); padding: 0 8px;
}
.adv-hero-copy { grid-column: 1; grid-row: 1; padding-top: 44px; }
.adv-h1 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: clamp(52px, 8.4vw, 100px); line-height: .92; letter-spacing: -.02em; }
.adv-h1 em { color: var(--cranberry); }
/* The "Security" easter egg (views.js adventHackWord): the word is a plain-looking button; clicked, it gets sprayed
   out, then HACKING is sprayed to its right, stroke by stroke (each path's --i is its turn), and the paint drips. The
   paint is the page's ink colour: black on the light theme, and light on the dark one, where black would vanish. */
.adv-hack {
  position: relative; display: inline; padding: 0; border: 0; background: none; color: inherit;
  font: inherit; letter-spacing: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.adv-hack:focus-visible { outline: 2px dashed currentColor; outline-offset: 6px; border-radius: 6px; }
.adv-hack svg {
  position: absolute; overflow: visible; pointer-events: none; visibility: hidden;
  fill: none; stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round;
}
.adv-hack svg path { stroke-dasharray: 1; stroke-dashoffset: 1; }
.adv-hack-strike { left: -4%; width: 108%; top: 42%; height: .17em; stroke-width: 5.4; }
.adv-hack-word {
  --hack-h: .84em;
  left: calc(100% + .14em); top: -.14em; height: var(--hack-h); width: calc(var(--hack-h) * 268 / 80); stroke-width: 12;
  stroke-linejoin: miter; stroke-miterlimit: 3; transform: rotate(-8deg); transform-origin: 0 60%;
}
/* Mid-size windows: a little smaller, so it stays clear of Plango's speech bubble. */
@media (min-width: 721px) and (max-width: 1320px) { .adv-hack-word { --hack-h: .66em; top: -.04em; } }
.adv-hack-drip { stroke-width: 4.5; }
.adv-hack.is-hacked svg { visibility: visible; }
/* Fast, and speeding up into each stroke: a hand slamming the can across, not a careful one. The drips run last. */
.adv-hack.is-hacked .adv-hack-word .adv-hack-drip { animation: adv-draw .7s cubic-bezier(.3, .6, .4, 1) 1.6s forwards; }
.adv-hack.is-hacked .adv-hack-strike path { animation: adv-draw .32s cubic-bezier(.7, 0, .9, .5) forwards; }
.adv-hack.is-hacked em { display: inline-block; animation: adv-jolt .22s ease-out .3s; }
@keyframes adv-jolt { 30% { transform: translate(-2px, 2px) rotate(-1.2deg); } 65% { transform: translate(2px, -1px) rotate(.8deg); } }
.adv-hack.is-hacked .adv-hack-word path { animation: adv-draw .12s cubic-bezier(.6, 0, .9, .6) forwards; animation-delay: calc(.42s + var(--i) * .075s); }
@keyframes adv-draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .adv-hack.is-hacked svg path { stroke-dashoffset: 0; } }
:root[data-theme="dark"] .adv-h1 em { color: #f07c8b; }
/* The greeting, signed: the signature follows the end of the line ("…happy holidays."), dropped a little below it,
   which on a laptop puts it under "Security". Where the line leaves no room (phones), it wraps to its own line and
   keeps to the right. */
.adv-signed { display: flex; flex-wrap: wrap; align-items: flex-start; column-gap: 16px; margin-top: 16px; }
.adv-lede { max-width: 34em; margin: 0; font-size: 18px; line-height: 1.55; color: var(--gray); }
/* Rich & Fred's signature: the photo's ink only (paper and lighting removed, art/advent/signature.webp), used as a
   mask so it's painted in the page's ink colour and reads in dark mode too. It writes itself in left to right.
   --sign-x / --sign-y nudge it from that spot, as set with the admin preview's "Move signature" drag (advent.js). */
.adv-sign {
  --sign-x: 0px; --sign-y: 0px;
  display: block; flex: none; width: min(230px, 58vw); aspect-ratio: 1049 / 176; margin: 14px 0 0;
  background: var(--ink); opacity: .88; transform-origin: 0 50%;
  transform: translate(var(--sign-x), var(--sign-y)) rotate(-2deg);
  -webkit-mask: url('/public/art/advent/signature.webp?v=1') center / contain no-repeat;
  mask: url('/public/art/advent/signature.webp?v=1') center / contain no-repeat;
  animation: adv-sign-write 1.6s cubic-bezier(.45, .05, .35, 1) .5s backwards;
}
.adv.is-moving-sign .adv-sign { cursor: grab; outline: 2px dashed var(--amber); outline-offset: 6px; touch-action: none; }
.adv.is-moving-sign .adv-sign:active { cursor: grabbing; }
@keyframes adv-sign-write { from { clip-path: inset(-10% 100% -10% 0); } to { clip-path: inset(-10% 0 -10% 0); } }
/* Progress: a row of 24 on a cranberry band, under the title at the foot of the hero, so it sits right on top of the
   painting. Each day is a faint empty ring until its door opens, a white snowball while it's open but unsolved, and a
   glowing gold bead once solved (classes set by render() in advent.js). */
.adv-progress {
  grid-column: 1; grid-row: 2; justify-self: start; align-self: end; margin-top: 18px;
  display: flex; align-items: center; gap: 10px; padding: 5px 12px 5px 10px; border-radius: 999px;
  background: linear-gradient(180deg, #d4434f, #ac2636); color: #fff; font-size: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28), 0 5px 12px -5px rgba(150, 20, 30, .55);
}
.adv-ornaments { display: flex; gap: 3px; margin: 0; padding: 0; list-style: none; }
.adv-ornaments li {
  width: 9px; height: 9px; border-radius: 50%;
  background: rgba(255, 255, 255, .1); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .32);
  transition: background .3s, box-shadow .3s, transform .3s;
}
.adv-ornaments li.is-available {
  background: radial-gradient(circle at 34% 30%, #fff 0 32%, #e4ebf4 62%, #aebdd0 100%);
  box-shadow: 0 0 3px rgba(255, 255, 255, .6);
}
.adv-ornaments li.is-done {
  background: radial-gradient(circle at 35% 30%, #fff5c4 0 20%, #ffcd4a 55%, #df950f 100%);
  box-shadow: 0 0 5px rgba(255, 205, 80, .95);
  animation: adv-pop-in .5s cubic-bezier(.3, 1.8, .5, 1);
}

/* Plango sits at the right of its column so the speech bubble, up and to the left of the head, lands in the open
   space by the waving paw rather than over the headline. */
.adv-hero-art { grid-column: 2; grid-row: 1 / span 2; position: relative; display: flex; justify-content: flex-end; padding-top: 64px; }
.adv-hero-btn { position: relative; padding: 0; border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.adv-hero-mascot { display: block; width: auto; height: 240px; animation: adv-breathe 3.4s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes adv-breathe { 50% { transform: scale(1.015, 1.03); } }
.adv-hero-btn:hover .adv-hero-mascot { animation: adv-wiggle .6s ease-in-out; }
.adv-hero-mascot.is-roll { animation: adv-curl 1.2s cubic-bezier(.5, 0, .3, 1); }
.adv-hero-mascot.is-talk { animation: adv-talk .4s ease-out; }
@keyframes adv-talk { 30% { transform: scale(1.03, .97) rotate(-1.5deg); } 65% { transform: scale(.99, 1.02) rotate(1deg); } }
/* Changing pose (the title's HACKING easter egg, advent.js setPose): a quick squash-and-pop, so it reads as a reaction. */
.adv-hero-mascot.is-swap { animation: adv-swap .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes adv-swap { 0% { transform: scale(1.06, .9); } 55% { transform: scale(.97, 1.05); } }

/* The bubble's tail corner is pinned just above Plango's cheek (percent of the image box), so the bubble only ever
   grows up and to the left. That keeps the tail on Plango whatever the line length, and the hero's padding-top is
   the headroom for the longest line (three rows at this width), so it never reaches the nav. */
.adv-bubble {
  position: absolute; z-index: 2; bottom: 87%; right: 60%; width: max-content; max-width: 262px;
  padding: 10px 14px; border-radius: 18px 18px 6px 18px;
  background: var(--card); color: var(--ink);
  filter: drop-shadow(0 0 .5px rgba(0, 0, 0, .35)) drop-shadow(0 8px 16px rgba(30, 20, 10, .14));
  font-size: 14px; line-height: 1.4; text-align: left;
  transform-origin: 92% 120%;
}
/* Tail: a slanted wedge from the bubble's bottom-right corner down toward Plango's face. The drop-shadow above
   outlines bubble and tail as one shape, which is why the bubble has no border. */
.adv-bubble::after {
  content: ""; position: absolute; top: calc(100% - 1px); right: 6px; width: 28px; height: 24px;
  background: var(--card); clip-path: polygon(0 0, 62% 0, 100% 100%);
}
.adv-bubble.is-pop { animation: adv-pop-in .45s cubic-bezier(.3, 1.6, .5, 1); }

@keyframes adv-wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-5deg); } 75% { transform: rotate(5deg); } }
@keyframes adv-curl {
  0% { transform: none; }
  30% { transform: scale(.72) rotate(-200deg); border-radius: 50%; }
  70% { transform: scale(.72) rotate(-560deg); }
  100% { transform: rotate(-720deg); }
}
@keyframes adv-pop-in { 0% { transform: scale(.3); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* ---------- The board: the painting, with each door cut out of it along its dashed outline ---------- */
/* Breaks out of the text column: as wide as the window allows, but never taller than the screen (the painting is
   3:2), so the whole scene fits in one view. Margin, not a transform, centres it: a transform here would become the
   containing block for the doors' 3D and the dialog's fixed confetti. */
.adv-board {
  position: relative; width: var(--board-w); margin-left: calc(50% - var(--board-w) / 2);
}
.adv-board-scroll {
  border-radius: 24px; overflow: hidden;
  box-shadow: 0 30px 60px -24px rgba(40, 30, 20, .45), 0 0 0 1px rgba(0, 0, 0, .06);
}
.adv-board-art { position: relative; aspect-ratio: 1536 / 1024; }
.adv-board-img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.adv-board-hint { display: none; }

/* The door's box takes no clicks: only the clipped shapes inside it do (flap and hollow are both buttons), so a click
   lands on the object itself and a neighbour's box never swallows it. :hover still reaches the box from them. */
.adv-door { position: absolute; z-index: 1; perspective: 600px; pointer-events: none; -webkit-tap-highlight-color: transparent; }
.adv-door.is-opened { z-index: 3; }
.adv-door:hover { z-index: 4; }
.adv-hole, .adv-flap, .adv-flap-img { position: absolute; inset: 0; }
.adv-hole, .adv-flap-img {
  margin: 0; padding: 0; border: 0; font: inherit; color: inherit; cursor: pointer; pointer-events: auto;
  -webkit-appearance: none; appearance: none; -webkit-tap-highlight-color: transparent;
}
.adv-flap { pointer-events: none; }
.adv-door:not(.is-opened) .adv-hole { pointer-events: none; }
.adv-hole:focus-visible, .adv-flap-img:focus-visible { outline: none; }
.adv-door:has(.adv-flap-img:focus-visible) .adv-flap { filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 6px var(--gold)); }
.adv-hole:focus-visible { filter: brightness(1.2); }

/* Behind the door: a warm, lit hollow in the painting. Hidden while shut, so no sliver shows at the cut edge. Once
   open it is the way in to the day's post, and brightens under the pointer to say so. */
.adv-hole {
  container-type: size; display: grid; place-items: center; overflow: hidden; opacity: 0; transition: opacity .15s, filter .2s;
  background: radial-gradient(ellipse at 50% 62%, #fff1c4 0%, #f5b34e 26%, #a3521b 62%, #3b1a0a 100%);
}
.adv-door.is-opened .adv-hole:hover { filter: brightness(1.15) saturate(1.1); }
.adv-door.is-locked .adv-hole { background: radial-gradient(ellipse at 50% 60%, #6b4a33 0%, #2c1a10 70%, #140b06 100%); }
.adv-door:hover .adv-hole, .adv-door.is-opened .adv-hole, .adv-door.is-shake .adv-hole { opacity: 1; }

/* The lock in the hollow: sad and shut until the day is done, then happy, gold and open (symbols in views.js).
   Sized to the hollow (cq units), so it fits the bell as well as the big chest. It pops in as the door opens. */
.adv-lock {
  position: relative; z-index: 2; display: grid; width: clamp(16px, 44cqmin, 72px); aspect-ratio: 64 / 72;
  transform: scale(.3); opacity: 0;
  transition: transform .5s cubic-bezier(.3, 1.8, .5, 1) .3s, opacity .2s .3s;
}
.adv-door.is-opened .adv-lock, .adv-door.is-closing .adv-lock { transform: none; opacity: 1; }
.adv-door.is-opened .adv-hole:hover .adv-lock { animation: adv-hop .6s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes adv-hop { 40% { transform: translateY(-14%) scale(1.12); } }
.adv-lock svg { grid-area: 1 / 1; width: 100%; height: 100%; overflow: visible; transform-origin: 50% 100%; }
.adv-lock-open { display: none; }
.adv-door.is-done .adv-lock-shut { display: none; }
.adv-door.is-done .adv-lock-open { display: block; }
/* Sad: dull, slumped to one side, slowly sighing. */
.adv-lock-shut {
  filter: saturate(.75) drop-shadow(0 3px 3px rgba(40, 15, 0, .5));
  animation: adv-sigh 4.2s ease-in-out infinite;
}
@keyframes adv-sigh {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(-5deg) scale(1.03, .95); }
}
/* Happy: glowing gold, a little hop every couple of seconds, and twinkling sparkles. */
.adv-lock-open {
  filter: drop-shadow(0 0 4px rgba(255, 232, 140, .95)) drop-shadow(0 3px 3px rgba(120, 60, 0, .35));
  animation: adv-happy 2.4s ease-in-out infinite;
}
@keyframes adv-happy {
  0%, 58%, 100% { transform: none; }
  68% { transform: translateY(-12%) rotate(-5deg); }
  78% { transform: scale(1.07, .93); }
  88% { transform: translateY(-4%) rotate(4deg); }
}
.adv-door.is-done .adv-lock::before, .adv-door.is-done .adv-lock::after {
  content: "✦"; position: absolute; color: #fffbe6; line-height: 1; pointer-events: none;
  text-shadow: 0 0 4px rgba(255, 240, 170, .95); animation: adv-twinkle-star 1.6s ease-in-out infinite;
}
.adv-door.is-done .adv-lock::before { top: -6%; left: -18%; font-size: clamp(6px, 9cqmin, 16px); }
.adv-door.is-done .adv-lock::after { bottom: 8%; right: -22%; font-size: clamp(5px, 7cqmin, 13px); animation-delay: -.8s; }
@keyframes adv-twinkle-star { 0%, 100% { opacity: .2; transform: scale(.6) rotate(0); } 50% { opacity: 1; transform: scale(1.1) rotate(20deg); } }

/* The door itself: the same pixels as the painting beneath, so it is invisible until it moves. */
.adv-flap { transform-origin: var(--o); transition: transform .85s cubic-bezier(.3, 1.2, .45, 1), filter .3s; will-change: transform; }
.adv-flap-img { background-image: var(--board); background-repeat: no-repeat; }

/* How each object opens (src/advent-board.js picks one per door). --peek is the hover hint, --open the opened pose. */
.adv-door[data-opens="left"] { --o: 0% 50%; --open: rotateY(-76deg); --peek: rotateY(-16deg); }
.adv-door[data-opens="right"] { --o: 100% 50%; --open: rotateY(76deg); --peek: rotateY(16deg); }
.adv-door[data-opens="top"] { --o: 50% 0%; --open: rotateX(72deg); --peek: rotateX(16deg); }
.adv-door[data-opens="bottom"] { --o: 50% 100%; --open: rotateX(-72deg); --peek: rotateX(-16deg); }
.adv-door[data-opens="hang"] { --o: 50% 0%; --open: rotate(58deg); --peek: rotate(7deg); }
.adv-door[data-opens="lift"] { --o: 50% 100%; --open: translate(-34%, -58%) rotate(-12deg) scale(1.05); --peek: translateY(-9%) rotate(-3deg); }
.adv-door[data-opens="roll"] { --o: 50% 50%; --open: translateX(-105%); --peek: translateX(-5%); }
.adv-door[data-opens="slide"] { --o: 50% 50%; --open: translate(-62%, 6%) rotate(-3deg); --peek: translateX(-4%); }

.adv-door:not(.is-locked):hover .adv-flap {
  transform: var(--peek);
  filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 7px rgba(255, 214, 120, .95));
}
.adv-door.is-locked:hover .adv-flap { filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 5px rgba(255, 255, 255, .7)); }
.adv-door.is-open .adv-flap, .adv-door.is-opened .adv-flap, .adv-door.is-opened:hover .adv-flap {
  transform: var(--open); filter: drop-shadow(0 12px 10px rgba(30, 15, 5, .45));
}
/* Opened things keep moving a little: lifted ones hover, hung ones sway on their hook. */
.adv-door[data-opens="lift"].is-opened .adv-flap { animation: adv-float 3.2s ease-in-out infinite; }
.adv-door[data-opens="hang"].is-opened .adv-flap { animation: adv-sway 2.8s ease-in-out infinite; }
@keyframes adv-float { 50% { transform: var(--open) translateY(-5%); } }
@keyframes adv-sway { 50% { transform: var(--open) rotate(-5deg); } }

.adv-door.is-shake .adv-flap { animation: adv-rattle .5s; }
@keyframes adv-rattle {
  0%, 100% { transform: none; }
  20% { transform: var(--peek) rotate(-2deg); }
  40% { transform: rotate(2deg); }
  60% { transform: var(--peek) rotate(-1.5deg); }
  80% { transform: rotate(1deg); }
}

/* Closing gets its own motion rather than the opening curve played backwards (whose overshoot made a shutting door
   wobble past closed): it swings back accelerating, like something falling shut, then lands with a small thud
   (.is-shut, added by advent.js when the swing ends). The hollow stays lit until the door covers it again. The
   :hover twin outranks the hover peek, so a pointer resting on the door can't hold it ajar while it shuts. */
.adv-door.is-closing .adv-flap, .adv-door.is-closing:hover .adv-flap {
  transform: none; filter: none;
  transition: transform .48s cubic-bezier(.55, 0, .85, .35), filter .2s;
}
.adv-door.is-closing .adv-hole { opacity: 1; }
.adv-door.is-shut .adv-flap { animation: adv-shut .38s ease-out; }
@keyframes adv-shut {
  35% { transform: scale(1.03, .97); }
  70% { transform: scale(.99, 1.01); }
}


/* Where hacking stops (the games, not the site): quiet, but readable, right under the board. */
.adv-scope { max-width: 46em; margin: 22px 4px 0; font-size: 14.5px; line-height: 1.55; color: var(--gray); }
.adv-scope a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.adv-foot { margin: 10px 4px 0; font-size: 13px; }

/* ---------- Dialog: one day's window, an open advent card ----------
   Opened under the site's nav, never over it (public/advent.js opens it non-modal and sizes it to the nav), so the
   Plango nav stays in view and usable. The card is two pages of paper: on the left a letter from Plango (mission,
   the lesson as a partly shown article, a P.S. with nudges and AI help, the share preview); on the right the game,
   with the answer present at its corner. Each page scrolls on its own. Phones get one column (media query below). */
.adv-backdrop {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; top: var(--adv-nav-h, 69px);
  background: rgba(16, 26, 22, .55); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  animation: adv-fade .35s ease;
}
@keyframes adv-fade { from { opacity: 0; } }
.adv-dialog {
  position: fixed; z-index: 31; inset: calc(var(--adv-nav-h, 69px) + 14px) 0 14px; width: min(1560px, calc(100vw - 120px)); height: auto;
  max-width: none; max-height: none; margin: 0 auto; padding: 0; border: 0; background: transparent; overflow: visible; color: #2a2118;
}
.adv-dialog:not([open]) { display: none; }
/* The paper keeps its own light colours whatever the site theme, so the share preview and buttons inside read as
   printed on the card. */
.adv-card {
  --card: #fffaf0; --bg: #fffaf0; --bg-subtle: #f4e7cd; --panel: #efe0c2; --line: #e3d2b1; --line-strong: #cdb48a;
  --ink: #2a2118; --gray: #5c4a36; --dim: #7a6650;
  position: relative; display: flex; flex-direction: column; height: 100%; overflow: hidden; border-radius: 8px; color: var(--ink);
  background:
    radial-gradient(rgba(120, 80, 30, .05) 1px, transparent 1.4px) 0 0 / 7px 7px,
    #f7ead2;
  box-shadow: 0 40px 80px -24px rgba(0, 0, 0, .6), 0 0 0 1px rgba(90, 60, 20, .14);
}
.adv-card.is-in { animation: adv-card-in .6s cubic-bezier(.2, 1.25, .4, 1); }
@keyframes adv-card-in { from { transform: scale(.15); opacity: 0; } 40% { opacity: 1; } }
.adv-slot { flex: 1; min-height: 0; overflow: hidden; }
.adv-slot.is-swap-next { animation: adv-swap-next .45s var(--ease-out); }
.adv-slot.is-swap-prev { animation: adv-swap-prev .45s var(--ease-out); }
@keyframes adv-swap-next { from { transform: translateX(40px); opacity: 0; } }
@keyframes adv-swap-prev { from { transform: translateX(-40px); opacity: 0; } }
.adv-close {
  position: absolute; z-index: 8; top: 10px; right: 12px; width: 36px; height: 36px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: rgba(255, 250, 240, .9); color: var(--dim); font-size: 24px; line-height: 1; cursor: pointer;
  transition: transform .2s, color .2s;
}
.adv-close:hover { transform: rotate(90deg); color: var(--ink); }
/* The day before and after: links in the margin either side of the card, like turning a book's page. The arrow is in
   the bold sans (Instrument Serif has no bold), so it reads at a glance on the dark backdrop. */
.adv-turn {
  position: absolute; z-index: 9; top: 50%; width: 56px; display: grid; justify-items: center; gap: 2px; padding: 10px 0;
  border: 0; background: none; color: #fbf1dc; cursor: pointer; transform: translateY(-50%);
  font: italic 17px/1.1 var(--serif); text-shadow: 0 1px 6px rgba(0, 0, 0, .45); transition: transform .2s, color .2s;
}
.adv-turn::before { font: 800 40px/1 var(--sans); font-style: normal; }
.adv-turn-prev { left: -60px; }
.adv-turn-prev::before { content: '‹'; }
.adv-turn-next { right: -60px; }
.adv-turn-next::before { content: '›'; }
.adv-turn:hover, .adv-turn:focus-visible { color: #fff; text-decoration: underline; text-underline-offset: 3px; }
.adv-turn-prev:hover { transform: translate(-3px, -50%); }
.adv-turn-next:hover { transform: translate(3px, -50%); }
.adv-turn[hidden] { display: none; }
/* Scrollbars, where a page still needs one (short windows, big text): thin and warm, on the paper. */
.adv-letter, .adv-play-scroll, .adv-slot { scrollbar-width: thin; scrollbar-color: rgba(122, 102, 80, .38) transparent; }
.adv-letter::-webkit-scrollbar, .adv-play-scroll::-webkit-scrollbar, .adv-slot::-webkit-scrollbar { width: 8px; }
.adv-letter::-webkit-scrollbar-track, .adv-play-scroll::-webkit-scrollbar-track, .adv-slot::-webkit-scrollbar-track { background: transparent; }
.adv-letter::-webkit-scrollbar-thumb, .adv-play-scroll::-webkit-scrollbar-thumb, .adv-slot::-webkit-scrollbar-thumb { border-radius: 8px; background: rgba(122, 102, 80, .32); border: 2px solid transparent; background-clip: padding-box; }

/* Letter and game split the card evenly. */
.adv-post { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

/* ---- Left page: the letter ---- */
.adv-letter {
  position: relative; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 24px clamp(32px, 3.4vw, 60px) 26px;
  box-shadow: inset -34px 0 40px -34px rgba(90, 60, 20, .35);
}
.adv-seal {
  position: absolute; top: 18px; right: 22px; width: 50px; height: 50px; display: grid; place-items: center; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d94a5d, #a8233a 60%, #6e1222); color: #fbe6c9; font: 400 26px/1 var(--serif);
  box-shadow: 0 6px 12px rgba(80, 10, 20, .3), inset 0 0 0 5px rgba(255, 255, 255, .08); transform: rotate(-8deg);
}
/* Plango stands beside the date and title, not above them, to keep the letter short. */
.adv-letter-head { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: end; gap: 14px; margin-right: 46px; }
.adv-letter-plango { display: block; height: 92px; width: auto; margin: 0 0 -2px -8px; filter: drop-shadow(0 10px 12px rgba(80, 50, 10, .26)); animation: adv-plango-in .9s cubic-bezier(.3, 1.4, .5, 1) both; }
.adv-letter-plango.is-jump { animation: adv-jump .9s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes adv-plango-in { from { opacity: 0; transform: translateY(18px) scale(.9); } }
@keyframes adv-jump {
  0% { transform: none; }
  20% { transform: scale(1.06, .92); }
  50% { transform: translateY(-26px) rotate(-6deg); }
  75% { transform: translateY(0) scale(1.04, .96); }
  100% { transform: none; }
}
.adv-date { margin: 0; font: italic 18px var(--serif); color: var(--dim); }
.adv-letter h2 { margin: 0; font: 400 clamp(30px, 2.7vw, 40px)/1.02 var(--serif); letter-spacing: -.01em; color: var(--ink); }
.adv-mission { margin: 10px 0 0; font: italic 18px/1.4 var(--serif); color: var(--ink); }
.adv-letter h3 { margin: 0 0 4px; font: 400 20px/1.15 var(--serif); color: var(--ink); }
.adv-letter p { font-size: 14.5px; line-height: 1.6; }
.adv-letter code { padding: 1px 5px; border-radius: 4px; background: var(--panel); font: 13.5px var(--mono); }

/* The lesson, shown like a news article: the start, fading out, until "Keep reading". */
.adv-lesson { margin-top: 16px; }
.adv-lesson-body p { margin: 0 0 10px; }
.adv-lesson-body pre { margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; background: #2a2118; color: #f1e4c8; font: 12.5px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.adv-lesson:not(.is-open) .adv-lesson-body {
  max-height: 3.4em; overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 30%, transparent); mask-image: linear-gradient(#000 30%, transparent);
}
.adv-lesson-more {
  display: inline-flex; align-items: baseline; gap: 8px; margin-top: 2px; padding: 0; border: 0; background: none; cursor: pointer;
  font: 600 14px var(--sans); color: #234d3a; text-decoration: underline; text-underline-offset: 4px;
}
.adv-lesson-more span { font-weight: 400; color: var(--dim); text-decoration: none; }

/* Revealed under the game once it's solved. */
.adv-takeaway:not([hidden]) {
  display: block; margin: 18px 0 0; padding: 12px 16px 14px; border-radius: 6px;
  background: rgba(31, 122, 85, .1); border-left: 3px solid #1f7a55;
  animation: adv-pop-in .5s cubic-bezier(.3, 1.6, .5, 1);
}
.adv-takeaway h3 { font: 600 15px var(--sans) !important; color: #1f6447 !important; }
.adv-takeaway p { margin: 0; }

.adv-letter-bottom { margin-top: 12px; }
.adv-signoff { display: flex; align-items: center; gap: 8px; margin: 0; font: italic 17px var(--serif) !important; color: var(--dim); }
.adv-signoff img { width: 24px; height: auto; }
/* The P.S. line is the toggle (no marker, no link styling): the nudges and the AI help unfold under it. */
.adv-ps { margin-top: 12px; padding-top: 10px; border-top: 1px dashed rgba(90, 60, 20, .35); }
.adv-ps summary { cursor: pointer; list-style: none; font: italic 16.5px/1.4 var(--serif); color: var(--gray); }
.adv-ps summary::-webkit-details-marker { display: none; }
.adv-ps summary b { font-style: normal; color: var(--ink); }
.adv-ps summary:hover, .adv-ps[open] summary { color: var(--ink); }
.adv-nudges ul { margin: 8px 0 2px; padding-left: 20px; }
.adv-nudges li { margin: 4px 0; font: italic 16.5px/1.4 var(--serif); color: var(--ink); }
/* AI help on one line: the sentence, then small buttons. */
.adv-ai { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 8px; }
.adv-ai > p { margin: 0; font-size: 13.5px !important; color: var(--gray); }
.adv-ai-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin: 0; }
.adv-ai-actions .btn { height: 30px; padding: 0 12px; font-size: 12.5px; }
.adv-ai-actions .btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.adv-md { font-size: 12.5px; color: var(--dim); }
/* The share preview, compact on the letter: the link card goes side by side, the buttons get smaller. */
/* No box of its own on the letter (solved or not): just the white mock post and the buttons, under a dashed line. */
.adv-letter .adv-share, .adv-letter .adv-share.is-solved { margin-top: 14px; padding: 2px 0 0; border: 0; border-top: 1px dashed rgba(90, 60, 20, .35); border-radius: 0; background: none; }
.adv-letter .adv-share h3 { margin: 10px 0 0 !important; font: 400 19px/1.2 var(--serif) !important; letter-spacing: 0 !important; text-transform: none !important; color: var(--ink) !important; }
.adv-letter .adv-share-preview { margin: 8px 0 10px; padding: 9px 11px; }
.adv-letter .adv-share-who { margin-bottom: 4px; gap: 6px; font-size: 12px; }
.adv-letter .adv-share-who > span:last-child { display: flex; gap: 6px; align-items: baseline; }
.adv-letter .adv-share-avatar { width: 20px; height: 20px; font-size: 0; }
.adv-letter .adv-share-text { margin: 0 0 8px !important; font-size: 13.5px !important; line-height: 1.45 !important; }
.adv-letter .adv-share-card { display: grid; grid-template-columns: 108px minmax(0, 1fr); align-items: center; }
.adv-letter .adv-share-card img { height: 100%; }
.adv-letter .adv-share-card div { padding: 6px 10px; }
.adv-letter .adv-share-card strong { font-size: 13px; }
.adv-letter .adv-share-nets { flex-wrap: nowrap; gap: 6px; }
.adv-letter .adv-net.adv-net-logo { flex: none; width: 30px; height: 30px; }
.adv-letter .adv-net-logo svg { width: 14px; height: 14px; }
.adv-letter .adv-net-facebook svg { width: 10px; }
.adv-letter .adv-net-copy, .adv-letter .adv-net-more { flex: none; padding: 5px 10px; font-size: 12px; }
/* Copy text sits at the far end, away from the network logos. */
.adv-letter .adv-net-copy { margin-left: auto; }
.adv-letter .adv-share-note { min-height: 0; margin-top: 4px !important; }

/* ---- Right page: the game ---- */
.adv-stage { position: relative; min-height: 0; box-shadow: inset 34px 0 40px -34px rgba(90, 60, 20, .35); }
.adv-play-scroll { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px clamp(22px, 2.6vw, 44px) 100px; }
/* The game's own sandboxed page, on the card's paper (kit.css drops its own background inside the calendar). It
   reports its content height and the frame takes it (public/advent.js, 240-4000px), so the page has one scrollbar. */
.adv-game { display: block; width: 100%; height: 480px; margin: 0; border: 0; background: transparent; color-scheme: light; transition: height .25s var(--ease-out); }

/* ---------- The answer present ----------
   Parked at the play column's bottom-right corner (it doesn't scroll with the game). Closed, it bobs with a label;
   clicked, the lid pops off and the answer box slides out above it. Solved, it stays open and a gold key floats up
   out of it. */
.adv-present {
  position: absolute; z-index: 6; right: 18px; bottom: 12px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px; pointer-events: none;
}
.adv-present > * { pointer-events: auto; }
.adv-present-btn {
  display: flex; align-items: center; gap: 10px; padding: 0; border: 0; background: none; color: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.adv-present-btn:focus-visible { outline: none; }
.adv-present-btn:focus-visible .adv-present-label { outline: 3px solid var(--gold); outline-offset: 2px; }
.adv-present-label {
  position: relative; padding: 8px 14px; border-radius: 999px; background: #1d1a16; color: #fff;
  font: 600 13.5px var(--sans); white-space: nowrap; box-shadow: 0 8px 20px -8px rgba(0, 0, 0, .45);
  transition: transform .2s;
}
.adv-present-label::after {
  content: ""; position: absolute; right: -6px; top: 50%; margin-top: -6px;
  border: 6px solid transparent; border-right: 0; border-left-color: #1d1a16;
}
.adv-present-btn:hover .adv-present-label { transform: translateX(-3px); }
.adv-present-gift {
  position: relative; width: 70px; height: 70px; flex: none;
  filter: drop-shadow(0 10px 12px rgba(80, 20, 20, .35));
  animation: adv-present-bob 3s ease-in-out infinite;
}
.adv-present-gift svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.adv-present-lid { transform-origin: 20% 48%; transition: transform .45s cubic-bezier(.3, 1.6, .5, 1); }
.adv-present-btn:hover .adv-present-lid { transform: translateY(-5px) rotate(-5deg); }
@keyframes adv-present-bob {
  0%, 70%, 100% { transform: none; }
  78% { transform: rotate(-6deg) translateY(-4px); }
  86% { transform: rotate(5deg); }
  93% { transform: rotate(-2deg); }
}
/* Open: the lid flies up and off to the side, a glow rises out of the box. */
.adv-present.is-open .adv-present-gift, .adv-present.is-solved .adv-present-gift { animation: none; }
.adv-present.is-open .adv-present-lid, .adv-present.is-solved .adv-present-lid { transform: translate(-16px, -26px) rotate(-32deg); }
.adv-present.is-open .adv-present-gift::before, .adv-present.is-solved .adv-present-gift::before {
  content: ""; position: absolute; left: 18%; right: 18%; top: 18%; bottom: 46%; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 236, 160, .95), rgba(255, 210, 90, 0));
  animation: adv-present-glow 1.6s ease-in-out infinite alternate;
}
@keyframes adv-present-glow { from { opacity: .55; transform: scale(.9); } to { opacity: 1; transform: scale(1.12); } }
/* The key: hidden down in the box until the day is solved, then it rises out and bobs gently, glowing. A click on a
   solved present makes it hop (.is-hop, advent.js). */
.adv-present-key { opacity: 0; transform: translateY(30%) scale(.8); }
.adv-present.is-solved .adv-present-key {
  opacity: 1; transform: translateY(-38%);
  filter: drop-shadow(0 0 5px rgba(255, 214, 110, .95));
  animation: adv-key-rise .9s cubic-bezier(.3, 1.5, .5, 1) both, adv-key-float 3s ease-in-out .9s infinite;
}
.adv-present.is-solved.is-hop .adv-present-key { animation: adv-key-hop .6s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes adv-key-rise { from { opacity: 0; transform: translateY(30%) scale(.8); } }
@keyframes adv-key-float { 50% { transform: translateY(-46%) rotate(-5deg); } }
@keyframes adv-key-hop { 40% { transform: translateY(-62%) rotate(8deg) scale(1.08); } }
.adv-present.is-solved .adv-present-label { background: #8a5a06; }
/* The cookie banner (ads.js) sits in the bottom-right corner until a choice is made; keep the present above it. */
body:has(> .ad-consent) .adv-present { bottom: 76px; }
.adv-present.is-solved .adv-present-label::after { border-left-color: #8a5a06; }

.adv-present-panel {
  position: relative; display: none; width: min(380px, calc(100vw - 40px)); margin-right: 14px; padding: 14px 18px 12px;
  border-radius: 18px; background: var(--card); border: 2px solid #e0a83a;
  box-shadow: 0 24px 48px -16px rgba(40, 20, 0, .45); transform-origin: 85% 110%;
}
.adv-present.is-open .adv-present-panel { display: block; animation: adv-present-out .45s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes adv-present-out { from { opacity: 0; transform: translateY(24px) scale(.4); } }
.adv-present-panel::after {
  content: ""; position: absolute; right: 36px; bottom: -11px; width: 18px; height: 18px; transform: rotate(45deg);
  background: var(--card); border-right: 2px solid #e0a83a; border-bottom: 2px solid #e0a83a;
}
.adv-present-panel h3 { margin: 2px 0 10px !important; font: 400 26px/1.1 var(--serif) !important; letter-spacing: 0 !important; text-transform: none !important; color: var(--ink) !important; }
.adv-present-kicker { margin: 0 !important; font-size: 11px !important; letter-spacing: .1em; text-transform: uppercase; color: #a86f0e; }
.adv-present-x {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border: 0; border-radius: 50%;
  background: var(--bg-subtle); color: var(--dim); font-size: 18px; line-height: 1; cursor: pointer;
}
.adv-present-form { display: flex; gap: 8px; }
.adv-present-input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 1.5px solid var(--line-strong);
  background: var(--bg); color: var(--ink); font: 15px var(--mono);
}
.adv-present-input:focus { outline: none; border-color: #e0a83a; box-shadow: 0 0 0 3px rgba(224, 168, 58, .3); }
.adv-present-form .btn { padding: 9px 16px; font-size: 14px; }
.adv-present-msg { min-height: 1.4em; margin-top: 6px !important; font-size: 13.5px !important; color: var(--dim); }
.adv-present-panel.is-shake { animation: adv-present-shake .45s; }
@keyframes adv-present-shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }

/* The clock-hack easter egg: the time-machine picture and its note, at the top of the letter (advent.js puts it
   there). The picture arrives with a brief glitch. */
.adv-hacked { margin-top: 16px; overflow: hidden; border-radius: 14px; background: #0d1418; color: #d8efe0; font-size: 14px; }
.adv-hacked-art { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; object-position: 50% 40%; animation: adv-glitch .6s steps(2) 2; }
.adv-hacked-text { padding: 14px 16px 16px; border-bottom: 3px solid #38c97e; }
.adv-hacked strong { display: block; margin-bottom: 6px; font: 600 15px var(--mono); color: #63e6a4; }
.adv-hacked p { font-size: 14px !important; color: inherit; }
.adv-hacked a { color: #8cc4ff; }
.adv-hacked-proof { margin-top: 10px !important; font-size: 11.5px !important; color: #77b48d !important; word-break: break-word; }
@keyframes adv-glitch {
  0% { transform: translate(0); filter: hue-rotate(0); }
  25% { transform: translate(-2px, 1px); filter: hue-rotate(40deg); }
  50% { transform: translate(2px, -1px); }
  75% { transform: translate(-1px, 0); filter: hue-rotate(-30deg); }
}

/* Phones and narrow windows: one column under the nav that scrolls as a whole. The letter's top (title, mission,
   lesson) comes first, then the game, then the P.S. and sharing; the present floats above the footer. */
@media (max-width: 900px) {
  .adv-dialog { inset: var(--adv-nav-h, 63px) 0 0; width: 100vw; }
  .adv-card { border-radius: 0; }
  .adv-slot { overflow-y: auto; overscroll-behavior: contain; }
  .adv-post { height: auto; display: flex; flex-direction: column; }
  .adv-letter { display: contents; }
  .adv-letter-top { position: relative; order: 1; padding: 20px 18px 6px; }
  .adv-stage { order: 2; box-shadow: none; border-top: 1px dashed rgba(90, 60, 20, .3); }
  .adv-letter-bottom { order: 3; margin: 0; padding: 4px 18px 120px; }
  .adv-play-scroll { position: static; overflow: visible; padding: 12px 8px 18px; }
  .adv-seal { top: 46px; right: 18px; width: 50px; height: 50px; font-size: 26px; }
  .adv-letter-plango { height: 110px; }
  .adv-letter h2 { margin-right: 56px; font-size: 34px; }
  .adv-mission { font-size: 20px; }
  .adv-present { position: fixed; right: 12px; bottom: 14px; }
  .adv-present-gift { width: 66px; height: 66px; }
  .adv-present-label { padding: 8px 12px; font-size: 13px; }
  /* No margin beside the card on a phone: the page-turn links sit small in its top corners. */
  .adv-turn { top: 8px; width: auto; display: flex; align-items: baseline; gap: 4px; padding: 6px 8px; transform: none; color: var(--dim); font-size: 14px; text-shadow: none; }
  .adv-turn::before { font-size: 22px; }
  .adv-turn-prev { left: 6px; }
  .adv-turn-next { right: 50px; flex-direction: row-reverse; }
  .adv-turn:hover, .adv-turn:focus-visible { color: var(--ink); transform: none; }
  .adv-turn-prev:hover, .adv-turn-next:hover { transform: none; }
  .adv-letter-top { padding-top: 40px; }
}

/* Toast and confetti */
.adv-toast {
  position: fixed; z-index: 50; left: 50%; bottom: 24px; max-width: calc(100vw - 32px);
  padding: 11px 18px; border-radius: 99px; background: #18241e; color: #fff; font-size: 14.5px;
  box-shadow: 0 12px 30px -8px rgba(0, 0, 0, .5);
  transform: translate(-50%, 160%); opacity: 0; visibility: hidden;
  transition: transform .45s cubic-bezier(.3, 1.4, .5, 1), opacity .25s, visibility 0s .45s;
}
.adv-toast.is-on { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition: transform .45s cubic-bezier(.3, 1.4, .5, 1), opacity .25s; }
.adv-dialog .adv-toast { bottom: 18px; }
.adv-bit { position: fixed; z-index: 60; pointer-events: none; will-change: transform, opacity; }
.adv-bit.scale { width: 12px; height: 15px; border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%; background: var(--c); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .15); }
.adv-bit.flake { color: #fff; font-size: 16px; text-shadow: 0 0 4px rgba(120, 160, 220, .9); }

/* Konami: a pangolin rolls across the bottom of the screen. */
.adv-roller { position: fixed; z-index: 40; bottom: 8px; left: 0; height: 120px; pointer-events: none; animation: adv-roll-across 3.2s cubic-bezier(.4, 0, .6, 1) forwards; }
@keyframes adv-roll-across {
  from { transform: translateX(-160px) rotate(0); }
  to { transform: translateX(calc(100vw + 40px)) rotate(1440deg); }
}

@media (max-width: 820px) {
  .adv-hero { grid-template-columns: 1fr; grid-template-rows: auto; }
  .adv-hero-copy { padding-top: 16px; }
  .adv-progress { grid-row: 3; justify-self: start; margin-top: 10px; gap: 8px; }
  .adv-ornaments { gap: 2px; }
  .adv-ornaments li { width: 8px; height: 8px; }
  .adv-hero-art { grid-column: 1; grid-row: 2; justify-content: flex-end; margin-top: 24px; padding-top: 60px; }
  .adv-hero-mascot { height: 200px; }
  .adv-bubble { right: 68%; max-width: 236px; }
}
@media (max-width: 720px) {
  .adv-lede { font-size: 16.5px; }
  .adv-sign { margin: 6px 0 0 auto; }
  /* No room to the right of "Security" on a phone: HACKING goes just above it instead, like a correction. */
  .adv-hero-copy { padding-top: 34px; }
  .adv-hack-word { --hack-h: .66em; left: 12%; top: auto; bottom: 82%; transform: rotate(-5deg); }
  .adv { --board-w: calc(100vw - 16px); }
  .adv-board-scroll { overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; border-radius: 18px; }
  .adv-board-art { width: 900px; }
  .adv-board-hint { display: block; margin: 8px 4px 0; font-size: 12px; color: var(--dim); text-align: right; }
  .adv-md { margin-left: 0; }
}

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