:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --text: #171a1f;
  --muted: #5a6370;
  --accent: #b8400f;
  --on-accent: #ffffff;
  --danger: #c62828;
  --border: #d3d8e0;
  --field-border: #7d8693;
  --warn-bg: #fff4d6;
  --warn-border: #e0b84a;
  --warn-text: #5c4200;
  --bar: #1f2328;
  --bar-text: #e8eaed;
  /* Session chrome: dark in both themes. */
  --chrome-bg: #14161a;
  --chrome-panel: #1a1d22;
  --chrome-raised: #23272e;
  --chrome-field: #1d2026;
  --chrome-border: #2c313a;
  --chrome-border-strong: #4a505b;
  --chrome-text: #e6e9ee;
  --chrome-muted: #9aa3af;
  --chrome-accent: #f06a3a;
  --chrome-on-accent: #0b1220;
  --chrome-pressed: #2f3947;
  --chrome-danger: #ffb4ab;
  --chrome-danger-border: #b3564c;
  --chrome-bad: #ff6b5e;
  --chrome-bad-bg: #3a2422;
  --chrome-good: #5fd38d;
  --chrome-good-text: #c9f2d9;
  --chrome-warn: #f2b84b;
  --chrome-warn-text: #ffe2a8;
  --chrome-warn-bg: #2a2412;
  --chrome-warn-border: #4d4220;
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  color-scheme: light dark;
}
/* Theme: follows the system unless the user picked one (settings.ts sets data-theme). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --panel: #1a1d22;
    --text: #e6e9ee;
    --muted: #9aa3af;
    --accent: #f06a3a;
    --on-accent: #0b1220;
    --danger: #ef5350;
    --border: #2c313a;
    --field-border: #6b7380;
    --warn-bg: #2a2412;
    --warn-border: #4d4220;
    --warn-text: #ffe2a8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161a;
  --panel: #1a1d22;
  --text: #e6e9ee;
  --muted: #9aa3af;
  --accent: #f06a3a;
  --on-accent: #0b1220;
  --danger: #ef5350;
  --border: #2c313a;
  --field-border: #6b7380;
  --warn-bg: #2a2412;
  --warn-border: #4d4220;
  --warn-text: #ffe2a8;
  color-scheme: dark;
}
:root[data-theme="light"] {
  color-scheme: light;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}
#app {
  height: 100%;
}
button,
input,
select {
  font: inherit;
}

/* Connect screen */
.connect {
  max-width: 60rem;
  margin: 6vh auto 2rem;
  padding: env(safe-area-inset-top) calc(1rem + env(safe-area-inset-right))
    env(safe-area-inset-bottom) calc(1rem + env(safe-area-inset-left));
}
.connect-head {
  margin-bottom: 1.5rem;
}
.connect-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 0.5rem;
}
.connect-brand img {
  width: 2.5rem;
  height: 2.5rem;
}
.connect h1 {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
.connect-head p {
  margin: 0;
  color: var(--muted);
}
.connect h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}
.connect button,
.connect input,
.connect summary {
  /* Keyboard focus must be visible on every control. */
  outline-offset: 2px;
}
.connect :focus-visible {
  outline: 2px solid var(--accent);
}
/* One column, saved remotes first when there are any; two columns from 900px. */
.connect-grid {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.saved.has-items {
  order: -1;
}
@media (min-width: 900px) {
  .connect-grid {
    display: grid;
    grid-template-columns: 24rem minmax(0, 1fr);
    gap: 2rem;
    align-items: start;
  }
  .saved.has-items {
    order: 0;
  }
}
.connect-form,
.saved {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  min-width: 0;
}
.connect-form {
  gap: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.5rem;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  color: var(--text);
}
.connect input:not([type="checkbox"]) {
  min-width: 0;
  height: 2.75rem;
  padding: 0 0.75rem;
  border: 1px solid var(--field-border);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--text);
}
.connect .id-input {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.125rem;
  letter-spacing: 0.04em;
}
.pw-row {
  display: flex;
  gap: 0.4rem;
}
.pw-row input {
  flex: 1;
}
.connect button {
  height: 2.75rem;
  padding: 0 0.8rem;
  border: 1px solid var(--field-border);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.connect button.primary {
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.connect button.danger {
  border-color: var(--danger);
  color: var(--danger);
  font-weight: 600;
}
.connect button:disabled {
  opacity: 0.5;
  cursor: default;
}
.hint {
  color: var(--muted);
  font-size: 0.8125rem;
  margin: 0;
}
.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.error,
.notice,
.lost {
  margin: 0 0 1.5rem;
  padding: 0.7rem 0.9rem;
  border-radius: 0.5rem;
}
.error {
  border: 1px solid var(--danger);
  color: var(--danger);
}
.error p,
.lost p {
  margin: 0 0 0.4rem;
}
.error code,
.lost code {
  font-size: 0.8rem;
  word-break: break-word;
}
.error code {
  color: var(--muted);
}
.notice {
  color: var(--muted);
}
.lost {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
}
.lost p {
  margin: 0;
}
.lost-actions {
  display: flex;
  gap: 0.5rem;
}
.lost-actions .primary {
  flex: 1;
}
.lost button:not(.primary) {
  background: transparent;
  color: inherit;
  border-color: var(--warn-border);
}
.lost button.primary {
  background: var(--warn-text);
  color: var(--warn-bg);
}
.lost :focus-visible {
  outline-color: var(--warn-text);
}

.saved h2 {
  color: var(--text);
}
.peers {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}
.peers li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.4rem 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.peers li:last-child {
  border-bottom: 0;
}
.peer-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.peer-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.peer-meta {
  color: var(--muted);
  font-size: 0.8125rem;
  overflow-wrap: anywhere;
}
.connect .peers .link {
  height: auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: inherit;
  text-decoration: underline;
}
.connect .peers input.rename {
  height: 2.25rem;
  width: 100%;
}
.connect .peer-connect {
  height: 2.25rem;
  flex: none;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.peer-menu-wrap {
  position: relative;
  flex: none;
}
.connect .peer-more {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
}
.peer-menu {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 2;
  min-width: 8rem;
  display: flex;
  flex-direction: column;
  padding: 0.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.25);
}
.connect .peer-menu button {
  height: 2.25rem;
  border: 0;
  text-align: left;
}
.connect .peer-menu button:hover {
  background: var(--bg);
}
.remember {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-size: 0.875rem;
}
.remember input {
  width: 1.125rem;
  height: 1.125rem;
  accent-color: var(--accent);
}
.confirm {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--panel);
}
.confirm p {
  margin: 0;
  font-size: 0.875rem;
}
.connect summary {
  cursor: pointer;
}

/* Touch screens: every target at least 44px high. */
@media (pointer: coarse) {
  .connect button,
  .connect input:not([type="checkbox"]),
  .connect .peer-menu button {
    min-height: 2.75rem;
  }
  .connect .peer-more {
    min-width: 2.75rem;
  }
  .connect .peers .link {
    min-height: 2.75rem;
  }
  .connect .peers input.rename {
    height: 2.75rem;
  }
  .connect summary {
    padding: 0.7rem 0;
  }
  .remember {
    min-height: 2.75rem;
  }
  .remember input {
    width: 1.5rem;
    height: 1.5rem;
  }
}
/* 320px: the row's buttons stay, the text wraps. */
@media (max-width: 380px) {
  .connect-form {
    padding: 1rem;
  }
  .lost-actions {
    flex-wrap: wrap;
  }
}

/* Session */
/* The session fills the visible viewport (main.tsx tracks visualViewport: phone browser bars and
   the on-screen keyboard excluded); 100dvh where that is not available. The chrome is dark in
   both themes, drawn from the --chrome-* tokens. One DOM serves every layout (SessionView.tsx):
   .layout-full (bar on top), .layout-narrow (strip on top, Menu at the bottom) and .layout-rail
   (short landscape: controls in a rail at the right edge). */
.session {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-top, 0);
  height: var(--vv-height, 100dvh);
  display: flex;
  flex-direction: column;
  background: #000;
  color: var(--chrome-text);
  font-size: 0.85rem;
  /* no pull-to-refresh or edge bounce while a session is live */
  overscroll-behavior: none;
}
:root:has(.session) {
  overscroll-behavior: none;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.session :focus-visible {
  outline: 2px solid var(--chrome-accent);
  outline-offset: 2px;
}

/* Buttons of the chrome: quiet by default, a pressed state with a border (visible in forced
   colours too), a filled primary and an outlined danger one. */
.bar button,
.popover button,
.bottom-row button,
.rail button,
.banner button,
.sheet button,
.dialog button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2rem;
  padding: 0 0.65rem;
  background: transparent;
  color: var(--chrome-text);
  border: 1px solid transparent;
  border-radius: 0.4rem;
  cursor: pointer;
}
.session button[aria-pressed="true"],
.session button.on {
  background: var(--chrome-pressed);
  border-color: var(--chrome-border-strong);
}
.session button:disabled {
  opacity: 0.5;
  cursor: default;
}
.session button.primary {
  background: var(--chrome-accent);
  border-color: var(--chrome-accent);
  color: var(--chrome-on-accent);
  font-weight: 600;
}
.session button.danger {
  border-color: var(--chrome-danger-border);
  color: var(--chrome-danger);
}
.session .icon-btn {
  width: 2rem;
  padding: 0;
}
.session select {
  height: 2rem;
  max-width: 13rem;
  min-width: 0;
  padding: 0 0.5rem;
  background: var(--chrome-field);
  color: var(--chrome-text);
  border: 1px solid var(--chrome-border);
  border-radius: 0.4rem;
}

