/* ---------- Tokens ---------- */
:root {
  --bg: #1D2027;
  --bg-panel: #262A33;
  --bg-panel-2: #2E333F;
  --text: #F2F3F5;
  --text-dim: #A7ABBB;
  --accent: #5B7FE0;
  --accent-2: #D9A94A;
  --line: rgba(242, 243, 245, 0.11);
  --line-strong: rgba(242, 243, 245, 0.22);

  --serif: "Fraunces", Georgia, serif;
  --sans: "Work Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --max-w: 1080px;
  --pad: clamp(1.25rem, 4vw, 3rem);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  /* clip (not hidden) so it doesn't become a scroll container and break position: sticky on the header */
  overflow-x: clip;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 400;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
  width: 100%;
}

/* subtle paper grain so the flat background isn't sterile */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* faint dot grid for a bit more texture/depth across the page */
.dot-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image: radial-gradient(rgba(242, 243, 245, 0.05) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: linear-gradient(to bottom, black, rgba(0,0,0,0.2) 60%, transparent 100%);
}

a { color: inherit; text-decoration: none; }

h1, h2, h3 { font-family: var(--serif); font-weight: 500; margin: 0; letter-spacing: -0.01em; }

img { max-width: 100%; display: block; }

/* ---------- Scroll progress ---------- */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--accent);
  z-index: 30;
  transition: width 0.1s linear;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 1rem var(--pad) 0;
  pointer-events: none;
}

.nav-pill {
  pointer-events: auto;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 0.6rem 0.6rem 0.6rem 1.1rem;
  background: rgba(38, 42, 51, 0.72);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.site-header.scrolled .nav-pill {
  background: rgba(38, 42, 51, 0.92);
  border-color: var(--line-strong);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.mark {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}

.nav-cta {
  flex-shrink: 0;
  font-size: 0.85rem;
  padding: 0.5rem 1.1rem;
  background: var(--accent);
  color: var(--bg);
  border-radius: 999px;
  transition: transform 0.2s ease, background 0.2s ease;
}

.nav-cta:hover,
.nav-cta:focus-visible {
  background: var(--accent-2);
}

/* Lights up while the contact section is in view */
.nav-cta.at-contact {
  background: var(--accent-2);
  color: var(--bg);
  box-shadow: 0 0 0 0 rgba(217, 169, 74, 0.55);
  animation: nav-cta-pulse 2s ease-out infinite;
}

@keyframes nav-cta-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(217, 169, 74, 0.55); }
  70%  { box-shadow: 0 0 0 12px rgba(217, 169, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(217, 169, 74, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .nav-cta.at-contact { animation: none; }
}

.site-nav {
  position: relative;
  display: flex;
  gap: clamp(1rem, 3vw, 2.25rem);
}

.nav-link {
  position: relative;
  font-size: 0.92rem;
  color: var(--text-dim);
  padding-bottom: 4px;
  transition: color 0.15s ease, transform 0.15s ease;
}

.nav-link:hover,
.nav-link:focus-visible,
.nav-link.active { color: var(--text); }

.nav-indicator {
  position: absolute;
  bottom: -1px;
  height: 1.5px;
  width: 0;
  background: var(--accent);
  transition: width 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

/* base state for JS-driven magnetic hover; transform is set inline via JS */
.magnetic {
  display: inline-block;
  will-change: transform;
  transition: transform 0.2s ease;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
}

.nav-toggle span {
  height: 1.5px;
  background: var(--text);
  width: 100%;
}

/* ---------- Hero ---------- */
.hero {
  position: relative;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: clamp(4rem, 12vw, 8rem) var(--pad) clamp(4.5rem, 10vw, 6.5rem);
  overflow: hidden;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: clamp(2rem, 6vw, 4rem);
  align-items: center;
}

@media (max-width: 900px) {
  .hero-grid { grid-template-columns: 1fr; }
  .code-card { max-width: 420px; }
}

.hero::before {
  content: "";
  position: absolute;
  top: -10%;
  left: 50%;
  width: min(900px, 100vw);
  height: 600px;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, rgba(91, 127, 224, 0.16), rgba(91, 127, 224, 0));
  pointer-events: none;
  z-index: -1;
}

.hero-eyebrow {
  display: flex;
  align-items: center;
  gap: 0.55em;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0 0 1rem;
}

.hero-eyebrow::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-2);
  flex-shrink: 0;
}

.hero-name-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.hero-name {
  font-size: clamp(2.75rem, 8vw, 5.25rem);
  line-height: 1.02;
  max-width: 14ch;
}

.name-underline {
  position: absolute;
  left: 0.03em;
  right: 0;
  bottom: -0.06em;
  width: calc(100% - 0.06em);
  height: 0.22em;
  overflow: visible;
}

.name-underline path {
  fill: none;
  stroke: var(--accent-2);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 480;
  stroke-dashoffset: 480;
  animation: drawUnderline 0.9s cubic-bezier(0.65, 0, 0.35, 1) forwards;
  animation-delay: 0.6s;
}

@keyframes drawUnderline {
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .name-underline path { animation: none; stroke-dashoffset: 0; }
}

.hero-desc {
  margin-top: 1.75rem;
  max-width: 46ch;
  font-size: 1.08rem;
  color: var(--text-dim);
}

.hero-meta {
  margin-top: 2.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  font-size: 0.88rem;
  color: var(--text-dim);
  border-top: 1px solid var(--line);
  padding-top: 1.25rem;
}

/* gentle bouncing prompt inviting the visitor to keep scrolling */
.scroll-hint {
  position: absolute;
  left: var(--pad);
  bottom: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  transition: color 0.2s ease;
}

.scroll-hint:hover,
.scroll-hint:focus-visible { color: var(--accent-2); }

.scroll-hint svg {
  animation: scrollBounce 1.8s ease-in-out infinite;
}

@keyframes scrollBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(5px); }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-hint svg { animation: none; }
}

