
  * { box-sizing: border-box; }

  :root, [data-theme="dark"] {
    --bg: #161618;
    --surface: #1e1e21;
    --surface-2: #26262a;
    --border: #333338;
    --border-soft: #2a2a2e;
    --text: #e8e8ea;
    --muted: #8f8f98;
    --accent: #a855f7;
    --ok: #34d399;
    --err: #f87171;
  }
  [data-theme="light"] {
    --bg: #f6f6f7;
    --surface: #ffffff;
    --surface-2: #f1f1f3;
    --border: #dcdce1;
    --border-soft: #e6e6ea;
    --text: #1b1b1e;
    --muted: #6a6a72;
    --accent: #7c3aed;
    --ok: #15803d;
    --err: #b91c1c;
  }
  [data-theme="mocha"] {
    --bg: #1e1e2e;
    --surface: #313244;
    --surface-2: #45475a;
    --border: #45475a;
    --border-soft: #313244;
    --text: #cdd6f4;
    --muted: #a6adc8;
    --accent: #cba6f7;
    --ok: #a6e3a1;
    --err: #f38ba8;
  }

  html, body { margin: 0; height: 100%; }
  body {
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
  }

  .layout { display: flex; min-height: 100vh; }

  /* ---------- sidebar ---------- */
  .sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
  }
  .sidebar-title {
    padding: 18px 20px 16px;
    font-size: 15px;
    font-weight: 650;
    border-bottom: 1px solid var(--border-soft);
  }
  .sidebar nav { padding: 8px; flex: 1; }
  .nav-item {
    display: block;
    padding: 6px 12px;
    border-radius: 6px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
  }
  .nav-item:hover { background: var(--surface-2); }
  .nav-item.active { background: var(--surface-2); color: var(--accent); }
  .sidebar-footer { padding: 12px 20px; border-top: 1px solid var(--border-soft); }
  .sidebar-footer-row { justify-content: flex-start; }
  .sidebar-footer button { width: auto; }
  .icon-btn { height: 34px; display: inline-flex; align-items: center; justify-content: center; padding: 0 10px; }
  .icon-btn img { display: block; }
  [data-theme="dark"] .icon-btn img,
  [data-theme="mocha"] .icon-btn img { filter: invert(1); }
  .sidebar-footer label { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
  .sidebar-footer .conn-note { color: var(--err); font-size: 12.5px; margin-top: 4px; }

  /* ---------- modal ---------- */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
  }
  .modal-backdrop[hidden] { display: none; }
  .modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    width: 360px;
    max-width: 92vw;
  }
  .modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
  .modal-head h2 { margin: 0; }
  .btn.active { border-color: var(--accent); color: var(--accent); }
  .conn-note { color: var(--err); font-size: 12.5px; margin-top: 8px; }

  /* ---------- main ---------- */
  main { flex: 1; padding: 28px 36px; min-width: 0; max-width: 1100px; }
  .page-head { margin-bottom: 20px; }
  h1 { font-size: 20px; font-weight: 650; margin: 0 0 6px; letter-spacing: -0.01em; }
  .page-sub { color: var(--muted); margin: 0; font-size: 13px; }
  h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
  .hidden { display: none; }

  /* ---------- panels ---------- */
  .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
  }
  .panel-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    margin: 0 0 12px;
  }
  .group { margin-bottom: 18px; }
  .group:last-child { margin-bottom: 0; }
  .group-title {
    font-size: 13px;
    font-weight: 600;
    padding-bottom: 6px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-soft);
  }

  /* ---------- device card ---------- */
  .device-card .device-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 16px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-soft);
  }
  .device-name { font-size: 16px; font-weight: 650; }
  .device-sub { color: var(--muted); font-size: 13px; }
  .device-head .spacer { flex: 1; }
  .status { font-size: 13px; }
  .status.ok { color: var(--ok); }
  .status.err { color: var(--err); }
  .status.off { color: var(--muted); }

  table.specs { width: 100%; border-collapse: collapse; font-size: 13.5px; }
  table.specs td { padding: 7px 0; border-bottom: 1px solid var(--border-soft); }
  table.specs tr:last-child td { border-bottom: none; }
  table.specs td:first-child { color: var(--muted); width: 160px; }
  table.specs td.mono { font-family: ui-monospace, monospace; font-size: 13px; }

  .daemon-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; }
  .daemon-row:last-child { border-bottom: none; }
  .daemon-row span:first-child { color: var(--muted); }

  /* ---------- settings grid ---------- */
  .settings-grid {
    display: grid;
    grid-template-columns: minmax(300px, 460px) 1fr;
    gap: 16px;
    align-items: start;
  }
  @media (max-width: 940px) { .settings-grid { grid-template-columns: 1fr; } }

  .screen {
    background: #000;
    border: 1px solid #000;
    border-radius: 4px;
    padding: 12px;
  }
  .screen canvas {
    display: block;
    width: 100%;
    cursor: default;
    touch-action: none;
  }
  #gif-src {
    position: absolute;
    left: -99999px;
    top: 0;
    width: 1px;
    height: 1px;
  }
  .screen-meta {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 12.5px;
    margin-top: 12px;
  }
  .drag-hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

  /* ---------- tabs ---------- */
  .tabs {
    display: flex;
    gap: 20px;
    border-bottom: 1px solid var(--border);
    margin: 0 0 20px;
  }
  .tab {
    padding: 6px 2px 8px;
    border: none;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
  }
  .tab:hover { color: var(--text); }
  .tab.active { color: var(--text); border-bottom-color: var(--accent); }

  /* ---------- forms ---------- */
  .form-row { margin-bottom: 14px; }
  .form-row label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 13px; }
  .form-row input[type="text"],
  .form-row input[type="number"],
  .form-row select,
  .inline input[type="text"] {
    width: 100%;
    padding: 6px 9px;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
  }
  .form-row input:focus, .form-row select:focus, .inline input[type="text"]:focus {
    outline: 2px solid var(--accent);
    outline-offset: 0;
    border-color: transparent;
  }
  .inline { display: flex; gap: 8px; align-items: center; }
  .inline .form-row { margin-bottom: 0; flex: 1; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .grid-3 { display: grid; grid-template-columns: 1fr 90px 100px; gap: 10px; }
  .checkbox { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 14px; }
  .checkbox input { width: auto; }
  input[type="file"] { font-size: 13.5px; color: var(--muted); }
  input[type="file"]::file-selector-button {
    font: inherit;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    margin-right: 10px;
    cursor: pointer;
  }

  /* ---------- text lines ---------- */
  .text-line {
    display: grid;
    grid-template-columns: 2fr 64px 88px 74px 44px 44px 30px;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
  }
  .text-line input, .text-line select {
    width: 100%;
    padding: 5px 8px;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
  }
  .text-line input:focus, .text-line select:focus { outline: 2px solid var(--accent); border-color: transparent; }
  .text-line.selected { outline: 1px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
  .text-line .btn { padding: 5px 0; }

  /* ---------- buttons ---------- */
  .btn {
    padding: 6px 14px;
    font: inherit;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
  }
  .btn:hover { border-color: var(--muted); }
  .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  .btn.primary:hover { filter: brightness(1.08); }
  .btn:disabled { opacity: 0.5; cursor: default; }

  .action-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-soft);
  }
  .scene-summary { color: var(--muted); font-size: 13px; margin-left: auto; text-align: right; }
  #dirty-note { color: var(--accent); margin-left: 0; }
