/* AI Wars base stylesheet. Colors come only from palette.css roles. */

/* Unmodified Web437 font by VileR; attribution and license ship beside it.
   The versioned URL keeps immutable/CDN caches safe when the font changes. */
@font-face {
  font-family: "AI Wars VGA";
  src: url("ibm-vga-8x16.woff?v=2.2") format("woff");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  --col-width: 90ch;
  --gutter: 16px;
}

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

html {
  background: var(--bg);
  color: var(--fg);
  font-family: "Px437 IBM VGA 8x16", "Perfect DOS VGA 437", "IBM Plex Mono",
    Menlo, Consolas, "DejaVu Sans Mono", monospace;
  font-size: 16px;
  line-height: 1.25;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--link);
}

/* ---- status bar ------------------------------------------------------- */

.status {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--status-bg);
  color: var(--status-fg);
  padding: 4px var(--gutter);
  display: flex;
  flex-wrap: wrap;
  gap: 0 3ch;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
}

.status-game,
.status-who {
  display: inline-flex;
  gap: 0 2ch;
  min-width: 0;
}

.status .who {
  overflow: hidden;
  text-overflow: ellipsis;
}

.status .hotkey {
  color: var(--status-fg);
  text-decoration: underline;
}

/* Narrow screens: drop the brand, keep the bar to two lines, and let a long
   character name truncate rather than wrap. */
@media (max-width: 639px) {
  .status .brand {
    display: none;
  }
  .status-game,
  .status-who {
    flex: 1 1 100%;
    justify-content: center;
  }
  .status .who {
    max-width: 60vw;
  }
}

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

main.screen {
  width: 100%;
  max-width: calc(var(--col-width) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 12px var(--gutter) 24px;
  flex: 1 0 auto;
}

.box {
  border: 1px solid var(--border);
  padding: 8px 12px;
  margin: 0 0 12px;
}

.box > h1,
.box > h2 {
  margin: -8px -12px 8px;
  padding: 2px 12px;
  font-size: 1em;
  font-weight: normal;
  background: var(--border);
  color: var(--bg);
}

h1,
h2,
h3 {
  font-size: 1em;
  font-weight: normal;
  color: var(--bright);
  margin: 0 0 8px;
}

p,
pre {
  margin: 0 0 8px;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.art-frame {
  container-type: inline-size;
  margin: 0 0 16px;
  text-align: center;
}

pre.art {
  font-family: "AI Wars VGA", monospace;
  font-weight: 400;
  font-variant-ligatures: none;
  letter-spacing: 0;
  white-space: pre;
  overflow: hidden;
  line-height: 1;
  /* VGA's 8x16 cells are half an em wide. Size to this scene, not to an
     assumed 80-column terminal. The viewport rule covers older browsers. */
  font-size: min(16px, calc((100vw - 2 * var(--gutter)) / (var(--art-cols) * 0.5)));
  font-size: min(16px, calc(200cqw / var(--art-cols)));
  margin: 0 auto;
  width: max-content;
  max-width: 100%;
  text-align: left;
}

.art-frame figcaption {
  margin: 8px auto 0;
  max-width: 60ch;
  color: var(--dim);
  font-size: 0.875rem;
  line-height: 1.4;
  text-wrap: pretty;
}

.bright {
  color: var(--bright);
}
.dim {
  color: var(--dim);
}
.ok {
  color: var(--ok);
}
.danger {
  color: var(--danger);
}
.warn {
  color: var(--warn);
}
.accent {
  color: var(--accent);
}

/* ---- menus ------------------------------------------------------------ */

.menu {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
}

.menu li {
  margin: 0;
}

.menu a,
.menu button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 8px 4px;
  margin: 0;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu a:hover,
.menu a:focus-visible,
.menu button:hover,
.menu button:focus-visible {
  background: var(--status-bg);
  color: var(--bright);
  outline: none;
}

.hotkey {
  color: var(--hotkey);
}

.menu .hotkey::before {
  content: "[";
  color: var(--dim);
}
.menu .hotkey::after {
  content: "]";
  color: var(--dim);
}

/* A highlighted row is one block of color: dimmed notes and hotkey brackets
   take the row's text color so they stay readable on the highlight. */
.menu :is(a, button):is(:hover, :focus-visible) .dim,
.menu :is(a, button):is(:hover, :focus-visible) .hotkey::before,
.menu :is(a, button):is(:hover, :focus-visible) .hotkey::after {
  color: inherit;
}

/* Two-column menu on wide screens. */
@media (min-width: 640px) {
  .menu.cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 2ch;
  }
  .menu a,
  .menu button {
    min-height: 0;
    padding: 2px 4px;
    /* A row that wraps keeps its hotkey on its first line. */
    align-items: baseline;
  }
}

/* ---- meters ----------------------------------------------------------- */

.meter {
  display: inline-block;
  white-space: nowrap;
}
.meter .fill {
  color: var(--meter-fill);
}
.meter .empty {
  color: var(--meter-empty);
}

/* ---- forms (BBS wrapper only; see plan 2.3 and 5.7) ------------------- */

label {
  display: block;
  margin: 0 0 4px;
}

input[type="text"],
input[type="password"] {
  font: inherit;
  width: 100%;
  max-width: 40ch;
  padding: 6px 8px;
  background: var(--bg);
  color: var(--bright);
  border: 1px solid var(--border);
}

input:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 0;
}

