/* FeLeeCa app: phone first (iPhone in Bluefy, then Edge on Windows), dark and light, one column, targets of 44 px or
   more, nothing that depends on hover. No web fonts and nothing fetched: icons are inline SVG (ui/icons.js) or the
   mask images of section 1. The design system is DESIGN.md (next to this file): read it before adding a screen. */

/* ==== 1. Tokens ==================================================================================================== */
/* One theme hue (--hue) builds the accent and tints every neutral. The values are OKLCH; the hex lines before them
   are the same colours for engines without oklch() (they follow the default hue only). Contrast: DESIGN.md. */
:root {
  color-scheme: light dark;
  --hue: 240;                     /* "steel": change this one number to re-tint the whole app (212 cyan-teal and 128 moss were tried) */

  /* light, sRGB fallback */
  --bg: #f1f4f6; --sunk: #e7ecef; --surface: #f8fafc; --surface-2: #e3e9ed; --surface-3: #d7dde2;
  --line: #d3d8dc; --line-strong: #7b858b;
  --fg: #1b2328; --fg-2: #505960; --fg-3: #7a8187;
  --accent: #2f6081; --accent-fill: #2f6081; --on-accent: #f8fafd; --accent-soft: #d8e9f6; --accent-line: #658ba7;
  --ok: #2c6d3e; --ok-soft: #daf1dd; --warn: #85581b; --warn-soft: #f9ebcf;
  --bad: #a43b35; --bad-soft: #fde7e4; --bad-fill: #af3d36; --on-bad: #fdf9f9;
  --scrim: rgb(27 35 40 / .4);

  /* type: system fonts only (DESIGN.md, "Type") */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "PingFang SC", "Hiragino Sans",
    "Microsoft YaHei UI", "Yu Gothic UI", "Noto Sans CJK SC", "Noto Sans CJK JP", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, "Cascadia Mono", Consolas, "Liberation Mono",
    "DejaVu Sans Mono", monospace;
  --fs-xs: .75rem;       /* 12: tab labels, times, tags */
  --fs-sm: .875rem;      /* 14: hints, notes, secondary lines, hex */
  --fs-md: 1.0625rem;    /* 17: body, buttons, fields */
  --fs-lg: 1.25rem;      /* 20: section headings, dialog titles */
  --fs-xl: 1.5rem;       /* 24: the screen's title */

  /* spacing (4 px steps), radius, sizes */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r1: 4px; --r2: 8px; --r3: 12px;
  --tap: 44px; --control: 48px; --icon: 20px; --tabs-h: 60px; --strip-h: 52px; --measure: 40rem;
  --gutter: 16px;
  --fs-input: max(16px, var(--fs-md));   /* text inputs, textareas, selects: NEVER below 16px in any size (iOS WebKit zooms the page on focus below that) */
  --fs-log: 13px;                        /* console log and quick buttons */
  --big: 52px; --row-h: 60px; --row-h-sm: 56px;   /* big button; a list row; a smaller row (blocks, type options) */
  --pad-y: 10px; --pad-x: 12px;          /* button and field padding */

  /* motion (DESIGN.md, "Motion"): only transform and opacity move */
  --t-fast: 120ms; --t-base: 180ms; --t-slow: 240ms;
  --ease-out: cubic-bezier(.2, .8, .2, 1); --ease-in: cubic-bezier(.4, 0, 1, 1);

  accent-color: var(--accent-fill);

  /* icons as masks, for notes, messages and chevrons (the same Lucide drawings as ui/icons.js; licence there) */
  --icon-info: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12a10 10 0 1 0 20 0a10 10 0 1 0 -20 0'/%3E%3Cpath d='M12 16v-4'/%3E%3Cpath d='M12 8h.01'/%3E%3C/svg%3E");
  --icon-warn: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3E%3Cpath d='M12 9v4'/%3E%3Cpath d='M12 17h.01'/%3E%3C/svg%3E");
  --icon-error: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12a10 10 0 1 0 20 0a10 10 0 1 0 -20 0'/%3E%3Cpath d='M12 8L12 12'/%3E%3Cpath d='M12 16L12.01 16'/%3E%3C/svg%3E");
  --icon-ok: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 12a10 10 0 1 0 20 0a10 10 0 1 0 -20 0'/%3E%3Cpath d='m16 9-5.5 5.5L8 12'/%3E%3C/svg%3E");
  --icon-lock: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 11h14a2 2 0 0 1 2 2v7a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-7a2 2 0 0 1 2 -2Z'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E");
  --icon-copy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 8h10a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2Z'/%3E%3Cpath d='M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2'/%3E%3C/svg%3E");
  --icon-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E");
  --icon-card-nfc: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 10h9a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2Z'/%3E%3Cpath d='M6 16h3'/%3E%3Cpath d='M15 6.5a3.5 3.5 0 0 1 3.5 3.5'/%3E%3Cpath d='M15 3a7 7 0 0 1 7 7'/%3E%3C/svg%3E");
}
@supports (color: oklch(0% 0 0)) {
  :root {
    --bg: oklch(96.5% .005 var(--hue)); --sunk: oklch(94% .007 var(--hue)); --surface: oklch(98.5% .003 var(--hue));
    --surface-2: oklch(93% .008 var(--hue)); --surface-3: oklch(89.5% .01 var(--hue));
    --line: oklch(88% .008 var(--hue)); --line-strong: oklch(61% .015 var(--hue));
    --fg: oklch(25% .015 var(--hue)); --fg-2: oklch(46% .016 var(--hue)); --fg-3: oklch(60% .013 var(--hue));
    --accent: oklch(47% .075 var(--hue)); --accent-fill: oklch(47% .075 var(--hue)); --on-accent: oklch(98.5% .004 var(--hue));
    --accent-soft: oklch(92.5% .025 var(--hue)); --accent-line: oklch(62% .06 var(--hue));
    --ok: oklch(48% .1 150); --ok-soft: oklch(93.5% .035 150); --warn: oklch(50% .095 70); --warn-soft: oklch(94.5% .04 85);
    --bad: oklch(50% .14 27); --bad-soft: oklch(94.5% .025 27); --bad-fill: oklch(52% .15 27); --on-bad: oklch(98.5% .004 27);
    --scrim: oklch(25% .015 var(--hue) / .4);
  }
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1216; --sunk: #080c0f; --surface: #141a1f; --surface-2: #1b2328; --surface-3: #262f36;
    --line: #282f34; --line-strong: #616a71;
    --fg: #e4e9ec; --fg-2: #a7afb5; --fg-3: #7a8187;
    --accent: #91c5ea; --accent-fill: #3c6582; --on-accent: #f2f6f9; --accent-soft: #1d303e; --accent-line: #597f9b;
    --ok: #89d298; --ok-soft: #1c2e20; --warn: #efc37e; --warn-soft: #352917;
    --bad: #f49287; --bad-soft: #3c201d; --bad-fill: #af4d45; --on-bad: #faf3f2;
    --scrim: rgb(5 7 8 / .66);
  }
  @supports (color: oklch(0% 0 0)) {
    :root {
      --bg: oklch(18% .011 var(--hue)); --sunk: oklch(15% .01 var(--hue)); --surface: oklch(21.5% .013 var(--hue));
      --surface-2: oklch(25% .015 var(--hue)); --surface-3: oklch(30% .017 var(--hue));
      --line: oklch(30% .013 var(--hue)); --line-strong: oklch(52% .016 var(--hue));
      --fg: oklch(93% .007 var(--hue)); --fg-2: oklch(75% .013 var(--hue)); --fg-3: oklch(60% .013 var(--hue));
      --accent: oklch(80% .075 var(--hue)); --accent-fill: oklch(49% .065 var(--hue)); --on-accent: oklch(97% .006 var(--hue));
      --accent-soft: oklch(30% .035 var(--hue)); --accent-line: oklch(58% .06 var(--hue));
      --ok: oklch(80% .11 150); --ok-soft: oklch(28% .035 150); --warn: oklch(84% .1 78); --warn-soft: oklch(29% .035 78);
      --bad: oklch(76% .12 27); --bad-soft: oklch(28% .045 27); --bad-fill: oklch(54.5% .13 27); --on-bad: oklch(97% .008 27);
      --scrim: oklch(10% .01 var(--hue) / .66);
    }
  }
}
/* ---- Size setting (Settings, "Size"; DESIGN.md, "Size"): <html data-size="compact|large">; Standard has no attribute and is
   the values above. Same tokens, redefined: type about 88 % (compact) or 113 % (large), spacing and control heights with it.
   Floors in Compact: a tap target stays at 40 px or more (the tab bar 52), and --fs-input never goes below 16px (see above). ---- */
