:root {
  --bg: #0f1115;
  --bg2: #181b22;
  --card: #1d212b;
  --text: #eceff4;
  --muted: #9aa3b2;
  --gold: #d4a64a;
  --green: #769656;
  --light: #eeeed2;
  --red: #c0504d;
  --radius: 20px;
  --piece-op: 0.06;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg) 0%, var(--bg2) 100%) fixed;
  line-height: 1.5;
}

/* Фон: падающие фигуры */
.bg {
  position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0;
}
.bg span {
  position: absolute; top: -10vh;
  color: var(--gold); opacity: var(--piece-op);
  animation: fall linear infinite;
  will-change: transform;
}
@keyframes fall { to { transform: translateY(120vh) rotate(360deg); } }

.skip {
  position: absolute; left: 8px; top: -60px;
  background: var(--gold); color: #000; padding: 8px 12px; border-radius: 8px; z-index: 10;
}
.skip:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* Профиль */
.profile {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  padding: 32px 16px;
  text-align: center;
  background:
    repeating-conic-gradient(rgba(255,255,255,.04) 0% 25%, transparent 0% 50%) 0 0 / 64px 64px,
    linear-gradient(180deg, #1a1e27, transparent);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.avatar {
  padding: 0; border: 4px solid var(--gold); border-radius: 50%;
  width: 160px; height: 160px; overflow: hidden; cursor: zoom-in; background: var(--card);
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-info { max-width: 640px; }
.profile h1 { margin: 0; font-size: 2rem; }
.status { margin: 4px 0; color: var(--gold); }
.bio { margin: 8px 0 16px; color: var(--muted); }
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0;
}
.stat { background: var(--card); border-radius: 16px; padding: 12px 8px; }
.stat dt { font-size: .8rem; color: var(--muted); }
.stat dd { margin: 0; font-size: 1.4rem; font-weight: 700; color: var(--light); }

/* Секции */
.section { max-width: 1000px; margin: 0 auto; padding: 32px 16px 8px; }
.section h2 { margin: 0 0 12px; font-size: 1.5rem; }
.section h2::before { content: "♞ "; color: var(--gold); }
.card:not(button) { cursor: default; }
.card .preview { width: 56px; height: 56px; object-fit: contain; }
.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }

/* Карточки */
.card {
  display: flex; gap: 14px; align-items: center; text-align: left;
  width: 100%; padding: 16px; font: inherit; color: inherit;
  background: var(--card); border: 1px solid rgba(255,255,255,.06); border-radius: var(--radius);
  cursor: pointer; transition: transform .15s, border-color .15s;
}
.card:hover { transform: translateY(-2px); border-color: var(--gold); }
.card h3 { margin: 0 0 2px; font-size: 1.05rem; }
.card p { margin: 0; color: var(--muted); font-size: .9rem; }
.icon { width: 48px; height: 48px; flex-shrink: 0; color: var(--gold); }
.game-icon {
  width: 48px; height: 48px; flex-shrink: 0; display: grid; place-items: center;
  font-size: 1.8rem; border-radius: 12px; color: #111; background: var(--light);
}
.badge {
  display: inline-block; margin-left: 6px; padding: 0 8px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; color: #fff;
}
.badge.win { background: var(--green); }
.badge.loss { background: var(--red); }
.badge.draw { background: #7a8394; }

.footer { text-align: center; color: var(--muted); padding: 32px 16px; }

/* Лайтбокс */
dialog#lightbox {
  position: fixed; inset: 0; width: 100vw; height: 100vh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: rgba(5,6,8,.92); color: var(--text);
}
dialog#lightbox[open] { display: flex; align-items: center; justify-content: center; }
dialog#lightbox::backdrop { background: rgba(0,0,0,.6); }
.lb-figure { margin: 0; padding: 16px; max-width: 100%; max-height: 100%; text-align: center; }
.lb-content img, .lb-content svg {
  max-width: min(92vw, 900px); max-height: 78vh; width: auto; height: auto; display: block; margin: 0 auto;
  border-radius: 12px;
}
.lb-content svg { width: min(80vw, 420px); height: auto; color: var(--gold); }
.lb-figure figcaption { margin-top: 12px; color: var(--muted); }
.close {
  position: absolute; top: 12px; right: 16px; width: 44px; height: 44px;
  font-size: 2rem; line-height: 1; color: var(--text); background: var(--card);
  border: 1px solid rgba(255,255,255,.2); border-radius: 50%; cursor: pointer;
}

/* Адаптив */
@media (min-width: 640px) {
  .profile { flex-direction: row; text-align: left; justify-content: center; padding: 48px clamp(56px, 10vw, 156px) 48px 24px; }
  .avatar { width: 200px; height: 200px; }
  .profile h1 { font-size: 2.6rem; }
  .grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
  .ach-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .card { transition: none; }
  .bg { display: none; }
}

/* Партии: квадратная обложка, под ней название и результат */
.grid.games-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
  gap: 18px;
}
.games-grid .card {
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 0;
  padding: 0;
  overflow: hidden;
}
.games-grid .card .preview {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
  background: var(--bg);
}
.games-grid article.card::before {
  content: "";
  width: 100%;
  aspect-ratio: 1;
  background:
    linear-gradient(135deg, rgba(212, 166, 74, .22), transparent 60%),
    repeating-conic-gradient(#2a2f3c 0 25%, var(--card) 0 50%) 0 0 / 25% 25%;
}
.games-grid .card h3 {
  margin: 14px 16px 6px;
  font-size: 1.15rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.games-grid .card h3:last-child { margin-bottom: 16px; }
.games-grid .badge { align-self: flex-start; margin: 0 16px 16px; }
.games-grid article.card:hover { transform: none; }
.games-grid button.card:is(:hover, :focus-visible) { border-color: var(--gold); }
.games-grid .is-fav { border-color: var(--gold); position: relative; }
.star {
  position: absolute; top: 10px; right: 10px; padding: 3px 10px;
  border-radius: 999px; background: var(--bg); color: var(--gold);
  font-size: .82rem; font-weight: 700;
}
.sections-nav {
  position: relative; display: flex; flex-wrap: wrap; gap: 8px;
  max-width: 1000px; margin: 0 auto; padding: 24px 16px 0;
}
.sections-nav a {
  padding: 8px 14px; border-radius: 999px; background: var(--card);
  color: var(--text); text-decoration: none;
}
.sections-nav a[aria-current] { background: var(--gold); color: var(--bg); }
main .section { scroll-margin-top: 5rem; }
.empty-note { color: var(--muted); }
