/* lsd.is front page. Colours are the BBS's own: the ANSI brights that
   src/theme.py's DARK palette names (heading = bright_magenta, label =
   bright_yellow, accent = bright_cyan, positive = bright_green, muted =
   grey62), the Textual theme's primary #6C56A3, and its pure-black
   screen. */
:root {
  --void: #000000;          /* BBS screen background */
  --night: #0a0612;         /* page base */
  --primary: #6c56a3;       /* Textual theme primary */
  --primary-hi: #9a86d6;
  --magenta: #ff00ff;       /* heading */
  --cyan: #00ffff;          /* accent */
  --yellow: #ffff00;        /* label */
  --green: #00ff00;         /* positive */
  --red: #ff5f5f;           /* negative, softened for prose */
  --muted: #9e9e9e;         /* grey62 */
  --ink: #e5e5e5;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono",
          Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --gutter: 16px;
  --bar-h: 46px;
}

* { box-sizing: border-box; }

html { background: var(--night); color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  /* No background here: it would paint over body::before. The base
     colour comes from html. */
}

/* Halftone backdrop on its own fixed layer, so scrolling never
   repaints it: a purple glow at the top over two dot grids in the
   theme purple, offset half a cell to make a checker dither. Dots are
   a full 1px so they land on whole pixels at DPR 1 (no moire). */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(ellipse 90% 60% at 50% 0%, rgba(108, 86, 163, 0.28), transparent 70%),
    radial-gradient(circle at 1px 1px, rgba(108, 86, 163, 0.20) 1px, transparent 1px),
    radial-gradient(circle at 1px 1px, rgba(108, 86, 163, 0.12) 1px, transparent 1px);
  background-size: 100% 100%, 4px 4px, 4px 4px;
  background-position: 0 0, 0 0, 2px 2px;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: clamp(28px, 6vh, 64px) var(--gutter) 48px;
}

/* ── Hero ─────────────────────────────────────────────────────────── */

.hero { text-align: center; }

/* ANSI art: a monospace cell is ~0.6em wide, so a font size of
   (available width / columns / 0.6) fits the widest line. --cols comes
   from the server. Line-height 1 and no tracking keep block glyphs
   (█ ▀ ▄) touching. */
pre.ansi {
  --fit: calc((min(100vw, 1280px) - 2 * var(--gutter)) / (var(--cols, 80) * 0.61));
  display: inline-block;
  margin: 0 auto;
  text-align: left;
  font-family: var(--mono);
  font-size: clamp(3px, var(--fit), 15px);
  line-height: 1;
  letter-spacing: 0;
  font-variant-ligatures: none;
  white-space: pre;
  color: var(--ink);
  overflow: hidden;
  max-width: 100%;
}

.welcome { margin-top: clamp(20px, 4vh, 36px); }

.welcome h1 {
  margin: 0;
  font-size: clamp(19px, 2.4vw, 28px);
  font-weight: 700;
  line-height: 1.2;
  color: var(--magenta);
  text-wrap: balance;
}

.welcome .tagline {
  margin: 6px 0 0;
  color: var(--yellow);
  font-size: clamp(14px, 1.4vw, 16px);
}

