/* Shared layout and interaction refinements for desktop, touch, and small screens. */
:root {
  --page-gutter: clamp(20px, 3.35vw, 48px);
  --header-height: 84px;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-height) + 20px);
  scroll-padding-top: calc(
    var(--header-height) + env(safe-area-inset-top, 0px) + 20px
  );
}

body {
  min-width: 0;
}

.wrap {
  width: min(1232px, calc(100% - var(--page-gutter) - var(--page-gutter)));
}

@supports (padding: max(0px)) {
  .wrap {
    width: min(
      1232px,
      calc(
        100% - max(var(--page-gutter), env(safe-area-inset-left, 0px)) -
          max(var(--page-gutter), env(safe-area-inset-right, 0px))
      )
    );
  }
}

.site-header {
  padding-top: env(safe-area-inset-top, 0px);
  -webkit-backdrop-filter: blur(16px);
}

.header-inner {
  height: var(--header-height);
  gap: 20px;
}

.header-inner > .brand,
.hero > *,
.section-heading > *,
.research-card > *,
.supporting-research > *,
.current-grid > *,
.about-grid > *,
.experience-grid > *,
.community-section > *,
.contact-inner > * {
  min-width: 0;
}

.header-inner > .brand > span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-inner > .brand > .brand-mark {
  flex-shrink: 0;
}

