/* Books that feel like this — direction B "Night Window" (design/PATTERNS.md) */

:root {
  --night: #17162e;
  --night-2: #1f1e3a;
  --ink: #ebe7f3;
  --muted: #8f8ba9;
  --amber: #f2b263;
  --amber-ink: #1a1230;
  --line: rgba(235, 231, 243, 0.09);
  --scene-wall: #1c1b35;
  --scene-floor: #2b2140;
  --tile-bg: #22213f;
  --backdrop: rgba(10, 9, 24, 0.78);
  --panel: #1b1a35;
  --gap: 4px;
  --gutter: 16px;
}
:root[data-theme="light"] {
  --night: #efe3ee;
  --night-2: #e6d7ea;
  --ink: #2a2140;
  --muted: #6f6688;
  --amber: #c9742f;
  --amber-ink: #fff4e6;
  --line: rgba(42, 33, 64, 0.12);
  --tile-bg: #e2d4e6;
  --backdrop: rgba(42, 33, 64, 0.55);
  --panel: #f6eef5;
}

* { box-sizing: border-box; }
html { background: var(--night); }
body {
  margin: 0;
  background: var(--night);
  color: var(--ink);
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
:root[data-theme="light"] body {
  background: linear-gradient(180deg, #f6dce6 0%, #efe3ee 420px, #d9cdee 100%) fixed;
}
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ---------- the scene */
.sky {
  height: 168px;
  background: linear-gradient(180deg, var(--scene-wall) 0 78.5%, var(--scene-floor) 78.5% 100%);
  overflow: hidden;
}
.sky { position: relative; }
.scene { height: 100%; }
.scene canvas {                       /* drawn by scene.js, blown up with crisp pixels */
  position: absolute; left: 50%; top: 0;
  transform: translateX(-50%);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
:root[data-theme="light"] .sky {
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.2);
}

/* ---------- the bar (sticks; slides off and back with the scroll — app.js slidingBar)
   .barSlot holds the bar's place in the page; .barTrack is the invisible lane the sticky bar
   rides in, laid over the content below, so it must not catch taps. */
.barSlot { position: relative; z-index: 5; }
.barTrack { position: absolute; top: 0; left: 0; right: 0; pointer-events: none; }
.barTrack > * { pointer-events: auto; }
.head {
  position: sticky;
  top: 0;
  background: var(--night);
  transition: box-shadow .25s;
}
.head.float { box-shadow: 0 1px 0 var(--line); }
/* lightning: the room's flash spills onto the bar, brightest at the top edge (--flash 0–1, scene.js) */
.head::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(rgba(180, 200, 255, calc(var(--flash, 0) * .2)), rgba(180, 200, 255, calc(var(--flash, 0) * .06)));
}
.metaSlot, .metaSlot > .barTrack { display: contents; }   /* desktop: the post viewer's bar doesn't slide */
.sw.labBtn {
  position: absolute; top: 16px; right: var(--gutter); z-index: 6;
  padding: 4px 0;
  color: #8f8ba9;                      /* sits on the scene, which stays dark in both themes */
}
.tools::before {
  /* the lamp's glow leaking onto the page */
  content: "";
  position: absolute; inset: -60px 0 auto 0; height: 140px;
  background: radial-gradient(60% 100% at 82% 0%, rgba(242, 178, 99, 0.14), transparent 70%);
  pointer-events: none;
}
/* Lab "on top: search" — the bar sits above the room: the flash and the lamp glow come from below */
:root[data-layout="search"] .head::after { background: linear-gradient(to top, rgba(180, 200, 255, calc(var(--flash, 0) * .2)), rgba(180, 200, 255, calc(var(--flash, 0) * .06))); }
:root[data-layout="search"] .sky { margin-bottom: 16px; }
:root[data-layout="search"] .tools::before { inset: auto 0 -60px 0; background: radial-gradient(60% 100% at 82% 100%, rgba(242, 178, 99, 0.14), transparent 70%); }.sw, .search input, .search .ph {
  font-family: "Silkscreen", monospace;
  font-size: 11px;
  letter-spacing: 0.02em;
  text-decoration: none;
  position: relative;
}
.sw { color: var(--muted); }

/* ---------- search + pills */
.tools {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px var(--gutter) 16px;
  position: relative;
}
/* The search box keeps the old site-name look (pixel font, amber, a hairline under it) but says
   "type here": a pixel magnifier in front and a blinking block cursor after the words. The words
   are a fake placeholder (.ph) so the cursor can sit right after them; the real placeholder is a
   space, which keeps :placeholder-shown working. Lab "search hint" turns either part off. */
.search { flex: 0 0 260px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); cursor: text; }
.search:focus-within { border-bottom-color: var(--amber); }
.search .mag { flex: none; width: 12px; height: 12px; fill: var(--amber); }
.search .field { position: relative; flex: 1; min-width: 0; display: flex; }
.search input {
  width: 100%;
  color: var(--amber);
  background: none;
  border: 0;
  padding: 6px 0;
  border-radius: 0;
  -webkit-appearance: none;
}
.search input::placeholder { color: transparent; }
.search input:focus { outline: none; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }   /* our own ✕ instead */
.search .clear { flex: none; display: grid; place-items: center; padding: 8px; margin: -8px -8px -8px 0; color: var(--amber); background: none; border: 0; cursor: pointer; }
.search .clear[hidden] { display: none; }
.search .clear svg { width: 9px; height: 9px; fill: currentColor; }
.search .ph {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  color: var(--amber); white-space: nowrap; pointer-events: none;
}
.search .ph::after {
  content: ""; display: inline-block; width: .6em; height: 1.05em; margin-left: 3px;
  vertical-align: -.15em; background: var(--amber); animation: caret 1.06s steps(1) infinite;
}
.search input:not(:placeholder-shown) + .ph { display: none; }
.search input:focus + .ph::after { visibility: hidden; }   /* the real cursor takes over */
@keyframes caret { 50% { opacity: 0; } }
:root[data-hint="cursor"] .search .mag, :root[data-hint="none"] .search .mag { display: none; }
:root[data-hint="icon"] .search .ph::after, :root[data-hint="none"] .search .ph::after { display: none; }
.pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0;
  -webkit-overflow-scrolling: touch;
}
.pills::-webkit-scrollbar { display: none; }
.pill {
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pill:hover { color: var(--ink); }
.pill.on { color: var(--amber-ink); background: var(--amber); border-color: var(--amber); }

/* ---------- the wall */
.wall {
  display: flex;
  gap: var(--gap);
  padding: 0 var(--gutter) 60px;
  align-items: flex-start;
  transition: opacity .16s ease-out;
}
.wall.out { opacity: 0; }
:root[data-edges="full"] .wall { padding-left: 0; padding-right: 0; }   /* Lab "pictures: edge to edge" */
/* new search / tag results come in one after another (delay set per tile in app.js) */
.tile.enter { animation: tileIn .4s ease-out both; }
@keyframes tileIn { from { opacity: 0; } to { opacity: 1; } }
.col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: var(--gap); }
.tile {
  position: relative;
  display: block;
  overflow: hidden;
  background-color: var(--tile-bg);
  background-size: cover;
  background-position: center;
  image-rendering: pixelated;
  text-decoration: none;
  color: #fff;
}
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: auto;
  opacity: 0;
  transition: opacity .25s ease-out;
}
.tile img.in { opacity: 1; transition: none; }
.veil {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
}
:root[data-shape="squares"] .tile { aspect-ratio: 1 / 1 !important; }
:root[data-shape="squares"] .tile img { position: absolute; inset: 0; }
.cap {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 26px 10px 9px;
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  font-size: 12px;
  line-height: 1.3;
  background: linear-gradient(transparent, rgba(10, 9, 24, 0.82));
  opacity: 0;
  transition: opacity .15s;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;   /* the whole title, cut at two lines */
}
.cap b { font-weight: 500; }
.cap span { color: rgba(255,255,255,.7); }
@media (hover: hover) {
  .tile:hover .cap, .tile:focus-visible .cap { opacity: 1; }
}
.sentinel { height: 1px; }
.empty { padding: 40px var(--gutter); color: var(--muted); }
.more { margin: -40px 0 40px; padding: 0 var(--gutter); text-align: center; }
.more[hidden] { display: none; }
.more button { color: var(--muted); border-bottom: 1px solid var(--amber); padding-bottom: 2px; }
.more button:hover { color: var(--ink); }

