/* SPDX-License-Identifier: MIT */
/* Copyright (c) 2026 Stanislav Sedov <stas@deglitch.com> */

/*
 * The page's look: a light console of the Lisp Machine era. The window is
 * the console's putty plastic; in its middle, a monitor housing holds the
 * screen (the canvas, whose size web/main.ts sets) in a thin charcoal bezel, as large as the window allows, with
 * the Space Cadet keys a browser keyboard lacks in two clusters of
 * keycaps on either side (web/key-clusters.ts). Above it, the page's
 * commands in one bar, as the Lisp Machine's own menus draw them: black
 * ink on paper, each item boxed, inverse while pressed. Below it, the
 * who-line: the run state, the latest notice and the disk's storage in
 * one inverse strip. The panels, the download question and, on a window
 * with no room beside the screen, the keys open as the Lisp
 * Machine's pop-up windows: boxed in ink, an inverse label bar on top.
 */

/* The typeface (web/fonts/README.md). */
@font-face {
  font-family: "IBM Plex Mono";
  font-weight: 400;
  font-display: swap;
  src: url("fonts/IBMPlexMono-Regular.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-weight: 600;
  font-display: swap;
  src: url("fonts/IBMPlexMono-SemiBold.woff2") format("woff2");
}

:root {
  --case: #dcd8cd;
  --case-face: #e7e4db;
  --case-inset: #d0cbbf;
  --case-rule: #b4afa2;
  --bezel: #2b2b2b;
  --paper: #f6f4ec;
  --ink: #141414;
  --label: #8a867c;
  --dim: #9b978c;
  --failed: #b3121a;
  /* The enclosure's printing and grille: near-black ink with real contrast on the case. */
  --ink-badge: #242820;
  --grille: #6f7662;
  /* A key latched by a tap: lit amber on its keycap, and named on Keys. */
  --latch: #f2c45a;
  --latch-ink: #3b2a10;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  /* A keycap, 1.6 by 1.3 cm on a short window and larger on a tall one, beside a larger screen; a cluster is four to a row. */
  --key-width: clamp(60px, 6vh, 84px);
  --key-height: calc(var(--key-width) * 0.8);
  --key-gap: 7px;
  --cluster-width: calc(4 * var(--key-width) + 3 * var(--key-gap) + 2 * 14px);
  /* The room each side of the screen keeps for its cluster, when the window has it. */
  --side-room: calc(var(--cluster-width) + 28px);
  color-scheme: light;
}

html, body {
  margin: 0;
  background: var(--case);
  color: var(--ink);
  font: 13px/1.4 var(--mono);
  /* A phone turned sideways keeps the text's size rather than enlarging it. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* The console fills the window: the commands, the monitor, the who-line. */
#console {
  height: 100vh;
  height: 100dvh;
  min-height: 420px;
  box-sizing: border-box;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  /* One column no wider than the window: a long who-line field ends in an ellipsis, never widens the page. */
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(#e2ded4, var(--case) 40%, #d5d1c5);
}

/* ---- The command bar ---- */

/* An inset panel across the console; its groups centred, a thin rule between them. */
#menu {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px 0;
  padding: 7px 12px;
  background: var(--case-inset);
  border-radius: 6px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.18), 0 1px 0 rgba(255, 255, 255, 0.7);
}

#menu .group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
}

#menu .group + .group { border-left: 1px solid var(--case-rule); }

/* Menu and the sheet's storage line, shown only on a phone's width (the phone's command bar, near the end of this file). */
#menu #menu-toggle,
#menu #menu-storage { display: none; }

/* A command: ink on paper in a one-pixel box; inverse under the mouse and while pressed. */
#menu button,
#menu .item,
#advanced button,
#advanced .item,
dialog button {
  display: inline-block;
  padding: 3px 10px;
  font: 12px/1.4 var(--mono);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 0;
  text-decoration: none;
  cursor: pointer;
}

#menu button:hover:enabled,
#menu .item:hover,
#menu button:active:enabled,
#advanced button:hover:enabled,
#advanced .item:hover,
#menu #keys[aria-expanded="true"],
dialog button:hover {
  background: var(--ink);
  color: var(--paper);
}

