/* ============================================================
   Ходочашће — all visuals live here.
   Palette: deep charcoal + gold + parchment sepia.
   ============================================================ */

:root {
  --charcoal: #1a1612;
  --charcoal-soft: #241f19;
  --gold: #c9a227;
  --gold-soft: #e0c46a;
  --parchment: #e8dcc4;
  --parchment-dark: #d4c5a0;
  --crimson: #7a2e2a;
  --font: "Cormorant Garamond", Georgia, "Times New Roman", serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--charcoal);
  color: var(--parchment);
  font-family: var(--font);
  overflow: hidden;
}

/* ---------- Screens: stacked, one visible at a time ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 1.5rem;
  opacity: 0;
  visibility: hidden;
  /* filmic dissolve: the incoming scene settles from a soft, slightly-zoomed
     blur, like a camera pulling focus — not a flat fade */
  transform: scale(1.04);
  filter: blur(7px);
  transition: opacity 0.9s ease, transform 1s cubic-bezier(0.22, 0.61, 0.36, 1),
              filter 0.9s ease, visibility 0s linear 1s;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
  filter: blur(0);
  transition: opacity 0.9s ease, transform 1s cubic-bezier(0.22, 0.61, 0.36, 1),
              filter 0.9s ease, visibility 0s;
}

@media (prefers-reduced-motion: reduce) {
  .screen, .screen.active {
    transition-duration: 0.01ms;
    transform: none;
    filter: none;
  }
}

.placeholder {
  font-size: 1.3rem;
  font-style: italic;
  opacity: 0.5;
}

/* ---------- Intro ---------- */

#intro-title {
  font-size: clamp(2.6rem, 9vw, 5rem);
  font-weight: 500;
  /* gold text with a bright band that sweeps across once, like light catching
     gilt letters; the glow lives on filter so it survives the clipped fill */
  color: transparent;
  background: linear-gradient(100deg,
    var(--gold) 0%, var(--gold) 40%, #fff3cf 50%, var(--gold) 60%, var(--gold) 100%);
  background-size: 260% 100%;
  background-position: 130% 0;
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 26px rgba(201, 162, 39, 0.3));
  animation: title-in 3.5s ease-out both,
             title-shimmer 2.8s cubic-bezier(0.4, 0, 0.2, 1) 1.1s both;
}

@keyframes title-in {
  0%   { opacity: 0; letter-spacing: 0.02em; }
  100% { opacity: 1; letter-spacing: 0.22em; }
}
@keyframes title-shimmer {
  to { background-position: -30% 0; }
}
@media (prefers-reduced-motion: reduce) {
  #intro-title { animation: title-in 0.01ms both; background-position: 50% 0; }
}

.subtitle {
  font-size: clamp(1rem, 3.5vw, 1.4rem);
  font-style: italic;
  color: var(--parchment-dark);
  opacity: 0;
  animation: fade-in 2s ease-out 1.8s forwards;
}

@keyframes fade-in {
  to { opacity: 0.85; }
}

/* ---------- Intro cross ---------- */

.intro-cross {
  width: 74px;
  height: auto;
  opacity: 0;
  /* the cross fades in, then its halo swells and settles — as if lit */
  animation: cross-in 2.5s ease-out 0.2s forwards,
             cross-ignite 3s ease-out 0.2s both;
}
@keyframes cross-in {
  to { opacity: 1; }
}
@keyframes cross-ignite {
  0%   { filter: drop-shadow(0 0 0 rgba(201, 162, 39, 0)) drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5)); }
  55%  { filter: drop-shadow(0 0 30px rgba(224, 196, 106, 0.75)) drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5)); }
  100% { filter: drop-shadow(0 0 14px rgba(201, 162, 39, 0.45)) drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5)); }
}
@media (prefers-reduced-motion: reduce) {
  .intro-cross { animation: cross-in 0.01ms forwards;
    filter: drop-shadow(0 0 14px rgba(201, 162, 39, 0.45)) drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5)); }
}

