:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --bg-card: #fff;
  --bg-input: #e8e8ed;
  --text: #1a1a1e;
  --secondary: #4a4a52;
  --muted: #65656f;
  --border: #d2d2d7;
  --border-hover: #a0a0aa;
  --accent: #5a5a66;
  --hero-gradient: linear-gradient(135deg, #8e8e98, #1a1a1e 50%, #6e6e77);
  --shadow: 0 4px 16px rgb(0 0 0 / 6%);
  --graph-opacity: .48;
  --radius: 14px;
  --motion: 240ms cubic-bezier(.25, .46, .45, .94);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0c;
  --bg-card: #1c1c1e;
  --bg-input: #2c2c2e;
  --text: #f2f2f5;
  --secondary: #b0b0b8;
  --muted: #a0a0aa;
  --border: #3a3a3c;
  --border-hover: #777781;
  --accent: #8e8e98;
  --hero-gradient: linear-gradient(135deg, #b0b0b8, #f2f2f5 50%, #9a9aa3);
  --shadow: 0 4px 16px rgb(0 0 0 / 40%);
  --graph-opacity: .42;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 5.5rem; }

body {
  isolation: isolate;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.65 Inter, system-ui, sans-serif;
  transition: background-color var(--motion), color var(--motion);
}

.graph-background {
  position: fixed;
  z-index: -1;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: var(--graph-opacity);
  pointer-events: none;
}

h1, h2, h3, p { margin: 0; }
h2, h3 { line-height: 1.2; }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-underline-offset: .2em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.container {
  width: min(1120px, calc(100% - 2 * clamp(16px, 4vw, 36px)));
  margin-inline: auto;
}

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

.skip-link {
  position: fixed;
  z-index: 5;
  inset: 8px auto auto 12px;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--bg-card);
  transform: translateY(-150%);
}

.skip-link:focus { transform: none; }
.site-header { position: sticky; z-index: 3; top: 0; background: var(--bg); }

.navbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px clamp(12px, 3vw, 32px);
  min-height: 64px;
  padding-block: 10px;
  border-bottom: 1px solid var(--border);
}

.logo { font-size: 1.4rem; font-weight: 700; letter-spacing: -.04em; text-decoration: none; }
.nav-links { display: flex; flex-wrap: wrap; gap: 4px clamp(10px, 2.6vw, 30px); margin-inline-start: auto; }
.nav-links a, .footer-socials a { color: var(--secondary); font-size: .88rem; font-weight: 500; text-decoration: none; }
.nav-links a:hover, .footer-socials a:hover { color: var(--text); text-decoration: underline; }

.theme-toggle {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  place-items: center;
  width: 54px;
  height: 32px;
  padding: 0 3px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: var(--bg-input);
  color: var(--secondary);
}

.theme-toggle svg, .strip-toggle svg {
  z-index: 1;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle .thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text);
  transition: transform var(--motion);
}

.theme-toggle .sun { color: var(--bg); }
[data-theme="dark"] .theme-toggle .thumb { transform: translateX(22px); }
[data-theme="dark"] .theme-toggle .sun { color: inherit; }
[data-theme="dark"] .theme-toggle .moon { color: var(--bg); }

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(20px, 7vw, 96px);
  padding: clamp(40px, 8vw, 88px) 0 clamp(32px, 6vw, 64px);
}

.hero-copy { min-width: 0; }

.hero-badge {
  display: inline-block;
  margin-bottom: 14px;
  padding: 4px 13px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: var(--bg-card);
  color: var(--secondary);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}

h1 {
  width: fit-content;
  background: var(--hero-gradient);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  font-size: clamp(3.6rem, 10vw, 7.2rem);
  line-height: .98;
  letter-spacing: -.075em;
}

.handle {
  display: inline-block;
  margin-top: 10px;
  color: var(--muted);
  font-size: .94rem;
  text-decoration: none;
}

.handle:hover { text-decoration: underline; }
.hero-desc { max-width: 58ch; margin-top: 20px; color: var(--secondary); font-size: clamp(1rem, 1.5vw, 1.12rem); }
.hero-location { margin-block: 12px 20px; color: var(--muted); font-size: .88rem; }

.portrait {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  width: clamp(96px, 21vw, 208px);
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--muted);
  font-size: 2rem;
  font-weight: 700;
}

.portrait img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--bg-input); }
.links { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: .86rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color var(--motion), border-color var(--motion);
}

.button:hover { border-color: var(--border-hover); background: var(--bg-input); }
.button.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.button.primary:hover { text-decoration: underline; }
.button.small { min-height: 34px; font-size: .8rem; }

.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}

.github { --icon: url("https://cdn.jsdelivr.net/npm/simple-icons@v14/icons/github.svg"); }
.leetcode { --icon: url("https://cdn.jsdelivr.net/npm/simple-icons@v14/icons/leetcode.svg"); }
.icon.gitflic { display: none; }

.tech-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 57px;
  border-block: 1px solid var(--border);
}

