/* BabelStone-derived fallback for the Unicode legacy-computing blocks used by
 * ANSI art in serial logs. System monospace fonts treat these as .notdef. */
@font-face {
  font-family: "Linkr Legacy Computing";
  src: url("./fonts/linkr-legacy-computing.woff2?v=20261030") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+1CC00-1CEBF, U+1FB00-1FBFF;
}

:root {
  color-scheme: dark;
  /* Edge-to-edge safe areas. Android 15+ forbids fitting the window above the
   * system bars, and the WebView does not report env(safe-area-inset-*) for the
   * status and navigation bars (measured 0 on Chromium 141). Capacitor's
   * SystemBars plugin injects the real WindowInsets as --safe-area-inset-*,
   * so prefer that and keep env() for iOS and plain browsers. */
  --safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  --safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --safe-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  --bg: #090d14;
  --bg-glow-1: rgba(63, 200, 138, 0.09);
  --bg-glow-2: rgba(80, 130, 240, 0.07);
  --panel: #11161f;
  --panel-2: #151b26;
  --panel-3: #1c2330;
  --text: #e8eef7;
  --muted: #8d9bb0;
  --line: #242d3d;
  --line-soft: #1c2431;
  --line-strong: #33405a;
  --placeholder: #7b8ba1;
  --accent: #3fc88a;
  --accent-strong: #6fe0ab;
  --accent-ink: #052517;
  --primary-grad: linear-gradient(135deg, #4dd596, #2fb377);
  --focus: #7aa8f8;
  --danger: #f2777c;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow:
    0 8px 24px rgba(2, 6, 16, 0.42),
    0 2px 6px rgba(2, 6, 16, 0.28);
  --terminal: #05080d;
  --input-bg: #0e131c;
  --btn-hover: #232c3d;
  /* The floating selection Copy pill sits over live terminal text, so it needs
   * its own opaque surface: skin-v2 makes --panel-3 translucent glass. */
  --selection-copy-bg: #1f2735;
  --selection-copy-border: rgba(255, 255, 255, 0.22);
  --selection-copy-text: #eef4fc;
  --selection-copy-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
  --font-mono:
    ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", "Linkr Legacy Computing", monospace;
  --layout-gap: clamp(12px, 1vw, 20px);
  --layout-gutter: clamp(10px, 1.25vw, 24px);
  --sidebar-width: clamp(300px, 22vw, 420px);
}

/* ---------- Light theme ---------- */
[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2f7;
  --bg-glow-1: rgba(47, 158, 99, 0.08);
  --bg-glow-2: rgba(59, 130, 246, 0.06);
  --panel: #ffffff;
  --panel-2: #f6f8fb;
  --panel-3: #e9eef5;
  --text: #0f1c2e;
  --muted: #5c6a82;
  --line: #dbe3ee;
  --line-soft: #e7edf5;
  --line-strong: #c3cfdf;
  --placeholder: #5a6a80;
  --accent: #1f9d64;
  --accent-strong: #157a4c;
  --accent-ink: #ffffff;
  --primary-grad: linear-gradient(135deg, #2fb377, #1f9d64);
  --focus: #3b82f6;
  --danger: #dc3434;
  --shadow:
    0 8px 24px rgba(15, 35, 70, 0.1),
    0 2px 6px rgba(15, 35, 70, 0.06);
  --terminal: #f8fafc;
  --input-bg: #ffffff;
  --btn-hover: #e4ebf4;
  --selection-copy-bg: #ffffff;
  --selection-copy-border: rgba(15, 32, 56, 0.22);
  --selection-copy-text: #0f1c2e;
  --selection-copy-shadow: 0 6px 20px rgba(15, 35, 70, 0.24);
}

/* ---------- Header right cluster ---------- */
.top-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
  flex-wrap: wrap;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-3);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.01em;
  transition: transform 0.06s ease, border-color 0.15s ease,
    background 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--accent);
  background: var(--panel-2);
}

