:root {
  --bg: #0e0f14;
  --panel: #171922;
  --panel-2: #1f2230;
  --line: #2b2f40;
  --text: #e8e9f0;
  --muted: #9498ad;
  --accent: #8b6cff;
  --accent-2: #5ad1c4;
  --accent-text: #ffffff;
  --danger: #ff6b7a;
  --warn: #f3b755;
  --ok: #4fd08a;
  --radius: 12px;
  color-scheme: dark;
}
/* Light: chosen with the switch in the top bar (data-theme, kept in localStorage and shared with
   the rooms), or by the system when nothing was chosen. */
:root[data-theme='light'] {
  --bg: #f4f4f8;
  --panel: #ffffff;
  --panel-2: #f0f0f6;
  --line: #dcdde8;
  --text: #1a1b25;
  --muted: #666a80;
  --accent: #6a48f2;
  --accent-2: #128f83;
  --danger: #d43a4c;
  --warn: #a86a00;
  --ok: #17874d;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    --bg: #f4f4f8;
    --panel: #ffffff;
    --panel-2: #f0f0f6;
    --line: #dcdde8;
    --text: #1a1b25;
    --muted: #666a80;
    --accent: #6a48f2;
    --accent-2: #128f83;
    --danger: #d43a4c;
    --warn: #a86a00;
    --ok: #17874d;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
p { margin: 0 0 12px; }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }

