@layer reset, tokens, base, layout, utilidades, encabezado, acerca, proyectos, trayectoria, contacto, pie, movimiento, responsive;

@layer reset {
  * {
    box-sizing: border-box;
    border-radius: 0;
  }

  html {
    scroll-behavior: smooth;
  }
}

@layer tokens {
  :root {
    --ink: #243020;
    --muted: #68644f;
    --paper: #f5f5f2;
    --soft: #e9e9e4;
    --line: #c9b37e;
    --green: #31573f;
    --green-dark: #213b2a;
    --gold: #a67c2e;
  }
}

@layer base {
  body {
    margin: 0;
    font-family: "Faculty Glyphic", "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--ink);
    background: var(--paper);
    line-height: 1.6;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  h1,
  h2,
  h3 {
    font-family: "Amarante", Georgia, "Palatino Linotype", "Times New Roman", serif;
    line-height: 1.15;
    margin: 0;
    font-weight: 600;
  }

  .section > h2 {
    font-size: clamp(1.7rem, 3vw, 2.2rem);
    text-align: center;
    color: var(--green-dark);
    margin-bottom: 0.6rem;
  }

  .section > h2::after {
    content: "❦";
    display: block;
    font-size: 1rem;
    color: var(--gold);
    margin-top: 0.45rem;
  }
}

@layer layout {
  main {
    max-width: 1020px;
    width: 100%;
    margin: 0 auto;
    padding: 0 clamp(1rem, 4vw, 2.5rem);
    min-height: 0;
    height: 100%;
  }

  .content {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(16rem, 21rem) minmax(0, 1fr);
    gap: clamp(1.5rem, 4vw, 3rem);
  }

  .sections {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    padding: 6px 6px 2rem;
    scrollbar-width: thin;
    scrollbar-color: var(--paper) var(--paper);

    &:focus-visible {
      outline: 2px solid var(--gold);
      outline-offset: -2px;
    }

    &::-webkit-scrollbar {
      width: 8px;
    }

    &::-webkit-scrollbar-track {
      background: var(--paper);
    }

    &::-webkit-scrollbar-thumb {
      background: var(--paper);
      border: none;
    }
  }

  .section {
    padding: clamp(2.5rem, 6vw, 4rem) 0;
    border-bottom: 1px solid var(--line);
  }
}

@layer utilidades {
  .project-link,
  .contact-link {
    display: inline-block;
    padding: 0.45rem 1.4rem;
    background: var(--green);
    color: var(--paper);
    border: 1px solid var(--green-dark);
    text-decoration: none;
    font-family: "Aubrey", Georgia, serif;
    font-size: 0.95rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  .project-link:hover,
  .project-link:focus-visible,
  .contact-link:hover,
  .contact-link:focus-visible {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--green-dark);
  }
}

@layer encabezado {
  .site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem clamp(1rem, 4vw, 2.5rem);
    background: var(--paper);
    border-bottom: 1px solid var(--gold);
  }

  .logo {
    display: inline-grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    background: var(--paper);
    color: var(--green-dark);
    border: 1px solid var(--gold);
    font-family: "Aubrey", Georgia, "Palatino Linotype", serif;
    font-weight: 400;
    font-size: 1.35rem;
    letter-spacing: 0.06em;
    text-decoration: none;
    flex: none;
  }

  .site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.4rem;

    & a {
      color: var(--ink);
      text-decoration: none;
      font-family: "Aubrey", Georgia, serif;
      font-size: 0.95rem;
      letter-spacing: 0.08em;
      text-transform: uppercase;
    }

    & a:hover,
    & a:focus-visible {
      color: var(--gold);
      text-decoration: underline;
      text-underline-offset: 5px;
    }
  }
}

@layer acerca {
  .about {
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(1.5rem, 4vw, 3rem);
    align-items: start;
  }

  #acerca-de-mi {
    border-bottom: none;
  }

  .about-text {
    border: 1px solid var(--gold);
    padding: 1.75rem;

    & h1 {
      font-size: clamp(2.6rem, 6vw, 4rem);
      color: var(--green-dark);
    }

    & p {
      margin: 0 0 1rem;
      max-width: 46ch;
    }

    & p:last-child {
      margin-bottom: 0;
    }
  }

  .role {
    font-family: "Aladin", Georgia, serif;
    font-size: 1.35rem;
    font-style: normal;
    color: var(--gold);
    margin: 0.5rem 0 1rem;
  }

  .chart-card {
    margin: 0;
    background: var(--paper);
    border: 1px solid var(--gold);
    padding: 1.25rem;
    text-align: center;

    & p {
      margin: 0.15rem 0 0;
      font-family: "Aladin", Georgia, serif;
      font-style: normal;
      color: var(--muted);
      font-size: 12px;
      text-align: left;
    }
  }

  #chart {
    width: 100%;
    overflow-x: auto;

    & svg {
      max-width: 100%;
      height: auto;
      display: block;
      margin: 0 auto;
    }
  }
}