:root[data-size="compact"] {
  --fs-xs: .6875rem; --fs-sm: .78125rem; --fs-md: .9375rem; --fs-lg: 1.0625rem; --fs-xl: 1.3125rem;   /* 11 12.5 15 17 21 */
  --s1: 3px; --s2: 7px; --s3: 10px; --s4: 14px; --s5: 21px; --s6: 28px; --s7: 42px;
  --r1: 3px; --r2: 7px; --r3: 10px;
  --tap: 40px; --control: 42px; --icon: 17px; --tabs-h: 52px; --strip-h: 45px; --gutter: 14px;
  --fs-log: 11.5px; --big: 46px; --row-h: 52px; --row-h-sm: 49px; --pad-y: 8px; --pad-x: 10px;
}
:root[data-size="large"] {
  --fs-xs: .84rem; --fs-sm: 1rem; --fs-md: 1.2rem; --fs-lg: 1.4rem; --fs-xl: 1.7rem;   /* 13.4 16 19.2 22.4 27.2 */
  --s1: 5px; --s2: 9px; --s3: 14px; --s4: 18px; --s5: 27px; --s6: 36px; --s7: 54px;
  --r1: 5px; --r2: 9px; --r3: 14px;
  --tap: 50px; --control: 54px; --icon: 23px; --tabs-h: 68px; --strip-h: 59px; --gutter: 18px;
  --fs-log: 15px; --big: 59px; --row-h: 68px; --row-h-sm: 63px; --pad-y: 12px; --pad-x: 14px;
}
/* The CJK fonts of the page's language first (Han characters are drawn differently in Chinese and Japanese). */
:root:lang(ja) {
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Yu Gothic UI", Meiryo, "Noto Sans CJK JP", sans-serif;
}
:root:lang(zh-Hans) {
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei UI",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

/* ==== 2. Base ====================================================================================================== */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 400 var(--fs-md)/1.5 var(--font-ui);
  overflow-x: hidden; overscroll-behavior-y: none;
}
:root:lang(ja) body, :root:lang(zh-Hans) body { line-height: 1.6; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
h1 {
  margin: var(--s5) 0 var(--s3); font-size: var(--fs-xl); font-weight: 650; line-height: 1.25; letter-spacing: -.01em;
  text-wrap: balance;
}
h2 { margin: var(--s5) 0 var(--s2); font-size: var(--fs-lg); font-weight: 600; line-height: 1.3; text-wrap: balance; }
:root:lang(ja) h1, :root:lang(zh-Hans) h1 { letter-spacing: 0; }
p { margin: var(--s2) 0; text-wrap: pretty; }
.muted { color: var(--fg-2); }
.small { font-size: var(--fs-sm); line-height: 1.45; }
.lead { font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); color: var(--fg); }

/* Icons (ui/icons.js): one size, the stroke of the drawing, the colour of the text next to them. */
svg.i {
  flex: none; width: var(--icon); height: var(--icon); fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
/* A mask icon: background is the colour, the mask the drawing. forced-color-adjust keeps it in Windows contrast themes. */
.note::before, .msg.bad::before, .field-err::before, .dlg-items li::before, .note-item::before {
  content: ""; position: absolute; width: calc(var(--icon) - 2px); height: calc(var(--icon) - 2px); background: currentColor;
  -webkit-mask: var(--icon-info) center / contain no-repeat; mask: var(--icon-info) center / contain no-repeat;
  forced-color-adjust: none;
}

/* Hex: monospace, figures of one width, a slashed zero, a little air between the four-byte groups. */
.hex, .hex-line, .mono, pre.connlog, #out, #line, .console-tab .quick button, #histPanel button {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums slashed-zero;
}
.hex { display: block; font-size: var(--fs-sm); line-height: 1.6; letter-spacing: .02em; word-spacing: .25em; white-space: normal; overflow-wrap: anywhere; }
.hex .z { color: var(--fg-2); }                                      /* zero bytes step back */
.hex .chg { border-radius: 3px; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.hex-line { margin: var(--s1) 0; font-size: var(--fs-sm); line-height: 1.6; overflow-wrap: anywhere; }

/* ---- buttons: one primary per view (DESIGN.md, "Buttons"). A press changes the fill over 120 ms; nothing scales, so a
   pressed control keeps its size and place. ---- */
button, .ghost-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--control); padding: var(--pad-y) var(--pad-x); border: 1px solid var(--line); border-radius: var(--r2);
  background: var(--surface-2); color: var(--fg); font-weight: 500; line-height: 1.25; text-align: center; text-wrap: balance;
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: background-color var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
button:active:not(:disabled) { background: var(--surface-3); }
/* Rows that are buttons (a list entry, a sector, a block, a switch) wrap like text; only labels are balanced. */
button.entry-main, button.entry-code, button.entry-id, button.entry-fake, button.sector-head, button.blk-main, button.switch, #histPanel button { text-wrap: wrap; }
button:disabled { opacity: .42; cursor: default; }
button.primary, .ghost-btn.primary { background: var(--accent-fill); color: var(--on-accent); border-color: transparent; font-weight: 600; }
button.danger, .ghost-btn.danger { background: var(--bad-fill); color: var(--on-bad); border-color: transparent; font-weight: 600; }
button.primary:active:not(:disabled), button.danger:active:not(:disabled) { box-shadow: inset 0 0 0 100vmax rgb(0 0 0 / .14); }
button.danger-outline { background: transparent; color: var(--bad); border-color: var(--bad); }
@supports (color: color-mix(in oklab, red, blue)) {
  button.danger-outline { border-color: color-mix(in oklab, var(--bad) 50%, transparent); }
}
button.danger-outline:active:not(:disabled) { background: var(--bad-soft); }
@media (hover: hover) {
  button:hover:not(:disabled) { background: var(--surface-3); }
  button.primary:hover:not(:disabled), button.danger:hover:not(:disabled) { box-shadow: inset 0 0 0 100vmax rgb(255 255 255 / .08); }
  button.danger-outline:hover:not(:disabled) { background: var(--bad-soft); }
}
button.big { display: flex; width: 100%; min-height: var(--big); margin: var(--s3) 0; font-size: var(--fs-md); font-weight: 600; }
button.small { min-height: var(--tap); padding: 6px 12px; font-size: var(--fs-sm); }
button.linkish {
  min-height: var(--tap); padding: 8px 0; border: 0; background: none; color: var(--accent); font-weight: 500;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
}
button.linkish:active:not(:disabled), button.linkish:hover:not(:disabled) { background: none; }
.row { display: flex; flex-wrap: wrap; gap: var(--s2); }
.actions { margin-top: var(--s3); }
.actions > button { flex: 1 1 9em; }