.tech-viewport { min-width: 0; overflow: visible; }
.tech-track { display: flex; width: 100%; }

.tech-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px clamp(22px, 4vw, 44px);
  margin: 0;
  padding: 10px 0;
  list-style: none;
  color: var(--secondary);
  font-size: .86rem;
  font-weight: 500;
}

.tech-list li { flex: none; white-space: nowrap; }
.tech-list li:hover { color: var(--text); }
.tech-clone { display: none; }

.tech-strip.is-looping .tech-viewport {
  overflow: hidden;
  mask-image: linear-gradient(to right, transparent, black 14px, black calc(100% - 14px), transparent);
}

.tech-strip.is-looping .tech-track { width: max-content; animation: tech-loop var(--loop-time, 42s) linear infinite; }
.tech-strip.is-looping .tech-list { flex: none; flex-wrap: nowrap; padding-inline-end: clamp(22px, 4vw, 44px); }
.tech-strip.is-looping .tech-clone { display: flex; }
.tech-strip.is-looping.is-paused .tech-track,
.tech-strip.is-looping .tech-viewport:hover .tech-track { animation-play-state: paused; }

@keyframes tech-loop { to { transform: translateX(-50%); } }

.strip-toggle {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--secondary);
}

.strip-toggle:hover { background: var(--bg-input); }
.strip-toggle .play-icon, .is-paused .strip-toggle .pause-icon { display: none; }
.is-paused .strip-toggle .play-icon { display: block; }

.section { padding-block: clamp(40px, 7vw, 72px) 0; }
.section h2 { font-size: clamp(1.75rem, 4vw, 2.8rem); letter-spacing: -.04em; }
.section-desc { margin-top: 7px; color: var(--secondary); }
.skills-grid, .projects-grid { display: grid; gap: clamp(14px, 2vw, 24px); margin-top: 20px; }
.skills-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.projects-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  min-width: 0;
  padding: clamp(17px, 3vw, 30px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  transition: transform var(--motion), border-color var(--motion), box-shadow var(--motion);
}

.card h3 { font-size: 1.13rem; letter-spacing: -.02em; }
.card p { margin-top: 8px; color: var(--secondary); font-size: .94rem; }

@media (hover: hover) {
  .card:hover { transform: translateY(-3px); border-color: var(--border-hover); box-shadow: var(--shadow); }
}

.card:focus-within { border-color: var(--border-hover); }
.project-card { display: flex; flex-direction: column; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; padding: 0; list-style: none; }
.tags li { padding: 2px 8px; border-radius: 5px; background: var(--bg-input); color: var(--secondary); font-size: .74rem; }
.project-links { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.project-links .button { min-height: 36px; font-size: .79rem; }

.project-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(2, minmax(0, 11rem));
  gap: 10px;
  margin-top: 20px;
}

.project-tools label { display: grid; gap: 4px; min-width: 0; color: var(--secondary); font-size: .82rem; font-weight: 600; }

.project-tools input, .project-tools select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: .9rem;
}

.project-tools input::placeholder { color: var(--muted); opacity: 1; }
.project-count { margin-top: 8px; color: var(--muted); font-size: .8rem; }
.project-count:empty { display: none; }
.empty { margin-top: 20px; color: var(--muted); }

.ping {
  margin-top: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.ping summary { cursor: pointer; padding: 12px 16px; font-weight: 600; }
.ping summary span { margin-inline-start: 6px; color: var(--muted); font-size: .82rem; font-weight: 400; }
.ping-body { padding: 0 16px 16px; font-size: .88rem; }
.ping-button { min-width: 10rem; min-height: 54px; margin-block: 10px; }
.ping-button.is-ready { background: var(--text); color: var(--bg); border-color: var(--text); }
.ping-body p:empty { display: none; }

.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  margin-top: clamp(32px, 6vw, 64px);
  padding-block: 20px 24px;
  border-top: 1px solid var(--border);
}

.footer-socials { gap: 10px 18px; }
.footer-socials a { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; }
.copy-status { flex-basis: 100%; color: var(--muted); font-size: .8rem; }
.copy-status:empty { display: none; }

@keyframes reveal {
  from { opacity: .35; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: no-preference) {
  .hero-copy, .portrait { animation: reveal 600ms cubic-bezier(.22, 1, .36, 1) both; }
  .portrait { animation-delay: 90ms; }
  .has-entered { animation: reveal 500ms cubic-bezier(.22, 1, .36, 1) both; }
}

@media (max-width: 720px) {
  .skills-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .project-tools { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .project-tools label:first-child { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .hero { position: relative; display: block; }
  .hero-copy h1, .hero-copy .handle { max-width: calc(100% - 108px); overflow-wrap: anywhere; }
  .portrait { position: absolute; inset: clamp(40px, 8vw, 88px) 0 auto auto; }
  .skills-grid, .projects-grid { grid-template-columns: 1fr; }
  .footer { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 370px) {
  html { scroll-padding-top: 8rem; }
  .navbar .nav-links { order: 3; width: 100%; margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