/* Chips: connection quality (bars filled 3/2/1 and a word, so colour is not the only signal)
   and recording. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 1.75rem;
  padding: 0 0.65rem;
  border: 1px solid var(--chrome-border);
  border-radius: 0.9rem;
  white-space: nowrap;
  flex: none;
}
.chip-good {
  color: var(--chrome-good-text);
}
.chip-good svg {
  color: var(--chrome-good);
}
.chip-fair {
  color: var(--chrome-warn-text);
}
.chip-fair svg {
  color: var(--chrome-warn);
}
.chip-poor {
  color: var(--chrome-danger);
}
.chip-poor svg {
  color: var(--chrome-bad);
}
.chip-wait {
  color: var(--chrome-muted);
}
.rec {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex: none;
  color: var(--chrome-danger);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.rec svg {
  color: var(--chrome-bad);
}
.badge {
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.3rem;
  border-radius: 0.55rem;
  background: var(--chrome-accent);
  color: var(--chrome-on-accent);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.1rem;
  text-align: center;
}

/* Session bar (wide layouts) */
.bar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  min-height: 3rem;
  padding: env(safe-area-inset-top) calc(0.75rem + env(safe-area-inset-right)) 0
    calc(0.75rem + env(safe-area-inset-left));
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--chrome-border);
}
.bar .peer,
.strip .peer {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.9rem;
}
.spacer {
  flex: 1;
}
.bar .group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: none;
}
.bar .group + .group {
  padding-left: 0.75rem;
  border-left: 1px solid var(--chrome-border);
}
.bar > button {
  flex: none;
}
.more-wrap {
  position: relative;
}
.popover {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 6;
  display: grid;
  gap: 0.2rem;
  min-width: 12rem;
  padding: 0.35rem;
  background: var(--chrome-bg);
  border: 1px solid var(--chrome-border-strong);
  border-radius: 0.5rem;
  box-shadow: 0 6px 16px rgb(0 0 0 / 0.4);
}
.popover button {
  justify-content: flex-start;
  width: 100%;
}
/* Narrower bars: icons alone (the names stay for screen readers). */
@media (max-width: 899px) {
  .bar .group > button .lbl {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* Narrow layouts: status strip on top, Keys and Menu above the key bar */
.strip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  padding: calc(0.5rem + env(safe-area-inset-top))
    calc(1rem + env(safe-area-inset-right)) 0.5rem
    calc(1rem + env(safe-area-inset-left));
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--chrome-border);
  font-size: 0.9rem;
}
.bottom-row {
  flex: none;
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem calc(0.75rem + env(safe-area-inset-right)) 0.5rem
    calc(0.75rem + env(safe-area-inset-left));
  background: var(--chrome-bg);
  border-top: 1px solid var(--chrome-border);
}
.bottom-row button {
  flex: 1;
  min-height: 2.75rem;
  background: var(--chrome-raised);
  border-color: var(--chrome-border);
  font-size: 0.95rem;
}
.session button.menu-btn {
  background: var(--chrome-accent);
  border-color: var(--chrome-accent);
  color: var(--chrome-on-accent);
  font-weight: 600;
}

