/* Design system: CSS custom properties are set at runtime from Telegram.WebApp.themeParams
   (see js/app.js) — these are just sane fallbacks so the app looks right even outside Telegram
   (plain browser preview during development). */
:root {
  /* Flat style: neutral gray-black + white + one saturated lime accent — deliberately no green
     shades anywhere else (success/progress-over states reuse the same --accent, not a tint). */
  --bg: #0a0a0a;
  --secondary-bg: #141414;
  --section-bg: #1a1a1a;
  --text: #ffffff;
  --hint: #9a9a9a;
  --link: #d4ff00;
  --button: #d4ff00;
  --button-text: #0a0a0a;
  --accent: #d4ff00;
  --destructive: #ff4d4d;
  --success: #d4ff00;
  --border: #2a2a2a;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- Header ---------- */
.topbar {
  flex: none;
  padding: var(--space-4) var(--space-4) var(--space-3);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.topbar h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
}
.topbar .subtitle {
  font-size: 13px;
  color: var(--hint);
}

/* ---------- Screen content ---------- */
.screen {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--space-4) calc(var(--space-6) + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

/* ---------- Bottom tab bar ---------- */
.tabbar {
  flex: none;
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--secondary-bg);
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  flex: 1;
  background: none;
  border: none;
  color: var(--hint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-2) 0 var(--space-2);
  font-size: 11px;
  font-family: inherit;
}
.tabbar button .icon { font-size: 20px; line-height: 1; }
.tabbar button.active { color: var(--accent); }

/* ---------- Cards ---------- */
.card {
  background: var(--section-bg);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.card h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 var(--space-3);
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.card + .card { margin-top: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--button); color: var(--button-text); }
.btn-secondary { background: rgba(255,255,255,0.08); color: var(--text); }
.btn-outline { background: transparent; color: var(--accent); border: 1.5px solid var(--accent); }
.btn-destructive { background: transparent; color: var(--destructive); }
.btn-block { display: flex; width: 100%; }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: var(--radius-sm); }

.btn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-2);
}

/* ---------- Chips (exercise picker, quick tags) ---------- */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.chip {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.chip.active { background: var(--accent); color: var(--button-text); }

/* ---------- Stepper (weight/reps input) ---------- */
.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-4) 0;
}
.stepper button {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 24px;
  font-family: inherit;
  cursor: pointer;
}
.stepper button:active { background: var(--accent); color: var(--button-text); }
.stepper .value {
  min-width: 84px;
  text-align: center;
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stepper .unit { font-size: 14px; color: var(--hint); margin-left: 4px; }

/* ---------- Progress bars ---------- */
.progress {
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.progress > div {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(.22,1,.36,1);
}
.progress.over > div { background: var(--success); }

.macro-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--hint);
  margin-bottom: var(--space-1);
}
.macro-row b { color: var(--text); font-weight: 600; }

/* ---------- Table (workout log) ---------- */
table.log {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.log th, table.log td {
  text-align: left;
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--border);
}
table.log th { color: var(--hint); font-weight: 500; font-size: 12px; }
table.log tr:last-child td { border-bottom: none; }

/* ---------- Checklist ---------- */
.checklist-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.checklist-item:last-child { border-bottom: none; }
.checklist-item .box {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--hint);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.checklist-item.done .box { background: var(--success); border-color: var(--success); }
.checklist-item .box::after {
  content: "";
  width: 12px;
  height: 7px;
  border-left: 2.5px solid var(--button-text);
  border-bottom: 2.5px solid var(--button-text);
  transform: rotate(-45deg) translate(1px, -1px);
  display: none;
}
.checklist-item.done .box::after { display: block; }
.checklist-item .label { flex: 1; font-size: 15px; }
.checklist-item .dose { font-size: 12px; color: var(--hint); }

/* ---------- Toggle switch ---------- */
.toggle {
  width: 46px;
  height: 28px;
  border-radius: 999px;
  background: rgba(255,255,255,0.15);
  border: none;
  position: relative;
  flex: none;
  cursor: pointer;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s ease;
}
.toggle.on { background: var(--success); }
.toggle.on::after { transform: translateX(18px); }

/* ---------- Form rows (settings) ---------- */
.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
  gap: var(--space-3);
}
.form-row:last-child { border-bottom: none; }
.form-row label { font-size: 15px; }
.form-row input[type="time"],
.form-row input[type="number"] {
  background: rgba(255,255,255,0.08);
  border: none;
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 15px;
  font-family: inherit;
  width: 100px;
  text-align: right;
}

textarea, input[type="text"] {
  width: 100%;
  background: rgba(255,255,255,0.08);
  border: none;
  color: var(--text);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
}
textarea:focus, input:focus { outline: 2px solid var(--accent); }