/* ---------- Start-screen gallery ---------- */
#intro-gallery {
  display: flex;
  gap: clamp(6px, 2vw, 14px);
  margin-top: 0.4rem;
  opacity: 0;
  animation: fade-in 2s ease-out 1.2s forwards;
}
.gallery-arch {
  position: relative;
  width: clamp(58px, 17vw, 84px);
  aspect-ratio: 3 / 4.4;
  border-radius: 50% 50% 0 0 / 34% 34% 0 0;
  overflow: hidden;
  border: 1px solid rgba(201, 162, 39, 0.35);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.7);
}
.gallery-arch img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(0.8) brightness(0.55); /* unlit but still visible */
  transition: filter 1.6s ease;
}
.gallery-arch.lit img { filter: sepia(0.1); }
.gallery-name {
  position: absolute;
  left: 0; right: 0; bottom: 2px;
  font-size: 0.66rem;
  text-align: center;
  letter-spacing: 0.06em;
  color: var(--parchment-dark);
  text-shadow: 0 1px 2px #000;
}
.gallery-flame {
  position: absolute;
  left: 50%; bottom: 12px;
  width: 5px; height: 8px;
  transform: translateX(-50%);
  border-radius: 50% 50% 42% 42%;
  background: radial-gradient(circle at 50% 70%, #ffe9a8, #e8a33d 65%, transparent);
  opacity: 0;
  transition: opacity 1s ease;
}
.gallery-arch.lit .gallery-flame { opacity: 1; animation: flicker 2.4s ease-in-out infinite; }

/* ---------- Candle (pure CSS) ---------- */

.candle {
  position: relative;
  width: 40px;
  height: 150px;
  margin-bottom: 1rem;
  opacity: 0;
  animation: fade-in 2.5s ease-out 0.5s forwards;
}

.wax {
  position: absolute;
  bottom: 0;
  width: 40px;
  height: 90px;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(90deg, #b8a888, #ede0c4 45%, #cbbb96);
}

.wick {
  position: absolute;
  bottom: 88px;
  left: 18px;
  width: 4px;
  height: 10px;
  background: #3a2f22;
  border-radius: 2px;
}

.flame {
  position: absolute;
  bottom: 94px;
  left: 8px;
  width: 24px;
  height: 44px;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(ellipse at 50% 75%,
    #fff7d6 0%, #ffdf80 35%, #f2a93b 65%, rgba(216, 106, 30, 0.35) 88%, transparent 100%);
  transform-origin: 50% 90%;
  animation: flicker 2.8s ease-in-out infinite;
  filter: drop-shadow(0 0 18px rgba(240, 180, 60, 0.55));
}

@keyframes flicker {
  0%, 100% { transform: rotate(-2deg) scaleY(1); opacity: 1; }
  22%      { transform: rotate(2deg)  scaleY(1.06); opacity: 0.92; }
  45%      { transform: rotate(-1deg) scaleY(0.94); opacity: 0.98; }
  60%      { transform: rotate(3deg)  scaleY(1.04); opacity: 0.9; }
  80%      { transform: rotate(-3deg) scaleY(0.97); opacity: 1; }
}

/* ---------- Buttons ---------- */

.btn {
  margin-top: 1.5rem;
  padding: 0.8rem 2.4rem;
  font-family: var(--font);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  color: var(--gold-soft);
  background: transparent;
  border: 1px solid var(--gold);
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  animation: fade-in 2s ease-out 3s forwards;
  transition: background 0.4s ease, color 0.4s ease, box-shadow 0.4s ease;
}

.btn:hover, .btn:focus-visible {
  background: rgba(201, 162, 39, 0.12);
  box-shadow: 0 0 20px rgba(201, 162, 39, 0.2);
}

:where(button, [role="button"]):focus-visible {
  outline: 3px solid var(--gold-soft);
  outline-offset: 4px;
}

.marker:focus-visible .church {
  filter: drop-shadow(0 0 8px rgba(201, 162, 39, 0.95));
}

/* game feel: every press answers the finger */
.btn:active { transform: translateY(1px) scale(0.98); box-shadow: 0 0 10px rgba(201, 162, 39, 0.25); }
.door:active, .king-card:active, .tile:active, .climb-candle:active, .arrow:active {
  transform: scale(0.93);
}
.king-card, .tile, .climb-candle, .arrow { transition: transform 0.12s ease; }
.king-card:hover, .door:not(.filled):hover {
  border-color: var(--gold);
  box-shadow: 0 0 10px rgba(201, 162, 39, 0.3);
}

.link-btn {
  background: none;
  border: none;
  color: var(--parchment-dark);
  font-family: var(--font);
  font-size: 0.95rem;
  font-style: italic;
  text-decoration: underline;
  cursor: pointer;
  opacity: 0.6;
}

/* ---------- Map (old fresco / parchment) ---------- */

.screen-map {
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 246, 220, 0.5), transparent 70%),
    radial-gradient(ellipse at 50% 50%, var(--parchment) 40%, var(--parchment-dark) 78%, #b9a678 100%);
  color: #4a3b24;
  gap: 0.6rem;
}

.map-hint {
  font-size: 1.15rem;
  font-style: italic;
  color: #6d5836;
  z-index: 2;
}

#map {
  width: min(92vw, 62vh, 560px);
  height: auto;
  max-height: 74vh;
  z-index: 2;
}

#land {
  fill: rgba(255, 250, 232, 0.45);
  stroke: rgba(140, 110, 50, 0.55);
  stroke-width: 2.5;
}

