/* =============================================================================================
   Advent Calendar framework — all styling.
   Theme it from the host page by overriding the --ac-* custom properties (docs/ARCHITECTURE.md §11).
   Class prefixes:  .ac (root)  .ac-door (tile)  .ac-dialog/.ac-scene/.ac-leaf/.ac-card (reveal)
                    .ac-puzzle (puzzle chrome)  .ac-btn/.ac-input/... (shared controls)  .ac-media
   ============================================================================================= */

:root {
  --ac-sky: #0d3447;
  --ac-sky-deep: #082330;
  --ac-sky-light: #175066;
  --ac-door: #0f3d52;
  --ac-door-edge: #0a2c3c;
  --ac-gold: #d4af5a;
  --ac-gold-deep: #b8923f;
  --ac-gold-light: #efd68a;
  --ac-cream: #f6ecd6;
  --ac-parchment: #fbf4e4;
  --ac-ink: #22302f;
  --ac-ink-soft: #4b5a58;
  --ac-correct: #2f7d4f;
  --ac-wrong: #b3412f;
  --ac-font-display: 'Outfit', 'Segoe UI', system-ui, sans-serif;
  --ac-font-serif: 'Fraunces', 'Cormorant Garamond', Georgia, serif;
  --ac-grid-max: 760px;
  --ac-gap: clamp(10px, 2.5vw, 22px);
  --ac-min-height: 100dvh;
}

/* ------------------------------------------------------------------ root, backdrop, heading */

advent-calendar {
  display: block;
}

.ac,
.ac *,
.ac *::before,
.ac *::after {
  box-sizing: border-box;
}

.ac [hidden] {
  display: none !important;
}

.ac {
  position: relative;
  isolation: isolate;
  min-height: var(--ac-min-height);
  padding: clamp(28px, 6vw, 64px) 16px clamp(48px, 8vw, 96px);
  background: linear-gradient(180deg, var(--ac-sky-deep) 0%, var(--ac-sky) 48%, var(--ac-sky-light) 100%);
  color: var(--ac-cream);
  font-family: var(--ac-font-display);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.ac-error {
  padding: 16px;
  font-family: var(--ac-font-display);
  color: #fff;
  background: #7a2e22;
}

.ac__backdrop {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.ac__image {
  position: absolute;
  inset: 0;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

.ac__stars,
.ac__stars::before,
.ac__stars::after {
  content: '';
  position: absolute;
  inset: 0;
  background-repeat: repeat;
}

.ac__stars {
  opacity: 0.85;
  background-image:
    radial-gradient(1px 1px at 18px 32px, rgba(255, 255, 255, 0.95), transparent),
    radial-gradient(1px 1px at 92px 110px, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1.3px 1.3px at 140px 46px, rgba(255, 255, 255, 0.85), transparent),
    radial-gradient(1px 1px at 210px 160px, rgba(255, 255, 255, 0.6), transparent),
    radial-gradient(1px 1px at 60px 204px, rgba(255, 255, 255, 0.75), transparent),
    radial-gradient(1.3px 1.3px at 252px 22px, rgba(255, 255, 255, 0.8), transparent),
    radial-gradient(1px 1px at 172px 240px, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1px 1px at 118px 268px, rgba(255, 255, 255, 0.65), transparent);
  background-size: 280px 280px;
}

.ac__stars::before {
  background-image:
    radial-gradient(1px 1px at 40px 70px, rgba(255, 255, 255, 0.9), transparent),
    radial-gradient(1.5px 1.5px at 300px 140px, rgba(255, 255, 255, 0.9), transparent),
    radial-gradient(1px 1px at 190px 330px, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1.2px 1.2px at 380px 40px, rgba(255, 255, 255, 0.8), transparent),
    radial-gradient(1px 1px at 120px 400px, rgba(255, 255, 255, 0.6), transparent),
    radial-gradient(1px 1px at 260px 250px, rgba(255, 255, 255, 0.7), transparent);
  background-size: 430px 430px;
  animation: ac-twinkle 5s ease-in-out infinite alternate;
}

.ac__stars::after {
  background-image:
    radial-gradient(2px 2px at 160px 90px, rgba(239, 214, 138, 0.95), transparent),
    radial-gradient(1.6px 1.6px at 480px 300px, rgba(255, 255, 255, 0.9), transparent),
    radial-gradient(2px 2px at 360px 520px, rgba(239, 214, 138, 0.8), transparent),
    radial-gradient(1.6px 1.6px at 60px 440px, rgba(255, 255, 255, 0.85), transparent);
  background-size: 620px 620px;
  animation: ac-twinkle 7s ease-in-out infinite alternate-reverse;
}

.ac__vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 72% 62% at 50% 42%, transparent 45%, rgba(2, 12, 18, 0.55) 100%);
}

@keyframes ac-twinkle {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

.ac__header {
  max-width: var(--ac-grid-max);
  margin: 0 auto clamp(14px, 3vw, 24px);
  text-align: center;
}

.ac__title {
  margin: 0 0 0.3em;
  font-family: var(--ac-font-display);
  font-weight: 700;
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--ac-cream);
  text-wrap: balance;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.35);
}

