@layer reset, base, layout, components, pages, utilities;

/* ─── Reset ─── */
@layer reset {
  *, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  html {
    scrollbar-gutter: stable;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

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

  ul, ol {
    list-style: none;
  }

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

  button, input, textarea {
    font: inherit;
  }
}

/* ─── Base ─── */
@layer base {
  @font-face {
    font-family: "Space Grotesk";
    src: url("/fonts/space-grotesk-variable.woff2") format("woff2");
    font-weight: 300 700;
    font-display: swap;
  }

  @font-face {
    font-family: "Inter";
    src: url("/fonts/inter-variable.woff2") format("woff2");
    font-weight: 100 900;
    font-display: swap;
  }

  @font-face {
    font-family: "JetBrains Mono";
    src: url("/fonts/jetbrains-mono-variable.woff2") format("woff2");
    font-weight: 100 800;
    font-display: swap;
  }

  :root {
    --bg:             #0a0a0a;
    --bg-surface:     #111111;
    --bg-surface-alt: #1a1a1a;
    --text:           #b8b8b8;
    --text-header:    #e8e8e8;
    --text-subtle:    #808080;
    --accent:         #3b82f6;
    --accent-soft:    rgba(59, 130, 246, 0.12);
    --border:         #1e1e1e;

    --font-heading: "Space Grotesk", system-ui, sans-serif;
    --font-body:    "Inter", system-ui, sans-serif;
    --font-mono:    "JetBrains Mono", ui-monospace, monospace;

    --container: min(72rem, 100% - 5rem);
    --section-gap: 2rem;
  }

  body {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  h1, h2, h3, h4 {
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.02em;
    color: var(--text-header);
  }

  h1 { font-size: clamp(2rem, 5vw, 3.5rem); }
  h2 { font-size: clamp(1.5rem, 4vw, 2.5rem); }
  h3 { font-size: 1.25rem; }

  p + p {
    margin-top: 1em;
  }

  a {
    transition: color 200ms ease;

    &:hover {
      color: var(--accent);
    }

    &:focus-visible {
      outline: 2px solid var(--accent);
      outline-offset: 3px;
      border-radius: 2px;
    }
  }

  code {
    font-family: var(--font-mono);
    font-size: 0.875em;
  }
}

/* ─── Layout ─── */
@layer layout {
  .container {
    width: var(--container);
    margin-inline: auto;
  }

  .site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 1rem 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }

  .site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .site-logo {
    font-family: var(--font-heading);
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-header);

    &:hover {
      color: var(--text-header);
    }
  }

  .site-nav {
    display: flex;
    gap: 2rem;
  }

  .site-nav a {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--text-header);
    letter-spacing: 0.03em;
    position: relative;
    transition: color 200ms ease;

    &::after {
      content: "";
      position: absolute;
      bottom: -4px;
      left: 0;
      width: 0;
      height: 1px;
      background: var(--accent);
      transition: width 250ms ease;
    }

    &[aria-current="page"]::after {
      width: 100%;
    }

    .site-nav:hover &[aria-current="page"]:not(:hover)::after {
      width: 0;
    }

    &:hover::after {
      width: 100%;
    }
  }

  main {
    padding-top: calc(var(--section-gap) * 1.5);
    padding-bottom: var(--section-gap);
  }

  .section {
    margin-top: calc(var(--section-gap) * 2);
  }

  .section:last-child {
    margin-bottom: var(--section-gap);
  }

  .section-heading {
    margin-bottom: var(--section-gap);
    color: var(--text-header);
    font-size: 1.25rem;
    padding-left: 0.75rem;
    border-left: 3px solid var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }


  .site-footer {
    padding: var(--section-gap) 0;
    border-top: 1px solid var(--border);
    color: var(--text-subtle);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.02em;
  }

  .site-footer .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
  }

  .footer-links {
    display: flex;
    gap: 1.5rem;

    & a {
      color: var(--text-subtle);
      transition: color 200ms ease;

      &:hover {
        color: var(--accent);
      }
    }
  }
}

