/* ============================================================================
   zhuzhbox — core
   A monochrome terminal. Emphasis is never carried by hue: it is carried by
   reverse video (swapping foreground and background), by weight, and by the
   hairline rules that draw the panes. Two themes, one grammar.
   ========================================================================= */

:root {
  color-scheme: dark;

  /* Warm-neutral ink. Not a blue-grey: the whole palette sits on a ~35deg hue
     at very low saturation, so the "black" reads like a photographed screen
     rather than a CSS default. */
  --bg:      #0b0a09;
  --panel:   #131110;
  --panel-2: #1b1917;
  --rule:    #2c2825;
  --rule-2:  #413b35;
  --dim:     #837c71;
  --fg:      #c7c1b7;
  --hi:      #f6f2ea;
  --grid:    #171514;

  /* Character cell. Every vertical rhythm value is a multiple of it, which is
     what makes a grid of proportional boxes still feel like a text screen. */
  --cell: 1.5rem;
  --half: 0.75rem;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", "Roboto Mono",
          Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;

  --t-fast: 90ms;
  --t-med: 180ms;
}

:root[data-theme="light"] {
  color-scheme: light;
  /* Paper terminal: ink on a warm bone stock. */
  --bg:      #e7e3da;
  --panel:   #f1eee7;
  --panel-2: #e0dbd0;
  --rule:    #c6bfb2;
  --rule-2:  #a9a091;
  --dim:     #665f57;
  --fg:      #2f2b27;
  --hi:      #100f0d;
  --grid:    #d9d4c9;
}

:root[data-theme="mocha"] {
  color-scheme: dark;
  /* Same grammar as the two monochrome themes — one hue, reverse video for
     emphasis — just carried on a plum ink instead of a warm neutral one.
     --dim and --fg are picked to clear 4.5:1 against --bg with margin
     (~5.3:1 and higher), matching the two themes above. */
  --bg:      #170f1c;
  --panel:   #1f1526;
  --panel-2: #281b30;
  --rule:    #392a44;
  --rule-2:  #4f3b5c;
  --dim:     #9482a3;
  --fg:      #d9cce2;
  --hi:      #f6eefb;
  --grid:    #1c1322;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 0.9375rem;
  line-height: 1.6;
  font-variant-ligatures: none;
  /* The character-cell grid, at the threshold of visibility. It is the only
     ornament on the page, and it is the one that says "text screen". */
  background-image:
    repeating-linear-gradient(to right,  var(--grid) 0 1px, transparent 1px var(--cell)),
    repeating-linear-gradient(to bottom, var(--grid) 0 1px, transparent 1px var(--cell));
  background-position: center top;
}
body::before {
  /* Fade the grid out toward the middle of the page so it reads as texture at
     the edges rather than as a table. */
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 120% 80% at 50% 40%, var(--bg) 30%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}
body > * { position: relative; z-index: 1; }

h1, h2, h3, h4 { font-weight: 500; margin: 0; letter-spacing: -0.02em; }
p { margin: 0 0 var(--cell); max-width: 68ch; }
p:last-child { margin-bottom: 0; }
ul, ol { margin: 0 0 var(--cell); padding-left: 1.5em; max-width: 68ch; }
li { margin-bottom: 0.35em; }
li::marker { color: var(--dim); }

a { color: var(--hi); text-decoration: none; border-bottom: 1px solid var(--rule-2); }
a:hover { border-bottom-color: var(--hi); }

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

::selection { background: var(--hi); color: var(--bg); }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--hi); color: var(--bg); padding: 0.5rem 1rem; z-index: 100;
  border: 0;
}
.skip:focus { left: 0; }

/* ---- text roles ---------------------------------------------------------- */

.label {
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
}
/* .label is for field names and eyebrows — a word or three. Anything that is
   actually a sentence uses .note, which stays in sentence case: uppercase
   running text at 11px is not readable. */
.note {
  font-size: 0.75rem;
  line-height: 1.55;
  color: var(--dim);
  margin: 0;
}
.dim { color: var(--dim); }
.hot { color: var(--hi); }
/* Anything carrying a figure keeps its case — "4.0 KiB" must never become
   "4.0 KIB", which is not a unit. */
.num { font-variant-numeric: tabular-nums; text-transform: none; }
.nowrap { white-space: nowrap; }

/* Display line. The one piece of type on the site set large. */
.thesis {
  font-size: clamp(1.375rem, 4.2vw, 2.25rem);
  line-height: 1.25;
  letter-spacing: -0.045em;
  color: var(--hi);
  font-weight: 500;
  margin: 0 0 var(--cell);
  max-width: 28ch;
}
.thesis .sep { color: var(--dim); }