#route {
  stroke: rgba(140, 110, 50, 0.45);
  stroke-width: 2;
  stroke-dasharray: 6 8;
  stroke-linecap: round;
}

#travel-path {
  stroke: var(--gold);
  stroke-width: 3;
  stroke-linecap: round;
  filter: drop-shadow(0 0 4px rgba(201, 162, 39, 0.6));
}

#trail {
  stroke: rgba(168, 132, 47, 0.75);
  stroke-width: 2.5;
  stroke-linecap: round;
}

/* Medieval-map dressing: inked rivers, mountains, the Serbian cross,
   a heraldic gonfalon, a compass rose. All quiet parchment inks. */
.river {
  fill: none;
  stroke: #7b93a4;
  stroke-width: 2.4;
  stroke-linecap: round;
  opacity: 0.5;
}
.river.thin { stroke-width: 1.7; opacity: 0.4; }

.mountains path {
  fill: none;
  stroke: #6d5836;
  stroke-width: 1.6;
  stroke-linejoin: round;
  opacity: 0.55;
}

#map-cross { opacity: 0.085; }
#map-cross .cross-bars { stroke: #7a2e2a; stroke-width: 11; }
#map-cross .ocilo      { stroke: #7a2e2a; stroke-width: 7; stroke-linecap: round; }

#map-banner .rod    { stroke: #5e4a28; stroke-width: 3; stroke-linecap: round; }
#map-banner .finial { fill: var(--gold); }
#map-banner .cloth {
  fill: #7d2f28;
  stroke: #55201c;
  stroke-width: 1.5;
  filter: drop-shadow(1px 3px 3px rgba(74, 59, 36, 0.35));
}
#map-banner .cloth-trim {
  fill: none;
  stroke: rgba(224, 196, 106, 0.55);
  stroke-width: 1.4;
}
.banner-emblem path {
  fill: none;
  stroke: #f0e6d0;
  stroke-linecap: round;
}