@media (max-width: 900px) {
  .scroll-hint { display: none; }
}

/* one orchestrated entrance for the hero on load — each line staggers in */
.reveal-item {
  opacity: 0;
  transform: translateY(14px);
  animation: revealUp 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.hero-eyebrow.reveal-item   { animation-delay: 0.05s; }
.hero-name-wrap.reveal-item { animation-delay: 0.15s; }
.hero-desc.reveal-item      { animation-delay: 0.32s; }
.hero-meta.reveal-item      { animation-delay: 0.48s; }
.code-card.reveal-item      { animation-delay: 0.55s; }

@keyframes revealUp {
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .reveal-item { animation: none; opacity: 1; transform: none; }
}

/* ---------- Hero code card ---------- */
.code-card {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
  width: 100%;
}

.code-card-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel-2);
}

.code-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  opacity: 0.85;
}

.code-dot.red { background: #E0685B; }
.code-dot.amber { background: #E0B75B; }
.code-dot.green { background: #6FCF97; }

.code-card-label {
  margin-left: 0.5rem;
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.code-card pre {
  margin: 0;
  padding: 1.25rem 1.35rem 1.4rem;
  font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
  font-size: clamp(0.78rem, 1.6vw, 0.88rem);
  line-height: 1.75;
  overflow-x: auto;
}

.code-card .tok-kw    { color: var(--accent); }
.code-card .tok-str   { color: var(--accent-2); }
.code-card .tok-prop  { color: var(--text-dim); }
.code-card .tok-punc  { color: var(--text-dim); opacity: 0.6; }
.code-card .tok-plain { color: var(--text); }

.code-cursor {
  display: inline-block;
  width: 7px;
  height: 1em;
  background: var(--accent-2);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: cursorBlink 1s step-end infinite;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .code-cursor { animation: none; }
}

/* ---------- Scroll-triggered fade-in ---------- */
.fade-in {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.fade-in.in-view {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .fade-in { opacity: 1; transform: none; transition: none; }
}

/* ---------- Section shared ---------- */
.section-head {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--pad);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.section-head h2 {
  font-size: clamp(1.5rem, 3vw, 2rem);
}

/* ---------- Quick stats ---------- */
.stats {
  background: var(--bg-panel);
  border-top: 2px solid var(--accent-2);
  border-bottom: 1px solid var(--line);
}

.stats-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 2.25rem) var(--pad);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0 1.25rem;
  border-left: 1px solid var(--line);
}

.stat:first-child { border-left: none; padding-left: 0; }

.stat-num {
  font-family: var(--serif);
  font-size: clamp(1.5rem, 3vw, 2.1rem);
  color: var(--accent-2);
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* ---------- Skills ---------- */
.skills {
  padding: clamp(2.5rem, 6vw, 4rem) 0;
  border-top: 2px solid var(--accent);
}

.skills-list {
  max-width: var(--max-w);
  margin: 1.75rem auto 0;
  padding: 0 var(--pad);
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 0.9rem;
}

.skills-list li {
  font-family: var(--serif);
  font-size: 1.15rem;
  color: var(--text);
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  transition: border-color 0.18s ease, color 0.18s ease;
}

.skills-list li:hover {
  border-color: var(--accent-2);
  color: var(--accent-2);
}

.skills-note {
  max-width: var(--max-w);
  margin: 1.5rem auto 0;
  padding: 0 var(--pad);
  font-size: 0.82rem;
  color: var(--text-dim);
}

.skills-note code {
  font-family: monospace;
  background: var(--bg-panel);
  padding: 0.1rem 0.4rem;
  border-radius: 2px;
}

/* ---------- Work / Projects ---------- */
.work {
  background: var(--bg-panel);
  padding: clamp(2.5rem, 6vw, 4rem) 0 clamp(3rem, 8vw, 5rem);
  border-top: 2px solid var(--accent-2);
}

.project {
  max-width: var(--max-w);
  margin: clamp(2.5rem, 6vw, 4rem) auto 0;
  padding: 0 var(--pad);
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: center;
}

/* Reversed rows swap which side the image sits on. The order values below
   change *visual* placement, but CSS Grid also uses order for auto-placement,
   which was shrinking the image into the narrower track. Swapping the track
   sizes here keeps the image column wide (1.5fr) no matter which side it's on. */
.project.reverse { grid-template-columns: 1fr 1.5fr; }
.project.reverse .project-media { order: 2; }
.project.reverse .project-info { order: 1; }

.project-media {
  position: relative;
  perspective: 900px;
}

/* Offset accent panel peeking out behind the frame */
.project-media::before {
  content: "";
  position: absolute;
  inset: 0;
  transform: translate(14px, 14px);
  border-radius: 10px;
  border: 1px solid var(--accent-2);
  opacity: 0.4;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease;
  pointer-events: none;
}

.project.reverse .project-media::before {
  transform: translate(-14px, 14px);
}

.project-media:hover::before {
  transform: translate(0, 0);
  opacity: 0.7;
}

.media-frame {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--bg-panel-2);
  padding: 8px;
  cursor: pointer;
  transform-style: preserve-3d;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.25s ease, box-shadow 0.25s ease;
}

.media-frame:hover {
  border-color: var(--accent-2);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.45);
}

.media-frame img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 5px;
  transition: transform 0.5s ease;
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  .media-frame { transition: none; transform: none !important; }
}

.media-play {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(242, 243, 245, 0.35);
  background: rgba(29, 32, 39, 0.75);
  backdrop-filter: blur(2px);
  color: var(--text);
  cursor: pointer;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.85);
  transition: opacity 0.25s ease, transform 0.25s ease, background 0.25s ease, border-color 0.25s ease;
}

