:root {
  color-scheme: dark;
  --page: #0d0e11;
  --surface: #15171d;
  --line: #2a2e39;
  --text: #eff0f6;
  --muted: #a4a9ba;
  --accent: #a28afb;
  --green: #55d9a2;
  --amber: #efbf72;
  --red: #ffa0a8;
  font-family: system-ui, -apple-system, "Hiragino Sans", sans-serif;
  background: var(--page);
  color: var(--text);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, p { margin: 0; }
p { line-height: 1.65; }
button, input { font: inherit; }
button {
  border: 1px solid var(--line);
  background: #20232c;
  color: var(--text);
  border-radius: .65rem;
  padding: .57rem .75rem;
  cursor: pointer;
}
button:hover { background: #303545; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button:disabled { cursor: default; opacity: .55; }
.primary { background: #a28afb; border-color: #a28afb; color: #171027; font-weight: 700; }
.primary:hover { background: #b39fff; }
.danger { color: var(--red); }
.mono { font: .78rem ui-monospace, SFMono-Regular, monospace; letter-spacing: .045em; color: var(--muted); }
.brand-mark { display: inline-block; width: 1.35rem; height: 1.1rem; border: 2px solid var(--accent); border-radius: .32rem; position: relative; }
.brand-mark::after { content: ""; position: absolute; width: .32rem; height: .32rem; border-radius: 50%; background: var(--accent); inset: auto .2rem .17rem auto; }
.viewer, .screen { background: #000; }
.screen { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.image-button { position: fixed; inset: 0; padding: 0; border: 0; border-radius: 0; width: 100%; height: 100%; background: #000; }
.image-button:hover { background: #000; }
.image-button:focus-visible { outline-offset: -3px; }
.image-button img { display: block; width: 100%; height: 100%; object-fit: contain; }
.viewer-state { max-width: 25rem; text-align: center; display: grid; justify-items: center; gap: .75rem; }
.viewer-state h1 { font-size: 1.15rem; }
.viewer-state p { color: var(--muted); }
.viewer-state form { display: grid; gap: .6rem; width: 100%; }
.viewer-state input { min-width: 0; padding: .6rem; border-radius: .5rem; border: 1px solid var(--line); }
.viewer-controls, .viewer-error { position: fixed; inset: auto 0 max(1rem, env(safe-area-inset-bottom)); justify-content: center; }
.viewer-error { margin: auto; text-align: center; color: var(--amber); pointer-events: none; }
.viewer-controls:not([hidden]) + .viewer-error { bottom: max(4rem, calc(env(safe-area-inset-bottom) + 3rem)); }

.desktop {
  --page: #0a0b0d;
  --surface: #111317;
  --panel: #171a1f;
  --button: #20242b;
  --line: #2a2f37;
  --text: #e9ebf0;
  --muted: #8a91a0;
  --accent: #8a5cf6;
  --green: #3ccf8e;
  --amber: #f0b43c;
  --red: #ff6b6b;
  --mono: "JetBrains Mono", "SF Mono", Menlo, monospace;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
}
:root:has(.desktop[data-theme="light"]) { color-scheme: light; background: #e4e7ed; }
.desktop[data-theme="light"] {
  color-scheme: light;
  --page: #e4e7ed;
  --surface: #f6f7f9;
  --panel: #fff;
  --button: #e8eaef;
  --line: #d8dbe3;
  --text: #14161b;
  --muted: #5b6272;
  --accent: #7446ee;
  --green: #087949;
  --amber: #956600;
  --red: #c73131;
}
.desktop .icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.desktop .icon { display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.desktop .icon.large { width: 40px; height: 40px; }
.desktop-stage {
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  isolation: isolate;
  border: 1px solid var(--line);
  border-radius: 0 0 14px 14px;
  background: var(--surface);
}
.desktop-stage:has(.stage-dialog[open])::after { content: ""; position: absolute; inset: 0; background: #0007; backdrop-filter: blur(4px); z-index: 4; }
.desktop-center { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px 16px 80px; }
.desktop-status { position: absolute; top: 16px; left: 18px; z-index: 1; display: flex; align-items: center; gap: 8px; color: var(--muted); font: 500 11px var(--mono); pointer-events: none; }
.desktop-status::before { content: ""; width: 7px; height: 7px; background: var(--muted); border-radius: 50%; }
.desktop-status[data-tone="online"]::before { background: var(--green); }
.desktop-status[data-tone="pending"]::before { background: var(--amber); }
.desktop-status[data-tone="busy"]::before { background: var(--accent); }
.initial-pair, .desktop-empty, .desktop-preview { display: grid; justify-items: center; gap: 12px; text-align: center; color: var(--muted); }
.initial-pair { gap: 18px; font: 500 13px var(--mono); letter-spacing: .12em; }
.initial-pair img { display: block; width: min(240px, 70vw, max(90px, calc(100dvh - 160px))); height: auto; border-radius: 16px; background: white; }
.desktop-empty { font-size: 13px; }
.desktop-empty strong { color: var(--text); font-size: 16px; }
.desktop button { background: var(--button); color: var(--text); border-color: var(--line); font-size: 13px; }
.desktop button:hover { border-color: var(--muted); }
.desktop button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.desktop button.primary:hover { border-color: var(--accent); filter: brightness(1.12); }
.desktop button.danger { color: var(--red); }
.desktop button.upload-target, .desktop button.text-button { background: transparent; border-color: transparent; color: var(--muted); }
.desktop button.upload-target { display: grid; justify-items: center; gap: 12px; padding: 0; font: 12px var(--mono); }
.desktop button.upload-target:hover { color: var(--text); }
.desktop button.text-button { color: var(--accent); padding: 2px 4px; }
.image-frame { width: 212px; height: min(460px, 68dvh); display: grid; border-radius: 24px; border: 1px solid var(--line); background: #000; overflow: hidden; }
.image-frame img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.desktop-preview output { font: 500 11px var(--mono); }
.desktop-preview[data-live="true"] output { color: var(--green); }
.toolbar { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px; box-shadow: 0 8px 30px #0003; z-index: 2; }
.desktop .toolbar button { position: relative; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; padding: 0; border-color: transparent; background: transparent; color: var(--muted); }
.desktop .toolbar button:hover { background: var(--button); color: var(--text); }
.desktop .toolbar button[aria-expanded="true"] { color: var(--accent); }
.desktop .toolbar button.danger:hover { color: var(--red); }
.toolbar-divider { width: 1px; height: 20px; margin: 0 4px; background: var(--line); }
.toolbar-badge { position: absolute; top: 1px; right: 1px; min-width: 15px; padding: 1px 3px; border-radius: 8px; background: var(--accent); color: #fff; font: 9px/13px var(--mono); }
.toolbar-badge.cli-dot { top: 5px; right: 6px; height: 6px; min-width: 6px; padding: 0; background: var(--green); }
.desktop-popover { position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 3; width: min(340px, calc(100% - 24px)); max-height: calc(100% - 110px); overflow: auto; display: grid; gap: 10px; padding: 14px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 12px 40px #0004; font-size: 12px; }
.desktop-popover h3 { margin: 0; color: var(--text); font-size: 13px; }
.desktop-popover .section-head, .device, .row { display: flex; align-items: center; gap: 6px; }
.desktop-popover .section-head, .device { justify-content: space-between; }
.row, .device { flex-wrap: wrap; }
.desktop-popover .section-head span, #code-expiry { font: 11px var(--mono); }
.device-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.device strong { color: var(--text); }
.desktop .pair-actions { display: flex; gap: 12px; align-items: center; border-top: 1px solid var(--line); padding-top: 10px; }
.pair-actions img { border-radius: 7px; flex: none; }
.desktop .pair-actions button { font-size: 11px; padding: 4px 6px; }
.desktop .command { margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--surface); font: 11px var(--mono); overflow-wrap: anywhere; }
.desktop #code { display: grid; justify-items: start; gap: 8px; }
.desktop-feedback { position: absolute; z-index: 7; top: 14px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 7px 12px; border-radius: 10px; color: var(--text); background: var(--panel); border: 1px solid var(--line); text-align: center; font-size: 12px; }
.desktop #drop-overlay { display: none; position: absolute; inset: 12px; z-index: 6; place-items: center; pointer-events: none; border: 2px dashed var(--accent); border-radius: 16px; background: #8a5cf629; color: var(--accent); font: 13px var(--mono); }
.desktop .desktop-stage.drag #drop-overlay { display: grid; }
.desktop .stage-dialog { position: absolute; z-index: 5; inset: 50% auto auto 50%; transform: translate(-50%, -50%); margin: 0; width: min(300px, calc(100% - 30px)); padding: 24px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--text); text-align: center; box-shadow: 0 20px 60px #0005; }
.stage-dialog[open] { display: grid; justify-items: center; gap: 8px; }
.stage-dialog h3 { margin: 0; font-size: 15px; }
.stage-dialog p { color: var(--muted); font-size: 12px; }
.stage-dialog .icon { color: var(--accent); width: 32px; height: 32px; margin-bottom: 6px; }
.request-actions { display: flex; width: 100%; gap: 10px; margin-top: 8px; }
.request-actions button { flex: 1; }