#menu button:disabled,
#advanced button:disabled { color: var(--dim); border-color: var(--case-rule); background: transparent; cursor: default; }

/* A file command is its label; the file input inside it is there for the keyboard and the pointer, not seen. */
#menu .item input,
#advanced .item input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* The disk image chosen, beside its command. */
#disk-name {
  display: inline-block;
  vertical-align: bottom;
  max-width: 14em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
  color: #55524a;
}

#disk-name:empty { display: none; }

#menu :focus-visible,
#menu .item:has(input:focus-visible),
#advanced :focus-visible,
#advanced .item:has(input:focus-visible),
dialog :focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---- The pop-up windows: About, Help, Settings, the download question, the keys on a narrow window ---- */

.window {
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 5px 5px 0 rgba(20, 20, 20, 0.28);
}

.window .label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin: 0;
  padding: 2px 8px 3px;
  background: var(--ink);
  color: var(--paper);
  font: 600 13px/1.4 var(--mono);
}

.window .label h2 { margin: 0; font: inherit; }
.window .label a { color: var(--paper); font-weight: 400; text-decoration: none; border: 1px solid var(--paper); padding: 0 8px; }
.window .label a:hover,
.window .label a:focus-visible { background: var(--paper); color: var(--ink); outline: none; }

/* About, How it works, Help and Settings: pop-up windows over the console while the address names one. */
.panel {
  display: none;
  position: fixed;
  z-index: 20;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(46em, calc(100vw - 48px));
  max-height: calc(100dvh - 96px);
  overflow-y: auto;
  overflow-wrap: anywhere;
  box-shadow: 5px 5px 0 rgba(20, 20, 20, 0.28), 0 0 0 100vmax rgba(60, 54, 40, 0.3);
}

.panel:target { display: block; }
.panel .label { position: sticky; top: 0; }
.panel .body,
.licenses .body { padding: 4px 18px 16px; }
.panel h3,
.licenses .body h2 {
  margin: 1.4em 0 0.5em;
  padding-bottom: 3px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--ink);
}
.panel ul,
.licenses ul { padding-left: 1.4em; }
.panel li,
.licenses li { margin: 0.4em 0; }
#rendering label { cursor: pointer; font-weight: 600; }
#rendering input { accent-color: var(--ink); vertical-align: -2px; margin: 0 4px 0 0; }
.panel .body a,
.licenses .body a { color: var(--ink); }
.panel .fine { margin-top: 1.6em; font-size: 11px; }

