/* © 2026 MEK.txt. All rights reserved. Part of the MEK design system; not licensed for reuse. */
/* MEK design system · part: TUI
   Terminal UIs in the page's own type: boxes, tables, bars and sparklines drawn with the box drawing, block and
   shade glyphs every MEK.txt face has (U+2500–259F, ■ □ ▪ ▫). Each glyph is one mono cell wide and exactly as tall
   as the line at line-height: normal, so lines join cell to cell and row to row with no gaps.
   <pre class="tui">…</pre> for a block, <span class="tui">…</span> inside text. js/tui.js draws boxes, tables,
   bars and sparklines from data-tui attributes, and the controls' brackets and marks (see Controls);
   without it the text shows as written.
   Opt-in: link it after mek.css. In the mek.parts layer (ordered by mek.css), so a project's own CSS wins over it. */

@layer mek.parts {

/* ---------- The grid ----------
   line-height: normal is the point: it's the height the glyphs were drawn to fill. No letter-spacing, kerning or
   ligatures, so every character keeps its cell. Size: --tui-size, on the face's grid only, so every cell is whole
   pixels and glyphs join with no seam: 12 (Dosage Mono's 7×15 cell) by default, or 24 (.tui-lg, 14×30). A TUI is a
   drawing in cells, not text to read, so the system's smallest text size (14) doesn't apply (MEK, 2026-11-13): at 14
   a cell is 8.17px and seams show between blocks. Inline in running text too: never the text's size. */
.tui {
  --tui-size: 12px;
  margin: 0; font-family: var(--font-mono); font-size: var(--tui-size); line-height: normal; white-space: pre;
  letter-spacing: 0; word-spacing: 0; font-kerning: none; font-variant-ligatures: none; font-feature-settings: "kern" 0, "liga" 0, "calt" 0;
  color: var(--text); -moz-osx-font-smoothing: auto;
}
pre.tui { overflow-x: auto; }
.tui-lg { --tui-size: 24px; }   /* a 14×30 cell: for a TUI people use (menus, controls), or a page that wants it big */
/* MEKMODE's grid is 10 (its cell 5 wide): 10, and 20 for the large size. */
[data-font="mekmode"] .tui { --tui-size: 10px; }
[data-font="mekmode"] .tui-lg { --tui-size: 20px; }

/* ---------- Ink ----------
   Spans inside a .tui. Drawn edges (js/tui.js) are .edge, in --tui-edge: the text's own ink unless set. */
.tui .edge { color: var(--tui-edge, inherit); }
.tui .hi { color: var(--accent); }
.tui .strong { color: var(--text-strong); }
.tui .dim { color: var(--text-muted); }
.tui .bad { color: var(--bad); }   /* a text diagram's failing way (mekTui.canvas) */
.tui .inv { color: var(--bg); background: var(--text-strong); }   /* fills the whole cell: the line box is the cell */
.tui .inv.hi { color: var(--bg); background: var(--accent); }
.tui .cursor::after { content: "█"; }   /* the core blinking cursor, as a block cell */

/* ---------- Controls ----------
   Real buttons, checkboxes, radios and inputs, drawn in cells. js/tui.js writes their brackets and marks as text
   ([ OK ], [x], (*), [Ash____]) so boxes measure them and nothing changes width. Each one is a run of whole cells.
   Rest: brackets in --tui-edge, label in the text ink. Hover dissolves the cells to inverse video through the
   system's 2×2 dither (the text-mode ░▒▓█), the ink flipping at the halfway frame. Focus: inverse, instant.
   Pressed: inverse in the accent. Chosen (.on, checked): a > marker or [x], strong ink. Disabled: --line, no hover. */
:where(.tui) :is(.tui-btn, .tui-menu > button, .tui-check, .tui-keybar > button, .pick-btn, .pick-menu button) {
  --dz: 0; transition: --dz var(--dur-dissolve) var(--ease-dissolve);
  --cell: transparent; --cell-to: var(--text-strong); --ink: var(--text); --ink-to: var(--bg);
  --dz-q1: clamp(0%, (var(--dz) - .2) * 10000%, 25%); --dz-q3: clamp(0%, (var(--dz) - .45) * 10000%, 25%);
  --dz-q2: clamp(0%, (var(--dz) - .7) * 10000%, 25%); --dz-q4: clamp(0%, (var(--dz) - .95) * 10000%, 25%);
  background: conic-gradient(
    var(--cell-to) 0 var(--dz-q1), var(--cell) 0 25%,
    var(--cell-to) 0 calc(25% + var(--dz-q2)), var(--cell) 0 50%,
    var(--cell-to) 0 calc(50% + var(--dz-q3)), var(--cell) 0 75%,
    var(--cell-to) 0 calc(75% + var(--dz-q4)), var(--cell) 0) 0 0 / 2px 2px;
  color: color-mix(in srgb, var(--ink-to) calc(clamp(0, (var(--dz) - .45) * 10000, 1) * 100%), var(--ink));
  font: inherit; line-height: inherit; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: left;
  -webkit-font-smoothing: inherit;
}
.tui :is(.tui-btn, .tui-menu > button, .tui-check, .tui-keybar > button, .pick-btn, .pick-menu button):is(:hover, :has(input:hover)):not(:disabled, [aria-disabled="true"], :has(input:disabled)) { --dz: 1; }
.tui :is(.tui-btn, .tui-menu > button, .tui-keybar > button, .pick-btn):focus-visible,
.tui :is(.tui-menu > button, .pick-menu button):focus,
.tui .tui-check:has(input:focus-visible) { --dz: 1; transition-duration: 0s; outline: none; }
.tui :is(.tui-btn, .tui-menu > button, .tui-keybar > button):is(:active, .pushed):not(:disabled) { --cell: var(--accent); --cell-to: var(--accent); --ink: var(--bg); --ink-to: var(--bg); }
.tui :is(.tui-btn, .tui-menu > button, .tui-keybar > button):disabled,
.tui .tui-check:has(input:disabled) { --ink: var(--line); --ink-to: var(--line); cursor: not-allowed; }
.tui [data-tui-mark] { color: var(--tui-edge, inherit); }   /* brackets and marks written by js/tui.js */
.tui :is(:hover, :focus, :focus-visible, :has(input:focus-visible)) > [data-tui-mark] { color: inherit; }

/* Button: [ OK ]. .primary: accent label and brackets, dissolving to inverse in the accent. */
.tui .tui-btn.primary { --ink: var(--accent); --cell-to: var(--accent); }
.tui .tui-btn.primary > [data-tui-mark] { color: inherit; }
/* A key (data-key) shows as its letter in the label, in the quiet accent (--key, as every key hint), so a menu of ten
   rows doesn't carry ten accent marks; on the chosen row (.on) it's --key-on. The [Y] before it hides. The bright
   accent stays for what's chosen: a menu's >. */
.tui .tui-hot { color: var(--key); }
.tui .on .tui-hot { color: var(--key-on); }
.tui .tui-btn.primary .tui-hot { color: var(--text-strong); }   /* the label is already the accent */
/* On the inverse cell (hover, focus, pressed) every ink inside a control follows the cell's: a key, and .dim, .bad
   and .strong, which would otherwise lose their contrast on the light cell. */
.tui :is(.tui-btn, .tui-menu > button, .tui-keybar > button, .tui-check, .pick-btn, .pick-menu button):is(:hover, :focus-visible, :focus, :active, :has(input:focus-visible)) :is(.tui-hot, .dim, .bad, .strong, .hi, kbd) { color: inherit; }
.tui .has-hot > kbd.key { display: none; }

/* Checkbox [x] and radio (*): <label class="tui-check"><input type="checkbox"> Sound</label>. The input is kept for
   the keyboard and screen readers, out of sight; the mark is text. Checked: the mark in --key-on (800), the quiet
   colour a chosen row's key takes, so a screen keeps one bright thing (board t67); the bright accent stays for a
   menu's > and a pressed control. */
.tui .tui-check { display: inline; }
.tui .tui-check > input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.tui .tui-check:not(:has(input:checked)) .tui-x { visibility: hidden; }   /* the cell stays: [ ] */
.tui .tui-check:has(input:checked) > [data-tui-mark] { color: var(--key-on); }
.tui .tui-check:has(input:checked):is(:hover, :has(input:focus-visible)) > [data-tui-mark] { color: inherit; }

/* Menu: one command a row, a selection bar across the whole row. role="menu", arrows move (js/tui.js).
   The current row (.on: where the bar was last) keeps a > in the accent; the bar is focus. */
.tui .tui-menu { display: inline-grid; vertical-align: top; }
.tui .tui-menu > button { display: block; width: 100%; }
.tui .tui-menu > button > [data-tui-mark] { color: var(--accent); visibility: hidden; }
.tui .tui-menu > button:is(.on, :focus) > [data-tui-mark] { visibility: visible; }
.tui .tui-menu > button:focus > [data-tui-mark] { color: inherit; }

/* Field: Name [Ash_______]. A real input, one cell per character (size="12"), each empty cell an underscore, a
   block caret in the accent. Focus: the brackets turn accent, instant. */
.tui .tui-field { display: inline; }
.tui .tui-field input { font: inherit; line-height: inherit; color: var(--text-strong); border: 0; padding: 0; margin: 0;
  width: calc(var(--cells, 12) * 1ch); outline: none; caret-color: var(--accent); caret-shape: block; -webkit-font-smoothing: inherit;
  background: linear-gradient(90deg, var(--text-muted) calc(100% - 1px), transparent 0) 0 calc(100% - 3px) / 1ch 1px repeat-x; }
.tui .tui-field input::placeholder { color: var(--text-muted); opacity: 1; }
.tui .tui-field input:placeholder-shown:not(:focus) { mask: var(--dim-mask); }   /* B/W greys the placeholder (DESIGN.md "Faithful themes") */
.tui .tui-field:has(input:focus) > [data-tui-mark] { color: var(--accent); }
.tui .tui-field:has(input:disabled) { color: var(--line); }

/* Key bar: the commands of a screen along its foot, each key an inverse cell: <nav class="tui-keybar"
   data-key-hint="bare"> of <button data-key="h">Help</button>. The keys come from js/mek.js (data-key). */
.tui .tui-keybar { display: inline-flex; flex-wrap: wrap; gap: 0 1ch; }
.tui .tui-keybar kbd.key { color: var(--bg); background: var(--text-muted); margin-right: 1ch; padding: 0 1ch; }
.tui .tui-keybar > button:hover kbd.key, .tui .tui-keybar > button:focus-visible kbd.key { background: var(--bg); color: var(--text-strong); }
.tui .tui-keybar > button:disabled kbd.key { background: var(--line); }

/* Pick: a dropdown in cells (board t82). The core Pick's markup and behaviour (js/mek.js: open, arrows, number keys,
   Esc, mek:pick, turning toward the room), drawn as text: Theme [Miner     v]. The trigger's value is as wide as the
   longest choice (js/tui.js sets --cells), so picking never changes its width; v turns ^ while the list is open, and
   the brackets take the strong ink (one bright thing a screen: the current choice's >). The list is a double-line box under the value, a row a choice: ║> Miner      [1]║, its
   bar across the row inside the edges, the current choice's > in the accent (as a .tui-menu's), its key [1] in the
   quiet accent. A gap (<hr>) is a ╟──╢ rule. No px-box, no lift, no pop: it's there at once, as in a terminal.
   Markup: <span class="pick"><button class="pick-btn" type="button"><span data-pick-value>Miner</span></button>
   <div class="pick-menu" hidden><button class="on">Miner</button>…</div></span>, inside a .tui. */
.tui .pick { vertical-align: top; }
pre.tui:has(.pick) { overflow: visible; }   /* its list hangs out of the block: so a pre.tui with a Pick must fit its lines (at 390px too); else put the Pick in an inline .tui */
.tui .pick-btn { display: inline; font: inherit; line-height: inherit; white-space: pre; --ink: var(--text); --ink-to: var(--bg); }
.tui .pick-btn::after { content: none; }
.tui .pick-btn [data-pick-value] { display: inline-block; vertical-align: top; width: calc(var(--cells, 12) * 1ch); overflow: hidden; white-space: pre; }
.tui .pick-btn .tui-caret::after { content: "v"; }
.tui .pick-btn[aria-expanded="true"] .tui-caret::after { content: "^"; }
.tui .pick-btn[aria-expanded="true"]:not(:hover, :focus-visible) > [data-tui-mark] { color: var(--text-strong); }
.tui .pick-menu { top: 100%; left: -2ch; min-width: 0; padding: 0; gap: 0; background: var(--bg); animation: none;
  font: inherit; line-height: inherit; white-space: pre; }
.tui .pick-menu:is(.end, .to-end) { left: auto; right: 0; }
.tui .pick-menu.to-top { top: auto; bottom: 100%; }
/* An edge's run of ═ is out of the flow, so the rows alone set the list's width, and it's cut to it in whole cells. */
.tui .pick-edge { position: relative; display: flex; justify-content: space-between; color: var(--tui-edge, inherit); }
.tui .pick-edge > .tui-run { position: absolute; inset: 0 1ch; overflow: hidden; }
.tui .pick-menu button { display: flex; align-items: baseline; gap: 0; padding: 0 1ch; border: 0; font: inherit; line-height: inherit;
  white-space: pre; background-clip: content-box; mask: none; --ink: var(--text); --ink-to: var(--bg); }
.tui .pick-menu button::before, .tui .pick-menu button::after { content: "║"; position: absolute; top: 0; width: 1ch;
  font: inherit; color: var(--tui-edge, var(--text)); clip-path: none; transition: none; }
.tui .pick-menu button::before { left: 0; }
.tui .pick-menu button::after { right: 0; }
.tui .pick-menu .pick-label { padding: 0; translate: none; transition: none; }
.tui .pick-menu .pick-label::before { content: "> "; visibility: hidden; }
.tui .pick-menu button:is(.on, [aria-selected="true"]) .pick-label::before { visibility: visible; color: var(--accent); }
.tui .pick-menu button:is(:hover, :focus):not(:disabled, [aria-disabled="true"]) .pick-label::before { visibility: visible; color: inherit; }
.tui .pick-menu kbd { font: inherit; line-height: inherit; white-space: pre; color: var(--key); }
.tui .pick-menu kbd::before { content: " "; }
.tui .pick-menu button:is(.on, [aria-selected="true"]) { --ink: var(--text-strong); }
.tui .pick-menu button:is(.on, [aria-selected="true"]) kbd { color: var(--key-on); }
.tui .pick-menu button:is(:disabled, [aria-disabled="true"]) { --ink: var(--line); --ink-to: var(--line); }
.tui .pick-menu button:is(:disabled, [aria-disabled="true"]) kbd { color: var(--line); }
.tui .pick-menu button.danger:is(:hover, :focus) { --cell-to: var(--bad); }
.tui .pick-menu > hr { position: relative; display: flex; justify-content: flex-end; height: auto; margin: 0; border: 0; color: var(--tui-edge, inherit); }
.tui .pick-menu > hr::before { position: absolute; inset: 0 1ch 0 0; content: "╟────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"; overflow: hidden; }
.tui .pick-menu > hr::after { content: "╢"; }

} /* @layer mek.parts */
