/*
 * The archive's terminal, set in the Timeless Halls: outside time, before
 * the world, where the Music was first sung.
 *
 * The glass is the Void. Everything printed on it is the Music, pale as
 * the choir (--fg). The Flame Imperishable is the maker's voice: the prompt,
 * the commands offered, and the cursor, which flickers but never goes out.
 * Violet harmony marks paths, the sea-green of Ulmo's waters marks programs,
 * and the rose of discord marks errors. Nothing else is coloured.
 */

@font-face {
  font-family: 'Plex Mono';
  src: url('../fonts/IBMPlexMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('../fonts/IBMPlexMono-Italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('../fonts/IBMPlexMono-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
/* Runes, for `runes`. Only used for the Runic block. */
@font-face {
  font-family: 'Runes';
  src: url('../fonts/NotoSansRunic-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+16A0-16FF;
}

/* ---- themes ------------------------------------------------------------ */

:root,
[data-theme='halls'] {
  color-scheme: dark;
  --night: #0b0916;     /* the Void */
  --night-hi: #211a3c;  /* the light of the Halls, at the heart of the glass */
  --bezel: #030207;
  --fg: #d9d3ee;        /* the Music */
  --fg-bright: #fbf9ff;
  --dim: #8f88ad;
  --voice: #ffc766;     /* the Flame Imperishable */
  --path: #ab9cff;      /* harmony */
  --leaf: #72d6c4;      /* the waters, where the Music echoes still */
  --ember: #ff6b86;     /* discord */
  --sel: rgba(171, 156, 255, 0.3);
  --glow: 1;
  --scan: 0.16;
  /* Inks of the Flame drawings, from the heart outwards. They follow each
     theme's own inks; a theme may also set them itself (see vision). */
  --art-core: var(--fg-bright);
  --art-flame: var(--voice);
  --art-glow: var(--fg);
  --art-halo: var(--path);
  --art-aura: color-mix(in srgb, var(--path) 60%, var(--night));
}

/* Aulë the smith: amber phosphor, the colour of the forge. */
[data-theme='aule'] {
  --night: #0d0904;
  --night-hi: #1f1708;
  --bezel: #050301;
  --fg: #f0c674;
  --fg-bright: #ffe6ad;
  --dim: #b08b4a;
  --voice: #ffd98a;
  --path: #f7b54a;
  --leaf: #e0cc72;
  --ember: #ff8f52;
  --sel: rgba(240, 198, 116, 0.26);
}

/* Varda, who kindled the stars: silver, cold and clear. */
[data-theme='varda'] {
  --night: #07090f;
  --night-hi: #141a26;
  --bezel: #020304;
  --fg: #d3dcec;
  --fg-bright: #ffffff;
  --dim: #8b98ae;
  --voice: #f5f8ff;
  --path: #b3c8ec;
  --leaf: #bcd5d0;
  --ember: #eca6a6;
  --sel: rgba(211, 220, 236, 0.24);
}

/* Ulmo of the waters: the old green glow. */
[data-theme='ulmo'] {
  --night: #030a05;
  --night-hi: #0a1d0f;
  --bezel: #010402;
  --fg: #4dff7a;
  --fg-bright: #c2ffd1;
  --dim: #34a957;
  --voice: #c9f25e;
  --path: #74ffb6;
  --leaf: #93ff62;
  --ember: #ffb347;
  --sel: rgba(77, 255, 122, 0.22);
}

/* Melkor's discord: embers on black. */
[data-theme='melkor'] {
  --night: #0b0403;
  --night-hi: #200a06;
  --bezel: #040101;
  --fg: #ff9e72;
  --fg-bright: #ffd7c2;
  --dim: #c06a4a;
  --voice: #ffd15e;
  --path: #ff7448;
  --leaf: #ffb873;
  --ember: #ff4a3d;
  --sel: rgba(255, 158, 114, 0.24);
}

/* The Vision: the World made visible, in daylight. */
[data-theme='vision'] {
  color-scheme: light;
  --night: #ece8f4;
  --night-hi: #f7f5fb;
  --bezel: #a59cbc;
  --fg: #241c3a;
  --fg-bright: #100a20;
  --dim: #5f577a;
  --voice: #8f4300;
  --path: #4a37a6;
  --leaf: #13695b;
  --ember: #a6163f;
  /* On paper the Flame is drawn the other way round: the most ink at its
     heart, fading to nothing where it meets the page. */
  --art-core: #8f4300;
  --art-flame: #c4761c;
  --art-glow: #d2a764;
  --art-halo: #9d8fdc;
  --art-aura: #cfc7ee;
  --sel: rgba(74, 55, 166, 0.18);
  --glow: 0;
  --scan: 0;
}

/* ---- the screen -------------------------------------------------------- */

:root {
  --mono: 'Plex Mono', 'IBM Plex Mono', 'Runes', ui-monospace, 'Cascadia Mono', 'DejaVu Sans Mono', Menlo, Consolas, monospace;
  --size: clamp(13px, 0.36vw + 10.6px, 16px);
  --lh: 1.5;
  --edge: clamp(16px, 3.2vw, 48px);
  --bezel-gap: clamp(0px, calc((100vw - 720px) * 0.03), 20px);
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bezel);
}

body {
  overflow: hidden;
  color: var(--fg);
  font: 400 var(--size) / var(--lh) var(--mono);
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* The crawler path. Present in the markup, absent from the layout. */
p[antidote] {
  margin: 0;
}

::selection {
  background: var(--sel);
  color: var(--fg-bright);
}

.crt {
  position: fixed;
  inset: 0;
  height: var(--app-height, 100dvh);
  padding: var(--bezel-gap);
}

/* Old glass: brighter at the centre, darker at the rim. */
.glass {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  border-radius: calc(var(--bezel-gap) * 0.9);
  background: radial-gradient(130% 95% at 50% 36%, var(--night-hi) 0%, var(--night) 64%);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--fg) 8%, transparent),
    0 24px 70px rgb(0 0 0 / 0.55);
}

/* Scanlines and vignette sit above everything and never catch the pointer. */
.glass::before,
.glass::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.glass::before {
  background: repeating-linear-gradient(to bottom, rgb(0 0 0 / var(--scan)) 0 1px, transparent 1px 3px);
}
.glass::after {
  background: radial-gradient(150% 115% at 50% 42%, transparent 58%, rgb(0 0 0 / 0.42) 100%);
  border-radius: inherit;
}
[data-theme='vision'] .glass::after {
  background: radial-gradient(150% 115% at 50% 42%, transparent 62%, rgb(60 40 110 / 0.16) 100%);
}
[data-crt='off'] .glass::before,
[data-crt='off'] .glass::after {
  display: none;
}

.scroller {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: clamp(14px, 2.4vw, 32px) var(--edge) 1.5em;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--fg) 22%, transparent) transparent;
  /* Phosphor: every glyph glows a little in its own colour. */
  text-shadow: 0 0 calc(var(--glow) * 5px) color-mix(in srgb, currentColor 42%, transparent);
}
[data-crt='off'] .scroller {
  text-shadow: none;
}

