:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --fg: #e9edf2;
  --dim: #8b95a3;
  --line: #212832;
  --accent: #4c9aff;
  --warn: #ffb44c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

#stage { height: 100%; display: grid; place-items: center; padding: 24px; }

.pane { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.pane.hidden, .hidden { display: none; }

/* The QR must stay crisp — the phone has to read it off this screen. */
#qr {
  width: min(320px, 70vmin);
  height: auto;
  border-radius: 12px;
  background: #fff;
  padding: 10px;
  image-rendering: pixelated;
}

.hint { margin: 0; font-size: 17px; }
.sub  { margin: 0; color: var(--dim); font-size: 13px; }

h1 { margin: 0; font-size: 20px; font-weight: 600; }

button {
  font: inherit;
  color: var(--fg);
  background: #1a1f27;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }

/* ------------------------------------------------------------- viewer */

/* The viewer escapes #stage entirely. #stage centres its child and adds
   padding, which is right for the QR but leaves the viewer without a definite
   size — and noVNC can only scale-to-fit against a container whose height it
   can actually measure. Without this the desktop renders at native size and
   overflows with a scrollbar. */
.pane.wide {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  gap: 0;
  padding: 0;
  background: var(--bg);
  z-index: 10;
}

#bar {
  width: 100%;
  flex: 0 0 auto;            /* never let the toolbar be squeezed away */
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.badge {
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--dim);
}
/* Control mode is the riskier state — make it visibly different, not decorative. */
.badge.control { color: var(--warn); border-color: var(--warn); }

.clock { margin-left: auto; color: var(--dim); font-variant-numeric: tabular-nums; }

/* min-height/min-width 0 matter: without them a flex item refuses to shrink
   below its content, so the canvas pushes the layout wider than the window. */
#screen {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: #000;
}

/* The Mac's video stream: one canvas, centred, sized in JS to fit. */
#screen.video { display: flex; align-items: center; justify-content: center; }
#screen canvas.video { display: block; outline: none; touch-action: none; }

/* Full screen: the bar leaves the layout so the picture gets every pixel,
   and waits just above the top edge until the tab brings it down. */
#handle {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: 64px;
  height: 12px;
  padding: 0;
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: rgba(26, 31, 39, .8);
  opacity: .55;
}
#handle:hover { opacity: 1; }
#pane-view.full #bar {
  position: fixed;
  top: 0;
  left: 50%;
  z-index: 21;
  /* Its own width, not what's left right of centre (left: 50% would halve it). */
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translate(-50%, -110%);
  transition: transform .18s ease;
  background: rgba(11, 13, 16, .94);
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 12px 12px;
}
#pane-view.full #bar.shown { transform: translate(-50%, 0); }

/* Keys a browser won't pass on, sent from a menu. */
.keys-wrap { position: relative; }
#keys-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  width: 250px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  background: #151a21;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  text-align: left;
}
#keys-menu.hidden { display: none; }
#keys-menu button {
  border: none;
  background: none;
  text-align: left;
  padding: 6px 10px;
}
#keys-menu button:hover { background: #222a35; }
#keys-menu small { color: var(--dim); margin-left: 6px; }
#keys-menu p { margin: 6px 10px 4px; font-size: 12px; line-height: 1.4; color: var(--dim); }