.ac__subtitle {
  margin: 0;
  font-family: var(--ac-font-serif);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(1.05rem, 2.4vw, 1.4rem);
  color: var(--ac-gold);
}

.ac__status {
  max-width: var(--ac-grid-max);
  margin: 0 auto clamp(22px, 4vw, 36px);
  text-align: center;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(246, 236, 214, 0.78);
}

.ac__status:empty {
  display: none;
}

.ac__countdown {
  display: block;
  margin-top: 0.35em;
  font-family: var(--ac-font-serif);
  font-style: italic;
  font-size: 1.45em;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--ac-gold-light);
}

/* ------------------------------------------------------------------------------- the grid */

.ac-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--ac-gap);
  max-width: var(--ac-grid-max);
  margin: 0 auto;
  padding: 0;
  list-style: none;
}

.ac-grid__item {
  display: block;
  min-width: 0;
}

/* A lone last door on the 3-column grid (25 = 3 × 8 + 1) sits in the centre column. */
@media (max-width: 639.98px) {
  .ac-grid > .ac-grid__item:nth-child(3n + 1):last-child {
    grid-column: 2;
  }
}

@media (min-width: 640px) {
  .ac-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

/* ------------------------------------------------------------------------- door artwork
   Shared by grid tiles (.ac-door) and the dialog's door leaves (.ac-leaf). Each is a container,
   so the notch, inset and numeral scale with the door's own width (cqw units).
   Layers, back to front:
     .ac-door__shape::before  gold silhouette        (outer gold line)
     .ac-door__shape::after   teal fill, inset --door-line (door panel)
     .ac-door__frame          gold, inset further    (inner gold line)
     .ac-door__frame::before  teal fill, inset 1.5px
   The silhouette is a notched rectangle (clip-path) or an arch (border-radius); the inner layers
   reuse the same values with a smaller box, so the gold lines follow the shape exactly. */

.ac-door,
.ac-leaf {
  --door-notch: clamp(6px, 8cqw, 12px);
  --door-inset: clamp(6px, 6.5cqw, 10px);
  --door-radius: 0px;
  --door-clip: polygon(
    var(--door-notch) 0,
    calc(100% - var(--door-notch)) 0,
    calc(100% - var(--door-notch)) var(--door-notch),
    100% var(--door-notch),
    100% calc(100% - var(--door-notch)),
    calc(100% - var(--door-notch)) calc(100% - var(--door-notch)),
    calc(100% - var(--door-notch)) 100%,
    var(--door-notch) 100%,
    var(--door-notch) calc(100% - var(--door-notch)),
    0 calc(100% - var(--door-notch)),
    0 var(--door-notch),
    var(--door-notch) var(--door-notch)
  );
  --door-line: clamp(2px, 2.2cqw, 3.5px);
  --door-gold: linear-gradient(160deg, var(--ac-gold-light) 0%, var(--ac-gold) 45%, var(--ac-gold-deep) 100%);
  --door-fill:
    radial-gradient(ellipse 90% 70% at 50% 42%, rgba(255, 255, 255, 0.06), transparent 70%),
    linear-gradient(180deg, var(--ac-door) 0%, var(--ac-door) 45%, var(--ac-door-edge) 100%);
  --door-num: var(--ac-gold);
  position: relative;
  container-type: inline-size;
  color: var(--ac-gold);
}

.ac-door__shape,
.ac-door__frame {
  position: absolute;
  pointer-events: none;
}

.ac-door__shape {
  inset: 0;
  z-index: 0;
  transition: filter 0.3s ease;
}

.ac-door__shape::before,
.ac-door__shape::after,
.ac-door__frame,
.ac-door__frame::before {
  content: '';
  clip-path: var(--door-clip);
  border-radius: var(--door-radius) var(--door-radius) 0 0;
}

.ac-door__shape::before,
.ac-door__shape::after {
  position: absolute;
  inset: 0;
}

.ac-door__shape::before {
  background: var(--door-gold);
}

.ac-door__shape::after {
  inset: var(--door-line);
  background: var(--door-fill);
  border-radius: max(0px, calc(var(--door-radius) - var(--door-line))) max(0px, calc(var(--door-radius) - var(--door-line))) 0 0;
  transition: background 0.3s ease;
}

.ac-door__frame {
  inset: var(--door-inset);
  z-index: 1;
  background: var(--door-gold);
  border-radius: max(0px, calc(var(--door-radius) - var(--door-inset))) max(0px, calc(var(--door-radius) - var(--door-inset))) 0 0;
  transition: transform 0.4s ease;
}

.ac-door__frame::before {
  position: absolute;
  inset: 1.5px;
  background: var(--door-fill);
  border-radius: max(0px, calc(var(--door-radius) - var(--door-inset) - 1.5px)) max(0px, calc(var(--door-radius) - var(--door-inset) - 1.5px)) 0 0;
}

.ac-door__hinge {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 7px;
  z-index: 2;
  pointer-events: none;
}

.ac-door__hinge--left { left: -1px; }
.ac-door__hinge--right { right: -1px; }

.ac-door__hinge::before,
.ac-door__hinge::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  height: 13%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--ac-gold-deep), var(--ac-gold-light) 60%, var(--ac-gold));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.ac-door__hinge::before { top: 20%; }
.ac-door__hinge::after { bottom: 20%; }