.output,
.prompt {
  max-width: 120ch;
}

.line,
.prompt {
  min-height: calc(var(--lh) * 1em);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Box drawing only joins up when lines sit close together. */
.line.tight {
  min-height: 1.22em;
  line-height: 1.22;
}

.probe {
  position: absolute;
  visibility: hidden;
  white-space: pre;
}

/* ---- inks ---------------------------------------------------------------- */

.dim { color: var(--dim); }
.voice { color: var(--voice); }
.bright { color: var(--fg-bright); }
.ember { color: var(--ember); }
.leaf { color: var(--leaf); }
.em { font-style: italic; }
.strong { font-weight: 600; }

.k-dir { color: var(--path); }
.k-exec,
.k-code { color: var(--leaf); }
.k-archive { color: var(--ember); }
.k-link { color: var(--voice); }

.match {
  color: var(--night);
  background: var(--voice);
  text-shadow: none;
}

.ps1-user { color: var(--voice); }
.ps1-path { color: var(--path); }

/* ---- things to click --------------------------------------------------- */

button {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

/* Commands on offer speak with the maker's voice; names in listings keep
   the colour of their kind. */
.act {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: inherit;
  text-shadow: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  text-underline-offset: 0.24em;
}

.act:not([class*='k-']) {
  color: var(--voice);
}
.act[class*='k-'] {
  text-decoration-style: dotted;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}

.act:hover,
a:hover {
  color: var(--fg-bright);
  text-decoration-style: solid;
  text-decoration-color: currentColor;
}

a {
  color: var(--path);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
  text-underline-offset: 0.24em;
}
a.voice { color: var(--voice); }

:focus-visible {
  outline: 1px dashed var(--voice);
  outline-offset: 2px;
}

/* ---- the prompt -------------------------------------------------------- */

.prompt {
  position: relative;
}
.prompt[hidden] {
  display: none;
}

/* The real input: invisible, but focusable, so phones offer a keyboard. */
.sink {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px; /* below 16px, iOS zooms in on focus */
  color: transparent;
  background: transparent;
  caret-color: transparent;
  pointer-events: none;
}

/* The cursor is the Flame Imperishable: it flickers, but never goes out. */
.cur {
  color: var(--night);
  background: var(--voice);
  text-shadow: none;
  box-shadow: 0 0 calc(var(--glow) * 9px) color-mix(in srgb, var(--voice) 60%, transparent);
  animation: flicker 2.3s ease-in-out infinite;
}
.cur[hidden] {
  display: none;
}
.prompt.typing .cur {
  animation: none;
}
/* Unfocused, the cursor is hollow: tap or type to wake it. */
.prompt:not(.focused) .cur {
  color: inherit;
  background: transparent;
  box-shadow: none;
  outline: 1px solid color-mix(in srgb, var(--voice) 70%, transparent);
  outline-offset: -1px;
  animation: none;
}
.prompt:not(.focused) .cur.over-ghost {
  color: var(--dim);
}
.ghost {
  color: var(--dim);
}
.sel {
  background: var(--sel);
}

@keyframes flicker {
  0%,
  100% {
    opacity: 1;
  }
  18% {
    opacity: 0.72;
  }
  31% {
    opacity: 0.94;
  }
  47% {
    opacity: 0.6;
    box-shadow: 0 0 calc(var(--glow) * 4px) color-mix(in srgb, var(--voice) 40%, transparent);
  }
  63% {
    opacity: 0.9;
  }
  80% {
    opacity: 0.76;
  }
}

.prompt.bell {
  animation: bell 180ms ease-out;
}
@keyframes bell {
  40% {
    background: color-mix(in srgb, var(--ember) 16%, transparent);
  }
}

/* ---- the Flame ------------------------------------------------------- */

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25em 6ch;
  margin: 0.25em 0;
}

.art {
  margin: 0;
  font: inherit;
  /* Never wider than the screen: a glyph of Plex Mono is 0.6em wide. */
  font-size: min(1em, calc((100vw - 2 * var(--edge) - 2 * var(--bezel-gap)) / (var(--cols, 40) * 0.6)));
  line-height: 1.22; /* tight enough for box lines to join */
  white-space: pre;
}

.aside {
  flex: 1 1 36ch;
  max-width: 64ch;
}

/* The Flame, from its white-hot core out to the faint edge where its light
   meets the Void. */
.art-core {
  color: var(--art-core);
  text-shadow:
    0 0 calc(var(--glow) * 12px) var(--voice),
    0 0 calc(var(--glow) * 3px) var(--fg-bright);
}
.art-flame {
  color: var(--art-flame);
  text-shadow: 0 0 calc(var(--glow) * 9px) color-mix(in srgb, var(--voice) 70%, transparent);
}
.art-glow {
  color: var(--art-glow);
  text-shadow: 0 0 calc(var(--glow) * 6px) color-mix(in srgb, var(--fg) 40%, transparent);
}
.art-halo {
  color: var(--art-halo);
  text-shadow: 0 0 calc(var(--glow) * 6px) color-mix(in srgb, var(--path) 50%, transparent);
}
.art-aura { color: var(--art-aura); }

/* On arrival the Flame is kindled, and its light runs out through the Halls
   towards you, once. */
.banner.reveal .art span {
  animation: kindle 1.6s var(--d, 0ms) both cubic-bezier(0.2, 0.7, 0.2, 1);
}
.banner.reveal .aside {
  animation: appear 1s 1.4s both ease-out;
}
@keyframes kindle {
  0% {
    opacity: 0;
  }
  28% {
    opacity: 1;
    color: var(--fg-bright);
    text-shadow:
      0 0 16px var(--voice),
      0 0 4px var(--fg-bright);
  }
  100% {
    opacity: 1;
  }
}
@keyframes appear {
  from {
    opacity: 0;
  }
}

.runes {
  letter-spacing: 0.08em;
}

/* ---- swatches for `theme` ------------------------------------------- */

.sw { background: var(--night); }
.sw-fg { color: var(--fg); }
.sw-voice { color: var(--voice); }
.sw-path { color: var(--path); }
.sw-leaf { color: var(--leaf); }
.sw-ember { color: var(--ember); }

/* ---- the moon --------------------------------------------------------- */

.moon-lit { color: var(--fg-bright); }
.moon-limb { color: var(--fg); }
.moon-dark {
  color: var(--dim);
  opacity: 0.4;
}

/* ---- pictures ------------------------------------------------------- */

.figure {
  margin: 0.5em 0 1em;
}
.shot {
  display: flex;
  flex-direction: column;
  gap: 0.35em;
  color: var(--dim);
  text-decoration: none;
}
.figure img {
  display: block;
  border: 1px solid color-mix(in srgb, var(--fg) 16%, transparent);
  background: color-mix(in srgb, var(--fg) 5%, transparent);
}
.shot:hover img,
.shot:focus-visible img {
  border-color: var(--voice);
}
.figure.single .shot {
  display: inline-flex;
  max-width: min(100%, 96ch);
}
.figure.single img {
  max-width: 100%;
  max-height: 62vh;
}
.figure.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(150px, 40vw), 1fr));
  gap: 1.1em 2ch;
  max-width: 120ch;
}
.figure.gallery img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}
.caption {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.figure.broken .shot::after {
  content: 'the picture could not be loaded';
  color: var(--ember);
}

/* ---- programs ------------------------------------------------------- */

.program {
  margin: 0.25em 0 0.75em;
}
.program-view {
  width: max-content;
  max-width: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
/* Games size their grids to the terminal, so only text lines ever reach the
   edge; those wrap rather than being cut off on narrow screens. */
.program-view .line {
  min-height: 1.22em;
  line-height: 1.22;
  white-space: pre-wrap;
  overflow-wrap: normal;
}
.program.closed {
  opacity: 0.6;
}
.song { color: var(--path); }
.song-head {
  color: var(--fg-bright);
  font-weight: 600;
}
.song-head.discord { color: var(--ember); }
.note {
  color: var(--voice);
  text-shadow: 0 0 calc(var(--glow) * 8px) var(--voice);
}

/* Inks for the games in ~/scripts; they name colours, the theme decides them
   (see programs/game.js). */
.ink-gold { color: var(--voice); }
.ink-violet { color: var(--path); }
.ink-pale { color: var(--fg); }
.ink-bright { color: var(--fg-bright); }
.ink-dim { color: var(--dim); }
.ink-rose { color: var(--ember); }
.ink-sea { color: var(--leaf); }

.pad {
  display: none;
}
@media (pointer: coarse) {
  .pad {
    display: grid;
    grid-template-columns: repeat(3, 3.4em);
    grid-template-areas:
      '. up pause'
      'left down right';
    gap: 0.5em;
    margin-top: 0.75em;
  }
}
.pad-key {
  min-height: 2.9em;
  border: 1px solid color-mix(in srgb, var(--fg) 30%, transparent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--fg) 6%, transparent);
  color: var(--fg);
  touch-action: manipulation;
}
.pad-ArrowUp { grid-area: up; }
.pad-ArrowDown { grid-area: down; }
.pad-ArrowLeft { grid-area: left; }
.pad-ArrowRight { grid-area: right; }
.pad-p { grid-area: pause; }
/* Any other keys a game asks for fill the free places, then further rows. */
.pad-key {
  min-width: 3.4em;
}

/* ---- the bar --------------------------------------------------------- */

.bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.5em 2.5ch;
  padding: 0.4em var(--edge) calc(0.4em + env(safe-area-inset-bottom));
  border-top: 1px solid color-mix(in srgb, var(--fg) 12%, transparent);
  background: color-mix(in srgb, var(--night) 80%, black);
  color: var(--dim);
  white-space: nowrap;
}
.quick {
  display: flex;
  flex: 1 1 auto;
  gap: 0 2.2ch;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  /* When the shortcuts do not fit, fade them out at the edge to show they scroll. */
  mask-image: linear-gradient(to right, #000 calc(100% - 2.5em), transparent);
  padding-right: 2em;
}
.quick::-webkit-scrollbar {
  display: none;
}
.quick-cmd,
.where,
.moon {
  padding: 0.25em 0;
  border: 0;
  background: none;
  color: var(--dim);
  cursor: pointer;
}
.quick-cmd:hover,
.where:hover,
.moon:hover {
  color: var(--voice);
}
.status {
  display: flex;
  gap: 2ch;
  margin-left: auto;
}
.where {
  max-width: 40ch;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--path);
}
.moon {
  color: var(--fg);
}
.keys {
  display: none;
  gap: 0.6ch;
}
.key {
  min-width: 2.6em;
  min-height: 2.3em;
  border: 1px solid color-mix(in srgb, var(--fg) 28%, transparent);
  border-radius: 5px;
  background: transparent;
  color: var(--fg);
  touch-action: manipulation;
}
@media (pointer: coarse) {
  .keys { display: flex; }
  .quick-cmd { padding: 0.7em 0.15em; }
  .where { display: none; }
}
@media (max-width: 560px) {
  .where { display: none; }
}