/* Short landscape: the rail sits beside the screen, inside the safe area */
.rail {
  flex: none;
  width: calc(3.75rem + env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: calc(0.6rem + env(safe-area-inset-top)) env(safe-area-inset-right)
    calc(0.6rem + env(safe-area-inset-bottom)) 0;
  background: var(--chrome-bg);
  border-left: 1px solid var(--chrome-border);
  font-size: 0.75rem;
}
.rail button {
  flex-direction: column;
  gap: 0.2rem;
  width: 3.5rem;
  min-height: 3.5rem;
  padding: 0;
  background: var(--chrome-raised);
  border-color: var(--chrome-border);
  border-radius: 0.6rem;
}
.rail .chip {
  flex-direction: column;
  gap: 0.15rem;
  height: auto;
  padding: 0;
  border: 0;
}
.rail .rec {
  gap: 0.25rem;
  font-size: 0.7rem;
}
.layout-rail .main {
  padding-left: env(safe-area-inset-left);
}

/* Status banners: persistent until acted on or dismissed */
.banners {
  flex: none;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem calc(0.75rem + env(safe-area-inset-right)) 0.4rem
    calc(0.75rem + env(safe-area-inset-left));
  border-bottom: 1px solid var(--chrome-border);
  background: var(--chrome-raised);
  color: var(--chrome-text);
}
.banner > span {
  flex: 1;
  min-width: 0;
}
.banner.warn {
  background: var(--chrome-warn-bg);
  border-color: var(--chrome-warn-border);
  color: var(--chrome-warn-text);
}
.banner.warn button {
  color: var(--chrome-warn-text);
}
.banner.warn button.primary {
  background: var(--chrome-warn);
  border-color: var(--chrome-warn);
  color: #1f1700;
}
.banner.bad {
  background: var(--chrome-bad-bg);
  border-color: var(--chrome-danger-border);
  color: var(--chrome-danger);
}
.banner.bad button {
  color: var(--chrome-danger);
}

/* Screen, with the side panel and the key bar around it */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
/* No key bar: keep the controls above the home indicator. */
.session:not(:has(.keybar)) .main {
  padding-bottom: env(safe-area-inset-bottom);
}
.screen {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden; /* a pinch-zoomed canvas (touch.ts) stays inside */
}
.screen canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  cursor: default;
}
/* Keyboard focus means "your keys go to the remote": show it. */
.screen canvas:focus {
  outline: none;
}
.screen canvas:focus-visible {
  outline: 2px solid var(--chrome-accent);
  outline-offset: -2px;
}
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  color: #ddd;
  background: #000;
}
.spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid #555;
  border-top-color: #ddd;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}
