:root {
  color-scheme: dark;
  --castle-width: 828px;
  --button-image: url("../assets/common/button.png");
  --danger-image: url("../assets/common/button-danger.png");
  --torch-sprite: url("../assets/common/torch-sprite.png");
  --top-image: url("../assets/day/castle-top.png");
  --mid-image: url("../assets/day/castle-mid.png");
  --base-image: url("../assets/day/castle-base.png");
  --cloud-image: url("../assets/day/clouds.png");
  --outer-bg-top: #1d6fba;
  --outer-bg-bottom: #07111b;
  --ambient-glow: rgba(127, 198, 255, 0.2);
  --dialog-glow: rgba(255, 202, 92, 0.32);
}

html[data-theme="dawn"] {
  --top-image: url("../assets/dawn/castle-top.png");
  --mid-image: url("../assets/dawn/castle-mid.png");
  --base-image: url("../assets/dawn/castle-base.png");
  --cloud-image: url("../assets/dawn/clouds.png");
  --outer-bg-top: #6c355b;
  --outer-bg-bottom: #100d1a;
  --ambient-glow: rgba(255, 156, 107, 0.24);
  --dialog-glow: rgba(255, 151, 88, 0.38);
}

html[data-theme="night"] {
  --top-image: url("../assets/night/castle-top.png");
  --mid-image: url("../assets/night/castle-mid.png");
  --base-image: url("../assets/night/castle-base.png");
  --cloud-image: url("../assets/night/clouds.png");
  --outer-bg-top: #08132c;
  --outer-bg-bottom: #020409;
  --ambient-glow: rgba(101, 137, 255, 0.18);
  --dialog-glow: rgba(255, 135, 54, 0.4);
}

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

html {
  min-width: 280px;
  background: var(--outer-bg-bottom);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  color: #f7e8bd;
  background:
    radial-gradient(circle at 50% 18%, var(--ambient-glow), transparent 46rem),
    linear-gradient(to bottom, var(--outer-bg-top), var(--outer-bg-bottom));
  font-family: Georgia, "Times New Roman", serif;
  transition: background 1.2s ease;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.75rem 1rem;
  color: #1c1208;
  background: #f5d78a;
  border: 3px solid #3a210d;
  transform: translateY(-180%);
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.page-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0 max(0px, env(safe-area-inset-right)) 0 max(0px, env(safe-area-inset-left));
}

.castle {
  position: relative;
  width: min(100%, var(--castle-width));
  overflow: hidden;
  isolation: isolate;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5),
    0 0 3.5rem rgba(0, 0, 0, 0.52);
  background: #303030;
}

.castle-section {
  position: relative;
  width: 100%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
}

.castle-top {
  z-index: 3;
  aspect-ratio: 828 / 604;
  overflow: visible;
  background-image: var(--top-image);
}

.castle-mid {
  z-index: 2;
  aspect-ratio: 828 / 524;
  background-image: var(--mid-image);
}

.castle-base {
  z-index: 1;
  aspect-ratio: 828 / 771;
  background-image: var(--base-image);
}

