*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3, p, dl, dd, ol, ul { margin: 0; padding: 0; }
ol, ul { list-style: none; }
a { color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- каркас ---------- */
#app { max-width: var(--page-max); margin: 0 auto; min-height: 100vh; }
#view {
  padding: 0 var(--gutter) calc(var(--tabbar-h) + 44px + env(safe-area-inset-bottom));
  outline: none;
}
#view > section { animation: enter .22s ease-out both; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }

.boot, .muted-center { padding: 64px 0; text-align: center; color: var(--muted); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) var(--gutter) 14px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 44px; height: 44px; border-radius: 12px; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name {
  font: 700 24px/1 var(--font-display); letter-spacing: .14em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub { margin-top: 4px; font: 600 11px/1 var(--font-body); letter-spacing: .24em; text-transform: uppercase; color: var(--gold); }

.icon-btn {
  position: relative; display: grid; place-items: center; flex: none;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line); cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; }
.badge {
  position: absolute; top: -2px; right: -2px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: var(--gold); color: var(--on-gold);
  font: 700 12px/20px var(--font-body); text-align: center;
}

/* ---------- типографика ---------- */
.eyebrow { font: 700 12px/1.2 var(--font-body); letter-spacing: .2em; text-transform: uppercase; color: var(--gold); }
.display {
  font-family: var(--font-display); font-weight: 700; text-transform: uppercase; letter-spacing: .01em; line-height: .98;
}
.h-section { font: 700 30px/1 var(--font-display); text-transform: uppercase; letter-spacing: .01em; }
.page-title { font: 700 56px/1 var(--font-display); text-transform: uppercase; margin: 8px 0 20px; }
.lead { color: var(--muted); font-size: 17px; line-height: 1.5; }
.small { font-size: 14px; color: var(--muted); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 36px 0 14px; }
.section-head a { color: var(--gold); font-weight: 700; padding: 8px 0 8px 12px; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 54px; padding: 0 24px; border: 0; border-radius: 18px;
  font: 700 17px/1 var(--font-body); cursor: pointer; text-align: center;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(.98); }
