/* Academic homepage of Josué da Silva Cavalcante.
   Hand-written CSS, no build step. Dark theme by default, with a light
   counterpart. Sections: tokens, base, layout, skip link, header, prose,
   trajectory, figures, tables, publications, projects, figure viewer, CV,
   footer, anchors, responsive, reduced motion, print. */

/* 1. Design tokens */
:root {
  color-scheme: dark;

  /* Dark palette (default) */
  --bg: #121214;
  --bg-elev: #1a1a1c;
  --bg-elev-hi: #262629;
  --ink: #e6e6e8;
  --muted: #9c9ca2;
  --line: #2c2c30;
  --accent: #8b8b92;
  --accent-hi: #d0d0d4;
  --accent-dim: #5c5c62;
  --paper: #f3f3f5;
  --focus: #f3f3f5;
  --figure-bg: #ffffff;

  /* Layout */
  --wrap: 55rem;
  --gutter: clamp(1.15rem, 4vw, 2rem);

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

:root[data-theme="light"] {
  color-scheme: light;

  /* Light palette: warm paper counterpart of the gray dark theme */
  --bg: #f6f5f2;
  --bg-elev: #ffffff;
  --bg-elev-hi: #efece5;
  --ink: #2b2b31;
  --muted: #5d5d66;
  --line: #e3e1da;
  --accent: #66666f;
  --accent-hi: #1b1b20;
  --accent-dim: #b4b2ab;
  --paper: #131318;
  --focus: #1b1b20;
  --figure-bg: #ffffff;
}

/* 2. Reset and base typography */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;

  /* Thin scrollbar with a transparent track. The tokens follow the theme. */
  scrollbar-width: thin;
  scrollbar-color: var(--accent-dim) transparent;
}

/* WebKit engines need these to match the thin preset and to round the thumb,
   which the standard properties cannot express. */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--accent-dim);
  border-radius: 999px;
  transition: background-color 0.15s var(--ease);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-hi);
}

body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
hr,
dl,
dd,
ol,
ul,
figure {
  margin: 0;
  padding: 0;
}

body {
  font-family: "IBM Plex Sans", "Source Sans 3", Helvetica, Arial, sans-serif;
  font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition:
    background-color 0.3s var(--ease),
    color 0.3s var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  body {
    transition: none;
  }
}

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

a {
  color: var(--accent-hi);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition:
    color 0.15s var(--ease),
    border-color 0.15s var(--ease);
}

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

::selection {
  background: var(--accent);
  color: var(--bg);
}

/* Keyboard focus: visible on both themes (WCAG 2.4.7) */
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 4px;
  border-radius: 2px;
}

/* Screen-reader-only utility */
.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;
}

/* 3. Layout containers */
.wrap {
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

main {
  padding-bottom: 3.5rem;
  min-height: 50vh;
}

/* Slightly wider reading column on ultra-wide displays */
@media (min-width: 112rem) {
  :root {
    --wrap: 57.5rem;
  }
}

/* 4. Skip link */
.skip-link {
  position: absolute;
  left: 1rem;
  top: 0;
  transform: translateY(-150%);
  z-index: 20;
  padding: 0.7rem 1.1rem;
  background: var(--paper);
  color: var(--bg);
  border: none;
  font-size: 0.9rem;
  transition: transform 0.15s var(--ease);
}

.skip-link:focus {
  transform: translateY(0.5rem);
  color: var(--bg);
}

/* 5. Header */
.site-header {
  text-align: center;
  padding: clamp(2rem, 1.5rem + 2.5vw, 3.25rem) 0 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: clamp(1.75rem, 1.25rem + 1.5vw, 2.75rem);
}

/* Utility row: language switcher + theme toggle */
.header-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: clamp(1.25rem, 1rem + 1vw, 1.9rem);
}

/* Compact EN | BR switcher. Each segment is a button: switching rewrites the
   page in place instead of navigating. */
.lang-switch {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-elev);
}

.lang-switch-btn {
  display: block;
  padding: 0.32rem 0.85rem;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent;
  border: none;
  line-height: 1.5;
  cursor: pointer;
  transition:
    color 0.15s var(--ease),
    background-color 0.15s var(--ease);
}

.lang-switch-btn + .lang-switch-btn {
  border-left: 1px solid var(--line);
}

.lang-switch-btn:hover {
  color: var(--paper);
  background: var(--bg-elev-hi);
}

.lang-switch-btn.is-active,
.lang-switch-btn[aria-pressed="true"] {
  color: var(--bg);
  background: var(--paper);
}

