/* ==========================================================================
   Shared by every direction: the font, the colours, the red grid, the curtain,
   the image viewer and the pillar editor. Each direction adds its own sheet.
   ========================================================================== */

/* Endless covers basic Latin only; other characters fall back to the next font. */
@font-face {
  font-family: "Endless";
  src: url("../fonts/Endless-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f3f3f1;
  --ink: #141414;
  --grey: #6e6e6c;
  --soft: #dededb;
  --red: #d8281e;
  --m: 80px; /* the module: js/curtain.js sets it from the window's width */
  --cols: 16;
  --font: "Endless", "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  /* The red grid: one line per module, each way. */
  --grid: linear-gradient(90deg, color-mix(in srgb, var(--red) 55%, transparent) 1px, transparent 1px) 0 0 / var(--m) var(--m),
    linear-gradient(color-mix(in srgb, var(--red) 55%, transparent) 1px, transparent 1px) 0 0 / var(--m) var(--m);
}

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

html {
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html:has(.lightbox[open]) {
  overflow: hidden;
}

/* Until the curtain exists (js/curtain.js), keep the page out of sight behind it. */
html.is-arriving body {
  visibility: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 400;
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

::selection {
  background: var(--red);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

.curtain {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  width: 100%;
  height: 100%;
}

/* The 3D views. Each direction sizes and places the canvas. */
.textmap {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: pan-y;
}

.textmap.is-grabbing {
  cursor: grabbing;
}

.textmap.is-pointer {
  cursor: pointer;
}

.textmap.is-picking {
  cursor: crosshair;
}

img.fade {
  opacity: 0;
  transition: opacity 0.6s var(--ease);
}

img.fade.is-loaded {
  opacity: 1;
}

/* --------------------------------------------------------------- image viewer */

.lightbox {
  width: 100vw;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--paper);
  color: var(--ink);
}

.lightbox::backdrop {
  background: var(--paper);
}

.lightbox__figure {
  position: absolute;
  inset: 56px clamp(16px, 7vw, 96px) 56px;
  display: grid;
  place-items: center;
  margin: 0;
}

.lightbox__img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.35s var(--ease);
  cursor: pointer;
}

.lightbox__img.is-loaded {
  opacity: 1;
}

.lightbox button {
  position: absolute;
  z-index: 2;
  padding: 8px 12px;
  font-size: 13px;
}

.lightbox button:hover {
  color: var(--red);
}

.lightbox__close {
  top: 10px;
  right: 14px;
}

.lightbox__prev,
.lightbox__next {
  top: 50%;
  transform: translateY(-50%);
}

.lightbox__prev {
  left: 6px;
}

.lightbox__next {
  right: 6px;
}

.lightbox__bar {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 16px;
  display: flex;
  gap: 16px;
  font-size: 12px;
}

.lightbox__count {
  color: var(--red);
}

/* ----------------------------------------------------------- pillar editor */

.editor {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  width: min(380px, 100vw);
  overflow: auto;
  padding: 24px 20px;
  border-left: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
}

.editor__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor__title {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.editor__close,
.editor__pick,
.editor__search button,
.editor__actions button {
  padding: 5px 10px 6px;
  border: 1px solid var(--ink);
  font-size: 12px;
  line-height: 1.3;
}

.editor__close:hover,
.editor__pick:hover,
.editor__pick.is-active,
.editor__search button:hover,
.editor__actions button:hover {
  background: var(--ink);
  color: var(--paper);
}

.editor__intro {
  margin: 14px 0 18px;
}

.editor__list,
.editor__results {
  margin: 0;
  padding: 0;
  list-style: none;
}

.editor__item {
  padding: 14px 0;
  border-top: 1px solid var(--ink);
}

.editor__head {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.editor__num {
  color: var(--red);
}

.editor__search {
  display: flex;
  gap: 6px;
}

.editor__search input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px 6px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
}

.editor__results button {
  display: block;
  width: 100%;
  padding: 6px 8px;
  border-top: 1px solid color-mix(in srgb, var(--ink) 25%, transparent);
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
}

.editor__results button:hover {
  background: var(--ink);
  color: var(--paper);
}

.editor__note,
.editor__where {
  margin-top: 6px;
  color: var(--grey);
  font-size: 12px;
}

.editor__where.is-warning {
  color: var(--red);
}

.editor__out {
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--ink);
}

.editor__out p {
  margin-bottom: 10px;
}

.editor__code {
  max-height: 220px;
  margin: 0 0 10px;
  overflow: auto;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--ink) 25%, transparent);
  font: 12px/1.5 "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.editor__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.map-note {
  color: var(--red);
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0s !important;
    transition-duration: 0.001ms !important;
  }
}
