:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe1ec;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.06), 0 8px 24px rgb(15 23 42 / 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --surface: #131c2e;
    --surface-2: #1b2638;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #273449;
    --accent: #3b82f6;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #131c2e; --surface-2: #1b2638; --text: #e2e8f0;
  --muted: #94a3b8; --border: #273449; --accent: #3b82f6; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-left: auto; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.status.online .dot { background: var(--ok); }
.status.offline .dot { background: var(--danger); }

.home {
  display: grid; gap: 16px; padding: 16px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  max-width: 960px; margin: 24px auto;
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px;
}
h2 { margin: 0; font-size: 18px; }
h3 { margin: 16px 0 4px; font-size: 14px; color: var(--muted); font-weight: 600; }
label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.big-value {
  font: 600 30px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.04em; user-select: all;
}
.big-value.small { font-size: 22px; flex: 1; }

input:not([type=checkbox]), select {
  font: inherit; color: inherit; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#remote-id { font: 600 20px ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.04em; }

button {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { background: transparent; }
button.icon { padding: 6px 10px; font-size: 16px; }
button:disabled { opacity: 0.55; cursor: default; }
#connect-btn { margin-top: 14px; }

.switch { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin-top: 14px; }
.notice { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin-top: 10px; font-size: 13px; }
.notice p { margin: 0 0 8px; color: var(--muted); }
.message { min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }
.message.error { color: var(--danger); }

.recent { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.recent li button {
  width: 100%; text-align: left; display: flex; justify-content: space-between; gap: 8px;
  background: transparent; border-color: transparent;
}
.recent li button:hover { background: var(--surface-2); }
.recent .id { font-family: ui-monospace, Menlo, Consolas, monospace; }

.host-sessions { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 5; max-width: calc(100vw - 32px); }
.host-session {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--danger);
  border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow);
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 14px;
}
.host-session .switch { margin: 0; font-size: 13px; }

.viewer { position: fixed; inset: 0; background: #000; display: flex; flex-direction: column; z-index: 10; }
.viewer-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 10px; background: #111827; color: #e5e7eb;
}
.viewer-bar button, .viewer-bar select { padding: 5px 10px; font-size: 13px; width: auto; color: #e5e7eb; border-color: #374151; background: #1f2937; }
.viewer-bar button.danger { background: var(--danger); border-color: var(--danger); }
.viewer-bar .peer { font-weight: 600; margin-right: auto; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #374151; }
.badge.direct { background: #14532d; }
.badge.relayed { background: #78350f; }
.viewer-stage { position: relative; flex: 1; min-height: 0; }
#remote-video { width: 100%; height: 100%; object-fit: contain; outline: none; cursor: default; touch-action: none; }
.viewer-overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #e5e7eb; font-size: 16px; text-align: center; padding: 16px; pointer-events: none;
}

dialog {
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
  padding: 20px; width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog form { display: flex; flex-direction: column; gap: 6px; }
dialog h3 { margin: 0 0 4px; color: var(--text); font-size: 17px; }
menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 16px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: #111827; color: #f9fafb; padding: 10px 16px; border-radius: 8px; font-size: 14px;
  max-width: calc(100vw - 32px);
}

@media (max-width: 600px) {
  .home { margin: 0; padding: 12px; }
  .big-value { font-size: 26px; }
  .viewer-bar #viewer-cad, .viewer-bar #viewer-clipboard { display: none; }
}

.ghost-link { font-size: 13px; color: var(--accent); text-decoration: none; }
.plan-chip { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px; text-transform: uppercase; letter-spacing: 0.04em; }
.plan-chip.paid { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.account-box { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px 10px; margin: 0 0 6px; display: flex; flex-direction: column; gap: 4px; }
.account-box legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.account-box p { margin: 4px 0; font-size: 14px; }
.row-end { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
.row-end a { font-size: 13px; color: var(--accent); }
.badge.warn { background: #92400e; }

.update-bar { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; padding: 8px 16px; background: var(--accent); color: var(--accent-text); font-size: 14px; }
.update-bar button { background: #fff; color: var(--accent); border-color: #fff; padding: 4px 12px; }
