/* =========================================================================
   MAJOR — Valorant Tracker
   Premium minimalism. Ruby. No shadows, no glows, no decorative animations.
   ========================================================================= */

:root {
  /* Surfaces */
  --bg:            #0A0A0B;
  --surface:       #111114;
  --surface-2:     #16161B;
  --surface-3:     #1B1B22;
  --border:        #1F1F25;
  --border-strong: #2A2A33;
  --hairline:      #15151A;

  /* Foreground */
  --fg:            #F4F4F5;
  --fg-2:          #C7C7CC;
  --muted:         #71717A;
  --muted-2:       #52525B;

  /* Ruby — единственный акцент */
  --ruby:          #E11D48;
  --ruby-2:        #BE123C;
  --ruby-3:        #881337;
  --ruby-tint:     rgba(225, 29, 72, 0.10);
  --ruby-tint-2:   rgba(225, 29, 72, 0.18);

  /* Семантика */
  --win:           #16A34A;
  --win-tint:      rgba(22, 163, 74, 0.10);
  --loss:          #DC2626;
  --loss-tint:     rgba(220, 38, 38, 0.10);

  /* Метрика */
  --radius:        10px;
  --radius-sm:     6px;
  --radius-lg:     14px;
  --nav-h:         62px;
  --top-h:         54px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
          "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", "Roboto Mono",
          Menlo, Consolas, monospace;

  /* Telegram safe-area */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Telegram передаёт свою тёмную тему — игнорируем, у нас единая. */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: contain;
}

button { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* =========================================================================
   Layout
   ========================================================================= */

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: calc(var(--top-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.brand-mark {
  width: 28px; height: 28px;
  border: 1px solid var(--ruby);
  color: var(--ruby);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}
.brand-name {
  font-size: 14px;
  letter-spacing: 0.16em;
}
.brand-dot {
  width: 4px; height: 4px;
  background: var(--muted-2);
  border-radius: 50%;
}
.brand-sub {
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--muted);
  font-weight: 500;
}

.top-actions { display: flex; gap: 2px; }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  color: var(--fg-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 120ms linear, color 120ms linear;
}
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }
.icon-btn:active { background: var(--surface-3); }

.view {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-bottom) + 20px) 16px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

/* =========================================================================
   Bottom nav
   ========================================================================= */

.navbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
  position: relative;
  transition: color 120ms linear;
}
.nav-item:active { color: var(--fg-2); }
.nav-item .nav-icon svg { width: 22px; height: 22px; display: block; }
.nav-item.active { color: var(--fg); }
.nav-item.active::before {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 28px; height: 2px;
  background: var(--ruby);
}

/* =========================================================================
   Typography blocks
   ========================================================================= */

.section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 22px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title .hairline {
  flex: 1;
  height: 1px;
  background: var(--hairline);
}

.h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.h2 { font-size: 17px; font-weight: 600; margin: 0; }
.h3 { font-size: 14px; font-weight: 600; margin: 0; color: var(--fg-2); }

.mono { font-family: var(--mono); font-feature-settings: "tnum" 1; }

/* =========================================================================
   Cards & primitives
   ========================================================================= */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 10px; }
.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.divider { height: 1px; background: var(--hairline); margin: 14px 0; }

.kv {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--hairline);
}
.kv:last-child { border-bottom: 0; padding-bottom: 0; }
.kv .k { color: var(--muted); font-size: 13px; }
.kv .v { font-weight: 600; }

.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-2);
  background: transparent;
}
.tag.ruby   { color: var(--ruby);  border-color: var(--ruby-3); background: var(--ruby-tint); }
.tag.win    { color: var(--win);   border-color: rgba(22,163,74,.4);  background: var(--win-tint); }
.tag.loss   { color: var(--loss);  border-color: rgba(220,38,38,.4); background: var(--loss-tint); }
.tag.muted  { color: var(--muted); }

/* =========================================================================
   Hero (profile header)
   ========================================================================= */

.hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.hero-body {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
}
.hero-avatar {
  width: 56px; height: 56px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ruby);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}