.cloud-window {
  position: absolute;
  z-index: 1;
  inset: 0 0 auto;
  height: 54%;
  overflow: hidden;
  pointer-events: none;
  mask-image: linear-gradient(to bottom, #000 0%, #000 74%, transparent 100%);
}

.cloud-layer {
  position: absolute;
  inset: -13% -12%;
  background-image: var(--cloud-image);
  background-repeat: no-repeat;
  background-position: center top;
  background-size: 115% auto;
  opacity: 0.47;
  will-change: transform;
  mix-blend-mode: screen;
}

.cloud-layer-one {
  animation: cloud-drift-one 38s ease-in-out infinite alternate;
}

.cloud-layer-two {
  opacity: 0.22;
  filter: blur(0.5px);
  transform: translate3d(-4%, 2%, 0) scale(1.06);
  animation: cloud-drift-two 54s ease-in-out infinite alternate;
}

@keyframes cloud-drift-one {
  from { transform: translate3d(-3%, 0, 0) scale(1.02); }
  to { transform: translate3d(3%, 1.5%, 0) scale(1.04); }
}

@keyframes cloud-drift-two {
  from { transform: translate3d(4%, 2%, 0) scale(1.08); }
  to { transform: translate3d(-4%, -0.5%, 0) scale(1.04); }
}

.title-scene {
  position: absolute;
  z-index: 4;
  inset: 0;
  pointer-events: none;
}

.site-logo {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: 50%;
  width: 72%;
  height: auto;
  transform: translateX(-50%);
  image-rendering: auto;
  filter: drop-shadow(0 0.45rem 0.3rem rgba(0, 0, 0, 0.65));
}

.construction-sign {
  position: absolute;
  z-index: 4;
  top: 77%;
  left: 50%;
  width: 45%;
  height: auto;
  transform-origin: 50% 4%;
  transform: translateX(-50%) rotate(-1.4deg);
  filter: drop-shadow(0 0.55rem 0.3rem rgba(0, 0, 0, 0.62));
  animation: sign-sway 4.8s ease-in-out infinite alternate;
}

@keyframes sign-sway {
  from { transform: translateX(-50%) rotate(-1.6deg); }
  to { transform: translateX(-50%) rotate(1.6deg); }
}

.torch {
  position: absolute;
  z-index: 5;
  top: 55%;
  width: 9.05%;
  aspect-ratio: 80 / 220;
  background-image: var(--torch-sprite);
  background-repeat: no-repeat;
  background-size: 1700% 100%;
  filter:
    drop-shadow(0 0 0.25rem rgba(255, 99, 18, 0.95))
    drop-shadow(0 0 0.9rem rgba(255, 120, 25, 0.7));
  animation: torch-play 1.12s steps(16, end) infinite;
}

.torch-left {
  left: 8.7%;
}

.torch-right {
  right: 8.7%;
  transform: scaleX(-1);
}

@keyframes torch-play {
  from { background-position: 0 0; }
  to { background-position: 100% 0; }
}

html[data-theme="day"] .torch {
  top: 61%;
  width: 4.35%;
  aspect-ratio: 23 / 40;
  background-image: url("../assets/day/torch-unlit.png");
  background-size: contain;
  background-position: center;
  filter: drop-shadow(0 0.25rem 0.2rem rgba(0, 0, 0, 0.65));
  animation: none;
}

html[data-theme="day"] .torch-left {
  left: 10.6%;
}

html[data-theme="day"] .torch-right {
  right: 10.6%;
}

.castle-menu {
  position: absolute;
  z-index: 5;
  inset: 23% 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.3rem, 1.25vw, 0.65rem);
}

.nav-button {
  position: relative;
  width: 58%;
  aspect-ratio: 6 / 1;
  padding: 0 7%;
  border: 0;
  border-radius: 0;
  color: #f5d98c;
  background-color: transparent;
  background-image: var(--button-image);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  cursor: pointer;
  text-align: center;
  font-size: clamp(0.82rem, 3.3vw, 1.52rem);
  font-weight: 700;
  letter-spacing: 0.055em;
  line-height: 1;
  text-shadow:
    0 2px 0 #2d1908,
    1px 0 0 #2d1908,
    -1px 0 0 #2d1908,
    0 0 0.45rem rgba(0, 0, 0, 0.85);
  filter: drop-shadow(0 0.45rem 0.18rem rgba(0, 0, 0, 0.48));
  transition: transform 130ms ease, filter 160ms ease;
}

.nav-button > span {
  position: relative;
  top: -1%;
}

.nav-button:hover,
.nav-button:focus-visible {
  outline: none;
  transform: translateY(-2px) scale(1.012);
  filter:
    brightness(1.08)
    drop-shadow(0 0.52rem 0.2rem rgba(0, 0, 0, 0.55));
}

.nav-button:active {
  transform: translateY(1px) scale(0.99);
}

.danger-button:hover,
.danger-button:focus-visible,
.danger-button.is-enraged {
  color: #ffd7c7;
  background-image: var(--danger-image);
  filter:
    brightness(1.13)
    drop-shadow(0 0 0.28rem #ff1c0b)
    drop-shadow(0 0 1rem rgba(255, 20, 0, 0.9));
  animation: angry-shake 320ms linear infinite;
}

@keyframes angry-shake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  20% { transform: translate(-2px, 1px) rotate(-0.35deg); }
  40% { transform: translate(2px, -1px) rotate(0.35deg); }
  60% { transform: translate(-1px, -1px) rotate(-0.25deg); }
  80% { transform: translate(2px, 1px) rotate(0.25deg); }
}

.social-links {
  position: absolute;
  z-index: 4;
  top: 11.5%;
  left: 50%;
  width: 62%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: center;
  gap: 2.2%;
}

