/* ── Typed custom property — enables smooth CSS transition of --stage-ar ──── */
@property --stage-ar {
  syntax: '<number>';
  inherits: false;
  initial-value: 1.5;
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
body {
  background: #fff;
  margin: 0;
  padding: 0;
  font-family: 'Times New Roman', Times, serif;
  font-size: 1.4rem;
  overflow-x: hidden;
  text-transform: uppercase;
}

/* ── Title area: fixed full-width header, centered over full viewport ──────── */
#title-area {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  text-align: center;
  padding: 12px 0rem 12px;
}

/* Lichen canvas — dynamically created by LichenZone, appended to parent */
.lichen-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10; /* Page-level default, overridden inline by viewer */
  pointer-events: none;
}

/* Sentence container */
.sentence-container {
  text-align: center;
  padding: 0;
  line-height: 1.05;
  position: relative;
  z-index: 1;
  display: block;
  white-space: nowrap;
}

/* Subtitle styling */
.subtitle {
  margin-top: 0;
  font-family: 'Times New Roman', Times, serif;
  white-space: nowrap;
}

.subtitle .letter {
  font-size: inherit;
}

.subtitle .space {
  width: 0;
}

/* Word wrapper */
.word {
  display: inline-block;
  white-space: nowrap;
  margin: 0 0.15em;
}

/* Letter styling */
.letter {
  display: inline-block;
  position: relative;
  line-height: inherit;
  transition: opacity 0.1s linear;
}

/* Hole styling */
.letter-hole {
  display: inline-block;
  min-width: 0.3ch;
  height: 1em;
  cursor: pointer;
  transition: background 0.2s;
  vertical-align: baseline;
  line-height: inherit;
}

.letter-hole:hover {
  background: rgba(0, 0, 0, 0.08);
}

.letter-hole.drag-over {
  background: rgba(0, 0, 0, 0.1);
}

.letter-hole.active {
  background: rgba(0, 0, 0, 0.12);
}

/* Space styling */
.space {
  display: inline-block;
  width: 0;
}

/* Floor container */
.floor {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100px;
  z-index: 150;
  pointer-events: none;
}

/* Fallen letter styling */
.fallen-letter {
  position: fixed;
  cursor: grab;
  user-select: none;
  font-family: 'Times New Roman', Times, serif;
  font-size: 1.4rem;
  color: #000;
  pointer-events: all;
  transition: opacity 0.1s linear;
}

.fallen-letter:hover {
  transform: scale(1.1);
}

.fallen-letter:active {
  cursor: grabbing;
}

.fallen-letter.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

/* Falling animation */
.falling {
  position: fixed;
  pointer-events: none;
  z-index: 200;
  will-change: transform;
  transition: opacity 0.1s linear;
}

/* ── Fixed sidebar: scroll-synced timeline ───────────────────────────────── */
#sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: fit-content;
  overflow-y: scroll;
  scrollbar-width: none;
  background: none;
  will-change: scroll-position;

  padding-top: var(--title-h, 180px);
  padding-bottom: 40px;
  z-index: 5;
  font-family: 'Times New Roman', Times, serif;
}

#sidebar::-webkit-scrollbar {
  display: none;
}

#sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

#sidebar li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  white-space: nowrap;
  padding: 10px 20px;
  cursor: pointer;
  color: #000;
  opacity: 0.3;
  transition: opacity 0.3s;
}

#sidebar li:hover {
  opacity: 0.6;
}

#sidebar li.active {
  opacity: 1;
}

.sidebar-nr {
  font-size: 1.3rem;
  letter-spacing: 0.05em;
}

.sidebar-name {
  font-size: 1.3rem;
  line-height: 1.3;
}

.sidebar-info {
  font-size: 0.8rem;
  opacity: 0.5;
}

/* ── Page lichen zone (intro + crosses) ──────────────────────────────────── */
#lichen-page-zone {
  position: relative;
  /* margin-left: 360px; */
  width: 100vw;
  margin-top: 0;
  display: flow-root; /* prevent child margin-top from collapsing outward */
}

/* ── Intro section ────────────────────────────────────────────────────────── */
#intro {
  margin: 20% auto 20vh auto; /* Center horizontally with auto margins */
  max-width: 800px; /* Limit width for readability */
  padding: 0 24px 0;
  font-family: 'Times New Roman', Times, serif;
  line-height: auto;
  letter-spacing: 0.01em;
  text-align: center;
  color: #000;
}