/* The cursor. Blinks on a 1.06s square wave, like a real one. */
.caret {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  vertical-align: -0.12em;
  background: var(--hi);
  animation: blink 1.06s steps(1) infinite;
}
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* ---- bars ---------------------------------------------------------------- */

.bar {
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
}
.bar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--cell);
  height: calc(var(--cell) * 3);
  display: flex;
  align-items: center;
  gap: var(--cell);
}

.bar-top {
  position: sticky;
  top: 0;
  z-index: 30;
}

.mark {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--hi);
  border: 0;
  flex: none;
}
/* The lockup SVG (icon + wordmark in one file) carries its own intrinsic
   296×72 size, which an <img> renders at literally with nothing else here
   to constrain it. Tie the height to the bar it sits in (its native size
   already matches this at the desktop --cell) and let width follow the
   aspect ratio; the mobile breakpoint below sets a smaller fixed height,
   since a bar-filling logo is what causes the overflow there. */
.mark-icon { display: block; height: calc(var(--cell) * 3); width: auto; }
.mark:hover { border: 0; }

/* Tabs read as a tmux window list: the active one is reverse video. They
   scroll rather than wrap, but never below a width that still shows one. */
.tabs { display: flex; gap: 1px; flex: 1 1 auto; min-width: 7rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
/* State changes are instant everywhere on this site. A terminal does not fade
   between states, and transitioning a colour that resolves through a custom
   property leaves the computed value stale when only the selector match
   changes — the active tab would keep the inactive tab's ink. */
.tab {
  border: 0;
  color: var(--dim);
  padding: 0.15rem 0.7rem;
  font-size: 0.8125rem;
  white-space: nowrap;
}
.tab:hover { color: var(--fg); border: 0; }
.tab[aria-current="page"] {
  background: var(--hi);
  color: var(--bg);
}

.bar-right { display: flex; align-items: center; gap: 1rem; flex: none; }
/* Pushes the right-hand controls over on a bar that has no tabs (the bundle
   page). Unlike .tabs it may collapse to nothing on a narrow screen. */
.bar-gap { flex: 1 1 auto; min-width: 0; }

/* .tabs' narrow-screen stand-in: a button naming the current page, and a
   small panel anchored under it — enabled only by the mobile breakpoint
   below. Hidden here so it never appears above it. */
.nav-menu { display: none; position: relative; min-width: 0; }
/* max-width lets the button shrink with its flex container instead of
   forcing the bar wider than the screen once a translated page name runs
   long; the label then does the actual truncating. */
.nav-menu-btn { gap: 0.4rem; max-width: 100%; }
#navMenuLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.nav-menu-caret { color: var(--dim); font-size: 0.7em; flex: none; }
.nav-menu-panel {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  min-width: 9rem;
  background: var(--bg);
  border: 1px solid var(--rule-2);
}
.nav-menu-panel[hidden] { display: none; }
.nav-menu-panel .tab {
  display: block;
  padding: 0.6rem 0.85rem;
  text-align: left;
}
.nav-menu-panel .tab + .tab { border-top: 1px solid var(--rule); }

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

.bar-foot {
  position: sticky;
  bottom: 0;
  z-index: 20;
  border-bottom: 0;
  border-top: 1px solid var(--rule);
  font-size: 0.75rem;
}
.bar-foot .bar-inner { height: calc(var(--cell) * 1.6); gap: 1.1rem; }
.keys { display: flex; gap: 1.1rem; flex-wrap: wrap; align-items: center; }
.keyhint { color: var(--dim); display: inline-flex; gap: 0.4rem; align-items: baseline; }

kbd {
  font: inherit;
  font-size: 0.6875rem;
  color: var(--fg);
  border: 1px solid var(--rule-2);
  padding: 0 0.3rem;
  min-width: 1.4em;
  display: inline-block;
  text-align: center;
  line-height: 1.45;
}

/* ---- panes --------------------------------------------------------------- */

/* A pane is an outline on the void with its title notched into the top rule,
   the way a box-drawn ┌─ title ─┐ interrupts the border it sits on. */
.pane {
  position: relative;
  border: 1px solid var(--rule);
  padding: calc(var(--cell) * 0.9) var(--cell) var(--cell);
  min-width: 0;
}
.pane > .pane-t {
  position: absolute;
  top: 0;
  left: 1.1rem;
  transform: translateY(-50%);
  padding: 0 0.55rem;
  background: var(--bg);
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg);
  display: flex;
  gap: 0.6rem;
  align-items: center;
  max-width: calc(100% - 2.2rem);
}
.pane > .pane-t .t-meta { color: var(--dim); letter-spacing: 0.1em; text-transform: none; }
/* A window-titlebar-style action tucked into the pane's own title, pushed to
   the far end. Shares the title's type treatment rather than looking like a
   regular button, so it reads as part of the chrome, not a second CTA. */
