:root {
  --bg: #131111; --panel: #1d1b1b; --panel2: #272424; --fg: #edebeb;
  --sub: #aaa2a2; --line: #343030; --accent: #b40101;
  /* Same hue lifted for legibility, used where the accent is text on the dark panel. */
  --accent-bright: #f04a4a;
  --twitch: #9146ff; --kick: #53fc18; --donation: #f0b429;
  --ok: #2ecc71; --bad: #e57373;
  /* One height for every form control, and for any button sitting beside one. */
  --control-h: 38px;
  /* A single subtle corner radius for panels, controls and buttons. */
  --radius: 4px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 14px; }
a { color: var(--accent-bright); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 15px; letter-spacing: 0.02em; }
.muted { color: var(--sub); }
.small { font-size: 12px; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 360px; }
.login-logo { display: block; height: auto; width: 100%; margin: 0 0 16px; }
.login-card h1 { margin-bottom: 4px; }
.login-card p { margin: 0 0 20px; color: var(--sub); }
.login-card input { width: 100%; margin-bottom: 12px; }
.login-card button { width: 100%; }
.err { color: var(--bad); margin: 0 0 10px; min-height: 0; font-size: 13px; }
.err:empty { display: none; }
.login-lead { margin: 0 0 12px !important; font-weight: 600; color: var(--fg) !important; font-size: 14px; }
/* ---- Dashboard shell ---- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar { flex: 0 0 250px; width: 250px; height: 100vh; background: #100f0f; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; padding: 10px 5px 10px; justify-content: space-evenly; }
.brand__logo { height: 75px; width: auto; display: block; }
/* `stretch` keeps the buttons exactly as tall as the select whatever the font
   metrics work out to, rather than relying on matched padding. */
.overlay-switch { display: flex; align-items: stretch; gap: 8px; padding: 4px 16px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.overlay-switch select { flex: 1; min-width: 0; }
.overlay-switch button { flex: 0 0 auto; line-height: 1; }
/* Needs the extra class to outrank `button.small`, which matches with the same
   specificity further down the file. */
.overlay-switch button.small { font-size: 16px; padding: 8px 11px; }
.nav { flex: 1; overflow-y: auto; padding: 8px 14px; display: flex; flex-direction: column; gap: 3px; }
.nav__label { padding: 14px 12px 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--sub); }
.nav__item { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border-radius: var(--radius);
  color: var(--sub); text-decoration: none; font-weight: 600; font-size: 14px;
  border: none; background: none; cursor: pointer; width: 100%; text-align: left; font-family: inherit; }
.nav__item svg { width: 18px; height: 18px; flex: 0 0 18px; }
.nav__item:hover { background: var(--panel); color: var(--fg); }
.nav__item.active { background: var(--accent); color: #fff; }
.sidebar__foot { padding: 12px 14px 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; }
.sidebar__user { display: flex; align-items: center; gap: 9px; padding: 8px 13px 10px; color: var(--fg); font-size: 13px; font-weight: 600; }

.main { flex: 1; min-width: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: 18px 36px; background: rgba(19,17,17,0.85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar__title { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; }
.topbar__title svg { width: 21px; height: 21px; flex: 0 0 21px; color: var(--accent-bright); }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--sub); font-size: 13px; }
.topbar__nav { display: flex; gap: 4px; }
.topbar__link { display: flex; align-items: center; gap: 7px; padding: 7px 12px; color: var(--sub);
  text-decoration: none; font-size: 13px; font-weight: 500; border: 1px solid transparent; border-radius: var(--radius); }
.topbar__link svg { width: 16px; height: 16px; }
.topbar__link:hover { color: var(--fg); background: var(--panel); }
.topbar__link.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.content { padding: 30px 36px 64px; max-width: 1180px; width: 100%; }
.page { display: none; }
.page.active { display: block; animation: pageIn 0.18s ease; }
@keyframes pageIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px 28px; }
.panel + .panel { margin-top: 22px; }

.backup-box { margin-top: 12px; padding: 14px; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); }
.backup-grid { display: grid; grid-template-columns: repeat(2, max-content); gap: 6px 28px;
  font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace; font-size: 14px; margin-top: 8px; }
.backup-grid code { letter-spacing: 0.06em; color: var(--fg); }

@media (max-width: 860px) {
  .app { flex-direction: column; height: auto; overflow: visible; }
  .sidebar { width: 100%; flex: none; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
    border-right: none; border-bottom: 1px solid var(--line); }
  .brand { padding: 14px 18px; }
  .nav { flex-direction: row; flex-wrap: wrap; overflow: visible; padding: 8px 12px; gap: 4px; }
  .nav__label { display: none; }
  .nav__item { width: auto; padding: 9px 12px; }
  .sidebar__foot { flex-direction: row; align-items: center; margin-left: auto; border-top: none; padding: 8px 14px; }
  .main { height: auto; overflow: visible; }
  .topbar { padding: 16px 20px; }
  .content { padding: 22px 20px 56px; max-width: none; }
}

