/* ── reset & variables ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f10;
  --panel: #1a1a1c;
  --panel-hover: #232326;
  --border: #2a2a2e;
  --text: #e8e8e8;
  --text-dim: #888;
  --text-dimmer: #5f5f63;
  --accent: #fe4e60;       /* y = warm red */
  --accent-hover: #ff6b7c;
  --danger: #e66;
  --success: #6ee2a0;
  --warning: #f0c040;
  --live: #ff3366;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  padding-top: max(0.5rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* `hidden` attribute must always win over any class-level `display:` rule. */
[hidden] { display: none !important; }

/* ── header ──────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
}
.header-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.header-sub {
  font-size: 0.8rem;
  color: var(--text-dim);
}
.icon-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
}
.icon-btn:hover { color: var(--text); background: var(--panel); }
.icon-btn + .icon-btn { margin-left: 0; }

/* ── tabs ────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0.6rem;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.55rem 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-count {
  display: inline-block;
  min-width: 1.4rem;
  padding: 0 0.4rem;
  margin-left: 0.25rem;
  background: var(--panel-hover);
  color: var(--text);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.3rem;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── toolbar ─────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}
.toolbar-spacer { flex: 1; }
.toolbar-hint { color: var(--text-dim); font-size: 0.8rem; }

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.check-pill input { accent-color: var(--accent); }
.check-pill:has(input:checked) { color: var(--text); border-color: var(--accent); }
.check-pill.as-button { cursor: pointer; }
.check-pill.as-button:hover { color: var(--text); border-color: var(--accent); }

/* disclosure dropdown (details/summary) */
.dropdown { position: relative; }
.dropdown > summary {
  list-style: none;
}
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown > summary::after {
  content: " ▾";
  color: var(--text-dimmer);
}
.dropdown[open] > summary { color: var(--text); border-color: var(--accent); }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 12rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem;
  display: flex;
  flex-direction: column;
  z-index: 10;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
.dropdown-menu button {
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.85rem;
}
.dropdown-menu button:hover { background: var(--panel-hover); color: var(--accent); }

/* ── grid / cards ────────────────────────────────────────────────── */
.grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.1s;
}
.card:hover { border-color: var(--panel-hover); }
.card.watched { opacity: 0.45; }

.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  display: block;
  overflow: hidden;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.thumb .duration {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0,0,0,0.8);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
}
.thumb .kind-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0,0,0,0.8);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
}
.thumb .kind-badge.live { background: var(--live); }
.thumb .kind-badge.upcoming { background: #4a6cff; }
.thumb .kind-badge.past-live { background: #555; }
.thumb .kind-badge.short { background: #6a4; }

.card-body {
  padding: 0.5rem 0.6rem 0.55rem;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0.2rem;
}
.card-title {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: auto;
}
.card-channel {
  color: var(--text-dim);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.card-channel:hover { color: var(--text); }
.card-time {
  flex-shrink: 0;
}

.card-actions {
  display: flex;
  border-top: 1px solid var(--border);
}
.card-actions button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 0.45rem 0.4rem;
  font-weight: 600;
}
.card-actions button:hover { background: var(--panel-hover); color: var(--text); }
.card-actions button.watched-btn.is-watched { color: var(--success); }
.card-actions button + button { border-left: 1px solid var(--border); }

/* ── channel list ────────────────────────────────────────────────── */
.add-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.add-bar input {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  outline: none;
}
.add-bar input:focus { border-color: var(--accent); }
.add-bar button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
}
.add-bar button:hover { background: var(--accent-hover); }
.add-bar button:disabled { opacity: 0.6; cursor: default; }

.add-status {
  margin-bottom: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}
.add-status.error { border-color: var(--danger); color: var(--danger); }
.add-status.success { border-color: var(--success); color: var(--success); }

.channel-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}
.channel-toolbar input[type="search"] {
  flex: 1;
  min-width: 8rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.45rem 0.7rem;
  font-size: 0.9rem;
  outline: none;
}
.channel-toolbar input[type="search"]:focus { border-color: var(--accent); }
.filter-count {
  color: var(--text-dim);
  font-size: 0.8rem;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.channel-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.channel-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--panel-hover);
  object-fit: cover;
  flex-shrink: 0;
}
.channel-info {
  flex: 1;
  min-width: 0;
}
.channel-title {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
a.channel-title:hover { color: var(--accent); }
.channel-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channel-actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}
.channel-actions button {
  background: var(--panel-hover);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 600;
}
.channel-actions button:hover { color: var(--text); border-color: var(--accent); }
.channel-actions button.danger:hover { color: var(--danger); border-color: var(--danger); }
.channel-actions button[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }

.channel-filters {
  grid-column: 1 / -1;
  display: none;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.5rem 0.25rem 0.1rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.channel-filters.open { display: flex; }
.channel-filters label { display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer; }
.channel-filters input[type="checkbox"] { accent-color: var(--accent); }
.channel-filters input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.2rem 0.4rem;
  font-size: 0.8rem;
  width: 5rem;
  outline: none;
}
.channel-filters input[type="number"]:focus { border-color: var(--accent); }

.channel-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.6rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── misc ────────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-dim);
}
.empty p { margin: 0.3rem 0; }
.empty-sub { font-size: 0.85rem; color: var(--text-dimmer); }
.empty code { background: var(--panel); padding: 0.1rem 0.3rem; border-radius: 3px; }

.btn-ghost {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
}
.btn-ghost:hover { background: var(--panel-hover); border-color: var(--accent); }
.btn-danger {
  background: var(--danger);
  border: none;
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}

/* ── modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}
.modal-overlay.active { display: flex; }
.modal {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  padding: 1.25rem;
  margin: auto;
}
.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  padding: 0.25rem 0.5rem;
}
.modal-close:hover { color: var(--text); }
.modal-title {
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
}
.modal-confirm { max-width: 360px; text-align: center; }
.confirm-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
}

.form-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem 0.65rem;
  margin-bottom: 0.75rem;
}
.form-fieldset legend {
  padding: 0 0.35rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}
.form-check input { accent-color: var(--accent); }
.form-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}
.form-label input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  outline: none;
}
.form-label input[type="text"]:focus { border-color: var(--accent); }
.form-label.inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0 0;
  color: var(--text);
  font-size: 0.9rem;
}
.form-label.inline input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.35rem 0.5rem;
  font-size: 0.9rem;
  width: 5.5rem;
  outline: none;
}
.form-label.inline input[type="number"]:focus { border-color: var(--accent); }

.field-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 0.1rem 0 0.5rem;
  line-height: 1.35;
}

.sep { border: 0; border-top: 1px solid var(--border); margin: 0.75rem 0; }

.settings-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.settings-label { flex: 1; font-size: 0.9rem; }
.settings-desc { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.1rem; }

.import-status {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: pre-wrap;
}

/* ── toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  z-index: 200;
  max-width: 90%;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); }

/* ── responsive tweaks ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.6rem; }
  .card-title { font-size: 0.82rem; }
  .card-meta { font-size: 0.7rem; }
  .channel-title { font-size: 0.88rem; }
}

/* --------------------------------------------------------------- auth ui */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.auth-overlay[hidden] { display: none; }
body.unauth .container { visibility: hidden; }

.auth-panel {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}
.auth-panel h2 {
  margin: 0 0 1rem 0;
  font-size: 1.25rem;
  text-align: center;
  letter-spacing: 0.02em;
}
.auth-panel p {
  margin: 0 0 1rem;
  color: var(--muted);
  text-align: center;
}
.auth-cta {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  width: 100%;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.auth-form[hidden] { display: none; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.auth-form input {
  background: var(--panel-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
  padding: 0.6rem 0.75rem;
}
.auth-form input:focus { border-color: var(--accent); outline: none; }
.auth-form .btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
}
.auth-switch {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 0.25rem;
}
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  cursor: pointer;
  font-size: inherit;
}
.btn-link:hover { text-decoration: underline; }
.auth-error {
  background: rgba(230, 102, 102, 0.12);
  color: var(--danger);
  border: 1px solid rgba(230, 102, 102, 0.35);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

/* -------------------------------------------------------- admin invites */
.admin-invites {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}
.admin-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}
.invite-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.invite-list .empty { color: var(--text-dim); font-size: 0.85rem; }
.invite-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  background: var(--panel-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}
.invite-code {
  font-family: ui-monospace, monospace;
  color: var(--text);
  flex: 1;
  overflow-wrap: anywhere;
}
.invite-status { color: var(--text-dim); font-size: 0.8rem; }

/* ── mobile touch handling ───────────────────────────────────────── */
/* On touch devices, treat drags as scrolls — kill long-press text
   selection on UI chrome and the 300ms double-tap-to-zoom delay. Keep
   form inputs selectable so copy-to-clipboard still works there. */
@media (pointer: coarse) {
  body {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
  }
  * { touch-action: manipulation; }
  input, textarea, [contenteditable] {
    user-select: text;
    -webkit-user-select: text;
  }
}