/* ---- without JavaScript ----------------------------------------------- */

.noscript {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: auto;
  padding: 8vh var(--edge);
  background: var(--night);
}
.noscript > * {
  max-width: 68ch;
}
.noscript h1 {
  margin: 0 0 0.2em;
  color: var(--voice);
  font: 600 1.5em/1.3 var(--mono);
}
.noscript ul {
  padding-left: 2ch;
}

/* ---- the 404 page --------------------------------------------------- */

.lost .output {
  max-width: 76ch;
}
/* Out in the Void: faint stars, and the Flame far off, guttering a little
   the way a light does at a great distance. */
.art.void {
  --cols: 48;
}
.void .art-core,
.void .art-flame {
  animation: gutter 3.1s ease-in-out infinite;
}
@keyframes gutter {
  0%,
  100% {
    opacity: 1;
  }
  27% {
    opacity: 0.7;
  }
  52% {
    opacity: 0.92;
  }
  74% {
    opacity: 0.58;
  }
}
.suggestion .act {
  color: var(--path);
}

/* ---- motion --------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .banner.reveal .art span,
  .banner.reveal .aside,
  .void .art-core,
  .void .art-flame,
  .cur,
  .prompt.bell {
    animation: none;
  }
}

/* ---- paper (cv --print) ---------------------------------------------- */

.print {
  display: none;
}

@media print {
  @page {
    margin: 16mm 15mm;
  }
  html,
  body {
    height: auto;
    overflow: visible;
    background: #fff;
  }
  body > :not(.print) {
    display: none !important;
  }
  .print {
    display: block;
    color: #161616;
    font: 400 10pt/1.45 var(--mono);
  }
  .print * {
    text-shadow: none !important;
  }
  .print .line {
    min-height: 1.45em;
  }
  .print .voice,
  .print .strong,
  .print .act {
    color: #000;
    font-weight: 600;
    text-decoration: none;
  }
  .print .bright { color: #222; }
  .print .dim { color: #5a5a5a; }
  .print a {
    color: #173a66;
    text-decoration: none;
  }
}
