/* The Library of Babel — interface
   Layout: the Library fills the screen; words sit on its darkness, left-aligned like a colophon.
   One look only (lamplight in a dark room), so a single dark palette. */
:root {
  --soot: #0d0a07;          /* the dark between the lamps; also the fog */
  --vellum: #d8c9a6;        /* text on darkness */
  --ash: #8f8169;           /* secondary text */
  --lamp: #e3a95a;          /* the lamps' light, used sparingly */
  --page: #cdbf9d;          /* the paper of the books */
  --ink: #2b2319;           /* their ink */
  --display: "Libre Bodoni", "Bodoni 72", "Bodoni MT", Didot, Georgia, serif;
  --type: "Courier Prime", "Courier New", Courier, monospace;
  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.1875rem;
  --step-2: 1.5rem;
  color-scheme: dark;
}

[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--soot);
  color: var(--vellum);
  font-family: var(--display);
  font-size: var(--step-0);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

#vignette {
  position: fixed; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 46%, transparent 52%, rgba(0, 0, 0, 0.6) 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.5  0 0 0 0 0.45  0 0 0 0 0.4  0 0 0 0.55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  opacity: 0.55;
  mix-blend-mode: soft-light;
}

.screen {
  position: fixed; inset: 0;
  padding-block: max(24px, env(safe-area-inset-top, 0px)) max(24px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  box-sizing: border-box;
}

p { margin: 0; }
h1, h2, h3 { font-weight: 400; margin: 0; text-wrap: balance; }

button {
  font: inherit;
  color: var(--vellum);
  background: transparent;
  border: 1px solid rgba(216, 201, 166, 0.34);
  border-radius: 2px;
  padding: 0.5em 1em;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}
button:hover { background: rgba(216, 201, 166, 0.08); border-color: rgba(216, 201, 166, 0.6); }
button.primary { background: var(--lamp); border-color: var(--lamp); color: var(--ink); }
button.primary:hover { background: #ecb86c; }
:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }

input[type="text"], input[type="number"] {
  font-family: var(--type);
  font-size: var(--step-1);
  color: var(--vellum);
  background: transparent;
  border: 0;
  border-bottom: 1px solid rgba(216, 201, 166, 0.5);
  border-radius: 0;
  padding: 0.25em 0.1em;
  min-width: 0;
}
input[type="text"]:focus, input[type="number"]:focus { outline: none; border-bottom-color: var(--lamp); }

.small { font-size: var(--step--1); color: var(--ash); }

.note { font-size: var(--step--1); color: var(--ash); line-height: 1.5; max-width: 34em; }
.controls { font-size: var(--step--1); color: var(--ash); line-height: 1.6; max-width: 36em; }
.controls kbd { font-family: var(--type); font-size: 0.95em; color: var(--vellum); }

/* ---------- walking ---------- */

#hud { position: fixed; inset: 0; pointer-events: none; }
#crosshair {
  position: absolute; left: 50%; top: 50%;
  width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%;
  background: rgba(216, 201, 166, 0.55);
}
#gaze {
  position: absolute; left: 50%; bottom: 13vh; transform: translateX(-50%);
  width: min(30rem, calc(100% - 32px));
  text-align: center; display: grid; gap: 0.3rem;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.9);
}
#gaze .spine { font-style: italic; font-size: var(--step-2); letter-spacing: 0.04em; }
#gaze .where { font-size: var(--step-0); }
#gaze .hint { font-size: var(--step--1); color: var(--ash); }
#look-hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, 1.4rem);
  font-style: italic; font-size: var(--step--1); color: var(--ash);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9);
}

/* ---------- reading ---------- */

