:root {
  --bg: #14111f;
  --bg-2: #1d1930;
  --card: #241f3a;
  --border: #352e55;
  --text: #f3f1fa;
  --muted: #a49dc2;
  --accent: #ffcc33;
  --accent-2: #ff4d6d;
  --win: #3ddc84;
  --loss: #ff6b6b;
  --radius: 14px;
  --sidebar: 300px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h2 small, h1 small { font-weight: 400; font-size: .6em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.accent { color: var(--accent); }
.error { color: var(--loss); min-height: 1.5em; margin: .5em 0; }
.empty { color: var(--muted); }
[hidden] { display: none !important; }

/* Header / footer */
.site-header { background: var(--bg-2); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; min-height: 60px; }
.header-inner, .footer-inner { max-width: 1240px; margin: 0 auto; padding: .75rem 1rem; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.logo { font-weight: 800; font-size: 1.3rem; color: var(--text); text-decoration: none; }
nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
nav a { color: var(--muted); text-decoration: none; font-weight: 600; }
nav a[aria-current="page"], nav a:hover { color: var(--text); }
nav a.btn { color: #1a1300; }
.site-footer { border-top: 1px solid var(--border); margin-top: 2rem; color: var(--muted); font-size: .9rem; min-height: 120px; }

/* Layout: main column + sticky ad sidebar on wide screens */
.layout { max-width: 1240px; margin: 0 auto; padding: 1rem; display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1fr); }
.sidebar { display: none; }
@media (min-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr) var(--sidebar); }
  .sidebar { display: block; }
  .ad-sidebar { position: sticky; top: 80px; }
}
main > * + *, #profile > * + *, #profile-more > * + * { margin-top: 1.5rem; }

/* Ads: reserved space avoids layout shift (CLS), which keeps Core Web Vitals
   (and so SEO traffic) healthy. */
.ad-slot { margin: 1rem auto; max-width: 1240px; text-align: center; overflow: hidden; }
.ad-top { min-height: 100px; padding: 0 1rem; }
.ad-inline { min-height: 280px; }
.ad-bottom { min-height: 100px; padding: 0 1rem; }
.ad-sidebar { min-height: 600px; width: var(--sidebar); margin: 0; }
@media (min-width: 728px) { .ad-top, .ad-bottom { min-height: 90px; } }
.ad-placeholder { display: flex; align-items: center; justify-content: center; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; }
.ad-empty { min-height: 0; margin: 0; }

/* Components */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.btn { display: inline-block; background: var(--accent); color: #1a1300; border: 0; border-radius: 999px; padding: .6rem 1.2rem; font-weight: 700; font-size: 1rem; text-decoration: none; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-small { padding: .35rem .9rem; font-size: .85rem; }
.btn-large { padding: .9rem 2rem; font-size: 1.15rem; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.tag { display: inline-block; color: var(--accent); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; margin: 0 0 .3rem; }
.badge { display: inline-block; background: var(--accent-2); color: #fff; border-radius: 999px; padding: .15rem .6rem; font-size: .75rem; font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1rem 0; }

/* Avatars */
.avatar { position: relative; display: inline-block; flex: none; border-radius: 50%; overflow: hidden; background: var(--bg-2); vertical-align: middle; }
.avatar img, .avatar-fallback { position: absolute; inset: 0; width: 100%; height: 100%; }
.avatar img { object-fit: cover; object-position: top; }
.avatar-fallback { display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; background: hsl(var(--h) 55% 40%); }
.avatar-sm { width: 36px; height: 36px; font-size: .8rem; }
.avatar-md { width: 64px; height: 64px; font-size: 1.2rem; }
.avatar-lg { width: 110px; height: 110px; font-size: 2rem; }
.avatar-xl { width: 180px; height: 180px; font-size: 3rem; }

/* Home */
.hero { text-align: center; padding: 2rem 1.25rem; background: linear-gradient(135deg, #2d2160, #3a1631); }
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.6rem); }
.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li { display: grid; grid-template-columns: 2rem 1fr auto auto; align-items: center; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.leaderboard li:last-child { border-bottom: 0; }
.rank { font-weight: 800; color: var(--accent); text-align: center; }
.lb-celeb { display: flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none; font-weight: 600; }
.lb-record { color: var(--muted); font-size: .9rem; }
.lb-points { font-weight: 800; color: var(--accent); }
#celebs { scroll-margin-top: 70px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
input[type="search"], select { background: var(--bg-2); color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: .55rem 1rem; font-size: 1rem; }
.tabs { display: flex; gap: .5rem; margin: 1rem 0; flex-wrap: wrap; }
.tabs button { background: var(--bg-2); color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: .4rem 1rem; cursor: pointer; font-weight: 600; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: #1a1300; border-color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1rem; }
.celeb-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: 1rem; transition: transform .15s; }
.celeb-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.card-link { color: var(--text); text-decoration: none; display: flex; flex-direction: column; align-items: center; }
.celeb-card h3 { font-size: 1rem; margin: .6rem 0 .2rem; }
.card-points { margin: 0; color: var(--accent); font-weight: 700; }

/* Profile */
.profile-head { display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap; }
.profile-head h1 { font-size: 2.2rem; margin-bottom: .3rem; }
.bio { color: var(--muted); margin: 0 0 .6rem; }
.points { font-size: 1.2rem; margin: 0; }
.points strong { color: var(--accent); font-size: 2rem; }
.record { width: 100%; border-collapse: collapse; }
.record th, .record td { text-align: left; padding: .6rem .3rem; border-bottom: 1px solid var(--border); }
.record tr:last-child th, .record tr:last-child td { border-bottom: 0; }
.win { color: var(--win); font-weight: 700; }
.loss { color: var(--loss); font-weight: 700; }
.rate { white-space: nowrap; color: var(--muted); }
.bar { display: inline-block; width: 80px; height: 8px; background: var(--loss); border-radius: 4px; overflow: hidden; vertical-align: middle; }
.bar span { display: block; height: 100%; background: var(--win); }
.two-col { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.top5 { margin: 0; padding-left: 1.4rem; }
.top5 li { padding: .35rem 0; }
.top5 li a { display: inline-flex; align-items: center; gap: .5rem; color: var(--text); text-decoration: none; font-weight: 600; }
.top5 .count { float: right; color: var(--muted); font-size: .9rem; line-height: 36px; }
.related { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 1rem; }
.related-item { display: flex; flex-direction: column; align-items: center; gap: .4rem; color: var(--text); text-decoration: none; font-size: .9rem; text-align: center; }

/* Battle */
.step { font-size: 1.1rem; color: var(--muted); }
.games { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.game-card { display: flex; flex-direction: column; align-items: flex-start; gap: .3rem; text-align: left; color: var(--text); font: inherit; cursor: pointer; }
.game-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.game-card:disabled { cursor: not-allowed; opacity: .7; }
.game-icon { font-size: 2rem; }
.game-name { font-weight: 800; font-size: 1.15rem; }
.game-desc { color: var(--muted); font-size: .9rem; }
.fighters { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: center; margin-bottom: 1.5rem; }
.fighter { display: flex; flex-direction: column; align-items: center; gap: .6rem; text-align: center; }
.fighter label { font-weight: 700; color: var(--muted); text-transform: uppercase; font-size: .8rem; letter-spacing: .08em; }
.fighter select { max-width: 100%; }
.preview { display: flex; flex-direction: column; align-items: center; gap: .4rem; min-height: 150px; }
.vs { font-weight: 900; font-size: 1.6rem; color: var(--accent-2); }
.difficulty input[type="range"] { width: 100%; accent-color: var(--accent); }
.setup .btn-large { width: 100%; margin-top: .5rem; }
.arena-title { display: flex; align-items: center; justify-content: center; gap: .6rem; flex-wrap: wrap; font-size: 1.2rem; }
.arena-title .vs { font-size: 1rem; }
#arena-meta { text-align: center; }
.result { text-align: center; border-top: 1px solid var(--border); margin-top: 1rem; padding-top: 1rem; }
.result h3 { font-size: 1.5rem; }
.result .actions { justify-content: center; }
@media (max-width: 560px) {
  .fighters { grid-template-columns: 1fr; }
  .leaderboard li { grid-template-columns: 1.5rem 1fr auto; }
  .lb-record { display: none; }
}

/* Tic Tac Toe */
.ttt { display: flex; flex-direction: column; align-items: center; }
.ttt-status { font-weight: 700; font-size: 1.1rem; min-height: 1.5em; }
.ttt-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(100%, 340px); aspect-ratio: 1; }
.ttt-cell { background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; font-size: clamp(2rem, 10vw, 3.5rem); font-weight: 900; color: var(--text); cursor: pointer; }
.ttt-cell:not(:disabled):hover { border-color: var(--accent); }
.ttt-cell:disabled { cursor: default; }
.ttt-cell.win { background: #3b3366; border-color: var(--accent); }
.mark-x { color: var(--accent); }
.mark-o { color: var(--accent-2); }
.ttt-legend { color: var(--muted); }

/* Static pages */
.prose { max-width: 760px; }
.prose h2 { margin-top: 1.5rem; }
