/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #2563eb;
  --blue-light: #eff6ff;
  --blue-mid: #3b82f6;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #ffffff;
  --section-alt: #f8fafc;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

/* NAV */
nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--blue);
}

nav ul {
  list-style: none;
  display: flex;
  gap: 2rem;
}

nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
  transition: color 0.2s;
}

nav a:hover { color: var(--blue); }

/* Projects dropdown */
.nav-dropdown { position: relative; }

.nav-dropdown > a::after {
  content: '▾';
  margin-left: 0.3rem;
  font-size: 0.7rem;
  vertical-align: middle;
}

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 0.6rem);
  left: 50%;
  min-width: 240px;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.4rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}

/* Bridges the gap under the trigger so the menu survives the mouse crossing it */
.nav-dropdown-menu::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -0.6rem;
  height: 0.6rem;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.nav-dropdown-menu a {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  color: var(--text);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.nav-dropdown-menu a:hover {
  background: var(--blue-light);
  color: var(--blue);
}

/* HERO */
#hero {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6rem 2rem 4rem;
  position: relative;
  overflow: hidden;
}

.hero-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #0a0f1e;
}

.hero-bg-layer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  border: none;
}

/* Robotic arm GIF — crop biased upward so the whole arm shows */
#bg-arm {
  object-position: center 25%;
  animation: fadeArm 25s infinite;
}

/* Maze YouTube Short (9:16) — fill full width so no side bars */
#bg-maze {
  width: 100vw;
  height: calc(100vw * 16 / 9);
  min-height: 100vh;
  object-fit: cover;
  animation: fadeMaze 25s infinite;
}

#bg-vid {
  object-position: center;
  animation: fadeVid 25s infinite;
}

#bg-micro {
  object-position: center;
  animation: fadeMicro 25s infinite;
}

#bg-pcb {
  object-position: center;
  animation: fadePcb 25s infinite;
}

/* 25s cycle:  arm 0-4s | maze 4-11s | video 11-17s | micro 17-21s | pcb 21-25s */
@keyframes fadeArm {
  0%   { opacity: 1; }
  16% { opacity: 1; }
  20% { opacity: 0; }
  96% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes fadeMaze {
  0%   { opacity: 0; }
  12% { opacity: 0; }
  16% { opacity: 1; }
  44% { opacity: 1; }
  48% { opacity: 0; }
  100% { opacity: 0; }
}

@keyframes fadeVid {
  0%   { opacity: 0; }
  40% { opacity: 0; }
  44% { opacity: 1; }
  68% { opacity: 1; }
  72% { opacity: 0; }
  100% { opacity: 0; }
}

@keyframes fadeMicro {
  0%   { opacity: 0; }
  64% { opacity: 0; }
  68% { opacity: 1; }
  84% { opacity: 1; }
  88% { opacity: 0; }
  100% { opacity: 0; }
}

@keyframes fadePcb {
  0%   { opacity: 0; }
  80% { opacity: 0; }
  84% { opacity: 1; }
  96% { opacity: 1; }
  100% { opacity: 0; }
}

.hero-overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 28, 0.6);
  z-index: 1;
}

.hero-content {
  position: relative;
  z-index: 2;
}

.hero-greeting {
  font-size: 1.1rem;
  color: #93c5fd;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

#hero h1 {
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  font-weight: 700;
  letter-spacing: -1px;
  margin-bottom: 0.75rem;
  color: #ffffff;
}

.hero-sub {
  font-size: 1.25rem;
  color: #cbd5e1;
  margin-bottom: 2rem;
}

.hero-btns {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* BUTTONS */
.btn {
  display: inline-block;
  background: var(--blue);
  color: #fff;
  padding: 0.75rem 2rem;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.2s, transform 0.15s;
}

.btn:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--blue);
  border: 2px solid var(--blue);
}

.btn-outline:hover {
  background: var(--blue-light);
  transform: translateY(-1px);
}

/* Blue-on-dark fails contrast over the hero, so outline buttons go white there */
#hero .btn-outline {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.7);
}

#hero .btn-outline:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: #fff;
}

/* SECTIONS */
section { padding: 5rem 2rem; }
#about { background: var(--section-alt); }
#projects { background: var(--bg); }
#contact { background: var(--blue-light); }

.container {
  max-width: 1100px;
  margin: 0 auto;
}

h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

h2::after {
  content: '';
  display: block;
  width: 48px;
  height: 4px;
  background: var(--blue);
  border-radius: 2px;
  margin-top: 0.5rem;
  margin-bottom: 2rem;
}

.section-sub {
  color: var(--muted);
  margin-top: -1.5rem;
  margin-bottom: 2.5rem;
}

/* ABOUT */
.about-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 3.5rem;
  align-items: start;
}

.about-photo {
  width: 100%;
  max-height: 280px;
  border-radius: 16px;
  object-fit: cover;
  object-position: center top;
  box-shadow: 0 8px 30px rgba(37,99,235,0.12);
  border: 3px solid var(--border);
}

