:root {
  --fg: #f4f1ea;
  --accent: #ffb454;
  --panel: rgba(16, 16, 18, 0.82);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: #111;
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#scroll-space { width: 1px; }   /* height is set from config.js */

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;          /* let scroll / touch gestures through */
}
body.debug #stage { pointer-events: auto; cursor: grab; touch-action: none; }
body.debug #stage:active { cursor: grabbing; }
body.debug #scroll-space { display: none; }
body.debug #hud { display: none; }

/* ---- HUD ---------------------------------------------------------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }

/* Fixed corner wordmark: stays put while the room scrolls past */
#brand-wrap {
  position: absolute;
  top: max(4.5vh, 20px);
  right: max(6vw, 22px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.55em;
  font-size: calc(clamp(1.9rem, 4.4vw, 3.4rem) * var(--scale, 1));
  color: rgba(255, 255, 255, var(--brand-opacity, 0.7));
  /* the walls in the scan are near-white, so a soft shadow keeps it readable */
  text-shadow: 0 1px 14px rgba(0, 0, 0, 0.4), 0 0 2px rgba(0, 0, 0, 0.2);
  user-select: none;
}
#brand { line-height: 1; white-space: nowrap; }

/* A single name swaps as the visitor scrolls through the room. */
#brand-names {
  visibility: hidden; /* names are drawn into the repeated-text pixel mask */
  align-self: flex-start;
  min-height: 1.25em;
  font-size: 0.43em;
  line-height: 1.15;
  font-weight: inherit;
  letter-spacing: 0.015em;
  text-transform: lowercase;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 160ms ease, transform 180ms ease;
  /* Keep the names in the wordmark's type style, staggered like a loose column. */
  text-shadow: inherit;
}
#brand-names.name-jacob { transform: translate(0.05em, -0.08em); }
#brand-names.name-kade { transform: translate(0.72em, 0.16em); }


/* Menu words under the wordmark. Plain text for now: give an item an href in config.js to make it a link. */
#brand-nav {
  display: flex;
  gap: 1.2em;
  font-size: max(0.3em, 13px);      /* relative to the wordmark, never smaller than 13px */
  font-weight: 400;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.55), 0 0 2px rgba(0, 0, 0, 0.35);
  letter-spacing: 0.04em;
  line-height: 1;
  white-space: nowrap;
}
#brand-nav a { color: inherit; text-decoration: none; pointer-events: auto; }
#brand-nav a:hover, #brand-nav a:focus-visible { text-decoration: underline; text-underline-offset: 0.25em; }

#caption {
  position: absolute;
  left: 50%;
  bottom: max(8vh, 56px);
  transform: translate(-50%, 12px);
  max-width: min(80vw, 720px);
  padding: 0.6em 1.1em;
  font-size: clamp(1rem, 2.4vw, 1.5rem);
  text-align: center;
  letter-spacing: 0.01em;
  background: var(--panel);
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
#caption.visible { opacity: 1; transform: translate(-50%, 0); }
#caption:empty { display: none; }

#scroll-hint {
  position: absolute;
  left: 50%;
  bottom: max(2.5vh, 18px);
  transform: translateX(-50%);
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.75;
  transition: opacity 0.6s ease;
}
#scroll-hint.hidden { opacity: 0; }

#progress {
  position: absolute;
  right: 0;
  top: 0;
  width: 3px;
  height: 100%;
  background: rgba(255, 255, 255, 0.08);
}
#progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform-origin: top;
  transform: scaleY(0);
}

/* ---- Loading ------------------------------------------------------------ */
#loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: #111;
  transition: opacity 0.6s ease, visibility 0.6s;
}
#loading.done { opacity: 0; visibility: hidden; pointer-events: none; }
#logo {
  margin: 0;
  padding: 0 5vw;
  max-width: 100%;
  font-size: calc(clamp(2.6rem, 11vw, 7.5rem) * var(--scale, 1));
  font-weight: 400;
  line-height: 1.1;
  text-align: center;
  text-wrap: balance;
  color: var(--logo-color, var(--fg));
  opacity: 0;
  filter: blur(6px);
  transition: opacity 1.1s ease, filter 1.1s ease;
}
#logo.show { opacity: 1; filter: blur(0); }

/* ---- Notices (errors, "no path recorded yet") --------------------------- */
#notice {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  z-index: 30;
  max-width: min(92vw, 640px);
  padding: 0.7em 1.1em;
  font-size: 0.85rem;
  line-height: 1.45;
  background: var(--panel);
  border: 1px solid rgba(255, 180, 84, 0.5);
  border-radius: 10px;
}
#notice.error { border-color: #ff6b6b; }
#notice code { background: rgba(255, 255, 255, 0.12); padding: 0.1em 0.35em; border-radius: 4px; }