.lang-switch-btn.is-active:hover,
.lang-switch-btn[aria-pressed="true"]:hover {
  color: var(--bg);
}

/* Inline language switch inside prose. Looks like a link, behaves as a
   button, so the switch never leaves the page. */
.prose .link-button {
  padding: 0;
  font: inherit;
  color: var(--accent-hi);
  background: none;
  border: none;
  border-bottom: 1px solid var(--accent-dim);
  cursor: pointer;
}

.prose .link-button:hover {
  color: var(--paper);
  border-bottom-color: var(--paper);
}

/* Icon-only theme toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--muted);
  cursor: pointer;
  transition:
    color 0.15s var(--ease),
    border-color 0.15s var(--ease),
    background-color 0.15s var(--ease);
}

.theme-toggle:hover {
  color: var(--paper);
  border-color: var(--accent);
}

.theme-toggle svg {
  width: 1rem;
  height: 1rem;
  display: block;
}

.theme-toggle .icon-sun {
  display: block;
}
.theme-toggle .icon-moon {
  display: none;
}
:root[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}
:root[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

/* Site identity */
.site-title {
  font-family: "IBM Plex Serif", "Source Serif 4", Georgia, serif;
  font-weight: 500;
  font-size: clamp(1.9rem, 1.4rem + 2.4vw, 2.7rem);
  letter-spacing: 0.015em;
  line-height: 1.15;
  color: var(--paper);
}

.site-title a,
.site-title a:hover {
  color: var(--paper);
  border: none;
}

.site-tag {
  margin-top: 0.6rem;
  font-size: clamp(0.72rem, 0.68rem + 0.2vw, 0.83rem);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 400;
}

/* Primary navigation, centered */
.nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.3rem 1.9rem;
  margin-top: clamp(1.3rem, 1.05rem + 1vw, 1.8rem);
  padding-bottom: 1rem;
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav a {
  position: relative;
  color: var(--muted);
  border: none;
  padding: 0.45rem 0;
  transition: color 0.15s var(--ease);
}

.nav a::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0.1rem;
  height: 1px;
  width: 0;
  background: var(--paper);
  transition: width 0.25s var(--ease);
}

.nav a:hover {
  color: var(--paper);
}
.nav a:hover::after {
  width: 100%;
}

.nav a[aria-current="page"] {
  color: var(--paper);
}
.nav a[aria-current="page"]::after {
  width: 100%;
}

/* 6. Prose */
.kicker {
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.25rem;
}

.prose h1 {
  font-family: "IBM Plex Serif", Georgia, serif;
  font-weight: 500;
  font-size: clamp(1.8rem, 1.3rem + 2vw, 2.5rem);
  line-height: 1.18;
  letter-spacing: -0.015em;
  color: var(--paper);
  margin: 0 0 1.2rem;
}

.prose p {
  margin-bottom: 1.05em;
  font-size: 1.03rem;
  color: var(--ink);
  max-width: 70ch;
}

.prose p.lead {
  font-size: clamp(1.12rem, 1.05rem + 0.35vw, 1.27rem);
  line-height: 1.6;
  color: var(--paper);
  max-width: 60ch;
}

.prose section {
  margin-top: clamp(2.2rem, 1.9rem + 1.2vw, 3.2rem);
}

.prose h2 {
  font-family: "IBM Plex Serif", Georgia, serif;
  font-size: clamp(1.28rem, 1.15rem + 0.6vw, 1.48rem);
  font-weight: 500;
  color: var(--paper);
  margin: 0 0 1.15rem;
  padding-top: 1.05rem;
  border-top: 1px solid var(--line);
}

.prose h3 {
  font-size: clamp(1.05rem, 1rem + 0.3vw, 1.14rem);
  letter-spacing: 0;
  color: var(--accent-hi);
  margin: 1.6rem 0 0.6rem;
  font-weight: 500;
}

.prose ul {
  margin: 0 0 1.1em 1.15em;
}

.prose li {
  margin-bottom: 0.4em;
  color: var(--ink);
  font-size: 1.02rem;
}

.prose li::marker {
  color: var(--accent);
}

.prose a:not(.figure-image) {
  border-bottom-color: var(--accent-dim);
}
.prose a:hover {
  border-bottom-color: var(--paper);
}

.prose .text-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  font-size: 0.95rem;
  margin: 1.5rem 0;
}

.prose .when,
.when {
  font-size: 0.87rem;
  color: var(--muted);
  line-height: 1.6;
}

.prose .institution {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 0.9rem;
}

.prose .source-link {
  font-size: 0.9rem;
  color: var(--muted);
}