.icon-btn:active {
  transform: translateY(1px);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.icon-sun,
.icon-moon {
  display: inline-block;
}

[data-theme="dark"] .icon-moon {
  display: none;
}

[data-theme="light"] .icon-sun {
  display: none;
}

/* Light theme: soften the terminal header gradient */
[data-theme="light"] .terminal-head {
  background: linear-gradient(180deg, #ffffff, #f2f5f9);
  border-bottom-color: var(--line);
}

[data-theme="light"] .terminal-output .xterm-viewport {
  background: var(--terminal) !important;
}

/* The mouse pointer belongs to the operating system, and the light theme is
 * nearly all white surfaces -- the terminal body is #f8fafc, the header is a
 * white gradient. A white pointer (the Windows default, and every white cursor
 * scheme) all but disappears there; the dark theme has no such problem, and it
 * keeps the system pointer. Windows is also where this shows up first, because
 * the theme follows the system preference and Windows defaults to light.
 *
 * So the light theme supplies its own pointers, taken from the deepin macaron
 * cursor theme (CC-BY-4.0, UnionTech Software Technology Co., Ltd; see
 * vendor/macaron-cursors/README.md, which the licence requires to stay). They
 * are teal with a dark outline and a pale halo, which is what makes them
 * readable on white regardless of the system cursor scheme.
 *
 * The hotspots come from the theme and are recorded in
 * vendor/macaron-cursors/cursors.json; a test keeps the two in step, because a
 * wrong hotspot points the click a few pixels off the arrow's tip and nothing
 * else would notice.
 *
 * One size, 32px, plain url() -- no image-set. Chromium parses the unprefixed
 * function inside `cursor` but does not use it for the pointer, and then falls
 * back to the keyword at the end of the declaration, which looks exactly like
 * these rules not applying at all. 32px is also the size MDN recommends:
 * Chromium and Firefox cap cursors at 128x128, but anything above 32x32 tends to
 * be refused or downscaled on a high-DPI screen. */
[data-theme="light"],
[data-theme="light"] .terminal-output .xterm-viewport {
  cursor: url("./vendor/macaron-cursors/left_ptr-32.png") 3 2, default;
}

/* Over the terminal, where xterm already asks for cursor: text. */
[data-theme="light"] .terminal-output .xterm {
  cursor: url("./vendor/macaron-cursors/xterm-32.png") 15 15, text;
}

/* And the hand, on the controls that ask for it. */
[data-theme="light"] :is(button, summary, a[href], select,
  input[type="checkbox"], input[type="radio"], [role="button"]):not(:disabled) {
  cursor: url("./vendor/macaron-cursors/hand2-32.png") 12 2, pointer;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  /* Mobile engines otherwise inflate small text after a viewport change, so
   * the same page opens at a different type scale on Edge and Firefox. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 12% -8%, var(--bg-glow-1), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, var(--bg-glow-2), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

::selection {
  background: rgba(63, 200, 138, 0.3);
}

[data-theme="light"] ::selection {
  background: rgba(47, 158, 99, 0.22);
}

button {
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Scrollbars ---------- */
/* Chromium drops every ::-webkit-scrollbar rule below as soon as the element
 * sets `scrollbar-width` or `scrollbar-color`, so the drawer must not set them:
 * doing that silently replaced the inset thumb with the native bar, whose square
 * corners crossed the drawer's 18px radius. The terminal viewport keeps the pair
 * for Firefox and its bar lives inside a square surface anyway. */
.xterm-viewport {
  scrollbar-color: var(--panel-3) transparent;
  scrollbar-width: thin;
}

.controls::-webkit-scrollbar,
.xterm-viewport::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}

.controls::-webkit-scrollbar-track,
.xterm-viewport::-webkit-scrollbar-track {
  background: transparent;
}

/* --panel-3 is lighter than the panel in the light theme: the thumb was there
 * but invisible on the one surface that actually renders it. */
.controls::-webkit-scrollbar-thumb,
.xterm-viewport::-webkit-scrollbar-thumb {
  background: var(--line);
  background-clip: padding-box;
  border: 3px solid transparent;
  border-radius: 999px;
}

.controls::-webkit-scrollbar-thumb:hover,
.xterm-viewport::-webkit-scrollbar-thumb:hover {
  background: var(--line-strong);
  background-clip: padding-box;
  border: 3px solid transparent;
}

/* Up to the drawer's touch layout the bar overlays instead of reserving a lane:
 * ten pixels there pushed the six settings tabs under their 44px touch floor at
 * 320px wide. Fingers scroll the drawer anyway. */
@media (max-width: 900px) {
  .controls::-webkit-scrollbar {
    height: 0;
    width: 0;
  }
}

/* ---------- Layout ---------- */
.app-shell {
  display: grid;
  grid-template-columns: minmax(0, var(--sidebar-width)) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  gap: var(--layout-gap);
  width: 100%;
  /* vh fallback: Android WebViews before Chrome 108 reject dvh, which would
   * leave the shell heightless and let terminal rows stretch the whole page. */
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding:
    max(var(--layout-gutter), var(--safe-top))
    max(var(--layout-gutter), var(--safe-right))
    max(var(--layout-gutter), var(--safe-bottom))
    max(var(--layout-gutter), var(--safe-left));
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand > div {
  min-width: 0;
}

.logo {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #fff;
  background: var(--primary-grad);
  box-shadow:
    0 6px 16px rgba(47, 179, 119, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.support-text {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

/* ---------- Status pill ---------- */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}

.status-dot {
  position: relative;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--danger);
}

.status-dot.connected {
  background: var(--accent-strong);
}

.status-dot.connected::after {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(111, 224, 171, 0.65);
  border-radius: 999px;
  content: "";
  animation: pulse-ring 1.8s ease-out infinite;
}

.status-pill:has(.status-dot.connected) {
  border-color: rgba(63, 200, 138, 0.45);
  color: var(--text);
}

@keyframes pulse-ring {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  75%,
  100% {
    opacity: 0;
    transform: scale(2.6);
  }
}

/* ---------- Controls column ---------- */
.controls {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.card {
  --card-pad: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: var(--shadow);
  padding: 16px;
  transition: border-color 0.2s ease;
}

.card:hover {
  border-color: var(--line-strong);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-title .dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
}

/* ---------- Transport switch ---------- */
.transport-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 12px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--input-bg);
}

.ts-btn {
  height: 30px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background 0.15s ease, color 0.15s ease,
    border-color 0.15s ease;
}

.ts-btn:hover:not(:disabled):not(.active) {
  color: var(--text);
}

.ts-btn.active {
  border-color: var(--line);
  background: var(--panel-3);
  color: var(--accent-strong);
}

.ts-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.ws-host-field {
  margin-bottom: 12px;
}

.ws-host-field[hidden] {
  display: none;
}

.field-error {
  display: block;
  margin-top: 6px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.field-error[hidden] {
  display: none;
}

input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 16%, transparent);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-3);
  color: var(--text);
  padding: 0 13px;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.06s ease, border-color 0.15s ease,
    background 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--btn-hover);
}

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.btn-primary {
  border-color: transparent;
  background: var(--primary-grad);
  color: var(--accent-ink);
  box-shadow:
    0 6px 16px rgba(47, 179, 119, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #5fe0a4, #36c184);
  border-color: transparent;
  box-shadow:
    0 8px 20px rgba(47, 179, 119, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.connect-icon[hidden] {
  display: none;
}

.btn-soft {
  background: var(--panel-2);
}

.btn-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.btn-grid.compact {
  margin-top: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.btn-grid.compact.two-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.btn-grid.compact.wifi-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wifi-actions .btn,
.diagnostics-button {
  min-height: 44px;
  height: auto;
  padding-block: 8px;
}

.diagnostics-button {
  width: 100%;
  margin-top: 10px;
}

.diagnostics-card {
  padding: 0;
}

.diagnostics-summary {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  cursor: pointer;
  list-style: none;
}

.diagnostics-summary::-webkit-details-marker {
  display: none;
}

.diagnostics-summary .card-title {
  margin: 0;
}

.diagnostics-summary::after {
  width: 8px;
  height: 8px;
  margin-left: 12px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  content: "";
  transform: rotate(45deg);
  transition: transform 0.18s ease;
}

.diagnostics-card[open] .diagnostics-summary::after {
  transform: rotate(225deg);
}

.diagnostics-summary:hover {
  background: var(--panel-3);
}

.diagnostics-summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -3px;
}

.diagnostics-content {
  padding: 0 14px 14px;
}

.diagnostics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.diagnostic-item {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--panel-3);
}

.diagnostic-item span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.diagnostic-item strong {
  display: block;
  overflow-wrap: anywhere;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

/* ---------- Fields ---------- */
.field {
  display: block;
  margin-bottom: 12px;
}

/* Explicit field layout must not override capability/transport visibility. */
#uartModeField[hidden],
#uartTransportStatus[hidden] {
  display: none;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.field-hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
}

.font-preview {
  display: block;
  margin-top: 7px;
  padding: 7px 9px;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  background: var(--panel-3);
  color: var(--accent-strong);
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.field-row input {
  min-width: 0;
}

.field-row .btn {
  min-width: 64px;
  white-space: nowrap;
}

.password-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

.password-toggle {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
}

.wifi-form .field {
  margin-bottom: 10px;
}

.wifi-connected-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 12px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-3);
}

.wifi-connected-summary[hidden],
.wifi-actions .btn[hidden] {
  display: none;
}

.wifi-connected-network {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.wifi-connected-mark {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent);
}

.wifi-connected-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

.wifi-connected-label,
.wifi-device-address > span {
  color: var(--muted);
  font-size: 11px;
}

.wifi-connected-copy strong {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wifi-device-address {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 2px;
}

.wifi-device-address output {
  color: var(--accent-strong);
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  user-select: all;
}

.wifi-network-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 2px;
}

.wifi-network-list:empty {
  display: none;
}

.wifi-network {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  max-width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-3);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  text-align: left;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.wifi-network:hover,
.wifi-network:focus-visible {
  border-color: var(--accent);
  background: var(--btn-hover);
}

.wifi-network-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wifi-network-rssi {
  flex: none;
  color: var(--accent-strong);
  font-family: var(--font-mono);
  font-size: 11px;
}

.wifi-feedback {
  min-height: 17px;
}

input,
select,
textarea {
  height: 36px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  padding: 0 12px;
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background-color 0.25s ease;
}

textarea {
  height: auto;
  min-height: 84px;
  padding: 10px 12px;
  line-height: 1.5;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--placeholder);
}

#wifiPasswordInput,
#wifiSsidInput {
  min-height: 44px;
  height: 44px;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--line-strong);
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(122, 168, 248, 0.22);
}

/* Shown only when the terminal never came up; set up by the inline script at the
 * end of index.html. It stands in the terminal's place so a failed boot says
 * something instead of leaving the page blank -- and it has to work when the
 * stylesheet did load while a module did not, which is the usual case. */
