/*
  Journey. Almost everything visible is drawn in WebGL; this sheet is the
  room it sits in (the bookshelf's dark, warm background) and the few quiet
  pieces of type around it.
*/

:root {
  --background: #1a1310;
  --background-deep: #100b09;
  --foreground: #f3ede1;
  --muted: #a89a87;
  --line: rgba(243, 237, 225, 0.22);

  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-mono: "DM Mono", ui-monospace, monospace;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --duration-fast: 180ms;
  --duration-medium: 350ms;
  --duration-slow: 900ms;
}

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

html {
  background: var(--background-deep);
  scroll-snap-type: y mandatory;
  overscroll-behavior-y: none;
  /* still scrolls, just without the system bar down the edge */
  scrollbar-width: none;
}

html::-webkit-scrollbar {
  display: none;
}

/* while a scripted turn is in progress, snapping would fight it */
html.no-snap {
  scroll-snap-type: none;
}

/* closed, a sideways drag turns the Journal in the hands rather than
   panning the page; up and down still scroll it open */
html.can-turn,
html.can-turn body {
  touch-action: pan-y;
}

html.is-turning,
html.is-turning * {
  cursor: grabbing !important;
  user-select: none;
  -webkit-user-select: none;
}

body {
  margin: 0;
  color: var(--foreground);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
}

/* the room: a pool of warm lamplight falling off into the dark. A fixed
   element of its own, which the compositor simply holds still while the
   page scrolls; as a fixed background on the body it was painted afresh
   on every frame of every scroll. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 70% 60% at 50% 46%, #2a1f19 0%, rgba(26, 19, 16, 0) 70%),
    var(--background);
}

.stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100lvh;
  display: block;
  pointer-events: none;
}

/* nothing until the first frame is drawn, then the Journal fades up out
   of the dark (the script sets opacity inline for reduced-motion fades;
   the animation wins over it while it runs) */
body:not(.is-ready) .stage {
  visibility: hidden;
}

body.is-ready .stage {
  animation: arrive 1.4s var(--ease-out);
}

.scroll {
  position: relative;
  width: 100%;
}

.stop {
  position: absolute;
  left: 0;
  width: 1px;
  height: 1px;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

/* ------------------------------------------------------------ chrome */

.edition {
  position: fixed;
  top: clamp(1.25rem, 3vw, 2rem);
  left: clamp(1.25rem, 3vw, 2.25rem);
  z-index: 2;
  color: var(--muted);
  font-size: 0.6875rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  text-decoration: none;
  padding: 0.5rem 0;
  transition: color var(--duration-fast) var(--ease-out);
}

.edition::before {
  content: "← ";
}

.edition:hover {
  color: var(--foreground);
}

/* the edition link and the close mark share the corner; the script fades
   one out as the other comes in, and only the one showing takes clicks */
.is-away {
  pointer-events: none;
}

.shut {
  position: fixed;
  top: clamp(0.75rem, 3vw - 0.5rem, 1.5rem);
  left: clamp(0.75rem, 3vw - 0.5rem, 1.75rem);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-height: 2.75rem;
  margin: 0;
  padding: 0 0.5rem;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.6875rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0;
  transition: color var(--duration-fast) var(--ease-out);
}

/* a hairline ring with a fine cross, drawn rather than typed */
.shut__mark {
  position: relative;
  flex: none;
  width: 1.875rem;
  height: 1.875rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  transition: border-color var(--duration-fast) var(--ease-out);
}

.shut__mark::before,
.shut__mark::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.625rem;
  height: 1px;
  background: currentColor;
  transform: translate(-50%, -50%) rotate(45deg);
}

.shut__mark::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* the word comes forward only when asked for */
.shut__label {
  opacity: 0;
  transform: translateX(-0.35rem);
  transition:
    opacity var(--duration-medium) var(--ease-out),
    transform var(--duration-medium) var(--ease-out);
}

.shut:hover,
.shut:focus-visible {
  color: var(--foreground);
}

.shut:hover .shut__mark {
  border-color: var(--muted);
}

.shut:hover .shut__label,
.shut:focus-visible .shut__label {
  opacity: 1;
  transform: none;
}

@media not all and (hover: hover) {
  .shut__label {
    display: none;
  }
}

.shut:focus-visible {
  outline: none;
}

.shut:focus-visible .shut__mark {
  border-color: var(--foreground);
}

.hint {
  position: fixed;
  left: 50%;
  bottom: max(1.75rem, env(safe-area-inset-bottom));
  z-index: 1;
  margin: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  color: var(--muted);
  font-size: 0.6875rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  pointer-events: none;
}

body:not(.is-ready) .hint {
  visibility: hidden;
}

body.is-ready .hint {
  animation: arrive 1.2s 0.6s var(--ease-out) backwards;
}

@keyframes arrive {
  from {
    opacity: 0;
  }
}

/* a thin ruled line that draws itself downward, then fades, then again */
.hint__rule {
  display: block;
  width: 1px;
  height: 2.75rem;
  background: var(--line);
  transform-origin: top;
  animation: draw-down 2.8s var(--ease-in-out) infinite;
}

@keyframes draw-down {
  0% {
    transform: scaleY(0);
    opacity: 1;
  }
  55% {
    transform: scaleY(1);
    opacity: 1;
  }
  100% {
    transform: scaleY(1);
    opacity: 0;
  }
}

/* a short screen has no room to spare beneath the Journal */
@media (max-height: 700px) {
  .hint {
    bottom: max(1.1rem, env(safe-area-inset-bottom));
    gap: 0.6rem;
  }

  .hint__rule {
    height: 1.75rem;
  }
}

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

/* what a hidden Contents link would say, shown while it has focus */
.focus-caption {
  position: fixed;
  left: 50%;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  z-index: 3;
  margin: 0;
  padding: 0.7rem 1.1rem;
  transform: translate(-50%, 0.5rem);
  background: rgba(16, 11, 9, 0.96);
  border: 1px solid var(--line);
  color: var(--foreground);
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-style: italic;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.focus-caption.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  outline: 1px solid var(--muted);
  outline-offset: 3px;
}

.focus-caption::after {
  content: "  ·  Enter";
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 0.6875rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

a:focus-visible,
button:focus-visible {
  outline: 1px solid var(--foreground);
  outline-offset: 4px;
}

.visually-hidden {
  position: fixed;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------ fallback */

.fallback {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-content: center;
  gap: 0.25rem;
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  line-height: 1.8;
  background: var(--background);
}

.fallback[hidden] {
  display: none;
}

.fallback__title {
  margin-bottom: 1rem;
  color: var(--foreground);
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-style: italic;
  letter-spacing: 0;
}

.fallback a {
  color: var(--foreground);
}

.no-webgl .hint,
.no-webgl .shut,
.no-webgl .scroll {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
