:root {
  --bg: #0a0a0b;
  --bg-2: #111113;
  --surface: #17171a;
  --text: #f0f0f2;
  --text-soft: #c8c8d0;
  --muted: #8a8a92;
  --border: #26262c;
  --accent: #ff1744;
  --accent-soft: #ff4d6d;
  --accent-dim: rgba(255, 23, 68, 0.14);

  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --display: 'Space Grotesk', var(--sans);

  --max: 1200px;
  --pad: clamp(1.25rem, 4vw, 2.5rem);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 300;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

::selection { background: var(--accent); color: var(--bg); }

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

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

.container {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 var(--pad);
}

/* ============ NAV ============ */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  padding: 1.25rem var(--pad);
  padding-top: max(1.25rem, env(safe-area-inset-top));
  padding-left: max(var(--pad), env(safe-area-inset-left));
  padding-right: max(var(--pad), env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.3s ease, border-color 0.3s ease;
  border-bottom: 1px solid transparent;
}
.nav.scrolled {
  background: rgba(10, 10, 11, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom-color: var(--border);
}
.nav-logo {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--text);
}
.nav-logo:hover { color: var(--accent); }
.nav-links {
  display: flex;
  gap: 2rem;
  list-style: none;
  font-family: var(--mono);
  font-size: 0.85rem;
}
.nav-links a {
  position: relative;
  padding: 0.25rem 0;
  color: var(--muted);
  transition: color 0.2s ease;
}
.nav-links a:hover { color: var(--text); }
.nav-links a::after {
  content: '';
  position: absolute;
  left: 0; bottom: -2px;
  width: 0; height: 1px;
  background: var(--accent);
  transition: width 0.35s ease;
}
.nav-links a:hover::after { width: 100%; }

@media (max-width: 640px) {
  .nav-links { gap: 1rem; font-size: 0.72rem; }
  .nav { padding: 1rem var(--pad); padding-top: max(1rem, env(safe-area-inset-top)); }
  .nav-logo { font-size: 1rem; }
}
@media (max-width: 440px) {
  .nav-links { gap: 0.7rem; font-size: 0.65rem; }
  .nav-logo { font-size: 0.95rem; }
}

/* ============ HERO ============ */
.hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding: 0 var(--pad);
  overflow: hidden;
  background: radial-gradient(ellipse at 75% 40%, rgba(255, 23, 68, 0.09), transparent 55%), var(--bg);
}
#hero-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 0.85;
}
.hero-wrap {
  position: relative;
  z-index: 1;
  max-width: var(--max);
  margin: 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  gap: 4rem;
  align-items: center;
  pointer-events: none;
}
.hero-wrap > * { pointer-events: auto; }
.hero-content { min-width: 0; }