.media-play svg { margin-left: 3px; }

.media-frame[data-video]:hover .media-play,
.media-frame[data-video]:focus-within .media-play {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Touch devices have no hover state, so keep the play button visible */
@media (hover: none) {
  .media-play {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.media-play:hover,
.media-play:focus-visible {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: var(--bg);
}

/* ---------- Video lightbox ---------- */
.video-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 5vw, 3rem);
  background: rgba(10, 11, 14, 0.9);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease;
  cursor: pointer;
}

.video-lightbox.open {
  opacity: 1;
  visibility: visible;
}

.video-lightbox video {
  display: block;
  margin: auto;
  max-width: min(960px, 100%);
  max-height: 80vh;
  max-height: 80dvh;
  border-radius: 10px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.video-lightbox-close {
  position: absolute;
  top: clamp(1rem, 4vw, 2rem);
  right: clamp(1rem, 4vw, 2rem);
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(242, 243, 245, 0.3);
  background: rgba(38, 42, 51, 0.85);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.video-lightbox-close:hover,
.video-lightbox-close:focus-visible {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: var(--bg);
}

.project-info h3 {
  font-size: clamp(1.4rem, 2.5vw, 1.9rem);
}

.project-tags {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: var(--accent-2);
}

.project-desc {
  margin-top: 1rem;
  color: var(--text-dim);
  max-width: 42ch;
}

.project-link {
  display: inline-block;
  margin-top: 1.1rem;
  font-size: 0.92rem;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--line-strong);
  transition: border-color 0.15s ease, color 0.15s ease;
}

.project-link:hover,
.project-link:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
}

.project-stack {
  margin-top: 1.1rem;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text-dim);
}