.compass-ring  { fill: none; stroke: #6d5836; stroke-width: 1.2; opacity: 0.6; }
.compass-star  { fill: #6d5836; opacity: 0.65; }
.compass-star.minor { opacity: 0.4; }
.compass-north { stroke: #7a2e2a; stroke-width: 2; opacity: 0.7; }

/* Monastery markers: little church silhouettes */
.marker { cursor: default; }
.marker .church {
  fill: #8a7048;
  stroke: #5e4a28;
  stroke-width: 1;
  transition: fill 0.5s ease;
}
.marker text {
  font-family: var(--font);
  font-size: 23px; /* SVG units: 600-wide viewBox on a 390px phone scales this to ~15px */
  fill: #4a3b24;
  text-anchor: middle;
  letter-spacing: 0.04em;
}

.marker.locked { opacity: 0.45; }

.marker.next { cursor: pointer; }
.marker.next .church {
  fill: var(--gold);
  animation: marker-pulse 2.2s ease-in-out infinite;
}

/* quest marker: a gold ring breathes out around the next destination */
.marker .quest-ring { fill: none; stroke: none; }
.marker.next .quest-ring {
  stroke: var(--gold);
  animation: quest-ring 2.2s ease-out infinite;
  transform-origin: center;
  transform-box: fill-box;
}
@keyframes quest-ring {
  0%   { stroke-width: 2.5; opacity: 0.85; transform: scale(0.55); }
  70%  { opacity: 0; }
  100% { stroke-width: 0.5; opacity: 0; transform: scale(1.5); }
}
@media (prefers-reduced-motion: reduce) {
  .marker.next .quest-ring { animation: none; opacity: 0.5; stroke-width: 1.5; }
}
@keyframes marker-pulse {
  0%, 100% { filter: drop-shadow(0 0 2px rgba(201, 162, 39, 0.4)); }
  50%      { filter: drop-shadow(0 0 9px rgba(201, 162, 39, 0.95)); }
}

.marker.done .church { fill: #a8842f; }
.marker.done .check {
  font-size: 16px;
  fill: #7a2e2a;
}

/* The pilgrim moving along the route */
.player-dot  { fill: #7a2e2a; }
.player-glow { fill: rgba(201, 162, 39, 0.45); }

/* Drifting mist layers over the map */
.mist {
  position: absolute;
  inset: -20%;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(ellipse 40% 18% at 30% 35%, rgba(255, 252, 240, 0.5), transparent 70%),
              radial-gradient(ellipse 35% 15% at 75% 60%, rgba(255, 252, 240, 0.4), transparent 70%);
  filter: blur(18px);
  animation: mist-drift 46s linear infinite alternate;
}
.mist-2 {
  background: radial-gradient(ellipse 30% 12% at 60% 25%, rgba(255, 252, 240, 0.4), transparent 70%),
              radial-gradient(ellipse 45% 16% at 20% 75%, rgba(255, 252, 240, 0.35), transparent 70%);
  animation-duration: 67s;
  animation-direction: alternate-reverse;
}
@keyframes mist-drift {
  from { transform: translateX(-4%) translateY(-1%); }
  to   { transform: translateX(4%)  translateY(2%); }
}

/* ---------- Monastery screen ---------- */

/* Each house has its own color, drawn from its real art history:
   Studenica marble + fresco blue, red Žiča, Sopoćani's golden ochre,
   Manasija's Resava green, Ostrog's limestone rock and sky. */
.screen-monastery {
  --m-accent: var(--gold);
  --m-stone: #e5ddc9;
  --m-robe: #2b241d;
  background:
    radial-gradient(ellipse at 50% 12%, color-mix(in srgb, var(--m-accent) 14%, transparent), transparent 62%),
    var(--charcoal);
}
#screen-monastery[data-m="studenica"] { --m-accent: #7d9ec7; --m-stone: #ece5d4; }
#screen-monastery[data-m="zica"]      { --m-accent: #a5473d; --m-stone: #d9c9b4; }
#screen-monastery[data-m="sopocani"]  { --m-accent: #d9a441; --m-stone: #e4d3ae; }
#screen-monastery[data-m="manasija"]  { --m-accent: #6f8f7a; --m-stone: #d6d2c4; }
#screen-monastery[data-m="ostrog"]    { --m-accent: #9db8d2; --m-stone: #efece3; }

/* candlelight inside the church: warm pools of light that breathe slowly,
   so stepping through the doors feels like standing among the votive candles */
#screen-monastery::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 55% 38% at 15% 92%, rgba(255, 172, 74, 0.12), transparent 70%),
    radial-gradient(ellipse 55% 38% at 85% 92%, rgba(255, 172, 74, 0.12), transparent 70%),
    radial-gradient(ellipse 85% 45% at 50% -5%, color-mix(in srgb, var(--m-accent) 12%, transparent), transparent 72%);
  animation: warm-breathe 6s ease-in-out infinite;
}
@keyframes warm-breathe {
  /* irregular steps read as a live candle flame, not a smooth sine pulse */
  0%   { opacity: 0.78; }
  18%  { opacity: 0.95; }
  32%  { opacity: 0.82; }
  50%  { opacity: 1; }
  63%  { opacity: 0.72; }
  81%  { opacity: 0.9; }
  100% { opacity: 0.78; }
}
@media (prefers-reduced-motion: reduce) {
  #screen-monastery::before { animation: none; }
}

#inner-icons svg {
  display: block;
  width: min(80vw, 340px);
  margin: 0 auto 0.4rem;
  filter: drop-shadow(0 4px 16px rgba(224, 196, 106, 0.22));
}

#inner-photo {
  margin: 0.4rem auto 0.2rem;
  width: min(92vw, 420px);
  padding: 6px;
  background: linear-gradient(160deg, #4a3626, #2b1f14);
  border: 1px solid rgba(201, 162, 39, 0.5);
  /* layered depth: a cast shadow to lift it off the wall, a gilt rim of light
     on top, and a soft inner shadow so the photo sits inside its frame */
  box-shadow:
    0 14px 36px rgba(0, 0, 0, 0.6),
    0 4px 10px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 232, 180, 0.35),
    inset 0 0 18px rgba(0, 0, 0, 0.55);
}
#inner-photo img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  filter: sepia(0.1); /* keep the warm cast, no darkening */
}
#inner-photo figcaption {
  padding-top: 5px;
  font-size: 0.92rem;
  font-style: italic;
  text-align: center;
  color: var(--parchment-dark);
}

/* thin fresco-border frame on the dark, "interior" screens; the inner
   shadow pools the corners in darkness, like a lit scene in a game */
#screen-intro::after,
#screen-monastery::after,
#screen-final::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(201, 162, 39, 0.16);
  box-shadow: inset 0 0 110px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

/* ---------- The gate scene: stone portal, wooden doors, the monk ---------- */

.door-scene {
  position: relative;
  width: min(76vw, 330px);
  aspect-ratio: 300 / 372;
  margin: 0 auto;
  filter: drop-shadow(0 8px 28px color-mix(in srgb, var(--m-accent) 28%, transparent));
}

