/* Lidless web client. Dark by default, light when the device asks for it.
   One accent colour; everything else is neutral so the remote picture is
   the only thing on screen that draws the eye. */

:root {
  --bg: #0f1317;
  --surface: #171c22;
  --raised: #222931;
  --raised-hi: #2c353f;
  --line: #2f3842;
  --text: #e9ecef;
  --muted: #9ba6b1;
  --accent: #6fb1d1;
  --accent-ink: #08151c;
  --accent-soft: rgba(111, 177, 209, 0.16);
  --good: #7fcaa2;
  --bad: #ee8f84;
  --stage: #05070a;
  --scrim: rgba(9, 12, 15, 0.78);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --field: #0b0e12;
  --radius: 10px;
  --gap: 6px;
  --speed: 0.18s;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --raised: #eceef1;
    --raised-hi: #dfe3e8;
    --line: #d3d8de;
    --text: #151a1f;
    --muted: #56616c;
    --accent: #1b6a8b;
    --accent-ink: #ffffff;
    --accent-soft: rgba(27, 106, 139, 0.12);
    --good: #1f7a4d;
    --bad: #b3392c;
    --stage: #dde1e6;
    --scrim: rgba(243, 244, 246, 0.86);
    --shadow: 0 10px 30px rgba(20, 30, 40, 0.18);
    --field: #ffffff;
    color-scheme: light;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root { --speed: 0s; }
}

* { box-sizing: border-box; }

/* The hidden attribute must win over the display rules below. */
[hidden] { display: none !important; }

