:root {
      color-scheme: dark;
      --bg: #0f1218;
      --panel: #171c26;
      --panel-2: #1e2533;
      --line: #2c3548;
      --text: #e8edf7;
      --muted: #93a0b8;
      --accent: #6ea8fe;
      --user: #243044;
      --bot: #1a2230;
      --danger: #ff8b8b;
      --ok: #8ee0b2;
    }

    * { box-sizing: border-box; }

    html, body {
      height: 100%;
      overflow: hidden;
    }

    body {
      margin: 0;
      font-family: "Segoe UI", system-ui, sans-serif;
      background: var(--bg);
      color: var(--text);
    }

    .app {
      max-width: 860px;
      margin: 0 auto;
      height: 100vh;
      height: 100dvh;
      display: flex;
      flex-direction: column;
      padding: 20px 16px 0;
      overflow: hidden;
    }

    header, .picker, .stress {
      flex: none;
    }

    .main {
      flex: 1;
      min-height: 0;
      overflow-y: auto;
      padding-bottom: 16px;
    }

    .title-row {
      display: flex;
      align-items: center;
      gap: 12px;
      margin: 0 0 4px;
    }

    a.brand {
      width: 32px;
      height: 32px;
      flex: none;
      display: grid;
      place-items: center;
      color: #29abe2;
      background: rgba(41, 171, 226, 0.08);
      border: 1.5px solid rgba(41, 171, 226, 0.35);
      clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
      font-size: 12px;
      line-height: 1;
      text-decoration: none;
    }

    header h1 {
      margin: 0;
      font-size: 1.35rem;
      font-weight: 650;
    }

    .picker-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }

    .stress-controls {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      justify-content: flex-end;
      gap: 6px;
    }

    input.stress-threads {
      width: 58px;
      margin: 0;
      padding: 4px 4px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: var(--panel-2);
      color: inherit;
      font: inherit;
      font-size: 0.75rem;
      line-height: 1.2;
      text-align: center;
    }

    input.stress-threads:focus {
      outline: 2px solid #3d5f99;
      border-color: transparent;
    }

    button.stress-launch {
      width: auto;
      margin: 0;
      padding: 4px 8px;
      border-radius: 8px;
      font-size: 0.75rem;
      font-weight: 600;
      line-height: 1.2;
    }

    .summary-gate {
      position: fixed;
      inset: 0;
      z-index: 40;
      display: grid;
      place-items: center;
      padding: 16px;
      background: rgba(0, 0, 0, 0.55);
    }

    .summary-gate[hidden] { display: none !important; }

    .summary-card {
      width: min(560px, 100%);
      max-height: min(80vh, 640px);
      overflow: auto;
      border: 1px solid var(--line);
      border-radius: 14px;
      background: var(--panel);
      color: var(--text);
      padding: 16px;
    }

    .summary-card h2 {
      margin: 0 0 6px;
      font-size: 1.05rem;
    }

    .summary-card p {
      margin: 0 0 12px;
      color: var(--muted);
      font-size: 0.85rem;
    }

    .summary-card table {
      width: 100%;
      border-collapse: collapse;
      font-size: 0.84rem;
    }

    .summary-card th,
    .summary-card td {
      padding: 7px 6px;
      border-bottom: 1px solid var(--line);
      text-align: right;
      white-space: nowrap;
    }

    .summary-card th:first-child,
    .summary-card td:first-child {
      text-align: left;
    }

    .summary-card .fail { color: var(--danger); }
    .summary-card td.msg { text-align: left; }

    .summary-card .totals {
      margin: 12px 0 14px;
      color: var(--ok);
      font-size: 0.84rem;
      white-space: pre-wrap;
    }

    .summary-card button {
      display: block;
      margin-left: auto;
      padding: 8px 14px;
    }

    .login-gate {
      position: fixed;
      inset: 0;
      z-index: 50;
      display: grid;
      place-items: center;
      padding: 16px;
      background: rgba(0, 0, 0, 0.62);
    }

    .login-gate[hidden] {
      display: none !important;
    }

    .login-card {
      width: min(380px, 100%);
      display: grid;
      gap: 12px;
      border: 1px solid var(--line);
      border-radius: 14px;
      background: var(--panel);
      color: var(--text);
      padding: 18px;
    }

    .login-card h2 {
      margin: 0;
      font-size: 1.05rem;
    }

    .login-card p {
      margin: 0;
      color: var(--muted);
      font-size: 0.85rem;
    }

    .login-card label {
      display: grid;
      gap: 4px;
    }

    .login-card input[type="text"],
    .login-card input[type="password"] {
      width: 100%;
      background: var(--panel-2);
      border: 1px solid var(--line);
      border-radius: 10px;
      padding: 10px 12px;
      color: inherit;
      font: inherit;
    }

    .login-card input:focus {
      outline: 2px solid #3d5f99;
      border-color: transparent;
    }

    .login-card .remember {
      display: flex;
      align-items: center;
      gap: 8px;
      color: var(--text);
    }

    .login-card .login-error {
      color: var(--danger);
    }

    button.gpu-toggle {
      padding: 6px 10px;
      font-size: 0.82rem;
      font-weight: 600;
    }

    button.gpu-toggle[aria-expanded="true"] {
      color: var(--text);
      border-color: var(--accent);
    }

    .gpu-opacity {
      display: flex;
      align-items: center;
      gap: 6px;
      color: var(--muted);
      font-size: 0.75rem;
    }

    .gpu-opacity input {
      width: 92px;
      accent-color: var(--accent);
      cursor: pointer;
    }

    header p {
      margin: 0 0 12px;
      color: var(--muted);
      font-size: 0.92rem;
    }

    .gpus {
      position: fixed;
      z-index: 20;
      top: 92px;
      left: 0;
      width: 100vw;
      height: calc(100vh - 100px);
      margin: 0;
      opacity: 1;
      display: grid;
      grid-auto-flow: column;
      grid-auto-columns: minmax(0, 1fr);
      gap: 6px;
    }

    .gpus[hidden] { display: none !important; }

    .gpu {
      height: 100%;
      min-width: 0;
      display: flex;
      flex-direction: column;
      background: #000;
      border: 1px solid var(--line);
      border-radius: 10px;
      overflow: hidden;
    }

    .gpu span {
      padding: 4px 10px;
      font-size: 0.75rem;
      color: var(--muted);
      background: var(--panel);
      border-bottom: 1px solid var(--line);
    }

    .gpu iframe {
      flex: 1;
      width: 100%;
      border: 0;
      background: #000;
    }

    .picker {
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: 14px;
      padding: 14px;
      display: grid;
      gap: 8px;
    }

    label {
      font-size: 0.82rem;
      color: var(--muted);
    }

    select, textarea, button {
      font: inherit;
      color: inherit;
    }

    select, textarea {
      width: 100%;
      background: var(--panel-2);
      border: 1px solid var(--line);
      border-radius: 10px;
      padding: 10px 12px;
    }

    select:focus, textarea:focus {
      outline: 2px solid #3d5f99;
      border-color: transparent;
    }

    .endpoint {
      font-size: 0.82rem;
      color: var(--muted);
      word-break: break-all;
    }

    .endpoint strong { color: var(--text); font-weight: 600; }

    .chat {
      min-height: 240px;
      margin-top: 14px;
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: 14px;
      padding: 14px;
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

    .empty {
      margin: auto;
      text-align: center;
      color: var(--muted);
      max-width: 360px;
      line-height: 1.45;
    }

    .msg {
      position: relative;
      max-width: 85%;
      padding: 10px 28px 10px 12px;
      border-radius: 12px;
      white-space: pre-wrap;
      word-break: break-word;
      line-height: 1.45;
    }

    button.msg-copy {
      position: absolute;
      top: 4px;
      right: 4px;
      width: 18px;
      height: 18px;
      padding: 0;
      border: 0;
      border-radius: 4px;
      background: transparent;
      color: var(--muted);
      display: grid;
      place-items: center;
      opacity: 0.55;
    }

    button.msg-copy:hover { opacity: 1; color: var(--text); }

    .msg.user {
      align-self: flex-end;
      background: var(--user);
      border-bottom-right-radius: 4px;
    }

    .msg.assistant {
      align-self: flex-start;
      background: var(--bot);
      border: 1px solid var(--line);
      border-bottom-left-radius: 4px;
    }

    .who {
      display: block;
      margin-bottom: 4px;
      font-size: 0.75rem;
      color: var(--accent);
    }

    details.think {
      margin-bottom: 8px;
      color: var(--muted);
      font-size: 0.86rem;
    }

    details.think summary { cursor: pointer; }

    .composer {
      margin-top: 12px;
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 8px;
      align-items: end;
    }

    textarea {
      min-height: 64px;
      max-height: 180px;
      resize: vertical;
    }

    .actions {
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    button {
      border: 0;
      border-radius: 10px;
      padding: 10px 14px;
      background: var(--accent);
      color: #0d1420;
      font-weight: 650;
      cursor: pointer;
    }

    button.ghost {
      background: transparent;
      color: var(--muted);
      border: 1px solid var(--line);
    }

    button:disabled { opacity: 0.55; cursor: default; }

    .status {
      min-height: 1.2em;
      margin: 8px 2px 0;
      font-size: 0.84rem;
      color: var(--muted);
    }

    .status.error { color: var(--danger); }
    .status.ok { color: var(--ok); }

    .stress {
      margin-bottom: 14px;
      display: grid;
      gap: 10px;
    }

    .stress[hidden] { display: none !important; }

    .stress-log {
      margin: 0;
      max-height: 160px;
      overflow: auto;
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: 14px;
      padding: 12px 14px;
      color: var(--ok);
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
      font-size: 0.8rem;
      line-height: 1.45;
      white-space: pre-wrap;
    }

    .stress-thread {
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: 14px;
      padding: 12px 14px;
      display: grid;
      gap: 8px;
    }

    .stress-thread h2 {
      margin: 0;
      font-size: 0.92rem;
      color: var(--accent);
    }

    .stress-body {
      max-height: 280px;
      overflow: auto;
      white-space: pre-wrap;
      word-break: break-word;
      line-height: 1.45;
      background: var(--bot);
      border: 1px solid var(--line);
      border-radius: 10px;
      padding: 10px 12px;
      min-height: 72px;
    }

    .stress-stats {
      color: var(--muted);
      font-size: 0.82rem;
      white-space: pre-wrap;
    }

    footer {
      margin-top: 16px;
      text-align: center;
      color: var(--muted);
      font-size: 0.78rem;
    }