/* ── Cross sections ───────────────────────────────────────────────────────── */
.cross-section {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  box-sizing: border-box;
}

/* ── Per-cross viewer ─────────────────────────────────────────────────────── */
.cross-viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(70vw, 1040px);
  position: relative;
  z-index: 20;
}


.cross-load-hint {
  font-size: 0.9rem;
  color: #999;
  margin: 32px 0;
}

.cross-section.loaded .cross-load-hint {
  display: none;
}

/* ── Image stack (per cross) ─────────────────────────────────────────────── */
.cross-frame-container {
  position: relative;
  width: 100%;
  max-height: 70vh;
  max-width: min(100%, calc(70vh * var(--stage-ar, 1.5)));
  aspect-ratio: var(--stage-ar, 1.5);
  overflow: visible;
  margin-bottom: 40px;
  transition: --stage-ar 0.4s ease, aspect-ratio 0.4s ease;
}

/* ── Per-frame wrapper ────────────────────────────────────────────────────── */
.frame-wrapper {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  transform-origin: center center;
  pointer-events: none;
  overflow: hidden;
}

.frame-wrapper img {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  z-index: 1;
}

/* ── Datum gradient (black corner fade behind date label) ─────────────────── */
.datum-gradient {
  position: absolute;
  width: 160px; height: 70px;
  background: radial-gradient(ellipse at bottom right, rgba(0,0,0,0.38) 0%, rgba(0,0,0,0.15) 40%, transparent 70%);
  transform-origin: bottom right;
  pointer-events: none;
  z-index: 20;
}

/* ── Datum label ─────────────────────────────────────────────────────────── */
.datum-label {
  position: absolute;
  font-family: 'Times New Roman', Times, serif;
  font-size: 0.8rem;
  font-weight: bold;
  letter-spacing: 0.03em;
  color: #fff;
  pointer-events: none;
  white-space: nowrap;
  padding: 0 2px 4px 0;
  opacity: 1;
  transform: translate(-100%, -100%);
  transform-origin: bottom right;
  z-index: 25;
}
.datum-label .letter-hole,
.datum-label .letter,
.datum-label .fallen-letter {
  pointer-events: auto;
}

/* ── Per-cross navigation row ────────────────────────────────────────────── */
.cross-nav {
  display: flex;
  align-items: center;
  gap: 0;
  margin-top: 24px;
  color: #000;
  position: relative;
  z-index: 20;
  background: rgba(255,255,255,0.25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 4px 10px;
  border-radius: 100px;
}

.cross-prev,
.cross-next {
  background: none;
  border: none;
  font-family: 'Times New Roman', Times, serif;
  font-size: 1.5rem;
  cursor: pointer;
  color: inherit;
  padding: 0px 10px 3px 10px;
  line-height: 1;
}
.cross-nav .word {
  margin-right: 0;
}

.cross-caption {
  display: none;
  font-size: 0.9rem;
  color: inherit;
  letter-spacing: 0.02em;
  text-align: center;
  min-width: 60px;
}

/* Manual kerning adjustments */
#sentenceContainer > .word:nth-child(7) { /* "in" */
  margin-left: 0.1em;
}

#sentenceContainer > .word:nth-child(9) > .letter:nth-child(4) { /* "v" in "Nörvenich" */
  margin-left: -0.08em;
}

#sentenceContainer > .word:nth-child(5) > .letter:nth-child(2) { /* "A" in "Baudenkmäler" */
    margin-left: -0.04em;
}

#sentenceContainer > .word:nth-child(5) > .letter:nth-child(3) { /* "U" in "Baudenkmäler" */
    margin-left: -0.08em;
}

#subtitleContainer > .word:nth-child(3) > .letter:nth-child(2) { /* "e" in "verfall" */
    margin-left: -0.05em;
}

#subtitleContainer > .word:nth-child(3) > .letter:nth-child(5) { /* "a" in "verfall" */
    margin-left: -0.07em;
}

#subtitleContainer > .word:nth-child(7) > .letter:nth-child(8) { /* "u" in "Wegekreuze" */
    margin-left: -0.03em;
}