.pane-action {
  all: unset;
  margin-left: auto;
  padding-left: 0.5rem;
  color: var(--dim);
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  text-transform: none;
  cursor: pointer;
  flex: none;
}
.pane-action:hover { color: var(--hi); }
.pane-fill { background: var(--panel); }
.pane-flush { padding: 0; }

/* Sub-rule inside a pane: a labelled divider. */
.divide {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: var(--cell) 0 var(--half);
}
.divide::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* ---- controls ------------------------------------------------------------ */

.btn {
  font: inherit;
  font-size: 0.8125rem;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--rule-2);
  padding: 0.3rem 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--fg); color: var(--hi); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* .btn sets its own display, which otherwise beats the [hidden] attribute's
   UA-stylesheet rule (author styles always win over UA ones, tie or not). */
.btn[hidden] { display: none; }
a.btn { border-bottom: 1px solid var(--rule-2); }
a.btn:hover { border-color: var(--fg); }

/* Reverse video is the only "primary" treatment on the site. */
.btn-go {
  background: var(--hi);
  color: var(--bg);
  border-color: var(--hi);
}
.btn-go:hover:not(:disabled) { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.btn-sm { font-size: 0.75rem; padding: 0.15rem 0.55rem; }
.btn-quiet { border-color: transparent; color: var(--dim); }
.btn-quiet:hover:not(:disabled) { border-color: var(--rule-2); }
.btn-x { border-color: var(--rule-2); }
.btn-x:hover:not(:disabled) { background: var(--fg); color: var(--bg); border-color: var(--fg); }

.btn-row { display: flex; gap: var(--half); flex-wrap: wrap; align-items: center; }

.input, .textarea, .select {
  font: inherit;
  font-size: 0.8125rem;
  width: 100%;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--rule);
  padding: 0.4rem 0.6rem;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--fg); outline-offset: 1px; }
.input::placeholder, .textarea::placeholder { color: var(--dim); opacity: 1; }
.textarea { resize: vertical; min-height: calc(var(--cell) * 3); line-height: 1.5; }
.input[readonly] { color: var(--hi); }

.field { display: block; margin-bottom: var(--half); }
.field > .label { display: flex; justify-content: space-between; margin-bottom: 0.3rem; }

/* Segmented switch — the active segment is reverse video, like a selected row
   in a list widget. */
.seg { display: inline-flex; border: 1px solid var(--rule-2); }
.seg button {
  font: inherit;
  font-size: 0.75rem;
  background: transparent;
  color: var(--dim);
  border: 0;
  padding: 0.25rem 0.8rem;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--rule-2); }
.seg button:hover { color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--hi); color: var(--bg); }

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

/* A meter is drawn as discrete cells, not a smooth bar: the fill is a
   repeating gradient so it segments itself at any width. */
.meter {
  --pct: 0%;
  position: relative;
  height: 0.7rem;
  border: 1px solid var(--rule);
  background: var(--panel);
  overflow: hidden;
}
.meter::before {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--pct);
  background:
    repeating-linear-gradient(to right, var(--fg) 0 4px, transparent 4px 6px);
  transition: width var(--t-med) linear;
}
.meter-hot::before { background: repeating-linear-gradient(to right, var(--hi) 0 4px, transparent 4px 6px); }
.meter-row { display: grid; grid-template-columns: 1fr auto; gap: 0.6rem; align-items: center; }

/* ---- code ---------------------------------------------------------------- */

.code {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--rule);
  padding: var(--half) 0.85rem;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.7;
  margin: 0 0 var(--half);
  max-width: none;
  tab-size: 2;
}
.code pre { margin: 0; font: inherit; }
.code .c { color: var(--dim); }
.code .k { color: var(--hi); }
.code-copy {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  opacity: 0;
  background: var(--panel);
  transition: opacity var(--t-fast);
}
.code:hover .code-copy, .code-copy:focus-visible { opacity: 1; }
/* No hover on touch, so the reveal-on-hover trick above never fires there —
   show the button outright rather than hiding a feature nobody can discover. */
@media (hover: none) {
  .code-copy { opacity: 1; }
}

code.tick {
  background: var(--panel-2);
  border: 1px solid var(--rule);
  padding: 0 0.3em;
  font-size: 0.875em;
  /* Set explicitly: most of these sit inside dimmed prose, and inline code
     should read at full strength wherever it lands. */
  color: var(--fg);
}

/* ---- tables -------------------------------------------------------------- */

.table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.table th, .table td {
  text-align: left;
  padding: 0.35rem 0.75rem 0.35rem 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: baseline;
}
.table th {
  font-weight: 400;
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
}
.table tr:last-child td { border-bottom: 0; }
.table td:last-child, .table th:last-child { padding-right: 0; }

/* ---- toasts -------------------------------------------------------------- */