@layer proyectos {
  .projects-wrap {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 1rem;
    align-items: center;
    margin: 1.5rem auto 0;
  }

  .projects {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: calc((100% - 1.25rem) / 2);
    grid-template-rows: auto auto 1fr auto;
    column-gap: 1.25rem;
    row-gap: 0;
    min-width: 0;
    margin: 0;
    padding: 6px 6px 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
  }

  .projects::-webkit-scrollbar {
    display: none;
  }

  .project {
    display: grid;
    grid-template-rows: subgrid;
    grid-row: span 4;
    border: 1px solid var(--gold);
    background: var(--paper);
    text-align: center;
    scroll-snap-align: start;
  }

  .projects-nav {
    display: flex;
    justify-content: flex-end;
  }

  .projects-next,
  .projects-prev {
    width: 3rem;
    height: 3rem;
    display: inline-grid;
    place-items: center;
    background: transparent;
    border: none;
    color: var(--green-dark);
    font-family: "Aubrey", Georgia, serif;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
  }

  .projects-next:hover,
  .projects-prev:hover {
    color: var(--gold);
  }

  .projects-next:focus-visible,
  .projects-prev:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
  }

  .project-shot {
    aspect-ratio: 16 / 10;
    display: grid;
    place-items: center;
    background: var(--soft);
    border-bottom: 1px solid var(--gold);
    color: var(--muted);
    font-family: "Aladin", Georgia, "Palatino Linotype", serif;
    font-style: normal;
    font-size: 1.2rem;
    overflow: hidden;
  }

  .project-shot img,
  .project img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }

  .project-slideshow {
    display: block;
    position: relative;
    padding: 0;

    & img {
      position: absolute;
      inset: 0;
      opacity: 0;
      animation: project-fade 10s infinite;
    }

    & img:first-child {
      position: relative;
      animation-delay: 0s;
    }

    & img:last-child {
      animation-delay: 5s;
    }
  }

  .project-slideshow-3 img {
    animation-duration: 15s;
  }

  .project-slideshow-3 img:nth-child(2) {
    animation-delay: 5s;
  }

  .project-slideshow-3 img:last-child {
    animation-delay: 10s;
  }

  .project-body {
    display: contents;

    & h3 {
      font-size: 1.05rem;
      color: var(--green-dark);
      margin: 0;
      padding: 0.9rem 0.9rem 0;
    }

    & p {
      margin: 0;
      padding: 0.3rem 0.9rem 0.8rem;
      color: var(--muted);
      font-size: 0.88rem;
      max-width: 52ch;
      justify-self: center;
    }

    & .project-link {
      align-self: end;
      justify-self: center;
      margin: 0 auto 1rem;
    }
  }
}

@layer trayectoria {
  .list {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 760px;
    margin: 1.5rem auto 0;
  }

  .item {
    padding: 1.2rem 1.5rem;
    border: 1px solid var(--line);
    background: var(--paper);

    & h3 {
      font-size: 1.08rem;
      color: var(--green-dark);
      margin-bottom: 0.3rem;
    }

    & p {
      margin: 0;
      color: var(--muted);
    }

    & .period {
      font-size: 0.85rem;
      font-style: italic;
      color: var(--gold);
      margin-bottom: 0.3rem;
    }
  }
}

@layer contacto {
  .contact {
    text-align: center;
    border-bottom: none;

    & > p {
      color: var(--muted);
      margin: 0 0 1.5rem;
    }
  }

  .contact-links {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
  }
}

@layer pie {
  .site-footer {
    max-width: 1020px;
    margin: 0 auto;
    padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 2.5rem;
    border-top: 1px solid var(--gold);
    color: var(--muted);
    font-size: 0.9rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 2rem;
    justify-content: space-between;

    & p {
      margin: 0;
    }
  }
}

@layer movimiento {
  @keyframes project-fade {
    0% { opacity: 0; }
    5% { opacity: 1; }
    45% { opacity: 1; }
    55% { opacity: 0; }
    100% { opacity: 0; }
  }

  @media (prefers-reduced-motion: reduce) {
    html {
      scroll-behavior: auto;
    }

    .projects {
      scroll-behavior: auto;
    }

    .sections {
      scroll-behavior: auto;
    }

    .project-slideshow img {
      animation: none;
    }

    .project-slideshow img:first-child {
      opacity: 1;
    }

    .project-slideshow img:last-child {
      display: none;
    }
  }
}

@layer responsive {
  @media (max-width: 760px) {
    body {
      height: auto;
      overflow: visible;
      display: block;
    }

    main {
      height: auto;
    }

    .content {
      display: block;
      height: auto;
    }

    .sections {
      overflow: visible;
    }

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

    .projects {
      grid-auto-columns: 85%;
      max-width: 420px;
    }

    .site-header {
      align-items: flex-start;
    }
  }
}