/* ---- Forms ---- */
label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 6px; }
input, select { background: var(--panel2); color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 9px 11px; font: inherit; font-size: 13px; width: 100%; }
/* Text-like controls all settle on the same height; range/checkbox/radio are
   sized by the browser and must be left alone. */
input:not([type="range"]):not([type="checkbox"]):not([type="radio"]), select { min-height: var(--control-h); }
input:focus, select:focus { outline: none; border-color: var(--accent); }
/* Native checkboxes, radios and range sliders paint themselves with the
   browser's default blue unless told otherwise. The lifted accent is used so
   the control stays visible against the dark panel. */
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--accent-bright); }
textarea { background: var(--panel2); color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 9px 11px; font: inherit; font-size: 13px; width: 100%; resize: vertical; }
textarea:focus { outline: none; border-color: var(--accent); }
.color-input { height: 38px; padding: 3px; cursor: pointer; }
/* Font-face combobox: filterable list, each row previewed in its own typeface. */
.fontpick { position: relative; }
.fontpick__menu { position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 2px);
  max-height: 260px; overflow-y: auto; background: var(--panel2); border: 1px solid var(--accent);
  border-radius: var(--radius); box-shadow: 0 12px 28px rgba(0,0,0,0.5); }
.fontpick__opt { padding: 8px 11px; font-size: 16px; line-height: 1.1; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid var(--line); }
.fontpick__opt:last-child { border-bottom: none; }
.fontpick__opt[hidden] { display: none; }
.fontpick__opt:hover, .fontpick__opt.active { background: var(--accent); color: #fff; }
/* Twitch channel points rewards */
.rw-list { display: flex; flex-direction: column; gap: 8px; }
.rw-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); }
.rw-swatch { flex: none; width: 30px; height: 30px; border: 1px solid rgba(255,255,255,0.15); border-radius: var(--radius); }
.rw-info { flex: 1; min-width: 0; }
.rw-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rw-cost { font-weight: 500; font-size: 12px; color: var(--accent-bright); border: 1px solid var(--accent); padding: 1px 7px; border-radius: 3px; }
.rw-sub { margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rw-actions { flex: none; display: flex; gap: 6px; }
.rw-badge { display: inline-block; font-size: 11px; padding: 1px 7px; margin-left: 4px; background: var(--panel); border: 1px solid var(--line); color: var(--sub); border-radius: 3px; }
.rw-badge.off { color: #ffb454; border-color: #7a5a2a; }
.rw-alert { margin-top: 4px; display: flex; align-items: center; }
.rw-alert__dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; background: var(--sub); }
.rw-alert__dot.on { background: #38d39f; }
.rw-alert__dot.off { background: #ff6b6b; }
.rw-editor { margin-top: 14px; padding: 16px; background: var(--panel2); border: 1px solid var(--accent); border-radius: var(--radius); }
.rw-editor h4 { margin: 20px 0 10px; font-size: 14px; }
/* End credits roster + sections */
.credit-roster { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 10px; }
.credit-stat { background: var(--panel2); border: 1px solid var(--line); padding: 12px 8px; text-align: center; border-radius: var(--radius); }
.credit-stat--total { border-color: var(--accent); }
.credit-stat__n { display: block; font-size: 22px; font-weight: 700; line-height: 1; }
.credit-stat__l { display: block; font-size: 12px; color: var(--sub); margin-top: 5px; }
.credit-section-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.credit-section-row:last-child { border-bottom: none; }
.credit-section-row .check { min-width: 150px; }
.credit-section-row .cr-sec-label { flex: 1; max-width: 260px; }
.credit-section-row .cr-sec-count { margin-left: auto; white-space: nowrap; }
/* Canvas background preview */
.canvas-bg-preview:not(:empty) { margin-top: 12px; }
.canvas-bg-preview img, .canvas-bg-preview video { display: block; max-width: 360px; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border: 1px solid var(--line); background: #000; border-radius: var(--radius); }
.rw-editor textarea { background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 11px; font: inherit; font-size: 13px; width: 100%; resize: vertical; }
.rw-editor textarea:focus { outline: none; border-color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
/* Capped variant: at most three roomy columns, for pages with many fields. */
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 760px) { .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .grid--3 { grid-template-columns: 1fr; } }
.field { min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; color: var(--fg); font-size: 13px; cursor: pointer; }
.check input { width: auto; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type=range] { width: 100%; }
.range-row output { color: var(--sub); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Buttons ---- */
/* Transparent border rather than none, so `.ghost`/`.danger` adding a 1px
   border doesn't make them 2px taller than a solid button beside them. */
button { background: var(--accent); color: #fff; border: 1px solid transparent; border-radius: var(--radius); padding: 9px 16px;
  font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; transition: filter .12s ease, transform .06s ease; }
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button.ghost { background: var(--panel2); border: 1px solid var(--line); color: var(--fg); }
button.danger { background: #3a2329; border: 1px solid #5a2b32; color: #f3b5b5; }
button.small { padding: 6px 10px; font-size: 12px; }
/* A button sharing a row with an input or select matches that control's height.
   `.small` stays compact everywhere else (reward lists, toolbars).
   The sibling selectors catch a button placed straight after a control; the
   class list covers the rows where a label-bearing `.field` sits between them. */
input + button, select + button,
.secret-row button, .tier__main button, .t-media-row button, .log-filters button,
/* Full-size buttons (save bars, modal actions) share the control height too;
   `.small` stays compact in dense lists and toolbars. */
button:not(.small) { min-height: var(--control-h); }
/* These fields carry a label, so the row is taller than the control itself —
   drop the button to the bottom so it lines up with the selects, not the field. */
.log-filters button { align-self: end; }
.save-bar { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.save-bar .status { font-size: 13px; color: var(--sub); }

/* ---- Event toggles ---- */
.toggles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.toggle { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel2);
  border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; text-transform: capitalize; }
.toggle input { width: auto; }

/* ---- Donation tiers ---- */
.tier { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.tier__main { display: grid; grid-template-columns: 1fr 0.8fr 1fr 1.1fr auto; gap: 10px; align-items: end; }
.tier__media { margin-top: 12px; }
.t-media-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.t-media-file { width: auto; flex: 0 1 auto; padding: 7px 9px; }
/* The picker button inside a file input is drawn by the browser and only
   reachable through this pseudo-element. The two selectors can't be grouped —
   a browser that doesn't know one would discard the whole rule. */
input[type="file"]::file-selector-button {
  margin-right: 10px; padding: 4px 10px;
  background: var(--accent); color: #fff;
  border: 1px solid transparent; border-radius: var(--radius);
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: filter .12s ease;
}
input[type="file"]::file-selector-button:hover { filter: brightness(1.15); }
input[type="file"]::-webkit-file-upload-button {
  margin-right: 10px; padding: 4px 10px;
  background: var(--accent); color: #fff;
  border: 1px solid transparent; border-radius: var(--radius);
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: filter .12s ease;
}
.tier .field label { margin-bottom: 4px; }
@media (max-width: 640px) { .tier__main { grid-template-columns: 1fr 1fr; } }

/* ---- Connections ---- */
.conn { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.conn header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.conn header .name { font-weight: 700; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 3px; color: #fff; }
.badge.tw { background: var(--twitch); } .badge.kk { background: var(--kick); color: #06210a; }
.badge.se { background: var(--donation); color: #2a1d00; }
.secret-row { display: flex; gap: 8px; align-items: end; }
.secret-row .field { flex: 1; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 3px; border: 1px solid var(--line); color: var(--sub); }
.pill.set { color: var(--ok); border-color: #245c3a; }

/* ---- Event log ---- */
.log-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.log-table th { text-align: left; padding: 8px 10px; color: var(--sub); font-weight: 600; border-bottom: 1px solid var(--line); white-space: nowrap; }
.log-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.log-table .log-time { white-space: nowrap; color: var(--sub); }
.log-table .log-detail { max-width: 420px; overflow-wrap: anywhere; }
.log-table .log-replays { text-align: center; }

/* ---- Test grid + status ---- */
.test-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.test-grid button { text-transform: capitalize; }
.statusline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--sub); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); display: inline-block; }
.dot.ok { background: var(--ok); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2);
  border: 1px solid var(--line); color: var(--fg); padding: 10px 18px; border-radius: var(--radius); font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .25s ease; z-index: 20; }
.toast.show { opacity: 1; }
.toast.bad { border-color: #5a2b32; color: #f3b5b5; }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(9,9,9, 0.62); backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.modal__card { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px 28px; box-shadow: 0 24px 70px -12px rgba(0, 0, 0, 0.7); animation: modalIn 0.16s ease; }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.modal__title { font-size: 17px; margin: 0 0 10px; }
.modal__msg { color: var(--sub); margin: 0 0 6px; line-height: 1.55; }
#modalLabel, #modalSelectWrap label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--sub); }
#modalSelectWrap { margin-top: 14px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
