/* Register a custom property to demonstrate @property (Baseline 2024) */
@property --brand-hue {
  syntax: "<number>";
  inherits: true;
  initial-value: 210; /* cool blue */
}

:root {
  color-scheme: light dark; /* Baseline 2024: pairs with light-dark() */

  /* Theme tokens */
  --brand-hue: 210; /* fallback initial value; also registered above */
  --radius: 0.75rem;
  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2rem;
  --shadow-soft: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.06);

  /* Font stacks */
  --font-sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-serif: "Georgia", "Times New Roman", serif;
  --font-mono: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --font-body: var(--font-sans);

  /* Colors using light-dark() as a baseline; JS may override these via custom themes */
  --surface: light-dark(hsl(var(--brand-hue) 30% 99%), hsl(var(--brand-hue) 20% 8%));
  --surface-2: light-dark(hsl(var(--brand-hue) 30% 97%), hsl(var(--brand-hue) 20% 12%));
  --text: light-dark(hsl(var(--brand-hue) 30% 10%), hsl(var(--brand-hue) 30% 90%));
  --muted: light-dark(hsl(var(--brand-hue) 20% 40% / 0.6), hsl(var(--brand-hue) 25% 80% / 0.6));
  --accent: hsl(var(--brand-hue) 90% 55%);
}

/* Explicit theme overrides controlled by JS via data-theme */
:root[data-theme="light"] {
  color-scheme: light;
  --surface: hsl(var(--brand-hue) 30% 99%);
  --surface-2: hsl(var(--brand-hue) 30% 97%);
  --text: hsl(var(--brand-hue) 30% 10%);
  --muted: hsl(var(--brand-hue) 20% 40% / 0.6);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: hsl(var(--brand-hue) 20% 8%);
  --surface-2: hsl(var(--brand-hue) 20% 12%);
  --text: hsl(var(--brand-hue) 30% 90%);
  --muted: hsl(var(--brand-hue) 25% 80% / 0.6);
}

/* Wider gamut accent (extra credit). Browsers will fall back to sRGB if needed. */
@supports (color: color(display-p3 0.2 0.55 1)) {
  :root { --accent: color(display-p3 0.2 0.55 1); /* vivid cool blue */ }
}

/* Base elements */
html {
  font-family: var(--font-body);
  font-size: clamp(16px, 1.2vw + 0.5rem, 18px);
  line-height: 1.6;
  scrollbar-gutter: stable; /* Baseline 2024 */
  /* Polished scrollbar color (Baseline 2024) */
  scrollbar-color: color-mix(in oklab, var(--accent), transparent 65%) transparent;
}

/* View Transition for smooth page changes (SPA-style) */
@supports (view-transition-name: slide-page) {
  main {
    view-transition-name: slide-page;
  }

  ::view-transition-old(slide-page) {
    animation: page-slide-out 350ms ease-in-out forwards;
  }

  ::view-transition-new(slide-page) {
    animation: page-slide-in 350ms ease-in-out forwards;
  }

  @keyframes page-slide-out {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(-40px); }
  }

  @keyframes page-slide-in {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: 0 0; }
  }
}