.social-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  padding: 7%;
  border: 0;
  border-radius: 50%;
  background: rgba(14, 10, 7, 0.17);
  cursor: pointer;
  filter: drop-shadow(0 0.3rem 0.18rem rgba(0, 0, 0, 0.6));
  transition: transform 150ms ease, filter 180ms ease, background 180ms ease;
}

.social-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.social-button:hover,
.social-button:focus-visible {
  outline: 2px solid rgba(255, 221, 142, 0.78);
  outline-offset: 2px;
  transform: translateY(-5%) scale(1.09);
  background: rgba(255, 213, 118, 0.13);
  filter:
    brightness(1.1)
    drop-shadow(0 0.38rem 0.2rem rgba(0, 0, 0, 0.65))
    drop-shadow(0 0 0.4rem rgba(255, 201, 92, 0.45));
}

.social-button:active {
  transform: translateY(0) scale(0.96);
}

.medieval-dialog {
  width: min(90vw, 34rem);
  max-height: min(82vh, 42rem);
  padding: 0;
  border: 0;
  color: #f6e2ad;
  background: transparent;
  overflow: visible;
}

.medieval-dialog::backdrop {
  background: rgba(4, 3, 3, 0.78);
  backdrop-filter: blur(3px);
}

.dialog-frame {
  position: relative;
  padding: clamp(2rem, 8vw, 3.4rem) clamp(1.35rem, 6vw, 3rem) clamp(1.5rem, 6vw, 2.5rem);
  text-align: center;
  background:
    linear-gradient(rgba(51, 26, 10, 0.22), rgba(11, 6, 3, 0.25)),
    repeating-linear-gradient(0deg, #613713 0 5px, #543012 5px 10px, #6d4018 10px 15px);
  border: clamp(0.45rem, 2vw, 0.75rem) ridge #8b633a;
  box-shadow:
    inset 0 0 0 3px #2b1709,
    inset 0 0 2rem rgba(0, 0, 0, 0.65),
    0 0 0 4px #17100a,
    0 1.2rem 3rem rgba(0, 0, 0, 0.72),
    0 0 2rem var(--dialog-glow);
}

.dialog-frame::before,
.dialog-frame::after {
  content: "";
  position: absolute;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  top: 0.8rem;
  background: radial-gradient(circle at 38% 35%, #d7c5a0 0 8%, #65574a 24%, #24201c 62%, #0d0c0a 100%);
}

.dialog-frame::before { left: 0.9rem; }
.dialog-frame::after { right: 0.9rem; }

.dialog-ornament {
  position: absolute;
  top: 0.65rem;
  left: 50%;
  transform: translateX(-50%);
  color: #e8c66c;
  font-size: 1.45rem;
  text-shadow: 0 0 0.65rem #ff9b28;
}

.medieval-dialog h2 {
  margin: 0 0 1rem;
  color: #ffe5a0;
  font-size: clamp(1.45rem, 6vw, 2.2rem);
  line-height: 1.08;
  text-shadow: 0 2px 0 #2d1708, 0 0 0.65rem rgba(255, 190, 73, 0.38);
}

.medieval-dialog p {
  margin: 0 auto 1.5rem;
  max-width: 28rem;
  color: #f3dfb1;
  font-size: clamp(1rem, 3.8vw, 1.18rem);
  line-height: 1.55;
  text-shadow: 0 1px 0 #1b0d05;
}

.dialog-close {
  min-width: 12rem;
  padding: 0.7rem 1.1rem;
  border: 3px ridge #a8793d;
  color: #ffe8ad;
  background: linear-gradient(#5c3415, #321a0b);
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.035em;
  box-shadow: inset 0 0 0 1px #241207, 0 0.35rem 0.5rem rgba(0, 0, 0, 0.42);
}

.dialog-close:hover,
.dialog-close:focus-visible {
  outline: 2px solid #ffd87a;
  outline-offset: 3px;
  filter: brightness(1.16);
}

.noscript-message {
  position: fixed;
  z-index: 200;
  right: 1rem;
  bottom: 1rem;
  left: 1rem;
  margin: 0 auto;
  max-width: 42rem;
  padding: 1rem;
  text-align: center;
  color: #2b1708;
  background: #f0d48f;
  border: 4px ridge #694218;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 520px) {
  .site-logo {
    top: 52%;
    width: 76%;
  }

  .construction-sign {
    top: 78%;
    width: 49%;
  }

  .torch {
    top: 57%;
    width: 9.42%;
  }

  .torch-left { left: 6.8%; }
  .torch-right { right: 6.8%; }

  html[data-theme="day"] .torch {
    top: 62%;
    width: 4.7%;
  }

  html[data-theme="day"] .torch-left { left: 8.5%; }
  html[data-theme="day"] .torch-right { right: 8.5%; }

  .castle-menu {
    inset: 25% 0 auto;
    gap: 0.24rem;
  }

  .nav-button {
    width: 64%;
    font-size: clamp(0.77rem, 4.3vw, 1.05rem);
  }

  .social-links {
    top: 10.5%;
    width: 72%;
    gap: 1.1%;
  }

  .social-button {
    padding: 5%;
  }
}

@media (min-width: 829px) {
  body::before,
  body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
  }

  body::before {
    background:
      linear-gradient(90deg, rgba(0, 0, 0, 0.2), transparent 22%, transparent 78%, rgba(0, 0, 0, 0.2));
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .torch {
    background-position: 0 0;
  }
}

/* Version 3: placement matched to the supplied 828 × 1899 layout sketch. */
.site-logo {
  top: 71.19%;
  width: 57.61%;
}

.construction-sign {
  top: 92.55%;
  width: 25.36%;
}

/* Corrected 17-frame sheet: each complete torch is centred in an 80 × 220 frame. */
.torch {
  top: 96.19%;
  width: 6.58%;
  aspect-ratio: 80 / 220;
  background-image: var(--torch-sprite);
  background-repeat: no-repeat;
  background-size: 1700% 100%;
  background-position: 0 0;
  animation: torch-play 1.12s steps(16, end) infinite;
  filter:
    drop-shadow(0 0.25rem 0.2rem rgba(0, 0, 0, 0.72))
    drop-shadow(0 0 0.23rem rgba(255, 99, 18, 0.95))
    drop-shadow(0 0 0.78rem rgba(255, 120, 25, 0.68));
}

.torch::before {
  content: none;
}

.torch-left {
  left: 12.68%;
}

.torch-right {
  right: 13.16%;
  transform: none;
}

html[data-theme="day"] .torch {
  top: 100.5%;
  width: 2.78%;
  aspect-ratio: 23 / 40;
  background-image: url("../assets/day/torch-unlit.png");
  background-size: contain;
  background-position: center;
  filter: drop-shadow(0 0.2rem 0.16rem rgba(0, 0, 0, 0.65));
}

html[data-theme="day"] .torch::before {
  content: none;
}

html[data-theme="day"] .torch-left {
  left: 14.20%;
}

html[data-theme="day"] .torch-right {
  right: 14.70%;
  transform: none;
}

.castle-menu {
  inset: auto;
  top: 47.14%;
  left: 11.35%;
  width: 74.15%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1.63%;
  row-gap: min(16.43vw, 136px);
  align-items: center;
}

.nav-button {
  width: 100%;
  aspect-ratio: 1050 / 175;
  padding: 0 6%;
  font-size: clamp(0.68rem, 2.3vw, 1.18rem);
}

.social-links {
  top: 12.30%;
  width: 53%;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5%;
}

.social-button {
  width: 100%;
  padding: 0;
  border-radius: 0;
  background: transparent;
}

.social-button:hover,
.social-button:focus-visible {
  outline: none;
  outline-offset: 0;
  transform: translateY(-5%) scale(1.10);
  background: transparent;
  filter:
    brightness(1.10)
    drop-shadow(0 0.38rem 0.2rem rgba(0, 0, 0, 0.65))
    drop-shadow(0 0 0.55rem rgba(255, 211, 92, 0.78));
}

@media (max-width: 520px) {
  .site-logo {
    top: 71.19%;
    width: 57.61%;
  }

  .construction-sign {
    top: 92.55%;
    width: 25.36%;
  }

  .torch {
    top: 96.19%;
    width: 6.58%;
  }

  .torch-left { left: 12.68%; }
  .torch-right { right: 13.16%; }

  html[data-theme="day"] .torch {
    top: 100.5%;
    width: 2.78%;
  }

  html[data-theme="day"] .torch-left { left: 14.20%; }
  html[data-theme="day"] .torch-right { right: 14.70%; }

  .castle-menu {
    top: 47.14%;
    left: 11.35%;
    width: 74.15%;
    column-gap: 1.63%;
    row-gap: min(16.43vw, 136px);
  }

  .nav-button {
    width: 100%;
    font-size: clamp(0.62rem, 2.75vw, 0.92rem);
  }

  .social-links {
    top: 12.30%;
    width: 53%;
    gap: 5%;
  }

  .social-button {
    padding: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .torch::before {
    background-position: 0 0;
  }
}