.boot-notice {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* An author display setting beats the user agent's rule for [hidden]. */
.boot-notice[hidden] {
  display: none;
}

.terminal-output:focus-within {
  box-shadow: inset 0 0 0 2px var(--focus);
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

/* A checked box reads as a mark, not a filled chip. The native control paints
 * the accent colour across the whole square (solid in Chromium, a pale tint with
 * a coloured tick in WebKit), which sat on the panel like a stray highlight next
 * to the label. Nothing here is accent-filled: the box stays transparent, the
 * border is a hairline and only the tick carries the colour.
 *
 * The 4px radius is deliberate: a 16px control cannot take the 10px control
 * radius without turning into a lozenge. */
.check input {
  appearance: none;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: transparent;
  display: grid;
  place-content: center;
  cursor: pointer;
}

.check input::after {
  content: "";
  width: 8px;
  height: 4px;
  border-left: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg) translate(1px, -1px);
  opacity: 0;
}

.check input:checked::after {
  opacity: 1;
}

.check input:hover {
  border-color: var(--muted);
}

.check input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.check input:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ---------- Work panel ---------- */
.workpanel {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  min-width: 0;
}

.terminal-card {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--terminal);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.terminal-card:fullscreen,
.terminal-card.terminal-fullscreen-fallback {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.terminal-card:fullscreen {
  background: var(--terminal);
}

.terminal-card.terminal-fullscreen-fallback {
  position: fixed;
  inset: 0;
  z-index: 1000;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

body.terminal-fullscreen-fallback {
  overflow: hidden;
}

.terminal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, var(--panel-3), var(--panel-2));
}

.term-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
}

.term-led {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.terminal-card:has(.terminal-output.connected) .term-led {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(63, 200, 138, 0.7);
}

.term-hint {
  display: none;
}

.terminal-output {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--terminal);
  contain: layout;
}

.terminal-output .xterm {
  box-sizing: border-box;
  height: 100%;
  /* FitAddon subtracts xterm padding, not its parent's padding. */
  padding: 10px;
  /* xterm 6 has no touch scrolling and its DOM rows do not take pointer
   * events; the terminal handles vertical drags itself in app.js. */
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-touch-callout: none;
}

/* The rows are real text, so a WebView long press would start its own
 * selection and take the gesture away from the xterm selection the app
 * drives. The app copies the selection itself. */
.terminal-output,
.terminal-output .xterm-rows,
.terminal-output .xterm-screen,
.terminal-output .xterm-helper-textarea {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* The page in a browser keeps the platform's own text selection and copy
 * menu; only the native shells draw the custom draggable dots. */
.browser-terminal-selection .terminal-output,
.browser-terminal-selection .terminal-output .xterm,
.browser-terminal-selection .terminal-output .xterm-rows,
.browser-terminal-selection .terminal-output .xterm-screen {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

.terminal-output .xterm-viewport {
  background: var(--terminal) !important;
}

.terminal-output .xterm-scrollable-element {
  background: var(--terminal) !important;
}

/* xterm sets the scrollbar's inline width from overviewRuler.width (see
 * initTerminal), so this only insets the painted thumb: the transparent border
 * keeps the full track tappable while the visible slider stays a thin pill. */
.terminal-output .xterm-scrollable-element > .scrollbar > .slider {
  box-sizing: border-box;
  border: 2px solid transparent;
  border-radius: 999px;
  /* xterm's injected `background:` shorthand resets the clip, and it is added
   * after this stylesheet, so this one property has to win explicitly. */
  background-clip: padding-box !important;
}

/* The overview ruler borrows the same width option, but this terminal has no
 * decorations, so its canvas would only paint a hairline over the slider. */
.terminal-output .xterm-decoration-overview-ruler {
  display: none;
}

/* ---------- Integrated terminal input ---------- */
.terminal-input-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 6px 10px 6px 14px;
  border-top: 1px solid var(--line-soft);
  background: var(--panel-2);
}

.terminal-input-hint {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.terminal-output.connected + .terminal-input-bar .terminal-input-hint {
  color: var(--accent-strong);
}

.terminal-input-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.terminal-break {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 5px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ---------- Mobile connect entry (P0: primary action always reachable) ---------- */
.mobile-connect {
  display: none;
}

/* The panel holds the primary connect action; when it is collapsed, this top bar
 * entry is the only way to reach it — on wide fine-pointer layouts too, not just
 * touch or narrow windows. */
.app-shell.controls-hidden .top-actions .mobile-connect {
  display: inline-flex;
  flex: 0 0 auto;
  min-width: 104px;
}

@media (max-width: 900px) {
  .mobile-connect {
    display: inline-flex;
  }

  .terminal-output.connected + .terminal-input-bar .mobile-connect {
    display: none;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .top-right {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .controls {
    grid-column: 1;
    overflow: visible;
  }

  .workpanel {
    grid-column: 1;
    min-height: 0;
    overflow: hidden;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding:
      max(10px, var(--safe-top))
      max(10px, var(--safe-right))
      max(10px, var(--safe-bottom))
      max(10px, var(--safe-left));
  }

  .topbar {
    gap: 8px;
    padding: 11px 12px;
    border-radius: var(--radius);
  }

  .brand {
    gap: 10px;
  }

  .logo {
    width: 34px;
    height: 34px;
    border-radius: 9px;
  }

  h1 {
    font-size: 16px;
  }

  .support-text {
    margin-top: 1px;
    font-size: 11.5px;
  }

  .top-right {
    gap: 8px;
    flex-wrap: nowrap;
  }

  .top-actions {
    gap: 6px;
    flex-wrap: nowrap;
  }

  .top-actions .icon-btn {
    width: 44px;
    padding: 0;
    justify-content: center;
  }

  #themeButton .btn-label {
    display: none;
  }

  .status-pill {
    min-width: 0;
    padding: 6px 10px;
    font-size: 12.5px;
  }

  .btn-grid {
    grid-template-columns: 1fr;
  }

  .terminal-input-bar {
    align-items: flex-start;
  }

  .terminal-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 7px;
    padding: 8px 10px;
  }

  .term-tools {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: nowrap;
  }

  .term-hint {
    margin-left: auto;
  }

  .terminal-output .xterm {
    padding: 8px;
  }

  .terminal-input-bar {
    min-height: 50px;
    padding: 5px 7px 5px 10px;
  }

  .terminal-input-hint {
    font-size: 11.5px;
  }

  .wifi-connected-summary {
    align-items: stretch;
    flex-direction: column;
  }

  .wifi-device-address {
    align-items: flex-start;
  }
}

/* ---------- Sidebar collapse (desktop) ---------- */
.app-shell.controls-hidden {
  grid-template-columns: 0 1fr;
}

@media (min-width: 901px) {
  .app-shell {
    transition: grid-template-columns 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .app-shell.controls-hidden .controls {
    visibility: hidden;
    overflow: hidden;
    padding-right: 0;
    transition: visibility 0s 0.28s;
  }
}

@media (max-width: 900px) {
  .app-shell.controls-hidden .controls {
    display: none;
  }
}

/* ---------- Cheat sheet / reference ---------- */
details.ref {
  border-top: 1px solid var(--line-soft);
  margin-top: 10px;
  padding-top: 8px;
}

details.ref:first-of-type {
  border-top: none;
  margin-top: 4px;
  padding-top: 0;
}

details.ref summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text);
  user-select: none;
}

details.ref summary::-webkit-details-marker {
  display: none;
}

details.ref summary::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--muted);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  transition: transform 0.15s ease;
}