.ac-door__star,
.ac-door__sprig,
.ac-door__num {
  position: absolute;
  left: 50%;
  z-index: 3;
  pointer-events: none;
  transform: translateX(-50%);
}

.ac-door__star {
  top: 13%;
  width: clamp(9px, 11cqw, 18px);
  color: var(--ac-gold-light);
  filter: drop-shadow(0 0 3px rgba(239, 214, 138, 0.7));
}

.ac-door__sprig {
  bottom: 11%;
  width: clamp(28px, 40cqw, 56px);
  color: var(--ac-gold);
}

.ac-door__star svg,
.ac-door__sprig svg {
  display: block;
  width: 100%;
  height: auto;
}

.ac-door__num {
  top: 50%;
  transform: translate(-50%, -54%);
  font-family: var(--ac-font-serif);
  font-weight: 700;
  font-size: clamp(2rem, 43cqw, 3.9rem);
  line-height: 1;
  color: var(--door-num);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 0 14px rgba(212, 175, 90, 0.25);
  transition: color 0.3s ease;
  font-variant-numeric: lining-nums;
}

/* --------------------------------------------------------------------------- door tiles */

.ac-door {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.25s ease;
}

.ac-door:focus-visible {
  outline: 3px solid var(--ac-gold-light);
  outline-offset: 4px;
}

/* Arches in the centre column: 3 columns under 640px, 5 columns above. */
.ac-grid > .ac-grid__item:nth-child(3n + 2) .ac-door {
  --door-clip: none;
  --door-radius: 50cqw;
}

@media (min-width: 640px) {
  .ac-grid > .ac-grid__item:nth-child(3n + 2) .ac-door {
    --door-clip: polygon(
      var(--door-notch) 0,
      calc(100% - var(--door-notch)) 0,
      calc(100% - var(--door-notch)) var(--door-notch),
      100% var(--door-notch),
      100% calc(100% - var(--door-notch)),
      calc(100% - var(--door-notch)) calc(100% - var(--door-notch)),
      calc(100% - var(--door-notch)) 100%,
      var(--door-notch) 100%,
      var(--door-notch) calc(100% - var(--door-notch)),
      0 calc(100% - var(--door-notch)),
      0 var(--door-notch),
      var(--door-notch) var(--door-notch)
    );
    --door-radius: 0px;
  }

  .ac-grid > .ac-grid__item:nth-child(5n + 3) .ac-door {
    --door-clip: none;
    --door-radius: 50cqw;
  }
}

/* Explicit silhouettes win over the position rule. */
.ac-grid > .ac-grid__item .ac-door.ac-door--arch {
  --door-clip: none;
  --door-radius: 50cqw;
}

.ac-grid > .ac-grid__item .ac-door.ac-door--notched {
  --door-radius: 0px;
  --door-clip: polygon(
    var(--door-notch) 0,
    calc(100% - var(--door-notch)) 0,
    calc(100% - var(--door-notch)) var(--door-notch),
    100% var(--door-notch),
    100% calc(100% - var(--door-notch)),
    calc(100% - var(--door-notch)) calc(100% - var(--door-notch)),
    calc(100% - var(--door-notch)) 100%,
    var(--door-notch) 100%,
    var(--door-notch) calc(100% - var(--door-notch)),
    0 calc(100% - var(--door-notch)),
    0 var(--door-notch),
    var(--door-notch) var(--door-notch)
  );
}