/* ---- fields ---- */
.field { margin: var(--s4) 0; }
.field > label, .field-title { display: block; margin-bottom: 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--fg); }
input[type="text"], select, textarea.mono {
  width: 100%; min-width: 0; min-height: var(--control); padding: var(--pad-y) var(--pad-x); border: 1px solid var(--line-strong);
  border-radius: var(--r2); background: var(--surface); color: var(--fg); font-size: var(--fs-input);
}
/* The device token (Settings, Server): a password field, the same as a text field. */
input[type="password"] {
  width: 100%; min-width: 0; min-height: var(--control); padding: var(--pad-y) var(--pad-x); border: 1px solid var(--line-strong);
  border-radius: var(--r2); background: var(--surface); color: var(--fg); font-size: var(--fs-input);
}
/* 16 px or more in every size (Standard, Compact, Large): iOS does not zoom into the field; a 32-digit block fits a 390 px phone. */
input.mono, textarea.mono { font-size: 16px; }
textarea.mono { display: block; min-height: 64px; line-height: 1.5; resize: vertical; }
input[type="text"]:focus, input[type="password"]:focus, select:focus, textarea:focus { border-color: var(--accent-fill); }
input[type="text"]:focus-visible, input[type="password"]:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }
::placeholder { color: var(--fg-2); opacity: 1; }
.with-buttons { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: stretch; }
.with-buttons input { flex: 1 1 13em; }
.with-buttons button { flex: none; min-height: var(--control); min-width: var(--control); padding: 6px 12px; }
.field-err { position: relative; margin: 6px 0 0; padding-left: calc(var(--icon) + 4px); color: var(--bad); font-size: var(--fs-sm); line-height: 1.45; }
.field-err::before { left: 0; top: 1px; -webkit-mask-image: var(--icon-error); mask-image: var(--icon-error); }
label.check { display: flex; align-items: center; gap: var(--s3); min-height: var(--control); margin: var(--s2) 0; }
label.check input { flex: none; width: 22px; height: 22px; margin: 0; }

/* A list of options (radio buttons): one grouped box, hairlines between the rows, the chosen row tinted. */
.type-list {
  display: flex; flex-direction: column; margin: var(--s2) 0 var(--s4); border: 1px solid var(--line); border-radius: var(--r3);
  background: var(--surface); overflow: hidden;
}
.type-opt { display: flex; align-items: flex-start; gap: var(--s3); min-height: var(--row-h-sm); padding: var(--s3) 14px; cursor: pointer; }
.type-opt + .type-opt { border-top: 1px solid var(--line); }
.type-opt input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; }
.type-opt:has(input:checked) { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.type-opt.disabled { opacity: .55; cursor: default; }
.type-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.type-text b { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 600; }
.type-text b .i { color: var(--fg-2); }
.type-text .why { color: var(--warn); font-size: var(--fs-sm); }

/* ---- notes, messages, banners: an icon and the words say the level; colour only repeats it ---- */
.note {
  position: relative; margin: var(--s3) 0; padding: 10px 12px 10px 40px; border-radius: var(--r2);
  background: var(--surface); color: var(--fg); font-size: var(--fs-sm); line-height: 1.45; overflow-wrap: anywhere;
}
.note::before { left: 12px; top: 11px; color: var(--accent); }
.note.warn { background: var(--warn-soft); }
.note.warn::before { color: var(--warn); -webkit-mask-image: var(--icon-warn); mask-image: var(--icon-warn); }
.msg {
  position: relative; margin: var(--s3) 0; padding: 10px 12px; border-left: 3px solid var(--accent-line); border-radius: var(--r2);
  background: var(--surface-2); overflow-wrap: anywhere;
}
.msg.bad { padding-left: 40px; border-left-color: var(--bad); background: var(--bad-soft); }
.msg.bad::before { left: 12px; top: 12px; color: var(--bad); -webkit-mask-image: var(--icon-error); mask-image: var(--icon-error); }
/* The save status of an image (ui/savestate.js, protocol §5 "Every change is saved"): one line, the icon's shape and the word say
   it (ok circle Saved, the disk Saving..., the triangle Not in library, the alert Not saved); colour only repeats it. */
.save-box { margin: var(--s3) 0; }
.save-status { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2); min-height: 36px; font-size: var(--fs-sm); }
.save-status .save-ico { display: inline-flex; color: var(--fg-2); }
.save-status[data-state="saved"] .save-ico { color: var(--ok); }
.save-status[data-state="unkept"] .save-ico { color: var(--warn); }
.save-status[data-state="failed"] .save-ico { color: var(--bad); }
.save-status .save-word { font-weight: 600; }
.save-status button { margin-left: auto; }
.save-box > p { margin: var(--s2) 0 0; }
.banners { max-width: calc(var(--measure) + 2 * var(--gutter)); margin: 0 auto; padding: 0 var(--gutter); }
.banner { margin: var(--s3) 0 0; padding: 10px 14px; border-left: 3px solid var(--accent-line); border-radius: var(--r2); background: var(--surface-2); }
.banner.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.banner p { margin: 0 0 var(--s2); }
.banner .row > button { flex: 1 1 8em; }
.tag {
  display: inline-flex; align-items: center; min-height: 20px; padding: 0 6px; border-radius: var(--r1);
  background: var(--accent-soft); color: var(--accent); font-size: var(--fs-xs); font-weight: 600; line-height: 1.6;
}
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.fatal { margin: var(--s4); padding: var(--s3); border-radius: var(--r2); background: var(--bad-soft); color: var(--bad); }

/* ---- a switch (role=switch): the knob's place and the track's fill both say on or off ---- */
.switch-row { padding: var(--s2) 0 var(--s3); border-top: 1px solid var(--line); }
.switch-row p { margin: 0; }
button.switch {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3); width: 100%;
  padding: 8px 0; border: 0; border-radius: 0; background: transparent; text-align: left; font-weight: 500;
}
button.switch:active:not(:disabled), button.switch:hover:not(:disabled) { background: transparent; }
.switch .knob {
  position: relative; flex: none; width: 48px; height: 28px; border-radius: 14px; background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--line-strong); transition: background-color var(--t-fast);
}
.switch .knob::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--fg-2);
}
.switch[aria-checked="true"] .knob { background: var(--accent-fill); box-shadow: none; }
.switch[aria-checked="true"] .knob::after { transform: translateX(20px); background: var(--on-accent); }
.switch.busy .knob { opacity: .5; }

/* ---- the LED brightness: a native range over eight levels (DESIGN.md, "Switch and brightness") ---- */
.bright-row { padding: var(--s2) 0 var(--s3); border-top: 1px solid var(--line); }
.bright-row p { margin: 0; }
.bright-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }
.bright-head .label { font-weight: 500; }
.bright-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.bright-ends { margin-bottom: var(--s1); display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
input[type="range"].bright-range {
  --track: 6px; --thumb: 24px;
  -webkit-appearance: none; appearance: none; display: block; width: 100%; height: var(--control); margin: 0; padding: 0;
  border: 0; border-radius: 0; background: transparent; cursor: pointer; accent-color: var(--accent-fill);
}
.bright-range::-webkit-slider-runnable-track { height: var(--track); border-radius: 3px; background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line-strong); }
.bright-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: var(--thumb); height: var(--thumb); margin-top: calc((var(--track) - var(--thumb)) / 2);
  border: 0; border-radius: 50%; background: var(--accent-fill); box-shadow: 0 0 0 2px var(--on-accent);
}
.bright-range::-moz-range-track { height: var(--track); border-radius: 3px; background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line-strong); }
.bright-range::-moz-range-progress { height: var(--track); border-radius: 3px; background: var(--accent-fill); }
.bright-range::-moz-range-thumb { width: var(--thumb); height: var(--thumb); border: 0; border-radius: 50%; background: var(--accent-fill); box-shadow: 0 0 0 2px var(--on-accent); }
.bright-range:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.bright-range:disabled { opacity: .55; cursor: default; }
.card.stale .bright-row { opacity: .55; }

/* ---- progress ---- */
progress.bar {
  -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 6px; margin: var(--s3) 0;
  border: 0; border-radius: 3px; background: var(--line); color: var(--accent-fill); overflow: hidden;
}
progress.bar::-webkit-progress-bar { background: var(--line); border-radius: 3px; }
progress.bar::-webkit-progress-value { background: var(--accent-fill); border-radius: 3px; }
progress.bar::-moz-progress-bar { background: var(--accent-fill); border-radius: 3px; }

