/* Kiste desktop viewer.
   The remote desktop owns every pixel. The overlay is one small black chip in
   the top-right corner that unfolds into a panel of readouts and controls,
   and folds away to a dot. Black and white like the rest of kiste.run; the
   only colour is the blue "live" dot. */

@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-display: swap; src: url("/desktop/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 500; font-display: swap; src: url("/desktop/fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-display: swap; src: url("/desktop/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); }

:root {
  --ground: #0a0a0a;
  --glass: #111111;
  --glass-solid: #111111;
  --edge: rgba(255, 255, 255, 0.08);
  --edge-strong: rgba(255, 255, 255, 0.18);
  --ink: #fafafa;
  --ink-dim: #a3a3a3;
  --ink-faint: #737373;
  --live: #6ea8fe;
  --sans: "IBM Plex Sans", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ---- The surface owns the window ---- */

/* Sized to the visual viewport by the viewer (fitToVisibleViewport): the
   visible part of the page on a phone, under the notch and the home
   indicator too (viewport-fit=cover). Without script it is the window. */
#workspace { position: fixed; top: 0; left: 0; width: 100%; height: 100%; }

#viewport {
  position: absolute;
  inset: 0;
  outline: none;
  background: var(--ground);
  /* Every touch is the guest's: no scrolling, no pinch, no double-tap zoom,
     no text selection callout or long-press menu of the browser's. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#surface, #rfb-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#surface { object-fit: contain; background: var(--ground); }
#rfb-stage > * { width: 100%; height: 100%; }

/* ---- Overlay chip ---- */

.console {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 40;
  width: max-content;
  max-width: calc(100vw - 24px);
  transition: opacity 0.4s ease;
}

/* While the stream is live and the overlay is closed and unhovered, it
   recedes — the desktop is what matters. */
body:has(#viewport[data-live="true"]) .console:not([open]):not(:hover):not(:focus-within) {
  opacity: 0.35;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--glass);
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-size: 12px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
/* No backdrop blur anywhere: over a live picture it samples the video every
   frame, which keeps it off the display's overlay plane (direct scanout) and
   costs a compositor pass per frame. Solid surfaces instead. */
.chip::-webkit-details-marker { display: none; }
.chip:hover { border-color: var(--edge-strong); }
.chip:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.chip strong {
  font-weight: 500;
  color: var(--ink);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: lowercase;
}

.chip #status {
  font-size: 11px;
  color: var(--ink-dim);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: lowercase;
}

.chip-fps {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.chip-fps:empty { display: none; }

.chip .chevron { color: var(--ink-faint); transition: transform 0.2s ease; }
.console[open] .chip .chevron { transform: rotate(180deg); }

/* Folded away: only the status dot stays, as a small button in the corner. */
.console[data-hidden="true"]:not([open]) .chip {
  width: 22px;
  height: 22px;
  padding: 0;
  justify-content: center;
}
.console[data-hidden="true"]:not([open]) .chip > :not(#lamp) { display: none; }

/* Lamps: a 6px dot. Idle is grey, live is blue. */
#lamp, #input-lamp {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex: none;
  display: inline-block;
  transition: background 0.3s ease;
}
#lamp[data-live="true"], #input-lamp[data-live="true"] { background: var(--live); }

/* ---- Panel ---- */

.panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 296px;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 60px);
  overflow-y: auto;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--glass-solid);
  padding: 12px;
  display: grid;
  gap: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
}
.brand:hover { color: #fff; }
.brand:focus-visible, .panel-hide:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.panel-hide {
  appearance: none;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
}
.panel-hide:hover { color: var(--ink); border-color: var(--edge-strong); }

.telemetry {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--edge);
  border-radius: 8px;
  overflow: hidden;
}
.telemetry > div {
  padding: 7px 10px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  border-bottom: 1px solid var(--edge);
}
.telemetry > div:nth-child(odd):not(.wide) { border-right: 1px solid var(--edge); }
.telemetry > div:last-child { border-bottom: none; }
.telemetry > div.wide { grid-column: 1 / -1; }
.telemetry dt {
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}
.telemetry dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.telemetry dd b { font-weight: 500; }
.telemetry dd i { vertical-align: 1px; margin-right: 2px; }

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.actions button {
  appearance: none;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-dim);
  font-family: var(--sans);
  padding: 8px 4px 7px;
  display: grid;
  justify-items: center;
  gap: 4px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.actions button[hidden] { display: none; }