/* ---------- lightbox */
.lightbox { position: fixed; inset: 0; z-index: 10; }
.lightbox[hidden] { display: none; }
.backdrop { position: absolute; inset: 0; background: var(--backdrop); }
.lightbox, .panel { animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } }
.lightbox.out, .lightbox.out .panel { animation: fadeout .15s ease-in forwards; }
@keyframes fadeout { to { opacity: 0; } }
.panel {
  position: absolute;
  inset: 4vh 4vw;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr);
  background: var(--panel);
  color: var(--ink);
  outline: none;
  box-shadow: 0 30px 80px rgba(0,0,0,.45);
}
.lightbox .panel, .lightbox .pics, .lightbox .side { overscroll-behavior: contain; }   /* reaching the end of the post doesn't carry on into the wall behind */
:root.lbOpen, :root.lbOpen body { overflow: hidden; overscroll-behavior: none; }
.pics { overflow-y: auto; background: #0e0d1e; display: flex; flex-direction: column; gap: 4px; }
:root[data-theme="light"] .pics { background: #e3d7e8; }
.pics img { display: block; width: 100%; height: auto; background: var(--tile-bg); }
.pics img.thumb { filter: none; }
.side { overflow-y: auto; }
/* "there's more this way": a blocky copy of the pictures at the edge they scroll toward (app.js scrollHint) */
.lbHint { position: absolute; z-index: 1; pointer-events: none; image-rendering: pixelated; image-rendering: crisp-edges; transition: opacity .4s; }
.lbHint.gone { opacity: 0; }                     /* the right-hand column: buttons, then the text, scrolling together */
.text { padding: 0 28px 40px; }
.meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 22px 28px 0; margin-bottom: 16px; }
.nav { display: flex; gap: 4px; }
/* ‹ › × all alike: same box, icon drawn dead centre */
.arrow { width: 32px; height: 32px; display: inline-grid; place-items: center; color: var(--muted); border: 1px solid var(--line); }
.arrow svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.arrow:hover { color: var(--ink); }
.title { font-size: 22px; font-weight: 500; line-height: 1.25; margin: 0 0 8px; }
.tag { display: block; font-family: "Silkscreen", monospace; font-size: 10px; color: var(--amber); margin: 0 0 8px; }
.tag:empty { display: none; }
.sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.sub a { color: var(--muted); }
.sub a:hover { color: var(--ink); }
.comments { list-style: none; margin: 0; padding: 0; max-width: 58ch; }
.comments li {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  font-size: 15.5px;
  line-height: 1.5;
  word-wrap: break-word;
}
.comments li:first-child { border-top: 0; }
.marks { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.up, .agree {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 5px 8px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--night-2);
}
.up .tri { width: 10px; height: 10px; fill: var(--muted); flex: none; }
.agree { color: var(--amber-ink); background: var(--amber); border-color: var(--amber); }
.hot .up { border-color: var(--amber); }
.hot .up .tri { fill: var(--amber); }
/* vote pill position (lab) */
.comments[data-pos="corner"] li { padding-right: 84px; }
.comments[data-pos="corner"] .marks { position: absolute; top: 12px; right: 0; margin: 0; }
.comments[data-pos="below"] .marks { order: 2; margin: 8px 0 0; }
/* highlight style (lab) */
.comments[data-hl="left line"] li.hot { border-left: 2px solid var(--amber); padding-left: 12px; }
.comments[data-hl="bottom line"] li.hot { box-shadow: inset 0 -2px 0 var(--amber); padding-bottom: 14px; }
.comments a { color: var(--amber); text-decoration: none; }
.comments a:hover { text-decoration: underline; }
.comments p { margin: 0 0 8px; }
.comments p:last-child { margin: 0; }

/* ---------- the lab */
.labBtn.on { color: var(--amber); }
.lab {
  position: fixed; top: 12px; right: 12px; z-index: 20;
  width: 300px; max-width: calc(100vw - 24px);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  padding: 12px 14px 10px;
}
.lab[hidden] { display: none; }
.labHead { display: flex; justify-content: space-between; align-items: center; font-family: "Silkscreen", monospace; font-size: 11px; color: var(--amber); margin-bottom: 10px; }
.labHead button { font-size: 20px; color: var(--muted); width: 28px; height: 28px; }
.lab .row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 13px; }
.lab .lbl { color: var(--muted); white-space: nowrap; }
.lab .opts { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.lab .opt { color: var(--muted); padding-bottom: 1px; white-space: nowrap; }
.lab .opt.on { color: var(--ink); border-bottom: 2px solid var(--amber); }
.labNote { margin: 10px 0 0; font-size: 12px; color: var(--muted); line-height: 1.4; }

/* ---------- phones */
@media (max-width: 720px) {
  :root { --gutter: 10px; --gap: 3px; }
  .sky { height: 112px; }
  .search input, .search .ph { font-size: 16px; }   /* phones zoom into smaller text boxes */
  .search .mag { width: 15px; height: 15px; }
  .search .clear { padding: 12px; margin: -12px -12px -12px 0; }   /* a thumb-sized target */
  .search .clear svg { width: 12px; height: 12px; }
  .tools { flex-direction: column; align-items: stretch; gap: 10px; }
  .search { flex-basis: auto; }
  /* one column that scrolls as a whole: buttons on top (they scroll away), pictures, then text */
  .panel { inset: 0; display: flex; flex-direction: column; overflow-y: auto; box-shadow: none; }
  .side { display: contents; }
  .metaSlot { display: block; order: 1; flex: none; z-index: 2; }
  .metaSlot > .barTrack { display: block; }
  .meta { padding: 8px var(--gutter); margin: 0; position: sticky; top: 0; background: var(--panel); }   /* slides with the scroll — app.js slidingBar */
  .pics { order: 2; flex: none; height: 52vh; flex-direction: row; overflow-x: auto; overflow-y: hidden; gap: 0; }
  .pics img { width: 100%; height: 100%; object-fit: contain; flex: 0 0 100%; }
  /* several pictures: a strip like the wall, sideways — each full height, side by side from the left */
  .pics.many { gap: var(--gap); padding-left: var(--gutter); background: none; }
  .pics.many img { width: auto; flex: none; object-fit: cover; }
  .pics.many::after { content: ""; flex: 0 0 calc(var(--gutter) - var(--gap)); }
  .text { order: 3; padding: 16px 16px 60px; }
  .arrow { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile img, .cap, .lightbox, .panel, .head, .meta, .veil, .wall, .tile.enter, .search .ph::after { transition: none; animation: none; }
}