.toasts {
  position: fixed;
  right: var(--cell);
  bottom: calc(var(--cell) * 2.6);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: flex-end;
  pointer-events: none;
}
.toast {
  background: var(--hi);
  color: var(--bg);
  padding: 0.3rem 0.8rem;
  font-size: 0.8125rem;
  max-width: 44ch;
  animation: toast-in var(--t-med) ease-out;
}
.toast-bad { background: var(--fg); }
@keyframes toast-in { from { opacity: 0; transform: translateX(0.5rem); } }

/* ---- modal --------------------------------------------------------------- */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: start center;
  padding: calc(var(--cell) * 2) var(--cell);
  overflow-y: auto;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
}
.modal-root[hidden] { display: none; }
.modal {
  width: min(620px, 100%);
  background: var(--bg);
  border: 1px solid var(--rule-2);
  animation: modal-in var(--t-med) ease-out;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(-0.5rem); } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--cell);
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--rule);
}
.modal-body { padding: var(--cell) 0.85rem; }

/* Tab strip inside a dialog. */
.subtabs { display: flex; gap: 1px; margin-bottom: var(--cell); }
.subtab {
  font: inherit;
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--dim);
  padding: 0.2rem 0.7rem;
  cursor: pointer;
}
.subtab[aria-selected="true"] { background: var(--hi); color: var(--bg); border-color: var(--hi); }

/* Theme picker rows: each swatch shows the target theme's OWN colours (set
   inline as --sw-* per option), independent of whichever theme is active
   while you're looking at the list. */
.theme-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--rule); }
.theme-list li + li { border-top: 1px solid var(--rule); }
.theme-opt {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 0.6rem 0.75rem;
  color: var(--fg);
  font-size: 0.8125rem;
  cursor: pointer;
}
.theme-opt:hover { background: var(--panel); }
.theme-opt[aria-pressed="true"] { background: var(--hi); color: var(--bg); }
.theme-swatch {
  flex: none;
  width: 3rem;
  height: 1.75rem;
  border: 1px solid var(--rule-2);
  background: var(--sw-bg);
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 0 0.4rem;
}
.theme-opt[aria-pressed="true"] .theme-swatch { border-color: var(--bg); }
.theme-swatch i { display: block; height: 2px; background: var(--sw-fg); }
.theme-swatch i:last-child { background: var(--sw-dim); width: 60%; }
.theme-name { flex: 1; text-transform: capitalize; }
.theme-mark { flex: none; font-variant-numeric: normal; opacity: 0.35; }
.theme-opt[aria-pressed="true"] .theme-mark { opacity: 1; }

/* ---- utility ------------------------------------------------------------- */

.stack > * + * { margin-top: var(--cell); }
.stack-sm > * + * { margin-top: var(--half); }
.row { display: flex; gap: var(--half); align-items: center; flex-wrap: wrap; }
.spread { display: flex; gap: var(--cell); align-items: center; justify-content: space-between; }
.mono-url {
  font-size: 0.8125rem;
  color: var(--hi);
  word-break: break-all;
}
.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .caret { opacity: 1; }
}

@media (max-width: 720px) {
  :root { --cell: 1.25rem; --half: 0.625rem; }
  body { font-size: 0.875rem; }
  .bar-inner { padding: 0 var(--cell); gap: var(--half); }
  .mark-icon { height: 1.15rem; }
  /* No keyboard to advertise, and the quota reading has a home in the session
     pane — both would otherwise squeeze the tabs off the bar. */
  .bar-foot { display: none; }
  .quota-chip { display: none; }
  /* Same reasoning, wherever a hotkey is named inline instead of in the foot
     bar — there is nothing to press on a touchscreen. */
  .kbd-hint { display: none; }
  /* The tab strip still runs off the edge of a phone no matter how it's
     dressed — swap it for the one-button page menu instead of fading it. */
  .tabs { display: none; }
  .nav-menu { display: block; flex: 1 1 auto; min-width: 0; }
  .toasts { right: var(--half); left: var(--half); bottom: var(--half); align-items: stretch; }
  .toast { max-width: none; }
  /* Pinned chrome costs more on a short phone screen than it saves — let the
     top bar scroll away with the page instead of eating the viewport for
     good, the same trade already made for the (fully hidden) foot bar. */
  .bar-top { position: static; }

  /* Touch targets, widened without touching type size: these are the controls
     tapped constantly on a phone (nav, dismiss, small toolbar buttons), and
     their desktop hit area is sized for a mouse pointer. */
  .tab { padding: 0.5rem 0.7rem; }
  .btn-sm { padding: 0.4rem 0.7rem; }
  .qi-drop { padding: 0.4rem 0.5rem; margin: -0.4rem -0.5rem; }
  .pane-action { padding: 0.4rem 0; margin: -0.4rem 0; }
  .seg button { padding: 0.45rem 0.8rem; }
}
