/* ==========================================================================
   Tokens
   ========================================================================== */
:root,
[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-soft: #11161d;
  --surface: #161b22;
  --surface-2: #1c2330;
  --border: #30363d;
  --border-strong: #484f58;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #3d444d;
  --accent: #39d353;
  --accent-soft: rgba(57, 211, 83, 0.14);
  --blue: #58a6ff;
  --purple: #d2a8ff;
  --yellow: #e3b341;
  --red: #ff7b72;
  --cyan: #56d4dd;
  --term-bg: #0a0d12;
  --term-bar: #161b22;
  --logo-bg: #e6edf3;
  --grid-line: rgba(240, 246, 252, 0.035);
  --glow-1: rgba(57, 211, 83, 0.13);
  --glow-2: rgba(88, 166, 255, 0.1);
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.7);
}

[data-theme='light'] {
  color-scheme: light;
  --bg: #f6f8fa;
  --bg-soft: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f3f5f7;
  --border: #d0d7de;
  --border-strong: #afb8c1;
  --text: #1f2328;
  --text-muted: #59636e;
  --text-dim: #d0d7de;
  --accent: #1a7f37;
  --accent-soft: rgba(26, 127, 55, 0.1);
  --blue: #0969da;
  --purple: #8250df;
  --yellow: #9a6700;
  --red: #cf222e;
  --cyan: #1b7c83;
  --term-bg: #ffffff;
  --term-bar: #f0f3f6;
  --logo-bg: #f6f8fa;
  --grid-line: rgba(31, 35, 40, 0.045);
  --glow-1: rgba(26, 127, 55, 0.1);
  --glow-2: rgba(9, 105, 218, 0.08);
  --shadow: 0 18px 50px -24px rgba(31, 35, 40, 0.35);
}

:root {
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 14px;
  --radius-sm: 9px;
  --container: 1120px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ==========================================================================
   Base
   ========================================================================== */
*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 76px; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
}

img { max-width: 100%; display: block; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.15; margin: 0; letter-spacing: -0.02em; }
code, kbd, pre { font-family: var(--font-mono); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

.muted { color: var(--text-muted); }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: -100px; left: 16px;
  z-index: 100;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #0d1117;
  font-weight: 600;
}
.skip-link:focus { top: 12px; }

/* Graph-paper backdrop with soft glows */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(600px 400px at 15% 8%, var(--glow-1), transparent 70%),
    radial-gradient(700px 500px at 90% 30%, var(--glow-2), transparent 70%),
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / 32px 32px;
  mask-image: linear-gradient(to bottom, #000 0%, #000 55%, transparent 100%);
}

.scroll-progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 60;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  transform: scaleX(0);
  transform-origin: left;
}

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px max(20px, calc((100% - var(--container)) / 2));
  border-bottom: 1px solid transparent;
  transition: background-color 0.25s, border-color 0.25s, backdrop-filter 0.25s;
}
.topbar.is-scrolled {
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-bottom-color: var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  font: 500 14px var(--font-mono);
  color: var(--text-muted);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-caret {
  display: inline-block;
  width: 8px; height: 15px;
  margin-left: 4px;
  vertical-align: -2px;
  background: var(--accent);
  animation: blink 1.06s steps(1) infinite;
}

.nav-links {
  display: flex;
  gap: 4px;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-links a {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--text-muted);
  font: 500 14px var(--font-mono);
  transition: color 0.2s, background-color 0.2s;
}
.nav-links a::before { content: './'; opacity: 0.5; }
.nav-links a:hover,
.nav-links a[aria-current] {
  color: var(--text);
  background: var(--surface-2);
  text-decoration: none;
}
.nav-links a[aria-current] { color: var(--accent); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px; height: 38px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, transform 0.2s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); transform: rotate(-12deg); }

/* ==========================================================================
   Hero
   ========================================================================== */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  min-height: calc(100vh - 64px);
  padding: 48px 20px 40px;
  text-align: center;
}

.avatar { position: relative; animation: rise 0.7s var(--ease) both; }
.avatar img {
  width: 112px; height: 112px;
  border-radius: 50%;
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 2px var(--accent), 0 10px 40px -8px var(--accent-soft);
}
.status-dot {
  position: absolute;
  right: 6px; bottom: 6px;
  width: 18px; height: 18px;
  border: 3px solid var(--bg);
  border-radius: 50%;
  background: var(--accent);
}

.hero h1 {
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  font-weight: 800;
  animation: rise 0.7s 0.08s var(--ease) both;
}
.gradient-text {
  background: linear-gradient(100deg, var(--accent), var(--cyan) 55%, var(--blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub {
  margin: -6px 0 6px;
  color: var(--text-muted);
  font-size: 1.08rem;
  animation: rise 0.7s 0.16s var(--ease) both;
}
.sep { color: var(--accent); margin: 0 4px; }

.hero-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
  animation: rise 0.7s 0.32s var(--ease) both;
}

.scroll-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: auto;
  padding-top: 24px;
  color: var(--text-muted);
  font: 12px var(--font-mono);
}
.scroll-hint:hover { color: var(--accent); text-decoration: none; }
.scroll-hint svg { animation: bob 1.8s ease-in-out infinite; }

/* ==========================================================================
   Terminal
   ========================================================================== */
.terminal {
  width: min(100%, 780px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--term-bg);
  box-shadow: var(--shadow);
  text-align: left;
  overflow: hidden;
  animation: rise 0.7s 0.24s var(--ease) both;
}
.terminal:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }

.terminal-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  background: var(--term-bar);
  border-bottom: 1px solid var(--border);
}
.dot { width: 12px; height: 12px; border-radius: 50%; }
.dot-red { background: #ff5f57; }
.dot-yellow { background: #febc2e; }
.dot-green { background: #28c840; }
.terminal-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  color: var(--text-muted);
  font: 13px var(--font-mono);
}

.terminal-body {
  height: 360px;
  padding: 14px 18px 16px;
  overflow-y: auto;
  font: 14px/1.65 var(--font-mono);
  cursor: text;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.t-line { min-height: 1.65em; white-space: pre-wrap; word-break: break-word; }
.t-line + .t-line:has(> .prompt) { margin-top: 4px; }

.prompt { white-space: pre; }
.t-user { color: var(--accent); }
.t-host { color: var(--blue); }
.t-path { color: var(--purple); }
.t-typed { color: var(--text); }
.t-muted { color: var(--text-muted); }
.t-dim { color: var(--text-dim); }
.t-accent { color: var(--accent); }
.t-warn { color: var(--yellow); }
.t-err { color: var(--red); }
.t-indent { display: inline-block; padding-left: 2ch; }
.t-link { color: var(--blue); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--blue) 40%, transparent); text-underline-offset: 3px; }

.t-caret {
  display: inline-block;
  width: 0.6em; height: 1.15em;
  vertical-align: text-bottom;
  background: var(--accent);
}

.t-cmd {
  padding: 0;
  border: 0;
  background: none;
  color: var(--cyan);
  font: inherit;
  text-align: left;
  cursor: pointer;
  text-decoration: underline dotted color-mix(in srgb, var(--cyan) 50%, transparent);
  text-underline-offset: 3px;
}
.t-cmd:hover { color: var(--accent); text-decoration-style: solid; }

.t-pre {
  margin: 0;
  font: inherit;
  white-space: pre;
  overflow-x: auto;
  scrollbar-width: thin;
}
.t-table { color: var(--text); }

.t-help {
  display: grid;
  grid-template-columns: minmax(15ch, max-content) 1fr;
  column-gap: 2ch;
  padding-left: 2ch;
}

.t-skill { display: inline-block; min-width: 14ch; padding-left: 2ch; }
.t-bar { letter-spacing: 1px; }

.neofetch {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  align-items: flex-start;
  padding: 4px 0;
}
.nf-art { color: var(--accent); line-height: 1.35; }
.nf-key { color: var(--accent); font-weight: 700; }
.nf-colors { display: flex; margin-top: 8px; }
.nf-swatch { width: 2.4ch; height: 1.1em; }
.nf-err { background: var(--red); }
.nf-warn { background: var(--yellow); }
.nf-accent { background: var(--accent); }
.nf-host { background: var(--blue); }
.nf-path { background: var(--purple); }
.nf-cyan { background: var(--cyan); }
.nf-muted { background: var(--text-muted); }
.nf-fg { background: var(--text); }

.terminal-input-line {
  display: flex;
  align-items: baseline;
  margin-top: 4px;
}
.terminal-input-line input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  caret-color: var(--accent);
  font: inherit;
}
.terminal-input-line input::placeholder { color: var(--text-muted); opacity: 0.6; }
.terminal-input-line.is-busy input { opacity: 0.4; }

/* ==========================================================================
   Sections
   ========================================================================== */
.section {
  width: min(100% - 40px, var(--container));
  margin: 0 auto;
  padding: 88px 0 24px;
}

.section-head { max-width: 720px; margin-bottom: 32px; }
.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font: 500 13px var(--font-mono);
  overflow-wrap: anywhere;
}
.section h2 { font-size: clamp(1.8rem, 3.6vw, 2.5rem); font-weight: 800; }
.section-sub { margin: 10px 0 0; color: var(--text-muted); font-size: 1.02rem; }
.subhead {
  margin: 56px 0 18px;
  font: 600 1.1rem var(--font-mono);
  color: var(--text-muted);
}
.subhead::before { content: '## '; color: var(--accent); }

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 10px;
  font: 12px var(--font-mono);
}

.panel {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  transition: border-color 0.25s, transform 0.25s var(--ease), box-shadow 0.25s;
}

/* Stack */
.stack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.stack-panel { padding: 20px; }
.stack-panel:hover { border-color: var(--border-strong); }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.panel-head h3 { font-size: 1.02rem; font-weight: 700; }
.panel-icon {
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
}
.panel-key {
  margin-left: auto;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.88rem;
  font-weight: 500;
  transition: border-color 0.2s, transform 0.2s;
}
.chip:hover { border-color: var(--accent); transform: translateY(-2px); }
.chip-logo {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--logo-bg);
}
.chip-logo img { width: 17px; height: 17px; object-fit: contain; }

