:root {
  --bg: #f4f5f8; --card: #ffffff; --fg: #1b1e27; --muted: #5d6475; --line: #d9dce5;
  --accent: #1f6feb; --accent-fg: #fff; --ok: #1a7f37; --warn: #9a6700; --bad: #cf222e;
  --on: #1f6feb; --shape: #c9cdd8; --shape-line: #9aa1b2;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --card: #181c25; --fg: #e6e9f0; --muted: #98a0b3; --line: #2b3140;
    --accent: #4c8dff; --accent-fg: #06101f; --ok: #3fb950; --warn: #d29922; --bad: #f85149;
    --on: #4c8dff; --shape: #2a3040; --shape-line: #4a5269; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218; --card: #181c25; --fg: #e6e9f0; --muted: #98a0b3; --line: #2b3140;
  --accent: #4c8dff; --accent-fg: #06101f; --ok: #3fb950; --warn: #d29922; --bad: #f85149;
  --on: #4c8dff; --shape: #2a3040; --shape-line: #4a5269; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
a { color: var(--accent); }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .85rem; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; flex-wrap: wrap; }
.brand { font-weight: 700; }
.brand .copy { font-weight: 400; font-size: 12px; color: var(--muted, #8a93a3); margin-left: 8px; white-space: nowrap; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { font-size: .8rem; padding: 3px 10px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: var(--ok); } .pill.bad { color: var(--bad); border-color: var(--bad); } .pill.warn { color: var(--warn); border-color: var(--warn); }
.tabs { display: flex; gap: 4px; padding: 0 12px; overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 12px 14px; min-height: 48px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; display: flex; align-items: center; }
.tabs a.on { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a kbd { display: none; }
.tabs .links { display: flex; gap: 4px; }
.tabs .navbtn { display: none; }
main { padding: 16px; max-width: 1100px; margin: 0 auto; outline: none; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.card > h2 { margin-bottom: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.row.spread { justify-content: space-between; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.btn { font: inherit; min-height: 44px; min-width: 44px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .tabs a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.danger { background: #cf222e; color: #fff; border-color: #cf222e; } /* fixed red: white text stays readable in the dark theme too */
.btn.big { min-height: 72px; font-size: 1.15rem; font-weight: 600; flex: 1 1 140px; }
.btn.sm { min-height: 36px; padding: 4px 10px; font-size: .85rem; }
.btn.on { background: var(--accent); color: var(--accent-fg); }
.btn:disabled, .btn[disabled] { opacity: .4; cursor: not-allowed; filter: grayscale(.8); box-shadow: none; }
.btn:disabled:hover, .btn[disabled]:hover { border-color: var(--line); }
.btn.primary:disabled:hover { border-color: var(--accent); }
.kv { display: grid; grid-template-columns: minmax(90px, 38%) 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; min-width: 0; }
.kv dd .btn { margin-left: 6px; }
.empty { border: 2px dashed var(--line); border-radius: 12px; padding: 28px 16px; text-align: center; color: var(--muted); }
.empty strong { color: var(--fg); }
.notice { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--warn); color: var(--warn); margin-bottom: 12px; }
.notice.bad { border-color: var(--bad); color: var(--bad); }
.toasts { position: fixed; left: 12px; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; align-items: center; z-index: 50; pointer-events: none; }
.toast { background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: 520px; box-shadow: 0 4px 16px #0005; }
.toast.error { background: #cf222e; color: #fff; } .toast.ok { background: #1a7f37; color: #fff; } .toast.warn { background: #9a6700; color: #fff; } /* fixed: 4.5:1 with white in both themes */
dialog.dlg { border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--fg); max-width: min(480px, calc(100vw - 32px)); padding: 18px; }
dialog.dlg::backdrop { background: #0008; }
label { display: block; }
.field { display: grid; grid-template-columns: 110px 1fr 48px; gap: 8px; align-items: center; margin: 6px 0; }
.field.two { grid-template-columns: 110px 1fr; }
input[type=range] { width: 100%; min-height: 36px; accent-color: var(--accent); }
input[type=color] { width: 64px; height: 44px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
input[type=text], input[type=number], input[type=password], select { font: inherit; min-height: 44px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); max-width: 100%; }
input[type=text], input[type=password] { width: 100%; }
svg.ctl { width: 100%; height: auto; display: block; max-height: 420px; }
svg.ctl .shape { fill: var(--shape); stroke: var(--shape-line); stroke-width: 2; }
svg.ctl .btnp { fill: none; stroke: var(--shape-line); stroke-width: 2; }
svg.ctl .btnp.on { fill: var(--on); stroke: var(--on); }
svg.ctl text { fill: var(--muted); font-size: 12px; text-anchor: middle; pointer-events: none; }
svg.ctl .trk { fill: var(--bg); stroke: var(--shape-line); }
svg.ctl .fill { fill: var(--on); }
svg.ctl .dot { fill: var(--accent); stroke: var(--fg); stroke-width: 1.5; }
svg.ctl .finger { fill: var(--bad); opacity: .85; }
canvas { max-width: 100%; display: block; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); }
.bar { height: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; }
.bar.ok > i { background: var(--ok); } .bar.bad > i { background: var(--bad); }
.nums { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 4px 12px; }
.nums div { display: flex; justify-content: space-between; gap: 6px; } .nums b { font-variant-numeric: tabular-nums; font-weight: 500; }
pre.hexdump { margin: 0; white-space: pre-wrap; word-break: break-all; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .8rem; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.chip.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.stat { font-size: 1.6rem; font-weight: 700; }
details summary { cursor: pointer; min-height: 36px; display: flex; align-items: center; }
@media (min-width: 1100px) { .tabs a kbd { display: inline-block; margin-left: 6px; font-size: .7rem; opacity: .6; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; } }
@media (max-width: 480px) { .field { grid-template-columns: 80px 1fr 40px; } .kv { grid-template-columns: 1fr; gap: 0; } .kv dd { margin-bottom: 8px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.skip { position: absolute; left: -9999px; top: 0; z-index: 60; }
.skip:focus { left: 8px; top: 8px; }

/* compact menu on narrow screens */
@media (max-width: 1099px) {
  .tabs { overflow: visible; padding: 0 16px; }
  .tabs .navbtn { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 48px; font: inherit; font-weight: 600; background: none; border: 0; color: var(--fg); cursor: pointer; padding: 0; }
  .tabs .links { display: none; position: absolute; left: 0; right: 0; top: 100%; background: var(--card); border-bottom: 1px solid var(--line); padding: 8px 16px 12px; grid-template-columns: 1fr 1fr; gap: 6px; box-shadow: 0 8px 16px #0004; }
  .tabs.open .links { display: grid; }
  .tabs .links a { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
  .tabs .links a.on { border-color: var(--accent); }
}

/* v4.5: header system pill, Device menu group */
.pill.sys { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; }
.pill.sys .mb { width: 6px; height: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 2px; display: inline-flex; align-items: flex-end; overflow: hidden; }
.pill.sys .mb i { display: block; width: 100%; background: var(--accent); }
.pill.sys .mb i.hot { background: var(--bad); }
.tabs .grp { align-self: center; padding: 0 6px 0 14px; margin-left: 6px; border-left: 1px solid var(--line); font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); white-space: nowrap; }
@media (max-width: 1099px) { .tabs .grp { grid-column: 1 / -1; border: 0; padding: 6px 2px 0; margin: 0; } }

/* v4.5: file manager */
.fdrop.over { outline: 2px dashed var(--accent); outline-offset: -6px; }
.fcrumbs { gap: 4px; margin-bottom: 10px; }
.fuse { max-width: 560px; } .fuse .bar { margin-bottom: 4px; }
.fprog { margin: 8px 0; } .fprog .bar { margin-top: 4px; }
.frow { display: grid; grid-template-columns: minmax(0, 1fr) 80px 140px 80px auto; gap: 4px 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.fname { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; text-align: left; padding: 6px 0; min-height: 44px; word-break: break-all; }
.facts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.fsize { text-align: right; }
.chip.prot { background: #9a6700; color: #fff; border-color: #9a6700; }
dialog.dlg.wide { width: min(900px, calc(100vw - 32px)); max-width: none; }
.fview, .fedit { width: 100%; max-height: 55vh; overflow: auto; margin: 0 0 8px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); font: .8rem/1.4 ui-monospace, Consolas, monospace; white-space: pre; }
.fedit { height: 50vh; resize: vertical; }
.fedit[hidden], .fview[hidden] { display: none; }
.flist { max-height: 45vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
.flrow { display: flex; gap: 8px; align-items: center; padding: 3px 0; flex-wrap: wrap; } .flrow .mono { flex: 1; word-break: break-all; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
@media (max-width: 700px) {
  .frow { grid-template-columns: minmax(0, 1fr) auto; }
  .frow .fname { grid-column: 1 / -1; }
  .frow .fdate { display: none; }
  .frow .fsize { text-align: left; }
  .frow .facts { grid-column: 1 / -1; justify-content: flex-start; }
}

/* v4.5: system monitor */
.tscroll { overflow-x: auto; }
.ttab { width: 100%; border-collapse: collapse; font-size: .85rem; }
.ttab th, .ttab td { text-align: left; padding: 4px 10px 4px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.thbtn { font: inherit; font-weight: 600; background: none; border: 0; color: var(--fg); cursor: pointer; padding: 6px 0; min-height: 36px; }
.ttab td.lowstack { color: var(--bad); font-weight: 700; }

/* shell status bar: page out of date, link to the box lost */
#sysbar { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
#sysbar .notice { margin: 12px 0 0; display: flex; gap: 8px 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
#sysbar .notice.info { border-color: var(--accent); color: var(--fg); }

/* choice cards: a button with a title and one line saying when to use it */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 10px; }
.choices .btn { flex-direction: column; align-items: flex-start; justify-content: flex-start; text-align: left; height: auto; padding: 12px 14px; gap: 4px; }
.choices .btn small { font-weight: 400; opacity: .85; font-size: .85rem; line-height: 1.35; }
.empty .steps { text-align: left; max-width: 520px; margin: 12px auto 0; padding-left: 22px; } .empty .steps li { margin: 6px 0; }
[hidden] { display: none !important; }
#view:focus-visible { outline: none; } /* focus is moved here on a view change; the ring is for controls */

/* header help button */
.topr { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.helpbtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; min-width: 44px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--fg); text-decoration: none; font-weight: 600; }
.helpbtn:hover { border-color: var(--accent); }
.helpbtn .q { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-fg); font-size: .85rem; }
@media (max-width: 480px) { .helpbtn span.lbl { display: none; } .helpbtn { padding: 0; } }

/* help view */
.hp-tools { margin: 12px 0 6px; }
.hp-sec { margin: 22px 0 10px; }
.hp-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin: 0 0 8px; scroll-margin-top: 64px; min-width: 0; }
.hp-item.open { border-color: var(--accent); }
.hp-leaf { background: var(--bg); margin: 8px 0 0; }
.hp-h { margin: 0; font-size: 1rem; }
.hp-mod > .hp-h { font-size: 1.1rem; }
.hp-btn { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 8px; width: 100%; min-height: 48px; padding: 10px 14px; cursor: pointer; font-weight: 600; border-radius: 12px; }
.hp-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hp-btn:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.hp-t { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.hp-btn::after { content: ""; flex: none; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; }
.hp-item.open > .hp-h > .hp-btn::after { transform: rotate(45deg); }
.hp-n { font-weight: 400; font-size: .8rem; white-space: nowrap; }
.hp-badges { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.hp-body { padding: 0 14px 14px; overflow-wrap: anywhere; }
.hp-body h4 { margin: 14px 0 4px; font-size: .9rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hp-body p { margin: 6px 0; }
.hp-steps, .hp-list { margin: 6px 0; padding-left: 22px; }
.hp-steps li, .hp-list li { margin: 4px 0; }
.hp-body .row { margin-top: 12px; }
.hp-b-writes { border-color: var(--warn); color: var(--warn); }
.hp-b-temp { border-color: var(--ok); color: var(--ok); }
.hp-b-usb, .hp-b-bench { color: var(--fg); }
.hp-leaves { margin-top: 12px; }