/* Help and Demos: the tour and the demos, each item's title, what to type or press, what you see and (Demos) how to stop it. */
#help ol { padding-left: 2em; }
#demos ul.demos { padding-left: 0; list-style: none; }
:is(#help, #demos) li { margin: 0.9em 0; }
:is(#help, #demos) li p { margin: 0.2em 0; }
:is(#help, #demos) .see { color: var(--label); }
:is(#help, #demos) code,
:is(#help, #demos) kbd { font-family: var(--mono); font-size: 12px; }
:is(#help, #demos) code { padding: 0 4px; background: rgba(20, 20, 20, 0.07); overflow-wrap: anywhere; }
:is(#help, #demos) kbd { padding: 0 4px; border: 1px solid var(--ink); border-bottom-width: 2px; border-radius: 2px; white-space: nowrap; }
:is(#help, #demos) .typed button {
  margin-left: 4px;
  padding: 0 5px;
  font: 11px/1.4 var(--mono);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink);
  cursor: pointer;
}
:is(#help, #demos) .typed button:hover:enabled,
:is(#help, #demos) .typed button:focus-visible { background: var(--ink); color: var(--paper); outline: none; }
:is(#help, #demos) .typed button:disabled { cursor: default; opacity: 0.4; }
#help table.keys { border-collapse: collapse; }
#help table.keys th,
#help table.keys td { padding: 2px 10px 2px 0; text-align: left; vertical-align: baseline; }
#help table.keys th { font-weight: 600; white-space: nowrap; }

/* The licences page (web/licenses.html): one window, read as a document. */
.licenses main { max-width: 52em; margin: 24px auto; overflow-wrap: anywhere; }
.licenses .label h1 { margin: 0; font: inherit; }
.licenses pre { white-space: pre-wrap; font-size: 12px; }

/* A question the page asks in a modal dialog (a download's). */
dialog.window { max-width: 36em; padding: 0; border: 2px solid var(--ink); }
dialog::backdrop { background: rgba(60, 54, 40, 0.3); }
dialog form { padding: 14px 16px 14px; }
dialog p { margin: 0 0 14px; }
dialog button { margin-right: 6px; }

/* ---- The monitor ---- */

/* web/main.ts fits the screen to this area's content box less the housing around it, both of which it measures. */
#screen-area {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  /* The keys' pop-up is placed in this area, so it fits whatever the monitor's width. */
  position: relative;
}

/* The housing: light plastic with a soft bevel; the bezel is the canvas's own shadow ring, inside its padding. */
/*
 * Hard-edged bevels, as moulded plastic catches the light: a light inset
 * on the top and left, a darker one on the bottom and right, no blur.
 */
#monitor {
  /* The housing around the screen, which the maker strip, the text sink and the run light are set in from. */
  --housing-x: 30px;
  --housing-top: 36px;
  padding: var(--housing-top) var(--housing-x) 0;
  background: var(--case-face);
  border: 1px solid #a7a598;
  border-radius: 6px;
  box-shadow:
    inset 5px 2px 0 #f4f2ea,
    inset -6px -6px 0 #c9c4b6,
    0 12px 28px rgba(70, 60, 40, 0.2);
}

/* The maker's strip above the screen: tiny engraved capitals and a short dark bar. */
#maker {
  position: absolute;
  top: 11px;
  left: var(--housing-x);
  right: var(--housing-x);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font: 600 7px/1 var(--mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-badge);
  white-space: nowrap;
  overflow: hidden;
}
#maker::after { content: ""; width: 34px; height: 4px; background: var(--ink-badge); }

#screen {
  display: block;
  /* An unlit screen until the first frame paints it. */
  background: #e9e7e0;
  image-rendering: pixelated;
  border-radius: 4px;
  /* The bezel: a thick dark ring and a thin light one outside it, taking no layout room, so the canvas's box is the screen alone. */
  box-shadow: 0 0 0 1px #000, 0 0 0 14px var(--bezel), 0 0 0 16px #f4f2ea, 0 0 0 17px #a7a598;
}

/* A finger on the screen is the mouse (web/input.ts TouchMouse), never a scroll or a zoom. */
#screen { touch-action: none; }

/*
 * While the machine runs, the Lisp Machine's arrow is the only pointer over
 * the screen: the arrow follows the host pointer to its place a few frames
 * behind (web/pointer.ts), so a host pointer shown there would trail a
 * second arrow ahead of it.
 * web/page.ts sets data-phase from the page's phase.
 */
#screen[data-phase="running"] { cursor: none; }

/*
 * The text sink: invisible, at the screen's top left so a browser that
 * scrolls a focused field into view scrolls to the screen, and at 16px
 * so iOS does not zoom the page when it takes the focus.
 */
#monitor { position: relative; }
#text-sink {
  position: absolute;
  top: var(--housing-top);
  left: var(--housing-x);
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  font-size: 16px;
  opacity: 0;
  resize: none;
  overflow: hidden;
  caret-color: transparent;
  pointer-events: none;
}

#screen:focus { outline: none; }
/* Drawn on the bezel, inside its 14px. */
#screen:focus-visible { outline: 2px solid var(--paper); outline-offset: 5px; }

/* The badge on the housing's chin, set as the console's labels are, between two short vents. */
#badge {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  height: 18px;
  margin: 14px 0 0;
  padding: 12px 0;
  font: 700 19px/18px var(--mono);
  letter-spacing: -1px;
  color: var(--ink-badge);
}
#badge .mark { display: flex; align-items: baseline; gap: 6px; }
#badge small { font: 600 7px/1 var(--mono); letter-spacing: 0.08em; }

#badge::before,
#badge::after {
  content: "";
  width: 65px;
  height: 17px;
  background: repeating-linear-gradient(90deg, var(--grille) 0 2px, transparent 2px 5px);
}

/*
 * The run light on the chin, right of the badge, as a panel indicator: a
 * lens in a dark recessed ring with its engraved name beside it. Lit
 * green while the machine runs, red once the page has failed, dark
 * otherwise (web/page.ts showLight sets the class). Except on a short
 * window, it takes no layout room, so web/main.ts's measure of the
 * housing is the housing alone.
 */
#run-light {
  position: absolute;
  right: var(--housing-x);
  bottom: 21px;
  transform: translateY(50%);
  display: flex;
  align-items: center;
  gap: 7px;
  font: 600 9px/1 var(--mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--label);
}
#run-light .lens {
  order: 1;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #6d6a62, #2c2b27 70%);
  box-shadow: 0 0 0 2px #3a3833, 0 0 0 3px #b9b4a7, inset 0 1px 1px rgba(0, 0, 0, 0.6);
  transition: box-shadow 0.2s;
}
#run-light.on .lens {
  background: radial-gradient(circle at 35% 30%, #d9ffd0, #3fd13a 45%, #1f8a1c);
  box-shadow: 0 0 0 2px #3a3833, 0 0 0 3px #b9b4a7, 0 0 7px 2px rgba(80, 220, 70, 0.55);
}
#run-light.paused .lens {
  background: radial-gradient(circle at 35% 30%, #fff1c9, #e7a92b 45%, #a8700f);
  box-shadow: 0 0 0 2px #3a3833, 0 0 0 3px #b9b4a7, 0 0 6px 2px rgba(230, 170, 40, 0.45);
}
#run-light.failed .lens {
  background: radial-gradient(circle at 35% 30%, #ffd2cc, #e0362b 45%, var(--failed));
  box-shadow: 0 0 0 2px #3a3833, 0 0 0 3px #b9b4a7, 0 0 7px 2px rgba(225, 50, 40, 0.5);
}
@media (prefers-reduced-motion: reduce) {
  #run-light .lens { transition: none; }
}

