:root {
  color-scheme: dark;
  --bg: #14161c;
  --panel: #1c1f28;
  --elev: #262a35;
  --line: #343846;
  --field: #101218;
  --top: #181b24;
  --text: #f3f4f8;
  --muted: #9aa0b0;
  --blue: #3b82f6;
  --blue-2: #2563eb;
  --danger: #f05252;
  --ok: #3dd68c;
  --warn: #f5b942;
  --gold: #f5c16c;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body.streamer #open-diagnostics,
body.moderator .toggles,
body.moderator #open-diagnostics,
body.moderator #open-settings { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
#app { display: flex; flex-direction: column; min-height: 100vh; }
#app:has(#settings:not([hidden])) { height: 100vh; overflow: hidden; }
#app:has(#settings:not([hidden])) .wrap {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 16px 28px 16px 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
* {
  scrollbar-width: thin;
  scrollbar-color: #4e5668 transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track, *::-webkit-scrollbar-corner { background: transparent; }
*::-webkit-scrollbar-thumb { background: #4e5668; border-radius: 99px; }
*::-webkit-scrollbar-button,
*::-webkit-scrollbar-button:single-button,
*::-webkit-scrollbar-button:vertical:start:decrement,
*::-webkit-scrollbar-button:vertical:end:increment,
*::-webkit-scrollbar-button:horizontal:start:decrement,
*::-webkit-scrollbar-button:horizontal:end:increment {
  display: none;
  width: 0;
  height: 0;
  background: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: #8cb4ff; }

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--top);
  position: sticky;
  top: 0;
  z-index: 4;
}
.toggles, .top-actions, .queue-actions, .transport, .who { display: flex; align-items: center; gap: 10px; }
.top-actions { margin-left: auto; }

.toggle, .text-btn, .icon-btn, .btn {
  border: 0;
  background: transparent;
  color: var(--text);
}
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}
.toggle i {
  width: 36px;
  height: 20px;
  border-radius: 99px;
  background: #3a4050;
  position: relative;
  display: inline-block;
}
.toggle i::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  transition: transform 0.15s ease;
}
.toggle.on { color: var(--text); }
.toggle.on i { background: var(--blue); }
.toggle.on i::after { transform: translateX(16px); }

.text-btn { color: var(--muted); padding: 8px 10px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; }
.text-btn svg, .settings-nav svg, .btn svg { width: 16px; height: 16px; flex: none; }
.text-btn:hover { background: var(--elev); color: var(--text); }
.text-btn.danger { color: var(--danger); }
.btn {
  border-radius: 10px;
  padding: 10px 16px;
  background: var(--elev);
  border: 1px solid transparent;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .12s ease, background .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.btn:hover { transform: translateY(-1px); background: #323846; }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--blue); color: white; box-shadow: 0 8px 22px rgba(59, 130, 246, .28); }
.btn.primary:hover { background: var(--blue-2); }
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--elev);
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: #323846; }
.icon-btn svg { width: 18px; height: 18px; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
.dot.connected { background: var(--ok); box-shadow: 0 0 0 4px rgba(61, 214, 140, .15); }
.dot.error, .dot.offline { background: var(--danger); }
.dot.connecting { background: var(--warn); }

.user { display: flex; align-items: center; gap: 8px; }
.user img, .avatar-fallback {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--elev);
  object-fit: cover;
}
.user a { color: var(--muted); text-decoration: none; font-size: 13px; }

.wrap { padding: 22px; max-width: 1180px; margin: 0 auto; }
.banner {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: #2a2418;
  border: 1px solid #5c4a22;
  color: #f6e7c1;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 18px;
}
.banner.error { background: #2a1717; border-color: #6e3030; color: #ffd4d4; }

.now {
  display: grid;
  grid-template-columns: 300px 1fr auto;
  gap: 22px;
  align-items: center;
  margin-bottom: 28px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(59, 130, 246, .08), transparent 55%);
  box-shadow: var(--shadow);
}
.thumb {
  position: relative;
  width: 300px;
  height: 168px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--elev) center/cover no-repeat;
  display: block;
}
.thumb.small { width: 72px; height: 40px; border-radius: 6px; }
.play-badge {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 48px;
  height: 34px;
  border-radius: 10px;
  background: #ff0033;
  color: white;
  display: grid;
  place-items: center;
}
.kicker { margin: 0 0 6px; color: var(--muted); letter-spacing: 0.08em; font-size: 12px; }
.now h2, .queue-head h2, .gate-card h1, .settings h2 { margin: 0; }
.meta { color: var(--muted); margin: 6px 0; }
.progress {
  height: 4px;
  background: #2a2f3c;
  border-radius: 99px;
  margin: 12px 0;
  overflow: hidden;
}
.progress span { display: block; height: 100%; background: var(--blue); width: 0; }
.volume { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.volume input { width: 140px; }
.side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; color: var(--muted); font-size: 13px; }