/* ---- grouped boxes: a box only where it groups something (DESIGN.md, "Hierarchy") ---- */
.card { margin: var(--s4) 0; padding: var(--s4); border: 1px solid var(--line); border-radius: var(--r3); background: var(--surface); }
.card:not(.status) > h2:first-child { margin-top: 0; }

/* ==== 3. Shell: status strip, screens, tab bar ===================================================================== */
.app { min-height: 100vh; min-height: 100dvh; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom, 0px)); }
.strip {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--s2); min-height: var(--strip-h);
  padding: env(safe-area-inset-top, 0px) max(var(--gutter), env(safe-area-inset-right, 0px), calc((100% - var(--measure)) / 2))
    0 max(var(--gutter), env(safe-area-inset-left, 0px), calc((100% - var(--measure)) / 2));
  border-bottom: 1px solid var(--line); background: var(--bg); font-size: var(--fs-sm);
}
.strip .dot { flex: none; display: flex; color: var(--fg-2); }
.strip[data-state="ready"] .dot { color: var(--ok); }
.strip[data-state="connecting"] .dot, .strip[data-state="choosing"] .dot { color: var(--accent); }
.strip[data-state="lost"] .dot { color: var(--bad); }
.strip .who { flex: 1 1 auto; min-width: min(8.5em, 40%); display: flex; flex-direction: column; line-height: 1.25; }   /* the board's name stays whole; a job's line wraps instead */
.strip .who > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strip .name { font-weight: 600; }
.strip .state { color: var(--fg-2); font-size: var(--fs-xs); }
.strip[data-state="ready"] .state { color: var(--ok); }
.strip[data-state="lost"] .state { color: var(--bad); }
.strip .job { flex: 0 1 auto; min-width: 0; color: var(--accent); line-height: 1.25; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.strip .batt { flex: none; display: inline-flex; align-items: center; gap: var(--s1); color: var(--fg-2); font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.25; }
.strip .batt .bi { display: flex; }
.strip .batt[data-kind="level"][data-state="charging"], .strip .batt[data-kind="level"][data-state="full"] { color: var(--ok); }
.strip .batt[data-kind="level"][data-state="battery"][data-low] { color: var(--warn); }
.strip button.small { flex: none; min-width: var(--tap); white-space: nowrap; }
/* A running job: a hairline under the strip, filled to its progress (shell.js sets --job), on every tab. */
.strip::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--accent);
  transform-origin: left; transform: scaleX(var(--job, 0)); opacity: 0; pointer-events: none;
}
.strip[data-job]::after { opacity: 1; }
.strip[data-job="busy"]::after { transform: none; opacity: .6; }

.screens {
  max-width: calc(var(--measure) + 2 * var(--gutter)); margin: 0 auto;
  padding: 0 max(var(--gutter), env(safe-area-inset-right, 0px)) var(--s6) max(var(--gutter), env(safe-area-inset-left, 0px));
  container-type: inline-size;
}
.screen > h1:first-child, .screen > .cards-view > h1:first-child, .more-view > h1:first-child { margin-top: var(--s5); }
.placeholder { padding: var(--s5) 0; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 0 max(env(safe-area-inset-right, 0px), calc((100% - var(--measure)) / 2)) env(safe-area-inset-bottom, 0px)
    max(env(safe-area-inset-left, 0px), calc((100% - var(--measure)) / 2));
  border-top: 1px solid var(--line); background: var(--surface);
}
.tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0;
  min-height: var(--tabs-h); padding: 8px 2px 6px; border: 0; border-radius: 0; background: transparent; color: var(--fg-2);
  font-size: var(--fs-xs); font-weight: 500; line-height: 1.2;
}
.tab:active:not(:disabled), .tab:hover:not(:disabled) { background: transparent; color: var(--fg); }
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab[aria-selected="true"], .tab[aria-selected="true"]:hover { color: var(--accent); font-weight: 600; }
.tab::before {
  content: ""; position: absolute; top: -1px; left: 50%; width: 32px; height: 2px; margin-left: -16px; border-radius: 0 0 2px 2px;
  background: var(--accent); transform: scaleX(0);
}
.tab[aria-selected="true"]::before { transform: scaleX(1); }

/* ==== 4. Dialogs: a sheet at the bottom of a phone, a box in the middle of a wider window ========================== */
.dlg-backdrop, .dlg-ghost {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center;
  padding: var(--s2); padding-bottom: calc(var(--s2) + env(safe-area-inset-bottom, 0px)); background: var(--scrim);
}
.dlg-ghost { pointer-events: none; }
@media (min-width: 600px) { .dlg-backdrop, .dlg-ghost { align-items: center; padding: var(--s5); } }
.dlg, .dlg-box {
  width: min(32rem, 100%); max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); overflow-y: auto;
  padding: 20px var(--s4) var(--s4); border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--fg);
  outline: none; overscroll-behavior: contain;
}
.dlg h2, .dlg-box h2 { margin: 0 0 var(--s2); font-size: var(--fs-lg); }
.dlg-buttons { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s4); }
.dlg-buttons > * { width: 100%; }
.dlg-items { margin: var(--s3) 0; padding: 0; list-style: none; }
.dlg-items li {
  position: relative; margin: var(--s2) 0; padding: 10px 12px 10px 40px; border-radius: var(--r2); background: var(--surface-2);
  font-size: var(--fs-sm); line-height: 1.45;
}
.dlg-items li::before { left: 12px; top: 11px; color: var(--accent); }
.dlg-items li.lvl-lock, .dlg-items li.lvl-permanent { background: var(--bad-soft); }
.dlg-items li.lvl-lock::before, .dlg-items li.lvl-permanent::before { color: var(--bad); -webkit-mask-image: var(--icon-lock); mask-image: var(--icon-lock); }
.dlg-items li.lvl-lock b, .dlg-items li.lvl-permanent b { color: var(--bad); }
.dlg-items li.lvl-warning { background: var(--warn-soft); }
.dlg-items li.lvl-warning::before { color: var(--warn); -webkit-mask-image: var(--icon-warn); mask-image: var(--icon-warn); }
.dlg-items li.lvl-warning b { color: var(--warn); }
@media (min-width: 600px) { .dlg, .dlg-box { padding: var(--s5); } }