footer.hint {
  flex: none;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.3rem calc(0.75rem + env(safe-area-inset-right)) 0.3rem
    calc(0.75rem + env(safe-area-inset-left));
  background: var(--chrome-bg);
  border-top: 1px solid var(--chrome-border);
  color: var(--chrome-muted);
  font-size: 0.75rem;
}
footer.hint kbd {
  padding: 0 0.3rem;
  border: 1px solid var(--chrome-border-strong);
  border-radius: 0.25rem;
  color: var(--chrome-text);
  font: inherit;
}
footer.hint .summary {
  flex: none;
  font-variant-numeric: tabular-nums;
}
/* The hint is for keyboards. */
@media (pointer: coarse) {
  footer.hint {
    display: none;
  }
}

/* Side panel (Chat, Files, Settings, Stats; one at a time, behind one header with tabs). Docked
   beside the screen where there is room; over it below that, and over everything on phones. The
   Files panel stays mounted while hidden (SessionView), so [hidden] must win over display. */
.dock {
  flex: none;
  width: 24rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--chrome-panel);
  color: var(--chrome-text);
  border-left: 1px solid var(--chrome-border);
  font-size: 0.9rem;
}
.dock[hidden],
.dock-panel[hidden] {
  display: none;
}
.dock-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 2.75rem;
  padding: 0 0.5rem;
  border-bottom: 1px solid var(--chrome-border);
}
.dock-head h2 {
  flex: 1;
  margin: 0;
  padding-left: 0.4rem;
  font-size: 1rem;
}
.dock-head .tabs {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-width: 0;
}
.dock button,
.dock input:not([type="checkbox"]):not([type="radio"]),
.dock select {
  font: inherit;
}
.dock button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2rem;
  padding: 0 0.75rem;
  background: var(--chrome-raised);
  color: var(--chrome-text);
  border: 1px solid var(--chrome-border);
  border-radius: 0.4rem;
  cursor: pointer;
}
.dock .icon-btn {
  width: 2rem;
  padding: 0;
}
.dock-head .icon-btn {
  flex: none;
  background: transparent;
  border-color: transparent;
}
.dock-head .tabs button {
  background: transparent;
  border-color: transparent;
}
/* Selected: a fill and a border (so it shows in forced colours too), not colour alone. */
.dock-head .tabs button[aria-selected="true"] {
  background: var(--chrome-pressed);
  border-color: var(--chrome-border-strong);
  font-weight: 600;
}
.dock input:not([type="checkbox"]):not([type="radio"]),
.dock select,
.dock textarea {
  min-width: 0;
  padding: 0.35rem 0.5rem;
  background: var(--chrome-field);
  color: var(--chrome-text);
  border: 1px solid var(--chrome-border-strong);
  border-radius: 0.4rem;
}
.dock-panel {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
}
.dock-panel:focus {
  outline: none;
}
.stats {
  margin: 0;
  padding: 0.9rem;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.65rem 1rem;
  font-variant-numeric: tabular-nums;
}
.stats dt {
  color: var(--chrome-muted);
}
.stats dd {
  margin: 0;
  overflow-wrap: anywhere;
}
@media (max-width: 1099px) {
  .layout-full .dock {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    width: min(26rem, 100%);
    box-shadow: -4px 0 16px rgb(0 0 0 / 0.3);
  }
}
.layout-rail .dock {
  position: absolute;
  top: 0;
  bottom: 0;
  right: calc(3.75rem + env(safe-area-inset-right));
  z-index: 4;
  width: min(24rem, calc(100% - 3.75rem));
  box-shadow: -4px 0 16px rgb(0 0 0 / 0.3);
}
.layout-narrow .dock {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: auto;
  border-left: 0;
}

