/* Shared mobile navigation for the seven root-site pages. */
.site-mobile-nav-toggle {
  display: none;
  width: 2.75rem;
  height: 2.75rem;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.site-mobile-nav-toggle:focus-visible,
[data-site-mobile-panel] a:focus-visible,
[data-site-desktop-links] a:focus-visible {
  outline: 2px solid #047857;
  outline-offset: 3px;
}

.site-menu-icon,
.site-menu-icon::before,
.site-menu-icon::after {
  display: block;
  width: 1.25rem;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.site-menu-icon {
  position: relative;
}

.site-menu-icon::before,
.site-menu-icon::after {
  position: absolute;
  left: 0;
  content: "";
}

.site-menu-icon::before {
  top: -0.4rem;
}

.site-menu-icon::after {
  top: 0.4rem;
}

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

@media (max-width: 767px) {
  /* Keep every destination reachable if the enhancement script has not run. */
  nav:not([data-mobile-nav-ready]) [data-site-desktop-links] {
    position: absolute;
    top: 4rem;
    right: 0;
    left: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    padding: 0.5rem 1rem 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    background: rgb(255 255 255 / 96%);
    box-shadow: 0 8px 16px rgb(17 24 39 / 8%);
  }

  nav:not([data-mobile-nav-ready]) [data-site-desktop-links] a {
    padding: 0.625rem 0.5rem;
  }

  nav[data-mobile-nav-ready] [data-site-desktop-links] {
    display: none;
  }

  nav[data-mobile-nav-ready] .site-mobile-nav-toggle {
    display: inline-flex;
  }

  nav[data-mobile-nav-ready] [data-site-mobile-panel] {
    position: absolute;
    top: 4rem;
    right: 1rem;
    left: 1rem;
    z-index: 1;
    flex-direction: column;
    gap: 0.125rem;
    max-width: 24rem;
    margin-left: auto;
    padding: 0.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    background: #fff;
    box-shadow: 0 12px 24px rgb(17 24 39 / 12%);
  }

  nav[data-mobile-nav-ready][data-mobile-nav-open] [data-site-mobile-panel] {
    display: flex;
  }

  nav[data-mobile-nav-ready] [data-site-mobile-panel][hidden] {
    display: none;
  }

  [data-site-mobile-panel] a {
    display: block;
    min-height: 2.75rem;
    padding: 0.75rem 0.875rem;
    border-radius: 0.5rem;
    color: inherit;
    font-size: 0.875rem;
    line-height: 1.25rem;
    text-decoration: none;
  }

  [data-site-mobile-panel] a:hover,
  [data-site-mobile-panel] a[aria-current="page"] {
    background: #f3f4f6;
  }

  [data-site-mobile-panel] a[aria-current="page"] {
    color: #047857;
    font-weight: 600;
  }
}

/* Shared long-content safeguards for the root site's inner pages. */
body[data-site-page] main :is(h1, h2, h3, h4, p, li, a, dt, dd, span) {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Biography metadata becomes a reading-order list before labels get cramped. */
body[data-site-page="bio"] .about-note {
  box-sizing: border-box;
  width: min(100%, 680px);
}

body[data-site-page="bio"] .about-meta {
  grid-template-columns: minmax(0, 7rem) minmax(0, 1fr);
}

@media (max-width: 640px) {
  body[data-site-page="bio"] .about-meta {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-site-page="other"] [data-other-content-meta] {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.75rem;
  }

  body[data-site-page="other"] [data-other-content-meta] > .text-right {
    text-align: left;
  }
}

/* Keep Project's iframe, lazy-load, and explicit external-open behavior. */
@media (max-width: 960px) {
  body[data-site-page="projects"] .case-grid,
  body[data-site-page="projects"] .evidence-grid {
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-site-page="projects"] .case-grid > *,
  body[data-site-page="projects"] .evidence-grid > * {
    min-width: 0;
  }
}

body[data-site-page="projects"] .live-frame {
  display: block;
}

body[data-site-page="projects"] .live-open {
  min-width: 2.75rem;
  min-height: 2.75rem;
  justify-content: center;
}

/* Keep the CV preview fluid and its open/download fallback prominent. */
body[data-site-page="cv"] [data-cv-preview] {
  width: 100%;
  max-width: 100%;
}

body[data-site-page="cv"] [data-cv-preview] iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Earlier-internship previews on the Other page keep their device-like aspect ratio without a fixed width. */
body[data-site-page="other"] [data-earlier-grid] {
  min-width: 0;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
}

body[data-site-page="other"] [data-earlier-copy],
body[data-site-page="other"] [data-earlier-preview] {
  min-width: 0;
}

body[data-site-page="other"] [data-earlier-preview] {
  justify-content: center;
}

body[data-site-page="other"] [data-earlier-scroll] img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

@media (max-width: 1023px) {
  body[data-site-page="other"] [data-earlier-scroll] {
    box-sizing: border-box;
    width: min(100%, 280px);
    max-width: 100%;
    height: auto;
    max-height: 520px;
    aspect-ratio: 1 / 2;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    scroll-behavior: smooth;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  body[data-site-page="other"] [data-earlier-grid] {
    grid-template-columns: repeat(2, minmax(0, 280px));
    justify-content: center;
    gap: 0.75rem;
  }

  body[data-site-page="other"] [data-earlier-copy] {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1024px) {
  body[data-site-page="other"] [data-earlier-grid] {
    grid-template-columns: minmax(0, 1fr) repeat(2, minmax(0, 280px));
    gap: 8px;
  }

  body[data-site-page="other"] [data-earlier-preview] {
    justify-content: flex-end;
  }
}

/* Carousels keep controls adjacent to their image and usable by touch. */
body[data-site-page="other"] .site-carousel-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

body[data-site-page="other"] .site-carousel-controls button {
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d4d4d4;
  border-radius: 0.5rem;
  background: #fff;
  color: #404040;
  font-size: 0.875rem;
  cursor: pointer;
}

body[data-site-page="other"] .site-carousel-controls button:hover:not(:disabled) {
  border-color: #059669;
  color: #047857;
}

body[data-site-page="other"] .site-carousel-controls button:focus-visible {
  outline: 2px solid #047857;
  outline-offset: 2px;
}

body[data-site-page="other"] .site-carousel-controls button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

/* Keep the writing highlights readable and individually scannable on phones. */
body[data-site-page="other"] [data-writing-section],
body[data-site-page="other"] [data-writing-heading],
body[data-site-page="other"] [data-writing-groups],
body[data-site-page="other"] [data-writing-list],
body[data-site-page="other"] [data-writing-list] li {
  min-width: 0;
}

body[data-site-page="other"] [data-writing-list] {
  display: block;
  list-style: disc;
  margin: 0;
  padding-left: 1.25rem;
}

body[data-site-page="other"] [data-writing-list] li + li {
  margin-top: 0.5rem;
}

body[data-site-page="other"] [data-writing-list] li::marker {
  color: #059669;
}

@media (hover: none) {
  body[data-site-page="cv"] [data-cv-preview],
  body[data-site-page="other"] [data-earlier-scroll],
  body[data-site-page="other"] [data-carousel-frame],
  body[data-site-page="projects"] .project-preview {
    transform: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  body[data-site-page="other"] .carousel-item {
    transition-duration: 0.01ms !important;
  }
}

@media (min-width: 768px) {
  .site-mobile-nav-toggle,
  [data-site-mobile-panel] {
    display: none !important;
  }

  /* Restore the original desktop order after moving actions for mobile reading flow. */
  #home [data-home-actions] {
    order: 5;
  }
}

/* Home page: keep its desktop split composition and restore document flow on phones. */
@media (max-width: 767px) {
  main[data-home-main] {
    display: block;
    height: auto;
    min-height: 0;
    padding: 5.5rem 0 1.5rem;
  }

  #home > .container {
    width: 100%;
    flex-direction: column;
    gap: 1.75rem;
    padding-inline: 1.25rem;
  }

  #home [data-home-portrait] {
    width: 100%;
  }

  #home [data-home-avatar] {
    width: clamp(7.5rem, 40vw, 10rem);
    max-width: 100%;
  }

  #home [data-home-content] {
    width: 100%;
    padding-left: 0;
    border-left-width: 0;
    align-items: stretch;
  }

  #home [data-home-identity] {
    order: 1;
    margin-bottom: 0.75rem;
  }

  #home [data-home-intro] {
    order: 2;
    margin-bottom: 1.5rem;
  }

  #home [data-home-actions] {
    order: 3;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.75rem;
  }

  #home [data-home-actions] > a + a {
    margin-left: 0;
  }

  #home [data-home-actions] a {
    display: inline-flex;
    min-height: 2.75rem;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1rem;
  }

  #home [data-home-core] {
    order: 4;
    margin-bottom: 1.5rem;
  }

  #home [data-home-background] {
    order: 5;
    margin-bottom: 0;
  }

  /* A long, animated section must not remain invisible while it is scrolled. */
  #home.section-fade {
    opacity: 1;
    transform: none;
  }

  /* Alternate portraits are a pointer-hover enhancement, not a touch interaction. */
  #home .avatar-container:hover .avatar-main {
    opacity: 1;
  }

  #home .avatar-container:hover .avatar-hover {
    opacity: 0;
  }
}