.welcome .kyn-line {
  margin: 12px auto 0;
  max-width: 62ch;
  color: var(--ink);
  font-size: clamp(14px, 1.4vw, 16px);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.welcome .kyn-sig {
  color: var(--cyan);
  white-space: nowrap;
}

.welcome .aside {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.welcome code {
  font-family: inherit;
  color: var(--cyan);
  user-select: all;
}

/* ── Terminal frame ───────────────────────────────────────────────── */

.frame {
  margin: clamp(28px, 6vh, 56px) auto 0;
  border: 1px solid var(--primary);
  background: var(--void);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 24px 80px -24px rgba(108, 86, 163, 0.55);
  display: flex;
  flex-direction: column;
  height: clamp(460px, 78vh, 860px);
  scroll-margin: 16px;
}

.frame-bar {
  flex: none;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 5px 0 12px;
  border-bottom: 1px solid var(--primary);
  background: #0d0919;
  font-size: 13px;
  color: var(--muted);
}

.frame-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lamp {
  flex: none;
  width: 7px;
  height: 7px;
  background: var(--muted);
  opacity: 0.6;
}
.frame[data-state="connecting"] .lamp { background: var(--yellow); opacity: 1; }
.frame[data-state="live"] .lamp { background: var(--green); opacity: 1; }
.frame[data-state="live"] .frame-status { color: var(--ink); }

.frame-controls { display: inline-flex; gap: 6px; flex: none; }

.chip {
  font: inherit;
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid #3a2f5c;
  padding: 0 12px;
  min-height: 36px;
  cursor: pointer;
}
.chip:hover { color: var(--cyan); border-color: var(--cyan); }
.chip[aria-pressed="true"] { color: var(--cyan); border-color: var(--primary-hi); }

.frame-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.screen {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--void);
}

.term-host {
  position: absolute;
  inset: 6px 4px 4px 8px;
}
.term-host .xterm { height: 100%; }
.term-host .xterm-viewport { background-color: var(--void) !important; }

/* Until the caller taps in, the page owns the wheel and the keys: a
   clear shield sits over the terminal and the first tap engages it. */
.engage {
  position: absolute;
  inset: 0;
  z-index: 5;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: text;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  font: inherit;
}
.engage span {
  margin: 10px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(13, 9, 25, 0.88);
  border: 1px solid #3a2f5c;
}
.engage:hover span { color: var(--cyan); border-color: var(--cyan); }

/* ── Sign-in, drawn as a BBS prompt ───────────────────────────────── */

.signin {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: clamp(20px, 5vh, 48px) clamp(16px, 4vw, 48px);
  font-size: 15px;
}

.prompt-head { margin: 0 0 22px; color: var(--green); }

.prompt {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 1ch;
  margin: 0 0 10px;
  max-width: 64ch;
  cursor: text;
}

.prompt-label { color: var(--yellow); white-space: nowrap; }

.prompt input {
  flex: 1 1 18ch;
  min-width: 14ch;
  font: inherit;
  color: var(--cyan);
  caret-color: var(--cyan);
  background: transparent;
  border: 0;
  border-bottom: 1px dashed #3a2f5c;
  border-radius: 0;
  padding: 2px 0;
  outline: none;
}
.prompt input:focus { border-bottom: 1px solid var(--cyan); }
.prompt input:-webkit-autofill {
  -webkit-text-fill-color: var(--cyan);
  -webkit-box-shadow: 0 0 0 40px var(--void) inset;
}

.prompt-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 22px;
}

.connect {
  font: inherit;
  color: var(--void);
  background: var(--cyan);
  border: 1px solid var(--cyan);
  padding: 7px 18px;
  min-height: 36px;
  cursor: pointer;
}
.connect:hover { background: #8ffcff; }
.connect:disabled { opacity: 0.5; cursor: wait; }

.prompt-msg { color: var(--red); min-height: 1.5em; }
.prompt-msg.info { color: var(--muted); }

.prompt-hint {
  margin: 28px 0 0;
  max-width: 60ch;
  font-size: 13px;
  color: var(--muted);
}

/* ── Audio dock + link bar (under the terminal) ───────────────────── */

/* A slim strip: the listen page posts its content height and the dock
   matches it; its controls live in the frame header. */
.dock {
  flex: none;
  height: var(--dock-h, 48px);
  border-top: 1px solid var(--primary);
  background: #0b0d12;
}
.dock iframe { width: 100%; height: 100%; border: 0; display: block; }

.linkbar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 8px 12px;
  border-top: 1px solid var(--primary);
  background: #0d0919;
  font-size: 13px;
  color: var(--muted);
}
.linkbar a { color: var(--cyan); word-break: break-all; }

[hidden] { display: none !important; }

/* ── Expanded: the frame takes the viewport ───────────────────────── */

body.-expanded { overflow: hidden; }
body.-expanded .frame {
  position: fixed;
  inset: 0;
  z-index: 100;
  margin: 0;
  height: 100vh;
  height: 100dvh;
  border: 0;
  box-shadow: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--void);
}

/* ── Focus + motion ───────────────────────────────────────────────── */

:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.prompt input:focus-visible { outline: none; }
.engage:focus-visible { outline-offset: -3px; }

@media (prefers-reduced-motion: no-preference) {
  .frame[data-state="connecting"] .lamp { animation: blink 0.9s steps(2, jump-none) infinite; }
  @keyframes blink { 50% { opacity: 0.2; } }
}

@media (max-width: 699px) {
  body { font-size: 14px; }
  .chip { padding: 0 8px; }
  .chip-wide { display: none; }
  .frame { height: min(70vh, 620px); }
  .signin { font-size: 14px; }
}