.arch-stone {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* the opening behind the doors: dark narthex lit by candles below */
.doorway {
  position: absolute;
  left: 16%;
  width: 68%;
  top: 12.9%;
  bottom: 5.4%;
  border-radius: 50% 50% 0 0 / 33.5% 33.5% 0 0;
  overflow: hidden;
  background: #0b0805;
  perspective: 700px;
}

.doorway .glow {
  position: absolute;
  inset: -2%;
  background:
    radial-gradient(ellipse at 50% 92%, color-mix(in srgb, var(--m-accent) 40%, #ffb85c) 0%, rgba(255, 160, 60, 0.25) 34%, transparent 68%),
    radial-gradient(ellipse at 50% 30%, rgba(255, 190, 110, 0.16), transparent 55%),
    #0d0906;
  opacity: 0.9;
  transition: opacity 1s ease, filter 1.2s ease;
}

/* oak leaves: planks, grain, two iron hinge bands with studs */
.door-leaf {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50.6%;
  backface-visibility: hidden;
  transition: transform 1.25s cubic-bezier(0.66, 0, 0.34, 1) 0.08s;
  background:
    radial-gradient(circle, #0f0c08 2.3px, rgba(0, 0, 0, 0) 3.4px) 4px 24% / 15px 9px repeat-x,
    radial-gradient(circle, #0f0c08 2.3px, rgba(0, 0, 0, 0) 3.4px) 4px 76% / 15px 9px repeat-x,
    linear-gradient(180deg,
      transparent 21.5%, rgba(12, 9, 6, 0.85) 22%, rgba(58, 48, 36, 0.9) 23.5%, rgba(12, 9, 6, 0.85) 26%, transparent 26.5%,
      transparent 73.5%, rgba(12, 9, 6, 0.85) 74%, rgba(58, 48, 36, 0.9) 75.5%, rgba(12, 9, 6, 0.85) 78%, transparent 78.5%),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.5) 0 1.5px, rgba(120, 90, 55, 0.16) 1.5px 3px, rgba(0, 0, 0, 0) 3px 22%),
    repeating-linear-gradient(88deg, rgba(0, 0, 0, 0.12) 0 2px, transparent 2px 5px),
    linear-gradient(102deg, #5a452c, #46351f 55%, #332514);
  box-shadow: inset 0 0 22px rgba(0, 0, 0, 0.55);
}
.door-leaf.left  { left: 0;  transform-origin: 0 50%;    border-right: 1px solid rgba(0, 0, 0, 0.7); }
.door-leaf.right { right: 0; transform-origin: 100% 50%; }

/* iron ring handles on backplates, by the meeting edge */
.door-leaf::before {
  content: "";
  position: absolute;
  top: 47%;
  width: 9%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #4a4038, #171310);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
.door-leaf::after {
  content: "";
  position: absolute;
  top: 49.5%;
  width: 16%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid #191410;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.08), 0 3px 4px rgba(0, 0, 0, 0.7);
}
.door-leaf.left::before  { right: 10%; }
.door-leaf.left::after   { right: 7%; }
.door-leaf.right::before { left: 10%; }
.door-leaf.right::after  { left: 7%; }

.monk-stand {
  position: absolute;
  left: 50%;
  bottom: 4.5%;
  width: 45%;
  transform: translateX(-50%);
  transition: opacity 0.55s ease 0.15s, transform 0.55s ease 0.15s;
}
.monk-stand svg {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
}

.monk-name {
  font-size: 1.15rem;
  color: var(--m-stone);
  letter-spacing: 0.08em;
  margin-top: 0.3rem;
}

.monk-greeting {
  max-width: 34ch;
  font-size: 1.05rem;
  font-style: italic;
  line-height: 1.5;
  color: var(--parchment-dark);
}

#particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.monastery-name {
  font-size: clamp(2rem, 7vw, 3.2rem);
  font-weight: 500;
  color: var(--gold);
  letter-spacing: 0.12em;
}

.founded {
  font-style: italic;
  color: var(--parchment-dark);
  opacity: 0.8;
}

.gate[hidden] { display: none; } /* display:flex would defeat [hidden] */

.gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  transition: opacity 0.8s ease;
}
.gate .btn { animation: fade-in 1s ease-out 0.4s forwards; }

/* entering: text fades, the monk steps aside, the doors swing inward,
   candlelight floods out, then the whole scene gives way to the interior */
.gate.leaving { pointer-events: none; }
.gate.leaving > :not(#gate-portal) { opacity: 0; transition: opacity 0.5s ease; animation: none; }
.gate.leaving .door-leaf.left  { transform: rotateY(-104deg); }
.gate.leaving .door-leaf.right { transform: rotateY(104deg); }
.gate.leaving .glow { opacity: 1; filter: brightness(1.4); }
.gate.leaving .monk-stand { opacity: 0; transform: translateX(-50%) translateY(5px); }
.gate.leaving #gate-portal { animation: gate-depart 1.7s ease forwards; }
@keyframes gate-depart {
  0%, 65% { opacity: 1; transform: none; }
  100%    { opacity: 0; transform: scale(1.07); }
}

@media (prefers-reduced-motion: reduce) {
  .door-leaf, .monk-stand, .doorway .glow { transition: none !important; }
  .gate.leaving #gate-portal { animation: none; opacity: 0; transition: opacity 0.8s ease; }
}

.inner {
  max-width: 620px;
  max-height: 100%;
  overflow-y: auto;
  padding: 1rem 0.5rem 4rem;
  text-align: center;
  opacity: 0;
  transition: opacity 1.2s ease;
}
.inner.visible { opacity: 1; }

/* gentle bobbing chevron: "there is more below" (the puzzle) */
#scroll-cue {
  position: absolute;
  bottom: 3.4rem; /* clear of the fixed progress-candles bar */
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.8rem;
  line-height: 1;
  color: var(--gold-soft);
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: cue-bob 1.8s ease-in-out infinite;
}
@keyframes cue-bob {
  0%, 100% { transform: translateX(-50%) translateY(0); opacity: 0.9; }
  50% { transform: translateX(-50%) translateY(6px); opacity: 0.5; }
}

#vignette {
  margin-top: 1.4rem;
  text-align: left;
}
#vignette p {
  font-size: 1.15rem;
  line-height: 1.65;
  margin-bottom: 1rem;
  color: var(--parchment);
}
#vignette p:first-child::first-letter {
  font-size: 2.2em;
  line-height: 1;
  color: var(--m-accent, var(--gold));
  float: left;
  padding-right: 0.12em;
}