/* Portrait frame */
.hero-portrait {
  opacity: 0;
  animation: fadeInUp 1.1s 0.9s forwards cubic-bezier(.16,.68,.43,.99);
}
.portrait-frame {
  position: relative;
  aspect-ratio: 3 / 4;
  background:
    linear-gradient(135deg, #17171b 0%, #0d0d11 100%);
  border: 1px solid var(--border);
  overflow: hidden;
  isolation: isolate;
}
.portrait-frame::before {
  content: 'PORTRAIT\A HMKG · Band & Drill Team';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  padding: 1rem;
  white-space: pre-line;
  letter-spacing: 0.14em;
  line-height: 1.8;
  z-index: 0;
}
.portrait-frame:has(img)::before { display: none; }
.portrait-frame img {
  position: relative;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  z-index: 1;
  filter: contrast(1.02) saturate(0.92);
}
.frame-corner {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  z-index: 2;
  pointer-events: none;
}
.frame-corner.tl { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.frame-corner.tr { top: -1px; right: -1px; border-left: 0; border-bottom: 0; }
.frame-corner.bl { bottom: -1px; left: -1px; border-right: 0; border-top: 0; }
.frame-corner.br { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }

.hero-portrait figcaption {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.85rem;
  text-align: right;
  letter-spacing: 0.08em;
}
.hero-portrait figcaption .cap-accent { color: var(--accent); }

@media (max-width: 900px) {
  .hero-wrap { grid-template-columns: 1fr; gap: 2.5rem; }
  .hero-portrait { max-width: 260px; margin: 0 auto; width: 100%; }
  .hero-portrait figcaption { text-align: center; }
}
@media (max-width: 440px) {
  .hero { min-height: 100svh; align-items: flex-start; padding-top: 6rem; }
  .hero-portrait { max-width: 220px; }
  .hero-cta { gap: 0.6rem; }
  .btn { padding: 0.8rem 1.2rem; font-size: 0.82rem; }
  .hero-scroll { display: none; }
}

.hero-label {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1.75rem;
  opacity: 0;
  animation: fadeInUp 0.9s 0.1s forwards cubic-bezier(.16,.68,.43,.99);
}
.hero-label::before {
  content: '▸ ';
  color: var(--accent);
}

.hero-title {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(2rem, 7vw, 5.5rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
  margin-bottom: 2rem;
  opacity: 0;
  animation: fadeInUp 1s 0.3s forwards cubic-bezier(.16,.68,.43,.99);
  word-break: break-word;
}
.accent {
  color: var(--accent);
  font-style: italic;
  font-weight: 400;
}

.hero-sub {
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  color: var(--text-soft);
  max-width: 640px;
  margin-bottom: 2.5rem;
  opacity: 0;
  animation: fadeInUp 0.9s 0.5s forwards cubic-bezier(.16,.68,.43,.99);
}
.hero-sub strong { color: var(--text); font-weight: 500; }

.hero-cta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  opacity: 0;
  animation: fadeInUp 0.9s 0.7s forwards cubic-bezier(.16,.68,.43,.99);
}
.btn {
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.95rem 1.6rem;
  border: 1px solid transparent;
  transition: all 0.25s ease;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5ch;
}
.btn-primary {
  background: var(--accent);
  color: var(--bg);
  font-weight: 500;
}
.btn-primary:hover {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-2px);
}
.btn-ghost {
  border-color: var(--border);
  color: var(--text);
  background: transparent;
}
.btn-ghost:hover {
  border-color: var(--text);
  transform: translateY(-2px);
}

.hero-scroll {
  position: absolute;
  bottom: 2rem;
  right: var(--pad);
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  writing-mode: vertical-rl;
  animation: drift 2.4s ease-in-out infinite;
  letter-spacing: 0.1em;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes drift {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50%      { transform: translateY(8px); opacity: 1; }
}

/* ============ SECTIONS ============ */
.section {
  padding: clamp(5rem, 13vh, 9rem) 0;
  border-top: 1px solid var(--border);
  position: relative;
}

.section-label {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 1rem;
  letter-spacing: 0.05em;
}
.section-title {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1.1;
  letter-spacing: -0.025em;
  margin-bottom: 3.5rem;
  max-width: 900px;
}

/* ============ ABOUT ============ */
.about-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 4rem;
  align-items: start;
}
.about-text p {
  font-size: 1.1rem;
  color: var(--text-soft);
  margin-bottom: 1.25rem;
  max-width: 62ch;
}
.about-text strong { color: var(--text); font-weight: 500; }

.about-stats {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  border-left: 1px solid var(--border);
  padding-left: 2rem;
}
.stat-num {
  display: block;
  font-family: var(--display);
  font-weight: 500;
  font-size: 3.2rem;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 0.4rem;
}
.stat-lbl {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}
.stat-lbl em { color: var(--text); font-style: normal; }

@media (max-width: 860px) {
  .about-grid { grid-template-columns: 1fr; gap: 2.5rem; }
  .about-stats {
    border-left: none;
    border-top: 1px solid var(--border);
    padding-left: 0;
    padding-top: 2rem;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 2rem 3rem;
  }
  .stat-num { font-size: 2.5rem; }
}

/* ============ TIMELINE ============ */
.timeline { display: flex; flex-direction: column; }

.tl-item {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 3rem;
  padding: 2rem 0;
  border-top: 1px solid var(--border);
  transition: padding 0.35s ease, background 0.35s ease;
  position: relative;
}
.tl-item:last-child { border-bottom: 1px solid var(--border); }
.tl-item:hover {
  padding-left: 1rem;
  background: linear-gradient(90deg, var(--accent-dim), transparent 40%);
}
.tl-date {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  padding-top: 0.5rem;
}
.tl-body h3 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.55rem;
  margin-bottom: 0.3rem;
  letter-spacing: -0.015em;
}
.tl-role {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 0.85rem !important;
}
.tl-body p:last-child {
  color: var(--text-soft);
  max-width: 65ch;
  margin-bottom: 0;
}
.tl-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.2rem 0.55rem;
  background: var(--accent);
  color: var(--bg);
  margin-bottom: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
}
.tl-featured .tl-body h3 { color: var(--text); }

.tl-body h3 a {
  color: inherit;
  transition: color 0.2s ease;
  border-bottom: 1px solid transparent;
}
.tl-body h3 a:hover { color: var(--accent); }
.ext {
  font-size: 0.75em;
  color: var(--muted);
  display: inline-block;
  transition: transform 0.25s ease, color 0.25s ease;
  margin-left: 0.2em;
}
.tl-body h3 a:hover .ext { color: var(--accent); transform: translate(2px, -2px); }

.tl-bullets {
  list-style: none;
  margin-top: 1rem;
  max-width: 65ch;
}
.tl-bullets li {
  position: relative;
  padding-left: 1.25rem;
  margin-bottom: 0.6rem;
  color: var(--text-soft);
  font-size: 0.95rem;
}
.tl-bullets li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--accent);
}
.tl-bullets code {
  font-family: var(--mono);
  font-size: 0.85em;
  color: var(--text);
  background: var(--surface);
  padding: 0.1em 0.4em;
  border: 1px solid var(--border);
  border-radius: 2px;
}

