:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-2: #eef2ff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --ok-bg: #dcfce7;
  --warn-bg: #fef3c7;
  --bad-bg: #fee2e2;
  --gray-bg: #f3f4f6;
  --track: #eceef5;
  --soft: #fafafa;
  --ok-soft: #f0fdf4;
  --toast-bg: #111827;
  --toast-text: #ffffff;
  --hero-from: #eef2ff;
  --rare-line: #bfdbfe;
  --epic-line: #ddd6fe; --epic-bg: #faf5ff;
  --legend-line: #fde68a; --legend-bg: #fffbeb;
  --rare: #2563eb; --epic: #7c3aed; --legend: #d97706;
  --radius: 12px;
  color-scheme: light;
}
/* dark theme. JS sets html[data-theme] to the effective theme (user choice or system preference) before first paint. */
html[data-theme="dark"] {
  --bg: #0f1117;
  --card: #171a23;
  --text: #e6e8ef;
  --muted: #9aa0b0;
  --line: #2a2f3d;
  --accent: #818cf8;
  --accent-2: #26283f;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --ok-bg: #153524;
  --warn-bg: #3b2f12;
  --bad-bg: #3f1d1d;
  --gray-bg: #232735;
  --track: #262a38;
  --soft: #1c2030;
  --ok-soft: #142a1e;
  --toast-bg: #e6e8ef;
  --toast-text: #0f1117;
  --hero-from: #1f2340;
  --rare-line: #1e3a8a;
  --epic-line: #4c1d95; --epic-bg: #1f1730;
  --legend-line: #78350f; --legend-bg: #2a2010;
  --rare: #93c5fd; --epic: #c4b5fd; --legend: #fcd34d;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); display: inline-flex; align-items: center; gap: 8px; }
.brand-icon { width: 28px; height: 28px; border-radius: 7px; }
.nav { display: flex; gap: 14px; align-items: center; }
.nav a.active { font-weight: 600; }
.theme-btn { background: transparent; border: 1px solid var(--line); color: var(--text); padding: 4px 8px; border-radius: 8px; font-size: 15px; line-height: 1; }
body, .card, .tile, .trophy, input, select, textarea { transition: background-color .2s, color .2s, border-color .2s; }
.container { max-width: 1080px; margin: 24px auto; padding: 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
button, .btn { border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit; }
button.secondary { background: var(--card); color: var(--accent); }
button.danger { background: var(--card); color: var(--bad); border-color: var(--bad); }
button.small { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--card); color: var(--text); }
label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 4px; }
form .row > * { flex: 1; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs button { background: var(--card); color: var(--text); border-color: var(--line); }
.tabs button.active { background: var(--accent-2); color: var(--accent); border-color: var(--accent); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--accent-2); color: var(--accent); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.gray { background: var(--gray-bg); color: var(--muted); }
.progress { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.levels { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.level { border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 12px; background: var(--soft); }
.level.done { border-color: var(--ok); background: var(--ok-soft); }
.goal { border: 1px dashed var(--line); border-radius: 8px; padding: 6px 10px; margin: 6px 0; font-size: 13px; background: var(--soft); }
.goal.done { border-color: var(--ok); background: var(--ok-soft); }
.reward { display: flex; gap: 12px; align-items: center; }
.reward img, .reward .ph { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--accent-2); display: flex; align-items: center; justify-content: center; font-size: 28px; }
.rarity-rare { color: var(--rare); } .rarity-epic { color: var(--epic); } .rarity-legendary { color: var(--legend); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--toast-bg); color: var(--toast-text); padding: 10px 18px; border-radius: 10px; z-index: 10; max-width: 90vw; }
.toast.error { background: var(--bad); }
.hidden { display: none; }
.auth { max-width: 420px; margin: 40px auto; }
.list > .card { margin-bottom: 10px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--gray-bg); padding: 2px 6px; border-radius: 6px; }
.notif.unread { border-left: 3px solid var(--accent); }
.line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line > span { flex: 1; min-width: 0; }
.line .row { flex-wrap: nowrap; }
.thumb { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; vertical-align: middle; margin-right: 6px; background: var(--accent-2); }
.thumb.lg { width: 64px; height: 64px; border-radius: 12px; }
.ach-head { display: flex; align-items: center; gap: 10px; }
.page-head { margin-bottom: 20px; align-items: flex-start; }
.group-hero { display: flex; gap: 16px; align-items: center; }
.group-hero h1 { margin-bottom: 4px; }
.group-hero img { width: 72px; height: 72px; border-radius: 14px; object-fit: cover; flex-shrink: 0; }
input[type="file"] { padding: 6px; font-size: 13px; }
input[type="file"].inline { width: auto; max-width: 180px; padding: 2px; }
.preview { max-height: 80px; border-radius: 8px; margin-top: 6px; display: block; }
/* ---- user page ---- */
.hero { display: flex; gap: 20px; align-items: center; background: linear-gradient(135deg, var(--hero-from), var(--card) 60%); }
.hero-body { flex: 1; min-width: 0; }
.hero-body h1 { margin-bottom: 4px; }
.hero-actions { flex-shrink: 0; }
.bio { margin: 4px 0 8px; white-space: pre-wrap; }
.avatar-xl { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; flex-shrink: 0; box-shadow: 0 0 0 4px var(--card), 0 0 0 6px var(--accent-2); }
.initials { display: inline-flex; align-items: center; justify-content: center; background: var(--accent); color: #fff; font-weight: 700; }
.avatar-xl.initials { font-size: 34px; }
.thumb.initials { font-size: 13px; }
.nav-avatar .thumb { margin: 0; width: 30px; height: 30px; border-radius: 50%; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 0 0 20px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-align: center; }
.tile-n { font-size: 22px; font-weight: 700; }
.trophies { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.trophy { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 10px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.trophy img, .trophy .ph { width: 72px; height: 72px; border-radius: 14px; object-fit: cover; background: var(--accent-2); display: flex; align-items: center; justify-content: center; font-size: 36px; margin-bottom: 4px; }
.trophy.rarity-rare { border-color: var(--rare-line); } .trophy.rarity-epic { border-color: var(--epic-line); background: linear-gradient(180deg, var(--epic-bg), var(--card)); } .trophy.rarity-legendary { border-color: var(--legend-line); background: linear-gradient(180deg, var(--legend-bg), var(--card)); }
.trophy b { color: var(--text); }
.small { font-size: 12px; }
.prow { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.prow:first-of-type { border-top: 0; }
.prow-icon { width: 44px; height: 44px; border-radius: 10px; background: var(--accent-2); display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; overflow: hidden; }
.prow-icon img { width: 100%; height: 100%; object-fit: cover; }
.prow-body { flex: 1; min-width: 0; }
.prow-body .progress { margin: 6px 0 4px; }
.prow.done .progress > div { background: var(--ok); }
.lvl-done { color: var(--ok); font-weight: 600; }
.grid.two { grid-template-columns: 1fr 1fr; margin-top: 20px; }
.timeline { position: relative; }
.tl-item { display: flex; gap: 12px; padding: 8px 0; }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-top: 7px; flex-shrink: 0; }
.tl-dot.reward { background: var(--warn); } .tl-dot.joined { background: var(--muted); } .tl-dot.progress { background: var(--accent); }
.slug-row { flex-wrap: nowrap; } .slug-row .mono { white-space: nowrap; }
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.wall-item { padding: 8px 0; border-top: 1px solid var(--line); }
.wall-item:first-child { border-top: 0; }
#wallForm textarea { flex: 1; resize: vertical; }
#wallForm { align-items: flex-start; margin-bottom: 10px; }
#wallForm button { flex: 0 0 auto; }

/* ---- mobile ---- */
html { -webkit-text-size-adjust: 100%; }
img { max-width: 100%; }
@media (max-width: 720px) {
  .container { margin: 12px auto; padding: 0 10px; }
  .topbar { padding: 8px 12px; }
  .brand { font-size: 16px; }
  .nav { gap: 8px; font-size: 13px; }
  .nav a { white-space: nowrap; }
  .tile { padding: 10px 6px; } .tile-n { font-size: 19px; } .tile .muted { font-size: 12px; }
  .card { padding: 14px; border-radius: 10px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid, .grid.two { grid-template-columns: 1fr; }
  h1 { font-size: 20px; } h2 { font-size: 17px; }
  form .row { flex-direction: column; align-items: stretch; }
  form .row > * { width: 100%; }
  .page-head { flex-direction: column; align-items: stretch; }
  .group-hero img { width: 56px; height: 56px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 0 0 auto; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
  button, .btn { padding: 10px 14px; min-height: 42px; }
  button.small { padding: 8px 12px; min-height: 36px; }
  input, select, textarea { font-size: 16px; } /* prevents iOS zoom on focus */
  input[type="file"].inline { max-width: 100%; }
  .hero { flex-direction: column; text-align: center; }
  .hero-actions { width: 100%; } .hero-actions button, .hero-actions .btn { width: 100%; }
  .avatar-xl { width: 80px; height: 80px; }
  .trophies { grid-template-columns: repeat(2, 1fr); }
  .levels .level { font-size: 11px; }
  .line { flex-wrap: wrap; }
  #wallForm { flex-direction: column; } #wallForm button { width: 100%; }
  .toast { bottom: 12px; width: calc(100% - 24px); }
}
@media (max-width: 340px) {
  .stats, .trophies { grid-template-columns: 1fr; }
}

.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 16px 0 12px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.vk-box { min-height: 42px; }
.btn-vk { display: inline-flex; align-items: center; gap: 8px; background: #0077ff; border-color: #0077ff; color: #fff; width: 100%; justify-content: center; margin-top: 8px; }