/* 7. Academic trajectory */
.trajectory {
  display: grid;
  gap: 1.9rem;
}

.trajectory-entry {
  display: grid;
  grid-template-columns: minmax(7rem, 9rem) minmax(0, 1fr);
  gap: 1rem;
}

.trajectory-entry + .trajectory-entry {
  padding-top: 1.9rem;
  border-top: 1px solid var(--line);
}

.trajectory-entry h3 {
  margin: 0 0 0.3rem;
  font-size: 1.15rem;
}

.trajectory-entry p:last-child {
  margin-bottom: 0;
}

/* 8. Figures */
.work-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.7rem;
  margin: 1rem 0 1.5rem;
  align-items: start;
}

.research-figure {
  margin: 1.2rem 0 1.8rem;
  min-width: 0;
}

.work-grid .research-figure {
  margin: 0;
}

.figure-image {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--figure-bg);
  padding: 0.65rem;
  cursor: zoom-in;
  transition: border-color 0.2s var(--ease);
}

.figure-image:hover {
  border-color: var(--accent);
  border-bottom: 1px solid var(--accent);
  color: inherit;
}

.figure-image img {
  width: 100%;
  height: auto;
}

.work-grid .figure-image {
  height: 17rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.work-grid .figure-image img {
  height: 100%;
  object-fit: contain;
}

.work-grid .compact .figure-image {
  height: 14rem;
}

.research-figure figcaption {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--muted);
  padding-top: 0.8rem;
}

.research-figure figcaption strong {
  color: var(--ink);
  font-weight: 500;
}

/* 9. Data tables */
.table-wrap {
  width: 100%;
  margin: 1.2rem 0;
  overflow-x: auto;
}

.results-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.95rem;
  table-layout: fixed;
}

.results-table caption {
  text-align: left;
  color: var(--muted);
  font-size: 0.875rem;
  padding-bottom: 0.6rem;
}

.results-table th,
.results-table td {
  padding: 0.8rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
  vertical-align: top;
}

.results-table th {
  font-weight: 500;
}

.results-table thead th {
  color: var(--muted);
  font-size: 0.875rem;
  background: var(--bg-elev);
}

.results-table td {
  font-variant-numeric: tabular-nums;
}

/* 10. Publications */
.pub {
  padding-bottom: 2rem;
  margin-bottom: 0;
  border-bottom: 1px solid var(--line);
}

.pub:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.pub h2 {
  border: 0;
  padding: 0;
  margin: 0.5rem 0 0.8rem;
  font-size: clamp(1.2rem, 1.1rem + 0.5vw, 1.38rem);
}

/* 11. Project cards */
.prose h3.project-group {
  margin: 1.85rem 0 0.65rem;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.prose h2 + h3.project-group {
  margin-top: 0.15rem;
}

.project-list {
  display: grid;
  gap: 1.35rem;
  margin-top: 0.35rem;
}

@media (min-width: 720px) {
  .project-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.project-list h3 {
  margin: 0 0 0.35rem;
  font-size: 1.06rem;
}

.project-list p {
  margin: 0;
}

.project-list .project-stack,
.project-list .project-note {
  margin-top: 0.7rem;
  font-size: 0.875rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.project-list .project-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.15rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

/* 12. Figure viewer */
.figure-viewer {
  max-width: min(94vw, 76rem);
  max-height: 92vh;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  overflow: hidden;
}

.figure-viewer::backdrop {
  background: rgb(0 0 0 / 72%);
}

.figure-viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
}

.figure-viewer-title {
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.figure-viewer-close {
  width: 2rem;
  height: 2rem;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition:
    color 0.15s var(--ease),
    border-color 0.15s var(--ease);
}

.figure-viewer-close:hover {
  color: var(--paper);
  border-color: var(--accent);
}

.figure-viewer-img {
  display: block;
  width: 100%;
  max-height: calc(92vh - 4rem);
  object-fit: contain;
  background: var(--figure-bg);
}

/* 13. CV page */
.page-cv .cv-main {
  max-width: 42rem;
  padding: 2rem var(--gutter) 4rem;
  margin-inline: auto;
}

.page-cv .cv-lead {
  font-size: 1.02rem;
  line-height: 1.55;
  color: var(--paper);
  margin: 0 0 2rem;
}

.page-cv .cv-main h1 {
  font-family: "IBM Plex Serif", Georgia, serif;
  font-weight: 500;
  font-size: clamp(1.7rem, 1.5rem + 1vw, 2rem);
  line-height: 1.2;
  color: var(--paper);
  letter-spacing: -0.01em;
  margin: 0 0 1.2rem;
}

.page-cv .cv-main section + section {
  margin-top: 1.9rem;
}

.page-cv .cv-main h2 {
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 500;
  margin: 0 0 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--line);
}

.page-cv .cv-dl {
  display: grid;
  gap: 1.05rem;
}

.page-cv .cv-dl dt {
  color: var(--paper);
  font-size: 0.98rem;
  font-weight: 500;
  margin-bottom: 0.15rem;
}

.page-cv .cv-dl dd {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.page-cv .cv-dl dd + dd {
  margin-top: 0.4rem;
}

.page-cv .cv-dl em {
  color: var(--ink);
  font-style: italic;
}

.page-cv .cv-dl a,
.page-cv .cv-contact a {
  border-bottom-color: var(--accent-dim);
}

.page-cv .cv-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.page-cv .cv-list li {
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.5;
  padding: 0.3rem 0 0.3rem 0.9rem;
  position: relative;
}

.page-cv .cv-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.78em;
  width: 0.38rem;
  height: 1px;
  background: var(--accent);
}

.page-cv .cv-contact {
  font-size: 0.92rem;
  color: var(--muted);
  margin-top: 0.5rem;
  overflow-wrap: anywhere;
}

/* 14. Footer */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.9rem 0 2.5rem;
  margin-top: 1rem;
}

.footer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.6rem;
}

