@import url("https://unpkg.com/normalize.css") layer(normalize);

/* Define Layers */
@layer normalize, base, layout, components;

/* --- BASE LAYER --- */
@layer base {
  :root {
    --bg-light: #ffffff;
    --text-light: #111111;
    --bg-dark: #000000;
    --text-dark: #f0f0f0;

    --easing: linear(
      0,
      0.1538 4.09%,
      0.2926 8.29%,
      0.4173 12.63%,
      0.5282 17.12%,
      0.6255 21.77%,
      0.7099 26.61%,
      0.782 31.67%,
      0.8425 37%,
      0.8887 42.23%,
      0.9257 47.79%,
      0.9543 53.78%,
      0.9752 60.32%,
      0.9883 67.11%,
      0.9961 75%,
      1 100%
    );
    --speed: 0.6s;

    --spacing-base: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
  }

  html {
    color-scheme: light dark;
    scroll-behavior: smooth;
  }

  html[data-theme="light"] {
    --bg-color: var(--bg-light);
    --text-color: var(--text-light);
    --grid-line-color: rgba(0, 0, 0, 0.1);
    --shadow-color: rgba(0, 0, 0, 0.5);
  }

  html[data-theme="dark"] {
    --bg-color: var(--bg-dark);
    --text-color: var(--text-dark);
    --grid-line-color: rgba(255, 255, 255, 0.1);
    --shadow-color: rgba(0, 0, 0, 0.7);
  }

  *,
  *:after,
  *:before {
    box-sizing: border-box;
  }

  body {
    background-color: var(--bg-color);
    color: var(--text-color);
    display: block;
    min-height: 100vh;
    font-family: "SF Pro Text", "SF Pro Icons", "AOS Icons", "Helvetica Neue",
      Helvetica, Arial, sans-serif, system-ui;
    transition: background-color 0.3s ease, color 0.3s ease;
  }

  body::before {
    --line: var(--grid-line-color);
    --size: 45px;
    content: "";
    height: 100vh;
    width: 100vw;
    position: fixed;
    background: linear-gradient(
          90deg,
          var(--line) 1px,
          transparent 1px var(--size)
        )
        50% 50% / var(--size) var(--size),
      linear-gradient(var(--line) 1px, transparent 1px var(--size)) 50% 50% /
        var(--size) var(--size);
    mask: linear-gradient(-20deg, transparent 50%, white);
    top: 0;
    z-index: -2;
    pointer-events: none;
    transition: background 0.3s ease;
  }

  h1,
  h2,
  h3,
  p {
    margin: 0;
  }
  ul {
    list-style: none;
    padding: 0;
    margin: 0;
  }
  a {
    color: inherit;
    text-decoration: none;
  }
  button {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: inherit;
  }
}

/* --- LAYOUT LAYER --- */
@layer layout {
  .container {
    width: 100%;
    max-width: 1200px;
    padding: 0 var(--spacing-lg);
    margin: 0 auto;
  }

  .site-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    padding: var(--spacing-md) 0;
    font-family: monospace;
  }

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

  main#projects {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 6rem 2rem;
    gap: var(--spacing-lg);
  }

  .about-section {
    padding: 6rem 2rem;
    text-align: center;
  }

  .site-footer {
    padding: 4rem 0;
  }

  .footer-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
  }

  .footer-grid {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-lg);
    width: 100%;
    border-top: 1px solid var(--grid-line-color);
    padding-top: var(--spacing-lg);
  }

  .footer-bottom {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-lg);
    width: 100%;
    margin-top: var(--spacing-lg);
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--grid-line-color);
    opacity: 0.7;
    font-size: 0.9rem;
  }
}