.queue-head, .public-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 8px 0 12px; }
#add-form, .links label, .settings label { display: flex; gap: 8px; }
#add-form { margin-bottom: 8px; }
#add-form input {
  flex: 1;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 12px 16px;
  outline: none;
}
#add-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59, 130, 246, .22); }
.settings input[type="text"],
.settings input[type="number"],
.settings select,
.links input,
.links select,
.command-form input[type="text"],
.command-form input[type="number"],
.command-form select,
.reply-list textarea,
.command-form textarea {
  width: 100%;
  color: var(--text);
  background-color: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.settings select,
.links select,
.command-form select,
.limit-box select {
  appearance: none;
  cursor: pointer;
  padding-right: 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='none' stroke='%23c2c6d4' stroke-width='1.6' stroke-linecap='round' d='M1 1.5 6 6.5 11 1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.settings input:focus,
.settings select:focus,
.links input:focus,
.links select:focus,
.command-form input:focus,
.command-form select:focus,
.command-form textarea:focus,
.reply-list textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .22);
}
.settings input[type="number"] { max-width: 220px; }
.links input { width: 100%; }

.command-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 14px; margin-top: 10px; min-height: 0; flex: 1; }
#command-list { min-height: 0; overflow: auto; padding-right: 4px; }
.command-item, .command-stage {
  background: #1a1e28;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.command-stage { min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.stage-tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.stage-tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 12px;
}
.stage-tabs button.active { background: #243044; color: var(--text); }
.command-empty { margin: 8px 16px 0; }
.command-stage .command-form, #shared-pane {
  background: transparent;
  border: 0;
  border-radius: 0;
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.commands {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--text);
}
.commands-head { flex: none; }
.commands-head .meta { margin-top: 4px; }
.command-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 8px;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease;
}
.command-item:hover { transform: translateX(2px); }
.command-item.active { border-color: var(--blue); box-shadow: 0 0 0 1px rgba(59, 130, 246, .35); }
.command-item small { display: block; color: var(--muted); margin-top: 3px; }
.command-form, #shared-pane { padding: 14px 16px 18px; }
.reply-list { padding-right: 4px; }
.reply-card {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}
.reply-card-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.reply-tools { display: flex; justify-content: space-between; gap: 12px; align-items: end; margin-top: 8px; }
.reply-tools h3 { margin: 0; }
.fold { border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; background: #1a1e28; }
.fold summary { cursor: pointer; font-weight: 650; }
.var-pop {
  position: fixed;
  z-index: 30;
  width: min(320px, calc(100vw - 24px));
  max-height: min(420px, calc(100vh - 24px));
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px;
}
.var-pop-head { display: flex; justify-content: space-between; align-items: center; }
.var-chip {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--field);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  margin-top: 6px;
}
.var-chip:hover { border-color: var(--blue); }
.var-chip code { color: #9ec1ff; }
.command-form label, .command-form .field { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.command-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.command-grid .span-2 { grid-column: 1 / -1; }
.command-toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.command-toolbar .meta { margin: 0; }
.segment {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.segment label {
  position: relative;
  flex: 1;
  flex-direction: row !important;
  justify-content: center;
  align-items: center;
  margin: 0;
  padding: 8px 6px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment label:has(input:checked) { background: var(--blue); color: white; }
.limit-box {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 320px;
  min-height: 44px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.limit-box:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59, 130, 246, .22); }
.limit-box select,
.limit-box input {
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background-color: transparent;
  width: auto;
  max-width: none !important;
}
select {
  color-scheme: dark;
}
select option {
  background-color: #16181f;
  color: #f3f4f8;
}
.limit-box select {
  flex: 0 0 auto;
  min-width: 118px;
  background-color: #16181f;
  color: var(--text);
  color-scheme: dark;
  border-right: 1px solid var(--line) !important;
}
.limit-box.is-unlimited select { flex: 1 1 auto; border-right: 0 !important; }
.settings .limit-box input,
.command-stage .limit-box input {
  flex: 1 1 4rem;
  min-width: 3rem;
  width: 4rem;
  padding-right: 8px;
}
.limit-box.is-unlimited input,
.limit-box.is-unlimited .limit-unit { display: none; }
.limit-unit { color: var(--muted); padding-right: 12px; font-size: 13px; }
.alias-list { display: flex; flex-wrap: wrap; gap: 6px; min-height: 8px; }
.alias-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #243044;
  border-radius: 999px;
  padding: 4px 8px;
}
.alias-chip button { border: 0; background: transparent; color: var(--muted); cursor: pointer; }
@media (max-width: 800px) {
  .command-layout, .command-grid, .settings-shell { grid-template-columns: 1fr; }
  .settings-nav { flex-direction: row; flex-wrap: wrap; }
  #command-list { max-height: 180px; }
}

.row {
  display: grid;
  grid-template-columns: 22px 28px 72px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 8px;
  border-radius: 10px;
  position: relative;
}
.row { transition: background .15s ease, transform .15s ease; }
.row:hover, .row.drag-over { background: #222632; transform: translateX(3px); }
.handle { color: #7d8496; cursor: grab; letter-spacing: -2px; }
.index, .duration, .who { color: var(--muted); }
.title { font-weight: 600; }
.sub {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  color: #1a1204;
  background: var(--gold);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
}
.row-actions, .pending-actions { display: flex; gap: 6px; }
.channel-actions { margin: 0 0 16px; align-items: center; }
.channel-badge { margin-left: 8px; padding: 2px 8px; border-radius: 999px; background: #173528; color: var(--ok); font-size: 12px; font-weight: 600; vertical-align: 1px; }
body.streamer .settings-nav { display: none; }
body.streamer .settings-shell { grid-template-columns: minmax(0, 1fr); }
body:not(.streamer) [data-settings-tab="channel"],
body:not(.streamer) [data-settings-panel="channel"] { display: none !important; }
.menu {
  position: absolute;
  right: 8px;
  top: 42px;
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 170px;
  padding: 4px;
  z-index: 6;
  box-shadow: var(--shadow);
}
.menu button, .menu a {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
}
.menu button:hover, .menu a:hover { background: #323846; }
.pending-label { color: var(--warn); font-size: 12px; margin: 14px 8px 4px; }
.backup-head { margin: 28px 8px 0; font-size: 18px; }
.backup-note { margin: 4px 8px 8px; }
.access-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.access-row .meta { margin: 2px 0 0; word-break: break-all; }

.empty { color: var(--muted); padding: 28px 8px 40px; text-align: center; }
#show-more {
  display: block;
  margin: 8px auto 20px;
  background: none;
  border: 0;
  color: var(--muted);
}

.settings {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  overflow: hidden;
}
#close-settings { justify-self: start; }
.settings-shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 28px; min-height: 0; align-items: stretch; width: 100%; }
.settings-nav { display: flex; flex-direction: column; gap: 4px; width: 220px; min-height: 0; overflow: auto; justify-self: start; }
.settings-nav button {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 10px;
  transition: background .15s ease, color .15s ease;
}
.settings-nav button:hover { background: #222632; color: var(--text); }
.settings-nav button.active { background: #243044; color: var(--text); box-shadow: inset 3px 0 0 var(--blue); }
.settings-main { display: grid; gap: 14px; min-width: 0; min-height: 0; overflow: auto; align-content: start; }
.settings-main > form,
.settings-main > .links { max-width: 760px; width: 100%; }
.settings-main:has(.commands:not([hidden])) { overflow: hidden; display: flex; flex-direction: column; }
.settings-main:has(.commands:not([hidden])) .commands { flex: 1; }
.settings-main h2 { margin: 0 0 4px; }
.reply-list { display: grid; gap: 12px; }
.reply-list label { flex-direction: column; align-items: stretch; }
.reply-list textarea, .command-form textarea {
  width: 100%;
  min-height: 64px;
  line-height: 1.45;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  resize: vertical;
}
.settings label, .links label { flex-direction: column; align-items: stretch; gap: 6px; color: var(--muted); font-size: 14px; }
.settings input[type="number"]:not(.limit-value), .settings input[type="range"] { max-width: 280px; }
.limit-box input:focus, .limit-box select:focus { box-shadow: none; border-color: transparent; }
.check { flex-direction: row !important; align-items: center !important; }
.commands { color: var(--muted); }
.commands code { color: var(--text); }
.error { color: #ff8d8d; min-height: 1.2em; }
.ok { color: var(--ok); }
.bad { color: #ff8d8d; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
  position: relative;
}
.modal-card h3 { margin-top: 0; }
.modal-card ol { color: var(--muted); padding-left: 18px; }
.modal-card li { margin: 8px 0; }
#modal-close { position: absolute; top: 10px; right: 10px; }
.diag-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; }

#toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid rgba(61, 214, 140, .55);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  border-radius: 10px;
  z-index: 30;
}

.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.eyebrow { color: var(--muted); letter-spacing: 0.08em; font-size: 12px; margin: 0 0 8px; }
.gate-card p { line-height: 1.5; }
.gate-card .btn { margin-top: 8px; background: #9146ff; }
.gate-card .btn:hover { background: #772ce8; }

.public { padding: 28px; max-width: 860px; margin: 0 auto; }
.public-row {
  display: grid;
  grid-template-columns: 36px 72px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 860px) {
  .now { grid-template-columns: 1fr; }
  .thumb { width: 100%; height: 190px; }
  .side { align-items: flex-start; }
  .row { grid-template-columns: 22px 72px 1fr auto; }
  .row .index { display: none; }
  .top { flex-wrap: wrap; }
}
