/**
 * Palace walk — layout + responsive.
 * Spec: algos/01, 02, 10-photos, 11-responsive.
 * Ivory on shadow. No cards, no glass, no radius on frames.
 */

:root {
  --ivory: #f4ede4;
  --ivory-mute: rgba(244, 237, 228, 0.72);
  --halo: 0 1px 2px rgba(20, 8, 4, 0.7), 0 0 18px rgba(20, 8, 4, 0.35);
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", system-ui, sans-serif;
  --gold: rgba(212, 175, 92, 0.72);
  --gold-line: rgba(212, 175, 92, 0.38);
  --gutter: clamp(16px, 4vw, 56px);
  --nav-h: 4.25rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: #140804; color: var(--ivory); }
html {
  -webkit-text-size-adjust: 100%;
}
html.walk-on { scroll-snap-type: none; }

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
::selection { background: rgba(201, 168, 106, 0.35); color: var(--ivory); }

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 30;
  padding: 8px 12px;
}
.skip:focus { top: calc(8px + var(--safe-top)); }

/* ----- Nav ----- */
.nav {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: var(--nav-h);
  padding: calc(12px + var(--safe-top)) var(--gutter) 12px;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-shadow: var(--halo);
}
.nav a { min-height: 44px; display: inline-flex; align-items: center; }
.nav nav { display: flex; gap: clamp(1.4rem, 3.2vw, 2.8rem); }
.nav nav a[aria-current="page"] { box-shadow: inset 0 -1px 0 var(--gold); }
.wordmark {
  font-family: var(--serif);
  font-size: 1.45rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.nav-toggle {
  display: none;
  width: 44px;
  height: 44px;
  position: relative;
}
.nav-toggle span {
  position: absolute;
  left: 12px;
  right: 12px;
  height: 1px;
  background: var(--ivory);
  box-shadow: var(--halo);
}
.nav-toggle span:first-child { top: 18px; }
.nav-toggle span:last-child { top: 26px; }
.nav.is-open .nav-toggle span:first-child { top: 22px; transform: rotate(45deg); }
.nav.is-open .nav-toggle span:last-child { top: 22px; transform: rotate(-45deg); }

/* ----- Chambers ----- */
.chamber-art { position: absolute; inset: 0; z-index: 0; }
.chamber-fx {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.chamber-type {
  position: absolute;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: clamp(1.25rem, 3vh, 2.4rem);
  color: var(--ivory);
  text-shadow: var(--halo);
  max-width: min(42ch, calc(100% - 2 * var(--gutter)));
  max-height: calc(100dvh - var(--nav-h) - 2rem - var(--safe-bottom));
  overflow: auto;
  padding-right: 8px;
  -webkit-overflow-scrolling: touch;
}
.chamber-type h1,
.chamber-type h2 {
  font-family: var(--serif);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: 0.04em;
  margin: 0;
  text-wrap: balance;
}
.chamber-type h1 { font-size: clamp(2.2rem, 7vw, 6rem); letter-spacing: 0.06em; }
#dawn .chamber-type,
#terrace .chamber-type { justify-content: flex-start; }
#vault .chamber-type,
#library .chamber-type { justify-content: flex-start; }

.enter {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.enter-top,
.enter-bottom {
  position: absolute;
  margin: 0;
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ivory);
  text-shadow: var(--halo);
}
.enter-top {
  left: 50%;
  transform: translateX(-50%);
  top: calc(var(--nav-h) + 0.55rem);
  width: calc(100% - 2 * var(--gutter));
  text-align: center;
}
.enter-bottom {
  left: auto;
  right: var(--gutter);
  bottom: calc(1.15rem + var(--safe-bottom));
  max-width: min(28rem, 42vw);
  text-align: right;
}
.enter-name {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.02em;
  font-family: var(--serif);
  font-size: clamp(2.6rem, 6.5vw, 5.4rem);
  font-weight: 500;
  line-height: 0.88;
  letter-spacing: 0.14em;
  text-align: center;
  color: var(--ivory);
  text-shadow: 0 1px 2px rgba(20, 8, 4, 0.95), 0 0 18px rgba(20, 8, 4, 0.75), 0 8px 24px rgba(20, 8, 4, 0.55);
  pointer-events: none;
}
.enter-name span { display: block; }
.enter-pair {
  position: absolute;
  left: var(--gutter);
  right: var(--gutter);
  top: 38%;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 1rem;
  pointer-events: none;
}
.enter-side {
  width: min(26vw, 18rem);
  min-height: 10.5rem;
  pointer-events: auto;
  padding: 0.95rem 1.05rem;
  background: rgba(245, 226, 214, 0.92);
  color: #2c1a12;
  text-shadow: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-sizing: border-box;
}
.enter-side .intro,
.enter-side .subline {
  color: #4a3228;
  max-width: none;
  margin: 0;
}
.enter-side .whisper {
  color: #8a4a38;
  margin: 0 0 0.55rem;
}
.enter-side .actions {
  justify-content: flex-start;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  margin: 0;
}
.enter-side .actions a {
  color: #7a3d2e;
  min-height: 0;
  padding: 0.15rem 0;
}
.whisper {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  letter-spacing: 0.18em;
  color: var(--gold);
  margin: 0;
}
.chamber-type h2 { font-size: clamp(1.6rem, 3.2vw, 2.8rem); }
.eyebrow {
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 1.4rem;
}
.intro {
  font-family: var(--serif);
  font-size: clamp(1.05rem, 2.1vw, 1.55rem);
  line-height: 1.7;
  letter-spacing: 0.03em;
  margin: 0;
  max-width: 28ch;
}
.subline,
.lede,
.quiet {
  font-family: var(--sans);
  font-size: clamp(0.74rem, 1.4vw, 0.86rem);
  line-height: 1.85;
  letter-spacing: 0.04em;
  color: var(--ivory-mute);
  margin: 0;
  max-width: 38ch;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 2.2rem;
  margin: 0;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.actions a,
.contact-links a,
.ledger-list button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  text-align: left;
}
.actions a { text-decoration: underline; text-underline-offset: 4px; }
.ledger-list {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0;
  font-family: var(--sans);
  font-size: clamp(0.84rem, 1.5vw, 0.98rem);
  line-height: 1.7;
  letter-spacing: 0.02em;
}
.ledger-list li {
  margin: 0;
  padding: 1.15rem 0;
  border-bottom: 1px solid var(--gold-line);
}
.ledger-list li:first-child { padding-top: 0; }
.ledger-list li:last-child { border-bottom: 0; }
.ledger-list em {
  font-style: normal;
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  margin-left: 0.55rem;
}
.contact-links {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.4rem 0;
  font-family: var(--sans);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  line-height: 1.7;
}
.contact-links a { text-decoration: underline; text-underline-offset: 3px; word-break: break-word; }
.colophon {
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  line-height: 1.8;
  color: var(--ivory-mute);
  max-width: 42ch;
}

.tiny-row { display: flex; gap: 1.1rem; flex-wrap: wrap; margin-top: 0.45rem; }
.tiny, .back {
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 3px;
  min-height: 36px;
}
.pts {
  margin: 0.5rem 0 0;
  padding: 0 0 0 1.05rem;
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--ivory-mute);
}
.sheet {
  position: absolute;
  z-index: 5;
  pointer-events: auto;
  width: min(34rem, 42vw);
  max-height: calc(100dvh - var(--nav-h) - 4rem);
  overflow: auto;
  padding: 1.2rem 1.3rem 1.4rem;
  background: rgba(14, 8, 4, 0.55);
  border: 1px solid var(--gold-line);
  color: var(--ivory);
  text-shadow: var(--halo);
}
.sheet h2 {
  font-family: var(--serif);
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  margin: 0 0 0.5rem;
}
#library .sheet { left: var(--gutter); bottom: 8vh; top: auto; }

.rail-kicker {
  position: absolute;
  left: 50%;
  top: calc(var(--nav-h) + 0.4rem);
  transform: translateX(-50%);
  margin: 0;
  z-index: 2;
}

.rail {
  position: absolute;
  top: calc(var(--nav-h) + 2.8rem);
  bottom: 5.5rem;
  width: min(28vw, 20rem);
  overflow: hidden;
  color: var(--ivory);
  text-shadow: none;
  text-align: left;
}
.rail--left { left: var(--gutter); }
.rail--right { right: var(--gutter); left: auto; }
.rail::-webkit-scrollbar,
.bay::-webkit-scrollbar,
.shelf::-webkit-scrollbar { display: none; }

.card,
.job-card {
  margin: 0 0 1.1rem;
  padding: 0.95rem 1.05rem 1.05rem;
  background: rgba(245, 226, 214, 0.92);
  color: #2c1a12;
  text-shadow: none;
  border: 1px solid rgba(90, 48, 32, 0.08);
}
.card h3,
.job-card strong {
  font-family: var(--serif);
  font-size: clamp(1.6rem, 2.8vw, 2.4rem);
  font-weight: 500;
  letter-spacing: 0.06em;
  margin: 0 0 0.35rem;
  line-height: 1.05;
  color: #2c1a12;
}
.card-line,
.job-card p,
.card .pts,
.job-card .pts {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  max-width: 32ch;
  color: #4a3228;
}
.card .pts,
.job-card .pts { margin-top: 0.4rem; color: #4a3228; }
.card .tiny,
.job-card .tiny { color: #7a3d2e; }
#courtyard .rail {
  width: min(28vw, 20rem);
  list-style: none;
  margin: 0;
  padding: 0;
}
#courtyard .job-card {
  margin: 0 0 0.9rem;
  padding: 0.95rem 1.1rem 1.05rem;
  border-left: 3px solid #c45c26;
  background: rgba(245, 226, 214, 0.95);
}
#courtyard .job-card strong {
  font-size: clamp(1.35rem, 2.1vw, 1.75rem);
  margin: 0 0 0.3rem;
  letter-spacing: 0.02em;
  line-height: 1.12;
}
.step-when {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #8a4a38;
  margin-bottom: 0.35rem;
}
.step-org {
  display: block;
  font-size: 0.88rem;
  line-height: 1.4;
  color: #5c4033;
  margin: 0 0 0.5rem;
}
#courtyard .job-line {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(0.95rem, 1.35vw, 1.12rem);
  line-height: 1.5;
  color: #3d2a22;
  max-width: none;
}
.school--floor {
  position: absolute;
  left: 50%;
  bottom: calc(5.1rem + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(40rem, 46vw);
  margin: 0;
  padding: 0.6rem 0.95rem;
  font-size: 0.82rem;
  color: #4a3228;
  background: rgba(245, 226, 214, 0.88);
  text-align: center;
}

.shelf {
  position: absolute;
  top: calc(var(--nav-h) + 2.8rem);
  bottom: 5.5rem;
  width: min(32vw, 22rem);
  overflow: hidden;
  color: var(--ivory);
  text-shadow: none;
  text-align: left;
}
.shelf--left { left: var(--gutter); }
.shelf--right { left: calc(var(--gutter) + min(32vw, 22rem) + 1.25rem); right: auto; }
.book {
  margin: 0 0 1.3rem;
  padding: 0.85rem 1rem;
  background: rgba(245, 226, 214, 0.92);
  color: #2c1a12;
  border: 1px solid rgba(90, 48, 32, 0.08);
}
.book-face {
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
  padding: 0;
  min-height: 0;
  color: inherit;
}
.book h3 {
  font-family: var(--serif);
  font-size: clamp(1.45rem, 2.4vw, 2rem);
  font-weight: 500;
  margin: 0 0 0.3rem;
  color: #2c1a12;
}
.book-line {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  line-height: 1.4;
  margin: 0;
  max-width: 30ch;
  color: #4a3228;
}
.book .pts { color: #4a3228; }
.book .tiny { color: #7a3d2e; }
.book-open { display: none; margin-top: 0.45rem; }
.book.is-open .book-open { display: block; }
.book.is-open { border-color: var(--gold); }
#library.is-reading .book:not(.is-open) { opacity: 0.28; }

.next-gate {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: calc(1.1rem + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  color: var(--ivory);
  text-shadow: var(--halo);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 0.65rem;
  font-family: var(--sans);
  min-height: 44px;
  cursor: pointer;
}
.next-gate[hidden] { display: none; }
.next-arrow {
  width: 10px;
  height: 10px;
  border-right: 1px solid var(--gold);
  border-bottom: 1px solid var(--gold);
  transform: rotate(45deg);
  animation: gate-bob 2.6s ease-in-out infinite;
}
@keyframes gate-bob {
  0%, 100% { transform: rotate(45deg) translateY(0); }
  50% { transform: rotate(45deg) translateY(4px); }
}
@media (prefers-reduced-motion: reduce) {
  .next-arrow { animation: none; }
}

/* ----- Terrace seals ----- */
.arrival {
  position: absolute;
  z-index: 3;
  left: auto;
  right: var(--gutter);
  bottom: calc(8vh + var(--safe-bottom));
  max-width: min(26rem, 34vw);
  color: var(--ivory);
  text-shadow: var(--halo);
  text-align: left;
}
.write {
  font-family: var(--serif);
  font-size: clamp(3.4rem, 10vw, 7.5rem);
  line-height: 0.85;
  letter-spacing: 0.08em;
  margin: 0 0 0.6rem;
  max-width: none;
}
.seals {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 1.3rem 0 1rem;
}
.seal {
  min-height: 44px;
  padding: 0.55rem 1.15rem;
  border: 1px solid var(--gold-line);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.7rem;
  font-family: var(--sans);
}
.seal:hover { border-color: var(--gold); color: var(--gold); }
.campus {
  font-size: 0.78rem;
  margin: 0 0 1.1rem;
  opacity: 0.7;
}
.campus a { text-decoration: underline; text-underline-offset: 3px; }

.me-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 2 / 3;
  border: 1px solid var(--gold-line);
  background: #140804;
}
.me-frame::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(212, 175, 92, 0.22);
  pointer-events: none;
}
.me-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 12%;
}
.me-frame.is-empty { display: none; }

@media (prefers-reduced-motion: no-preference) {
  .chamber-art img {
    transform-origin: 50% 50%;
    transition: none;
  }
  .is-kenburning .chamber-art img {
    animation: ken 22s ease-in-out alternate infinite;
  }
  #dawn.is-kenburning .chamber-art img { transform-origin: 50% 50%; }
  #vault.is-kenburning .chamber-art img { transform-origin: 40% 50%; }
  #courtyard.is-kenburning .chamber-art img { transform-origin: 50% 70%; }
  #library.is-kenburning .chamber-art img { transform-origin: 30% 45%; }
  #terrace.is-kenburning .chamber-art img { transform-origin: 40% 70%; }
  @keyframes ken {
    from { transform: scale(1); }
    to { transform: scale(1.045); }
  }
  .dust-mote {
    position: absolute;
    border-radius: 50%;
    background: var(--ivory);
    opacity: 0;
    animation: dust-drift linear infinite;
  }
  @keyframes dust-drift {
    0% { transform: translate(0, 0); opacity: 0; }
    18% { opacity: var(--dust-o, 0.16); }
    100% { transform: translate(var(--dust-x, 2px), calc(-1 * var(--dust-y, 10px))); opacity: 0; }
  }
}

[data-stub] { outline: none; }

/* ----- Tablet ----- */
@media (max-width: 1024px) {
  .rail, .shelf { width: min(34vw, 18rem); }
}

/* ----- Phone ----- */
@media (max-width: 767px) {
  :root { --gutter: 14px; --nav-h: 3.6rem; }

  .nav { z-index: 40; }
  .nav-toggle { display: block; z-index: 42; }
  .nav nav {
    position: fixed;
    inset: 0;
    z-index: 41;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 0.35rem;
    padding: calc(var(--nav-h) + var(--safe-top) + 0.5rem) var(--gutter) 12vh;
    background: rgba(14, 8, 4, 0.92);
    transform: translateY(-110%);
    transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .nav.is-open nav { transform: none; }
  .nav nav a {
    font-family: var(--serif);
    font-size: clamp(1.7rem, 8vw, 2.4rem);
    letter-spacing: 0.02em;
    text-transform: none;
    min-height: 48px;
  }

  .shot img { object-position: 50% 28%; }

  .enter-name {
    top: 16%;
    font-size: clamp(1.8rem, 9vw, 2.6rem);
    letter-spacing: 0.1em;
  }
  .enter-top { top: calc(var(--nav-h) + 0.25rem); font-size: 0.58rem; letter-spacing: 0.14em; }
  .enter-bottom {
    left: auto;
    right: var(--gutter);
    bottom: calc(0.55rem + var(--safe-bottom));
    max-width: 46vw;
    font-size: 0.52rem;
    letter-spacing: 0.1em;
    text-align: right;
  }
  .enter-pair {
    top: auto;
    bottom: calc(4.9rem + var(--safe-bottom));
    gap: 0.55rem;
  }
  .enter-side {
    width: 0;
    flex: 1 1 0;
    min-height: 8.75rem;
    padding: 0.7rem 0.75rem;
  }

  #vault.room,
  #courtyard.room,
  #library.room,
  #terrace.room {
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: calc(var(--nav-h) + 2rem) var(--gutter) calc(5.4rem + var(--safe-bottom));
  }
  .rail-kicker {
    position: static;
    transform: none;
    left: auto;
    margin: 0 0 0.85rem;
    text-align: left;
  }
  .rail,
  .shelf,
  .bays,
  .arrival {
    position: static;
    inset: auto;
    width: 100%;
    max-width: none;
    overflow: visible;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
  }
  .shelf--right { left: auto; }
  #courtyard .rail { width: 100%; }
  .school--floor {
    position: static;
    transform: none;
    width: 100%;
    margin-top: 0.6rem;
    text-align: left;
  }
  .card h3, .job-card strong { font-size: clamp(1.35rem, 6vw, 1.8rem); }
  .write { font-size: clamp(2.4rem, 14vw, 3.4rem); }
  .seals { gap: 0.45rem; }
  .seal { min-height: 44px; padding: 0.5rem 0.9rem; }
  .next-gate { font-size: 0.6rem; }
}

/* ----- Narrow phones ----- */
@media (max-width: 420px) {
  .nav { font-size: 0.65rem; }
  .enter-name { font-size: 1.7rem; }
  .write { font-size: 2.2rem; }
}

/* ----- Landscape phones ----- */
@media (max-height: 500px) and (orientation: landscape) {
  .enter-name { top: 12%; font-size: 1.6rem; }
  .enter-side { display: none; }
  #vault.room,
  #courtyard.room,
  #library.room,
  #terrace.room {
    padding-top: calc(var(--nav-h) + 0.6rem);
    padding-bottom: 3.5rem;
  }
}

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