/* Menu sheet and disconnect confirmation: the only things that cover the screen */
.scrim {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  background: rgb(0 0 0 / 0.55);
}
.sheet-scrim {
  flex-direction: column;
  justify-content: flex-end;
}
.sheet,
.dialog {
  background: var(--chrome-panel);
  color: var(--chrome-text);
  border: 1px solid var(--chrome-border);
}
.sheet {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  max-height: 100%;
  overflow: auto;
  padding: 0.5rem calc(0.75rem + env(safe-area-inset-right))
    calc(1rem + env(safe-area-inset-bottom))
    calc(0.75rem + env(safe-area-inset-left));
  border-width: 1px 0 0;
  border-radius: 1rem 1rem 0 0;
}
.layout-rail .sheet {
  align-self: center;
  width: min(36rem, 100%);
  border-width: 1px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 0.4rem;
}
.sheet-head h2 {
  margin: 0;
  font-size: 1rem;
}
.sheet-head p {
  margin: 0.15rem 0 0;
  color: var(--chrome-muted);
  font-size: 0.8rem;
}
.sheet-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}
.layout-rail .sheet-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.sheet-grid button {
  flex-direction: column;
  gap: 0.4rem;
  min-height: 4.75rem;
  padding: 0.4rem;
  background: var(--chrome-raised);
  border-color: var(--chrome-border);
  border-radius: 0.75rem;
  text-align: center;
}
.sheet-grid .note {
  color: var(--chrome-muted);
}
.sheet .sheet-disconnect {
  width: 100%;
  min-height: 3rem;
  margin-top: 0.4rem;
  font-weight: 600;
  border-radius: 0.65rem;
}
.dialog-scrim {
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.dialog {
  width: min(24rem, 100%);
  padding: 1rem;
  border-radius: 0.75rem;
}
.confirm {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0 0.4rem;
}
.confirm p {
  margin: 0;
  font-size: 0.95rem;
}
.confirm button {
  min-height: 3rem;
  font-weight: 600;
  border-radius: 0.65rem;
}

/* Touch screens: every target at least 44px. */
@media (pointer: coarse) {
  .bar button,
  .popover button,
  .banner button,
  .session .icon-btn,
  .dock-head .icon-btn,
  .session select {
    min-height: 2.75rem;
    min-width: 2.75rem;
  }
  .session .bar select {
    height: 2.75rem;
  }
  .bar,
  .banners .banner {
    font-size: 0.95rem;
  }
}
@media (forced-colors: active) {
  .session button[aria-pressed="true"],
  .session button.on {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }
  .session button.primary,
  .session button.menu-btn {
    border-color: ButtonText;
  }
}

/* Files panel */
.files {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem;
}
.files.dragging {
  outline: 3px dashed var(--chrome-accent);
  outline-offset: -6px;
}
.files p {
  margin: 0;
}
.files .error {
  color: var(--chrome-danger);
}
.files .hint {
  color: var(--chrome-muted);
  font-size: 0.8rem;
}
.files .pathbar,
.files .newfolder {
  display: flex;
  gap: 0.3rem;
}
.files .pathbar input,
.files .newfolder input {
  flex: 1;
  min-width: 0;
}
.files .pathbar input {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
}
.files .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.files .spacer {
  flex: 1;
}
.files .listing {
  flex: 1 1 auto;
  min-height: 6rem;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
  border: 1px solid var(--chrome-border);
  border-radius: 0.5rem;
}
.files .listing li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.25rem;
  padding: 0.15rem 0.6rem 0.15rem 0.2rem;
  border-bottom: 1px solid var(--chrome-raised);
}
.files .listing li:last-child {
  border-bottom: 0;
}
/* A selected row has a fill and its checkbox: not colour alone. */
.files .listing li.selected {
  background: color-mix(in srgb, var(--chrome-accent) 16%, transparent);
}
.files .listing li.empty {
  padding: 0.6rem;
  color: var(--chrome-muted);
}
.files .check {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
}
.files .check input {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
}
.files .listing .name,
.files .listing .dir {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}
.files .listing button.dir {
  justify-content: flex-start;
  gap: 0.4rem;
  min-height: 0;
  padding: 0.2rem 0;
  background: none;
  border: 0;
  color: inherit;
  text-align: left;
}
.files .listing button.dir svg {
  flex: none;
  color: var(--chrome-accent);
}
.files .size {
  flex: none;
  color: var(--chrome-muted);
  font-variant-numeric: tabular-nums;
}
.files .transfers h3 {
  margin: 0.2rem 0 0.5rem;
  color: var(--chrome-muted);
  font-size: 0.8rem;
  font-weight: 600;
}
.files .transfers ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.7rem;
}
.files .transfers li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.25rem 0.6rem;
  align-items: center;
}
.files .transfers .label {
  display: flex;
  gap: 0.35rem;
  min-width: 0;
  overflow-wrap: anywhere;
}
.files .transfers .label svg {
  flex: none;
  margin-top: 0.15rem;
}
.files .transfers progress {
  grid-column: 1 / -1;
  width: 100%;
  height: 0.5rem;
  accent-color: var(--chrome-accent);
}
.files .transfers .detail {
  grid-column: 1 / -1;
  color: var(--chrome-muted);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.files .transfers li[data-state="failed"] .detail {
  color: var(--chrome-danger);
}

/* Settings panel: sections of fields, segmented controls made of native radios */
.view-settings {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
}
.view-settings h3 {
  margin: 0;
  color: var(--chrome-muted);
  font-size: 0.8rem;
  font-weight: 600;
}
.view-settings h3:not(:first-child) {
  margin-top: 0.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--chrome-border);
}
.view-settings .field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.view-settings legend {
  padding: 0;
  margin-bottom: 0.4rem;
}
.view-settings .field-hint {
  margin: 0;
  color: var(--chrome-muted);
  font-size: 0.8rem;
}
.view-settings select,
.view-settings input[type="number"] {
  min-height: 2.25rem;
  max-width: 100%;
}
/* The choices wrap onto more lines before they overflow (narrow panels, 200% zoom). */
.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  background: var(--chrome-bg);
  border: 1px solid var(--chrome-border);
  border-radius: 0.6rem;
}
.seg label {
  position: relative;
  flex: 1 1 5rem;
  display: grid;
}
.seg input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.seg span {
  display: grid;
  place-items: center;
  min-height: 2.25rem;
  padding: 0.2rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 0.45rem;
  text-align: center;
  overflow-wrap: anywhere;
}
.seg input:checked + span {
  background: var(--chrome-pressed);
  border-color: var(--chrome-border-strong);
  font-weight: 600;
}
.seg input:focus-visible + span {
  outline: 2px solid var(--chrome-accent);
  outline-offset: 1px;
}
@media (forced-colors: active) {
  .seg input:checked + span,
  .dock-head .tabs button[aria-selected="true"],
  .files .listing li.selected {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }
}
/* Touch screens: every target at least 44px. */
@media (pointer: coarse) {
  .dock button,
  .dock input:not([type="checkbox"]):not([type="radio"]),
  .dock select,
  .view-settings select,
  .view-settings input[type="number"] {
    min-height: 2.75rem;
  }
  .dock .icon-btn {
    min-width: 2.75rem;
  }
  .seg span {
    min-height: 2.75rem;
  }
  .files .listing li {
    min-height: 2.75rem;
  }
  .files .check {
    width: 2.75rem;
    height: 2.75rem;
  }
  .files .check input {
    width: 1.4rem;
    height: 1.4rem;
  }
  .files .listing button.dir {
    min-height: 2.75rem;
  }
}
/* Scaling "original": one remote pixel per CSS pixel, scrolling when larger than the window. */
.screen.original {
  overflow: auto;
}
.screen.original canvas {
  max-width: none;
  max-height: none;
}