/* ==== 5. Board ====================================================================================================== */
.area { padding: var(--s2) 0; }
.area > .muted { max-width: 34em; }
.help { padding: var(--s1) 0; }
.help a { display: inline-flex; align-items: center; min-height: var(--tap); }
ol.steps {
  list-style: none; margin: var(--s4) 0; padding: 0;
  background: linear-gradient(var(--line), var(--line)) no-repeat 10px 22px / 2px calc(100% - 44px);   /* the line between the steps */
}
ol.steps li { position: relative; min-height: var(--tap); padding: 10px 0 10px 36px; color: var(--fg-2); }
ol.steps li::before {
  content: ""; position: absolute; left: 1px; top: 13px; width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--line-strong); background: var(--bg); box-sizing: border-box;
}
ol.steps li.done { color: var(--fg); }
ol.steps li.done::before { border-color: var(--ok); background: var(--ok); }
ol.steps li.done::after {   /* a tick */
  content: ""; position: absolute; left: 8px; top: 17px; width: 5px; height: 9px; border: solid var(--bg); border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
ol.steps li.active { color: var(--fg); font-weight: 600; }
ol.steps li.active::before { border-color: var(--accent); border-right-color: transparent; }
.card.status { margin: 0; padding: 0; border: 0; border-radius: 0; background: none; }
.card-title {
  display: flex; align-items: baseline; gap: var(--s3); min-width: 0; margin: var(--s5) 0 var(--s3);
  font-size: var(--fs-xl); font-weight: 650; line-height: 1.25;
}
.card-title .dot { display: none; }       /* the strip shows the link's state with its icon */
.card-title .title-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title .title-state { margin-left: auto; flex: none; font-size: var(--fs-sm); font-weight: 500; color: var(--fg-2); }
.card[data-state="ready"] .title-state { color: var(--ok); }
.card[data-state="lost"] .title-state { color: var(--bad); }
.card.stale dl, .card.stale .switch-row { opacity: .55; }
dl { margin: var(--s2) 0 var(--s4); }
.kv {
  display: grid; grid-template-columns: 6.75em minmax(0, 1fr); gap: 2px var(--s3); align-items: baseline;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.kv dt { color: var(--fg-2); font-size: var(--fs-sm); }
.kv dd { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--s2); margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.kv dd > * { min-width: 0; }
.kv dd .sub { flex-basis: 100%; color: var(--fg-2); font-size: var(--fs-sm); }
.kv dd.hexv { font-family: var(--font-mono); font-size: var(--fs-sm); font-variant-numeric: tabular-nums slashed-zero; letter-spacing: .02em; }
.kv dd .bat { display: flex; align-self: center; color: var(--fg-2); }
.card .cal { margin-top: var(--s4); padding-top: var(--s3); border-top: 1px solid var(--line); }
.card .cal .lead { margin: 0 0 var(--s1); }
.card .cal p { margin: var(--s1) 0; }
.kv dd .bat:empty { display: none; }
.kv dd .bat + span { flex: 1 1 0; }
@container (max-width: 320px) { .kv { grid-template-columns: minmax(0, 1fr); } }
.conn-details { margin-top: var(--s5); }
.connbox { margin-top: var(--s1); }
pre.connlog {
  margin: var(--s2) 0; padding: 10px 12px; max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--r2);
  background: var(--sunk); font-size: var(--fs-xs); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
.version { margin-top: var(--s6); font-size: var(--fs-xs); }

/* ==== 6. Cards and the new card form ================================================================================ */
/* The list: rows under hairlines, the card's kind as an icon in a column of its own, the number and the type on the
   first line, the UID or IDm under them; the row's actions open under it. */
.cardlist { list-style: none; margin: var(--s3) calc(-1 * var(--s3)); padding: 0; }
.cardlist.stale .card-entry { opacity: .55; }
.card-entry { position: relative; border-top: 1px solid var(--line); }
.card-entry:last-child { border-bottom: 1px solid var(--line); }
.card-entry.open { background: var(--surface); }
.card-entry.active { box-shadow: inset 3px 0 0 var(--ok); }
button.entry-main {
  position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 2px; width: 100%; min-height: var(--row-h);
  padding: var(--s3) var(--s3) var(--s3) 48px; border: 0; border-radius: 0; background: transparent; text-align: left; font-weight: 400;
}
button.entry-main:active:not(:disabled), button.entry-main:hover:not(:disabled) { background: var(--surface-2); }
.entry-main .entry-icon { position: absolute; left: var(--s3); top: 14px; color: var(--fg-2); }
.entry-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px var(--s2); min-width: 0; }
.entry-top .num { color: var(--fg-2); font-family: var(--font-mono); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.entry-top .type { font-weight: 600; }
.entry-top .name { min-width: 0; overflow-wrap: anywhere; }
.entry-top .badge {
  margin-left: auto; padding: 0 6px; border-radius: var(--r1); background: var(--ok-soft); color: var(--ok);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.6;
}
.entry-top .badge.warn { background: var(--warn-soft); color: var(--warn); }
.entry-sub { color: var(--fg-2); font-size: var(--fs-sm); overflow-wrap: anywhere; font-variant-numeric: tabular-nums slashed-zero; }
/* The access code: a line of the row with the copy icon in the icon column; a tap copies it. */
button.entry-code, button.entry-id, button.entry-fake {
  position: relative; display: flex; justify-content: flex-start; width: calc(100% - 2 * var(--s3)); min-height: var(--tap);
  margin: -6px var(--s3) 6px; padding: 6px 8px 6px 36px; border: 0; background: transparent; text-align: left;
  font-size: var(--fs-sm); font-weight: 400; font-variant-numeric: tabular-nums slashed-zero;
}
button.entry-code::before, button.entry-id::before, button.entry-fake::before {
  content: ""; position: absolute; left: 1px; top: 50%; width: 18px; height: 18px; margin-top: -9px; background: var(--accent);
  -webkit-mask: var(--icon-copy) center / contain no-repeat; mask: var(--icon-copy) center / contain no-repeat; forced-color-adjust: none;
}
button.entry-code:active:not(:disabled), button.entry-code:hover:not(:disabled),
button.entry-id:active, button.entry-id:hover, button.entry-fake:active, button.entry-fake:hover { background: var(--surface-2); }
button.entry-id, button.entry-fake { color: var(--fg-2); }
button.entry-code.asking { color: var(--fg-2); }
button.entry-code.asking::before { display: none; }
.entry-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); padding: 0 var(--s3) var(--s3); }
@container (min-width: 520px) { .entry-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
/* Edit access code: the small form under its row (DESIGN.md "Small forms inside a screen"), boxed like the On air form. */
.card-entry .code-edit { margin: 0 var(--s3) var(--s3); border: 1px solid var(--line); border-radius: var(--r3); background: var(--bg); }
.code-edit .lead { margin: var(--s2) 0; }
.code-current-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s3); }
.code-current { margin: 0; font-variant-numeric: tabular-nums; }
.code-edit .field p.muted { margin: 0 0 var(--s1); }
/* A status line under a field that keeps its height while empty (New card, Banapass: what the field recognised). */
.kind-line { min-height: calc(var(--fs-sm) * 1.6); margin: var(--s1) 0 0; }
#cards-msg, #emu-msg, #rd-msg { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
#cards-msg > span { flex: 1 1 12em; min-width: 0; }
#emu-msg > span, #rd-msg > span { flex: 1 1 14em; min-width: 0; }
#cards-msg button { min-height: var(--tap); }
.backup-note { margin-top: var(--s5); }
/* One primary per view: a Save file in the message is the next step, so New card steps back meanwhile. */
#screen-cards:has(#cards-save-file:not([hidden])) #cards-new { background: var(--surface-2); color: var(--fg); border-color: var(--line); }

/* ---- Button slots (Cards, ui/slots.js): the slot's number and its LED pulses in groups of four, what it holds, Emulate ---- */
.slots { margin-top: var(--s5); }
.slots-body h2 { margin: 0 0 var(--s1); }
.stepper { display: flex; align-items: center; gap: var(--s3); margin: var(--s3) 0; }
.stepper .step { flex: none; min-width: var(--control); padding: 0; }
.stepper .count-value { min-width: 6em; font-weight: 600; font-variant-numeric: tabular-nums; }
.slotlist { list-style: none; margin: var(--s3) calc(-1 * var(--s3)); padding: 0; }
.slots-body.stale .slot-row { opacity: .55; }
.slot-row { border-top: 1px solid var(--line); padding: var(--s3); }
.slot-row:last-child { border-bottom: 1px solid var(--line); }
.slot-row.current { box-shadow: inset 3px 0 0 var(--ok); }
.slot-head { display: flex; align-items: center; gap: var(--s3); min-height: var(--tap); }
.slot-head .num { min-width: 1.2em; font-family: var(--font-mono); font-size: var(--fs-md); font-weight: 600; font-variant-numeric: tabular-nums; }
.pulses { display: inline-flex; align-items: center; gap: var(--s3); }
.pulses .pg { display: inline-flex; align-items: center; gap: var(--s1); }
.pulses .pd { width: calc(var(--s1) * 2); height: calc(var(--s1) * 2); border-radius: 50%; background: var(--fg-2); }
.slot-head .badge { margin-left: auto; padding: 0 6px; border-radius: var(--r1); background: var(--ok-soft); color: var(--ok); font-size: var(--fs-xs); font-weight: 600; line-height: 1.6; }
.slot-row select { margin-top: var(--s1); }
.slot-now { margin: var(--s2) 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums slashed-zero; }
.slot-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
.slot-actions > button[hidden] { display: none; }
.slot-warns .note { margin: var(--s2) 0; }

