/* ---------- Tokens ---------- */
:root {
  --bg: #f6f8fa;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #dff5e5 0%, transparent 60%),
             radial-gradient(900px 500px at 110% 0%, #e3ecff 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f3f5f7;
  --border: #d9dee4;
  --text: #1f2328;
  --muted: #59636e;
  --accent: #1f883d;
  --accent-2: #0969da;
  --shadow: 0 1px 2px rgba(31, 35, 40, .06), 0 8px 24px rgba(31, 35, 40, .06);
  --c0: #eff2f5; --c1: #aceebb; --c2: #4ac26b; --c3: #2da44e; --c4: #116329;
  --c0-stroke: rgba(31, 35, 40, .06);
  --radius: 14px;
  --tip-bg: #25292e; --tip-fg: #ffffff;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0c10;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(46, 160, 67, .14) 0%, transparent 60%),
               radial-gradient(900px 500px at 110% 0%, rgba(56, 139, 253, .12) 0%, transparent 55%);
    --surface: #10141a;
    --surface-2: #161b22;
    --border: #2a313c;
    --text: #e6edf3;
    --muted: #9198a1;
    --accent: #3fb950;
    --accent-2: #4493f8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .25);
    --c0: #151b23; --c1: #033a16; --c2: #196c2e; --c3: #2ea043; --c4: #56d364;
    --c0-stroke: rgba(240, 246, 252, .08);
    --tip-bg: #3d444d; --tip-fg: #f0f6fc;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0a0c10;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(46, 160, 67, .14) 0%, transparent 60%),
             radial-gradient(900px 500px at 110% 0%, rgba(56, 139, 253, .12) 0%, transparent 55%);
  --surface: #10141a;
  --surface-2: #161b22;
  --border: #2a313c;
  --text: #e6edf3;
  --muted: #9198a1;
  --accent: #3fb950;
  --accent-2: #4493f8;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .25);
  --c0: #151b23; --c1: #033a16; --c2: #196c2e; --c3: #2ea043; --c4: #56d364;
  --c0-stroke: rgba(240, 246, 252, .08);
  --tip-bg: #3d444d; --tip-fg: #f0f6fc;
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  transition: background-color .25s, color .25s;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0; line-height: 1.25; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.icon { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
.muted { color: var(--muted); }
.small { font-size: 13px; font-weight: 400; }
.dot { color: var(--muted); opacity: .7; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { padding-top: env(safe-area-inset-top); display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background:
    linear-gradient(var(--c4), var(--c4)) 3px 3px / 7px 7px no-repeat,
    linear-gradient(var(--c2), var(--c2)) 12px 3px / 7px 7px no-repeat,
    linear-gradient(var(--c3), var(--c3)) 3px 12px / 7px 7px no-repeat,
    linear-gradient(var(--c1), var(--c1)) 12px 12px / 7px 7px no-repeat,
    var(--surface-2);
  border: 1px solid var(--border);
}
.controls { display: flex; align-items: center; gap: 8px; }

.lang { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 3px; background: var(--surface); }
.lang a { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; }
.lang a:hover { text-decoration: none; color: var(--text); }
.lang a.active { background: var(--text); color: var(--bg); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; transition: transform .15s;
}
.icon-btn:hover { text-decoration: none; border-color: var(--accent); }
#theme-toggle:hover { transform: rotate(-12deg); }
.divider { width: 1px; height: 22px; background: var(--border); margin: 0 2px; }
.icon-btn .icon { width: 18px; height: 18px; }
.icon-btn .icon-sun { display: none; }
:root[data-theme="dark"] .icon-btn .icon-sun { display: block; }
:root[data-theme="dark"] .icon-btn .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-btn .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-btn .icon-moon { display: none; }
}

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; padding: 24px 0 8px; align-items: start; }
.main-col { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; min-width: 0; }
.side-col { position: sticky; top: 80px; min-width: 0; }

@media (max-width: 1040px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side-col { position: static; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.notice { color: var(--muted); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 650; }
.section-head h2 .icon { width: 18px; height: 18px; }
.section-head > a { font-size: 13px; }
.section-desc { margin: -4px 0 12px; color: var(--muted); }

/* ---------- Hero ---------- */
.hero { display: flex; gap: 20px; align-items: center; padding: 24px; }
.avatar { width: 96px; height: 96px; border-radius: 50%; border: 1px solid var(--border); flex: none; object-fit: cover; }
.avatar-ph { background: var(--surface-2); }
.hero h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.handle { margin: 2px 0 6px; color: var(--muted); }
.bio { margin: 0 0 10px; }
.stats { display: flex; flex-wrap: wrap; gap: 4px 16px; list-style: none; padding: 0; margin: 0 0 14px; font-size: 14px; color: var(--muted); }
.stats strong { color: var(--text); }
.socials { display: flex; flex-wrap: wrap; gap: 8px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 13px; font-weight: 550;
  transition: border-color .15s, transform .15s;
}
.pill:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.pill-strong { background: var(--text); color: var(--bg); border-color: var(--text); }

@media (max-width: 560px) {
  .hero { flex-direction: column; align-items: flex-start; }
  .avatar { width: 72px; height: 72px; }
}

/* ---------- Contributions ---------- */
.contrib-scroll { overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.contrib-svg { display: block; }
.contrib-svg .lbl { font-size: 10px; fill: var(--muted); }
.contrib-svg rect, .legend rect { stroke: var(--c0-stroke); stroke-width: 1; }
.contrib-svg rect { cursor: pointer; }
.contrib-svg rect:hover, .contrib-svg rect.active { stroke: var(--text); stroke-width: 1.5; }

.contrib-tip {
  position: absolute; z-index: 50; pointer-events: none;
  max-width: 260px; padding: 6px 10px; border-radius: 6px;
  background: var(--tip-bg); color: var(--tip-fg);
  font-size: 12px; font-weight: 500; line-height: 1.35; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  animation: tip-in .08s ease-out;
}
.contrib-tip::after {
  content: ""; position: absolute; left: var(--arrow-x, 50%); top: 100%;
  transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--tip-bg);
}
.contrib-tip.below::after { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--tip-bg); }
@keyframes tip-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.l0 { fill: var(--c0); } .l1 { fill: var(--c1); } .l2 { fill: var(--c2); } .l3 { fill: var(--c3); } .l4 { fill: var(--c4); }
.contrib-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--muted); }
.contrib-foot a { color: var(--muted); }
.legend { display: inline-flex; align-items: center; gap: 3px; }
.legend svg { display: block; }
.legend svg:first-of-type { margin-left: 4px; }
.legend svg:last-of-type { margin-right: 4px; }

/* ---------- Repos ---------- */
.repo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.org-avatar { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border); }