.about-right {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.about-text p {
  color: var(--muted);
  margin-bottom: 1rem;
  font-size: 1.05rem;
}

.about-skills h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.skills-list {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.skills-list li {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  color: var(--text);
}

/* PROJECTS */
/* 480px floor gives 2 columns at the 1100px container, so four cards land
   as a balanced 2x2 instead of 3 + 1 stranded */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
  gap: 1.5rem;
}

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
}

.card:hover {
  box-shadow: 0 8px 30px rgba(37,99,235,0.1);
  transform: translateY(-3px);
  border-color: #cbd5e1;
}

/* Card image — CAD renders sit on white, so contain rather than crop */
.card-media {
  background: var(--section-alt);
  border-bottom: 1px solid var(--border);
  aspect-ratio: 16 / 10;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 0.75rem;
  transition: transform 0.3s ease;
}

.card:hover .card-media img { transform: scale(1.03); }

.card-media-empty {
  color: var(--muted);
  font-size: 0.85rem;
  background: linear-gradient(135deg, var(--blue-light), var(--section-alt));
}

.card-body {
  padding: 1.5rem 1.75rem 1.75rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* Cards with no photo yet — centred text rather than an empty frame */
.card-no-media .card-body { justify-content: center; }

.card-tag {
  display: inline-block;
  background: var(--blue-light);
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.card p {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}

.card-details {
  list-style: none;
  margin: 0.5rem 0 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.card-details li {
  font-size: 0.88rem;
  color: var(--muted);
  padding-left: 1rem;
  position: relative;
}

.card-details li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--blue);
  font-size: 0.8rem;
}

.card-link {
  display: inline-block;
  margin-top: auto;
  padding-top: 1rem;
  color: var(--blue);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: opacity 0.2s;
}

.card-link:hover { opacity: 0.7; }

.second-heading {
  margin-top: 4rem;
}

/* CONTACT */
.contact-inner {
  text-align: center;
  max-width: 600px;
}

#contact h2::after { margin: 0.5rem auto 2rem; }

#contact p {
  color: var(--muted);
  margin-bottom: 2rem;
  font-size: 1.05rem;
}

.social-links {
  margin-top: 1.5rem;
  display: flex;
  gap: 1.5rem;
  justify-content: center;
}

.social-links a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: opacity 0.2s;
}

.social-links a:hover { opacity: 0.7; }

/* FOOTER */
footer {
  text-align: center;
  padding: 1.5rem;
  background: var(--text);
  color: #94a3b8;
  font-size: 0.85rem;
}

/* PROJECT DETAIL PAGES */
.project-main {
  padding: 8rem 2rem 5rem;
}

.project-main .container { max-width: 820px; }

.back-link {
  display: block;
  width: fit-content;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 1.5rem;
  transition: color 0.2s;
}

.back-link:hover { color: var(--blue); }

.project-tag {
  display: inline-block;
  background: var(--blue-light);
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.project-main h1 {
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 0.75rem;
}

.project-lead {
  font-size: 1.15rem;
  color: var(--muted);
  margin-bottom: 2rem;
}

.project-hero {
  background: var(--section-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.project-hero img {
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  padding: 1rem;
}

.project-content h2 {
  font-size: 1.35rem;
  margin-top: 2.5rem;
}

.project-content h2:first-child { margin-top: 0; }

.project-content h2::after {
  width: 36px;
  height: 3px;
  margin-bottom: 1.25rem;
}

.project-content p {
  color: var(--muted);
  margin-bottom: 1rem;
  font-size: 1.02rem;
}

.project-content .card-details li { font-size: 0.98rem; }

/* Secondary images on a project page */
.project-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin: 2rem 0 0.5rem;
}

.project-gallery figure {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--section-alt);
}

.project-gallery img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  padding: 0.75rem;
  display: block;
  transition: transform 0.25s ease;
}

/* Diagrams are dense — clicking opens the original at full size */
.gallery-zoom {
  display: block;
  cursor: zoom-in;
}

.gallery-zoom:hover img { transform: scale(1.04); }

.project-gallery figcaption {
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 0.7rem 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.project-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

/* Nav: mark the project page you're currently on */
.nav-dropdown-menu a[aria-current="page"] {
  background: var(--blue-light);
  color: var(--blue);
  font-weight: 600;
}

/* REDUCED MOTION
   The hero cycles five backgrounds on a 25s loop with autoplaying video.
   For anyone who has asked the OS to limit motion, hold on a single still. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  .hero-bg-layer {
    animation: none !important;
    opacity: 0;
  }

  #bg-micro { opacity: 1; }

  #bg-maze { display: none; }

  .card,
  .card-media img,
  .project-gallery img,
  .btn {
    transition: none !important;
  }

  .card:hover,
  .btn:hover {
    transform: none;
  }

  .card:hover .card-media img,
  .gallery-zoom:hover img {
    transform: none;
  }
}

/* RESPONSIVE */
@media (max-width: 800px) {
  .about-grid { grid-template-columns: 1fr; gap: 2rem; }
  .about-photo { width: 160px; }
  .skills-list { grid-template-columns: 1fr; }
  nav ul { gap: 1rem; }
  .project-main { padding: 6.5rem 1.25rem 3.5rem; }
  /* No hover on touch — Projects stays a plain link to the card grid */
  .nav-dropdown-menu { display: none; }
  .nav-dropdown > a::after { content: none; }
}
