:root {
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #14233b;
  --muted: #5a6b85;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --accent: #06b6d4;
  /* --accent is 2.4:1 on white — decorative only. Use this for any teal TEXT. */
  --accent-text: #0e7490;
  --border: #e2e8f0;
  --shadow: 0 10px 30px rgba(20, 35, 59, 0.08);
  --radius: 16px;
  --max: 1120px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

.container { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 20px; }

/* ---------- Header / Nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; color: var(--text); }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: grid; place-items: center; color: #fff; font-weight: 900;
}
.nav-links { display: flex; gap: 26px; align-items: center; }
.nav-links a { color: var(--muted); font-weight: 600; font-size: 0.95rem; }
.nav-links a:hover { color: var(--primary); text-decoration: none; }
.nav-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 1.1rem; cursor: pointer; }

/* ---------- Hero ---------- */
.hero {
  padding: 64px 0 40px;
  background:
    radial-gradient(1200px 480px at 85% -10%, rgba(124,58,237,0.12), transparent 60%),
    radial-gradient(900px 420px at 0% 0%, rgba(6,182,212,0.12), transparent 55%);
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.12; margin: 0 0 16px; letter-spacing: -0.02em;
}
.hero h1 .grad {
  background: linear-gradient(120deg, var(--primary), var(--primary-2), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p.lead { font-size: 1.15rem; color: var(--muted); max-width: 720px; margin: 0 0 28px; }
.hero-cta { display: flex; gap: 14px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px; border-radius: 12px; font-weight: 700; cursor: pointer;
  border: 1px solid transparent; transition: transform .12s ease, box-shadow .12s ease;
}
.btn-primary { background: linear-gradient(120deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { transform: translateY(-2px); text-decoration: none; color: #fff; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }

.hero-stats { display: flex; gap: 28px; margin-top: 30px; flex-wrap: wrap; }
.hero-stats .stat strong { display: block; font-size: 1.5rem; color: var(--text); }
.hero-stats .stat span { color: var(--muted); font-size: 0.9rem; }

/* ---------- Section ---------- */
section { padding: 56px 0; }
.section-head { margin-bottom: 28px; }
.section-head h2 { font-size: clamp(1.5rem, 3vw, 2.1rem); margin: 0 0 8px; letter-spacing: -0.01em; }
.section-head p { color: var(--muted); margin: 0; max-width: 720px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .78rem; font-weight: 800; color: var(--primary); margin-bottom: 6px; }

/* ---------- Game (built-in) ---------- */
.game-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.game-wrap { position: relative; background: #0b1020; }
#game-canvas { display: block; width: 100%; height: auto; touch-action: none; }
.game-hud {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface);
  font-weight: 700;
}
.game-hud .pill { background: var(--surface-2); color: var(--muted); padding: 4px 12px; border-radius: 999px; font-size: .9rem; }
.game-controls { padding: 0 16px 16px; color: var(--muted); font-size: .9rem; }
.game-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  background: rgba(11,16,32,0.82); color: #fff; padding: 20px;
}
.game-overlay.hidden { display: none; }
.game-overlay h3 { font-size: 1.6rem; margin: 0 0 8px; }
.game-overlay p { color: #c7d2e8; margin: 0 0 18px; }

/* ---------- Gallery ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 10px; transition: transform .14s ease, box-shadow .14s ease;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.card .tag { align-self: flex-start; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--primary); background: var(--surface-2); padding: 4px 10px; border-radius: 999px; }
.card h3 { margin: 4px 0 0; font-size: 1.15rem; }
.card .dev { color: var(--muted); font-size: .85rem; margin: 0; }
.card p.desc { color: var(--muted); font-size: .92rem; margin: 0; flex: 1; }
.card .card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.card .badge { font-size: .75rem; color: var(--accent-text); font-weight: 700; }

/* ---------- Sources ---------- */
.source-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 18px; }
.source {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px;
}
.source h3 { margin: 0 0 6px; font-size: 1.1rem; }
.source p { color: var(--muted); font-size: .9rem; margin: 0 0 12px; }

/* ---------- FAQ ---------- */
.faq { max-width: 820px; margin: 0 auto; }
.faq-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; overflow: hidden; }
.faq-q { width: 100%; text-align: left; background: none; border: 0; padding: 18px 20px; font-size: 1.02rem; font-weight: 700; color: var(--text); cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.faq-q .ico { color: var(--primary); font-weight: 900; transition: transform .2s ease; }
.faq-item.collapsed .faq-q .ico { transform: rotate(0deg); }
.faq-item:not(.collapsed) .faq-q .ico { transform: rotate(45deg); }
/* Answers are visible by default: no-JS crawlers and generative engines get
   the full Q&A text. Collapsing is an opt-in enhancement driven by JS, which
   sets .collapsed on the item. */
.faq-a { max-height: none; overflow: hidden; transition: max-height .25s ease; }
.faq-item.collapsed .faq-a { max-height: 0; }
.faq-a div { padding: 0 20px 18px; color: var(--muted); }

/* ---------- CTA / Footer ---------- */
.cta {
  background: linear-gradient(120deg, var(--primary), var(--primary-2));
  color: #fff; border-radius: var(--radius); padding: 40px; text-align: center;
}
.cta h2 { color: #fff; margin: 0 0 10px; }
.cta p { color: #e6e8ff; margin: 0 0 22px; }

.site-footer { border-top: 1px solid var(--border); padding: 40px 0; color: var(--muted); font-size: .9rem; }
.footer-cols { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.footer-cols a { color: var(--muted); }
.footer-cols a:hover { color: var(--primary); }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .nav-links { display: none; position: absolute; top: 64px; left: 0; right: 0; flex-direction: column; background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px 20px; gap: 14px; }
  .nav-links.open { display: flex; }
  .nav-toggle { display: block; }
}

/* ---------- 404 ---------- */
.center-screen { min-height: 70vh; display: grid; place-items: center; text-align: center; }

/* ---------- Detail pages ---------- */
.detail-hero {
  padding: 40px 0 32px;
  background:
    radial-gradient(1000px 380px at 88% -20%, rgba(124,58,237,0.10), transparent 60%),
    radial-gradient(800px 340px at 0% 0%, rgba(6,182,212,0.10), transparent 55%);
  border-bottom: 1px solid var(--border);
}
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 18px; display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--primary); }
.crumbs span { color: var(--muted); }
.detail-hero .tag {
  display: inline-block; font-size: .72rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .08em; color: var(--primary); background: var(--surface-2);
  padding: 4px 10px; border-radius: 999px; margin-bottom: 10px;
}
.detail-hero h1 { font-size: clamp(1.8rem, 4vw, 2.8rem); margin: 0 0 12px; letter-spacing: -0.02em; }
.detail-hero .lead { font-size: 1.08rem; color: var(--muted); max-width: 760px; margin: 0 0 18px; }
.meta-row { display: flex; gap: 22px; flex-wrap: wrap; color: var(--muted); font-size: .92rem; margin-bottom: 22px; }
.meta-row strong { color: var(--text); }

.detail-body { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 40px; align-items: start; }
.detail-body article h2 { font-size: 1.25rem; margin: 28px 0 10px; }
.detail-body article h2:first-child { margin-top: 0; }
.detail-body article p { color: #33445f; margin: 0 0 14px; line-height: 1.75; }

.detail-side {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; position: sticky; top: 84px;
}
.detail-side h3 { font-size: .95rem; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.detail-side h3:not(:first-child) { margin-top: 22px; }
.detail-side dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; font-size: .9rem; }
.detail-side dt { color: var(--muted); }
.detail-side dd { margin: 0; font-weight: 600; }
.link-list { list-style: none; padding: 0; margin: 0; font-size: .9rem; display: grid; gap: 8px; }

.pager { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 8px 0 24px; }

@media (max-width: 860px) {
  .detail-body { grid-template-columns: 1fr; gap: 28px; }
  .detail-side { position: static; }
}

/* ---------- GitHub trending ---------- */
.trend-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.trend-meta { font-size: .85rem; color: var(--muted); }
.trend-meta strong { color: var(--text); }
.trend-list { display: grid; gap: 12px; margin-top: 24px; }
.trend-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; display: flex; justify-content: space-between; gap: 18px;
  align-items: center; transition: transform .12s ease, box-shadow .12s ease;
}
.trend-item:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.trend-main { min-width: 0; }
.trend-name { font-weight: 700; font-size: 1rem; display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.trend-name .rank { color: var(--muted); font-weight: 600; font-size: .85rem; }
.trend-desc { color: var(--muted); font-size: .88rem; margin: 6px 0 0; }
.trend-stats { text-align: right; white-space: nowrap; font-size: .85rem; }
.trend-stats .num { font-weight: 800; color: var(--text); }
.trend-stats .lbl { color: var(--muted); }
.trend-stats .up { color: #15803d; font-weight: 700; }
.lang-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-right: 4px; }
.btn-sm { padding: 7px 14px; border-radius: 9px; font-size: .85rem; }

@media (max-width: 640px) {
  .trend-item { flex-direction: column; align-items: flex-start; }
  .trend-stats { text-align: left; }
}

/* ---------- Section anchor offset (clears sticky header) ---------- */
section[id] { scroll-margin-top: 80px; }
html { scroll-padding-top: 80px; }

/* Visually hidden but exposed to screen readers and crawlers. Used for
   headings that give a landmark/section an accessible name without
   adding duplicate visual text. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Perf / a11y ---------- */
.skip-link {
  position: absolute; left: -9999px; top: 0; background: var(--primary); color: #fff;
  padding: 10px 16px; border-radius: 0 0 10px 0; z-index: 100; font-weight: 700;
}
.skip-link:focus { left: 0; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
/* <main> receives focus from the skip link; do not paint a ring on the whole page */
main:focus { outline: none; }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