/* ─── Components ─── */
@layer components {
  /* Project Card */
  .card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.75rem;
    transition: transform 250ms ease, border-color 250ms ease;
    display: flex;
    flex-direction: column;
    position: relative;

    &:hover {
      transform: translateY(-2px);
      border-color: var(--accent);
    }
  }

  .card-header {
    margin-bottom: 0.75rem;
  }

  .card-title {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;

    & a {
      color: var(--text);

      &::after {
        content: "";
        position: absolute;
        inset: 0;
      }
    }
  }

  .card-meta {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-subtle);
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
  }

  .card-description {
    color: var(--text);
    font-size: 0.9375rem;
    flex: 1;
  }

  .card-footer {
    margin-top: 1.25rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Pills / Tags */
  .pill {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    padding: 0.25rem 0.625rem;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 100px;
    letter-spacing: 0.02em;
  }

  .pill--muted {
    background: var(--bg-surface-alt);
    color: var(--text);
  }

  /* Status badge */
  .status {
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;

    &::before {
      content: "";
      display: inline-block;
      width: 6px;
      height: 6px;
      border-radius: 50%;
      margin-right: 0.375rem;
      vertical-align: middle;
    }
  }

  .status--active::before { background: #22c55e; }
  .status--wip::before    { background: #eab308; }
  .status--archived::before { background: var(--text-subtle); }

  /* Metadata list */
  .meta-list {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem 2.5rem;

    & dt {
      font-family: var(--font-mono);
      font-size: 0.6875rem;
      color: var(--text-subtle);
      text-transform: uppercase;
      letter-spacing: 0.08em;
      margin-bottom: 0.25rem;
    }

    & dd {
      font-size: 0.9375rem;
      color: var(--text);
    }
  }

  /* Link with arrow */
  .link-arrow {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    transition: gap 200ms ease;

    &:hover {
      color: var(--accent);
      gap: 0.625rem;
    }

    &::after {
      content: "→";
    }
  }

  /* Social / Connect grid */
  .connect-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 1rem;
  }

  .connect-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    transition: border-color 250ms ease, color 250ms ease;

    & svg {
      width: 20px;
      height: 20px;
      flex-shrink: 0;
      color: var(--text-subtle);
      transition: color 250ms ease;
    }

    & .connect-label {
      font-size: 0.9375rem;
    }

    & .connect-url {
      font-family: var(--font-mono);
      font-size: 0.6875rem;
      color: var(--text-subtle);
      display: block;
    }

    &:hover {
      border-color: var(--accent);
      color: var(--text);

      & svg {
        color: var(--accent);
      }
    }
  }
}