body {
  margin: 0;
  background: var(--surface, #f7f7fa);
  color: var(--text, #111);
  display: grid;
  grid-template-rows: auto 1fr auto; /* Grid for page layout */
  min-block-size: 100dvh; /* dynamic viewport height */
}

main {
  width: min(100% - 2rem, 74rem);
  margin-inline: auto;
  padding-block: min(10dvh, 6rem);
}

/* Typography scale using relative units */
h1 { font-size: clamp(1.8rem, 2.5vw + 1rem, 3rem); line-height: 1.2; }
h2 { font-size: clamp(1.4rem, 1.5vw + 0.8rem, 2.2rem); line-height: 1.25; }
h3 { font-size: 1.2rem; }
p, li, small { font-size: 1rem; }
small { font-size: 0.9rem; }

img { max-inline-size: 100%; block-size: auto; }

/* Global link styling: keep links same color as text (not blue/purple) */
a { color: var(--text); text-decoration: underline; text-underline-offset: 0.15em; text-decoration-thickness: from-font; }
a:visited { color: var(--text); }
a:hover { text-decoration-thickness: 2px; }

.media-cover {
  inline-size: 100%;
  block-size: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  object-position: center;
  border-radius: var(--radius);
}

.logo { object-fit: contain; object-position: center; }

/* Header and navigation */
header {
  position: static; /* default: participate in flow on non-home pages */
  top: auto;
  background: color-mix(in oklab, var(--surface), black 2%);
  border-bottom: none;
  z-index: 10;
  /* Expose nav height for hero sizing */
  --nav-h: clamp(56px, 8vh, 96px);
}

/* Primary nav layout with theme select */
nav[aria-label="Primary"] {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.theme-select[hidden] {
  display: none;
}

.theme-select {
  margin-inline-start: auto; /* push to right within the nav row */
  border-radius: 999px;
  padding: 0.35em 0.9em;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid color-mix(in oklab, var(--text), transparent 75%);
  font: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.theme-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

 

nav pill-nav, /* custom element as descendant of nav */ pill-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: var(--space-2);
}

/* CSS Nesting for nav links */
pill-nav {
  a {
    display: inline-block;
    padding: 0.5em 0.9em; /* em for element-relative spacing */
    border-radius: 9999px;
    text-decoration: none;
    color: var(--text);
    background: transparent; /* hover pill effect: default is clean */
    border: 1px solid transparent;
    transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
  }
  a:hover, a:focus-visible {
    transform: translateY(-2px);
    background: var(--surface-2);
    border-color: color-mix(in oklab, var(--text), transparent 85%);
  }
  a[aria-current="page"] {
    color: #000;
    /* Relative color syntax adjusts lightness from the accent */
    background: hsl(from var(--accent) h s calc(l + 5%));
    border-color: color-mix(in oklab, var(--accent), black 20%);
  }
}

:root[data-theme="dark"] pill-nav a[aria-current="page"],
:root[data-theme="ocean"] pill-nav a[aria-current="page"] {
  color: #fff;
}

/* Use :has() to highlight nav container when a current page link exists (extra credit) */
nav:has(a[aria-current="page"]) {
  box-shadow: inset 0 -1px 0 0 color-mix(in oklab, var(--accent), transparent 70%);
}

/* Homepage only: overlay header so it doesn't consume layout space */
body:has(#about) header {
  position: absolute;
  inset-block-start: 0;
  inset-inline: 0;
}

/* CSS-only hamburger using details/summary */
.nav-menu { margin: 0; padding: 0; }
.nav-menu > summary {
  list-style: none;
  cursor: pointer;
  padding: var(--space-2);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
}
.nav-menu > summary::before {
  content: "";
  inline-size: 1.5rem;
  block-size: 0.12rem;
  background: currentColor;
  box-shadow: 0 -0.4rem 0 currentColor, 0 0.4rem 0 currentColor; /* hamburger bars */
  border-radius: 2px;
}
.nav-menu > pill-nav { display: none; }
.nav-menu[open] > pill-nav { display: flex; }

/* Inline desktop nav (hidden on mobile) */
.nav-inline { display: none; }

/* Hero/About section with dvh and animation */
#about { border: none; }
#contact, #projects, #experiences { border: none; }

#about > div {
  block-size: calc(100dvh - var(--nav-h, 64px));
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  gap: var(--space-1);
  padding-block: var(--space-4);
  animation: fade-slide-up 600ms ease-out both;
  @starting-style { opacity: 0; translate: 0 2rem; }
  overflow: hidden; /* prevent hero from scrolling */
}

/* Minimalist hero presentation */
#about h1 {
  font-weight: 700;
  font-size: clamp(2.2rem, 4.5vw + 1rem, 4rem);
  margin-block-end: 0; /* TIGHT gap to description */
}

#about p { max-inline-size: 60ch; }
/* Inside the hero, remove default paragraph margins so spacing is controlled by grid gap */
#about > div p { margin: 0; }

/* IMPORTANT: only hide leading <br> (if present), don't globally hide all <br> */
#about > div p > br:first-child { display: none; }

/* Hide decorative/semi-redundant elements in hero for a clean look */
 
#about > div > p:nth-of-type(1) { display: none; } /* hide contact line */
/* If you still want to hide emphasis text, keep em/b but NOT br */
#about p em, #about p b { display: none; }

/* Keep UCSD photo visible, centered and framed */
#about img[alt*="Geisel"] { margin-block: var(--space-2); border-radius: var(--radius); }

/* Place UCSD image above the education text visually, without HTML changes */
#about > div > p:nth-of-type(2) {
  position: relative;
  display: grid;
  justify-items: center;
  padding-block-start: 14rem; /* space reserved for the image */
}
#about > div > p:nth-of-type(2) picture {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  inline-size: min(28rem, 90%);
}

/* Social icons row under Resume; hide X icon visually */
#about > div > div {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}
#about > div > div .social-icon { inline-size: 28px; block-size: 28px; object-fit: contain; }

 