#reader {
  background: rgba(9, 7, 5, 0.88);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  overflow: auto;
}
.book { display: grid; gap: 0.9rem; justify-items: center; max-width: 100%; }
.book-head { text-align: center; display: grid; gap: 0.25rem; }
#book-title { font-style: italic; font-size: var(--step-2); letter-spacing: 0.05em; }
#book-where { font-size: var(--step--1); color: var(--ash); }
.page-wrap { max-width: 100%; overflow-x: auto; }
.page {
  font-family: var(--type);
  font-size: 14px; /* set from the window size when a book is opened */
  line-height: 1.3;
  white-space: pre;
  margin: 0;
  padding: 2.1em 2.6em 2.4em;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 88%, rgba(120, 82, 40, 0.14), transparent 22%),
    radial-gradient(circle at 86% 9%, rgba(120, 82, 40, 0.1), transparent 18%),
    linear-gradient(90deg, rgba(60, 40, 20, 0.16), transparent 7%, transparent 93%, rgba(60, 40, 20, 0.1)),
    var(--page);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 0, 0, 0.3);
  font-variant-ligatures: none;
}
.page:focus-visible { outline-offset: 4px; }
/* control characters: their pictures, scaled into one typewriter column, a little faint */
.page .ctl {
  display: inline-flex; justify-content: center; width: 1ch; line-height: 1;
  transform: scale(var(--ctl-fit, 0.8)); opacity: 0.72;
}
/* a symbol the typeface lacks, drawn by another font: kept to one column */
.page .fit {
  display: inline-flex; justify-content: center; width: 1ch; line-height: 1;
  transform: scale(var(--glyph-fit, 1));
}
.page .folio { display: block; text-align: center; color: rgba(43, 35, 25, 0.7); margin-top: 1.1em; }
.book-nav { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.6rem; }
.book-nav > button:first-child, #next-page { font-size: var(--step-2); line-height: 1; padding: 0.15em 0.65em 0.25em; }
.page-form { display: flex; align-items: baseline; gap: 0.5rem; font-variant-numeric: tabular-nums; }
.page-form label { font-style: italic; color: var(--ash); }
.page-form input { width: 4.5ch; text-align: center; font-size: var(--step-0); }
#page-count { color: var(--ash); }
.book-keys { font-size: var(--step--1); color: var(--ash); }

mark { background: rgba(227, 169, 90, 0.55); color: var(--ink); box-shadow: 0 0 0 1px rgba(227, 169, 90, 0.55); }

/* ---------- the catalogue ---------- */
/* Its screen is a different object from everything else in the Library: cool glass, not lamplight. */

