/* Two skies. The voyage is black and starred; at landfall the stars fade
   and the page turns to loam. The closing document is the one object set
   on paper. */

:root {
  --ground: #000;
  --raised: #0e131d;
  --ink: #e3ebf1;
  --muted: #8a99b2;
  --accent: #9dcbea;
  --good: #8fd3a4;
  --bad: #f08a7e;
  --warn: #e8c95f;
  --line: #26303f;
  --paper: #dce2e4;
  --paper-ink: #1d2832;

  --prose: "Spectral", "Iowan Old Style", Georgia, serif;
  --ui: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --table: ui-monospace, "Cascadia Mono", "DejaVu Sans Mono", monospace;

  color-scheme: dark;
}

body[data-act="colony"] {
  --ground: #1e2820;
  --raised: #27332a;
  --ink: #ebeadf;
  --muted: #9aa392;
  --accent: #c5d88a;
  --line: #36443a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--ground);
  color: var(--ink);
  font: 1.125rem/1.65 var(--prose);
  transition: background-color 2.4s ease, color 2.4s ease;
}

/* Faint stars, fixed behind the log. Each layer tiles at its own odd size
   so the field never visibly repeats. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 12% 18%, rgb(255 255 255 / 0.55) 0 1px, transparent 1.5px),
    radial-gradient(circle at 63% 41%, rgb(255 255 255 / 0.35) 0 1px, transparent 1.5px),
    radial-gradient(circle at 37% 77%, rgb(220 230 255 / 0.45) 0 1px, transparent 1.5px),
    radial-gradient(circle at 88% 9%, rgb(255 255 255 / 0.3) 0 1px, transparent 1.5px),
    radial-gradient(circle at 24% 56%, rgb(255 240 220 / 0.4) 0 1px, transparent 1.5px),
    radial-gradient(circle at 71% 85%, rgb(255 255 255 / 0.25) 0 1px, transparent 1.5px),
    radial-gradient(circle at 49% 23%, rgb(200 220 255 / 0.6) 0 1.2px, transparent 2px),
    radial-gradient(circle at 93% 64%, rgb(255 255 255 / 0.3) 0 1px, transparent 1.5px);
  background-size: 317px 283px, 409px 367px, 251px 433px, 523px 199px,
                   379px 311px, 461px 257px, 787px 619px, 229px 347px;
  transition: opacity 2.4s ease;
}
body[data-act="colony"]::before { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  body, body::before { transition: none; }
}

.shell {
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr);
  gap: 0 3rem;
  max-width: 76rem;
  margin: 0 auto;
  padding: 0 max(1rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left));
}

/* --- telemetry rail ------------------------------------------------------- */

.rail {
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100dvh;
  overflow-y: auto;
  padding: 2rem 0;
  font: 0.875rem/1.5 var(--ui);
  font-variant-numeric: tabular-nums;
}

.rail summary { display: none; }

.rail .row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  padding: 0.1rem 0;
}

.rail .gap { height: 0.75rem; }
.rail .line:first-child { font-size: 1rem; }

.commands {
  display: grid;
  gap: 0.25rem;
  margin-top: 1.5rem;
}

/* --- the log -------------------------------------------------------------- */

main {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 40rem;
}

.log { flex: 1; padding: 2rem 0 1rem; }

.block { margin-bottom: 1.75rem; scroll-margin-top: 1.5rem; }
.block p { margin: 0 0 0.75rem; }

.block .mech,
.block .choice {
  font: 0.875rem/1.5 var(--ui);
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.block .choice { color: var(--accent); margin-bottom: 0.75rem; }

.block .table {
  font: 0.8125rem/1.45 var(--table);
  white-space: pre;
  overflow-x: auto;
  margin: 0;
  color: var(--accent);
}

/* A survey: worlds across, readings down. */
.block .survey {
  overflow-x: auto;
  margin: 0.5rem 0 1.25rem;
}
.survey table {
  border-collapse: collapse;
  font: 0.875rem/1.4 var(--ui);
  font-variant-numeric: tabular-nums;
}
.survey th,
.survey td {
  padding: 0.375rem 1.25rem 0.375rem 0;
  text-align: left;
  vertical-align: top;
}
.survey thead th,
.survey thead td {
  font-weight: 700;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.survey tbody th {
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
}
.survey tbody tr + tr { border-top: 1px solid color-mix(in srgb, var(--line) 55%, transparent); }
.survey td { color: var(--accent); min-width: 9rem; }

.block .quote { padding-left: 1.5rem; font-style: italic; }

.block h2 {
  font: 600 1rem/1.4 var(--ui);
  margin: 0 0 0.5rem;
}

hr.leg {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2.5rem 0 1rem;
}

/* The end of a voyage or a century: the document they wrote. */
.document {
  background: var(--paper);
  color: var(--paper-ink);
  padding: 2.5rem clamp(1.25rem, 5vw, 3.5rem);
  margin: 1rem 0 2rem;
  border-radius: 2px;
  line-height: 1.7;
}
.document h2 {
  font: 600 1.05rem/1.4 var(--prose);
  font-variant: small-caps;
  font-variant-numeric: oldstyle-nums;
  text-transform: lowercase;
  letter-spacing: 0.04em;
  margin: 2rem 0 0.75rem;
}
.document h2:first-child { font-size: 1.5rem; margin-top: 0; }
.document .mech { color: #56616b; }
.document .good, .document .bad, .document .warn { color: inherit; }

/* --- choices -------------------------------------------------------------- */

.dock {
  position: sticky;
  bottom: 0;
  padding: 1rem 0 max(1.25rem, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--ground) 1rem);
  transition: background-color 2.4s ease;
}

.prompt { margin: 0 0 0.5rem; font: 700 0.9375rem/1.4 var(--ui); }

.choices {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.375rem;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.choices button,
.commands button {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  width: 100%;
  text-align: left;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.625rem 0.875rem;
  font: 0.9375rem/1.45 var(--ui);
}
.commands button {
  background: none;
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

.choices button:hover,
.commands button:hover { border-color: var(--accent); }

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

kbd {
  font: 700 0.8125rem/1 var(--ui);
  color: var(--accent);
  min-width: 1ch;
}

/* --- markup from the engine ---------------------------------------------- */

.b { font-weight: 700; }
.i { font-style: italic; }
.dim { opacity: 0.68; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.muted { color: var(--muted); }
.accent { color: var(--accent); }
.ink { color: var(--ink); }

/* --- narrow screens ------------------------------------------------------- */

@media (max-width: 52rem) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  /* The rail becomes a strip pinned to the top: the vitals always in view,
     the full telemetry a tap away. */
  .rail {
    position: sticky;
    top: 0;
    z-index: 1;
    max-height: 70dvh;
    padding: max(0.5rem, env(safe-area-inset-top)) 0 0.5rem;
    background: var(--ground);
    border-bottom: 1px solid var(--line);
    transition: background-color 2.4s ease;
  }
  .rail summary {
    display: block;
    cursor: pointer;
    list-style: none;
  }
  .rail summary::-webkit-details-marker { display: none; }
  #vitals {
    display: flex;
    flex-wrap: wrap;
    gap: 0.125rem 0.875rem;
  }
  .vital { white-space: nowrap; }
  .more {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--muted);
  }
  .more::before { content: "Show all telemetry"; }
  .rail[open] .more::before { content: "Hide telemetry"; }
  .rail[open] .more { margin-bottom: 0.75rem; }
  .rail[open] #vitals { display: none; }
  .block { scroll-margin-top: 6rem; }
  body { font-size: 1.0625rem; }
}