.ac-door__badge {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: clamp(20px, 22cqw, 28px);
  height: clamp(20px, 22cqw, 28px);
  border-radius: 50%;
  background: var(--ac-gold);
  color: var(--ac-sky-deep);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.ac-door__badge svg {
  width: 62%;
  height: 62%;
}

/* Both badges sit in the top-right corner so the numeral stays readable (a door is never locked
   and solved at once, so they never meet). */
.ac-door__badge--lock,
.ac-door__badge--tick {
  top: 7%;
  right: 7%;
  transform: scale(0.8);
}

.ac-door__badge--lock {
  background: var(--ac-gold-light);
}

/* --- states --- */

.ac-door.is-locked {
  cursor: not-allowed;
  --door-num: rgba(212, 175, 90, 0.55);
}

.ac-door.is-locked .ac-door__shape {
  filter: saturate(0.5) brightness(0.72);
}

.ac-door.is-locked .ac-door__star,
.ac-door.is-locked .ac-door__sprig,
.ac-door.is-locked .ac-door__hinge {
  opacity: 0.5;
}

.ac-door.is-locked:hover .ac-door__badge--lock,
.ac-door.is-locked:focus-visible .ac-door__badge--lock {
  opacity: 1;
  transform: scale(1);
}

.ac-door.is-openable:hover,
.ac-door.is-openable:focus-visible {
  transform: translateY(-3px);
}

.ac-door.is-openable:hover .ac-door__shape,
.ac-door.is-openable:focus-visible .ac-door__shape {
  filter: brightness(1.1) drop-shadow(0 0 10px rgba(239, 214, 138, 0.5));
}

.ac-door.is-today .ac-door__shape {
  animation: ac-pulse 2.6s ease-in-out infinite;
}

.ac-door.is-opened {
  --door-num: var(--ac-cream);
}

.ac-door.is-opened .ac-door__shape {
  filter: drop-shadow(0 0 12px rgba(239, 214, 138, 0.55));
}

/* Warm light spilling from inside, and the inner panel swung slightly ajar. */
.ac-door.is-opened .ac-door__shape::after {
  background:
    radial-gradient(ellipse 70% 60% at 50% 55%, rgba(239, 214, 138, 0.55), rgba(212, 175, 90, 0.18) 55%, transparent 80%),
    var(--door-fill);
}

.ac-door.is-opened .ac-door__frame {
  transform: perspective(600px) rotateY(-14deg);
  transform-origin: left center;
  box-shadow: 6px 0 12px rgba(0, 0, 0, 0.4), 1px 0 0 rgba(0, 0, 0, 0.25);
}

.ac-door.is-opened .ac-door__num {
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 0 16px rgba(239, 214, 138, 0.8);
}

.ac-door.is-solved .ac-door__badge--tick {
  opacity: 1;
  transform: scale(1);
}

/* The final door is solid gold with a cream numeral. */
.ac-door--final {
  --door-fill: linear-gradient(165deg, var(--ac-gold-light) 0%, var(--ac-gold) 50%, var(--ac-gold-deep) 100%);
  --door-gold: linear-gradient(160deg, var(--ac-gold-deep) 0%, var(--ac-gold-light) 50%, var(--ac-gold-deep) 100%);
  --door-num: var(--ac-cream);
  color: var(--ac-cream);
}

.ac-door--final .ac-door__star,
.ac-door--final .ac-door__sprig {
  color: var(--ac-cream);
}

.ac-door--final .ac-door__hinge::before,
.ac-door--final .ac-door__hinge::after {
  background: linear-gradient(90deg, var(--ac-gold-deep), var(--ac-cream) 60%, var(--ac-gold-light));
}

/* Locked, it waits as dimmed gold with a soft cream numeral rather than the muted ink the other
   locked doors use, so the showpiece door still looks precious all through December. */
.ac-door--final.is-locked {
  --door-num: rgba(246, 236, 214, 0.82);
}

.ac-door--final.is-locked .ac-door__shape {
  filter: saturate(0.85) brightness(0.8) drop-shadow(0 0 8px rgba(239, 214, 138, 0.2));
}

.ac-door--final.is-opened .ac-door__shape::after {
  background:
    radial-gradient(ellipse 70% 60% at 50% 55%, rgba(255, 255, 255, 0.45), transparent 75%),
    var(--door-fill);
}

.ac-door.is-shaking {
  animation: ac-shake 0.5s ease both;
}

@keyframes ac-pulse {
  0%, 100% { filter: drop-shadow(0 0 5px rgba(239, 214, 138, 0.35)); }
  50% { filter: drop-shadow(0 0 18px rgba(239, 214, 138, 0.85)); }
}

@keyframes ac-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

/* ------------------------------------------------------------------------------- toast */

.ac-toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 50;
  max-width: min(92vw, 420px);
  padding: 10px 18px;
  border: 1px solid var(--ac-gold);
  border-radius: 999px;
  background: rgba(8, 35, 48, 0.95);
  color: var(--ac-cream);
  font-family: var(--ac-font-display);
  font-size: 0.95rem;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.ac-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------------------- reveal dialog */

.ac-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ac-ink);
  font-family: var(--ac-font-display);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.ac-dialog::backdrop {
  background: rgba(3, 16, 24, 0.8);
  backdrop-filter: blur(3px);
}

.ac-dialog__layout {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: clamp(12px, 3vw, 32px) 16px;
}

