:root {
  color-scheme: dark;
  --bg: #0a0c0f;
  --surface: #12151a;
  --surface-2: #191d23;
  --surface-3: #22272f;
  --border: #252b34;
  --text: #eef1f5;
  --dim: #8b93a2;
  --faint: #5f6775;
  --accent: #3cffa0;
  --accent-dim: rgba(60, 255, 160, 0.13);
  --accent-ink: #03150c;
  --danger: #ff6161;
  --danger-dim: rgba(255, 97, 97, 0.12);
  --radius: 14px;
  --topbar-h: 56px;
  --tabbar-h: 62px;
  --max-w: 560px;
  --gutter: max(16px, calc((100vw - var(--max-w)) / 2 + 16px));
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body.sheet-open { overflow: hidden; }

h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
.num, .row-subs, .stat-value, .tile-value, .row-rank { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }

/* ---------- inputs & buttons ---------- */

input, textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  font: inherit;
  font-size: 16px; /* anything smaller makes iOS zoom in on focus */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { resize: vertical; min-height: 92px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--dim);
}
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  font-weight: 650;
  font-size: 15px;
  line-height: 1;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: transform 0.1s, background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: var(--danger-dim); border-color: rgba(255, 97, 97, 0.3); }
.btn.danger-solid { color: #1c0505; background: var(--danger); border-color: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn.icon-btn { width: 46px; padding: 0; flex-shrink: 0; }
.btn svg, .tabbar svg, .search svg { width: 20px; height: 20px; flex-shrink: 0; }

.link-btn {
  background: none;
  border: 0;
  padding: 6px 0 6px 12px;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
}

.spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- sign in ---------- */

.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) 16px calc(env(safe-area-inset-bottom) + 24px);
}
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 22px; }
.link-btn.center { align-self: center; }
.install-text { display: flex; flex-direction: column; gap: 10px; }
.install-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.login-head { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.login-logo { width: 72px; height: 72px; border-radius: 18px; }
.login-head h1 { font-size: 24px; font-weight: 750; }
.login-head p { color: var(--dim); }
.login form { display: flex; flex-direction: column; gap: 16px; }
.form-error {
  padding: 10px 12px;
  font-size: 14px;
  color: var(--danger);
  background: var(--danger-dim);
  border-radius: 10px;
}

/* ---------- shell ---------- */

.app {
  min-height: 100dvh;
  padding: calc(var(--topbar-h) + env(safe-area-inset-top) + 16px) var(--gutter)
    calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--gutter) 0;
  background: rgba(10, 12, 15, 0.86);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 20px; font-weight: 750; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--dim);
  background: var(--surface-2);
  border-radius: 999px;
  white-space: nowrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
.status-pill[data-state="online"] .dot,
.live-row.active .dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.status-pill[data-state="offline"] { color: var(--danger); }
.status-pill[data-state="offline"] .dot { background: var(--danger); }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 0 calc(var(--gutter) - 16px) env(safe-area-inset-bottom);
  background: rgba(10, 12, 15, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.tabbar button {
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--faint);
  background: none;
  border: 0;
}
.tabbar button[aria-current="page"] { color: var(--accent); }

.view { display: flex; flex-direction: column; gap: 14px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}
.section-head h2 { font-size: 13px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--dim); }

.card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card h2 { font-size: 16px; font-weight: 700; }

.hint { font-size: 13px; color: var(--dim); }
.hint.center { text-align: center; }
.empty {
  padding: 22px 16px;
  text-align: center;
  font-size: 14px;
  color: var(--dim);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- home ---------- */

.ann-mini { text-align: left; width: 100%; font: inherit; color: inherit; gap: 6px; }
.ann-mini .ann-message { font-size: 15px; overflow-wrap: anywhere; }
.ann-mini .ann-next { font-size: 13px; color: var(--dim); }

.effects-lines { font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; }
.effects-lines.dim { color: var(--dim); font-size: 13px; }
.effects-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.live-row { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 600; color: var(--dim); }
.live-row.active { color: var(--text); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.tile.wide { grid-column: 1 / -1; }
.tile-label { font-size: 12px; font-weight: 600; color: var(--dim); }
.tile-value { font-size: 26px; font-weight: 750; line-height: 1.15; }
.tile-value.name { font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-sub { font-size: 13px; font-weight: 650; color: var(--accent); }

/* ---------- channel rows ---------- */

.list {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.list:empty { display: none; }

.row {
  display: grid;
  grid-template-columns: 26px 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 10px 14px 10px 12px;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--surface-2); }
.row-rank { font-size: 13px; font-weight: 700; color: var(--faint); text-align: center; }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-subs { font-size: 13.5px; color: var(--dim); }

.gain {
  padding: 4px 8px;
  font-size: 12.5px;
  font-weight: 650;
  border-radius: 999px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.gain.up { color: var(--accent); background: var(--accent-dim); }
.gain.down { color: var(--danger); background: var(--danger-dim); }
.gain.flat { color: var(--dim); background: var(--surface-3); }

.avatar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface-3);
  color: var(--dim);
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 64px; height: 64px; font-size: 24px; }

/* ---------- channels view ---------- */

.toolbar {
  position: sticky;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  z-index: 5;
  display: flex;
  gap: 8px;
  margin: -8px 0;
  padding: 8px 0;
  background: var(--bg);
}
.search { position: relative; flex: 1; display: block; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search input { padding-left: 42px; background: var(--surface); }

/* ---------- announce view ---------- */

.counter { align-self: flex-end; font-size: 12px; color: var(--faint); }
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.segmented button {
  min-height: 38px;
  font-weight: 600;
  font-size: 14px;
  color: var(--dim);
  background: none;
  border: 0;
  border-radius: 9px;
}
.segmented button[aria-checked="true"] { color: var(--text); background: var(--surface-3); }

.sched-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.sched-row:last-child { border-bottom: 0; }
.sched-info { flex: 1; min-width: 0; }
.sched-time { font-size: 13px; font-weight: 650; color: var(--accent); }
.sched-message { overflow-wrap: anywhere; }

/* ---------- settings ---------- */

.setting-row { display: flex; flex-direction: column; gap: 4px; }

/* ---------- sheets ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.2s;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  width: 100%;
  max-width: var(--max-w);
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  transform: translateY(100%);
  transition: transform 0.22s ease;
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet-grabber { width: 38px; height: 5px; margin: 0 auto 14px; border-radius: 3px; background: var(--surface-3); }
.sheet-body { display: flex; flex-direction: column; gap: 18px; }
.sheet-title { font-size: 20px; font-weight: 750; overflow-wrap: anywhere; }
.sheet-text { color: var(--dim); }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; }

.channel-head { display: flex; align-items: center; gap: 14px; }
.channel-head-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.channel-head .sheet-sub { font-size: 13px; color: var(--dim); overflow-wrap: anywhere; }
.cid-chip {
  align-self: flex-start;
  max-width: 100%;
  padding: 4px 8px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 12px;
}
.stat-label { font-size: 11.5px; font-weight: 600; color: var(--dim); }
.stat-value { font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.action { display: flex; flex-direction: column; gap: 8px; padding-top: 16px; border-top: 1px solid var(--border); }
.action .hint { margin-top: -2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.chip:active { background: var(--surface-3); }
.chip.selected { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  left: var(--gutter);
  right: var(--gutter);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 550;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--dim);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.2s ease;
  overflow-wrap: anywhere;
}
.toast.success { border-left-color: var(--accent); }
.toast.error { border-left-color: var(--danger); }
.toast.leaving { opacity: 0; transform: translateY(-6px); transition: opacity 0.2s, transform 0.2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