/* ---- Debug / path editor ------------------------------------------------ */
#debug-panel {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 15;
  width: 290px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.5;
  background: var(--panel);
  border-radius: 10px;
  backdrop-filter: blur(6px);
}
#debug-panel h2 { margin: 0 0 6px; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); }
#debug-panel .keys { margin: 0 0 10px; padding: 0; list-style: none; opacity: 0.85; }
#debug-panel kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 0.35em;
  text-align: center;
  font: inherit;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 4px;
}
#debug-panel .row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
#debug-panel button {
  flex: 1 1 auto;
  padding: 6px 8px;
  font: inherit;
  color: var(--fg);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  cursor: pointer;
}
#debug-panel button:hover { background: rgba(255, 255, 255, 0.2); }
#debug-panel button.primary { background: var(--accent); color: #222; border-color: var(--accent); font-weight: 600; }
#debug-panel input[type="range"] { width: 100%; accent-color: var(--accent); }
#debug-panel .readout { font-family: ui-monospace, Menlo, Consolas, monospace; opacity: 0.85; white-space: pre; }
#debug-panel textarea {
  width: 100%;
  height: 150px;
  margin-top: 6px;
  padding: 6px;
  font: 11px/1.4 ui-monospace, Menlo, Consolas, monospace;
  color: var(--fg);
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  resize: vertical;
}
#debug-panel .status { min-height: 1.5em; color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  #caption { transition: none; }
  #logo { filter: none; transition: opacity 0.4s ease; }
}

/* Text-pixel edition: the room is composed entirely of repeated phrase cells. */
#loading, #progress, #scroll-hint { display: none !important; }
/* Keep the wordmark and scrolling names visible over the text-pixel room. */
#brand-wrap { display: flex !important; color: #fff; z-index: 20; }
#brand { display: block; }
#brand-names { display: block; color: #fff; font-size: 0.48em; min-height: 1.25em; opacity: 1; }
#stage { visibility: hidden; }
#text-pixels { display: block; }

/* ---- Reading mode (a name was clicked) ---------------------------------- */
html.reading, html.reading body { background: #080808; }   /* same near-black as the frame */
/* While reading, only the baked image and the text exist on the page; both scroll natively on their own layers. */
html.reading #text-pixels, html.reading #stage, html.reading #hud { display: none !important; }
#text-snap {
  position: absolute; top: 0; left: 0;
  z-index: 2;
  display: block;
  pointer-events: none;
  will-change: transform;
}
#reader {
  position: absolute;
  top: 0; left: 0; right: 0;
  margin: 0 auto;
  width: min(38rem, calc(100vw - 64px));
  z-index: 4;
  padding-bottom: 2rem;
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  font-weight: 300;
  font-size: 17px;
  line-height: 1.8;
  color: #fff;
  text-align: justify;
  text-align-last: center;
  hyphens: auto;
  -webkit-font-smoothing: antialiased;
  will-change: transform;
}
#reader:empty { display: none; }
#reader p { margin: 0 0 1.6em; }

/* ---- Contact page ---- */
html.contact, html.contact body, html.argot, html.argot body { overflow: hidden; overscroll-behavior: none; }
#contact-sr { display: none; }
html.contact #contact-sr { display: block; position: fixed; left: 0; top: 0; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- "the argot" reading page ------------------------------------------ */
html.argot, html.argot body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
}
html.argot #text-pixels,
html.argot #stage,
html.argot #hud {
  display: none !important;
}
#argot-text {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 8vh 24px;
  background: #000;
  color: #fff;
}
html.argot #argot-text { display: flex; }
#argot-text.ready { visibility: visible; }
#argot-back {
  position: fixed;
  z-index: 2;
  top: max(22px, env(safe-area-inset-top));
  left: max(28px, env(safe-area-inset-left));
  appearance: none;
  border: 0;
  padding: 0 8px 8px 0;
  background: transparent;
  color: #fff;
  font: 300 clamp(52px, 7vw, 88px)/0.9 Arial, Helvetica, sans-serif;
  cursor: pointer;
  -webkit-font-smoothing: antialiased;
}
#argot-back:hover { opacity: 0.65; }
#argot-back:focus-visible { outline: 1px solid #fff; outline-offset: 8px; }
#argot-column {
  width: min(42rem, calc(100vw - 56px));
  max-height: 100%;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 0.5rem 0;
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  font-weight: 300;
  font-size: clamp(15px, 1.2vw, 18px);
  line-height: 1.75;
  color: #fff;
  text-align: justify;
  hyphens: none;
  -webkit-font-smoothing: antialiased;
}
#argot-column::-webkit-scrollbar { display: none; }
#argot-column p { margin: 0 0 1.2em; }
#argot-column p:last-child { margin-bottom: 0; }

/* ---- Mobile layout ------------------------------------------------------ */
@media (max-width: 700px) {
  html, body { width: 100%; min-height: 100%; overflow-x: hidden; }
  #brand-wrap {
    top: max(16px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    left: 14px;
    font-size: clamp(1.55rem, 7vw, 2.4rem);
    gap: 0.45em;
  }
  #brand { max-width: 100%; white-space: normal; }
  #brand-nav {
    max-width: 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.7em 1em;
    font-size: 12px;
    line-height: 1.3;
  }
  #caption {
    bottom: max(76px, calc(env(safe-area-inset-bottom) + 64px));
    width: calc(100vw - 28px);
    max-width: 520px;
    padding: 0.65em 0.9em;
    border-radius: 14px;
    font-size: clamp(0.95rem, 4vw, 1.15rem);
  }
  #scroll-hint {
    bottom: max(18px, env(safe-area-inset-bottom));
    font-size: 0.68rem;
    letter-spacing: 0.12em;
  }
  #progress { width: 2px; }
  #debug-panel { width: min(290px, calc(100vw - 24px)); max-height: 70dvh; overflow: auto; }
}

@media (max-width: 380px) {
  #brand-wrap { font-size: 1.45rem; }
  #brand-nav { font-size: 11px; }
  #caption { bottom: max(72px, calc(env(safe-area-inset-bottom) + 60px)); }
}
