/* ==========================================================================
   PeraMorphIQ - Base: reset, typography, layout primitives
   Depends on tokens.css. No raw colour values in this file.
   ========================================================================== */

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

html {
  /* 1rem = 10px - every rem in this codebase assumes this. */
  font-size: 62.5%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + var(--space-5));
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  color: var(--ink-700);
  background-color: var(--surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

main {
  flex: 1 0 auto;
}

/* --- Typography ---------------------------------------------------------- */

h1,
h2,
h3,
h4,
h5,
h6 {
  color: var(--ink-900);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-3xl);
}
h2 {
  font-size: var(--text-2xl);
}
h3 {
  font-size: var(--text-xl);
}
h4 {
  font-size: var(--text-lg);
}
h5 {
  font-size: var(--text-md);
}
h6 {
  font-size: var(--text-base);
}

p {
  text-wrap: pretty;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

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

/* Links sitting inside running text must not rely on colour alone (WCAG 1.4.1).
   Standalone links in nav, cards, buttons and lists are excluded because they
   are not embedded in a text block. */
.prose a,
.article__body a,
.project-section p a,
.info-block__value a,
.site-footer__tagline a,
.page-head__lead a,
.section-head__lead a,
figcaption a {
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

strong,
b {
  font-weight: var(--weight-semibold);
  color: var(--ink-900);
}

ul,
ol {
  list-style: none;
}

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

img {
  height: auto;
}

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

button {
  background: none;
  border: none;
  cursor: pointer;
}

hr {
  border: none;
  border-top: var(--border);
  margin: var(--space-6) 0;
}

code,
kbd,
pre {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

::selection {
  background-color: var(--accent-weak);
  color: var(--ink-900);
}

/* --- Focus --------------------------------------------------------------- */

:focus {
  outline: none;
}

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

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-overlay);
  padding: var(--space-2) var(--space-4);
  background-color: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transform: translateY(-200%);
  transition: transform var(--transition);
}

.skip-link:focus-visible {
  transform: translateY(0);
}

/* --- Touch targets -------------------------------------------------------- */

/* WCAG 2.2 SC 2.5.8 asks for a 24x24 minimum. Several standalone action links
   (DOI / Cite, Profile / LinkedIn, breadcrumbs, footer columns) sit at 17-20px
   on their own line, which is fiddly on a phone. Only touch pointers get the
   extra height, so desktop density is unchanged. */
@media (pointer: coarse) {
  .pub__actions a,
  .pub__actions button,
  .person__links a,
  .breadcrumb a,
  .footer-col a,
  .site-footer__bottom a,
  .site-footer__brand a,
  .info-block__value a,
  .resources__list a,
  .link-forward,
  .aside-block a,
  .card__footer a {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
  }

  /* Short labels ("DOI", "Cite", "CV") clear 24px in height but not in width. */
  .pub__actions a,
  .pub__actions button,
  .person__links a {
    justify-content: center;
    min-width: 24px;
  }

  .filter-group__label + .cluster .chip,
  .chip {
    min-height: 36px;
  }
}

/* --- Layout primitives --------------------------------------------------- */

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

.container--narrow {
  max-width: var(--container-narrow);
}

/* Constrain running prose to a readable measure regardless of container. */
.prose {
  max-width: var(--measure);
}

.prose p + p {
  margin-top: var(--space-4);
}

.prose p {
  color: var(--ink-700);
}

.section {
  padding-block: var(--section-y);
}

.section--lg {
  padding-block: var(--section-y-lg);
}

.section--tight {
  padding-block: var(--space-7);
}

/* Alternating band - the only "background colour" device in the system. */
.section--alt {
  background-color: var(--surface-2);
}

.section--bordered {
  border-top: var(--border);
}

/* Section heading block: eyebrow + title + optional lead paragraph. */
.section-head {
  margin-bottom: var(--space-7);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.section-head__eyebrow {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--ink-500);
}

.section-head__title {
  font-size: var(--text-2xl);
}

.section-head__lead {
  max-width: var(--measure);
  color: var(--ink-500);
  font-size: var(--text-md);
}

/* Heading row with a trailing "view all" link. */
.section-head--row {
  flex-direction: row;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-5);
  flex-wrap: wrap;
}

/* --- Grid ---------------------------------------------------------------- */

.grid {
  display: grid;
  gap: var(--space-5);
}

.grid--2 {
  grid-template-columns: repeat(2, 1fr);
}
.grid--3 {
  grid-template-columns: repeat(3, 1fr);
}
.grid--4 {
  grid-template-columns: repeat(4, 1fr);
}
.grid--5 {
  grid-template-columns: repeat(5, 1fr);
}

@media (max-width: 62em) {
  .grid--4,
  .grid--5 {
    grid-template-columns: repeat(3, 1fr);
  }
  .grid--3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 46em) {
  .grid--2,
  .grid--3,
  .grid--4,
  .grid--5 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 34em) {
  .grid--2,
  .grid--3,
  .grid--4,
  .grid--5 {
    grid-template-columns: 1fr;
  }
}

/* --- Utilities ----------------------------------------------------------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.text-center {
  text-align: center;
}

.muted {
  color: var(--ink-500);
}

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

[hidden] {
  display: none !important;
}

/* --- Reveal on scroll (subdued) ------------------------------------------ */

.reveal-item {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--transition-slow), transform var(--transition-slow);
  transition-delay: var(--reveal-delay, 0ms);
}

.reveal-item.revealed {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .reveal-item {
    opacity: 1;
    transform: none;
  }
}

/* --- Page-level states --------------------------------------------------- */

.state {
  padding: var(--space-8) var(--space-5);
  text-align: center;
  color: var(--ink-500);
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
}

.state__title {
  font-size: var(--text-md);
  color: var(--ink-900);
  margin-bottom: var(--space-2);
}