.repo {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.repo:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); transform: translateY(-2px); }
.repo-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.repo-name { font-weight: 650; font-size: 15px; word-break: break-word; }
.badge { font-size: 11px; padding: 1px 8px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); }
.badge-warn { color: #9a6700; border-color: #d4a72c80; }
.repo-desc {
  margin: 0; color: var(--muted); font-size: 13.5px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.commit {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; align-items: start;
  padding: 10px 12px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid transparent; color: var(--text); font-size: 13px; margin: 0;
}
a.commit:hover { text-decoration: none; border-color: var(--border); }
.commit > .icon { color: var(--accent); margin-top: 2px; }
.commit-msg { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.commit-meta { grid-column: 2; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.commit-meta img { border-radius: 50%; }
.commit-empty { display: block; color: var(--muted); }

.repo-foot { margin-top: auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.lang-tag { display: inline-flex; align-items: center; gap: 6px; }
.lang-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.stat { display: inline-flex; align-items: center; gap: 4px; }
.stat .icon { width: 14px; height: 14px; }
.pushed { margin-left: auto; }

/* ---------- X ---------- */
.x-card { padding: 16px; display: grid; gap: 14px; }
.x-card .section-head { margin: 0; }
.pill-sm { padding: 4px 12px; font-size: 12.5px; }
.x-profile { display: flex; align-items: center; gap: 12px; color: var(--text); }
.x-profile:hover { text-decoration: none; }
.x-profile img, .x-avatar-ph { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); flex: none; }
.x-avatar-ph { display: grid; place-items: center; background: var(--surface-2); }
.x-profile > span:last-child { display: grid; line-height: 1.3; min-width: 0; }
.x-profile strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.x-posts { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; max-height: 70vh; overflow-y: auto; scrollbar-width: thin; }
.x-post { padding: 12px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid transparent; transition: border-color .15s; }
.x-post:hover { border-color: var(--border); }
.x-repost { margin: 0 0 4px; }
.x-text { margin: 0; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.x-media { display: grid; gap: 4px; margin-top: 10px; border-radius: 10px; overflow: hidden; }
.x-media img { width: 100%; height: 100%; object-fit: cover; display: block; aspect-ratio: 16 / 9; }
.x-media-2, .x-media-3, .x-media-4 { grid-template-columns: 1fr 1fr; }
.x-media-2 img, .x-media-3 img, .x-media-4 img { aspect-ratio: 1; }
.x-media-3 img:first-child { grid-row: span 2; aspect-ratio: auto; }
.x-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; white-space: nowrap; margin-top: 8px; font-size: 12px; color: var(--muted); }
.x-meta:hover { text-decoration: none; color: var(--text); }
.x-open { margin-left: auto; }
.x-empty { text-align: center; padding: 8px 8px 0; color: var(--muted); font-size: 14px; }
.x-empty p { margin: 0; }
.x-all { display: inline-flex; align-items: center; gap: 6px; justify-content: center; font-size: 13px; font-weight: 550; padding: 8px; border-radius: 10px; border: 1px dashed var(--border); color: var(--text); }
.x-all:hover { text-decoration: none; border-color: var(--accent); }

/* ---------- Live status ---------- */
.live-status { display: flex; align-items: center; gap: 8px; margin: -8px 0 0; font-size: 12.5px; color: var(--muted); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
#live.updated > * { animation: flash 1.2s ease-out; }
@keyframes flash { from { opacity: .35; } to { opacity: 1; } }

/* ---------- Footer ---------- */
.footer { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding: 24px 16px 40px; color: var(--muted); font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .layout { padding-top: 16px; gap: 16px; }
  .main-col { gap: 16px; }
  .card { padding: 16px; border-radius: 12px; }
  .hero { padding: 18px; gap: 14px; }
  .hero h1 { font-size: 22px; }
  .socials { gap: 6px; }
  .pill { padding: 6px 10px; }
  .repo-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .repo { padding: 14px; }
  .repo:hover { transform: none; }
  .section-head h2 { font-size: 16.5px; }
  .contrib-foot { font-size: 11.5px; }
  .x-posts { max-height: none; }
  .footer { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
}

@media (max-width: 440px) {
  .wrap { padding: 0 12px; }
  .brand > span:last-child, .divider { display: none; }
  .controls { gap: 6px; }
  .icon-btn { width: 34px; height: 34px; }
  .stats { gap: 2px 12px; font-size: 13px; }
  .pushed { margin-left: 0; width: 100%; }
}

/* Touch devices: no sticky hover lift */
@media (hover: none) {
  .pill:hover, .repo:hover { transform: none; }
}

/* ---------- Featured projects ---------- */
.featured-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
/* odd one out spans the full row */
.featured:last-child:nth-child(odd) { grid-column: 1 / -1; }
.featured {
  display: flex; flex-direction: column; gap: 12px; position: relative; overflow: hidden;
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}
.featured::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--c2), var(--accent-2));
}
.featured-head { display: flex; align-items: center; gap: 12px; }
.featured-icon { width: 48px; height: 48px; border-radius: 12px; flex: none; border: 1px solid var(--border); background: var(--surface-2); object-fit: contain; padding: 4px; }
.featured-icon-ph { display: grid; place-items: center; font-weight: 700; font-size: 20px; color: var(--accent); padding: 0; }
.featured-title { min-width: 0; flex: 1; }
.featured-title h3 { margin: 0; font-size: 17px; line-height: 1.25; }
.featured-title h3 a { color: var(--text); }
.featured-host { font-size: 12.5px; color: var(--muted); }
.featured-desc { margin: 0; font-size: 14px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; align-self: flex-start; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-up { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.status-up .status-dot { background: var(--accent); animation: pulse 2s infinite; box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); }
.status-down { color: #cf222e; border-color: #cf222e55; }
.status-down .status-dot { background: #cf222e; }

.featured-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.tag .icon { width: 12px; height: 12px; }
.tag-open { color: var(--accent); }
.tag-closed { color: #9a6700; border-color: #d4a72c66; }
.tag-topic { color: var(--accent-2); }

.featured-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 10px; font-size: 13.5px; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #04130a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #04130a; } }
.btn-primary:hover { filter: brightness(1.08); }
.btn-muted { opacity: .6; }

@media (max-width: 640px) {
  .featured-grid { grid-template-columns: minmax(0, 1fr); }
  .featured:last-child:nth-child(odd) { grid-column: auto; }
  .featured-head { flex-wrap: wrap; }
}