/* Homepage: make hero full screen width and prevent horizontal overflow */
body:has(#about) { overflow-x: hidden; }
body:has(#about) main {
  width: 100vw;
  max-width: 100vw;
  margin-inline: 0;
  padding: 0;
}

/* Apply same full-width/no-overflow to other pages */
body:has(#contact) { overflow-x: hidden; }
body:has(#contact) main {
  width: 100vw;
  max-width: 100vw;
  margin-inline: 0;
  padding: 0;
}

/* Contact page layout: stacked labels, outputs below fields */
@scope (#contact) {
  #contact {
    width: min(100% - 2rem, 40rem);
    margin-inline: auto;
    padding-block: var(--space-4);
    display: grid;
    gap: var(--space-3);
  }

  #contact > h2,
  #contact > p {
    text-align: left;
  }

  #contact form {
    margin-inline: auto;
    display: block;
  }

  fieldset {
    border: 0;
    padding: var(--space-3);
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  legend {
    font-weight: 700;
    margin-block-end: var(--space-2);
  }

  label {
    font-weight: 600;
  }

  input,
  textarea,
  button,
  output {
    inline-size: 100%;
  }

  textarea {
    min-block-size: 10rem;
    border-radius: var(--radius);
  }

  output {
    min-height: 1.25em;
    font-size: 0.9rem;
  }

  #error-output {
    color: #b00020;
  }

  #info-output {
    color: var(--muted);
  }

  /* Validation states: HTML/CSS only */
  input:required,
  textarea:required {
    /* visually mark required fields without changing layout */
    border-left-width: 3px;
    border-left-color: color-mix(in oklab, var(--accent), black 15%);
  }

  input:user-invalid,
  textarea:user-invalid {
    border-color: #b00020;
    border-left-color: #b00020;
    box-shadow: 0 0 0 1px rgba(176, 0, 32, 0.18);
  }

  input:valid,
  textarea:valid {
    border-color: color-mix(in oklab, var(--accent), black 20%);
    border-left-color: color-mix(in oklab, var(--accent), black 10%);
  }

  .helper-text {
    font-size: 0.85rem;
    color: var(--muted);
  }

  .helper-text.warning {
    color: #b00020;
    font-weight: 600;
  }

  .field-flash {
    animation: field-flash 180ms ease-in-out 0s 3 alternate;
  }
}

body:has(#projects) { overflow-x: hidden; }
body:has(#projects) main { width: 100vw; max-width: 100vw; margin-inline: 0; padding: 0; }

body:has(#experiences) { overflow-x: hidden; }
body:has(#experiences) main { width: 100vw; max-width: 100vw; margin-inline: 0; padding: 0; }

@keyframes fade-slide-up {
  from { opacity: 0; translate: 0 2rem; }
  to { opacity: 1; translate: 0 0; }
}

@keyframes field-flash {
  from { background-color: #ffebee; }
  to { background-color: var(--surface-2); }
}

/* Buttons and interactive elements */
button, [type="submit"], .button, #about a[href$=".pdf"] {
  font: inherit;
  padding: 0.6em 1em;
  border-radius: calc(var(--radius) / 1.2);
  border: 1px solid color-mix(in oklab, var(--accent), black 20%);
  color: white;
  background: var(--accent);
  transition: transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}
button:hover, [type="submit"]:hover, .button:hover, #about a[href$=".pdf"]:hover {
  transform: translateY(-1px) scale(1.01);
  box-shadow: 0 8px 20px color-mix(in oklab, var(--accent), transparent 75%);
}

/* Forms */
form { display: grid; gap: var(--space-2); max-inline-size: 40rem; }
label { font-weight: 600; }
input, textarea {
  font: inherit;
  padding: 0.6em 0.8em;
  border-radius: var(--radius);
  border: 1px solid color-mix(in oklab, var(--text), transparent 80%);
  background: var(--surface-2);
  color: inherit;
}

/* Footer */
footer {
  padding: var(--space-3) var(--space-2);
  background: color-mix(in oklab, var(--surface), black 3%);
  border-top: 1px solid color-mix(in oklab, var(--text), transparent 85%);
}
footer nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: 0;
  margin: 0 0 var(--space-1) 0;
  list-style: none;
}
footer nav a { text-decoration: none; color: var(--text); }

/* Scoped styles for Projects page (match Experiences layout) */
@scope (#projects) {
  ul { list-style: none; padding: 0; margin: 0; }
  li { margin: 0; }
  article {
    border-block-end: 1px solid color-mix(in oklab, var(--text), transparent 85%);
    padding-block: var(--space-3);
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: var(--space-2);
    align-items: center;
    grid-auto-rows: min-content;
    background: transparent;
    border: none;
    box-shadow: none;
    padding-inline: 0;
  }
  /* Treat first image as a compact logo beside title */
  article img { inline-size: 40px; block-size: 40px; object-fit: contain; grid-column: 1; border-radius: 6px; }
  article h2 { grid-column: 2; margin: 0; font-size: 1rem; }
  article p { grid-column: 2; margin: 0.25rem 0 0 0; font-size: 0.95rem; color: var(--muted); }
}

/* Scoped styles for Experiences page */
@scope (#experiences) {
  article {
    border-block-end: 1px solid color-mix(in oklab, var(--text), transparent 85%);
    padding-block: var(--space-3);
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: var(--space-2);
    align-items: center;
    grid-auto-rows: min-content;
  }
  /* Place logo beside company name */
  article .logo { inline-size: 40px; block-size: 40px; object-fit: contain; grid-column: 1; }
  article h2 { grid-column: 2; margin: 0; font-size: 1rem; }
  article p { grid-column: 2; margin: 0.15rem 0 0 0; font-size: 0.95rem; color: var(--muted); }
  article ul { grid-column: 2; margin: 0.35rem 0 0 0; }
  ul { padding-inline-start: 1.2em; }
  /* Leadership list styled like work experiences */
  ol { list-style: none; padding: 0; margin: 0; }
  ol > li {
    border-block-end: 1px solid color-mix(in oklab, var(--text), transparent 85%);
    padding-block: var(--space-3);
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: var(--space-2);
    align-items: center;
    grid-auto-rows: min-content;
  }
  /* Make the heading row compact with a logo beside the name */
  ol li h3 { grid-column: 2; margin: 0; font-size: 1rem; display: flex; align-items: center; gap: var(--space-1); }
  ol li h3 .logo { inline-size: 40px; block-size: 40px; object-fit: contain; }
  ol li p { grid-column: 2; margin: 0.15rem 0 0 0; font-size: 0.95rem; color: var(--muted); }
  ol li ul { grid-column: 2; margin: 0.35rem 0 0 0; }
}

/* Experiments page generic section framing (moved from inline styles) */
body:has(#contact), body:has(#projects), body:has(#experiences), body:has(#about) {}
main section {
  border-radius: var(--radius);
  border: 1px solid color-mix(in oklab, var(--text), transparent 90%);
  padding: var(--space-1);
  background: var(--surface);
}

/* Media queries for responsiveness */
@media (width >= 48rem) {
  main { padding-block: min(12dvh, 7rem); }
  pill-nav { justify-content: center; }
  /* Desktop: hide hamburger, show inline nav */
  .nav-menu { display: none; }
  .nav-inline { display: flex; justify-content: center; }
}

@media (width >= 72rem) {
  /* 50/50 split hero on wide screens */
  #about > div {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: none;
    column-gap: var(--space-4);
    place-items: center; /* vertical centering of right column */
  }
  /* Left column: name, resume/desc, social */
  #about h1,
  #about > div > p:nth-of-type(3),
  #about > div > div { grid-column: 1; }
  /* Right column: education + UCSD image block */
  #about > div > p:nth-of-type(2) {
    grid-column: 2;
    position: static;
    display: grid;
    justify-items: center;
    padding-block-start: 0;
  }
  #about > div > p:nth-of-type(2) picture {
    position: static;
    inset: auto;
    transform: none;
    inline-size: min(28rem, 100%);
  }
}

