:root {
  /* Значения по умолчанию (перекрываются темой Telegram) */
  --bg: #0f1420;
  --bg-secondary: #171e2e;
  --card: #1c2436;
  --card-hover: #232d43;
  --text: #f2f5fb;
  --text-secondary: #a7b1c6;
  --hint: #7c879e;
  --accent: #4f8cff;
  --accent-2: #7c5cff;
  --accent-soft: rgba(79, 140, 255, 0.16);
  --danger: #ff5f6d;
  --win: #35d07f;
  --lose: #ff5f6d;
  --gold: #ffc93c;
  --silver: #c8d0e0;
  --bronze: #e09a5f;
  --border: rgba(255, 255, 255, 0.07);
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(124, 92, 255, 0.14), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}

/* ==== Шапка ==== */
.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(16px + env(safe-area-inset-top)) 16px 0;
  background: linear-gradient(var(--bg) 65%, transparent);
}

.appbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.appbar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.appbar__logo {
  font-size: 30px;
  filter: drop-shadow(0 4px 12px rgba(255, 201, 60, 0.35));
}

.appbar__title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.appbar__subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 14px;
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.1s ease, background 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.94);
  background: var(--card-hover);
}

/* ==== Вкладки режимов ==== */
.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 0 8px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.search-wrap {
  padding: 4px 0 2px;
}

.search {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
}

.search::placeholder {
  color: var(--hint);
}

.tab {
  flex: 0 0 auto;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(79, 140, 255, 0.35);
}

/* ==== Контент ==== */
.content {
  padding: 4px 16px 20px;
  max-width: 640px;
  margin: 0 auto;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--text-secondary);
  padding: 60px 0;
}

.loading[hidden] {
  display: none;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==== Таблица ==== */
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--hint);
  margin: 18px 4px 10px;
}

.standings {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
  animation: rise 0.3s ease both;
}

.row:active {
  transform: scale(0.985);
  background: var(--card-hover);
}

.row.top {
  border: none;
  background: linear-gradient(135deg, rgba(255, 201, 60, 0.12), rgba(255, 201, 60, 0.03)),
    var(--card);
}

.rank {
  flex: 0 0 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  font-weight: 800;
  font-size: 14px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

.rank.gold {
  background: linear-gradient(135deg, #ffd76a, #f5a623);
  color: #3a2800;
}
.rank.silver {
  background: linear-gradient(135deg, #e8edf7, #aeb9cf);
  color: #2a3040;
}
.rank.bronze {
  background: linear-gradient(135deg, #f0b483, #c87a3a);
  color: #3a1f08;
}

.who {
  flex: 1 1 auto;
  min-width: 0;
}

.who__name {
  font-weight: 700;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.who__sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.score-chip {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 16px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--bg-secondary);
  text-align: center;
}

.score-chip .wl {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--hint);
  letter-spacing: 0.4px;
}

.points {
  flex: 0 0 auto;
  text-align: right;
}

.points__num {
  font-weight: 800;
  font-size: 17px;
  color: var(--accent);
}

.points__label {
  font-size: 10px;
  color: var(--hint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.badge-you {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: 1px;
}

/* ==== Плавающая кнопка ==== */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  z-index: 30;
  box-shadow: 0 12px 28px rgba(79, 140, 255, 0.45);
  transition: transform 0.15s ease;
}

.fab:active {
  transform: scale(0.9);
}

/* ==== Sheet (нижний экран) ==== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 40;
}

.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88vh;
  background: var(--bg-secondary);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
  z-index: 50;
  transform: translateY(105%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
}

.sheet.open {
  transform: translateY(0);
}

.sheet__handle {
  width: 42px;
  height: 5px;
  border-radius: 999px;
  background: var(--border);
  margin: 10px auto 2px;
  flex: 0 0 auto;
}

.sheet__body {
  overflow-y: auto;
  padding: 6px 20px calc(28px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

/* ==== Профиль игрока ==== */
.profile-head {
  text-align: center;
  padding: 8px 0 4px;
}

.avatar {
  width: 72px;
  height: 72px;
  margin: 0 auto 10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 34px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(79, 140, 255, 0.4);
}

.profile-head h2 {
  margin: 0;
  font-size: 22px;
}

.profile-head .rank-line {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 18px 0;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
}

.stat-card .v {
  font-size: 20px;
  font-weight: 800;
}

.stat-card .l {
  font-size: 11px;
  color: var(--hint);
  margin-top: 3px;
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mode-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.mode-item .icon {
  font-size: 18px;
}

.mode-item .name {
  flex: 1 1 auto;
  font-size: 13px;
  color: var(--text-secondary);
}

.mode-item .rec {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.chip {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  margin: 3px 4px 0 0;
}

.chip .win {
  color: var(--win);
  font-weight: 700;
}

.match-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 13px;
}

.match-line .result {
  font-weight: 800;
}

.match-line.win .result {
  color: var(--win);
}
.match-line.lose .result {
  color: var(--lose);
}

.match-line .opp {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.match-line .meta {
  color: var(--hint);
  font-size: 11px;
  text-align: right;
  flex: 0 0 auto;
}

/* ==== Форма ==== */
.form-title {
  font-size: 18px;
  font-weight: 800;
  margin: 8px 0 14px;
}

.step-hint {
  color: var(--hint);
  font-size: 12px;
  margin: 0 0 10px;
}

.opt-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  transition: background 0.15s ease;
}

.opt:active {
  background: var(--card-hover);
}

.opt .emoji {
  font-size: 18px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.score-btn {
  padding: 14px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-weight: 800;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.score-btn:active {
  background: var(--card-hover);
}

.score-btn.custom {
  grid-column: span 3;
  background: var(--bg);
  color: var(--text-secondary);
}

.field {
  width: 100%;
  padding: 13px 14px;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
}

.field::placeholder {
  color: var(--hint);
}

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

.back-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 8px 0;
  cursor: pointer;
}

/* ==== Toast ==== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 60;
  max-width: 80vw;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