/* ─── Pages ─── */
@layer pages {
  /* Hero */

  .hero-accent {
    display: block;
    width: clamp(3rem, 8vw, 6rem);
    height: 3px;
    background: var(--accent);
    border-radius: 2px;
    margin-block: calc(var(--section-gap) * 0.75);
  }

  .hero {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--section-gap) * 2);
  }

  .hero-content {
    flex: 1 1 30rem;
    min-width: 0;
  }

  .hero-text {
    max-width: 42rem;
    line-height: 1.6;

    & p + p {
      margin-top: 1.25em;
    }
  }

  .hero-tagline {
    font-size: 1.0625rem;
    color: var(--text);
  }

  .hero-portrait {
    flex: 0 0 auto;
    align-self: center;
    margin-inline: auto;
    text-align: center;
  }

  .hero-portrait img {
    width: clamp(12rem, 20vw, 18rem);
    height: clamp(12rem, 20vw, 18rem);
    border-radius: 50%;
    object-fit: cover;
  }


  /* Projects Grid */
  .projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
    gap: 1.5rem;
  }

  .projects-more {
    margin-top: 1.5rem;
  }

  /* About Page */
  .about-layout {
    display: flex;
    flex-wrap: wrap;
    gap: calc(var(--section-gap) * 2);
  }

  .about-content {
    flex: 1 1 30rem;
    min-width: 0;
    color: var(--text);
    font-size: 1.0625rem;

    & p + p {
      margin-top: 1.25em;
    }

    & a {
      color: var(--accent);
      text-decoration: underline;
      text-underline-offset: 3px;
    }

    & h2 {
      color: var(--text-header);
      margin-top: var(--section-gap);
      margin-bottom: 1.5rem;
    }
  }

  .about-skills {
    flex: 0 1 16rem;
    display: flex;
    flex-direction: column;
    gap: var(--section-gap);
  }

  .about-skills .section-heading {
    margin-bottom: 0;
  }

  /* Certifications */
  .certifications-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .cert-card {
    container-type: inline-size;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: 1fr auto;
    gap: 0 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    transition: border-color 250ms ease;

    &:hover {
      border-color: var(--accent);
    }
  }

  .cert-name {
    grid-column: 1 / -1;
    grid-row: 1;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-header);
    margin-bottom: 0.125rem;
  }

  .cert-meta {
    grid-column: 1;
    grid-row: 2;
    align-self: baseline;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-subtle);
    margin-top: 0;
  }

  .cert-year {
    grid-column: 2;
    grid-row: 2;
    align-self: baseline;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-subtle);

  }

  .cert-card .link-arrow {
    margin-top: 0.75rem;
  }

  /* Cert toggle: show only featured by default */
  .cert-toggle:not(:checked) ~ .certifications-grid .cert-card:not(.cert-featured) {
    display: none;
  }

  .cert-toggle-label {
    display: inline-flex;
    margin-top: 2rem;
    cursor: pointer;
  }

  .cert-toggle:not(:checked) ~ .cert-toggle-label::before {
    content: "Show all";
  }

  .cert-toggle:checked ~ .cert-toggle-label::before {
    content: "Show less";
  }

  .skill-group h4 {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-subtle);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.75rem;
  }

  .skill-group-items {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .timeline {
    position: relative;
    padding-left: 2rem;
    margin-top: 1rem;

    &::before {
      content: "";
      position: absolute;
      left: 0;
      top: 0.5rem;
      bottom: 0.5rem;
      width: 1px;
      background: var(--border);
    }
  }

  .timeline-item {
    position: relative;
    padding-bottom: 1.25rem;

    & p + p {
      margin-top: 0.5rem;
    }

    &::before {
      content: "";
      position: absolute;
      left: -2rem;
      top: 0.5rem;
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: var(--accent);
      transform: translateX(-50%);
    }

    &:last-child {
      padding-bottom: 0;
    }
  }

  .timeline-year {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent);
    letter-spacing: 0.06em;
    margin-bottom: 0.375rem;
  }

  .timeline-title {
    font-size: 1.0625rem;
    font-weight: 600;
    line-height: 1;
    margin-bottom: 0;
  }

  .timeline-org {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1;
    color: var(--text-subtle);
    margin-bottom: 0;
  }

  .timeline-desc {
    color: var(--text);
    font-size: 0.9375rem;
  }

  /* Contact Page */
  .contact-content {
    max-width: 36rem;
  }

  .contact-content .connect-grid {
    grid-template-columns: 1fr;
  }

  .contact-methods {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .contact-method {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: border-color 250ms ease;

    & svg {
      width: 20px;
      height: 20px;
      flex-shrink: 0;
      color: var(--text-subtle);
    }

    & span {
      font-size: 0.9375rem;
      color: var(--text);
    }

    &:hover {
      border-color: var(--accent);
    }
  }

  /* Project Detail */
  .project-header {
    background: var(--bg);
    padding: 2rem 4rem 2rem 2rem;
    margin-left: calc(-50vw + 50%);
    padding-left: calc(50vw - 50%);
    border-radius: 0 6px 6px 0;
    corner-shape: round superellipse superellipse round;
    width: fit-content;
    margin-bottom: calc(var(--section-gap) * 1.5);
    position: relative;
    z-index: 1;
    outline: 2px solid var(--accent);
  }

  .project-header h1 {
    margin-bottom: 1rem;
    line-height: 1;
  }

  .project-body {
    max-width: 42rem;
    color: var(--text);
    font-size: 1.0625rem;

    & p + p {
      margin-top: 1.25em;
    }

    & ul, & ol {
      padding-left: 1.5rem;
      list-style: disc;
      margin-block: 1em;
    }

    & ol {
      list-style: decimal;
    }

    & li + li {
      margin-top: 0.5em;
    }

    & a {
      color: var(--accent);
      text-decoration: underline;
      text-underline-offset: 3px;
    }

    & code {
      background: var(--bg-surface-alt);
      padding: 0.125em 0.375em;
      border-radius: 3px;
    }

    & pre {
      background: var(--bg-surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 1.25rem;
      overflow-x: auto;
      margin: 1.5rem 0;
    }

    & pre code {
      background: none;
      padding: 0;
    }
  }

  .project-tech {
    margin-top: var(--section-gap);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .project-links {
    margin-top: var(--section-gap);
    display: flex;
    gap: 1.5rem;
  }

  /* Project Layout */
  .project-layout {
    display: flex;
    flex-wrap: wrap;
    gap: calc(var(--section-gap) * 2);
  }

  .project-main {
    flex: 1 1 30rem;
    min-width: 0;
    max-width: 42rem;
  }

  .project-hero {
    flex: 0 1 24rem;
    margin-left: auto;
    align-self: center;
  }

  .project-hero img {
    border-radius: 6px;
  }

  .project-hero figcaption {
    font-size: 0.8125rem;
    color: var(--text);
    text-align: center;
    margin-top: 0.5rem;
  }

  .project-hero img {
    width: 100%;
    display: block;
  }


  /* 404 */
  .not-found {
    text-align: center;
    padding: var(--section-gap) 0;
  }

  .not-found-code {
    font-family: var(--font-mono);
    font-size: clamp(4rem, 12vw, 10rem);
    font-weight: 700;
    color: var(--border);
    line-height: 1;
    margin-bottom: 1rem;
  }

  .not-found p {
    color: var(--text);
    margin-bottom: 2rem;
  }
}

/* ─── Utilities ─── */
@layer utilities {
  .skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    z-index: 100;
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: #fff;
    font-family: var(--font-mono);
    font-size: 0.875rem;

    &:focus {
      top: 0;
    }
  }

  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }

  @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;
    }
  }

  @media (max-width: 40rem) {
    :root {
      --section-gap: 1.5rem;
    }

    .site-header {
      padding-block: 1rem;
    }

    .site-header .container {
      flex-wrap: wrap;
      justify-content: center;
      gap: 1rem;
    }

    .site-logo {
      width: 100%;
      text-align: center;
      padding-block: 0.25rem;
    }

    .site-nav {
      gap: 1.25rem;
    }

    .projects-grid {
      grid-template-columns: 1fr;
    }

    .connect-grid {
      grid-template-columns: 1fr;
    }
  }


  @media (max-width: 55rem) {
    .certifications-grid {
      grid-template-columns: 1fr;
    }
  }

  @media (max-width: 56rem) {
    .hero-portrait {
      display: none;
    }
  }

  @media (max-width: 63rem) {
    .project-hero {
      margin-inline: auto;
    }
  }
}