details.ref[open] summary::before {
  transform: rotate(90deg);
}

.ref-body {
  margin-top: 8px;
}

.ref-group {
  margin-bottom: 12px;
}

.ref-group:last-child {
  margin-bottom: 0;
}

.ref-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.ref-item {
  display: flex;
  width: 100%;
  gap: 10px;
  align-items: baseline;
  padding: 5px 0;
  border-bottom: 1px dashed var(--line-soft);
}

button.ref-item {
  appearance: none;
  border-top: 0;
  border-right: 0;
  border-left: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}

.ref-item[data-cmd] {
  margin-inline: -6px;
  padding-inline: 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.ref-item[data-cmd]:hover:not(:disabled) {
  background: var(--panel-3);
}

.ref-item[data-cmd]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.ref-item[data-cmd]:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.ref-item:last-child {
  border-bottom: none;
}

.ref-cmd {
  flex: none;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 7px;
  color: var(--accent-strong);
  white-space: nowrap;
}

.ref-desc {
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- Mobile drawer ---------- */
.drawer-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease;
}

@media (max-width: 900px) {
  .app-shell .controls {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    width: min(86vw, 340px);
    padding: 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--panel);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow);
    transform: translate3d(-100%, 0, 0);
    visibility: hidden;
    will-change: transform;
    transition: transform 0.24s cubic-bezier(0.22, 0.61, 0.36, 1),
      visibility 0s 0.24s;
  }

  .app-shell.sidebar-open .controls {
    transform: translate3d(0, 0, 0);
    visibility: visible;
    transition-delay: 0s;
  }

  .app-shell.sidebar-open .drawer-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .workpanel {
    min-height: 0;
    gap: 8px;
  }

  .terminal-card {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
  }

  .presets {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .presets::-webkit-scrollbar {
    display: none;
  }

  .preset-chip {
    flex: 0 0 auto;
  }

  .statusbar {
    flex: 0 0 auto;
    gap: 10px;
    padding: 8px 10px;
  }
}

body.drawer-open {
  overflow: hidden;
}

/* ---------- Theme transition ---------- */
body,
.topbar,
.card,
.terminal-card,
.terminal-input-bar,
.statusbar,
.controls,
.btn,
.icon-btn,
.preset-chip,
.term-tool {
  transition: background-color 0.25s ease, border-color 0.25s ease,
    color 0.2s ease;
}

/* ---------- Drawer header (mobile only) ---------- */
.drawer-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
}

.drawer-head .icon-close {
  height: 34px;
  width: 34px;
  padding: 0;
  justify-content: center;
}

.drawer-head-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.drawer-head-actions .icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
}

/* ---------- Connect spinner ---------- */
.spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 999px;
  animation: spin 0.7s linear infinite;
}

.btn.loading .spinner {
  display: inline-block;
}

.btn.loading svg {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Terminal tools ---------- */
.term-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.term-tool {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-3);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.fullscreen-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#fullscreenBtn .icon-collapse {
  display: none;
}

#fullscreenBtn.active .icon-expand {
  display: none;
}

#fullscreenBtn.active .icon-collapse {
  display: block;
}

.term-tool:hover {
  border-color: var(--accent);
  background: var(--btn-hover);
}

.term-tool.active {
  border-color: var(--accent);
  background: var(--panel-2);
  color: var(--accent-strong);
}

/* ---------- Quick-send presets ---------- */
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease,
    background 0.15s ease, transform 0.15s ease;
}

.preset-chip:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-1px);
}

.preset-chip[data-danger="true"]:not(:disabled) {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--line));
  color: var(--danger);
}

.preset-chip[data-danger="true"]:hover:not(:disabled) {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, var(--panel-2));
  color: var(--danger);
}

.preset-chip:active:not(:disabled) {
  transform: translateY(0);
}

.preset-chip:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .presets {
    flex-wrap: nowrap;
  }
}

.preset-chip:focus-visible,
.term-tool:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Status bar ---------- */
.statusbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: var(--shadow);
  font-size: 12.5px;
  letter-spacing: 0.01em;
  color: var(--muted);
}

@media (min-width: 521px) {
  .statusbar .sb-item + .sb-item {
    position: relative;
    padding-left: 17px;
  }

  .statusbar .sb-item + .sb-item::before {
    position: absolute;
    top: 50%;
    left: 0;
    width: 1px;
    height: 14px;
    background: var(--line);
    content: "";
    transform: translateY(-50%);
  }

  .statusbar .sb-item.sb-state::before {
    display: none;
  }
}