/* ---- Keys (More, WP9): the dictionary as rows of hex; a long list stays fast ---- */
.keylist .entry-top { align-items: center; }
.keylist .keyhex { font-family: var(--font-mono); font-weight: 500; font-variant-numeric: slashed-zero; letter-spacing: .02em; }
.keylist .keys-actions { grid-template-columns: minmax(0, 1fr); }
/* Rows below the first screenful are laid out and painted only near the view (guide defer-rendering-heavy-content); the
   estimate is the row's height, so the scrollbar does not jump. */
.keylist .key-entry:nth-child(n+13) { content-visibility: auto; contain-intrinsic-size: auto none auto 61px; }
#keys-msg { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
#keys-msg > span { flex: 1 1 12em; min-width: 0; }
#keys-msg button { min-height: var(--tap); }
#keys-add-input { text-transform: uppercase; }
#keys-add-input::placeholder { text-transform: none; }
.keys-filter { margin: var(--s3) 0 0; }
#keys-progress { margin: var(--s3) 0; }
/* One primary per view: a Save file in the message is the next step, so Import steps back meanwhile. */
#screen-more:has(#keys-save-file:not([hidden])) #keys-import { background: var(--surface-2); color: var(--fg); border-color: var(--line); }

/* ==== 7. Emulator, Reader and Files: sectors, blocks and hex ======================================================== */
.sectors, .blocks, .diff, .notes { list-style: none; margin: 0; padding: 0; }
.sectors { margin: var(--s3) 0; border-top: 1px solid var(--line); }
.sector { position: relative; border-bottom: 1px solid var(--line); }
.sector.edited::before {    /* the change mark in the margin */
  content: ""; position: absolute; left: -10px; top: 14px; width: 3px; height: 24px; border-radius: 2px; background: var(--accent);
}
button.sector-head {
  display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: var(--big); padding: 10px 0; border: 0; border-radius: 0;
  background: transparent; text-align: left; font-weight: 400;
}
button.sector-head:active:not(:disabled), button.sector-head:hover:not(:disabled) { background: transparent; }
button.sector-head::after {
  content: ""; flex: none; width: 18px; height: 18px; margin-left: auto; background: var(--fg-2);
  -webkit-mask: var(--icon-chevron) center / contain no-repeat; mask: var(--icon-chevron) center / contain no-repeat; forced-color-adjust: none;
}
button.sector-head[aria-expanded="true"]::after { transform: rotate(90deg); }
.sector-top, .blk-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px var(--s2); min-width: 0; }
.sector-top { flex: 1 1 auto; }
/* A sector's head is one line of text (inline boxes on a shared baseline, not flex items, so a CJK fallback font cannot
   shift one of them); a tag that does not fit goes to a second line. */
button.sector-head .sector-top { display: block; }
.sector-top > * + * { margin-left: var(--s2); }
.sector-top .tag { display: inline-block; vertical-align: baseline; }
.sector-top b { font-weight: inherit; }   /* one weight on the line: a bold CJK fallback font sits a pixel higher */
.blocks { margin: 0 0 var(--s3); border: 1px solid var(--line); border-radius: var(--r3); background: var(--surface); overflow: hidden; }
.blk + .blk { border-top: 1px solid var(--line); }
.blk.editing { background: var(--surface-2); }
button.blk-main, div.blk-main {
  display: flex; flex-direction: column; align-items: stretch; gap: 2px; width: 100%; min-height: var(--row-h-sm); padding: 10px 14px;
  border: 0; border-radius: 0; background: transparent; text-align: left; font-weight: 400;
}
button.blk-main:active:not(:disabled), button.blk-main:hover:not(:disabled) { background: var(--surface-2); }
div.blk-main.unread { opacity: .75; }
.blk-top b { font-size: var(--fs-sm); }
.blk-top .muted { font-size: var(--fs-sm); }
.blk-line { display: block; color: var(--fg-2); font-size: var(--fs-sm); line-height: 1.45; overflow-wrap: anywhere; font-variant-numeric: tabular-nums slashed-zero; }
.editor { padding: var(--s1) 14px 14px; }
/* The FeliCa view (ui/emulator-felica.js): a row is the block row with its Copy button beside it; codes are mono text. */
.fl-row { display: flex; align-items: stretch; }
.fl-row > button.blk-main { flex: 1 1 auto; width: auto; min-width: 0; }
.fl-row > button.copy { flex: none; align-self: center; margin-right: var(--s2); min-width: var(--tap); padding-inline: var(--s2); }
.code-list { display: block; font-size: var(--fs-sm); line-height: 1.6; overflow-wrap: anywhere; }
#emf .editor textarea { min-height: 3em; }
.emf-lines { margin: var(--s3) 0; }
.emf-lines summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; }
.emf-pre { margin: 0 0 var(--s2); padding: var(--s3); border: 1px solid var(--line); border-radius: var(--r3); background: var(--surface); font-size: var(--fs-sm); white-space: pre-wrap; overflow-wrap: anywhere; }
/* the Emulator's on-air SAK / ATQA: a section under a hairline; its form is the open sector's box */
.emu-onair { padding-bottom: var(--s2); border-bottom: 1px solid var(--line); }
.emu-onair h2 { margin-top: var(--s4); }
.emu-onair .editor { margin-top: var(--s2); border: 1px solid var(--line); border-radius: var(--r3); background: var(--surface); }
.emu-onair .field > .muted { display: block; margin-bottom: 4px; }
.emu-onair input { max-width: 8em; }
.editor .row > button, .emu-list .row > button, .emu-review .row > button { flex: 1 1 9em; }
.notes { margin: var(--s2) 0; }
.note-item {
  position: relative; margin: var(--s2) 0; padding: 10px 12px 10px 40px; border-radius: var(--r2); background: var(--surface-2);
  font-size: var(--fs-sm); line-height: 1.45; overflow-wrap: anywhere;
}
.note-item::before { left: 12px; top: 11px; color: var(--accent); }
.note-item.lvl-lock { background: var(--bad-soft); }
.note-item.lvl-lock::before { color: var(--bad); -webkit-mask-image: var(--icon-lock); mask-image: var(--icon-lock); }
.note-item.lvl-warning { background: var(--warn-soft); }
.note-item.lvl-warning::before { color: var(--warn); -webkit-mask-image: var(--icon-warn); mask-image: var(--icon-warn); }
.diff-item { margin: var(--s3) 0; padding: var(--s3) 14px; border: 1px solid var(--line); border-radius: var(--r3); background: var(--surface); }
.diff-row { display: flex; flex-direction: column; margin: 6px 0; }
.diff-label { font-size: var(--fs-xs); }
.diff-item button.undo { display: flex; width: 100%; margin-top: var(--s2); }
.apply-box { margin: var(--s3) 0; padding: var(--s4); border: 1px solid var(--accent-line); border-radius: var(--r3); background: var(--surface); }
#screen-emulator:has(#emu-msg button.primary) #emu-review { background: var(--surface-2); color: var(--fg); border-color: var(--line); }

/* Reader: the card to hold, the sweep sector by sector, the result. */
.hold {
  position: relative; margin: var(--s4) 0 var(--s2); padding: 60px var(--s4) 20px; border: 1px dashed var(--accent-line);
  border-radius: var(--r3); background: var(--surface); font-size: var(--fs-lg); font-weight: 600; text-align: center; overflow-wrap: anywhere;
}
.hold::before {
  content: ""; position: absolute; left: 50%; top: 20px; width: 28px; height: 28px; margin-left: -14px; background: var(--accent);
  -webkit-mask: var(--icon-card-nfc) center / contain no-repeat; mask: var(--icon-card-nfc) center / contain no-repeat; forced-color-adjust: none;
}
.hold.found { border-style: solid; border-color: var(--accent); }
.hold.found::before { -webkit-mask-image: var(--icon-ok); mask-image: var(--icon-ok); }
/* 16 cells, one per sector: tinted when its keys are known, filled when its blocks are read (ui/reader.js). The
   progress element stays for assistive technology; the cells are aria-hidden. */