@media (max-width: 640px) {
  .tl-item { grid-template-columns: 1fr; gap: 0.5rem; }
  .tl-item:hover { padding-left: 0.5rem; }
}

/* ============ PROJECTS ============ */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr));
  gap: 1.5rem;
}
.project {
  padding: 2rem;
  border: 1px solid var(--border);
  background: var(--bg-2);
  transition: transform 0.4s cubic-bezier(.16,.68,.43,.99), border-color 0.3s ease, box-shadow 0.3s ease;
  position: relative;
  overflow: hidden;
  will-change: transform;
}
.project::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(400px circle at var(--mx, 50%) var(--my, 50%), rgba(255, 23, 68, 0.12), transparent 40%);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.project::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 0; height: 2px;
  background: var(--accent);
  transition: width 0.5s ease;
}
.project:hover {
  border-color: #3a3a42;
  box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.5);
}
.project:hover::before { opacity: 1; }
.project:hover::after  { width: 100%; }

.project-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  font-family: var(--mono);
  font-size: 0.78rem;
}
.project-num { color: var(--accent); font-weight: 500; }
.project-tags { color: var(--muted); text-align: right; }

.project h3 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.4rem;
  margin-bottom: 0.85rem;
  letter-spacing: -0.015em;
  position: relative;
  z-index: 1;
}
.project p {
  color: var(--text-soft);
  font-size: 0.95rem;
  margin-bottom: 1rem;
  position: relative;
  z-index: 1;
}
.project-role {
  font-family: var(--mono);
  font-size: 0.75rem !important;
  color: var(--muted) !important;
  margin: 1rem 0 0 !important;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ============ LAB / SELF-HOSTED ============ */
.lab-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4rem;
  align-items: start;
}
.lab-text p {
  font-size: 1.1rem;
  color: var(--text-soft);
  margin-bottom: 1.25rem;
  max-width: 55ch;
}
.lab-stack {
  border: 1px solid var(--border);
  background: var(--bg-2);
  padding: 1.5rem 1.75rem;
  font-family: var(--mono);
  position: relative;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.lab-stack:hover {
  border-color: #3a3a42;
  box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.6);
}
.lab-stack-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1rem;
  border-bottom: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}
.lab-stack-badge {
  color: var(--accent);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
}
.lab-stack-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 1rem;
  padding: 0.7rem 0;
  align-items: baseline;
}
.lab-stack-row + .lab-stack-row {
  border-top: 1px solid var(--border);
}
.lab-stack-key {
  color: var(--accent);
  font-weight: 500;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
}
.lab-stack-val {
  color: var(--text-soft);
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 300;
}

@media (max-width: 860px) {
  .lab-grid { grid-template-columns: 1fr; gap: 2.5rem; }
  .lab-stack-row { grid-template-columns: 110px 1fr; }
}

/* ============ CONTACT ============ */
.contact-lead {
  font-size: 1.15rem;
  color: var(--text-soft);
  max-width: 60ch;
  margin-bottom: 3rem;
}
.contact-links { display: flex; flex-direction: column; }
.contact-link {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 2rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
  align-items: baseline;
  transition: padding-left 0.3s ease, color 0.3s ease;
}
.contact-link:last-child { border-bottom: 1px solid var(--border); }
.contact-link:hover { padding-left: 1rem; color: var(--accent); }
.contact-lbl {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
}
.contact-link:hover .contact-lbl { color: var(--accent); }
.contact-val {
  font-family: var(--display);
  font-size: clamp(1rem, 2vw, 1.5rem);
  font-weight: 500;
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.contact-link { -webkit-user-drag: none; }
.contact-val .arr {
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}
.arr {
  display: inline-block;
  transition: transform 0.3s ease;
}
.contact-link:hover .arr { transform: translate(4px, -4px); }

@media (max-width: 640px) {
  .contact-link { grid-template-columns: 1fr; gap: 0.25rem; }
}

/* ============ FOOTER ============ */
.footer {
  padding: 2rem 0;
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}
.footer a { color: var(--muted); transition: color 0.2s; }
.footer a:hover { color: var(--accent); }

/* ============ REVEAL ANIMATIONS ============ */
.reveal {
  opacity: 0;
  transform: translateY(32px);
  transition: opacity 0.9s cubic-bezier(.16,.68,.43,.99), transform 0.9s cubic-bezier(.16,.68,.43,.99);
}
.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}
/* staggered reveal for grid children */
.reveal-stagger > * {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}
.reveal-stagger.visible > * {
  opacity: 1;
  transform: translateY(0);
}
.reveal-stagger.visible > *:nth-child(1) { transition-delay: 0.05s; }
.reveal-stagger.visible > *:nth-child(2) { transition-delay: 0.15s; }
.reveal-stagger.visible > *:nth-child(3) { transition-delay: 0.25s; }
.reveal-stagger.visible > *:nth-child(4) { transition-delay: 0.35s; }
.reveal-stagger.visible > *:nth-child(5) { transition-delay: 0.45s; }
.reveal-stagger.visible > *:nth-child(6) { transition-delay: 0.55s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