/* ---- The Space Cadet keys ---- */

/*
 * A cluster: a recessed tray of keycaps in rows of four, its name above
 * them. Each key is a button web/input.ts holds down while the pointer
 * does; its cap is a top face (::before) on a darker skirt, raised by
 * its shadow, and it goes down while held. As on a real keyboard, the
 * command keys are light putty, the shift keys a darker warm grey with
 * light legends, Abort brick and the prefix keys slate blue. Each cap's colours are
 * custom properties, so a kind of key sets only those; every legend
 * keeps at least 4.5:1 contrast against its face.
 */
.cluster {
  display: grid;
  grid-template-columns: repeat(4, var(--key-width));
  grid-template-rows: auto;
  grid-auto-rows: var(--key-height);
  gap: var(--key-gap);
  box-sizing: border-box;
  width: var(--cluster-width);
  padding: 10px 14px 16px;
  background: linear-gradient(#d3cfc3, #cbc6ba);
  border-radius: 10px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.25), 0 1px 0 rgba(255, 255, 255, 0.75);
}

.cluster::before {
  content: attr(aria-label);
  grid-column: 1 / -1;
  font: 600 calc(var(--key-width) * 0.16)/1 var(--mono);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-align: center;
  color: var(--label);
}

.cluster button {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 4px 8px;
  font: 600 calc(var(--key-width) * 0.14)/1.2 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  /* A legend's words stand one to a line (web/key-clusters.ts). */
  white-space: pre-line;
  --legend: #3b3933;
  --face-top: #fbf9f4;
  --face-bottom: #e6e2d8;
  --skirt-top: #cfcabd;
  --skirt-bottom: #b7b2a4;
  --skirt-edge: #8e897c;
  --skirt-shadow: #9d988b;
  color: var(--legend);
  background: linear-gradient(var(--skirt-top), var(--skirt-bottom));
  border: 1px solid var(--skirt-edge);
  border-radius: 6px;
  box-shadow: 0 3px 0 var(--skirt-shadow), 0 5px 7px rgba(50, 40, 20, 0.3);
  cursor: pointer;
  touch-action: none;
  transition: transform 40ms, box-shadow 40ms;
}