.sweep { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 3px; margin: var(--s3) 0 var(--s2); }
.sweep > span { position: relative; height: 12px; border-radius: 2px; background: var(--line); overflow: hidden; }
.sweep > span::after { content: ""; position: absolute; inset: 0; background: var(--accent); transform: scaleY(0); transform-origin: bottom; }
.sweep > span.keys::after { transform: none; background: var(--accent-line); }
.sweep > span.got::after { transform: none; background: var(--accent); }
.read-box[data-sweep="mifare"] #rd-bar {
  position: absolute; width: 1px; height: 1px; margin: 0; clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}
.read-box .row.actions { margin-top: var(--s4); }
.result h2 { margin-top: var(--s5); }
#rd-interrupted { margin-top: var(--s4); padding-left: var(--s4); border-left: 3px solid var(--warn); }
#rd-interrupted h2 { margin-top: var(--s2); }
.fblocks { margin: var(--s2) 0; }
.fblocks .blk:first-child { border-top: 0; }
.write { margin-top: var(--s6); padding-top: var(--s2); border-top: 1px solid var(--line); }
/* Write a card (ui/writer.js): the checklist is the sector list with a checkbox on every sector and block; a row is the 44 px
   label of a native checkbox (modern-web-guidance: checkbox), the sector head a button next to it. */
.write h3 { margin: var(--s5) 0 var(--s2); font-size: var(--fs-md); font-weight: 600; line-height: 1.3; }
.write .row > button { flex: 1 1 9em; }
.wr-sources > button { flex: 1 1 8em; }
.write input[type="checkbox"] { accent-color: var(--accent-fill); }
.wr-sector-top { display: flex; align-items: center; gap: var(--s2); }
.wr-check { display: flex; align-items: center; justify-content: center; flex: none; width: var(--control); min-height: var(--control); margin: 0; }
.wr-check input { width: 22px; height: 22px; margin: 0; }
.wr-sector-top > button.sector-head { flex: 1 1 auto; width: auto; min-width: 0; }
.wr-blocks { margin-left: var(--control); }
.wr-blk label.check { align-items: center; margin: 0; padding: 4px 14px; }
.wr-blk label.check span { min-width: 0; font-size: var(--fs-sm); line-height: 1.45; overflow-wrap: anywhere; }
.wr-blk:not(.wr-will) label.check span { color: var(--fg-2); }
#wr-running .row.actions { margin-top: var(--s3); }
#wr-result .row > button { flex: 1 1 14em; }
#wr-res-title.msg { margin-top: 0; }
.result .row > button, .read-box .row > button { flex: 1 1 14em; }   /* long labels: one button to a line on a phone */
#screen-reader:has(#rd-continue-box:not([hidden])) #rd-load.primary { background: var(--surface-2); color: var(--fg); border-color: var(--line); }

/* Files: the dumps list shares the card list's rows; the export panel is a grouped box. */
#files-dump-view > button:first-child { margin-top: var(--s4); }
#screen-more:has(#files-export-box:not([hidden])) #files-open-editor { background: var(--surface-2); color: var(--fg); border-color: var(--line); }

/* ==== 8. More: the sub-views, the console, the settings ============================================================= */
.subnav {
  display: flex; gap: 2px; margin: var(--s4) 0 var(--s2); padding: 3px; border-radius: 11px; background: var(--surface-2);
}
.subnav > button {
  flex: 1 1 0; min-width: 0; min-height: var(--tap); padding: 6px 4px; border: 0; border-radius: var(--r2); background: transparent;
  color: var(--fg-2); font-size: var(--fs-sm);
}
.subnav > button:hover:not(:disabled), .subnav > button:active:not(:disabled) { background: var(--surface-3); color: var(--fg); }
.subnav > button[aria-pressed="true"] { background: var(--surface); color: var(--fg); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }

.console-tab {
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto; grid-template-columns: minmax(0, 1fr); min-height: 300px;
}
.console-tab > * { min-width: 0; }
.console-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.console-head h1 { margin: var(--s3) 0 var(--s2); }
.console-head button { min-height: var(--tap); }
.console-tab > p { margin: 0 0 var(--s2); }
.console-tab .outwrap {
  position: relative; min-height: 0; overflow: hidden; border: 1px solid var(--line); border-bottom: 0;
  border-radius: var(--r3) var(--r3) 0 0; background: var(--sunk);
}
#out {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; background: var(--sunk);
  font-size: var(--fs-log); line-height: 1.5; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
