:root {
  --bg: var(--tg-theme-bg-color, #0e1519);
  --surface: var(--tg-theme-secondary-bg-color, #172129);
  --surface-soft: rgba(255, 255, 255, 0.055);
  --surface-strong: #202b34;
  --text: var(--tg-theme-text-color, #f5f7fb);
  --muted: var(--tg-theme-hint-color, #8c9aa7);
  --accent: var(--tg-theme-button-color, #32b7e8);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(255, 255, 255, 0.09);
  --green: #4fd99a;
  --yellow: #ffd166;
  --red: #ff6b6b;
  --blue: #62c7ff;
  --radius: 8px;
  --shadow: 0 14px 38px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 8% 0%, rgba(79, 217, 154, 0.14), transparent 22rem),
    radial-gradient(circle at 100% 4%, rgba(98, 199, 255, 0.15), transparent 23rem),
    linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 22rem),
    var(--bg);
}

button {
  font: inherit;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-shell {
  width: min(100%, 680px);
  margin: 0 auto;
}

.app-layout {
  min-height: 100vh;
  padding: calc(16px + env(safe-area-inset-top)) 10px calc(92px + env(safe-area-inset-bottom));
}

.loading-screen,
.state-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 14px;
  text-align: center;
}

.state-card {
  width: min(100%, 360px);
  display: grid;
  gap: 12px;
  justify-items: center;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(23, 33, 41, 0.88);
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(50, 183, 232, 0.24), rgba(79, 217, 154, 0.18));
  font-size: 30px;
}

.top-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  margin-bottom: 10px;
  padding: 2px 2px 0;
}

.top-bar h1 {
  margin-top: 2px;
  font-size: 23px;
  line-height: 1.1;
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
}

.user-chip {
  grid-column: 1 / -1;
  width: max-content;
  max-width: 100%;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 13px;
}

.status-pill,
.tag,
.risk-pill {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.premium {
  color: var(--yellow);
  background: rgba(255, 209, 102, 0.12);
}

.status-pill.free {
  color: var(--blue);
}

.hero,
.section,
.coach-card {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(23, 33, 41, 0.88);
  box-shadow: var(--shadow);
}

.hero {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.coach-hero {
  background:
    linear-gradient(145deg, rgba(50, 183, 232, 0.12), rgba(79, 217, 154, 0.07)),
    rgba(23, 33, 41, 0.9);
}

.premium-hero {
  background:
    linear-gradient(145deg, rgba(255, 209, 102, 0.13), rgba(50, 183, 232, 0.08)),
    rgba(23, 33, 41, 0.9);
}

.profile-hero {
  justify-items: center;
  text-align: center;
}

.hero-top,
.coach-head,
.section-head,
.row-title,
.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hero h2 {
  margin-top: 3px;
  font-size: 26px;
  line-height: 1.06;
}

.mini-score {
  min-width: 56px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
  color: var(--green);
  text-align: center;
  font-size: 18px;
  font-weight: 900;
}

.section {
  padding: 12px;
}

.section-head {
  margin-bottom: 10px;
}

.section-title,
.coach-head {
  font-size: 16px;
  font-weight: 900;
}

.section-note,
.row-description,
.empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.36;
}

.coach-card {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.stats-grid,
.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stats-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat {
  min-width: 0;
  min-height: 62px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.stat-value {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-label {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-actions {
  display: grid;
  gap: 8px;
}

.action-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
}

.action-button.secondary {
  background: rgba(255, 255, 255, 0.075);
  color: var(--text);
}

.action-button.primary {
  background: linear-gradient(135deg, var(--accent), #36d69d);
  color: #061015;
}

.task-list,
.topic-list,
.inventory-list,
.shop-list {
  display: grid;
  gap: 8px;
}

.row-card,
.topic-card,
.shop-card {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.row-title {
  align-items: flex-start;
  font-weight: 850;
  line-height: 1.25;
}

.tag.easy {
  color: var(--green);
  background: rgba(79, 217, 154, 0.11);
}

.tag.medium {
  color: var(--yellow);
  background: rgba(255, 209, 102, 0.11);
}

.tag.hard,
.risk-pill.highRisk {
  color: var(--red);
  background: rgba(255, 107, 107, 0.12);
}

.risk-pill.mediumRisk {
  color: var(--yellow);
  background: rgba(255, 209, 102, 0.11);
}

.risk-pill.lowRisk {
  color: var(--green);
  background: rgba(79, 217, 154, 0.11);
}

.progress-line {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
}

.progress-fill {
  width: var(--value);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.progress-line.highRisk .progress-fill {
  background: linear-gradient(90deg, var(--red), var(--yellow));
}

.progress-line.mediumRisk .progress-fill {
  background: linear-gradient(90deg, var(--yellow), var(--blue));
}

.metric-row {
  min-height: 34px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

.metric-row:last-child {
  border-bottom: 0;
}

.metric-row strong {
  color: var(--text);
  text-align: right;
}

.lock-card {
  background:
    linear-gradient(145deg, rgba(255, 209, 102, 0.11), rgba(98, 199, 255, 0.06)),
    rgba(23, 33, 41, 0.88);
}

.avatar {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: linear-gradient(145deg, var(--accent), #36d69d);
  color: #061015;
  font-size: 30px;
  font-weight: 1000;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: min(100%, 680px);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(14, 21, 25, 0.94);
  backdrop-filter: blur(16px);
  transform: translateX(-50%);
}

.tab-button {
  min-width: 0;
  min-height: 50px;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 6px 4px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab-button.active {
  background: rgba(50, 183, 232, 0.15);
  color: var(--text);
}

.tab-icon {
  font-size: 18px;
  line-height: 1;
}

.tab-label {
  max-width: 100%;
  overflow: hidden;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 520px) {
  .app-layout {
    padding-left: 8px;
    padding-right: 8px;
  }

  .top-bar h1 {
    font-size: 21px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quick-grid {
    grid-template-columns: 1fr;
  }

  .section,
  .hero,
  .coach-card {
    padding: 12px;
  }
}

@media (max-width: 350px) {
  .tab-label {
    display: none;
  }

  .tab-button {
    min-height: 44px;
  }

  .stats-grid,
  .stats-grid.compact {
    grid-template-columns: 1fr;
  }
}