/* The top face: lighter, dished, set in from the skirt more at the front. */
.cluster button::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 2px 4px 7px;
  border-radius: 4px;
  background: linear-gradient(var(--face-top), var(--face-bottom));
  box-shadow: inset 0 -1px 2px rgba(0, 0, 0, 0.08), 0 1px 1px rgba(0, 0, 0, 0.15);
}

/* The shift keys: a darker warm grey, light legends. */
#keys-shift button {
  --legend: #f6f3ea;
  --face-top: #726c62;
  --face-bottom: #676157;
  --skirt-top: #5f5a51;
  --skirt-bottom: #4f4b43;
  --skirt-edge: #3e3a34;
  --skirt-shadow: #45413a;
}

/* Abort: a muted brick. */
#keys-command button[aria-label="Abort"] {
  --legend: #f6f3ea;
  --face-top: #9a5a48;
  --face-bottom: #8f5242;
  --skirt-top: #844c3d;
  --skirt-bottom: #6f3f33;
  --skirt-edge: #573128;
  --skirt-shadow: #633a2f;
}

/* The PC function key that presses this key (web/keymap.ts FUNCTION_KEYS), small in the cap's top left corner. */
.cluster button[data-fkey]::after {
  content: attr(data-fkey);
  position: absolute;
  top: 4px;
  left: 7px;
  font-size: calc(var(--key-width) * 0.1);
  font-weight: 500;
  letter-spacing: 0;
}

/* The prefix keys, pressed and then followed by a letter: a muted slate blue, light legends. */
#keys-command button:is([aria-label="system"], [aria-label="network"], [aria-label="terminal"]) {
  --legend: #f6f3ea;
  --face-top: #5d6b80;
  --face-bottom: #556377;
  --skirt-top: #4d5a6d;
  --skirt-bottom: #414c5d;
  --skirt-edge: #333c4a;
  --skirt-shadow: #3a4453;
}

.cluster button[data-symbol] { font-size: calc(var(--key-width) * 0.25); letter-spacing: 0; }

/* Held, or latched by a tap (web/input.ts Latches): the key goes down, and its shadow with it. */
.cluster button:active,
.cluster button[aria-pressed="true"] {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--skirt-shadow), 0 1px 2px rgba(50, 40, 20, 0.3);
}

/* Latched or locked: its top face lit amber as well, so a latch reads at a glance (the ids outrank each cluster's colours). */
:is(#keys-shift, #keys-command) button[aria-pressed="true"] {
  --legend: var(--latch-ink);
  --face-top: var(--latch);
  --face-bottom: #e2b044;
}

/* The keys latched by a tap, named on Keys (web/main.ts), so they show while the pop-up is closed. */
#keys-latched {
  display: inline-block;
  max-width: 12ch;
  vertical-align: bottom;
  margin-left: 6px;
  padding: 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--latch);
  color: var(--latch-ink);
}
#keys-latched:empty { display: none; }

.cluster button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
/* Locked by a double tap, or a lock key tapped down: ringed as well, as it stays down past the next key. */
.cluster button[data-latch="locked"] { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Without room beside the screen: a pop-up menu over the monitor holding both clusters, opened by Keys. */
#keys-menu {
  position: absolute;
  z-index: 10;
  top: 8px;
  left: 0;
  right: 0;
  width: max-content;
  max-width: calc(100% - 16px);
  max-height: calc(100% - 16px);
  margin: 0 auto;
  overflow: auto;
}

#keys-menu[hidden] { display: none; }

#palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  padding: 16px;
}

