:root {
  --bg: #f6f5f8;
  --surface: #ffffff;
  --surface-2: #efedf3;
  --text: #1d1b22;
  --muted: #6b6676;
  --border: #dcd8e3;
  --accent: #7c3aed;
  --accent-text: #ffffff;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --live: #dc2626;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131217;
    --surface: #1c1a22;
    --surface-2: #26232e;
    --text: #ece9f1;
    --muted: #a19bab;
    --border: #35313f;
    --accent: #9b6bff;
    --accent-text: #ffffff;
    --ok: #4ade80;
    --warn: #fbbf24;
    --danger: #f87171;
    --live: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }

h1, h2 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; }
p { margin: 0 0 12px; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.logo { color: var(--accent); font-size: 1.2rem; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 6px 12px; border-radius: 6px; color: var(--muted); }
.tabs button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.me { color: var(--muted); font-size: 0.9rem; }
.lang { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.lang button { border: 0; border-radius: 0; padding: 3px 8px; background: none; color: var(--muted); font-size: 0.8rem; }
.lang button.active { background: var(--accent); color: var(--accent-text); }

main { max-width: 980px; margin: 0 auto; padding: 20px 16px 60px; }
.view { display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.card.narrow { max-width: 420px; margin: 40px auto; text-align: center; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }

button, .button {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 7px 14px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:hover, .button:hover { filter: brightness(1.05); }
button:disabled { opacity: 0.55; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.ghost { background: transparent; }
.danger { color: var(--danger); }
.small { padding: 3px 9px; font-size: 0.85rem; }

input[type=text], input[type=number], input[type=search], input:not([type]), input[readonly] {
  font: inherit; width: 100%; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
input[type=color] { width: 56px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.92rem; }
label > span { color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check > span { color: var(--text); }
fieldset { margin: 0; display: flex; flex-direction: column; gap: 12px; }
legend { font-weight: 700; padding: 0 4px; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0; }
.muted { color: var(--muted); }
.notice { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; font-size: 0.9rem; }
.notice.warn { border-left: 3px solid var(--warn); }
.form-error { color: var(--danger); margin: 0; }

.status-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-size: 0.85rem;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--ok); }
.pill.bad .dot { background: var(--danger); }
.pill.live .dot { background: var(--live); box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 30%, transparent); }
.pill b { font-weight: 600; }

.slots { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.slot {
  border: 1px solid var(--border); border-left: 4px solid var(--slot-color, var(--border));
  border-radius: 8px; padding: 10px 12px; background: var(--bg); min-width: 0;
}
.slot .num { color: var(--muted); font-size: 0.75rem; }
.slot .title { font-weight: 600; overflow-wrap: anywhere; }
.slot.empty .title { color: var(--muted); font-weight: 400; font-style: italic; }
.slot .err { color: var(--danger); font-size: 0.8rem; overflow-wrap: anywhere; }

.log { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.log li { padding: 6px 0; border-bottom: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; }
.log li:last-child { border-bottom: 0; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; }
.log .bad { color: var(--danger); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1 1 200px; width: auto; }
.sound-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sound {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--slot-color, var(--border));
  border-radius: var(--radius); padding: 10px 12px;
}
.sound.disabled { opacity: 0.6; }
.sound .info { flex: 1 1 220px; min-width: 0; }
.sound .title { font-weight: 600; overflow-wrap: anywhere; }
.sound .meta { color: var(--muted); font-size: 0.85rem; display: flex; gap: 10px; flex-wrap: wrap; }
.badge { font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; background: var(--accent); color: var(--accent-text); }
.badge.off { background: var(--surface-2); color: var(--muted); }
.sound .btns { display: flex; gap: 6px; flex-wrap: wrap; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 0; }

.copy-row { display: flex; gap: 8px; margin-bottom: 14px; }
.copy-row input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
  background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 20; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 0.9rem; box-shadow: 0 4px 16px rgba(0,0,0,0.2); }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 600px) {
  .top-actions { margin-left: 0; width: 100%; justify-content: space-between; }
  .card-head { flex-wrap: wrap; }
}

/* ---- multi-channel additions ---- */
#channel-select {
  font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); max-width: 220px;
}
.quota { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 0.85rem; }
.meter { flex: 1 1 160px; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; align-self: center; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.meter.full > span { background: var(--danger); }
.channel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.channel-list li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.role { font-size: 0.75rem; color: var(--muted); }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; }
.status-badge { font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); }
.status-badge.suspended { background: var(--danger); color: #fff; }

/* ---- rewards tab ---- */
.reward-link { flex: 0 1 260px; min-width: 200px; }
.reward-link select {
  font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); width: 100%;
}
