:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #7d8b99);
  --link: var(--tg-theme-link-color, #6ab7ff);
  --button: var(--tg-theme-button-color, #5288c1);
  --button-text: var(--tg-theme-button-text-color, #fff);
  --accent: var(--tg-theme-accent-text-color, #6ab7ff);
  --danger: #e0533d;
  --ok: #4caf50;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

header { padding: 14px 16px 6px; }
header h1 { margin: 0; font-size: 20px; }
#subtitle { color: var(--hint); font-size: 13px; }

#tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  position: sticky; top: 0;
  background: var(--bg);
  z-index: 10;
}
#tabs button {
  flex: 1;
  padding: 8px 4px;
  border: none;
  border-radius: 9px;
  background: var(--secondary-bg);
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
}
#tabs button.active { background: var(--button); color: var(--button-text); }

main { padding: 8px 12px 40px; }
.tab { display: none; }
.tab.active { display: block; }

#search {
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-radius: 10px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 10px;
}

.card {
  background: var(--secondary-bg);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.book-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.book-title { font-weight: 700; font-size: 16px; }
.book-sub { color: var(--hint); font-size: 12px; margin-top: 2px; }

.switch { position: relative; width: 46px; height: 27px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: #47525e; border-radius: 27px; transition: .2s;
}
.slider::before {
  content: ""; position: absolute;
  height: 21px; width: 21px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(19px); }

.sports { margin-top: 10px; display: none; }
.card.open .sports { display: block; }
.chevron { color: var(--hint); transition: transform .2s; }
.card.open .chevron { transform: rotate(90deg); }

.sport-group { margin-top: 8px; }
.sport-name {
  font-size: 13px; font-weight: 700; color: var(--accent);
  padding: 6px 2px; display: flex; justify-content: space-between;
}
.sport-name .count { color: var(--hint); font-weight: 400; }

.comp-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 6px; border-top: 1px solid rgba(255,255,255,.06);
}
.comp-row:active { background: rgba(255,255,255,.04); }
.comp-check {
  width: 22px; height: 22px; flex: none;
  border-radius: 6px; border: 2px solid var(--hint);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: #fff;
}
.comp-row.on .comp-check { background: var(--ok); border-color: var(--ok); }
.comp-label { flex: 1; }
.comp-label .name { font-size: 14px; }
.comp-label .cat { font-size: 11px; color: var(--hint); }
.book-tag {
  font-size: 10px; color: var(--hint);
  border: 1px solid var(--hint); border-radius: 5px; padding: 1px 5px;
}

.status-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.status-row .k { color: var(--hint); }
.dot { font-size: 11px; }
.err { color: var(--danger); font-size: 12px; margin-top: 4px; }

.feed-item { border-top: 1px solid rgba(255,255,255,.06); padding: 9px 2px; }
.feed-item:first-child { border-top: none; }
.feed-title { font-size: 14px; font-weight: 600; }
.feed-meta { font-size: 12px; color: var(--hint); }

label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--hint); }
label input { width: 100%; margin-top: 5px; padding: 10px; border-radius: 8px; border: none;
  background: var(--bg); color: var(--text); font-size: 15px; }
button#save-settings {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: var(--button); color: var(--button-text); font-size: 15px; font-weight: 600;
}
.hint { color: var(--hint); font-size: 12px; margin-top: 10px; }

.empty { text-align: center; color: var(--hint); padding: 40px 20px; }

#toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #000c; color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 13px; transition: transform .25s; z-index: 100; max-width: 90%;
}
#toast.show { transform: translateX(-50%) translateY(0); }