button.primary {
  font: inherit;
  min-height: 44px;
  padding: 8px 16px;
  background: var(--status-bg);
  color: var(--status-fg);
  border: 1px solid var(--border);
  cursor: pointer;
}

@media (min-width: 640px) {
  button.primary {
    min-height: 0;
  }
}

/* ---- footer ----------------------------------------------------------- */

footer.hint {
  position: relative;
  color: var(--dim);
  text-align: center;
  padding: 8px var(--gutter) 22px;
}

/* The build in the lower-left corner of the main screens (issue 170). */
footer.hint .build {
  position: absolute;
  left: var(--gutter);
  bottom: 4px;
  font-size: 0.75em;
}

/* Inline preformatted text inside a menu row (choosers with aligned columns). */
pre.inline {
  display: inline;
  margin: 0;
  white-space: pre;
  font: inherit;
}

/* ---- backstory picks -------------------------------------------------- */

.menu .blurb {
  margin: 0 0 12px 4ch;
}

/* ---- spending and results --------------------------------------------- */

/* A row's label and its price are one flex item, so a long row wraps as
   one run of text after the hotkey instead of splitting into two narrow
   blocks side by side. The hotkey never shrinks. */
.menu .hotkey {
  flex: none;
}
.menu .label {
  flex: 1;
  margin-left: 1ch;
}

/* Menu rows are flex boxes, which drop the space before a dimmed note
   ("The Hotel Bar at NeurIPS Buy a round..."): put it back. */
.menu a > .dim,
.menu button > .dim {
  margin-left: 1ch;
}

/* What the player has to spend, on every screen that spends it. */
.have {
  color: var(--accent);
}

/* What an action changed: "Skill increased by 2 (now 17)." */
.changes {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  color: var(--bright);
}

/* ---- help ------------------------------------------------------------- */

.glossary {
  margin: 0;
}

.glossary dt {
  color: var(--bright);
  margin-top: 8px;
}

.glossary dd {
  margin: 0 0 0 4ch;
}

.hint a {
  color: var(--link);
}

/* ---- live screens -------------------------------------------------------
   The lines are in the page already; terminal.js plays them. */

.term-screen {
  margin: 0;
  min-height: 6em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.term-screen > span {
  display: block;
}

.t-cmd {
  color: var(--bright);
}

.t-out {
  color: var(--fg);
}

.t-say {
  color: var(--accent);
}

.term-title {
  margin: 0 0 6px;
  color: var(--dim);
  border-bottom: 1px solid var(--dim);
}

.t-bar {
  color: var(--accent-2);
}

.t-ok {
  color: var(--ok);
}

.t-warn {
  color: var(--warn);
}

.t-bad {
  color: var(--danger);
}

.term-hint {
  margin: 8px 0 0;
  text-align: right;
}

/* The result waits for the terminal; its space is kept so nothing jumps. */
.term-wait {
  visibility: hidden;
}