/* Small phones: tighten spacing and avoid horizontal scroll */
@media (width < 30rem) {
  :root { --space-2: 0.75rem; --space-3: 1rem; }
  main { width: min(100% - 1rem, 74rem); }
  pill-nav a { padding: 0.65em 0.9em; }
}

/* Mobile and medium-mobile: prioritize resume/desc/social above education block */
@media (width < 48rem) {
  #about > div {
    grid-template-areas:
      "name"
      "resume"
      "social"
      "edu";
  }
  #about h1 { grid-area: name; }
  /* Education paragraph is the 2nd <p> inside the hero */
  #about > div > p:nth-of-type(2) { grid-area: edu; }
  /* Resume/description paragraph is the 3rd <p> */
  #about > div > p:nth-of-type(3) { grid-area: resume; }
  /* Social icons container */
  #about > div > div { grid-area: social; }
  /* Ensure UCSD image sits above education text (no overlay) */
  #about > div > p:nth-of-type(2) { position: static; padding-block-start: 0; }
  #about > div > p:nth-of-type(2) picture { position: static; inset: auto; transform: none; inline-size: min(28rem, 100%); }
}

/* Medium screens: keep the same prioritized order as mobile */
@media (width >= 48rem) and (width < 72rem) {
  #about > div {
    grid-template-areas:
      "name"
      "resume"
      "social"
      "edu";
  }
  #about h1 { grid-area: name; }
  #about > div > p:nth-of-type(2) { grid-area: edu; }
  #about > div > p:nth-of-type(3) { grid-area: resume; }
  #about > div > div { grid-area: social; }
  /* Ensure UCSD image sits above education text (no overlay) */
  #about > div > p:nth-of-type(2) { position: static; padding-block-start: 0; }
  #about > div > p:nth-of-type(2) picture { position: static; inset: auto; transform: none; inline-size: min(32rem, 100%); }
}

/* Focus visibility */
:focus-visible {
  outline: 3px solid color(display-p3 0.2 0.6 1 / 0.7);
  outline-offset: 2px;
}