html {
  height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* The body is pinned to the part of the page that is really visible. The
   script keeps --app-h and --app-top in step with the visual viewport, so
   when the onscreen keyboard opens the whole app becomes shorter instead of
   being pushed or scrolled. Nothing here can scroll or bounce. */
body {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  height: var(--app-h, 100dvh);
  transform: translateY(var(--app-top, 0px));
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h1, h2, p, ul { margin: 0; }

button, select, input, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

button, select {
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--raised);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: background var(--speed), border-color var(--speed), color var(--speed);
}
button:hover { background: var(--raised-hi); }
button:active { background: var(--raised-hi); border-color: var(--muted); }
button:disabled { opacity: 0.55; cursor: default; }

button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, .sheet:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
button.primary:hover, button.primary:active { background: var(--accent); filter: brightness(1.08); }
button.quiet { background: transparent; border-color: transparent; color: var(--accent); font-weight: 600; }
button.quiet:hover { background: var(--accent-soft); }
button.danger { color: var(--bad); }
button.wide { width: 100%; }

/* 16px keeps iOS from zooming the page when a field takes focus. */
input[type="text"], textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  font-size: 16px;
  line-height: 1.4;
}
input[type="text"]:focus-visible, textarea:focus-visible { outline-offset: 0; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.note { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.note strong { color: var(--text); font-weight: 600; }

/* Hints that depend on how the device is used, not on how big it is. */
@media not ((hover: hover) and (pointer: fine)) { .fine-only { display: none !important; } }
@media not (pointer: coarse) { .coarse-only { display: none !important; } }

/* ---------------------------------------------------------------- pairing */

.pair {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  padding: calc(env(safe-area-inset-top) + 20px) calc(env(safe-area-inset-right) + 20px)
           calc(env(safe-area-inset-bottom) + 20px) calc(env(safe-area-inset-left) + 20px);
}
.pair-card {
  width: 100%;
  max-width: 400px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { border-radius: 11px; display: block; }
.brand-name { font-size: 17px; font-weight: 600; letter-spacing: 0.01em; color: var(--muted); }
.pair-card h1 { font-size: 24px; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; }
.lede { color: var(--muted); font-size: 15.5px; }
.lede strong { color: var(--text); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13.5px; font-weight: 600; }
.field-hint { color: var(--muted); font-size: 13px; }
#pair-code {
  min-height: 56px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 26px;
  letter-spacing: 0.14em;
  text-align: center;
  text-transform: uppercase;
}
.error {
  padding: 10px 12px;
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
}
.error::before { content: "Problem: "; color: var(--bad); font-weight: 600; }
.pair-card .primary { min-height: 50px; font-size: 16px; }

/* ---------------------------------------------------------------- session */

.session {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.strip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: calc(env(safe-area-inset-top) + 2px) calc(env(safe-area-inset-right) + 10px) 2px
           calc(env(safe-area-inset-left) + 12px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  white-space: nowrap;
}
.strip-space { flex: 1 1 auto; min-width: 0; }

/* The dot repeats what the words next to it say, with a shape for each
   state so it never depends on colour alone. */
.dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--muted);
}
.dot[data-state="on"] { border-color: var(--good); background: var(--good); }
.dot[data-state="busy"] { border-color: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.dot[data-state="off"] { border-color: var(--muted); border-style: dotted; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .dot[data-state="busy"] { animation: none; } }

.conn-text { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.chip {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 12px;
}
.metrics { flex: none; display: flex; gap: 8px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
/* On the narrowest phones the round-trip time makes way, so the word
   "Connected" is not cut short. */
@media (max-width: 360px) { #rtt { display: none; } }
.strip-button {
  flex: none;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 13px;
}
/* A slim button still gets a full-size place to press. */
.strip-button { position: relative; }
.strip-button::after { content: ""; position: absolute; inset: -7px -4px; }
/* On the narrowest phones the strip keeps its icons and numbers, not words. */
@media (max-width: 400px) { .strip-word { display: none; } }

/* Things that only mean something with a touch screen (set by the script). */
.session[data-touch="no"] .touch-only { display: none !important; }

/* Shows the pointer mode at a glance and switches it: the ring for
   Trackpad, a fingertip for Touch. */
.pointer-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.pointer-toggle svg { flex: none; }
.session[data-pointer="touch"] .pointer-toggle .icon-trackpad,
.session:not([data-pointer="touch"]) .pointer-toggle .icon-touch { display: none; }
.session[data-pointer="touch"] .pointer-toggle { border-color: var(--accent); color: var(--accent); }
/* One tap here changes what every touch does, so it gets a full 44 px to
   press. The strip is only 36 px tall, so the place to press reaches from
   the top of the strip to a little below it, over the top edge of the
   picture in that corner; the strip is raised so that part can be pressed.
   Under a notice it reaches no further than the other strip buttons do,
   so it takes nothing more from the notice. */
.strip { position: relative; z-index: 1; }
/* Measured from inside the button's 1 px border. */
.pointer-toggle::after { inset: -4px -4px -13px; }
.session:has(.banner:not([hidden])) .pointer-toggle::after { bottom: -8px; }

.banner {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px calc(env(safe-area-inset-right) + 10px) 8px calc(env(safe-area-inset-left) + 12px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.banner-icon { flex: none; margin-top: 1px; color: var(--accent); }
.banner-body { flex: 1 1 auto; min-width: 0; }
.banner-main strong, .banner-list strong { font-weight: 600; }
.banner-main span, .banner-list span { color: var(--muted); }
.banner-list { margin-top: 6px; padding: 0; list-style: none; display: grid; gap: 6px; }
.banner-list strong { display: block; }

/* The work area holds the picture and every control. Its grid is chosen by
   the script from the space available (data-mode and data-dock), never from
   a device name or a fixed screen size:
     compact + below   picture, with a bar of three buttons under it
     compact + side    picture, with the same three buttons in a rail
     roomy + below     picture, with the typing box and key pad under it
     roomy + side      picture, with them in a column beside it */
.work {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: grid;
  overflow: hidden;
  padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
  background: var(--surface);
}
.session[data-mode="compact"][data-dock="below"] .work {
  grid-template: "stage" minmax(0, 1fr) "cluster" auto / minmax(0, 1fr);
}
.session[data-mode="compact"][data-dock="side"] .work {
  grid-template: "stage cluster" minmax(0, 1fr) / minmax(0, 1fr) auto;
}
.session[data-mode="roomy"][data-dock="below"] .work {
  grid-template: "stage stage" minmax(0, 1fr) "compose keys" auto / minmax(13rem, 18rem) minmax(0, 1fr);
}
.session[data-mode="roomy"][data-dock="side"] .work {
  grid-template: "stage compose" auto "stage keys" minmax(0, 1fr) / minmax(0, 1fr) 22rem;
}

.stage {
  grid-area: stage;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--stage);
  outline: none;
  /* The trackpad gestures are ours; the browser must not pan or zoom here. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
/* Shows when physical keys are going to the Mac. Only where there are
   physical keys and a mouse; on a phone it would mean nothing. It is drawn
   above the picture so the picture cannot cut it. */
@media (hover: hover) and (pointer: fine) {
  .stage:focus::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    box-shadow: inset 0 0 0 1px var(--accent);
  }
  .stage:focus-visible::after { box-shadow: inset 0 0 0 2px var(--accent); }
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* Where the next tap will land. Touch only; see the script. */
.pointer-mark {
  position: absolute;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s;
}
.pointer-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: var(--accent);
}
.pointer-mark[data-state="on"] { opacity: 0.95; }
.pointer-mark[data-state="idle"] { opacity: 0.5; }
@media (prefers-reduced-motion: reduce) { .pointer-mark { transition: none; } }

/* Touch mode: a brief ring where a click landed, and a larger filled one
   for the right click of a touch-and-hold. The script moves the anchor;
   the ring is the pseudo-element so its animation can use transform. */
.tap-mark { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }
.tap-mark::before {
  content: "";
  position: absolute;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(0, 0, 0, 0.6);
  opacity: 0;
}
.tap-mark[data-state="tap"]::before { animation: tap-ping 0.45s ease-out; }
.tap-mark[data-state="hold"]::before {
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-width: 3px;
  background: var(--accent-soft);
  animation: tap-ping 0.6s ease-out;
}
@keyframes tap-ping {
  from { opacity: 0.95; transform: scale(0.45); }
  60% { opacity: 0.9; }
  to { opacity: 0; transform: scale(1.15); }
}
@media (prefers-reduced-motion: reduce) {
  .tap-mark[data-state="tap"]::before, .tap-mark[data-state="hold"]::before { animation: none; opacity: 0.9; }
}

/* A passing tip at the top of the picture; it never takes a touch. */
.hint {
  position: absolute;
  left: 50%;
  top: 10px;
  z-index: 2;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--raised);
  box-shadow: var(--shadow);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}
/* Beside an open side sheet, the tip keeps to the part still in view. */
.session[data-mode="compact"][data-dock="side"]:not([data-sheet="none"]) .hint {
  left: 12px;
  transform: none;
  max-width: calc(100% - min(21rem, 72%) - 24px);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  background: var(--scrim);
  text-align: center;
}
.overlay-title { max-width: 26rem; font-size: 17px; font-weight: 600; }
.overlay-text { max-width: 26rem; color: var(--muted); }
.overlay .primary { margin-top: 8px; min-width: 9rem; }

/* --- keys */

.key { padding: 0 8px; font-size: 14px; white-space: nowrap; }
.keygroup { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); }
.keygroup.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.chords .key, .keygroup.eight .key { padding: 0 2px; }

/* Sticky modifiers. Each state has its own words under the name as well as
   its own look: off, "next key" (armed for one key), "locked". */
.mod { display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.mod::after { font-size: 10px; font-weight: 600; letter-spacing: 0.02em; }
.mod[data-state="armed"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.mod[data-state="armed"]::after { content: "next key"; color: var(--accent); }
.mod[data-state="locked"] { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.mod[data-state="locked"]::after { content: "locked"; }

/* --- typing box */

.compose {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  background: var(--surface);
}
.compose-main { display: flex; align-items: flex-end; gap: var(--gap); }
.compose textarea { flex: 1 1 auto; min-width: 0; max-height: 7.5em; resize: none; }
.compose-main .primary { flex: none; min-width: 72px; }
.icon-button { flex: none; display: flex; align-items: center; justify-content: center; width: 44px; padding: 0; color: var(--muted); }
.compose-options { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 16px; }
/* The options stay on one row down to the narrowest phone. */
.compose { container-type: inline-size; }
@container (max-width: 470px) { .check .sub { display: none; } }
/* The way to the clipboard sits at the end of that row; on the narrowest
   phones it keeps its icon and gives up its word. */
.clip-open { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; padding: 0 8px; font-size: 14px; }
.clip-open svg { flex: none; }
@container (max-width: 330px) { .clip-open-word { display: none; } }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; font-size: 14px; }
.check .sub { color: var(--muted); font-size: 12.5px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
/* Live typing: the Live button switches between writing then sending and
   sending every key as it is pressed. Live swaps the text box and Send for
   a slim field that shows the last few characters, and Done. */
.lt-toggle { flex: none; padding: 0 10px; font-size: 14px; }
.lt-toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.lt-done { flex: none; min-width: 60px; padding: 0 10px; }
.lt-strip { position: relative; flex: 1 1 auto; min-width: 0; }
.lt-strip[hidden], .lt-done[hidden] { display: none; }
#lt-field {
  display: block;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  resize: none;
  overflow: hidden;
  white-space: pre;
  border-color: var(--accent);
}
.lt-hint {
  position: absolute;
  inset: 0 12px;
  display: none;
  align-items: center;
  overflow: hidden;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
}
.lt-strip[data-empty="true"] .lt-hint { display: flex; }
@container (max-width: 470px) { .lt-more { display: none; } }
/* Beside the clipboard button, where the Send-only options were. */
.lt-note { display: none; flex: 1 1 0; min-width: 0; overflow: hidden; color: var(--muted); font-size: 13px; white-space: nowrap; text-overflow: ellipsis; }
.compose[data-lt="live"] .lt-note { display: block; }
.compose[data-lt="live"] #compose-note,
.compose[data-lt="live"] #compose-text,
.compose[data-lt="live"] #compose-send,
.compose[data-lt="live"] .compose-options .check { display: none; }
.keystrip {
  display: flex;
  gap: var(--gap);
  overflow-x: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  touch-action: pan-x;
  margin: 0 -10px;
  padding: 0 10px;
}
.keystrip::-webkit-scrollbar { display: none; }
.keystrip .key { flex: none; min-width: 52px; }

/* --- sheets */

.sheet {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 10px;
  background: var(--surface);
  outline-offset: -2px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 44px; margin: -4px 0; }
.sheet-head h2 { font-size: 16px; font-weight: 650; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-label { font-size: 14px; }
.keys { container-type: inline-size; }

/* Two-option switch (the pointer mode). */
.pointer-set { display: grid; gap: 6px; }
.segmented { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--field); }
.segment { position: relative; display: flex; cursor: pointer; }
.segment input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.segment span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 14px;
  transition: background var(--speed), color var(--speed);
}
.segment input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.segment input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Three-option switch (the picture mode). Three labels do not fit beside a
   row label on a phone, so the label sits above and the options share the
   width. */
.picture-set { display: grid; gap: 6px; }
.picture-set .segmented { display: flex; }
.picture-set .segment { flex: 1 1 0; min-width: 0; }
.picture-set .segment span { flex: 1; min-width: 0; padding: 0 4px; text-align: center; white-space: nowrap; }
.picture-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 20px; }
.picture-line button { flex: none; min-height: 44px; margin: -6px 0; padding: 0 10px; font-size: 13px; }

/* --- displays: one button for each of the Mac's displays, only shown when
   there is more than one. The one being shown says so in words as well as
   with its outline. */
.display-set { display: grid; gap: 6px; }
.display-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: var(--gap); }
.display-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  min-width: 0;
  min-height: 48px;
  padding: 5px 10px;
  text-align: left;
  white-space: normal;
  line-height: 1.2;
}
.display-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.display-detail { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.display-option[data-state="current"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.display-option[data-state="current"] .display-name { font-weight: 600; }
.display-option[data-state="pending"] { border-color: var(--accent); border-style: dashed; }
.display-option[aria-disabled="true"] { cursor: default; }
.display-option[aria-disabled="true"][data-state="other"] { opacity: 0.55; }
/* The old display's picture stays up, dimmed, until the new one arrives. */
.session[data-display="switching"] #screen { opacity: 0.55; }
.display-note:empty { display: none; }
.display-note[data-kind="busy"] { color: var(--text); }
.display-note[data-kind="error"]::before { content: "Problem: "; color: var(--bad); font-weight: 600; }

/* --- the Mac's own screen: fit it to this window (in Display), hide it at
   the Mac (At the Mac). One full-width button and the words under it. */
.fx-row { display: grid; gap: 6px; }
.fx-row .key { min-height: 48px; padding: 5px 10px; white-space: normal; line-height: 1.2; }
.fx-row .key[aria-disabled="true"] { opacity: 0.55; cursor: default; }
.fx-note:empty { display: none; }
.fx-note[data-kind="busy"], .fx-note[data-kind="good"] { color: var(--text); }
.fx-note[data-kind="problem"]::before { content: "Problem: "; color: var(--bad); font-weight: 600; }
.hide-chip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }

/* Sound: one switch and the words that say what it is. */
.sound-set { display: grid; gap: 6px; }
.sound-set .key { flex: none; min-width: 96px; min-height: 44px; }
.sound-set .key[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.sound-set .note[data-kind="error"] { color: var(--text); }
.sound-set .note[data-kind="error"]::before { content: "Problem: "; color: var(--bad); font-weight: 600; }

/* --- clipboard */

.clip textarea {
  flex: none;
  min-height: 5.6em;
  max-height: 11em;
  resize: none;
  /* Whatever was copied is shown as it is, long lines included. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.clip-count { min-height: 1.4em; margin-top: -6px; text-align: right; font-variant-numeric: tabular-nums; }
.clip-count[data-over="true"] { color: var(--text); font-weight: 600; }
/* The bar at the side repeats what the words say: working, done, problem. */
.clip-status { padding: 2px 0 2px 10px; border-left: 3px solid var(--line); font-size: 13.5px; line-height: 1.4; }
.clip-status[data-kind="busy"] { border-left-color: var(--accent); }
.clip-status[data-kind="ok"] { border-left-color: var(--good); }
.clip-status[data-kind="error"] { border-left-color: var(--bad); }
.clip-status[data-kind="error"]::before { content: "Problem: "; color: var(--bad); font-weight: 600; }
.clip-set { display: grid; gap: 6px; }
.clip-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
/* These labels are sentences, not key names: they may take two lines. */
.clip-actions .key { padding: 6px 8px; white-space: normal; line-height: 1.2; }
.clip { container-type: inline-size; }
@container (max-width: 300px) { .clip-actions { grid-template-columns: minmax(0, 1fr); } }

/* More below the fold: a fade pinned to the edge of a sheet that scrolls.
   The script sets data-more; the negative margin keeps it from adding to
   the height it is describing. */
.sheet::after {
  content: "";
  display: none;
  position: sticky;
  bottom: -10px;
  flex: none;
  height: 30px;
  /* gap 10 + height 30 - 40 = 0 */
  margin: -40px -10px 0;
  background: linear-gradient(to bottom, transparent, var(--surface) 90%);
  pointer-events: none;
}
.sheet[data-more="true"]::after { display: block; }
.keys-body { display: grid; gap: var(--gap); }

/* The key pad lays itself out from its own width: one row of eight keys
   when they fit at full size, and the shortcuts beside the keys when there
   is room for both. */
@container (min-width: 420px) {
  .keygroup.eight { grid-template-columns: repeat(8, minmax(0, 1fr)); }
}
@container (min-width: 760px) {
  .keys-body { grid-template: "mods chords" auto "keys chords" auto "note note" auto / minmax(0, 1fr) minmax(0, 1fr); column-gap: 14px; }
  .keys-body > .mods { grid-area: mods; }
  .keys-body > .eight { grid-area: keys; }
  .keys-body > .chords { grid-area: chords; }
  .keys-body > .note { grid-area: note; }
}

/* --- cluster: the three buttons of the compact arrangement */

.cluster { grid-area: cluster; display: flex; justify-content: center; gap: 8px; background: var(--surface); }
.cluster-button {
  flex: 1 1 0;
  /* On a wide window three buttons do not need the whole width. */
  max-width: 11rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 10px;
  font-size: 14px;
  font-weight: 600;
}
.cluster-button svg { flex: none; }
.cluster-button[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }

/* ------------------------------------------------- compact arrangement */

.session[data-mode="compact"] .roomy-only { display: none !important; }

.session[data-mode="compact"][data-dock="below"] .cluster {
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1px solid var(--line);
}
/* "safe" and the scrolling keep every button reachable when the rail is
   taller than the space above the keyboard. */
.session[data-mode="compact"][data-dock="side"] .cluster {
  flex-direction: column;
  justify-content: safe center;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  padding: 8px;
  border-left: 1px solid var(--line);
}
.session[data-mode="compact"][data-dock="side"] .cluster::-webkit-scrollbar { display: none; }
.session[data-mode="compact"][data-dock="side"] .cluster-button {
  flex: none;
  flex-direction: column;
  gap: 2px;
  width: 60px;
  min-height: 56px;
  max-width: none;
  padding: 0;
  font-size: 11.5px;
}

/* The compose bar and the sheets lie over the edge of the stage. Closed,
   they are moved out of view rather than removed, so opening is a slide and
   the text in the box is never lost. */
.session[data-mode="compact"] .compose,
.session[data-mode="compact"] .sheet {
  grid-area: stage;
  align-self: end;
  z-index: 3;
  visibility: hidden;
  transform: translateY(100%);
  transition: transform var(--speed) ease-out, visibility 0s linear var(--speed);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.session[data-mode="compact"] .sheet {
  max-height: 72%;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  border-radius: 14px 14px 0 0;
}
.session[data-mode="compact"][data-dock="side"] .sheet {
  justify-self: end;
  align-self: stretch;
  width: min(21rem, 72%);
  max-height: none;
  transform: translateX(100%);
  border-top: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
}
/* The rail's Keys button is right beside it and closes it, so the side
   sheet spends its little height on keys instead of a header. */
.session[data-mode="compact"][data-dock="side"] .keys .sheet-head { display: none; }
.session[data-mode="compact"][data-compose="open"] .compose,
.session[data-mode="compact"][data-sheet="keys"] .keys,
.session[data-mode="compact"][data-sheet="more"] .more,
.session[data-mode="compact"][data-sheet="clip"] .clip {
  visibility: visible;
  transform: none;
  transition: transform var(--speed) ease-out, visibility 0s;
}

/* With the compose bar open the cluster under it steps aside, so the bar
   sits directly on the keyboard. */
.session[data-mode="compact"][data-dock="below"][data-compose="open"] .cluster { display: none; }
.session[data-mode="compact"][data-dock="below"][data-compose="open"] .compose {
  padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
}
.session[data-mode="compact"] .compose .note { display: none; }

/* The compose bar gives up parts of itself, one level at a time, when the
   picture above it would otherwise be a sliver (the script picks the level
   from what is measured, see applyLayout):
     1  the banner shrinks to its title on one line
     2  the banner and the options row go
     3  the status strip and the key strip go too: only the text box, Send
        and the close button stay, and the rail shrinks to icons. */
.session[data-level="1"] .banner { align-items: center; padding-top: 4px; padding-bottom: 4px; }
.session[data-level="1"] .banner-main { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session[data-level="1"] .banner-main span,
.session[data-level="1"] .banner-list,
.session[data-level="1"] #banner-more,
.session[data-level="2"] .banner,
.session[data-level="3"] .banner,
.session[data-level="2"] .compose-options,
.session[data-level="3"] .compose-options,
.session[data-level="3"] .strip,
.session[data-level="3"] .keystrip { display: none; }
.session[data-level="3"] .compose { padding: 6px 10px; }
.session[data-level="3"][data-dock="side"] .cluster { gap: 2px; padding: 2px 8px; }
.session[data-level="3"][data-dock="side"] .cluster-button { min-height: 44px; }
.session[data-level="3"][data-dock="side"] .cluster-button span { display: none; }

/* --------------------------------------------------- roomy arrangement */

.session[data-mode="roomy"] .compact-only,
.session[data-mode="roomy"] .cluster { display: none !important; }
.session[data-mode="roomy"] .compose { grid-area: compose; }
.session[data-mode="roomy"] .compose textarea { min-height: 66px; }
.session[data-mode="roomy"] .keys { grid-area: keys; overflow-y: auto; }

.session[data-mode="roomy"][data-dock="below"] .compose,
.session[data-mode="roomy"][data-dock="below"] .keys {
  border-top: 1px solid var(--line);
  padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
}
.session[data-mode="roomy"][data-dock="side"] .compose,
.session[data-mode="roomy"][data-dock="side"] .keys { border-left: 1px solid var(--line); }
.session[data-mode="roomy"][data-dock="side"] .keys { padding-bottom: calc(env(safe-area-inset-bottom) + 10px); }

/* "More" is a small card that drops from the corner of the stage, and so
   is the clipboard, a little wider for its text. */
.session[data-mode="roomy"] .more,
.session[data-mode="roomy"] .clip {
  grid-area: stage;
  align-self: start;
  justify-self: end;
  z-index: 3;
  width: min(21rem, calc(100% - 20px));
  max-height: calc(100% - 20px);
  margin: 10px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  visibility: hidden;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity var(--speed), transform var(--speed), visibility 0s linear var(--speed);
}
.session[data-mode="roomy"] .clip { width: min(24rem, calc(100% - 20px)); }
.session[data-mode="roomy"][data-sheet="more"] .more,
.session[data-mode="roomy"][data-sheet="clip"] .clip {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity var(--speed), transform var(--speed), visibility 0s;
}

/* ------------------------------------------------------------------ files */

/* The Files sheet behaves like the clipboard's in both arrangements: a
   sheet from the bottom or the side when compact, a card from the corner
   when roomy. The rules are repeated here rather than added to the lists
   above, so this block is all there is to file transfer. */
.files { container-type: inline-size; }
.files-set { display: grid; gap: 8px; }
.files-set .key { min-height: 48px; white-space: normal; line-height: 1.2; }
.files-transfer { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.files-bar {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 10px;
  border: 0;
  border-radius: 5px;
  overflow: hidden;
  background: var(--field);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--accent);
}
.files-bar::-webkit-progress-bar { background: transparent; }
.files-bar::-webkit-progress-value { background: var(--accent); border-radius: 5px; transition: width var(--speed) linear; }
.files-bar::-moz-progress-bar { background: var(--accent); border-radius: 5px; }
.files-status { padding: 2px 0 2px 10px; border-left: 3px solid var(--line); font-size: 13.5px; line-height: 1.4; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.files-status[data-kind="busy"] { border-left-color: var(--accent); }
.files-status[data-kind="ok"] { border-left-color: var(--good); }
.files-status[data-kind="error"] { border-left-color: var(--bad); }
.files-status[data-kind="error"]::before { content: "Problem: "; color: var(--bad); font-weight: 600; }
.files-list { display: grid; gap: var(--gap); padding: 0; list-style: none; }
.files-item {
  display: grid;
  gap: 2px;
  width: 100%;
  min-height: 52px;
  padding: 7px 12px;
  text-align: left;
}
.files-name { font-size: 14.5px; font-weight: 600; overflow-wrap: anywhere; -webkit-user-select: none; user-select: none; }
.files-meta { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.files-saved { display: grid; gap: var(--gap); }
.files-save {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.files-save:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.session[data-mode="compact"][data-sheet="files"] .files {
  visibility: visible;
  transform: none;
  transition: transform var(--speed) ease-out, visibility 0s;
}
.session[data-mode="roomy"] .files {
  grid-area: stage;
  align-self: start;
  justify-self: end;
  z-index: 3;
  width: min(24rem, calc(100% - 20px));
  max-height: calc(100% - 20px);
  margin: 10px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  visibility: hidden;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity var(--speed), transform var(--speed), visibility 0s linear var(--speed);
}
.session[data-mode="roomy"][data-sheet="files"] .files {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity var(--speed), transform var(--speed), visibility 0s;
}

/* ------------------------------------------------------------------ modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.55);
}
.modal-card {
  width: 100%;
  max-width: 360px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.modal-card p { margin: 0 0 16px; }
.modal-row { display: flex; justify-content: flex-end; gap: 8px; }
.modal-row .key { padding: 0 16px; }

.noscript { padding: 24px; }

/* --- desktop keyboards (kb-) */

.kb-set { display: grid; gap: 2px; }
.kb-set .key { margin-top: 6px; }
.kb-set .key[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.kb-chip { background: var(--accent); color: var(--accent-ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }
/* Named actions are words, not key caps: three to a row on a phone, where
   a label may take two lines so the sheet stays short. */
.keygroup.named { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.keygroup.named .key { padding: 2px 4px; font-size: 13px; line-height: 1.2; white-space: normal; }
@container (min-width: 420px) { .keygroup.named { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@container (min-width: 760px) {
  .keys-body { grid-template: "mods chords" auto "keys chords" auto "named named" auto "note note" auto / minmax(0, 1fr) minmax(0, 1fr); }
  .keys-body > .named { grid-area: named; grid-template-columns: repeat(7, minmax(0, 1fr)); }
}