.ac-dialog__stage {
  position: relative;
  width: min(100%, 560px);
}

.ac-scene {
  position: relative;
  perspective: 1400px;
}

.ac-card {
  position: relative;
  z-index: 1;
  min-height: 240px;
  padding: clamp(28px, 7vw, 44px) clamp(18px, 5vw, 40px) clamp(22px, 5vw, 36px);
  border: 2px solid var(--ac-gold);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(255, 255, 255, 0.5), transparent 55%),
    radial-gradient(ellipse at 100% 100%, rgba(212, 175, 90, 0.18), transparent 60%),
    var(--ac-parchment);
  color: var(--ac-ink);
  box-shadow:
    inset 0 0 0 5px var(--ac-parchment),
    inset 0 0 0 6px var(--ac-gold-deep),
    0 0 0 1px rgba(0, 0, 0, 0.25),
    0 0 56px rgba(212, 175, 90, 0.38),
    0 24px 60px rgba(0, 0, 0, 0.55);
}

.ac-card:focus {
  outline: none;
}

.ac-card__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--ac-gold);
  border-radius: 50%;
  background: var(--ac-cream);
  color: var(--ac-ink-soft);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s ease, color 0.15s ease;
}

.ac-card__close svg {
  width: 18px;
  height: 18px;
}

.ac-card__close:hover,
.ac-card__close:focus-visible {
  color: var(--ac-ink);
  transform: scale(1.06);
}

.ac-card__close:focus-visible,
.ac-card__title:focus-visible {
  outline: 3px solid var(--ac-gold-deep);
  outline-offset: 3px;
}

.ac-card__title:focus {
  outline: none;
}

.ac-card__day {
  margin: 0 0 0.3em;
  font-family: var(--ac-font-serif);
  font-variant-caps: small-caps;
  font-size: 1rem;
  letter-spacing: 0.18em;
  text-align: center;
  color: var(--ac-gold-deep);
}

.ac-card__title {
  margin: 0;
  font-family: var(--ac-font-display);
  font-weight: 700;
  font-size: clamp(1.45rem, 4.6vw, 1.95rem);
  line-height: 1.15;
  text-align: center;
  text-wrap: balance;
  color: var(--ac-ink);
}

.ac-card__rule {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(60%, 220px);
  margin: 0.9em auto 1.1em;
  color: var(--ac-gold);
}

.ac-card__rule::before,
.ac-card__rule::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--ac-gold));
}

.ac-card__rule::after {
  background: linear-gradient(90deg, var(--ac-gold), transparent);
}

.ac-card__rule svg {
  width: 14px;
  height: 14px;
  flex: none;
}

.ac-card__content {
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--ac-ink);
  transition: opacity 0.25s ease;
}

.ac-scene.is-switching .ac-card__content {
  opacity: 0;
  transition: none;
}

.ac-card__content p,
.ac-text p {
  margin: 0 0 0.9em;
}

.ac-card__content > :last-child,
.ac-text > :last-child {
  margin-bottom: 0;
}

.ac-card__content a {
  color: var(--ac-gold-deep);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2px;
}

.ac-card__content img {
  max-width: 100%;
  height: auto;
}

.ac-card__error {
  padding: 10px 14px;
  border-left: 3px solid var(--ac-wrong);
  background: rgba(179, 65, 47, 0.08);
  color: var(--ac-wrong);
}

/* The two door leaves that cover the card and swing open. */
.ac-leaf {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 2;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  will-change: transform;
}

/* The decoration follows the leaf past 90° (the star and sprig carry their own transforms, so
   without this they would float on after the leaf's body has turned away). */
.ac-leaf > * {
  backface-visibility: inherit;
}

.ac-leaf--left {
  left: 0;
  transform-origin: left center;
}

.ac-leaf--right {
  right: 0;
  transform-origin: right center;
}

.ac-leaf .ac-door__shape {
  filter: drop-shadow(0 0 12px rgba(0, 0, 0, 0.5));
}

.ac-leaf--left .ac-door__hinge--right,
.ac-leaf--right .ac-door__hinge--left {
  display: none;
}

.ac-leaf .ac-door__star {
  top: 8%;
  width: clamp(14px, 8cqw, 24px);
}

.ac-leaf .ac-door__sprig {
  bottom: 7%;
  width: clamp(44px, 32cqw, 96px);
}

/* Mirror the right leaf's sprig so the pair is symmetrical, like a real pair of doors. */
.ac-leaf--right .ac-door__sprig svg {
  transform: scaleX(-1);
}

.ac-scene__numeral {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  font-family: var(--ac-font-serif);
  font-weight: 700;
  font-size: clamp(5rem, 28vw, 10rem);
  line-height: 1;
  color: var(--ac-gold-light);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4), 0 0 30px rgba(212, 175, 90, 0.6);
  pointer-events: none;
}