/* a small cross-flower divider under the monastery's name, fresco style */
#inner-name::after {
  content: "✣";
  display: block;
  font-size: 0.45em;
  letter-spacing: 0;
  margin-top: 0.35em;
  color: var(--m-accent, var(--gold));
  opacity: 0.9;
}

/* ---------- Puzzle ---------- */

#puzzle { margin-top: 1.6rem; }

.instruction {
  font-size: 1.1rem;
  font-style: italic;
  color: var(--gold-soft);
  margin-bottom: 1rem;
}

#puzzle-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  text-align: left;
}

.card {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.9rem;
  background: var(--charcoal-soft);
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 4px;
  font-size: 1.05rem;
  cursor: grab;
  touch-action: none;              /* the finger drags the card, not the page */
  user-select: none;
  -webkit-user-select: none;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.card.dragging {
  position: relative;
  z-index: 2;
  cursor: grabbing;
  border-color: var(--gold);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  background: #2b251d;
}

.card-text { flex: 1; }

.card-year {
  color: var(--gold);
  font-style: italic;
  opacity: 0;                      /* years would give the answer away */
  transition: opacity 1s ease;
}
#puzzle-list.solved .card-year,
.card.year-lit .card-year { opacity: 1; }
#puzzle-list.solved .card { cursor: default; }
#puzzle-list.solved .card-arrows { visibility: hidden; }

.card-arrows { display: flex; flex-direction: column; gap: 2px; }
.arrow {
  background: none;
  border: 1px solid rgba(201, 162, 39, 0.3);
  border-radius: 3px;
  color: var(--gold-soft);
  font-size: 0.85rem;
  padding: 4px 10px;
  cursor: pointer;
}
.arrow:hover { border-color: var(--gold); }

.shake { animation: shake 0.45s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}

.puzzle-msg {
  min-height: 1.5em;
  margin-top: 1rem;
  font-size: 1.15rem;
  font-style: italic;
  color: var(--gold-soft);
}
/* the reward: the success line swells and glows as the gold-dust blooms */
.puzzle-msg.solved {
  animation: msg-bloom 1.4s ease-out both;
}
@keyframes msg-bloom {
  0%   { opacity: 0; transform: scale(0.9); text-shadow: 0 0 0 rgba(224, 196, 106, 0); }
  40%  { opacity: 1; transform: scale(1.06); text-shadow: 0 0 22px rgba(224, 196, 106, 0.85); }
  100% { opacity: 1; transform: scale(1); text-shadow: 0 0 10px rgba(224, 196, 106, 0.35); }
}
@media (prefers-reduced-motion: reduce) {
  .puzzle-msg.solved { animation: none; }
}

#puzzle .btn { animation: none; opacity: 1; margin-top: 0.8rem; }

.help-btn { display: block; margin: 0.9rem auto 0; }
.help-verse {
  margin-top: 0.5rem;
  font-size: 0.95rem;
  font-style: italic;
  color: var(--parchment-dark);
  opacity: 0.8;
}

/* ---------- Progress candles bar ---------- */

.candles[hidden] { display: none; } /* our display:flex would defeat [hidden] */

.candles {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 1.6rem;
  padding: 0.5rem 0 0.7rem;
  z-index: 5;
}

.candle-mini {
  position: relative;
  width: 12px;
  height: 34px;
}
.candle-mini .body {
  position: absolute;
  bottom: 0;
  width: 12px;
  height: 24px;
  border-radius: 3px 3px 1px 1px;
  background: linear-gradient(90deg, #a2916f, #d9cba6 45%, #b3a37e);
  opacity: 0.7;
}
.candle-mini .flame-mini {
  position: absolute;
  bottom: 25px;
  left: 2.5px;
  width: 7px;
  height: 13px;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(ellipse at 50% 75%, #fff7d6 0%, #ffdf80 40%, #f2a93b 70%, transparent 100%);
  transform-origin: 50% 90%;
  opacity: 0;
  transition: opacity 1.2s ease;
}
.candle-mini.lit .body { opacity: 1; }
.candle-mini.lit .flame-mini {
  opacity: 1;
  animation: flicker 2.8s ease-in-out infinite;
  filter: drop-shadow(0 0 6px rgba(240, 180, 60, 0.7));
}

/* ---------- Final screen ---------- */

.screen-final {
  background:
    radial-gradient(ellipse at 50% 80%, rgba(201, 162, 39, 0.14), transparent 60%),
    var(--charcoal);
}

#final-heading {
  animation: title-in 3.5s ease-out both;
}

#dedication {
  max-width: 560px;
  text-align: center;
}

#dedication p {
  font-size: 1.25rem;
  font-style: italic;
  line-height: 1.7;
  margin-bottom: 1.1rem;
  color: var(--parchment);
  opacity: 0;
  animation: fade-in 2.5s ease-out forwards; /* delay set per line by game.js */
}