.header-inner > .site-nav {
  margin-left: auto;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.site-nav > a,
.site-nav .nav-cv {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.menu-toggle,
.theme-toggle,
.motion-toggle,
.copy-email {
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
}

.motion-toggle {
  width: 44px;
  height: 44px;
}

.lab-heading > div {
  min-width: 0;
}

.walkthrough-toggle,
.scenario-controls button,
.publication-filters button,
.diagram-dialog .close-dialog {
  min-height: 44px;
  font-size: 0.875rem;
}

.diagram-expand,
.project-links a,
.publication-actions > a,
.cite-button,
.social-links > a,
.contact-cv,
.research-detail summary,
.highlights summary {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.diagram-expand {
  font-size: 0.8125rem;
}

.research-detail summary {
  display: list-item;
  padding-block: 8px;
}

.highlights summary {
  display: flex;
}

.contact-details {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  column-gap: 6px;
  row-gap: 8px;
  align-items: center;
}

.contact-details > * {
  grid-column: 1 / -1;
}

.contact-details > .email-link {
  grid-column: 1;
  margin-top: 0;
  overflow-wrap: break-word;
  overflow-wrap: anywhere;
  word-break: normal;
}

.contact-details > .copy-email {
  grid-column: 2;
  grid-row: 2;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  padding: 10px;
}

.university-email {
  overflow-wrap: break-word;
  overflow-wrap: anywhere;
}

.site-footer {
  flex-wrap: wrap;
  padding-bottom: calc(23px + env(safe-area-inset-bottom, 0px));
}

.contact-section::before {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000);
}

.toast {
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

.diagram-dialog {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.diagram-dialog::backdrop {
  -webkit-backdrop-filter: blur(7px);
}

.diagram-dialog header {
  gap: 16px;
}

.diagram-dialog .close-dialog {
  flex-shrink: 0;
}

.diagram-scroll {
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.diagram-scroll:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
  border-radius: 4px;
}

.diagram-scroll img {
  max-height: 65vh;
  max-height: 65dvh;
}

.diagram-mobile-hint {
  display: none;
}

@supports not (backdrop-filter: blur(1px)) {
  .site-header {
    background: var(--bg);
  }
}

/* Tablets retain a composed two-column research layout when space permits. */
@media (min-width: 901px) and (max-width: 1150px) {
  .site-nav {
    gap: 15px;
  }

  .header-inner {
    gap: 16px;
  }

  .hero {
    max-width: none;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 28px;
  }

  .hero-copy {
    max-width: none;
  }

  .hero h1 {
    font-size: clamp(2.6rem, 4.55vw, 3.25rem);
  }

  .lab-panel {
    max-width: none;
    padding: 23px 19px 20px;
  }

  .lab-heading h2 {
    font-size: 1.125rem;
  }

  .lab-kicker {
    font-size: 0.625rem;
  }

  .hero-actions .button {
    padding-inline: 16px;
    font-size: 0.875rem;
  }

  .research-card {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .research-copy {
    padding: 28px;
  }

  .research-copy h3 {
    font-size: 1.625rem;
  }

  .project-hook {
    font-size: 1.5625rem;
  }

  .research-visual {
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .reverse .research-visual {
    order: 2;
    border-right: 0;
    border-left: 1px solid var(--line);
    border-bottom: 0;
  }

  .supporting-research {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .support-copy {
    padding: 26px;
  }

  .testbed-visual {
    min-height: 250px;
  }

  .testbed-architecture {
    gap: 9px;
  }

  .testbed-icon {
    width: 42px;
    height: 42px;
  }

  .testbed-node > span,
  .trace-output {
    font-size: 0.6875rem;
  }
}

@media (min-width: 701px) and (max-width: 1150px) {
  .current-grid {
    grid-template-columns: 1fr;
  }

  .current-card {
    display: grid;
    grid-template-columns: minmax(0, 0.75fr) minmax(0, 1.25fr);
    column-gap: 28px;
    padding: 28px;
  }

  .current-card > .project-meta {
    grid-column: 1 / -1;
    margin-bottom: 10px;
  }

  .current-card > .mini-diagram {
    grid-column: 1;
    grid-row: 2 / span 6;
    height: 100%;
    min-height: 160px;
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    align-self: center;
  }

  .current-card > h3,
  .current-card > .current-hook,
  .current-card > .current-hook + p,
  .current-card > .current-contribution,
  .current-card > .tech-tags,
  .current-card > .text-link {
    grid-column: 2;
  }

  .current-hook {
    min-height: 0;
  }
}

/* Navigation remains usable with the theme switch at tablet and phone widths. */
@media (max-width: 900px) {
  :root {
    --header-height: 72px;
  }

  .header-inner {
    height: var(--header-height);
    gap: 14px;
  }

  .brand {
    font-size: 0.875rem;
    gap: 11px;
  }

  .header-actions {
    margin-left: auto;
    gap: 7px;
  }

  .header-actions .theme-toggle {
    width: 44px;
    min-width: 44px;
    padding: 10px;
  }

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

  .menu-toggle:not([hidden]) {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 -5px 0 0;
    padding: 10px;
    color: var(--ink);
    border-radius: 7px;
  }

  .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin: 0;
    padding: 12px var(--page-gutter) 20px;
    padding-left: max(var(--page-gutter), env(safe-area-inset-left, 0px));
    padding-right: max(var(--page-gutter), env(safe-area-inset-right, 0px));
    max-height: calc(100vh - var(--header-height) - 16px);
    max-height: calc(
      100dvh - var(--header-height) - env(safe-area-inset-top, 0px) - 16px
    );
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--line);
  }

  .site-nav.is-open {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
  }

  .site-nav > a {
    min-height: 46px;
    padding: 11px 12px;
    font-size: 0.9375rem;
    border-radius: 5px;
  }

  .site-nav .nav-cv {
    justify-content: center;
    margin-top: 7px;
  }

  .menu-toggle[aria-expanded="true"] .menu-lines {
    background: transparent;
  }

  .menu-toggle[aria-expanded="true"] .menu-lines::before {
    transform: translateY(7px) rotate(45deg);
  }

  .menu-toggle[aria-expanded="true"] .menu-lines::after {
    transform: translateY(-7px) rotate(-45deg);
  }
}

@media (max-width: 700px) {
  .hero h1 {
    font-size: clamp(2.5rem, 9vw, 3.65rem);
  }

  .hero-actions .button {
    min-height: 48px;
    font-size: 0.875rem;
    padding-inline: 18px;
  }

  .hero-affiliation {
    gap: 9px 13px;
    font-size: 0.75rem;
  }

  .project-meta,
  .badge,
  .visual-topline .mono-label,
  .visual-stat > span {
    font-size: 0.75rem;
  }

  .visual-topline {
    flex-wrap: wrap;
  }

  .lab-heading h2 {
    line-height: 1.35;
  }

  .lab-kicker {
    font-size: 0.6875rem;
    line-height: 1.65;
  }

  .scenario-controls button {
    font-size: 0.875rem;
    padding: 8px 3px;
    line-height: 1.4;
  }

  .scenario-description {
    min-height: 0;
    margin-bottom: 18px;
  }

  .scenario-status,
  .scenario-description p {
    font-size: 0.875rem;
  }

  .diagram-note {
    font-size: 0.75rem;
    line-height: 1.65;
  }

  .walkthrough-controls {
    gap: 10px;
  }

  .publication-filters {
    gap: 8px;
  }

  .publication-filters button {
    font-size: 0.875rem;
    padding: 8px 11px;
  }

  .publication-filters button > span {
    font-size: 0.6875rem;
  }

  .publication-actions {
    gap: 5px 20px;
  }

  .publication-actions > a,
  .cite-button {
    font-size: 0.875rem;
  }

  .diagram-dialog {
    width: calc(100% - 24px);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    padding: 16px;
  }

  .diagram-dialog h2 {
    line-height: 1.4;
  }

  .diagram-dialog .diagram-scroll {
    margin-top: 12px;
    max-height: 58vh;
    max-height: 58dvh;
    border: 1px solid var(--line);
    border-radius: 7px;
  }

  .diagram-dialog .diagram-scroll img {
    width: 620px;
    min-width: 620px;
    max-width: none;
    max-height: none;
  }

  .diagram-dialog > p {
    font-size: 0.75rem;
    line-height: 1.6;
  }

  .diagram-mobile-hint {
    display: block;
    margin-top: 4px;
  }

  .contact-actions {
    flex-wrap: wrap;
    gap: 12px 24px;
  }

  .contact-details .email-link {
    font-size: clamp(1rem, 4.7vw, 1.25rem);
    line-height: 1.6;
  }

  .social-links {
    gap: 4px 22px;
    margin-top: 3px;
  }

  .site-footer {
    gap: 12px 20px;
  }
}

@media (max-width: 400px) {
  .visual-tag {
    display: none;
  }

  .hero-actions .button {
    padding-inline: 14px;
    gap: 10px;
  }
}

/* Short landscape viewports keep navigation and the modal's close action reachable. */
@media (max-height: 520px) and (orientation: landscape) {
  .hero {
    padding-top: 30px;
  }

  .diagram-dialog {
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    padding: 12px 16px;
  }

  .diagram-dialog header {
    padding-bottom: 10px;
  }

  .diagram-dialog .diagram-scroll {
    max-height: 52vh;
    max-height: 52dvh;
  }

  .diagram-dialog > p {
    margin-top: 8px;
  }
}

@media (hover: none), (pointer: coarse) {
  a,
  button,
  summary {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgb(111 151 255 / 18%);
  }

  .button:hover,
  .current-card:hover,
  .project-links a:hover .icon,
  .text-link:hover .icon {
    transform: none;
  }

  .button:active,
  .theme-toggle:active,
  .walkthrough-toggle:active,
  .scenario-controls button:active {
    opacity: 0.84;
  }
}

@media (forced-colors: active) {
  .button,
  .badge,
  .theme-toggle,
  .publication-filters button,
  .scenario-controls button,
  .walkthrough-toggle,
  .diagram-dialog .close-dialog {
    border: 1px solid ButtonText;
  }

  .site-header,
  .diagram-dialog::backdrop {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media print {
  .header-actions,
  .diagram-dialog {
    display: none !important;
  }

  .wrap {
    width: 100%;
  }

  .contact-details {
    display: block;
  }
}