/* ---------- Misc ---------- */
.hint { color: var(--hint); font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: var(--space-2); align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.big-number { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; }
.badge {
  display: inline-block;
  background: rgba(212,255,0,0.18);
  color: var(--accent);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
}
.badge.warn { background: rgba(255,159,10,0.18); color: #ff9f0a; }
.empty-state { text-align: center; padding: var(--space-6) var(--space-3); color: var(--hint); }
.empty-state .emoji { font-size: 40px; display: block; margin-bottom: var(--space-2); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--section-bg);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  max-width: 85%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.06) 25%, rgba(255,255,255,0.12) 37%, rgba(255,255,255,0.06) 63%);
  background-size: 400% 100%;
  animation: skeleton 1.4s ease infinite;
  border-radius: var(--radius-sm);
  height: 16px;
}
@keyframes skeleton {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

.fade-in { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* chat bubbles (digest) */
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}
.chat-msg.user { align-self: flex-end; background: var(--button); color: var(--button-text); }
.chat-msg.ai { align-self: flex-start; background: var(--section-bg); }
.chat-log { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-3); }

/* ---------- Dashboard "Сегодня" widget (top of Профиль) ---------- */
.dashboard-card {
  background: var(--section-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.dashboard-rating-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.dashboard-rating-row .rating-value { font-size: 34px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.dashboard-rating-row .rating-delta { font-size: 14px; font-weight: 600; }
.dashboard-rating-row .rating-delta.positive { color: var(--success); }
.dashboard-rating-row .rating-delta.negative { color: var(--destructive); }
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: var(--space-3);
}
.dashboard-tile { text-align: center; }
.dashboard-tile .icon { font-size: 20px; display: block; margin-bottom: 2px; }
.dashboard-tile .label { font-size: 11px; color: var(--hint); text-transform: uppercase; letter-spacing: 0.02em; }
.dashboard-tile .value { font-size: 13px; font-weight: 600; }
.dashboard-tile.done .icon { filter: none; }
.dashboard-tile.pending { opacity: 0.45; }

.streak-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.streak-chip {
  background: rgba(212,255,0,0.14);
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
}

/* ---------- First-visit onboarding tour ---------- */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: var(--space-4);
}
.onboarding-card {
  background: var(--section-bg);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-5);
  max-width: 340px;
  width: 100%;
  text-align: center;
}
.onboarding-icon { font-size: 48px; margin-bottom: var(--space-3); line-height: 1; }
.onboarding-card h2 { font-size: 19px; margin: 0 0 var(--space-2); }
.onboarding-card p { font-size: 14px; color: var(--hint); line-height: 1.5; margin: 0; }
.onboarding-dots { display: flex; justify-content: center; gap: 6px; margin-top: var(--space-4); }
.onboarding-dots .dot { width: 6px; height: 6px; border-radius: 999px; background: rgba(255,255,255,0.2); transition: all 0.2s ease; }
.onboarding-dots .dot.active { background: var(--accent); width: 18px; }

/* ---------- Chess board ("Партия" tab) ---------- */
.chess-hero {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.chess-hero .rating-value { font-size: 22px; font-weight: 700; }
.chess-hero .result-tag { font-size: 14px; font-weight: 600; color: var(--accent); }

.chess-board-outer {
  display: flex;
  gap: var(--space-2);
  align-items: stretch;
  margin-bottom: var(--space-3);
}
.chess-eval-bar {
  width: 12px;
  border-radius: 999px;
  background: #1a1a1a;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column-reverse;
  flex: none;
}
.chess-eval-bar > div { background: #eeeeee; width: 100%; transition: height 0.4s ease; }

.chess-board-wrap { position: relative; flex: 1; aspect-ratio: 1 / 1; }
.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}
.chess-square { position: relative; }
.chess-square.light { background: #262626; }
.chess-square.dark { background: #151515; }
.chess-square img { width: 100%; height: 100%; display: block; padding: 8%; }
.chess-arrow-layer { position: absolute; inset: 0; pointer-events: none; }

.chess-banner {
  background: rgba(212,255,0,0.14);
  color: var(--accent);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  margin-bottom: var(--space-3);
}

.chess-move-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.chess-move-row:last-child { border-bottom: none; }
.chess-move-row .side-tag { font-size: 11px; color: var(--hint); width: 52px; flex: none; }
.chess-move-row .san { font-weight: 600; flex: none; }
.chess-move-row .category-label { flex: 1; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chess-quality { border-radius: 999px; padding: 3px 10px; font-size: 11px; font-weight: 600; flex: none; }
.chess-quality.brilliant { background: rgba(212,255,0,0.22); color: var(--accent); }
.chess-quality.excellent { background: rgba(212,255,0,0.14); color: var(--accent); }
.chess-quality.good { background: rgba(255,255,255,0.08); color: var(--text); }
.chess-quality.inaccuracy { background: rgba(255,159,10,0.14); color: #ff9f0a; }
.chess-quality.mistake { background: rgba(255,159,10,0.22); color: #ff9f0a; }
.chess-quality.blunder { background: rgba(255,77,77,0.18); color: var(--destructive); }

.chess-game-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.chess-game-row:last-child { border-bottom: none; }

/* ---------- Rating breakdown list ---------- */
.rating-breakdown-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.rating-breakdown-row:last-child { border-bottom: none; }
.rating-breakdown-row .cat-name { color: var(--text); }
.rating-breakdown-row .cat-score { color: var(--hint); font-variant-numeric: tabular-nums; }
.rating-breakdown-row.full .cat-score { color: var(--success); }