.btn-block { width: 100%; }
.btn-gold { background: var(--gold-grad); color: var(--on-gold); box-shadow: 0 12px 32px -12px rgba(226, 184, 92, .65); }
.btn-ghost { background: var(--surface-hi); color: var(--text); border: 1px solid var(--line); }
.btn-small { min-height: 44px; padding: 0 18px; font-size: 15px; border-radius: 14px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; box-shadow: none; }
.btn.is-loading { pointer-events: none; opacity: .75; }
.btn.is-loading::after {
  content: ""; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.link-btn { background: none; border: 0; padding: 12px 0; color: var(--muted); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.field { display: grid; gap: 8px; }
.field label { font-weight: 600; font-size: 15px; }
.input {
  width: 100%; min-height: 54px; padding: 0 16px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text); font-size: 16px; outline: none;
}
.input::placeholder { color: var(--faint); }
.input:focus { border-color: var(--gold); }
.field-error { color: var(--danger); font-size: 14px; min-height: 0; }

/* ---------- карточки ---------- */
.card {
  position: relative; border-radius: var(--r-xl); padding: 20px;
  background: var(--surface); border: 1px solid var(--line);
}
.card + .card { margin-top: 14px; }
.card h2 { font: 700 26px/1.1 var(--font-display); text-transform: uppercase; margin-bottom: 14px; }

.hero {
  position: relative; overflow: hidden; border-radius: 32px; padding: 26px 22px 22px;
  background: radial-gradient(120% 90% at 100% 0%, rgba(226, 184, 92, .22), transparent 60%), linear-gradient(165deg, #231b0c 0%, #141210 60%, #0f0f10 100%);
  border: 1px solid var(--line-gold);
}
.hero h1 { font-size: 54px; margin: 14px 0 14px; max-width: 8ch; }
.hero .lead { margin-bottom: 24px; max-width: 30ch; }
.hero .mark { position: absolute; right: -28px; top: -18px; width: 230px; opacity: .07; color: var(--gold-hi); pointer-events: none; }
.hero > :not(.mark) { position: relative; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  display: flex; flex-direction: column; gap: 10px; min-height: 168px; padding: 20px;
  border-radius: var(--r-xl); background: var(--surface); border: 1px solid var(--line);
}
.tile svg { width: 28px; height: 28px; color: var(--gold); }
.tile h3 { font: 700 26px/1.05 var(--font-display); text-transform: uppercase; }
.tile p { color: var(--muted); font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 20px;
  background: rgba(255, 255, 255, .08); font-weight: 600; font-size: 15px;
}
.chip-gold { background: rgba(226, 184, 92, .16); color: var(--gold-hi); }

/* ---------- турнир ---------- */
.t-card {
  position: relative; overflow: hidden; border-radius: var(--r-xl); padding: 22px 20px 20px;
  background: linear-gradient(160deg, #2b2210 0%, #17130c 55%, #121110 100%); border: 1px solid var(--line-gold);
}
.t-card + .t-card { margin-top: 14px; }
.t-card > :not(.mark) { position: relative; }
.t-card .mark { position: absolute; right: -40px; top: 10px; width: 190px; opacity: .06; color: var(--gold-hi); pointer-events: none; }
.t-card .t-title { font: 700 40px/1 var(--font-display); text-transform: uppercase; margin: 10px 0 16px; overflow-wrap: anywhere; }
.t-card .t-title a { display: block; }
.t-card .eyebrow.is-muted { color: var(--muted); }
.t-card--detail .t-title { font-size: 48px; }
.t-sep { height: 1px; background: var(--line); margin: 18px 0; }
.t-card .actions { margin-top: 18px; display: grid; gap: 4px; justify-items: stretch; }
.t-card .actions .link-btn { justify-self: center; }
.t-result { margin-top: 16px; }

details.structure summary {
  display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; list-style: none;
  color: var(--gold-hi); font-weight: 700;
}
details.structure summary::-webkit-details-marker { display: none; }
details.structure summary::before { content: ""; border: 6px solid transparent; border-left: 9px solid currentColor; border-right: 0; transition: transform .15s; }
details.structure[open] summary::before { transform: rotate(90deg); }
.structure-body { margin: 4px 0 6px; padding: 14px 16px; border-radius: var(--r-md); background: rgba(0, 0, 0, .28); color: var(--muted); font-size: 15px; white-space: pre-line; }

.back { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; margin: 4px 0 12px; color: var(--gold); font: 700 22px/1 var(--font-display); text-transform: uppercase; }
.back svg { width: 22px; height: 22px; }
.quote { color: var(--muted); font-size: 17px; line-height: 1.55; white-space: pre-line; margin-bottom: 20px; overflow-wrap: anywhere; }
.facts { display: grid; gap: 4px; padding: 16px 18px; border-radius: var(--r-md); background: rgba(0, 0, 0, .3); border: 1px solid var(--line); }
.facts div { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; }
.facts dt { color: var(--muted); }
.facts dd { font-weight: 600; text-align: right; }
.reentry { margin-top: 18px; }
.reentry .eyebrow { display: block; margin-bottom: 6px; }

/* ---------- сегменты ---------- */
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.seg {
  min-height: 52px; border-radius: 18px; border: 1px solid var(--line); background: var(--bg-soft);
  font-weight: 700; font-size: 17px; color: var(--text); cursor: pointer;
}
.seg[aria-pressed="true"] { background: linear-gradient(180deg, #e8c677, #d9ab4b); color: var(--on-gold); border-color: transparent; }

/* ---------- рейтинг ---------- */
.rating { border-radius: var(--r-xl); background: var(--surface); border: 1px solid var(--line); padding: 6px 4px; margin-top: 14px; }
.rrow { display: grid; grid-template-columns: 34px 46px 1fr auto; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 18px; }
.rrow + .rrow { border-top: 1px solid var(--line); border-radius: 0; }
.rrow.is-me { background: rgba(226, 184, 92, .10); border-radius: 18px; border-top-color: transparent; }
.rrow .rank { font: 700 20px/1 var(--font-display); color: var(--muted); text-align: center; }
.rrow.top .rank { color: var(--gold); }
.rrow .name { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rrow .sub { color: var(--faint); font-size: 13px; }
.rrow .pts { font: 700 28px/1 var(--font-display); color: var(--gold-hi); }
.rrow .who { min-width: 0; }

.avatar {
  display: grid; place-items: center; flex: none; width: 46px; height: 46px; border-radius: 50%; overflow: hidden;
  background: hsl(var(--hue, 40) 48% 36%); color: #fff; font: 700 17px/1 var(--font-body);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar--lg { width: 84px; height: 84px; font-size: 30px; border: 2px solid var(--line-gold); }

/* ---------- профиль ---------- */
.profile-head { display: flex; align-items: center; gap: 16px; }
.profile-head .who { min-width: 0; flex: 1; }
.profile-name { display: flex; align-items: center; gap: 10px; }
.profile-name h2 { margin: 0; font-size: 34px; overflow-wrap: anywhere; }
.profile-rank { margin-top: 4px; color: var(--gold); font-weight: 700; }
.edit-row { display: grid; gap: 10px; margin-top: 4px; }
.edit-row .row { display: flex; gap: 10px; }
.edit-row .input { min-height: 48px; }
.notice { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.notice b { display: block; margin-bottom: 4px; }
.status-ok { color: var(--ok); font-weight: 600; margin-top: 14px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { padding: 20px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.stat b { display: block; font: 700 44px/1 var(--font-display); color: var(--gold-hi); margin-bottom: 6px; }
.stat span { color: var(--muted); font-size: 15px; }
.hist { border-radius: var(--r-xl); background: var(--surface); border: 1px solid var(--line); padding: 4px 18px; margin-top: 12px; }
.hist li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 0; }
.hist li + li { border-top: 1px solid var(--line); }
.hist .place { font-weight: 700; color: var(--gold-hi); white-space: nowrap; }

/* ---------- уведомления ---------- */
.notif { padding: 16px 18px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.notif + .notif { margin-top: 10px; }
.notif.is-new { border-color: var(--line-gold); background: #1b1810; }
.notif b { display: block; margin-bottom: 4px; }
.notif p { color: var(--muted); font-size: 15px; overflow-wrap: anywhere; }
.notif time { display: block; margin-top: 8px; color: var(--faint); font-size: 13px; }

/* ---------- нижняя навигация ---------- */
.tabbar {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  bottom: max(12px, env(safe-area-inset-bottom)); width: calc(100% - 24px); max-width: calc(var(--page-max) - 24px);
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 6px;
  background: rgba(22, 22, 24, .86); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: 30px; box-shadow: 0 18px 40px -18px #000;
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 56px; border-radius: 24px; color: var(--muted); font-size: 12px; font-weight: 700;
}
.tab svg { width: 26px; height: 26px; }
.tab[aria-current="page"] { background: var(--surface-hi); color: var(--gold-hi); }

/* ---------- состояния ---------- */
.skel { border-radius: var(--r-xl); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-hi) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.skel--card { height: 190px; }
.skel--row { height: 68px; border-radius: 18px; margin-top: 8px; }
.skel + .skel { margin-top: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.state { padding: 48px 20px; text-align: center; color: var(--muted); border-radius: var(--r-xl); border: 1px dashed var(--line); }
.state b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
.state .btn { margin-top: 18px; }

.toasts { position: fixed; z-index: 50; left: 0; right: 0; bottom: calc(var(--tabbar-h) + 34px + env(safe-area-inset-bottom)); display: grid; gap: 8px; justify-items: center; padding: 0 16px; pointer-events: none; }
.toast {
  max-width: 460px; padding: 14px 18px; border-radius: 16px; background: #26262a; border: 1px solid var(--line);
  box-shadow: 0 14px 36px -12px #000; font-weight: 600; animation: enter .2s ease-out both;
}
.toast.is-error { border-color: rgba(255, 138, 128, .5); }
.toast.is-ok { border-color: rgba(123, 216, 143, .5); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
@media (max-width: 360px) {
  .hero h1 { font-size: 44px; }
  .page-title { font-size: 46px; }
  .t-card .t-title { font-size: 34px; }
}

/* ник показываем как есть, без принудительных заглавных */
.profile-name h2 { text-transform: none; font-size: 32px; }