.hero-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.hero-text { min-width: 0; flex: 1; }
.hero-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hero-tag { color: var(--muted); font-size: 13px; }
.hero-meta { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

.hero-rank {
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}
.hero-rank-left .label { font-size: 11px; color: var(--muted); letter-spacing: 0.16em; text-transform: uppercase; }
.hero-rank-left .tier { font-size: 18px; font-weight: 700; margin-top: 2px; }
.hero-rank-right { text-align: right; }
.hero-rank-right .rr { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; line-height: 1; }
.hero-rank-right .rr small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 4px; letter-spacing: 0.04em; }
.hero-rank-right .delta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.hero-rank-right .delta.up   { color: var(--win); }
.hero-rank-right .delta.down { color: var(--loss); }

/* =========================================================================
   Stats grid
   ========================================================================= */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 12px 10px;
}
.stat .label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat .value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-top: 4px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat.accent .value { color: var(--ruby); }

/* WR bar — flat, без anim */
.wr-bar {
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}
.wr-bar > span {
  display: block;
  height: 100%;
  background: var(--ruby);
}

/* =========================================================================
   Match list
   ========================================================================= */

.match-list { display: flex; flex-direction: column; gap: 8px; }
.match {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 4px 1fr auto;
  gap: 12px;
  align-items: center;
}
.match-bar { width: 3px; align-self: stretch; background: var(--muted-2); border-radius: 2px; }
.match.win  .match-bar { background: var(--win); }
.match.loss .match-bar { background: var(--loss); }
.match-main { min-width: 0; }
.match-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--fg-2);
}
.match-top .map { font-weight: 600; color: var(--fg); }
.match-top .dot { width: 3px; height: 3px; background: var(--muted-2); border-radius: 50%; }
.match-bottom {
  margin-top: 6px;
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
}
.match-bottom b { color: var(--fg-2); font-weight: 600; }
.match-right { text-align: right; min-width: 70px; }
.match-right .kda {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.match-right .score {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  margin-top: 3px;
}

/* =========================================================================
   Forms
   ========================================================================= */

.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.input, .select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 120ms linear, background-color 120ms linear;
}
.input:focus, .select:focus {
  border-color: var(--ruby);
  background: var(--surface);
}
.input::placeholder { color: var(--muted-2); }

.select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 19px, calc(100% - 11px) 19px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px;
  background: var(--surface-2);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background-color 120ms linear, border-color 120ms linear, color 120ms linear;
}
.btn:hover { background: var(--surface-3); }
.btn:active { background: var(--surface-3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--ruby);
  border-color: var(--ruby);
  color: #FFFFFF;
}
.btn-primary:hover { background: var(--ruby-2); border-color: var(--ruby-2); }
.btn-primary:active { background: var(--ruby-3); border-color: var(--ruby-3); }
.btn-danger {
  background: transparent;
  color: var(--loss);
  border-color: rgba(220, 38, 38, 0.4);
}
.btn-danger:hover { background: var(--loss-tint); }

/* Mode chips (matches/stats filter) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 32px;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--fg-2);
  font-size: 13px;
  cursor: pointer;
  transition: background-color 120ms linear, border-color 120ms linear, color 120ms linear;
}
.chip:hover { background: var(--surface-3); }
.chip.active {
  background: var(--ruby-tint);
  color: var(--ruby);
  border-color: var(--ruby-3);
}

/* =========================================================================
   States
   ========================================================================= */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 24px;
}
.empty-icon {
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--muted);
  margin-bottom: 18px;
}
.empty-icon svg { width: 26px; height: 26px; }
.empty-title { font-size: 17px; font-weight: 600; margin: 0 0 6px; }
.empty-text  { font-size: 14px; color: var(--muted); margin: 0 0 18px; max-width: 320px; }

.loader {
  position: fixed;
  inset: var(--top-h) 0 calc(var(--nav-h) + var(--safe-bottom)) 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--ruby);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

[hidden] { display: none !important; }

/* Маленькие экраны */
@media (max-width: 360px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat .value { font-size: 20px; }
  .brand-sub { display: none; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  * { transition: none !important; }
}