/* ---------- Žiča: seven doors ---------- */
.doors { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; margin-bottom: 0.7rem; }
.door {
  width: 44px; height: 68px;
  border: 1px solid rgba(201, 162, 39, 0.4);
  border-radius: 50% 50% 0 0 / 40% 40% 0 0;
  background: linear-gradient(180deg, #221b13, #171009);
  color: var(--parchment-dark);
  font-family: var(--font); font-size: 0.72rem;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  gap: 1px; padding-bottom: 4px; cursor: pointer;
  transition: box-shadow 0.5s ease, background 0.5s ease, transform 0.12s ease, border-color 0.3s ease;
}
.door.filled {
  background: linear-gradient(180deg, color-mix(in srgb, var(--m-accent) 45%, #221b13), #171009);
  box-shadow: 0 0 12px color-mix(in srgb, var(--m-accent) 55%, transparent);
  color: var(--parchment); pointer-events: none;
}
.door-year { line-height: 1.1; padding: 0 2px; }
/* the matched king's face appears in his door, above the year */
.door-king { display: none; width: 30px; margin-top: 4px; }
.door-king svg { display: block; width: 30px; height: auto; }
.door.filled { justify-content: space-between; padding-top: 2px; }
.door.filled .door-king { display: block; }
.door.filled .door-year { color: var(--gold-soft); font-size: 0.68rem; }
@keyframes shake-door { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.door.shake-door { animation: shake-door 0.3s ease 2; }
.kings { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.king-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 96px;
  padding: 0.45rem 0.3rem;
  font-family: var(--font); font-size: 0.95rem;
  color: var(--parchment); background: rgba(255, 246, 220, 0.06);
  border: 1px solid rgba(201, 162, 39, 0.45); border-radius: 3px; cursor: pointer;
}
.king-card svg { width: 58px; height: auto; display: block; }
.king-name { line-height: 1.2; text-align: center; }
.king-card.picked { background: rgba(201, 162, 39, 0.25); box-shadow: 0 0 10px rgba(201, 162, 39, 0.35); }

/* ---------- Sopoćani: the broken fresco ---------- */
#fresco-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  width: min(78vw, 320px);
  aspect-ratio: 1;
  margin: 0 auto 0.5rem;
  transition: gap 0.8s ease;
}
.tile {
  border: 1px solid rgba(0, 0, 0, 0.6);
  background-size: 300% 300%;
  cursor: pointer;
  padding: 0;
  filter: sepia(0.1);
}
.tile.picked { outline: 2px solid var(--gold); outline-offset: -2px; filter: brightness(1.1); }
.tile.locked { pointer-events: none; }
#fresco-grid.whole { gap: 0; }
#fresco-grid.whole .tile { border-color: transparent; filter: sepia(0.1) brightness(1); pointer-events: none; }

/* ---------- Ostrog: the climb ---------- */
#climb-scene {
  position: relative;
  width: min(78vw, 300px);
  height: 340px;
  margin: 0 auto 0.5rem;
  border-radius: 6px;
  overflow: hidden;
  background:
    radial-gradient(ellipse 90% 30% at 50% 108%, rgba(255, 176, 80, 0.14), transparent 70%),
    linear-gradient(196deg, #2c2620 12%, #221c15 45%, #17120c 100%);
  border: 1px solid rgba(201, 162, 39, 0.2);
}
/* the cliff face: rock masses at the flanks, stars in the night above */
#climb-scene .cliff {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
#climb-scene .rock { fill: #14100b; }
#climb-scene .rock-edge {
  fill: none; stroke: rgba(157, 184, 210, 0.22); stroke-width: 1.2;
}
#climb-scene .star { fill: #e8dcc4; opacity: 0.5; animation: star-wink 3.4s ease-in-out infinite; }
#climb-scene .star:nth-of-type(2n) { animation-delay: 1.1s; }
#climb-scene .star:nth-of-type(3n) { animation-delay: 2.2s; }
@keyframes star-wink {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 0.15; }
}

.cave {
  position: absolute; top: 6%; left: 50%; transform: translateX(-50%);
  width: 74px; height: 56px;
  border-radius: 50% 50% 0 0 / 62% 62% 0 0;
  background: radial-gradient(ellipse at 50% 80%, #0d0a06 55%, #1c1610);
  border: 2px solid rgba(239, 236, 227, 0.35);
  transition: box-shadow 1s ease;
}
#climb-scene.arrived .cave { box-shadow: 0 0 34px rgba(255, 202, 106, 0.65); }
.climb-candle {
  position: absolute;
  width: 34px; height: 46px;
}
.climb-wax {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 9px; height: 24px; border-radius: 3px 3px 1px 1px;
  background: linear-gradient(90deg, #b8a888, #ede0c4 45%, #cbbb96);
  opacity: 0.55;
}
.climb-flame {
  position: absolute; bottom: 23px; left: 50%; transform: translateX(-50%);
  width: 8px; height: 13px; border-radius: 50% 50% 40% 40%;
  background: radial-gradient(circle at 50% 72%, #fff3d0, #ffca6a 45%, #e8862d 80%, transparent);
  opacity: 0;
  transition: opacity 0.5s ease;
}
.climb-candle.lit .climb-wax { opacity: 1; }
.climb-candle.lit .climb-flame { opacity: 1; animation: flicker 2s ease-in-out infinite; }
.climb-candle.hinted .climb-wax { box-shadow: 0 0 12px rgba(201, 162, 39, 0.8); opacity: 1; }

/* the way is shown: each candle flares gold as the path lights up */
.climb-candle.flash .climb-flame { opacity: 1; animation: none; }
.climb-candle.flash .climb-wax { opacity: 1; box-shadow: 0 0 16px 4px rgba(255, 205, 110, 0.9); }

/* the pilgrim climbs the rock candle by candle */
.pilgrim {
  position: absolute;
  width: 24px; height: auto;
  transform: translateX(-50%);
  transition: left 0.55s cubic-bezier(0.34, 0.1, 0.3, 1),
              bottom 0.55s cubic-bezier(0.34, 0.1, 0.3, 1);
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

/* the question each candle keeps, and its three answers */
#climb-quiz { max-width: 340px; margin: 0 auto; }
.climb-q {
  min-height: 2.6em;
  font-size: 1.1rem;
  color: var(--parchment);
  margin-bottom: 0.7rem;
}
.climb-answers { display: flex; flex-direction: column; gap: 0.5rem; }
.answer {
  padding: 0.6rem 1rem;
  font-family: var(--font); font-size: 1.02rem;
  color: var(--parchment); text-align: center;
  background: var(--charcoal-soft);
  border: 1px solid rgba(201, 162, 39, 0.4);
  border-radius: 4px; cursor: pointer;
  transition: border-color 0.3s ease, box-shadow 0.3s ease,
              opacity 0.5s ease, transform 0.12s ease;
}
.answer:hover:not(:disabled) { border-color: var(--gold); box-shadow: 0 0 10px rgba(201, 162, 39, 0.3); }
.answer:active:not(:disabled) { transform: scale(0.97); }
.answer.burnt { opacity: 0.3; text-decoration: line-through; cursor: default; }
.answer.right {
  border-color: var(--gold); color: var(--gold-soft);
  box-shadow: 0 0 14px rgba(201, 162, 39, 0.45);
}

/* the wind gust when a false answer burns away */
#climb-scene.gust { animation: gust-shake 0.5s ease; }
@keyframes gust-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); } 40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(2px); }
}

@media (prefers-reduced-motion: reduce) {
  .pilgrim { transition: none; }
  #climb-scene.gust { animation: none; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.2s !important;
  }
  #intro-title { letter-spacing: 0.22em; }
  .subtitle, .btn, .candle { opacity: 1; }
  .subtitle { opacity: 0.85; }
}