#out .entry { padding: 6px 12px; border-bottom: 1px solid var(--line); }
#out .entry .head { display: flex; gap: var(--s2); align-items: baseline; min-width: 0; }
#out .entry .cmd { font-weight: 600; white-space: pre; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#out .entry .cmd::before { content: "› "; color: var(--accent); }
#out .entry .meta { margin-left: auto; flex: none; color: var(--fg-2); font-size: var(--fs-xs); white-space: nowrap; }
#out .entry pre { margin: 2px 0 0; padding: 0; white-space: pre; overflow-x: auto; max-width: 100%; font: inherit; }
#out .entry .ln { display: block; }
#out .entry .ln.status { font-weight: 700; }
#out .entry .ln.status.ok { color: var(--ok); }
#out .entry .ln.status.err { color: var(--bad); }
#out .entry.timeout .meta, #out .entry.failed .meta { color: var(--bad); font-weight: 600; }
#out .entry.queued .meta, #out .entry.sent .meta { color: var(--accent); }
#out .entry.unasked .head { color: var(--warn); }
#out .entry.unasked .cmd::before { content: "‹ "; color: var(--warn); }
#out .entry.info { color: var(--fg-2); font-family: var(--font-ui); font-size: var(--fs-log); }
#out .entry.info.ok { color: var(--ok); }
#out .entry.info.bad { color: var(--bad); }
#out .entry.info.warn { color: var(--warn); }
#jump {
  position: absolute; right: 12px; bottom: 12px; z-index: 4; min-height: var(--tap); border-color: transparent;
  background: var(--accent-fill); color: var(--on-accent); font-weight: 600;
}
#histPanel {
  position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 5; max-height: 60%; overflow-y: auto; padding: 6px;
  border: 1px solid var(--line-strong); border-radius: var(--r2); background: var(--surface-2);
}
#histPanel button {
  display: block; width: 100%; margin: 2px 0; text-align: left; white-space: pre; overflow: hidden; text-overflow: ellipsis;
  border-color: transparent; background: transparent;
}
.console-tab .quick {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px; border: 1px solid var(--line); border-bottom: 0; background: var(--surface);
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.console-tab .quick::-webkit-scrollbar { display: none; }
.console-tab .quick button { flex: none; min-height: var(--tap); min-width: 48px; padding: 4px 12px; font-size: var(--fs-log); white-space: nowrap; }
form.cmdline {
  display: flex; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 0 0 var(--r3) var(--r3); background: var(--surface);
}
#line { flex: 1 1 auto; min-width: 0; min-height: var(--tap); padding: 6px 10px; font-size: 16px; }
#histBtn, #sendBtn { flex: none; min-height: var(--tap); padding: 6px 12px; }
#sendBtn { background: var(--accent-fill); color: var(--on-accent); border-color: transparent; font-weight: 600; }

/* Firmware update (ui/firmware.js): Back to Settings, the notes with a command line, the two parts, the run, the result. */
.fw #fw-back { display: inline-flex; align-items: center; gap: var(--s1); margin-top: var(--s2); text-decoration: none; }
.fw .note p, .fw .msg p { margin: 0 0 var(--s2); }
.fw .note p:last-child, .fw .msg p:last-child { margin-bottom: 0; }
.fw-cmd {
  padding: var(--s2) var(--s3); border-radius: var(--r2); background: var(--sunk); color: var(--fg); font-size: var(--fs-sm);
  overflow-wrap: anywhere; user-select: all; -webkit-user-select: all;
}
.fw-part > h2 { margin-top: var(--s5); }
#fw-choose { width: 100%; }
#fw-image-info { margin: var(--s3) 0 0; overflow-wrap: anywhere; }
#fw-run ol.steps { margin-top: 0; }
#fw-run .lead { margin: var(--s3) 0 0; }
#fw-percent { margin: 0; }
#fw-result .row.actions { margin-top: var(--s3); }
#settings-firmware button { width: 100%; }

/* ==== 9. Motion (DESIGN.md, "Motion"): only with no reduced-motion wish; 120 to 240 ms, eased out; transform and
   opacity only; nothing waits for it and nothing loops except while something is in progress. Without these rules
   every state is shown at once. ===================================================================================== */
@media (prefers-reduced-motion: no-preference) {
  /* screens and the parts of a screen that come and go (the keyframes run when display none turns into a box) */
  .screen:not([hidden]), .more-view:not([hidden]) { animation: fade-in var(--t-base) var(--ease-out); }
  .area, .card.status, .msg, .banner, .connbox, .entry-actions, .read-box, .result, #rd-failed, .cards-new-view, .emu-review,
  #emu-list, #emu-onair-form, .apply-box, #files-list-view, #files-paste-view, #files-import-view, #files-dump-view, #files-export-box,
  #keys-progress, #keys-lost, .blocks.enter, #fw-run, #fw-image-info { animation: rise-in var(--t-base) var(--ease-out); }
  #rd-interrupted { animation: rise-in var(--t-slow) var(--ease-out); }

  /* the tab bar's mark, the chevron, the switch */
  .tab::before { transition: transform var(--t-base) var(--ease-out); }
  button.sector-head::after { transition: transform var(--t-base) var(--ease-out); }
  .switch .knob::after { transition: transform var(--t-base) var(--ease-out), background-color var(--t-fast); }

  /* the link: searching pulses while it connects; connected and lost settle once */
  .strip[data-state="connecting"] .dot .i, .strip[data-state="choosing"] .dot .i { animation: pulse 1.2s ease-in-out infinite; }
  .strip[data-state="ready"] .dot .i, .strip[data-state="lost"] .dot .i, .strip[data-state="idle"] .dot .i { animation: settle var(--t-slow) var(--ease-out); }
  ol.steps li.active::before { animation: spin .9s linear infinite; }
  ol.steps li.done::before, ol.steps li.done::after { animation: fade-in var(--t-base) var(--ease-out); }

  /* a job: the strip's hairline follows the progress; without a count it breathes */
  .strip::after { transition: transform var(--t-slow) var(--ease-out), opacity var(--t-base); }
  .strip[data-job="busy"]::after { animation: breathe 1.4s ease-in-out infinite; }
  progress.bar:not([value]) { animation: breathe 1.4s ease-in-out infinite; }

  /* the reader: the field icon breathes while the board waits for a card; sectors fill in as they arrive */
  .hold:not(.found)::before { animation: breathe 1.6s ease-in-out infinite; }
  .hold.found::before { animation: settle var(--t-slow) var(--ease-out); }
  .sweep > span::after { transition: transform var(--t-base) var(--ease-out), background-color var(--t-base); }

  /* dialogs: the sheet rises, the scrim fades; a closed one fades away as a picture (ui/dialogs.js) */
  .dlg-backdrop { animation: fade-in var(--t-base) var(--ease-out); }
  .dlg { animation: sheet-in var(--t-slow) var(--ease-out); }
  .dlg-ghost { animation: fade-out 140ms var(--ease-in) forwards; }
  .dlg-ghost .dlg-box { animation: sheet-out 140ms var(--ease-in) forwards; }
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(24px); } }
@keyframes sheet-out { to { opacity: 0; transform: translateY(12px); } }
@keyframes settle { from { opacity: .3; transform: scale(1.3); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes breathe { 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (min-width: 600px) {
  @keyframes sheet-in { from { opacity: 0; transform: scale(.97); } }
  @keyframes sheet-out { to { opacity: 0; transform: scale(.98); } }
}
@media (prefers-reduced-motion: reduce) {
  ol.steps li.active::before { border-right-color: var(--accent); }    /* a full ring instead of the spinning one */
}

/* ==== Toast (ui/toast.js, DESIGN.md "The toast"): one floating line, fixed, above the tab bar and inside the
   safe-area insets; it takes no room in the page and no pointer events. =========================================== */
.toasts {
  position: fixed; left: 0; right: 0; z-index: 30; display: flex; justify-content: center; pointer-events: none;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom, 0px) + var(--s3));
  padding: 0 max(var(--gutter), env(safe-area-inset-right, 0px)) 0 max(var(--gutter), env(safe-area-inset-left, 0px));
}
.toast {
  margin: 0; max-width: min(100%, 30rem); padding: 10px 14px; border: 1px solid var(--line-strong); border-left: 3px solid var(--ok);
  border-radius: var(--r2); background: var(--surface-3); color: var(--fg); box-shadow: 0 4px 16px rgba(0, 0, 0, .28);
  overflow-wrap: anywhere; visibility: hidden; opacity: 0;
}
.toast[data-kind="bad"] { border-left-color: var(--bad); background: var(--bad-soft); }
.toast.show { visibility: visible; opacity: 1; }
@media (forced-colors: active) { .toast { border: 1px solid CanvasText; } }
@media (prefers-reduced-motion: no-preference) {
  .toast { transform: translateY(8px); transition: opacity var(--t-base) var(--ease-out), transform var(--t-base) var(--ease-out), visibility 0s var(--t-base); }
  .toast.show { transform: none; transition-delay: 0s; }
}

/* ==== 10. Windows contrast themes =================================================================================== */
@media (forced-colors: active) {
  .switch .knob { border: 1px solid CanvasText; }
  .switch[aria-checked="true"] .knob { background: Highlight; }
  .switch[aria-checked="true"] .knob::after { background: Canvas; }
  .tab[aria-selected="true"] { text-decoration: underline; }
  .sweep > span { border: 1px solid CanvasText; }
  .sweep > span.got::after, .sweep > span.keys::after { background: Highlight; forced-color-adjust: none; }
}

/* Transit IC card result (ui/reader.js renderTransit): the usage history as a list of rows under hairlines. */
.tr-list { list-style: none; margin: var(--s2) 0 var(--s3); padding: 0; }
.tr-row, .tr-empty { display: block; padding: var(--s3) 0; border-top: 1px solid var(--line); }
.tr-row:first-child, .tr-empty:first-child { border-top: 0; }
.tr-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px var(--s3); }
.tr-date { font-weight: 600; font-variant-numeric: tabular-nums slashed-zero; }
.tr-kind { flex: 1 1 auto; min-width: 0; }
.tr-amount { margin-inline-start: auto; font-variant-numeric: tabular-nums slashed-zero; }
.tr-amount.plus { color: var(--ok); font-weight: 600; }
.tr-sub { display: block; margin-top: 2px; color: var(--fg-2); font-size: var(--fs-sm); line-height: 1.45; overflow-wrap: anywhere; font-variant-numeric: tabular-nums slashed-zero; }
.tr-empty { color: var(--fg-2); }
#rd-transit .row.actions { margin-top: var(--s4); }
/* The IDm code line (ui/fakecode.js): the access code line's look; its one-line explanation sits under it. */
.fake-help, .konami-help { margin: -2px var(--s3) 6px; }
.blk .fake-code { margin-top: 0; }
.blk .fake-help, .blk .konami-help { margin-left: var(--s3); }
.konami-id { margin-top: 0; }