/* Open state: leaves swing out, overlay numeral fades, card settles in. */
.ac-scene.is-open .ac-leaf {
  transition: transform 0.9s cubic-bezier(0.5, 0.05, 0.3, 1);
}

.ac-scene.is-open .ac-leaf--left {
  transform: rotateY(-105deg);
}

.ac-scene.is-open .ac-leaf--right {
  transform: rotateY(105deg);
}

.ac-scene.is-open .ac-scene__numeral {
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* Once the swing is over the leaves leave the layout, so they add no scrollable overflow. */
.ac-scene.is-done .ac-leaf,
.ac-scene.is-done .ac-scene__numeral {
  display: none;
}

/* Wide viewports: the leaves stay, standing open either side of the card like the artwork, with
   their inner faces showing. At 150° each leaf projects to ~0.54× the stage width beyond its hinge,
   so card + leaves need ~1150px; from 1200px they fit beside the full-width (560px) card, and below
   that the card keeps its full width with no standing leaves rather than shrinking to make room.
   .ac-dialog clips any rest (overflow-x: hidden) so nothing here can add horizontal scrolling.
   Perspective makes each leaf's outer edge ~11% taller than the card, so the layout gets extra
   room above and below for it. The prev/next row sits under the card in this range (the floating
   arrows would collide with the leaves). */
@media (min-width: 1200px) {
  .ac-dialog__layout {
    padding-block: 56px;
  }

  .ac-leaf,
  .ac-leaf > * {
    backface-visibility: visible;
  }

  .ac-scene.is-open .ac-leaf--left {
    transform: rotateY(-150deg);
  }

  .ac-scene.is-open .ac-leaf--right {
    transform: rotateY(150deg);
  }

  .ac-scene.is-done .ac-leaf {
    display: block;
  }
}

.ac-scene--animated:not(.is-open) .ac-card {
  opacity: 0;
  transform: scale(0.97);
}

.ac-scene--animated.is-open .ac-card {
  opacity: 1;
  transform: none;
  transition: opacity 0.5s ease 0.3s, transform 0.7s ease 0.3s;
}

/* Previous / next day. A row under the card; floating arrows beside it between 900px and 1199px,
   where there is room beside the card but not for the open leaves (see the 1200px rule above). */
.ac-dialog__nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.ac-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid rgba(212, 175, 90, 0.7);
  border-radius: 999px;
  background: rgba(8, 35, 48, 0.7);
  color: var(--ac-cream);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.ac-nav-btn--next {
  margin-left: auto;
}

.ac-nav-btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.ac-nav-btn:hover,
.ac-nav-btn:focus-visible {
  background: rgba(212, 175, 90, 0.25);
}

.ac-nav-btn:focus-visible {
  outline: 3px solid var(--ac-gold-light);
  outline-offset: 3px;
}

@media (min-width: 900px) and (max-width: 1199.98px) {
  .ac-dialog__nav {
    position: absolute;
    top: 50%;
    left: -76px;
    right: -76px;
    margin: 0;
    transform: translateY(-50%);
    pointer-events: none;
  }

  .ac-nav-btn {
    width: 56px;
    height: 56px;
    padding: 0;
    justify-content: center;
    pointer-events: auto;
  }

  .ac-nav-btn__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .ac-nav-btn svg {
    width: 24px;
    height: 24px;
  }
}

/* ---------------------------------------------------------------------- puzzle chrome */

.ac-puzzle {
  margin-top: 1.1rem;
}

.ac-text + .ac-puzzle {
  padding-top: 1rem;
  border-top: 1px solid rgba(184, 146, 63, 0.35);
}

.ac-puzzle__body {
  transition: opacity 0.3s ease;
}

.ac-puzzle__body.is-revealed {
  opacity: 0.8;
}

.ac-puzzle__prompt {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

.ac-puzzle__prompt > :last-child {
  margin-bottom: 0;
}

.ac-puzzle__emoji {
  margin: 0.2em 0 0.5em;
  font-size: 3rem;
  line-height: 1.2;
  text-align: center;
}

.ac-puzzle__image {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto 1rem;
  border-radius: 10px;
}

.ac-puzzle__feedback {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  min-height: 1.5em;
  margin: 0.9rem 0 0;
  font-weight: 600;
  text-align: center;
  color: var(--ac-ink-soft);
}

.ac-puzzle__feedback:empty {
  margin: 0;
  min-height: 0;
}

.ac-puzzle__feedback:focus,
.ac-puzzle__reveal:focus {
  outline: none;
}

.ac-puzzle__feedback:focus-visible,
.ac-puzzle__reveal:focus-visible {
  outline: 2px solid var(--ac-gold-deep);
  outline-offset: 4px;
}

.ac-puzzle__feedback.is-wrong {
  color: var(--ac-wrong);
}

.ac-puzzle__feedback.is-correct {
  color: var(--ac-correct);
}

.ac-puzzle__tick {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--ac-correct);
  color: #fff;
}

.ac-puzzle__tick svg {
  width: 14px;
  height: 14px;
}

.ac-puzzle__note {
  display: block;
  width: 100%;
  font-weight: 400;
  font-size: 0.92rem;
  color: var(--ac-ink-soft);
}

.ac-puzzle__hint {
  margin: 0.8rem 0 0;
  padding: 10px 14px;
  border-left: 3px solid var(--ac-gold);
  border-radius: 0 8px 8px 0;
  background: rgba(212, 175, 90, 0.16);
  font-style: italic;
}

.ac-puzzle__hint > :last-child {
  margin-bottom: 0;
}

.ac-puzzle__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 0.9rem;
}