/* Key deck for touch devices: chrome tokens, touch-sized keys. One row where there is room; on
   phones in portrait two rows of equal-width keys, then Type, the second page and pointer mode. */
.keybar {
  flex: none;
  position: relative;
  padding: 0.5rem calc(0.5rem + env(safe-area-inset-right))
    calc(0.5rem + env(safe-area-inset-bottom))
    calc(0.5rem + env(safe-area-inset-left));
  background: var(--chrome-bg);
  border-top: 1px solid var(--chrome-border);
  color: var(--chrome-text);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.keybar.narrow {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.keybar .row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  overflow-x: auto;
}
.keybar .row .spacer {
  flex: 1;
  min-width: 0.5rem;
}
.keybar .sep {
  flex: none;
  width: 1px;
  height: 1.75rem;
  margin: 0 0.25rem;
  background: var(--chrome-border);
}
.keybar .grid {
  display: grid;
  gap: 0.35rem;
}
.keybar .grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.keybar .grid.six {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
.keybar .grid.combos {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.keybar .grid.foot {
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
}
.keybar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  flex: none;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0 0.6rem;
  background: var(--chrome-raised);
  color: var(--chrome-text);
  border: 1px solid var(--chrome-border);
  border-radius: 0.5rem;
  font: inherit;
  font-size: 0.95rem;
  touch-action: manipulation;
  cursor: pointer;
}
.keybar .row button {
  min-width: 3.25rem;
}
.keybar .grid button {
  min-width: 0;
  padding: 0 0.25rem;
}
.keybar .grid.foot button {
  min-height: 3rem;
}
.keybar button[aria-pressed="true"],
.keybar button[aria-expanded="true"] {
  background: var(--chrome-pressed);
  border-color: var(--chrome-border-strong);
}
/* Modifiers: off, latched (the next key) and locked (until tapped again). Dark text on the
   accent; locked adds a lock icon and a inner ring, so the three differ without
   colour. */
.keybar button.mod[data-state="latched"],
.keybar button.mod[data-state="locked"] {
  background: var(--chrome-accent);
  border-color: var(--chrome-accent);
  color: var(--chrome-on-accent);
  font-weight: 600;
}
.keybar button.mod[data-state="locked"] {
  box-shadow:
    inset 0 0 0 2px var(--chrome-accent),
    inset 0 0 0 4px var(--chrome-on-accent);
}
.keybar .held {
  margin: 0 0 0.35rem;
  color: var(--chrome-muted);
  font-size: 0.85rem;
}
.keybar .page {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.keys-popover {
  position: absolute;
  right: calc(0.5rem + env(safe-area-inset-right));
  bottom: calc(100% + 0.35rem);
  z-index: 6;
  width: min(26rem, calc(100% - 1rem));
  padding: 0.5rem;
  background: var(--chrome-panel);
  border: 1px solid var(--chrome-border-strong);
  border-radius: 0.6rem;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.5);
}
.keybar :focus-visible {
  outline: 2px solid var(--chrome-accent);
  outline-offset: 2px;
}
@media (forced-colors: active) {
  .keybar button.mod[data-state="latched"],
  .keybar button.mod[data-state="locked"] {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }
  .keybar button.mod[data-state="locked"] {
    outline-width: 4px;
  }
}
/* Focusable (so the soft keyboard opens) but invisible; iOS will not focus display:none. */
.keybar .soft-keyboard {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  resize: none;
  font-size: 16px; /* below 16px iOS zooms the page on focus */
}
.screen canvas {
  touch-action: none;
}

/* Gesture help: a card in the free space on phones in portrait, a banner elsewhere */
.gesture-card {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0.5rem 0.75rem;
  padding: 0.75rem;
  background: var(--chrome-panel);
  border: 1px solid var(--chrome-border);
  border-radius: 0.75rem;
}
.gesture-card .gestures {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 0.75rem;
}
.gesture-card button {
  align-self: flex-start;
  min-height: 2.75rem;
  padding: 0 0.9rem;
  background: transparent;
  color: var(--chrome-text);
  border: 1px solid var(--chrome-border-strong);
  border-radius: 0.5rem;
}
.gestures {
  margin: 0;
  padding: 0;
  list-style: none;
}
.gestures strong {
  font-weight: 600;
}
.banner .gestures {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.75rem;
}
.banner .gestures li + li::before {
  content: "\00b7";
  margin-right: 0.75rem;
  color: var(--chrome-muted);
}
.bar .status,
.bar .status-short {
  color: var(--chrome-muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}
.bar .status-short {
  display: none;
}
@media (max-width: 1099px) {
  .bar .status {
    display: none;
  }
  .bar .status-short {
    display: inline;
  }
}

/* Chat */
.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem;
}
.chat button:disabled {
  opacity: 0.5;
  cursor: default;
}
.chat .messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat .messages li {
  max-width: 85%;
  padding: 0.4rem 0.6rem;
  border-radius: 0.5rem;
  background: var(--chrome-raised);
  border: 1px solid var(--chrome-border);
}
.chat .messages li.me {
  align-self: flex-end;
  background: color-mix(in srgb, var(--chrome-accent) 18%, var(--chrome-panel));
}
.chat .messages li.empty {
  max-width: none;
  color: var(--chrome-muted);
  border: 0;
  background: none;
}
.chat .who {
  font-weight: 600;
  margin-right: 0.4rem;
}
.chat time {
  color: var(--chrome-muted);
  font-size: 0.8em;
  font-variant-numeric: tabular-nums;
}
.chat .messages p {
  margin: 0.2rem 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat form {
  display: flex;
  gap: 0.4rem;
  align-items: flex-end;
}
.chat textarea {
  flex: 1;
  resize: none;
  font: inherit;
  font-size: max(16px, 1em); /* below 16px iOS zooms the page on focus */
}
.chat form button {
  align-self: stretch;
}

/* All displays at once: side by side, each as wide as its share (flex-grow = its width) */
.screen.multi {
  display: flex;
  gap: 2px;
}
.screen.multi canvas {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
}

/* Trackpad mode */
/* The local cursor (touch.ts): placed by transform from client coordinates, so fixed. */
.trackpad-cursor {
  position: fixed;
  left: 0;
  top: 0;
  width: 20px;
  height: 28px;
  pointer-events: none;
  z-index: 5;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.6));
}
.trackpad-cursor svg {
  display: block;
}
.keybar .pointer-mode {
  font-size: 0.85rem;
}