#terminal {
  --glass: #0f1716;
  --glow: #d4e3dc;
  --glow-dim: #8ea29a;
  --signal: #a8d6c4;
  background: rgba(6, 8, 8, 0.78);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.glass {
  width: min(58rem, 100%);
  max-height: 100%;
  overflow: auto;
  box-sizing: border-box;
  padding: 1.4rem clamp(1rem, 3vw, 2rem) 1.8rem;
  border-radius: 14px;
  background: radial-gradient(120% 90% at 30% 0%, #172423 0%, var(--glass) 60%);
  box-shadow: 0 0 0 1px rgba(212, 227, 220, 0.12), 0 0 0 7px #1c1d1c, 0 0 0 8px #2c2e2c, 0 30px 90px rgba(0, 0, 0, 0.7), 0 0 70px rgba(130, 200, 180, 0.08);
  color: var(--glow);
  font-family: var(--type);
  font-size: 0.95rem;
  line-height: 1.5;
}
.glass :focus-visible { outline-color: var(--signal); }
.glass h2 { font-family: var(--display); font-style: italic; font-size: clamp(1.6rem, 3.4vw, 2.2rem); }
.glass h3 { font-family: var(--display); font-style: italic; font-size: var(--step-1); color: var(--glow); }
.glass-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem 1.6rem; margin-bottom: 1.2rem; }
.glass-head h2 { margin-right: auto; }
.glass button { font-family: var(--type); font-size: 0.9rem; color: var(--glow); border-color: rgba(212, 227, 220, 0.3); border-radius: 6px; }
.glass button:hover { background: rgba(212, 227, 220, 0.08); border-color: rgba(212, 227, 220, 0.6); }
.glass button.primary { background: var(--glow); border-color: var(--glow); color: var(--glass); }
.glass button.primary:hover { background: #e6f1ec; }
.glass button:disabled { opacity: 0.4; cursor: default; }
.glass button.quiet { border-color: transparent; color: var(--glow-dim); }
.tabs { display: flex; flex-wrap: wrap; gap: 0 0.3rem; order: 3; width: 100%; border-bottom: 1px solid rgba(212, 227, 220, 0.14); }
.tabs button { border: 0; border-radius: 0; padding: 0.5em 0.9em; color: var(--glow-dim); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--glow); border-bottom-color: var(--signal); background: transparent; }
.panel { display: grid; gap: 1.4rem; }
.glass label { color: var(--glow-dim); }
.glass textarea, .glass input[type="text"], .glass input[type="search"], .glass select {
  font-family: var(--type); font-size: 1rem; color: var(--glow);
  background: rgba(0, 0, 0, 0.28); border: 1px solid rgba(212, 227, 220, 0.22); border-radius: 6px;
  padding: 0.55em 0.7em; box-sizing: border-box;
}
.glass textarea { width: 100%; resize: vertical; min-height: 4.5em; text-transform: none; }
.glass textarea:focus, .glass input[type="text"]:focus, .glass input[type="search"]:focus, .glass select:focus { outline: none; border-color: var(--signal); }
.find { display: grid; gap: 0.5rem; }
.find-foot { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 0.6rem 1.2rem; }
.find-foot .note { flex: 1 1 22rem; min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.note, .glass .status { color: var(--glow-dim); font-size: 0.85rem; }
.query { color: var(--glow-dim); font-size: 0.85rem; overflow-wrap: anywhere; }
.query span { color: var(--glow); background: rgba(168, 214, 196, 0.12); padding: 0 0.25em; white-space: pre-wrap; }
.results { display: grid; gap: 1.2rem; }
.result { display: grid; gap: 0.6rem; align-content: start; padding-top: 0.9rem; border-top: 1px solid rgba(212, 227, 220, 0.14); }
.result .where { line-height: 1.55; overflow-wrap: anywhere; }
.result .where strong { font-weight: 400; color: var(--signal); }
.glass sup { font-size: 0.7em; line-height: 0; }
.fill { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; color: var(--glow-dim); font-size: 0.85rem; }
.fill legend { padding: 0; margin-bottom: 0.2rem; width: 100%; }
.fill input { accent-color: var(--signal); }
.glass .addr { color: var(--glow); }
.glass .error { color: #e8b48a; font-size: 0.85rem; }
.go { display: grid; gap: 0.6rem; padding-top: 0.9rem; border-top: 1px solid rgba(212, 227, 220, 0.14); }
.intro { display: grid; gap: 0.7rem; }
.intro .status { max-width: 46em; }

/* the first tab: where the reader is */
#panel-here:focus { outline: none; }
.here-now { display: grid; gap: 0.6rem; }
.here-now .lead { font-size: 1.02rem; line-height: 1.6; max-width: 46em; overflow-wrap: anywhere; }
.here-now .note { max-width: 46em; }
.seam { display: flex; flex-wrap: wrap; gap: 1rem 1.6rem; align-items: flex-start; }
.seam .note { flex: 1 1 22rem; max-width: 46em; }
.seam-map {
  position: relative; flex: none; box-sizing: border-box; margin: 0.3rem 0.4rem;
  border: 1px dashed rgba(212, 227, 220, 0.5); background: rgba(212, 227, 220, 0.04);
}
.seam-here, .seam-was { position: absolute; width: 9px; height: 9px; border-radius: 50%; box-sizing: border-box; transform: translate(-50%, 50%); }
.seam-here { background: var(--signal); box-shadow: 0 0 10px var(--signal); }
.seam-was { border: 1px solid var(--glow-dim); }
.glass .controls { color: var(--glow-dim); max-width: 46em; }

/* the About tab: the Markdown of about.js */
#panel-about:focus { outline: none; }
.about { min-width: 0; line-height: 1.6; overflow-wrap: break-word; } /* min-width: a wide table scrolls, not the tab */
.about > p, .about > ul, .about > ol, .about > blockquote, .about > pre, .about > h1, .about > h2, .about > h3, .about > h4 { max-width: 46em; }
.about > * + * { margin-top: 0.9em; }
.about h1, .about h2, .about h3, .about h4, .about h5, .about h6 {
  font-family: var(--display); font-style: italic; font-weight: 400; color: var(--glow); line-height: 1.25;
}
.about > h1, .about > h2, .about > h3, .about > h4 { margin-top: 1.6em; }
.about > :first-child { margin-top: 0; }
.about [data-anchor] { scroll-margin-top: 1.4rem; }
.about h1 { font-size: clamp(1.6rem, 3.4vw, 2.2rem); }
.about h2 { font-size: 1.45rem; }
.about h3 { font-size: 1.2rem; }
.about h4, .about h5, .about h6 { font-size: 1.05rem; }
.about p, .about li { color: var(--glow-dim); }
.about strong { color: var(--glow); }
.about a { color: var(--signal); text-underline-offset: 0.2em; }
.about ul, .about ol { margin-bottom: 0; padding-left: 1.5em; }
.about li + li, .about li > ul, .about li > ol { margin-top: 0.35em; }
.about blockquote { margin-left: 0; margin-right: 0; padding-left: 1em; border-left: 2px solid rgba(212, 227, 220, 0.3); }
.about hr { border: 0; border-top: 1px solid rgba(212, 227, 220, 0.14); }
.about pre { margin-bottom: 0; padding: 0.7em 0.9em; overflow-x: auto; background: rgba(0, 0, 0, 0.28); border: 1px solid rgba(212, 227, 220, 0.14); border-radius: 6px; }
.about pre code { background: none; padding: 0; white-space: pre; }
.about table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 0.85rem; }
.about th, .about td { padding: 0.45em 0.7em; text-align: left; vertical-align: top; border: 1px solid rgba(212, 227, 220, 0.16); color: var(--glow-dim); }
.about th { color: var(--glow); font-weight: 400; background: rgba(212, 227, 220, 0.05); }
/* on a phone, a table scrolls sideways rather than squeeze its columns */
@media (max-width: 640px) { .about th, .about td { min-width: 14em; } }
.glass .controls kbd { color: var(--glow); }
.glass code { font-family: var(--type); color: var(--glow); background: rgba(212, 227, 220, 0.08); padding: 0 0.25em; border-radius: 3px; }
.books { list-style: none; margin: 0; padding: 0; display: grid; }
.books:empty { display: none; }
.books li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.4rem 1rem; padding: 0.75rem 0; border-top: 1px solid rgba(212, 227, 220, 0.14); }
.books li > div { display: grid; gap: 0.1rem; min-width: 0; flex: 1 1 18rem; }
.books cite { font-family: var(--display); font-size: var(--step-1); color: var(--glow); overflow-wrap: anywhere; }
.books .by { color: var(--glow); }
.books li[aria-current="true"] cite { color: var(--signal); }
/* the collection: searched, ordered, and scrolled within its own box */
.shelf-tools input[type="search"] { flex: 1 1 16rem; min-width: 0; }
.shelf-tools label { display: flex; align-items: center; gap: 0.5rem; }
.glass select { font-size: 0.9rem; padding: 0.45em 0.6em; }
.books.shelf li { padding: 0.55rem 0; }
.books.shelf cite { font-size: var(--step-0); }
.books.shelf { max-height: min(26rem, 52vh); overflow: auto; overscroll-behavior: contain; padding-right: 0.6rem; border-bottom: 1px solid rgba(212, 227, 220, 0.14); }
.result h3 cite { font-style: normal; }
.parts { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
.parts li { display: grid; gap: 0.5rem; }
.offset label { display: flex; align-items: center; gap: 0.5rem; }
.offset input { width: 15ch; }
#go-address { display: grid; gap: 0.5rem; }

/* ---------- addresses ---------- */

.addr { font-family: var(--type); color: var(--vellum); letter-spacing: 0.04em; word-break: break-all; }

/* ---------- messages ---------- */

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(28px, env(safe-area-inset-bottom, 0px));
  background: rgba(13, 10, 7, 0.9); border: 1px solid rgba(216, 201, 166, 0.25);
  padding: 0.55em 1.1em; font-size: var(--step--1);
}
/* ---------- sleep ---------- */