/* With room beside the screen: the clusters stand on either side of the monitor, always shown, and Keys is not needed. */
@media (min-width: 1180px) and (min-aspect-ratio: 4/3) {
  #screen-area { padding: 0 var(--side-room); }
  /* The monitor, which the clusters are placed against. */
  #rig { position: relative; }
  #menu #keys { display: none; }
  #keys-menu,
  #keys-menu[hidden],
  #palette { display: contents; }
  #keys-menu > .label { display: none; }
  .cluster { position: absolute; top: 50%; transform: translateY(-50%); }
  #keys-shift { right: calc(100% + var(--side-room) - var(--cluster-width)); }
  #keys-command { left: calc(100% + var(--side-room) - var(--cluster-width)); }
}

/* ---- The who-line ---- */

/*
 * The screen's colours inverted, across the console's bottom. One row
 * that keeps its height while the status changes (a long field ends in an
 * ellipsis), so the monitor above holds still.
 */
#wholine {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 24px;
  padding: 4px 12px;
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  box-shadow: 0 0 0 3px var(--case-inset);
  border-radius: 1px;
}

#status { flex: 0 1 auto; max-width: 45%; margin: 0; color: #c9c6bc; }
#storage { flex: 0 1 auto; max-width: 30%; color: #c9c6bc; }
/* The speed against a CADR: short, so it never shrinks; it takes no room while it shows nothing. */
#speed { flex: none; white-space: nowrap; }
#speed:empty { display: none; }
#status, #storage { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* A failure holds the status line: unmistakable, and all of it shown. */
#status.failed {
  flex: 1 0 60%;
  max-width: none;
  padding: 0 8px;
  white-space: normal;
  background: var(--failed);
  color: #fff;
  font-weight: 600;
}

/*
 * The notices: the latest fills the who-line's free room; hovered or
 * focused, every notice the page keeps, in a panel over the whole
 * who-line growing up over the monitor. The row keeps its height.
 */
#notices {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--paper);
}

#notices > li { display: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#notices > li:last-child { display: block; }
#notices > li::before { content: "> "; }

#notices:hover,
#notices:focus {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 50vh;
  overflow-y: auto;
  padding: 6px 12px 4px;
  background: var(--ink);
  border-top: 1px solid var(--paper);
}

#notices:hover > li,
#notices:focus > li { display: block; margin: 2px 0; white-space: normal; }

#wholine :focus-visible { outline: 2px solid var(--paper); outline-offset: 2px; }

/* A portrait window (a phone): the screen at the top, where a soft keyboard leaves it in view. */
@media (max-aspect-ratio: 3/4) and (pointer: coarse) {
  #screen-area { place-items: start center; }
}

/* A narrow window: the bar's groups wrap as rows, without the rules between them. */
@media (max-width: 1100px) {
  #menu .group { padding: 0 8px; }
  #menu .group + .group { border-left: none; }
}

/*
 * A phone's width: narrower margins, so the screen, which web/main.ts
 * fits to what they leave, is as wide as it can be. The housing stands
 * centred between the command bar and the who-line (in place of the
 * portrait rule's top: a soft keyboard scrolls the focused text sink at
 * the screen's top into view either way), so a tall phone's spare height
 * is split above and below it rather than left as one band. The
 * housing's sides keep the bezel (the canvas's 17px shadow ring) inside
 * them, the maker strip is set tighter so it stays one line, the badge
 * drops its vents so the run light beside it has room, and the panels
 * take nearly the whole window.
 */
@media (max-width: 560px) {
  #console { gap: 8px; padding: 8px; }
  #screen-area { place-items: center; }
  #monitor { --housing-x: 24px; }
  #maker { font-size: 6px; letter-spacing: 0.12em; }
  #badge::before,
  #badge::after { display: none; }
  .panel { width: calc(100vw - 16px); max-height: calc(100dvh - 32px); }
  .panel .body { padding: 4px 12px 16px; }
  /*
   * The who-line in one row: the status, then the latest notice, which
   * gives up its room first; the storage line is in the Menu sheet. A
   * status longer than the row still ends in an ellipsis.
   */
  #wholine { gap: 12px; padding: 3px 10px; font-size: 11px; }
  #status { flex: 0 1 auto; max-width: none; }
  #storage { display: none; }
}