.project-stack + .project-link {
  margin-top: 0.9rem;
}

/* ---------- Contact ---------- */
.contact {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: clamp(3rem, 8vw, 5rem) var(--pad);
  border-top: 2px solid var(--accent);
  text-align: left;
}

.contact h2 { font-size: clamp(2rem, 5vw, 3rem); }

.contact p {
  color: var(--text-dim);
  margin-top: 0.75rem;
}

.contact-email {
  display: inline-block;
  margin-top: 1.5rem;
  font-family: var(--serif);
  font-size: clamp(1.3rem, 3vw, 1.8rem);
  border-bottom: 1px solid var(--line-strong);
}

.contact-email:hover { color: var(--accent); border-color: var(--accent); }

.contact-links {
  margin-top: 2rem;
  display: flex;
  gap: 1.75rem;
  flex-wrap: wrap;
}

.contact-links a { color: var(--text-dim); font-size: 0.92rem; }
.contact-links a:hover { color: var(--text); }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--bg-panel);
  padding: 1.5rem var(--pad) 2.5rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ---------- Back to top ---------- */
.to-top {
  position: fixed;
  right: clamp(1rem, 4vw, 2rem);
  bottom: clamp(1rem, 4vw, 2rem);
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease, background 0.2s ease, border-color 0.2s ease;
  z-index: 15;
}

.to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.to-top:hover,
.to-top:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .project,
  .project.reverse {
    grid-template-columns: 1fr;
  }

  .project.reverse .project-media,
  .project.reverse .project-info,
  .project-media,
  .project-info { order: initial; }
}

@media (max-width: 640px) {
  .nav-toggle { display: flex; }
  .nav-cta { display: none; }

  .site-nav {
    position: fixed;
    top: 76px;
    left: var(--pad);
    right: var(--pad);
    background: var(--bg-panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    flex-direction: column;
    padding: 1rem 1.25rem 1.25rem;
    gap: 1rem;
    transform: translateY(-8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  }

  .site-nav.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  .nav-indicator { display: none; }

  .stats-inner {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem 0;
  }

  .stat:nth-child(2n+1) { border-left: none; padding-left: 0; }
}