:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-2: #f0f0f3;
  --text: #16161a;
  --muted: #62626e;
  --line: #e2e2e8;
  --accent: #e11d48;
  --accent-text: #ffffff;
  --twitch: #9146ff;
  --live: #e5173f;
  --ok: #15803d;
  --warn-bg: #fff7e6;
  --warn-line: #f2d49b;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f13;
    --panel: #18181e;
    --panel-2: #212129;
    --text: #ececf1;
    --muted: #9b9baa;
    --line: #2b2b35;
    --warn-bg: #2a2212;
    --warn-line: #5c4a1f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

a { color: inherit; }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.small { padding: 5px 10px; font-size: 0.85rem; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.twitch { background: var(--twitch); border-color: var(--twitch); color: #fff; }
.btn.disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Header ---- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.boxart { border-radius: 6px; object-fit: cover; }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.top-actions form { margin: 0; }
.twitch-area { display: flex; align-items: center; gap: 8px; }
.twitch-on { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.twitch-on .dot { background: var(--twitch); }

main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 48px; }

/* ---- Status + notices ---- */

.status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 14px; }
.discord-area { display: inline-flex; align-items: center; gap: 8px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.pill.live { background: color-mix(in srgb, var(--live) 14%, transparent); color: var(--live); }
.pill.done { background: var(--panel-2); color: var(--muted); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.pill.live .dot { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .pill.live .dot { animation: none; } }

.notice {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
  padding: 10px 14px;
  border: 1px solid var(--warn-line);
  border-radius: var(--radius);
  background: var(--warn-bg);
}

/* ---- Controls ---- */

.controls { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.controls input, .controls select, .login-card input {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}
.controls input { flex: 1 1 240px; max-width: 360px; }
.sort { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.sort select { color: var(--text); font-weight: 500; }

/* ---- File list ---- */

.list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.files { width: 100%; border-collapse: collapse; }
.files th {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
}
.files td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.files tr:last-child td { border-bottom: 0; }
.files tr.is-live { background: color-mix(in srgb, var(--live) 4%, transparent); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }

.streamer { min-width: 220px; }
.streamer .cell { display: flex; align-items: center; gap: 12px; }
.avatar { border-radius: 50%; flex: none; background: var(--panel-2); object-fit: cover; }
.who { min-width: 0; }
.name { font-weight: 700; text-decoration: none; }
.name:hover { text-decoration: underline; }
.title { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions .cell { display: flex; justify-content: flex-end; gap: 4px; white-space: nowrap; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }

@media (max-width: 820px) {
  .topbar, main { padding-left: 16px; padding-right: 16px; }
  .files thead { display: none; }
  .files, .files tbody, .files tr, .files td { display: block; }
  .files tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .files tr:last-child { border-bottom: 0; }
  .files td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border: 0; }
  .files td[data-label]::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 0.82rem; }
  .files td .cell { min-width: 0; text-align: right; }
  .files td.streamer { display: block; min-width: 0; padding-bottom: 8px; }
  .files td.streamer .cell { text-align: left; }
  .title { max-width: 70vw; }
  .files td.actions { padding-top: 10px; }
  .files td.actions .cell { justify-content: flex-start; }
}

/* ---- Tabs + Users ---- */

.tabs { display: flex; gap: 4px; max-width: 1200px; margin: 0 auto; padding: 12px 24px 0; }
.tabs button {
  padding: 8px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tabs button[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.panel { margin-bottom: 16px; padding: 18px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.panel h2 { margin-bottom: 4px; }
.add-user { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(220px, 1.5fr) minmax(190px, 1.2fr) auto; gap: 12px; align-items: end; margin-top: 14px; }
.add-user label { display: grid; gap: 6px; font-weight: 600; font-size: 0.9rem; }
.add-user input, .add-user select, .users select {
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}
.add-user .btn { justify-content: center; padding: 9px 16px; }
.new-login {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--ok) 45%, transparent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--ok) 8%, transparent);
}
.credentials { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--panel-2); font-size: 0.95rem; white-space: pre-wrap; overflow-wrap: anywhere; user-select: all; }
.new-login .row { display: flex; gap: 8px; }
.btn.danger { color: var(--live); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

@media (max-width: 820px) {
  .tabs { padding: 10px 16px 0; }
  .add-user { grid-template-columns: 1fr; }
}

/* ---- Log viewer ---- */

.viewer {
  width: min(960px, calc(100vw - 32px));
  height: min(80vh, 900px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}
.viewer[open] { display: flex; flex-direction: column; }
.viewer::backdrop { background: rgb(0 0 0 / 0.55); }
.viewer-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.v-title { flex: 1; min-width: 160px; }
.v-actions { display: flex; gap: 6px; }
.v-note { padding: 8px 16px; border-bottom: 1px solid var(--line); font-size: 0.85rem; }

.lines {
  flex: 1;
  margin: 0;
  padding: 10px 16px;
  overflow-y: auto;
  list-style: none;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}
.lines li { padding: 2px 0; }
.lines time { margin-right: 8px; color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.lines .me span { font-style: italic; }
.lines .event { color: var(--twitch); font-weight: 600; }
.lines .system { color: var(--muted); font-style: italic; }

/* ---- Toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
}
.toast.error { background: var(--live); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* ---- Login ---- */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(380px, 100%);
  padding: 32px 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card img { border-radius: 12px; }
.login-card form { display: grid; gap: 14px; width: 100%; margin-top: 10px; text-align: left; }
.login-card label { display: grid; gap: 6px; font-weight: 600; font-size: 0.9rem; }
.login-card .btn { justify-content: center; padding: 10px; }
.form-error { width: 100%; padding: 8px 12px; border-radius: 8px; background: color-mix(in srgb, var(--live) 12%, transparent); color: var(--live); font-weight: 600; font-size: 0.9rem; }
