/* —— The walk to the castle —— */

.kingdom-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transition: opacity 0.9s ease;
}

.kingdom-canvas--ground {
  z-index: 1;
}

.kingdom-canvas--near {
  z-index: 3;
}

/* At the door the meadow stays underfoot; only the near things fade away */
body[data-walk="arrived"] .kingdom-canvas--near {
  opacity: 0;
}

/* The walk draws its own fields and path, so the castle's own give way */
body[data-walk] .landscape,
body[data-walk] .castle .kingdom-path,
body[data-walk] .castle .bank--front {
  display: none;
}

/* While she walks, the page holds still and the gate waits */
body[data-walk="walking"] {
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

body[data-walk="walking"] .castle-wrap {
  transform: scale(0.1667);
}

.castle-wrap {
  transform-origin: 50% 90.4%;
  will-change: transform;
}

.landscape,
.story,
.castle-wrap::after,
.knocker {
  transition: opacity 0.9s ease 0.2s, visibility 0s linear 0s;
}

body[data-walk="walking"] .landscape,
body[data-walk="walking"] .story,
body[data-walk="walking"] .castle-wrap::after,
body[data-walk="walking"] .knocker {
  opacity: 0;
  visibility: hidden;
  transition: none;
}

/* The walk control */
.walk-ui {
  position: fixed;
  left: 50%;
  bottom: max(1.4rem, calc(env(safe-area-inset-bottom) + 0.8rem));
  z-index: 30;
  display: grid;
  justify-items: center;
  gap: 0.6rem;
  translate: -50% 0;
  transition: opacity 0.6s ease, translate 0.6s ease;
}

body[data-walk="arrived"] .walk-ui {
  opacity: 0;
  translate: -50% 1rem;
  pointer-events: none;
}

/* A game-style thumbstick: hold it, or push it up, to walk */
.walk-stick {
  position: relative;
  display: grid;
  place-items: center;
  width: 5.2rem;
  height: 5.2rem;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(232, 201, 138, 0.45);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, rgba(60, 22, 36, 0.55), rgba(18, 6, 12, 0.8));
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.45),
    inset 0 0 18px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.walk-stick::before {
  content: "";
  position: absolute;
  top: 0.45rem;
  left: 50%;
  width: 0;
  height: 0;
  translate: -50% 0;
  border: 0.32rem solid transparent;
  border-bottom-color: rgba(232, 201, 138, 0.55);
  border-top: 0;
}

.walk-stick:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}

.walk-stick__knob {
  display: grid;
  place-items: center;
  width: 2.9rem;
  height: 2.9rem;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fbe6b0, #d4a94e 70%, #8a6424);
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.45),
    inset 0 -2px 4px rgba(90, 50, 20, 0.35);
  transition: transform 0.18s cubic-bezier(0.3, 1.4, 0.5, 1), box-shadow 0.2s ease;
  animation: walk-beckon 2.4s ease-in-out infinite;
}

.walk-stick__knob svg {
  width: 1.4rem;
  height: 1.4rem;
  fill: #5a2a18;
}

.walk-stick.is-pressed .walk-stick__knob {
  animation: none;
  transition: transform 0.06s linear;
  box-shadow:
    0 0 18px rgba(255, 210, 130, 0.7),
    inset 0 -2px 4px rgba(90, 50, 20, 0.35);
}

body[data-walk-started="1"] .walk-stick__knob {
  animation: none;
}

.walk-hint {
  margin: 0;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  background: rgba(24, 9, 16, 0.6);
  color: #f6e2b4;
  font-family: var(--font-display);
  font-size: 0.66rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: opacity 0.6s ease;
}

body[data-walk-started="1"] .walk-hint {
  opacity: 0;
}

.walk-hint kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 0.05em 0.35em;
  border: 1px solid rgba(232, 201, 138, 0.5);
  border-radius: 0.3em;
  font-family: var(--font-display);
  font-size: 0.95em;
  text-align: center;
}

.walk-hint__keys {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .walk-hint__touch {
    display: none;
  }

  .walk-hint__keys {
    display: inline;
  }
}

.walk-progress {
  --walked: 0%;
  width: 9rem;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, #e8c070 var(--walked), rgba(232, 201, 138, 0.25) var(--walked));
}

@keyframes walk-beckon {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .walk-stick__knob {
    animation: none;
    transition: none;
  }

  .kingdom-canvas,
  .walk-ui,
  .landscape,
  .story,
  .knocker {
    transition: none;
  }
}

/* —— At the door: a close view, and a game-style prompt to knock —— */
/* The castle is scaled up here, so words inside it scale back down. */
.castle-wrap .guard-speech {
  scale: calc(1 / var(--zoom, 1));
}

.knocker__hint {
  scale: calc(1 / var(--zoom, 1));
  transform-origin: 50% 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.3em 0.8em;
  border: 1px solid rgba(232, 201, 138, 0.55);
  border-radius: 999px;
  background: rgba(24, 9, 16, 0.72);
  animation: knock-prompt 1.8s ease-in-out infinite;
}

.knocker__hint kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0.05em 0.35em;
  border: 1px solid rgba(232, 201, 138, 0.6);
  border-radius: 0.3em;
  background: rgba(232, 201, 138, 0.12);
  font-family: var(--font-display);
  text-align: center;
}

.knocker__hint-keys {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .knocker__hint-touch {
    display: none;
  }

  .knocker__hint-keys {
    display: inline;
  }
}

.knocker.is-knocked .knocker__hint {
  animation: none;
}

.knocker.is-pressed-key {
  transform: translateY(0.05rem) scale(0.95);
}

/* Up close, the warden does the talking: the title below steps aside. */
body[data-walk="arrived"] .story {
  display: none;
}

@keyframes knock-prompt {
  0%,
  100% {
    opacity: 0.85;
  }
  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .knocker__hint {
    animation: none;
  }
}