#sleep {
  position: fixed; inset: 0; cursor: none;
  display: grid; place-items: center; padding: 2rem;
  -webkit-user-select: none; user-select: none;
}
#dream-quote {
  max-width: 28ch; margin: 0; text-align: center; text-wrap: balance;
  font-style: italic; font-size: clamp(1.5rem, 3.4vw, 2.6rem); line-height: 1.32; letter-spacing: 0.01em;
  color: #efe4cb;
  text-shadow: 0 0 1.2em rgba(0, 0, 0, 0.85), 0 0 0.25em rgba(0, 0, 0, 0.6);
  opacity: 0;
}
#sleep-hint {
  position: absolute; left: 0; right: 0; margin: 0; text-align: center;
  bottom: max(28px, env(safe-area-inset-bottom, 0px));
  font-size: var(--step--1); font-style: italic; color: var(--vellum);
  text-shadow: 0 0 0.8em rgba(0, 0, 0, 0.9);
  opacity: 0;
}
#sleep-black { position: fixed; inset: 0; background: #000; pointer-events: none; opacity: 0; }

#error { display: flex; align-items: center; background: var(--soot); }
.error-block { max-width: 36rem; display: grid; gap: 1rem; margin-left: clamp(0px, 6vw, 7rem); }
.error-block h2 { font-size: var(--step-2); }
#error-message { font-family: var(--type); line-height: 1.5; color: var(--lamp); }

@media (max-width: 640px) {
  .error-block { margin-left: 0; }
  .tabs button { padding: 0.45em 0.55em; }
}

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