.statusbar .sb-item b {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.statusbar .sb-state {
  margin-left: auto;
  font-weight: 600;
  color: var(--text);
}

/* ---------- Device name in pill ---------- */
.device-name {
  margin-left: 8px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

/* ---------- Cheat hint ---------- */
.ref-hint {
  margin: 10px 0 0;
  font-size: 11.5px;
  font-style: italic;
  color: var(--muted);
}

/* ---------- Toasts ---------- */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  max-width: 90vw;
  padding: 10px 16px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--panel-3);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

@supports (backdrop-filter: blur(6px)) {
  .toast {
    background: color-mix(in srgb, var(--panel-3) 88%, transparent);
    backdrop-filter: blur(6px);
  }
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-error {
  border-color: var(--danger);
}

/* ---------- Password visibility toggle ---------- */
.password-toggle .icon-eye-off {
  display: none;
}

.password-toggle[aria-pressed="true"] .icon-eye {
  display: none;
}

.password-toggle[aria-pressed="true"] .icon-eye-off {
  display: block;
}

/* ---------- Touch targets (coarse pointers) ---------- */
@media (pointer: coarse) {
  .btn {
    height: auto;
    min-height: 44px;
    padding-block: 8px;
  }

  .icon-btn {
    height: 44px;
  }

  .ts-btn {
    height: 44px;
  }

  input,
  select {
    height: 44px;
  }

  .check input {
    width: 20px;
    height: 20px;
  }

  .term-tool {
    min-width: 44px;
    height: 44px;
  }

  .preset-chip {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  .terminal-break {
    min-height: 44px;
  }

  .ref-item[data-cmd] {
    padding-block: 10px;
  }

  details.ref summary,
  .diagnostics-summary {
    min-height: 44px;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* ---------- Mobile drawer header visible ---------- */
@media (max-width: 900px) {
  .drawer-head {
    display: flex;
  }

  .term-tools {
    gap: 5px;
  }
}

/* ---------- Compact phone terminal ---------- */
@media (max-width: 520px) {
  .app-shell {
    gap: 6px;
    padding:
      max(6px, var(--safe-top))
      max(6px, var(--safe-right))
      max(6px, var(--safe-bottom))
      max(6px, var(--safe-left));
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 7px 8px;
  }

  .brand {
    gap: 8px;
  }

  .logo {
    width: 30px;
    height: 30px;
    border-radius: 8px;
  }

  .logo svg {
    width: 17px;
    height: 17px;
  }

  h1 {
    font-size: 15px;
  }

  .support-text,
  .status-pill {
    display: none;
  }

  .top-right,
  .top-actions {
    width: auto;
  }

  .top-right {
    margin-left: auto;
  }

  .top-actions {
    gap: 5px;
  }

  .top-actions .mobile-connect {
    display: inline-flex;
    flex: 0 0 auto;
    width: auto;
    min-width: 104px;
    height: 40px;
    min-height: 40px;
    margin-left: 0;
    padding: 0 12px;
  }

  #themeButton,
  #langButton {
    display: none;
  }

  .top-actions .icon-btn {
    width: 40px;
    height: 40px;
    min-height: 40px;
  }

  .workpanel {
    gap: 5px;
  }

  .terminal-head {
    min-height: 42px;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 4px 6px 4px 9px;
  }

  .term-title {
    flex: 0 0 auto;
    font-size: 11px;
  }

  .term-tools {
    width: auto;
    min-width: 0;
    margin-left: auto;
    gap: 4px;
  }

  .term-tool {
    min-width: 34px;
    width: 34px;
    height: 34px;
    padding: 0 5px;
    font-size: 11px;
  }

  .term-hint {
    display: none;
  }

  .terminal-output .xterm {
    padding: 5px;
  }

  .terminal-input-bar {
    min-height: 36px;
    padding: 3px 5px 3px 8px;
  }

  .terminal-input-hint {
    font-size: 11px;
  }

  .terminal-break {
    height: 32px;
    min-height: 32px;
    padding: 3px 8px;
    font-size: 11px;
  }

  .presets {
    gap: 4px;
    padding-bottom: 0;
  }

  .preset-chip {
    min-height: 36px;
    padding: 4px 10px;
    font-size: 11px;
  }

  .statusbar {
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-size: 11.5px;
  }

  .statusbar .sb-item b {
    font-size: 11.5px;
  }
}

/* ---------- Mobile and tablet interaction layout ---------- */
.settings-tabs {
  display: none;
}

.settings-tab {
  min-width: 0;
  min-height: 44px;
  padding: 7px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 650;
  font-size: 12.5px;
}

.settings-tab.active {
  background: var(--panel-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.terminal-keyboard {
  display: none;
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12px;
}

@media (max-width: 1100px) {
  .settings-tabs {
    position: sticky;
    top: 0;
    z-index: 3;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 4px;
    flex: 0 0 auto;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel-2);
  }

  .controls[data-settings-active="connection"] [data-settings-page]:not([data-settings-page="connection"]),
  .controls[data-settings-active="terminal"] [data-settings-page]:not([data-settings-page="terminal"]),
  .controls[data-settings-active="network"] [data-settings-page]:not([data-settings-page="network"]) {
    display: none;
  }

  .terminal-keyboard {
    display: inline-flex;
  }
}

@media (min-width: 901px) and (max-width: 1100px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 38vw);
  }

  .app-shell.controls-hidden {
    grid-template-columns: minmax(0, 1fr) 0;
  }

  .controls {
    grid-column: 2;
    grid-row: 2;
    padding-right: 0;
  }

  .workpanel {
    grid-column: 1;
    grid-row: 2;
  }

  .mobile-connect {
    display: inline-flex;
  }

  .settings-tabs {
    top: -1px;
  }
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: row;
    align-items: center;
  }

  .top-right {
    width: auto;
    margin-left: auto;
    flex-wrap: nowrap;
  }

  .status-pill {
    display: none;
  }

  .controls {
    top: 0;
    right: 0;
    left: auto;
    width: min(440px, 68vw);
    padding:
      max(14px, var(--safe-top))
      max(14px, var(--safe-right))
      max(14px, var(--safe-bottom))
      max(14px, var(--safe-left));
    border-right: 0;
    border-left: 1px solid var(--line);
    transform: translateX(100%);
  }

  .drawer-head {
    position: sticky;
    top: 0;
    z-index: 5;
    flex: 0 0 auto;
    background: var(--panel);
  }

  .settings-tabs {
    top: 49px;
  }

  .app-shell.sidebar-open .controls {
    transform: translateX(0);
  }
}

@media (max-width: 600px) {
  .support-text,
  #themeButton,
  #langButton {
    display: none;
  }

  .controls {
    width: 100vw;
    padding:
      max(8px, var(--safe-top))
      max(8px, var(--safe-right))
      max(10px, var(--safe-bottom))
      max(8px, var(--safe-left));
    border-left: 0;
  }

  .drawer-head {
    min-height: 46px;
    margin-bottom: 0;
    padding: 3px 2px 8px;
  }

  .settings-tabs {
    top: 46px;
    margin-bottom: 2px;
  }

  .controls .card {
    --card-pad: 13px;
    padding: var(--card-pad);
    border-radius: 8px;
    box-shadow: none;
  }

  .controls [data-settings-page="connection"] .btn-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .terminal-keyboard,
  .terminal-break {
    width: 34px;
    height: 32px;
    min-height: 32px;
    justify-content: center;
    padding: 0;
  }

  .terminal-keyboard .btn-label {
    display: none;
  }

  .terminal-input-actions {
    gap: 4px;
  }

  .terminal-input-hint {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ---------- Soft keyboard workspace ---------- */
html.settings-drawer-layout .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

html.settings-drawer-layout .workpanel {
  grid-column: 1;
  grid-row: 2;
}

html.settings-drawer-layout .mobile-connect {
  display: inline-flex;
}

html.settings-drawer-layout .controls {
  position: fixed;
  top: max(12px, var(--safe-top));
  right: max(12px, var(--safe-right));
  bottom: max(12px, var(--safe-bottom));
  left: auto;
  z-index: 60;
  width: min(420px, calc(100vw - 32px));
  padding: 14px;
  overflow-y: auto;
  visibility: visible;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transform: translate3d(calc(100% + 32px), 0, 0);
  will-change: transform;
  transition: transform 0.24s cubic-bezier(0.22, 0.61, 0.36, 1);
}

html.settings-drawer-layout .app-shell.sidebar-open .controls {
  transform: translate3d(0, 0, 0);
}

html.settings-drawer-layout .drawer-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease;
}

html.settings-drawer-layout .app-shell.sidebar-open .drawer-backdrop {
  opacity: 1;
  pointer-events: auto;
}

html.settings-drawer-layout .drawer-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex: 0 0 auto;
  background: var(--panel);
}

html.settings-drawer-layout .settings-tabs {
  position: sticky;
  top: 49px;
  z-index: 3;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 4px;
  flex: 0 0 auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
}

html.settings-drawer-layout .controls[data-settings-active="connection"] [data-settings-page]:not([data-settings-page="connection"]),
html.settings-drawer-layout .controls[data-settings-active="terminal"] [data-settings-page]:not([data-settings-page="terminal"]),
html.settings-drawer-layout .controls[data-settings-active="network"] [data-settings-page]:not([data-settings-page="network"]) {
  display: none;
}

@media (max-width: 600px) {
  html.settings-drawer-layout .controls {
    top: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    padding:
      max(8px, var(--safe-top))
      max(8px, var(--safe-right))
      max(10px, var(--safe-bottom))
      max(8px, var(--safe-left));
    border: 0;
    border-radius: 0;
  }
}

html.soft-keyboard-open,
html.soft-keyboard-open body {
  height: 100%;
  overflow: hidden;
}

html.soft-keyboard-open .app-shell {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
  height: var(--terminal-viewport-height, 100vh);
  min-height: 0;
  padding:
    max(4px, var(--safe-top))
    max(6px, var(--safe-right))
    2px
    max(6px, var(--safe-left));
  overflow: hidden;
}

html.soft-keyboard-open .topbar,
html.soft-keyboard-open .controls,
html.soft-keyboard-open .presets,
html.soft-keyboard-open .statusbar,
html.soft-keyboard-open .drawer-backdrop {
  display: none;
}

html.soft-keyboard-open .workpanel {
  grid-column: 1;
  grid-row: 1;
  gap: 0;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

html.soft-keyboard-open .terminal-card {
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: var(--radius-sm);
  box-shadow: none;
}

/* Fullscreen cards are outside the workspace's sizing context. WebViews can
 * shrink visualViewport without changing the fixed/fullscreen layout height. */
html.soft-keyboard-open .terminal-card.terminal-fullscreen-fallback {
  height: var(--terminal-viewport-height, 100vh);
}

html.soft-keyboard-open .terminal-card:fullscreen {
  /* Browsers force native fullscreen height to 100% with a UA !important
   * rule. Reserve the keyboard-covered area inside that fixed outer box. */
  padding-bottom: max(0px, calc(100vh - var(--terminal-viewport-height, 100vh)));
}

/* A declaration containing var() can fail at computed-value time, after the
 * preceding fallback has been discarded. Gate the unsupported unit instead. */
@supports (height: 100dvh) {
  html.soft-keyboard-open .app-shell,
  html.soft-keyboard-open .terminal-card.terminal-fullscreen-fallback {
    height: var(--terminal-viewport-height, 100dvh);
  }
  html.soft-keyboard-open .terminal-card:fullscreen {
    padding-bottom: max(0px, calc(100dvh - var(--terminal-viewport-height, 100dvh)));
  }
}

html.soft-keyboard-open .terminal-head {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 3px 5px 3px 10px;
}

html.soft-keyboard-open .term-tools {
  width: auto;
  margin-left: auto;
  gap: 4px;
}

html.soft-keyboard-open #zoomOutBtn,
html.soft-keyboard-open #zoomInBtn,
html.soft-keyboard-open #fullscreenBtn,
html.soft-keyboard-open .term-hint {
  display: none;
}

html.soft-keyboard-open .term-tool {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
}

html.soft-keyboard-open .terminal-output {
  min-height: 0;
}

html.soft-keyboard-open .terminal-output .xterm {
  padding: 5px;
}

html.soft-keyboard-open .terminal-input-bar {
  flex: 0 0 auto;
  justify-content: flex-end;
  min-height: 36px;
  padding: 2px 4px;
}

html.soft-keyboard-open .terminal-input-hint,
html.soft-keyboard-open .terminal-keyboard {
  display: none;
}

html.soft-keyboard-open .terminal-input-actions {
  width: 100%;
  justify-content: flex-end;
}

html.soft-keyboard-open .terminal-output:not(.connected) + .terminal-input-bar {
  display: none;
}

/* Two-row accessory keyboard: fixed modifiers, then scrollable key groups. */
.terminal-card .terminal-input-bar {
  --terminal-key-size: clamp(44px, 5vw, 56px);
  flex: 0 0 auto;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  gap: 4px;
  padding: 6px 8px;
}

.terminal-card .terminal-input-actions {
  width: 100%;
  min-width: 0;
  align-items: flex-start;
  gap: 8px;
}

.terminal-key-group {
  display: grid;
  grid-template-columns: repeat(3, var(--terminal-key-size));
  grid-template-rows: repeat(2, 44px);
  flex: 0 0 auto;
  gap: 8px;
}

.terminal-modifiers {
  padding: 2px 0;
}

.terminal-key-pair {
  grid-template-columns: var(--terminal-key-size);
}

.terminal-key-scroll {
  display: flex;
  flex: 1 1 0;
  min-width: 0;
  align-items: flex-start;
  gap: 12px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  padding: 2px 0;
}

.terminal-card .terminal-key,
.terminal-card .terminal-keyboard {
  display: inline-flex;
  width: 100%;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  justify-content: center;
  padding: 0 2px;
  border-radius: 8px;
  background: var(--panel-3);
  font-family: var(--font-mono);
  font-size: clamp(11px, 1.2vw, 13px);
  white-space: nowrap;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.terminal-card .terminal-key[aria-pressed="true"] {
  color: var(--accent-ink);
  border-color: var(--accent);
  background: var(--accent);
}

.terminal-key:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -3px;
}

html.soft-keyboard-open .terminal-card .terminal-input-bar {
  padding: 4px;
}

html.soft-keyboard-open .terminal-card .terminal-keyboard {
  display: inline-flex;
}

/* Agent workspace shares the existing terminal; no second xterm or modal. */
#agentButton[hidden] { display: none; }
#agentButton {
  --agent-button-from: rgba(104, 142, 228, 0.1);
  --agent-button-to: rgba(157, 127, 214, 0.14);
  --agent-button-ink: #d9d4f4;
  --agent-button-film: rgba(255, 255, 255, 0.04);
  --agent-button-edge: rgba(184, 172, 227, 0.3);
  --agent-button-sheen: rgba(255, 255, 255, 0.16);
  color: var(--agent-button-ink);
  background: linear-gradient(135deg, var(--agent-button-from), var(--agent-button-to)) var(--agent-button-film);
  border-color: var(--agent-button-edge);
  box-shadow: inset 0 1px 0 var(--agent-button-sheen);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  backdrop-filter: blur(10px) saturate(120%);
  font-weight: 600;
  letter-spacing: 0;
}
[data-theme="light"] #agentButton {
  --agent-button-ink: #504571;
  --agent-button-film: rgba(255, 255, 255, 0.36);
  --agent-button-edge: rgba(121, 108, 171, 0.24);
  --agent-button-sheen: rgba(255, 255, 255, 0.92);
}
#agentButton:hover {
  --agent-button-from: rgba(104, 142, 228, 0.16);
  --agent-button-to: rgba(157, 127, 214, 0.2);
  border-color: rgba(143, 126, 201, 0.4);
}
#agentButton[aria-pressed="true"] {
  --agent-button-from: rgba(104, 142, 228, 0.22);
  --agent-button-to: rgba(157, 127, 214, 0.26);
  border-color: rgba(143, 126, 201, 0.5);
}
.terminal-workspace { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.agent-panel[hidden], .agent-terminal-peek[hidden] { display: none; }
.agent-panel { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; color: var(--text); background: var(--terminal); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
html.agent-mode, html.agent-mode body { height: 100%; overflow: hidden; }
html.agent-mode.settings-drawer-layout .app-shell {
  position: fixed;
  top: var(--agent-viewport-top, 0px);
  left: 0;
  width: 100%;
  height: var(--terminal-viewport-height, 100vh);
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
  padding: max(6px, var(--safe-top)) max(6px, var(--safe-right)) max(6px, var(--safe-bottom)) max(6px, var(--safe-left));
}
@supports (height: 100dvh) {
  html.agent-mode.settings-drawer-layout .app-shell {
    height: var(--terminal-viewport-height, 100dvh);
  }
}
html.agent-mode.settings-drawer-layout .topbar,
html.agent-mode.settings-drawer-layout .controls,
html.agent-mode.settings-drawer-layout .presets,
html.agent-mode.settings-drawer-layout .statusbar,
html.agent-mode.settings-drawer-layout .drawer-backdrop { display: none; }
html.agent-mode.settings-drawer-layout .workpanel { grid-column: 1; grid-row: 1; gap: 0; min-height: 0; }
html.agent-mode .terminal-workspace { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, .45fr) minmax(0, .55fr); gap: 8px; }
html.agent-mode .terminal-workspace[data-agent-layout="columns"] { grid-template-columns: minmax(0, 1.35fr) minmax(360px, 1fr); grid-template-rows: minmax(0, 1fr); }
html.agent-mode .terminal-card { height: 100%; min-width: 0; min-height: 0; }
html.agent-mode .terminal-head { min-height: 44px; padding: 2px 6px; flex: 0 0 auto; }
html.agent-mode .term-tool { min-width: 44px; min-height: 44px; height: 44px; }
html.agent-mode #fullscreenBtn, html.agent-mode #zoomOutBtn, html.agent-mode #zoomInBtn,
html.agent-mode .term-hint, html.agent-mode .terminal-input-hint { display: none; }
html.agent-mode .terminal-card .terminal-input-bar { padding: 4px; }
.agent-terminal-peek { min-height: 44px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: var(--panel-2); font: inherit; font-size: 13px; cursor: pointer; text-align: left; }
html.agent-keyboard-chat .terminal-workspace[data-agent-layout] { grid-template-columns: minmax(0, 1fr); grid-template-rows: 44px minmax(0, 1fr); }
html.agent-keyboard-chat #terminalCard { display: none; }
html.agent-keyboard-terminal .terminal-workspace[data-agent-layout="rows"] { grid-template-rows: minmax(0, .6fr) minmax(0, .4fr); }
html.agent-keyboard-terminal .agent-console { display: none; }
.agent-header, .agent-form { flex: 0 0 auto; padding: 6px 10px; }
.agent-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.agent-actions { display: flex; gap: 8px; justify-content: flex-end; }
.agent-panel .btn { min-height: 44px; padding-inline: 10px; }
.agent-settings[hidden], .settings-tab[hidden] { display: none; }
.agent-settings { flex: 0 0 auto; }
.agent-settings fieldset { padding: 0; margin: 0; border: 0; min-width: 0; }
.agent-settings input:not([type="checkbox"]):not([type="radio"]) { width: 100%; min-height: 44px; font-size: 16px; }
.agent-settings .btn { min-height: 44px; }
.agent-settings .field-hint { overflow-wrap: anywhere; }
#agentSettingsStatus:empty { display: none; }
#agentSettingsStatus.field-error { color: var(--danger); }
.controls.has-agent-settings .settings-tabs {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  gap: 4px; flex: 0 0 auto; padding: 4px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--panel-2);
}
.controls.has-agent-settings[data-settings-active="connection"] [data-settings-page]:not([data-settings-page="connection"]),
.controls.has-agent-settings[data-settings-active="terminal"] [data-settings-page]:not([data-settings-page="terminal"]),
.controls.has-agent-settings[data-settings-active="network"] [data-settings-page]:not([data-settings-page="network"]),
.controls.has-agent-settings[data-settings-active="ai"] [data-settings-page]:not([data-settings-page="ai"]) { display: none; }
/* Keep the shared drawer usable above the soft keyboard, including Agent mode. */
html.settings-drawer-layout .app-shell.sidebar-open .controls {
  display: flex;
  top: calc(var(--settings-viewport-top, 0px) + max(12px, var(--safe-top)));
  bottom: auto;
  height: calc(var(--terminal-viewport-height, 100vh) - max(12px, var(--safe-top)) - max(12px, var(--safe-bottom)));
}
@media (max-width: 600px) {
  html.settings-drawer-layout .app-shell.sidebar-open .controls {
    top: var(--settings-viewport-top, 0px);
    height: var(--terminal-viewport-height, 100vh);
  }
}
@supports (height: 100dvh) {
  html.settings-drawer-layout .app-shell.sidebar-open .controls {
    height: calc(var(--terminal-viewport-height, 100dvh) - max(12px, var(--safe-top)) - max(12px, var(--safe-bottom)));
  }
  @media (max-width: 600px) {
    html.settings-drawer-layout .app-shell.sidebar-open .controls {
      height: var(--terminal-viewport-height, 100dvh);
    }
  }
}
.agent-gear { display: flex; align-items: center; gap: 8px; min-width: 112px; min-height: 44px; padding: 5px 8px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--panel-2); color: var(--text); font: inherit; cursor: pointer; text-align: left; touch-action: manipulation; }
.agent-gear:active, .agent-gear[aria-expanded="true"] { background: var(--panel-3); border-color: var(--accent); }
.agent-gear:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.agent-gear-label { display: grid; gap: 2px; }
.agent-gear-caption { color: var(--muted); font-size: 12px; line-height: 1; }
#agentActiveMode { font-size: 13px; font-weight: 650; line-height: 1.2; white-space: nowrap; }
.agent-gear-chevron { flex: 0 0 auto; margin-left: auto; color: var(--muted); transition: transform 180ms ease; }
.agent-gear[aria-expanded="true"] .agent-gear-chevron { transform: rotate(180deg); }
.agent-gear-track { position: relative; flex: 0 0 10px; height: 26px; display: flex; flex-direction: column; justify-content: space-between; align-items: center; }
.agent-gear-track::before { content: ""; position: absolute; left: 4px; top: 2px; bottom: 2px; width: 2px; background: var(--line-strong); }
.agent-gear-track i { width: 4px; height: 4px; border-radius: 50%; background: var(--muted); }
.agent-gear-track b { position: absolute; top: -2px; left: 1px; width: 8px; height: 8px; border-radius: 3px; background: var(--accent); box-shadow: 0 0 0 2px var(--panel-2); transform: translateY(calc(var(--gear-index, 1) * 11px)); transition: transform 180ms ease; }
.agent-mode-picker[hidden] { display: none; }
.agent-mode-picker { position: fixed; z-index: 80; box-sizing: border-box; margin: 0; padding: 10px; min-width: 0; display: flex; flex-direction: column; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.agent-mode-legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.agent-mode-title { padding: 4px 4px 10px; color: var(--muted); font-size: 12px; }
.agent-mode-options { display: flex; flex-direction: column; gap: 8px; position: relative; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.agent-mode-options::before { content: ""; position: absolute; top: 36px; bottom: 36px; left: 28px; width: 2px; background: var(--line-strong); }
.agent-mode-options label { position: relative; min-width: 0; cursor: pointer; }
.agent-mode-options input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.agent-mode-option { display: flex; align-items: center; gap: 12px; min-height: 76px; padding: 8px 10px; border: 1px solid transparent; border-radius: 9px; font-size: 13px; }
.agent-mode-gear { display: grid; place-items: center; flex: 0 0 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--panel-2); color: var(--muted); font-size: 16px; font-family: var(--font-mono); }
.agent-mode-option strong { display: block; font-weight: 650; }
.agent-mode-option small { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.agent-mode-options input:checked + .agent-mode-option { border-color: var(--accent); background: var(--panel-2); }
.agent-mode-options input:checked + .agent-mode-option .agent-mode-gear { border-color: var(--accent); color: var(--accent-strong); box-shadow: inset 0 0 0 1px var(--accent); }
.agent-mode-options input:focus-visible + .agent-mode-option { outline: 2px solid var(--focus); outline-offset: -3px; }
.agent-mode-options label:active .agent-mode-option { background: var(--panel-3); }
@media (prefers-reduced-motion: reduce) { .agent-gear-track b, .agent-gear-chevron { transition: none; } }
.agent-notice { flex: 0 0 auto; margin: 0; padding: 8px 16px; font-size: 12px; color: var(--muted); }
.agent-console { flex: 0 0 auto; margin: 0; padding: 4px 10px; font-size: 12px; color: var(--muted); }
/* Desktop uses the top bar; touch drawers need their own preferences. */
html:not(.settings-drawer-layout) :is(#drawerThemeButton, #drawerLangButton) { display: none; }
.agent-messages { flex: 1 1 auto; min-width: 0; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 10px; }
.agent-empty { color: var(--muted); }
.agent-message { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; background: var(--panel-2); }
.agent-message > b { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.agent-message-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; }
/* Accessory approval card: the change is described in the message text, so the
 * note only carries the "this changes the bridge, not the target" warning. */
.accessory-approval-note { margin: 4px 0 6px; color: var(--muted); font-size: 12.5px; }
.field-row.pricing { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.agent-usage { margin: 2px 0 0; color: var(--muted); font: 12px/1.4 ui-monospace, "SF Mono", Menlo, monospace; }
.agent-mode-countdown { color: var(--muted); font: 12px/1.2 ui-monospace, "SF Mono", Menlo, monospace; }
.agent-policy { margin-top: 8px; }
.agent-policy > summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.agent-policy textarea { width: 100%; min-height: 44px; font: 12px/1.4 ui-monospace, "SF Mono", Menlo, monospace; }
.agent-note { display: flex; gap: 6px; align-items: baseline; margin: 4px 0; font-size: 13px; overflow-wrap: anywhere; }
.agent-note .btn { flex: 0 0 auto; }
.agent-message-text.agent-markdown { white-space: normal; min-width: 0; max-width: 100%; }
.agent-markdown > :first-child { margin-top: 0; }
.agent-markdown > :last-child { margin-bottom: 0; }
.agent-markdown p, .agent-markdown ul, .agent-markdown ol,
.agent-markdown blockquote, .agent-markdown pre, .agent-table-scroll { margin: 0 0 12px; }
.agent-markdown :is(h1, h2, h3, h4, h5, h6) { margin: 20px 0 8px; line-height: 1.35; font-weight: 650; }
.agent-markdown h1 { font-size: 20px; }
.agent-markdown h2 { font-size: 18px; }
.agent-markdown :is(h3, h4, h5, h6) { font-size: 15px; }
.agent-markdown :is(ul, ol) { padding-left: 24px; }
.agent-markdown li + li { margin-top: 4px; }
.agent-markdown li > :is(ul, ol) { margin: 4px 0; }
.agent-markdown li > p { margin-bottom: 4px; }
.agent-markdown code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.9em; background: var(--panel); border-radius: 4px; padding: 2px 4px; }
.agent-markdown pre { box-sizing: border-box; width: 100%; max-width: 100%; min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--terminal); overflow-x: auto; white-space: pre; overflow-wrap: normal; }
.agent-markdown pre code { padding: 0; background: none; border-radius: 0; }
.agent-markdown blockquote { padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; }
.agent-markdown blockquote > :last-child { margin-bottom: 0; }
.agent-markdown a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.agent-markdown a:hover { text-decoration-thickness: 2px; }
.agent-markdown hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.agent-table-scroll { max-width: 100%; overflow-x: auto; }
.agent-markdown table { border-collapse: collapse; font-size: 13px; }
.agent-markdown :is(th, td) { padding: 6px 10px; border: 1px solid var(--line); text-align: left; min-width: 80px; }
.agent-markdown th { background: var(--panel); font-weight: 650; }
.agent-markdown :is(a, .agent-table-scroll):focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.agent-message .agent-actions { margin-top: 12px; }
.agent-user { border-color: var(--accent); }
.agent-status { margin: 0; padding: 0 16px; font-size: 12px; color: var(--muted); }
.agent-status:empty { display: none; }
.agent-queue-controls { flex: 0 0 auto; padding: 6px 10px; border-top: 1px solid var(--line-soft); background: var(--panel-2); }
.agent-queue-controls[hidden] { display: none; }
.agent-queue-controls p { margin: 0 0 6px; color: var(--muted); font-size: 12px; }
.agent-queue-controls .agent-actions { flex-wrap: wrap; }
#agentQueue { max-height: 72px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
.agent-form { background: var(--panel-2); border-top: 1px solid var(--line-soft); display: flex; align-items: flex-end; gap: 8px; }
.agent-question { flex: 1; min-width: 0; display: grid; gap: 6px; font-size: 12px; }
.agent-question > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.agent-question textarea { width: 100%; height: 44px; min-height: 44px; max-height: 100px; resize: none; font: inherit; font-size: 16px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.agent-heading { min-width: 0; display: flex; align-items: center; gap: 12px; }
#agentNew svg { display: none; }
.agent-narrow #agentTitle { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.agent-narrow #agentNew { min-width: 44px; padding: 0; }
.agent-narrow #agentNew svg { display: block; }
.agent-narrow #agentNew span { display: none; }
.agent-tight .agent-console, .agent-tight #agentNew { display: none; }
.agent-tight .agent-header, .agent-tight .agent-form { padding: 2px 8px; }
.agent-panel .agent-form #agentStop:disabled { display: none; }
.agent-terminal-peek:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
@media (max-width: 380px) { .agent-header { gap: 4px; } .agent-header .agent-actions { gap: 4px; } .agent-header .btn { padding-inline: 8px; } }

.agent-history { flex: 0 1 auto; min-height: 24px; max-height: 28%; overflow: auto; padding: 4px 10px; border-bottom: 1px solid var(--line); font-size: 12px; }
.agent-history summary { cursor: pointer; overflow-wrap: anywhere; }
.agent-history p { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0; }
.agent-history details { margin-top: 12px; }
.agent-message-text pre { max-width: 100%; overflow: auto; white-space: pre; font-size: 12px; }
.agent-message-text summary { cursor: pointer; margin-top: 12px; }
.agent-code-copy { margin-top: 8px; }
/* Let a restored task use the available space when no chat is displayed. */
.agent-panel:has(.agent-messages:empty) .agent-history { max-height: 65%; }

.agent-panel.window-surface, .agent-messages { background: var(--terminal); }
.agent-panel #agentAsk { display: inline-flex; justify-content: center; align-items: center; width: 44px; height: 44px; min-width: 44px; padding: 0; flex-shrink: 0; }
.agent-panel #agentAsk:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.target-binding { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 16px; }
.target-binding h3 { font-size: 14px; margin: 0 0 8px; }
.target-binding fieldset { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: 12px; }
.target-binding .check { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; }
#targetBindingIdentity { overflow-wrap: anywhere; white-space: pre-wrap; }

.target-binding .check { min-height: 44px; padding-block: 8px; }
.target-binding .check input[type="checkbox"] { box-sizing: border-box; width: 18px; min-width: 18px; max-width: 18px; height: 18px; min-height: 18px; flex: 0 0 18px; margin: 0; padding: 0; }

/* ---------- Terminal selection handles ---------- */
.terminal-selection-ui {
  position: fixed;
  inset: 0;
  z-index: 45;
  pointer-events: none;
}

.terminal-selection-handle {
  position: fixed;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-strong);
  border: 2px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.terminal-selection-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 2px;
  height: 10px;
  background: var(--accent-strong);
  transform: translateX(-50%);
}

.terminal-selection-handle-start::after {
  top: 100%;
}

.terminal-selection-handle-end::after {
  bottom: 100%;
}

.terminal-selection-copy {
  position: fixed;
  transform: translate(-50%, -100%);
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--selection-copy-border);
  background: var(--selection-copy-bg);
  color: var(--selection-copy-text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--selection-copy-shadow);
  pointer-events: auto;
  touch-action: manipulation;
  z-index: 71;
}

.terminal-selection-copy-below {
  transform: translate(-50%, 0);
}