.ac-puzzle__actions:empty {
  display: none;
}

.ac-puzzle__reveal {
  margin-top: 1rem;
  padding: 16px 18px;
  border: 1px solid var(--ac-gold);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 0 0 3px var(--ac-parchment), inset 0 0 0 4px rgba(184, 146, 63, 0.55);
  animation: ac-rise 0.4s ease both;
}

.ac-puzzle__reveal-label {
  margin: 0 0 0.4em;
  font-family: var(--ac-font-serif);
  font-variant-caps: small-caps;
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  color: var(--ac-gold-deep);
}

.ac-puzzle__reveal-body > :first-child {
  margin-top: 0;
}

.ac-puzzle__reveal-body > :last-child {
  margin-bottom: 0;
}

@keyframes ac-rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------------- shared controls */

.ac-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 22px;
  border: 1px solid var(--ac-gold-deep);
  border-radius: 999px;
  background: linear-gradient(180deg, var(--ac-gold-light), var(--ac-gold));
  color: var(--ac-ink);
  font-family: var(--ac-font-display);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 2px 6px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
}

.ac-btn:hover {
  filter: brightness(1.05);
}

.ac-btn:active {
  transform: translateY(1px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 1px 2px rgba(0, 0, 0, 0.15);
}

.ac-btn:focus-visible,
.ac-input:focus-visible,
.ac-choice:focus-visible,
.ac-tile:focus-visible,
.ac-cell:focus-visible,
.ac-list__item button:focus-visible {
  outline: 3px solid var(--ac-gold-deep);
  outline-offset: 2px;
}

.ac-btn:disabled,
.ac-choice:disabled,
.ac-tile:disabled,
.ac-list__item button:disabled {
  cursor: default;
  opacity: 0.55;
  filter: none;
  transform: none;
}

.ac-btn--secondary {
  background: transparent;
  color: var(--ac-ink);
  box-shadow: none;
  border-width: 1.5px;
}

.ac-btn--secondary:hover {
  background: rgba(212, 175, 90, 0.15);
  filter: none;
}

.ac-input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 14px;
  border: 1.5px solid var(--ac-gold-deep);
  border-radius: 10px;
  background: #fff;
  color: var(--ac-ink);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ac-input::placeholder {
  color: #8a918f;
}

.ac-input:disabled {
  background: rgba(255, 255, 255, 0.5);
  color: var(--ac-ink-soft);
}

.ac-answer-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
}

.ac-answer-form .ac-input {
  flex: 1 1 180px;
}

.ac-answer-form .ac-btn {
  flex: 0 0 auto;
}

/* Multiple-choice option */
.ac-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  margin: 0 0 8px;
  padding: 12px 16px;
  border: 1.5px solid var(--ac-gold-deep);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ac-ink);
  font: inherit;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.ac-choice:last-child {
  margin-bottom: 0;
}

.ac-choice:hover:not(:disabled) {
  background: rgba(239, 214, 138, 0.35);
}

.ac-choice[aria-pressed='true'],
.ac-choice.is-selected {
  background: var(--ac-gold-light);
  box-shadow: inset 0 0 0 1px var(--ac-gold-deep);
}

.ac-choice.is-correct {
  background: rgba(47, 125, 79, 0.14);
  border-color: var(--ac-correct);
  opacity: 1;
}

.ac-choice.is-wrong {
  background: rgba(179, 65, 47, 0.1);
  border-color: var(--ac-wrong);
}

/* Letter / number / picture tiles (anagram, code lock, memory match, sliding puzzle) */
.ac-tiles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 0.5rem 0;
}

.ac-tiles--grid {
  display: grid;
  grid-template-columns: repeat(var(--ac-tiles-cols, 4), minmax(0, 1fr));
  justify-content: stretch;
}