@media (min-width: 700px) {
  .footer-grid {
    grid-template-columns: 1.6fr 1fr;
    gap: 2rem;
  }
}

.footer-name {
  font-family: "IBM Plex Serif", Georgia, serif;
  font-size: 1rem;
  color: var(--paper);
  margin-bottom: 0.55rem;
}

.footer-heading {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.55rem;
}

.footer-list {
  list-style: none;
}

.footer-list li {
  margin-bottom: 0.4rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.footer-list a {
  color: var(--muted);
  border: none;
  overflow-wrap: anywhere;
}
.footer-list a:hover {
  color: var(--accent-hi);
}

.footer-copy {
  margin-top: 1.7rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.footer-copy p {
  margin: 0;
}

/* 15. Anchors and global details */
[id] {
  scroll-margin-top: 1.5rem;
}

/* Subtle top hairline framing the page */
body::before {
  content: "";
  display: block;
  height: 1px;
  background: var(--line);
}

/* 16. Responsive adjustments */
@media (max-width: 640px) {
  .site-tag {
    letter-spacing: 0.08em;
    line-height: 1.8;
  }

  .nav {
    letter-spacing: 0.08em;
    gap: 0.25rem 1.2rem;
  }
  .nav a {
    padding: 0.6rem 0;
  }

  .trajectory-entry {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.2rem;
  }
  .trajectory-entry .when {
    margin-bottom: 0.3rem;
  }

  .work-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.8rem;
  }

  .work-grid .figure-image,
  .work-grid .compact .figure-image {
    height: auto;
    min-height: 0;
  }

  .work-grid .figure-image img {
    height: auto;
    max-height: 19rem;
    object-fit: contain;
  }

  .results-table {
    font-size: 0.875rem;
  }
  .results-table th,
  .results-table td {
    padding: 0.65rem 0.4rem;
  }

  .prose section {
    margin-top: 2.2rem;
  }
}

/* 17. Reduced motion */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  a,
  a::after,
  .theme-toggle,
  .figure-image,
  .lang-switch-btn,
  ::-webkit-scrollbar-thumb {
    transition: none;
  }
}

/* 18. Print */
@media print {
  :root,
  :root[data-theme="light"],
  :root[data-theme="dark"] {
    color-scheme: light;
    --bg: #ffffff;
    --bg-elev: #ffffff;
    --ink: #1c1c1f;
    --muted: #3f3f46;
    --line: #d4d4d8;
    --accent: #3f3f46;
    --accent-hi: #18181b;
    --accent-dim: #71717a;
    --paper: #18181b;
    --focus: #18181b;
  }

  body::before,
  .skip-link,
  .header-controls,
  .nav,
  .site-footer,
  .text-links,
  .source-link,
  .figure-viewer {
    display: none !important;
  }

  .site-header,
  .page-cv .cv-main {
    padding-top: 0;
    border: none;
    margin: 0;
  }

  a {
    border: none;
  }

  .figure-image {
    border: 1px solid #d4d4d8;
  }

  /* Let the browser use its default scrollbar when printing. */
  html {
    scrollbar-width: auto;
    scrollbar-color: auto;
  }
}
