:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f2f2f2);
  --card-bg: var(--tg-theme-section-bg-color, #f7f7f8);
  --danger: #e0483f;
  --success: #34a86a;
  --video-accent: #ff5e7a;
  --audio-accent: #8b5cf6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 32px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 16px 16px 0;
  border-bottom: 1px solid var(--secondary-bg);
}

.topbar h1 {
  margin: 0 0 12px;
  font-size: 19px;
}

.tabs {
  display: flex;
  gap: 6px;
}

.tab-btn {
  flex: 1;
  padding: 10px 8px;
  border: none;
  background: none;
  color: var(--hint);
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--link);
  border-bottom-color: var(--link);
}

.tab-panel {
  display: none;
}

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

.status {
  text-align: center;
  color: var(--hint);
  padding: 24px 16px;
  font-size: 14px;
}

/* ---- Videos ---- */

.video-list {
  list-style: none;
  margin: 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.video-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: opacity 0.2s ease;
}

.video-card.removing {
  opacity: 0;
}

.video-icon {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
}

.video-icon.video {
  background: linear-gradient(135deg, var(--video-accent), #ff8a65);
}

.video-icon.audio {
  background: linear-gradient(135deg, var(--audio-accent), #6366f1);
}

.video-info {
  flex: 1;
  min-width: 0;
}

.video-title {
  font-weight: 600;
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-meta {
  color: var(--hint);
  font-size: 12.5px;
  margin-top: 3px;
}

.video-actions {
  display: flex;
  gap: 4px;
  flex: none;
}

.icon-btn {
  border: none;
  background: var(--secondary-bg);
  font-size: 17px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.danger {
  color: var(--danger);
}

.empty {
  text-align: center;
  color: var(--hint);
  padding: 48px 20px;
  font-size: 14px;
  line-height: 1.6;
}

/* ---- Channels tab ---- */

.add-channel-card {
  margin: 14px;
  padding: 14px;
  background: var(--card-bg);
  border-radius: 16px;
}

.add-channel-label {
  font-weight: 600;
  font-size: 14.5px;
  margin-bottom: 4px;
}

.add-channel-hint {
  color: var(--hint);
  font-size: 12.5px;
  line-height: 1.5;
  margin-bottom: 10px;
}

.add-channel-row {
  display: flex;
  gap: 8px;
}

.add-channel-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--secondary-bg);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.channel-add-status {
  font-size: 12.5px;
  margin: 8px 0 0;
  min-height: 16px;
}

.channel-add-status.error {
  color: var(--danger);
}

.channel-add-status.success {
  color: var(--success);
}

.channel-manage-list {
  list-style: none;
  margin: 0;
  padding: 0 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.channel-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 12px 14px;
}

.channel-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.channel-avatar {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--link), #6dd5fa);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
}

.channel-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-toggles {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.toggle-pill {
  flex: 1;
  padding: 8px;
  border-radius: 10px;
  border: none;
  background: var(--secondary-bg);
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.toggle-pill.on {
  background: var(--link);
  color: #fff;
}

/* ---- Channel picker sheet ---- */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 10;
}

.sheet.hidden {
  display: none;
}

.sheet-inner {
  background: var(--bg);
  width: 100%;
  border-radius: 16px 16px 0 0;
  padding: 20px 16px 28px;
  max-height: 70vh;
  overflow-y: auto;
}

.sheet-inner h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.sheet-subtitle {
  color: var(--hint);
  font-size: 13px;
  margin: 0 0 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.channel-item {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  border: none;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

.btn {
  display: block;
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  cursor: pointer;
}

.btn-secondary {
  background: var(--secondary-bg);
  color: var(--text);
}

.btn-primary {
  background: var(--button);
  color: var(--button-text);
  width: auto;
  padding: 10px 16px;
  font-weight: 600;
  white-space: nowrap;
}