.actions button span { font-size: 14px; line-height: 1; }
.actions button small { font-size: 10.5px; text-transform: lowercase; }
.actions button small::first-letter { text-transform: uppercase; }
.actions button:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--edge-strong);
  background: rgba(255, 255, 255, 0.04);
}
.actions button:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.actions button:disabled { opacity: 0.35; cursor: default; }
.actions button.engaged {
  color: var(--ground);
  background: var(--ink);
  border-color: var(--ink);
}

.select {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 7px 10px;
}
.select:focus-within { border-color: var(--edge-strong); }
.select small {
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}
.select select {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  text-align: right;
  cursor: pointer;
  outline: none;
  min-width: 0;
}
.select select option { background: #171717; color: var(--ink); }

/* ---- Message overlay (connection states) ---- */

#message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--ground);
}
#message[hidden] { display: none; }

.message-card {
  width: min(26rem, 100%);
  border: 1px solid var(--edge);
  border-radius: 14px;
  background: #111;
  padding: 24px;
  display: grid;
  gap: 14px;
}

.message-kicker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-faint);
}
.message-brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}
.message-kicker b { font-family: var(--mono); font-weight: 400; }

#title {
  margin: 0;
  font-weight: 600;
  font-size: clamp(22px, 4.5vw, 28px);
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-transform: lowercase;
}
#title::first-letter { text-transform: uppercase; }
#title em { font-style: normal; color: var(--ink-dim); }

#detail {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-dim);
}

#security-note {
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-faint);
  border-top: 1px solid var(--edge);
  padding-top: 12px;
}

#message-action {
  justify-self: start;
  appearance: none;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--ground);
  background: var(--ink);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  text-transform: lowercase;
  transition: background 0.15s ease;
}
#message-action::first-letter { text-transform: uppercase; }
#message-action:hover { background: #fff; }
#message-action:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
#message-action[hidden] { display: none; }

/* Progress: a quiet bar and the stream state beside it. */
.machine-cutaway {
  display: flex;
  align-items: center;
  gap: 10px;
}
.machine-cutaway .fan { display: none; }
.machine-cutaway .bus { display: flex; gap: 3px; flex: none; }
.machine-cutaway .bus i {
  width: 3px;
  height: 10px;
  background: var(--ink-faint);
  border-radius: 1px;
  animation: pulse 1.4s ease-in-out infinite;
}
.machine-cutaway .bus i:nth-child(2) { animation-delay: 0.12s; }
.machine-cutaway .bus i:nth-child(3) { animation-delay: 0.24s; }
.machine-cutaway .bus i:nth-child(4) { animation-delay: 0.36s; }
.machine-cutaway .bus i:nth-child(5) { animation-delay: 0.48s; }
.machine-cutaway .bus i:nth-child(6) { animation-delay: 0.6s; }
.machine-cutaway span {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-dim);
  text-transform: lowercase;
}

@keyframes pulse {
  0%, 100% { transform: scaleY(0.5); opacity: 0.4; }
  50% { transform: scaleY(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .machine-cutaway .bus i { animation: none; }
  .console, .chip, .chip .chevron { transition: none; }
}

/* Phones: the chip stays a chip in the corner (it never spans the top of the
   desktop); the open panel uses the width of the screen. */
@media (max-width: 480px) {
  .console {
    right: max(8px, env(safe-area-inset-right));
    top: max(8px, env(safe-area-inset-top));
  }
  .chip strong { max-width: 96px; }
  .chip #status { max-width: 110px; }
  .panel { width: calc(100vw - 16px); max-width: none; }
}