/* shell */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 56px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; color: var(--text); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 20px; border-radius: 5px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; left: 10px; top: 5px;
  border-left: 8px solid #fff; border-top: 5px solid transparent; border-bottom: 5px solid transparent;
}
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--text); text-decoration: none; background: var(--panel-2); }
.nav a.active { color: var(--text); background: var(--panel-2); }
.page { max-width: 1180px; margin: 0 auto; padding: 28px 20px 60px; }
/* the bar is one line at every width: nothing in it wraps, and what does not fit goes */
.topbar .nav { overflow-x: auto; scrollbar-width: none; }
.topbar .nav::-webkit-scrollbar { display: none; }
.topbar .nav a, .topbar button { white-space: nowrap; flex: none; }
.topbar .account { display: flex; align-items: center; gap: 10px; flex: none; }
.topbar .account .name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label-short { display: none; }
@media (max-width: 640px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar .account { gap: 6px; }
  .topbar .account .name, .topbar .brand-name { display: none; }
  .topbar .nav a { padding: 6px 9px; }
  .label-long { display: none; }
  .label-short { display: inline; }
  .page { padding: 20px 14px 48px; }
}
.page-head { margin-bottom: 22px; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 12px; font-weight: 700; color: var(--muted); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* controls */
button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--muted); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover, .btn.primary:hover { filter: brightness(1.1); }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--panel-2); }
button.sm, .btn.sm { padding: 4px 10px; font-size: 13px; border-radius: 7px; }
button.big, .btn.big { padding: 12px 22px; font-size: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=number], input[type=search], select, textarea {
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 11px; width: 100%;
}
textarea { resize: vertical; min-height: 70px; }
input:disabled, select:disabled { opacity: 0.6; }
label.field { display: block; }
label.field > span { display: block; font-weight: 600; margin-bottom: 5px; }
label.field > small, .hint { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }
label.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
label.check input { margin-top: 4px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
label.check small { display: block; color: var(--muted); font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0; min-width: 0; }
legend { padding: 0 8px; font-weight: 600; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; }

/* surfaces */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.banner { padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); }
.banner.error { border-color: var(--danger); color: var(--danger); }
.banner.warn { border-color: var(--warn); color: var(--warn); }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty h2 { color: var(--text); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.plain::before { display: none; }
.pill.running { color: var(--ok); }
.pill.starting, .pill.stopping, .pill.deleting { color: var(--warn); }
.pill.starting::before, .pill.stopping::before, .pill.deleting::before { animation: pulse 1.1s infinite; }
.pill.error { color: var(--danger); }
@keyframes pulse { 50% { opacity: 0.25; } }

/* lobby */
.rooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.room-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; color: var(--text);
  transition: border-color 0.15s, transform 0.15s;
}
.room-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.thumb {
  aspect-ratio: 16 / 9; background: #06070a; position: relative;
  display: flex; align-items: center; justify-content: center; color: #5b5f73; font-size: 13px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .pill { position: absolute; left: 10px; top: 10px; background: rgba(10, 11, 16, 0.82); border-color: transparent; }
.thumb .viewers { position: absolute; right: 10px; top: 10px; background: rgba(10, 11, 16, 0.82); border-color: transparent; color: #e8e9f0; }
.room-card .body { padding: 13px 15px 15px; }
.room-card .title { font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-card .meta { color: var(--muted); font-size: 13px; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }

/* tabs */
/* The row scrolls sideways when it does not fit, and only sideways: setting one overflow axis makes
   the other scroll too, so the vertical one is switched off and the active tab's underline is drawn
   inside the row instead of hanging a pixel below it. */
.tabs {
  display: flex; gap: 2px; margin-bottom: 20px;
  box-shadow: inset 0 -1px 0 var(--line);
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: none; border-radius: 0; padding: 10px 14px; color: var(--muted);
  border-bottom: 2px solid transparent; flex: none; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button + button { margin-left: 6px; }
td.wrap { word-break: break-word; }

/* room page */
.hero { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(260px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 800px) { .hero { grid-template-columns: 1fr; } }
.hero .thumb { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
pre.log {
  background: #06070a; color: #c9ccd9; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; max-height: 420px; overflow: auto; margin: 0; white-space: pre-wrap; word-break: break-all;
}
.copy { display: flex; gap: 8px; }
.copy input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat .n { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.stat .l { color: var(--muted); font-size: 13px; }

/* watch */
.watch { position: fixed; inset: 0; display: flex; flex-direction: column; background: #000; }
.watch-bar {
  display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 12px; flex: none;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.watch-bar .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch iframe { flex: 1; border: 0; width: 100%; background: #000; }

/* dialogs and toasts */
.backdrop {
  position: fixed; inset: 0; background: rgba(5, 6, 10, 0.66); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto;
}
.dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: min(720px, 100%); padding: 22px; }
.dialog.narrow { width: min(460px, 100%); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
/* a dialog is drawn where its component sits, which can be a table cell: none of the cell's text
   rules (no wrapping, right-aligned, spacing between buttons) are meant for it */
.dialog { white-space: normal; text-align: left; }
.dialog h2, .dialog p { overflow-wrap: anywhere; }
td.actions .dialog-foot button + button { margin-left: 0; }
@media (max-width: 520px) {
  .backdrop { padding: 16px 12px; align-items: flex-end; }
  .dialog, .dialog.narrow { width: 100%; padding: 18px 16px; }
  .dialog-foot { flex-wrap: wrap; }
  .dialog-foot button { flex: 1 1 120px; text-align: center; justify-content: center; padding-top: 11px; padding-bottom: 11px; }
}
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 36px)); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent-2); border-radius: 10px; padding: 10px 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35); }
.toast.error { border-left-color: var(--danger); }

/* sign-in */
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login { width: min(400px, 100%); text-align: center; }
.login .brand { justify-content: center; font-size: 26px; margin-bottom: 6px; }
.login .brand-mark { width: 40px; height: 30px; border-radius: 8px; }
.login .brand-mark::after { left: 15px; top: 8px; border-left-width: 12px; border-top-width: 7px; border-bottom-width: 7px; }
.login .card { margin-top: 22px; text-align: left; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; justify-content: center; padding: 60px; }
button.icon { padding: 6px; }
@media (max-width: 360px) {
  .topbar { gap: 6px; padding: 0 8px; }
  .topbar .nav a { padding: 6px; }
  .topbar button.sm { padding: 4px 6px; }
}