.ac-tile {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 48px;
  padding: 0 10px;
  border: 1.5px solid var(--ac-gold-deep);
  border-radius: 10px;
  background: linear-gradient(180deg, #fffdf6, #f3e6c6);
  color: var(--ac-ink);
  font-family: var(--ac-font-serif);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--ac-gold-deep), 0 3px 6px rgba(0, 0, 0, 0.12);
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.12s ease, opacity 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
}

.ac-tiles--grid .ac-tile {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
}

.ac-tile:hover:not(:disabled) {
  transform: translateY(-1px);
}

.ac-tile:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 1px 0 var(--ac-gold-deep);
}

.ac-tile.is-selected,
.ac-tile[aria-pressed='true'] {
  background: var(--ac-gold-light);
  box-shadow: inset 0 0 0 2px var(--ac-gold-deep), 0 2px 0 var(--ac-gold-deep);
}

.ac-tile.is-used {
  opacity: 0.3;
  cursor: default;
}

.ac-tile.is-flipped {
  background: var(--ac-sky);
  color: var(--ac-cream);
  border-color: var(--ac-gold);
}

.ac-tile.is-matched {
  background: rgba(47, 125, 79, 0.16);
  border-color: var(--ac-correct);
  color: var(--ac-correct);
}

/* An empty answer slot (anagram): a dashed outline waiting for a letter. */
.ac-tile.is-empty {
  border-style: dashed;
  background: rgba(255, 255, 255, 0.4);
  box-shadow: none;
}

.ac-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}

/* Word-search cells */
.ac-grid-cells {
  display: grid;
  grid-template-columns: repeat(var(--ac-cells, 10), minmax(0, 1fr));
  gap: 2px;
  margin: 0.5rem auto;
  max-width: 440px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.ac-cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 1px solid rgba(184, 146, 63, 0.4);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--ac-ink);
  font-family: var(--ac-font-display);
  font-size: clamp(0.75rem, 3.4vw, 1.05rem);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.ac-cell.is-selected {
  background: var(--ac-gold-light);
  border-color: var(--ac-gold-deep);
}

.ac-cell.is-found {
  background: var(--ac-gold);
  border-color: var(--ac-gold-deep);
  color: #fff;
}

/* Ordering rows */
.ac-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0.5rem 0;
  padding: 0;
  list-style: none;
  counter-reset: ac-list;
}

.ac-list__item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 10px 8px 14px;
  border: 1.5px solid var(--ac-gold-deep);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ac-ink);
  counter-increment: ac-list;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.ac-list__item::before {
  content: counter(ac-list);
  flex: none;
  min-width: 1.6em;
  font-family: var(--ac-font-serif);
  font-weight: 700;
  color: var(--ac-gold-deep);
}

.ac-list__text,
.ac-list__item > span:first-of-type {
  flex: 1 1 auto;
  min-width: 0;
}

.ac-list__controls {
  display: flex;
  flex: none;
  gap: 4px;
}

.ac-list__item button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--ac-gold-deep);
  border-radius: 50%;
  background: #fff;
  color: var(--ac-ink);
  font: inherit;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.12s ease;
}

.ac-list__item button:hover:not(:disabled) {
  background: var(--ac-gold-light);
}

.ac-list__item button svg {
  width: 20px;
  height: 20px;
}

.ac-list__item.is-correct {
  border-color: var(--ac-correct);
  background: rgba(47, 125, 79, 0.12);
}

.ac-list__item.is-wrong {
  border-color: var(--ac-wrong);
  background: rgba(179, 65, 47, 0.08);
}

/* ------------------------------------------------------------------------------ media */

.ac-media {
  margin: 0;
}

.ac-media__frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--ac-gold-deep);
  border-radius: 12px;
  /* Night sky rather than black, so a poster or clip of another shape is framed in the calendar's
     own colour instead of black bars. */
  background: var(--ac-sky-deep);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.ac-media__frame > iframe,
.ac-media__frame > video,
.ac-media__frame > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.ac-media__frame > img {
  object-fit: cover;
}

.ac-media > img,
.ac-media > picture > img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--ac-gold-deep);
  border-radius: 12px;
}

.ac-media audio {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
}

.ac-media__caption {
  margin: 0.6rem 0 0;
  font-size: 0.92rem;
  font-style: italic;
  text-align: center;
  color: var(--ac-ink-soft);
}

/* ----------------------------------------------------------------------- reduced motion */

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

  .ac-door.is-today .ac-door__shape {
    filter: drop-shadow(0 0 12px rgba(239, 214, 138, 0.7));
  }

  .ac-scene .ac-leaf,
  .ac-scene .ac-scene__numeral {
    display: none;
  }

  .ac-scene--animated:not(.is-open) .ac-card {
    opacity: 1;
    transform: none;
  }
}

/* …except on wide viewports, where the leaves simply appear already standing open (no swing). */
@media (prefers-reduced-motion: reduce) and (min-width: 1200px) {
  .ac-scene.is-open .ac-leaf {
    display: block;
  }
}