/* --- COMPONENTS LAYER --- */
@layer components {
  /* --- Header Components --- */
  .nav-left,
  .nav-right {
    flex: 1;
  }
  .nav-left {
    display: flex;
    justify-content: flex-start;
  }
  .nav-right {
    display: flex;
    justify-content: flex-end;
  }

  .main-nav {
    flex: 2;
    display: flex;
    justify-content: center;
    gap: var(--spacing-lg);
  }

  .main-nav a {
    position: relative;
    opacity: 0.7;
    transition: opacity 0.3s ease, text-shadow 0.3s ease;
    text-transform: lowercase;
    text-shadow: 0 1px 3px var(--shadow-color);
  }

  .main-nav a:hover {
    opacity: 1;
  }

  .main-nav a::after {
    content: "";
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 1px;
    background-color: var(--text-color);
    transition: width 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .main-nav a:hover::after {
    width: 100%;
  }

  .logo-container {
    display: block;
    width: 3rem;
    height: 1.5rem;
    position: relative;
  }
  .logo-circles {
    position: relative;
    width: 100%;
    height: 100%;
  }
  .circle {
    position: absolute;
    border-radius: 50%;
    transition: transform 0.3s ease;
    width: 1.4rem;
    height: 1.4rem;
    background-color: var(--text-color);
    top: 50%;
  }
  .circle-1 {
    left: 0;
    transform: translate(0, -50%);
  }
  .circle-2 {
    left: 0.8rem;
    transform: translate(0, -50%);
    mix-blend-mode: exclusion;
  }
  .logo-container:hover .circle-1 {
    transform: translate(-0.5rem, -50%);
  }
  .logo-container:hover .circle-2 {
    transform: translate(0.5rem, -50%);
  }

  #theme-toggle {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
  }
  #theme-toggle svg {
    width: 22px;
    height: 22px;
    transition: transform 0.3s ease-out;
    filter: drop-shadow(0 1px 2px var(--shadow-color));
  }
  #theme-toggle:hover svg {
    transform: scale(1.1) rotate(15deg);
  }

  .moon-icon {
    display: none;
  }
  html[data-theme="dark"] .sun-icon {
    display: none;
  }
  html[data-theme="dark"] .moon-icon {
    display: block;
  }

  /* --- Hero Section --- */
  .hero-section {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    overflow: hidden;
    padding: var(--spacing-lg);
  }

  #spiral-background {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 120%;
    height: 120%;
    z-index: -1;
  }

  #spiral-background svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .hero-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    max-width: 700px;
  }
  .hero-content h1 {
    font-size: clamp(2.5rem, 8vw, 4rem);
    font-weight: 500;
    font-family: monospace;
    text-transform: lowercase;
    line-height: 1.1;
  }
  #typing-text::after {
    content: "|";
    display: inline-block;
    animation: blink 0.7s infinite;
    font-weight: 300;
  }
  @keyframes blink {
    0%,
    100% {
      opacity: 1;
    }
    50% {
      opacity: 0;
    }
  }

  .hero-content .subtitle {
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    line-height: 1.5;
    opacity: 0.9;
    text-transform: lowercase;
    text-wrap: balance;
    text-shadow: 0 2px 4px var(--shadow-color);
  }

  .hero-buttons {
    display: flex;
    gap: var(--spacing-base);
    margin-top: var(--spacing-base);
  }
  .btn {
    padding: 0.75rem 1.5rem;
    border: 1px solid var(--text-color);
    border-radius: 4px;
    font-family: monospace;
    text-transform: lowercase;
    transition: all 0.2s ease;
    opacity: 0.8;
  }
  .btn:hover {
    opacity: 1;
  }
  .btn-primary {
    background-color: var(--text-color);
    color: var(--bg-color);
  }
  .btn-secondary:hover {
    background-color: var(--grid-line-color);
  }

  /* --- About & Project Headings --- */
  .about-section h2,
  main#projects h2 {
    font-family: monospace;
    font-size: 2rem;
    text-transform: lowercase;
    margin-bottom: var(--spacing-md);
  }

  .about-section p {
    max-width: 60ch;
    margin: 0 auto;
    line-height: 1.6;
    opacity: 0.8;
  }

  /* --- Project List (Fixed specificity to match CodePen exactly) --- */
  #project-list {
    --base: clamp(2rem, 8cqi, 80px);
    --gap: 8px;
    display: grid;
    container-type: inline-size;
    grid-template-columns: 10fr 1fr 1fr 1fr 1fr 1fr;
    gap: var(--gap);
    list-style-type: none;
    height: clamp(350px, 50vh, 500px);
    width: 100%;
    max-width: 1200px;
    transition: grid-template-columns var(--speed) var(--easing);
  }

  #project-list li {
    background: var(--bg-color);
    position: relative;
    overflow: hidden;
    min-width: var(--base);
    border-radius: 8px;
    border: 1px solid var(--grid-line-color);
    cursor: pointer;
  }

  /* CRITICAL FIX: Remove #project-list prefix to match CodePen specificity */
  li :is(svg, h3) {
    opacity: 0.6;
    transition: opacity calc(var(--speed) * 1.2) var(--easing);
  }

  li :is(a, p) {
    opacity: 0;
    transition: opacity calc(var(--speed) * 1.2) var(--easing);
    width: fit-content;
  }

  li img {
    filter: grayscale(1) brightness(1.5);
    scale: 1.1;
    transition-property: filter, scale;
    transition-duration: calc(var(--speed) * 1.2);
    transition-timing-function: var(--easing);
  }

  /* These selectors now have the right specificity to override the above */
  [data-active="true"] :is(a, p, h3, svg) {
    opacity: var(--opacity, 1);
  }

  [data-active="true"] :is(a, p) {
    transition-delay: calc(var(--speed) * 0.25);
  }

  [data-active="true"] img {
    filter: grayscale(0) brightness(1);
    scale: 1;
    transition-delay: calc(var(--speed) * 0.25);
  }

  #project-list li article {
    width: calc(var(--article-width, 0) * 1px);
    height: 100%;
    position: absolute;
    font-family: monospace;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 1rem;
    padding-inline: calc(var(--base) * 0.5 - 9px);
    padding-bottom: 1rem;
    overflow: hidden;
  }

  #project-list li article h3 {
    position: absolute;
    top: 1rem;
    left: calc(var(--base) * 0.5);
    transform-origin: 0 50%;
    rotate: 90deg;
    white-space: nowrap;
    font-size: 1rem;
    font-weight: 300;
    text-transform: uppercase;
  }

  #project-list li article svg {
    width: 18px;
    fill: none;
  }

  #project-list li article p {
    font-size: 13px;
    text-wrap: balance;
    line-height: 1.25;
    --opacity: 0.8;
  }

  #project-list li article a {
    position: absolute;
    bottom: 1rem;
    height: 18px;
    line-height: 1;
    color: inherit;
    text-decoration: none;
  }

  #project-list li article a:is(:focus-visible, :hover) {
    outline: none;
  }

  #project-list li article a:is(:focus-visible, :hover) span {
    text-decoration: underline;
    text-underline-offset: 4px;
  }

  #project-list li article a span {
    display: inline-block;
    line-height: 18px;
    translate: calc(var(--base) * 0.5);
    font-weight: 500;
  }

  #project-list li article img {
    position: absolute;
    pointer-events: none;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    mask: radial-gradient(100% 100% at 100% 0, #fff, #0000);
  }

  /* --- Footer --- */
  .footer-item h3,
  .footer-item p,
  .footer-item li,
  .footer-item a {
    text-transform: lowercase;
  }
  .footer-item h3 {
    font-weight: 500;
    margin-bottom: var(--spacing-base);
    opacity: 0.9;
  }
  .footer-item p,
  .footer-item li {
    margin-bottom: 0.5rem;
    opacity: 0.7;
  }
  .footer-item a {
    opacity: 0.7;
    transition: opacity 0.3s ease;
  }
  .footer-item a:hover {
    opacity: 1;
    text-decoration: underline;
    text-underline-offset: 4px;
  }
  .footer-item ul {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
}