/*
 * Any short window, a phone held sideways among them: the console no
 * taller than the window, the commands one row that scrolls sideways
 * (the auto margins centre it while it fits; once it overflows it starts
 * at the left, so every command can be scrolled to), and a lower
 * housing, so the screen keeps as much of the height as it can. The chin
 * drops the maker strip and the vents and sets the badge in a middle
 * column with the run light in its own column after it, so the two
 * never overlap; a housing the chin widens keeps the screen centred.
 */
@media (max-height: 500px) {
  #console { min-height: 0; gap: 6px; padding: 6px 12px; }
  #menu { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; padding: 4px 8px; }
  #menu .group { flex: none; flex-wrap: nowrap; }
  #menu .group:first-child { margin-left: auto; }
  #menu .group:last-of-type { margin-right: auto; }
  #monitor {
    --housing-top: 20px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    column-gap: 12px;
    align-items: center;
  }
  #maker { display: none; }
  #screen { grid-column: 1 / -1; justify-self: center; }
  #badge { grid-column: 2; margin-top: 18px; padding: 4px 0 6px; }
  #badge::before,
  #badge::after { display: none; }
  #run-light { grid-column: 3; justify-self: start; position: static; transform: none; margin-top: 18px; }
}

/* A finger, not a mouse: every command, Close and Type it at least 40px tall. */
@media (pointer: coarse) {
  #menu button,
  #menu .item,
  #advanced button,
  #advanced .item,
  dialog button { padding: 9px 12px; line-height: 20px; }
  .window .label { align-items: center; }
  .window .label a { padding: 9px 12px; line-height: 20px; }
  :is(#help, #demos) .typed button { padding: 9px 10px; line-height: 20px; }
}

/*
 * A phone's command bar: one row of four equal commands, Keys, Demos,
 * Help and Menu, over a band of the console's top kept for it; Pause,
 * which reads the wider Continue while paused, waits in the sheet with the
 * rest. Menu opens the sheet: the same bar drawn as a pop-up window, the
 * other commands two to a row under the first row, which stays where it
 * was, and the storage line the who-line has no room for. The sheet covers
 * the console rather than moving it, so the screen keeps its size; a touch
 * on the shade around it closes it (web/main.ts).
 */
@media (max-width: 560px) {
  #console { position: relative; grid-template-rows: 48px minmax(0, 1fr) auto; }
  #screen-area { grid-row: 2; }
  #wholine { grid-row: 3; }
  #menu {
    position: absolute;
    z-index: 15;
    top: 8px;
    left: 8px;
    right: 8px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    padding: 4px;
  }
  #menu .group { display: contents; }
  #menu button,
  #menu .item {
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    height: 40px;
    padding: 0 4px;
    white-space: nowrap;
  }
  #menu #keys { order: -4; }
  #menu #demos-link { order: -3; }
  #menu #help-link { order: -2; }
  #menu #menu-toggle { display: flex; order: -1; }
  #menu #menu-toggle[aria-expanded="true"] { background: var(--ink); color: var(--paper); }
  #menu .group > :not(#keys, #demos-link, #help-link, #menu-toggle) { display: none; grid-column: span 2; }

  #menu[data-open] {
    top: 6px;
    left: 6px;
    right: 6px;
    background: var(--paper);
    border: 2px solid var(--ink);
    border-radius: 0;
    box-shadow: 5px 5px 0 rgba(20, 20, 20, 0.28), 0 0 0 100vmax rgba(60, 54, 40, 0.3);
  }
  /* A clear layer over the shade and under the commands: a touch on the shade lands on the bar, not on the screen. */
  #menu[data-open]::before {
    content: "";
    position: fixed;
    z-index: -1;
    inset: 0;
  }
  #menu[data-open] .group > :not(#keys, #demos-link, #help-link, #menu-toggle) { display: flex; }
  #menu[data-open] #menu-storage {
    display: block;
    grid-column: 1 / -1;
    margin: 4px 2px 2px;
    font-size: 11px;
    color: #55524a;
  }
}

/* The offer of Pause after the user stayed on a page that asked before closing (web/main.ts): over the screen's top, for a moment. */
#leave-offer {
  position: fixed;
  top: 3rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  padding: 0.5rem 1rem;
}
#leave-offer[hidden] { display: none; }