/* General kerning for 'RI' pair */
.letter[data-char="R"] + .letter[data-char="I"] {
  margin-left: -0.08em;
}

/* Kerning for 'LT' pair (ALTERN, ERHALTEN, ALTERT, etc.) */
.letter[data-char="L"] + .letter[data-char="T"] {
  margin-left: -0.08em;
}

/* Additional pair kerning */
.letter[data-char="S"] + .letter[data-char="A"] {
  margin-left: -0.08em;
}
.letter[data-char="A"] + .letter[data-char="U"] {
  margin-left: -0.08em;
}
.letter[data-char="R"] + .letter[data-char="W"] {
  margin-left: -0.08em;
}
.letter[data-char="D"] + .letter[data-char="A"] {
  margin-left: -0.08em;
}
.letter[data-char="J"] + .letter[data-char="A"] {
  margin-left: -0.08em;
}
.letter[data-char="R"] + .letter[data-char="T"] {
  margin-left: -0.08em;
}
.letter[data-char="A"] + .letter[data-char="N"] {
  margin-left: -0.08em;
}
.letter[data-char="N"] + .letter[data-char="D"] {
  margin-left: -0.08em;
}
.letter[data-char="W"] + .letter[data-char="A"] {
  margin-left: -0.16em;
}
.letter[data-char="D"] + .letter[data-char="W"] {
  margin-left: -0.08em;
}
.letter[data-char="Ä"] + .letter[data-char="C"] {
  margin-left: -0.08em;
}
.letter[data-char="B"] + .letter[data-char="A"] {
  margin-left: -0.12em;
}
.letter[data-char="R"] + .letter[data-char="V"] {
  margin-left: -0.08em;
}

/* ── Legal footer ─────────────────────────────────────────────────────────── */
#legal-footer {
  position: relative;
  z-index: 30;
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 12vh;
  padding: 16px;
  color: #000;
  font-family: 'Times New Roman', Times, serif;
}

#legal-footer a {
  color: inherit;
  font-size: 0.68rem;
  line-height: 1.2;
  text-decoration: none;
}

#legal-footer a:hover,
#legal-footer a:focus-visible {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.legal-page {
  background: #fff;
  color: #000;
  font-family: 'Times New Roman', Times, serif;
}

.legal-page main {
  max-width: 760px;
  margin: 0 auto;
  padding: 8vh clamp(18px, 5vw, 54px) 10vh;
}

.legal-page a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.legal-back {
  display: inline-block;
  margin-bottom: 8vh;
  font-size: 0.72rem;
  text-transform: uppercase;
  text-decoration: none;
}

.legal-page h1 {
  margin: 0 0 28px;
  font-size: 1.35rem;
  font-weight: normal;
  line-height: 1.1;
  text-transform: uppercase;
}

.legal-page h2 {
  margin: 34px 0 12px;
  font-size: 0.98rem;
  font-weight: normal;
  line-height: 1.2;
  text-transform: uppercase;
}

.legal-page h3 {
  margin: 22px 0 8px;
  font-size: 0.9rem;
  font-weight: normal;
  line-height: 1.2;
}

.legal-page p,
.legal-page li {
  font-size: 0.88rem;
  line-height: 1.48;
}

.legal-page p {
  margin: 0 0 14px;
}

.legal-page ul {
  margin: 0 0 14px 1.1em;
  padding: 0;
}

/* ── Mobile responsive ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #title-area {
    padding-left: 0;
    padding-right: 0;
  }

  #sidebar {
    width: 250px;
    z-index: 1; /* behind lichen (z:10) and cross viewer (z:20) */
  }

  .sidebar-nr,
  .sidebar-name {
    font-size: 0.9rem;
  }

  .sidebar-info {
    font-size: 0.56rem;
  }

  #sidebar li {
    padding: 7px 14px;
    white-space: normal;
  }

  #lichen-page-zone {
    margin-left: 0;
    width: 100vw;
    overflow-x: hidden;
  }

  .cross-section {
    align-items: flex-start;
    padding: 10vh 10px 20px 10px;
  }

  .cross-viewer {
    width: min(92vw, 1040px);
  }

  #intro {
    margin: 30% auto 10vh auto;
    padding: 0 12px;
  }

  #legal-footer {
    margin-top: 8vh;
    padding: 14px;
  }

}