.level { display: inline-flex; gap: 3px; }
.level i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
}
.level i.on { background: var(--accent); }

/* Certifications */
.certs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.cert {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px;
  color: inherit;
}
a.cert:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-3px); box-shadow: var(--shadow); }
.cert-img {
  display: grid;
  place-items: center;
  width: 92px; height: 92px;
  flex: none;
}
.cert-img img { max-height: 92px; object-fit: contain; }
.cert-body h3 { margin: 8px 0 4px; font-size: 1rem; font-weight: 700; }
.cert-body p { margin: 0; font-size: 0.86rem; }
.cert-verify {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 600;
}
.cert.is-pending { border-style: dashed; }
.cert.is-pending .cert-img img { filter: grayscale(1); opacity: 0.55; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font: 600 11px var(--font-mono);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.pill-ok { background: var(--accent-soft); color: var(--accent); }
.pill-wip { background: color-mix(in srgb, var(--yellow) 15%, transparent); color: var(--yellow); }

/* Projects */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.featured-grid { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }

.project {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
}
.project:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: var(--shadow); }
.project.is-featured {
  background:
    linear-gradient(160deg, var(--accent-soft), transparent 45%),
    color-mix(in srgb, var(--surface) 88%, transparent);
}
.project-head { display: flex; align-items: center; gap: 8px; color: var(--text-muted); }
.project-head h3 { min-width: 0; font: 600 1rem var(--font-mono); overflow-wrap: anywhere; }
.project-link { color: var(--text); }
.project-link::after { content: ''; position: absolute; inset: 0; border-radius: inherit; }
.project-link:hover { text-decoration: none; }
.project:hover .project-link { color: var(--accent); }
.project-demo {
  position: relative;
  z-index: 1;
  margin-left: auto;
  color: var(--text-muted);
}
.project-demo:hover { color: var(--accent); }
.project-desc { flex: 1; margin: 0; color: var(--text-muted); font-size: 0.93rem; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.tags li {
  padding: 2px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--blue) 12%, transparent);
  color: var(--blue);
  font: 500 12px var(--font-mono);
}

.project-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  color: var(--text-muted);
  font-size: 0.82rem;
}
.lang, .meta { display: inline-flex; align-items: center; gap: 6px; }
.lang-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
}
.meta-date { margin-left: auto; }

.repo-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: 14px var(--font-sans);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#repo-search { flex: 1 1 260px; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font: 13px var(--font-mono);
  cursor: pointer;
}
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.repo-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 22px;
}
.repo-footer p { margin: 0; font-size: 0.88rem; }

.empty {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
  padding: 36px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}
.loader {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.93rem;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s, color 0.2s, transform 0.2s;
}
.btn:hover { text-decoration: none; transform: translateY(-2px); }
.btn-ghost { background: var(--surface); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0d1117; }
[data-theme='light'] .btn-primary { color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }

/* Contact */
.contact-card {
  padding: clamp(28px, 5vw, 56px);
  text-align: center;
  background:
    radial-gradient(500px 200px at 50% 0%, var(--accent-soft), transparent 70%),
    color-mix(in srgb, var(--surface) 88%, transparent);
}
.contact-card .section-sub { max-width: 560px; margin: 12px auto 0; }
.contact-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 28px;
}

.footer {
  padding: 56px 20px 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.86rem;
}
.footer p { margin: 4px 0; }
.footer .muted { font-family: var(--font-mono); font-size: 0.78rem; opacity: 0.8; }

.noscript {
  width: min(100% - 40px, 720px);
  margin: 0 auto 40px;
  padding: 16px;
  border: 1px solid var(--yellow);
  border-radius: var(--radius-sm);
  text-align: center;
}

/* ==========================================================================
   Motion
   ========================================================================== */
.reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.6s var(--ease) var(--delay, 0ms), transform 0.6s var(--ease) var(--delay, 0ms),
    border-color 0.25s, box-shadow 0.25s;
}
.reveal.is-visible { opacity: 1; transform: none; }
a.cert.reveal.is-visible:hover,
.project:hover { transition-delay: 0ms; }
a.cert.reveal.is-visible:hover { transform: translateY(-3px); }

@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes bob { 50% { transform: translateY(4px); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .reveal { opacity: 1; transform: none; }
}

/* ==========================================================================
   Small screens
   ========================================================================== */
@media (max-width: 640px) {
  .brand { font-size: 12px; }
  .brand-caret { display: none; }
  .nav-links a { padding: 6px 8px; font-size: 13px; }
  .nav-links a::before { display: none; }
  .hero { padding-top: 28px; }
  .terminal-body { height: 380px; padding: 12px; font-size: 13px; }
  .terminal-input-line input { font-size: 16px; } /* stops iOS zoom on focus */
  .stack-grid, .certs-grid, .projects-grid, .featured-grid { grid-template-columns: 1fr; }
  .section { padding-top: 64px; }
}

@media (max-width: 520px) {
  .brand { display: none; }
  .nav-links { margin-left: -8px; margin-right: auto; }
  .nav-links a { padding: 6px; }
}
