/* khalidkalam.com — design tokens (design-system.md) */

:root {
  /* Color — light mode (default) */
  --color-bg: #FBFAF7;
  --color-bg-raised: #F1EEE5;
  --color-ink: #2C1012;
  --color-ink-muted: #6E5346;
  --color-border: #E3DFD3;
  --color-accent: #BC5336; /* was #303086 earth-blue; terracotta per launch feedback #2 —
                               now serves as both link color and the design system's
                               former --color-highlight (same value). Dark mode below is
                               untouched, so dark stays rosalind-green as intended. */
  --color-accent-hover: #26265E;
  --color-accent-tint: #D6D6EC;
  --color-highlight: #BC5336;

  /* Status marks */
  --color-status-positive: #31773B;
  --color-status-neutral: var(--color-ink-muted);
  --color-status-pending: #856024;

  /* Typography */
  --font-serif: 'Newsreader', serif;
  --font-sans: 'Public Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --text-display: 2.9rem;
  --text-h1: 2.3rem;
  --text-h2: 1.7rem;
  --text-h3: 1.35rem;
  --text-body-lg: 1.15rem;
  --text-body: 1rem;
  --text-meta: 0.85rem;
  --text-caption: 0.8rem;
}

[data-theme="dark"] {
  /* Dark mode redesigned per round-3 feedback: a literal inversion of the
     light-mode palette rather than an independent color scheme. Light mode's
     ink (#2C1012, a dark umber-brown) becomes dark mode's background; light
     mode's near-white background (#FBFAF7) becomes dark mode's text color.
     --color-ink-muted and --color-bg get reused directly (not re-colored) by
     the footer copyright block below to produce an automatic light-mode/
     dark-mode inverse pair from one CSS rule — see .footer-copyright. */
  --color-bg: #2C1012;
  --color-bg-raised: #3D2018;
  --color-ink: #FBFAF7;
  --color-ink-muted: #D9C9BE;
  --color-border: #4A2E24;
  --color-accent: #A6B54E; /* rosalind-green — unchanged, not part of this ask */
  --color-accent-tint: rgba(166,181,78,0.16);

  --color-status-positive: #C3D178;
  --color-status-pending: #D9B15C;
}

@font-face {
  font-family: 'Newsreader';
  src: url('/fonts/newsreader-variable.woff2') format('woff2');
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Public Sans';
  src: url('/fonts/public-sans-variable.woff2') format('woff2');
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/jetbrains-mono-variable.woff2') format('woff2');
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  font-size: var(--text-body);
  color: var(--color-ink);
  background-color: var(--color-bg);
}

main {
  flex: 1 0 auto;
}

h1, h2, h3 { font-family: var(--font-serif); font-weight: 500; margin: 0 0 0.5em; }
h1 { font-size: var(--text-h1); }
h2 { font-size: var(--text-h2); }
h3 { font-size: var(--text-h3); }

/* Base link behavior, site-wide: no underline at rest, underline appears on
   hover. .nav-link overrides this below (bold-on-hover instead) since nav
   chrome and inline body links carry different affordance expectations. */
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Background texture — applied to page background only, not cards */
.textured-bg {
  background-color: var(--color-bg);
  background-image: url("/img/topo-bg-light.svg");
  background-repeat: repeat;
  background-size: 640px 640px;
}
[data-theme="dark"] .textured-bg {
  background-color: var(--color-bg);
  background-image: url("/img/topo-bg-dark.svg");
}

/* External-link arrow, scoped to prose body copy only.
   \FE0E is the text-presentation variation selector — forces plain-glyph
   rendering instead of iOS/WebKit's colored-emoji font for U+2197. Fixes
   the blue-badge-arrow bug from launch feedback #5, zero added bytes. */
.prose a[href^="http"]::after,
.prose a[data-external]::after {
  content: " ↗\FE0E";
  font-size: 0.85em;
  display: inline-block;
}

/* --- Header --- */

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--color-border);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: color-mix(in srgb, var(--color-bg) 85%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: box-shadow 0.2s ease;
  flex-wrap: wrap;
  gap: 1rem;
}
.site-header.scrolled {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.site-logo {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  text-decoration: none;
  color: var(--color-ink);
}

.site-nav ul {
  list-style: none;
  display: flex;
  gap: 1.5rem;
  padding: 0;
  margin: 0;
  flex-wrap: wrap;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Nav-link chrome: no underline ever, bold-on-hover instead of color/underline
   shift. Kept modest (400→600, not 400→800) so variable-width fonts don't
   visibly reflow the layout on hover. */
.nav-link {
  text-decoration: none;
  font-weight: 400;
  color: var(--color-ink);
}
.nav-link:hover,
.nav-link:focus-visible,
.nav-link[aria-current="page"] {
  font-weight: 600;
  color: var(--color-accent);
}

/* Hamburger button — hidden on desktop, shown under the mobile breakpoint */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  color: var(--color-ink);
}
.nav-toggle svg {
  width: 24px;
  height: 24px;
  display: block;
}

@media (max-width: 768px) {
  .nav-toggle {
    display: inline-flex;
  }
  .site-nav {
    order: 3;
    width: 100%;
  }
  .site-nav ul {
    display: none;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem 0 0.5rem;
  }
  .site-nav.open ul {
    display: flex;
  }
}

/* --- Footer --- */

.site-footer {
  color: var(--color-ink-muted);
  font-size: var(--text-caption);
}
.footer-nav-block {
  background-color: var(--color-bg);
  border-radius: 12px 12px 0 0;
  padding: 1.5rem 2rem 1rem;
}
.footer-nav ul {
  list-style: none;
  display: flex;
  gap: 1.5rem;
  padding: 0;
  margin: 0 0 1rem;
  flex-wrap: wrap;
}
.footer-row-2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}
.footer-social {
  display: flex;
  gap: 0.9rem;
}
.footer-social a {
  color: var(--color-ink-muted);
  display: inline-flex;
}
.footer-social a:hover {
  color: var(--color-accent);
  text-decoration: none;
}
.footer-social svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}
.footer-privacy {
  font-size: var(--text-caption);
}
/* Copyright block — a deliberate inverse of the page's own theme colors,
   not a themed element itself. Reuses --color-ink-muted as background and
   --color-bg as text in BOTH themes: in light mode that's umber-brown bg /
   near-white text; in dark mode (after the token inversion above) those same
   two variables resolve to near-white bg / umber-brown text — the requested
   "opposite" automatically, from one rule, no separate dark override needed. */
.footer-copyright {
  background-color: var(--color-ink-muted);
  color: var(--color-bg);
  text-align: center;
  margin: 0;
  padding: 1rem 2rem;
}

/* --- Home + About layouts --- */

.home-identity {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  padding: 3rem 2rem;
  max-width: 900px;
  margin: 2rem auto 1rem;
  background-color: var(--color-bg);
  border-radius: 12px;
}
.home-identity-text p {
  font-size: var(--text-body-lg);
  line-height: 1.6;
}

/* Shared portrait treatment — Home and About both use class="headshot".
   Outline per launch feedback #3; light/dark image swap fixes bug #4 (the
   two portrait files existed but only one was ever wired into the template). */
.headshot {
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  outline: 1.5px solid var(--color-accent);
  outline-offset: 3px;
}
.page-header .headshot {
  margin-top: 1rem;
}

.routing-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  max-width: 900px;
  margin: 1rem auto 3rem;
  padding: 0 2rem;
}
@media (max-width: 640px) {
  .routing-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
.routing-card {
  display: block;
  padding: 1.5rem;
  text-align: center;
  background-color: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-ink);
  font-family: var(--font-serif);
  font-size: 1.1rem;
  transition: border-color 0.15s ease;
}
.routing-card:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.page {
  max-width: 720px;
  margin: 2rem auto;
  padding: 2rem;
  background-color: var(--color-bg);
  border-radius: 12px;
}
.page-header {
  margin-bottom: 2rem;
}
.page-header .meta {
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  color: var(--color-ink-muted);
}

.prose h2 {
  margin-top: 2.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--color-border);
}
.prose ol, .prose ul {
  padding-left: 1.25rem;
}
.prose li {
  margin-bottom: 0.5rem;
  line-height: 1.5;
}
.prose details {
  margin-top: 1rem;
  padding: 1rem;
  background-color: var(--color-bg-raised);
  border-radius: 6px;
}
.prose details summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  color: var(--color-accent);
}
.prose details ol {
  margin-top: 1rem;
}

@media (max-width: 640px) {
  .home-identity {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
}

/* --- Theme toggle: 3-position slider (light / auto / dark) --- */

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}
.theme-toggle .theme-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--color-ink-muted);
}
.theme-toggle .theme-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}
.theme-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 72px;
  height: 20px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
.theme-slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--color-accent-tint), var(--color-ink-muted));
}
.theme-slider::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--color-accent-tint), var(--color-ink-muted));
}
.theme-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--color-accent);
  border: 2px solid var(--color-bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.theme-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-accent);
  border: 2px solid var(--color-bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.theme-slider:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

/* --- Publications + Patents --- */

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 1.5rem 0 2rem;
}
.tag-pill {
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-ink-muted);
  cursor: pointer;
  transition: all 0.12s ease;
}
.tag-pill:hover {
  border-color: var(--color-accent);
}
.tag-pill.active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-bg);
}
.tag-pill.tag-clear {
  border-style: dashed;
}

.pub-list-section {
  margin-bottom: 2.5rem;
}
.year-heading {
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  color: var(--color-ink-muted);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}
.entry-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.entry-row {
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--color-border);
}
.entry-row:last-child {
  border-bottom: none;
}
.entry-title {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  color: var(--color-ink);
}
.entry-title:hover {
  color: var(--color-accent);
}
.entry-meta {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  color: var(--color-ink-muted);
  margin-top: 0.2rem;
}

.oa-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  margin-left: 0.4rem;
}
.oa-badge.oa-open {
  background: var(--color-accent-tint);
  color: var(--color-accent);
}
.oa-badge.oa-closed {
  background: var(--color-bg-raised);
  color: var(--color-ink-muted);
}

.breadcrumbs {
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  color: var(--color-ink-muted);
  margin-bottom: 1rem;
}
.breadcrumbs a {
  color: var(--color-ink-muted);
}

.pub-detail .author-list {
  list-style: none;
  padding: 0;
  font-size: var(--text-meta);
  color: var(--color-ink-muted);
}
.pub-detail .author-list li {
  display: inline;
}
.pub-detail .author-list li::after {
  content: " · ";
}
.pub-detail .author-list li:last-child::after {
  content: "";
}

.closed-note {
  font-size: var(--text-meta);
  color: var(--color-ink-muted);
  background: var(--color-bg-raised);
  padding: 0.75rem 1rem;
  border-radius: 6px;
}

.tag-row {
  margin-top: 2rem;
}
.tag-pill-static {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--color-bg-raised);
  color: var(--color-ink-muted);
  margin: 0 0.3rem 0.3rem 0;
}

/* --- Work page --- */

.entity-cards {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  margin-top: 2rem;
}
.entity-card {
  padding: 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg-raised);
}
.entity-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.entity-card-header h2 {
  margin: 0;
  flex-shrink: 0;
}
.status-mark {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.status-mark.status-active {
  background: var(--color-status-positive);
}
.status-mark.status-dissolved {
  background: var(--color-ink-muted);
}
.status-label {
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  color: var(--color-ink-muted);
}
.entity-meta {
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  color: var(--color-ink-muted);
  margin-top: 0.2rem;
}
.incubating-heading {
  font-size: var(--text-meta);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-ink-muted);
  margin-top: 1.5rem;
  border: none;
}
.incubating-list .entry-row {
  border-bottom: 1px solid var(--color-border);
}
.entry-title-static {
  display: block;
  font-family: var(--font-serif);
  font-weight: 500;
}

/* --- Collaborate, Contact, 404, Privacy --- */

.intro-line {
  font-size: var(--text-body-lg);
  line-height: 1.6;
  margin-bottom: 2rem;
}

.segment-list {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}
.segment h2 {
  margin-top: 0;
}
.cta-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: var(--text-meta);
}
.outlink-line {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.contact-page form {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  margin-top: 1.5rem;
  max-width: 480px;
}
.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.form-row label {
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  color: var(--color-ink-muted);
}
.form-row input,
.form-row select,
.form-row textarea {
  font-family: var(--font-sans);
  font-size: var(--text-body);
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-ink);
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

.honeypot-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.submit-button {
  align-self: flex-start;
  padding: 0.7rem 1.5rem;
  background: var(--color-accent);
  color: var(--color-bg);
  border: none;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-weight: 600;
  cursor: pointer;
}
.submit-button:hover {
  background: var(--color-accent-hover);
}
.submit-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.form-status {
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  color: var(--color-ink-muted);
  min-height: 1.2em;
}
.confirmation-screen {
  max-width: 480px;
  padding: 2rem;
  margin-top: 1.5rem;
  background: var(--color-bg-raised);
  border-radius: 8px;
}

.error-404 {
  max-width: 480px;
  margin: 5rem auto;
  text-align: center;
  padding: 0 2rem;
}
.error-404 .error-code {
  font-family: var(--font-mono);
  font-size: var(--text-display);
  color: var(--color-ink-muted);
  margin: 0;
}
.error-404 h1 {
  margin-top: 0.5rem;
}

/* --- Launch feedback round 2 additions --- */

.jump-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 1.25rem;
  margin: 1rem 0 2rem;
  padding: 0.75rem 1rem;
  background: var(--color-bg-raised);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: var(--text-caption);
}
.jump-nav-label {
  color: var(--color-ink-muted);
  font-weight: 600;
  margin-right: 0.25rem;
}
.jump-nav a {
  color: var(--color-ink-muted);
}
.jump-nav a:hover {
  color: var(--color-accent);
}

/* Anchor targets need breathing room above them so the sticky header doesn't
   cover the top of the section when jumped to. ~100px clears the header's
   real height (padding + logo/nav line + border) with a little margin. */
h2[id], h3[id], section[id] {
  scroll-margin-top: 100px;
}

.back-to-top {
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  margin-top: -0.5rem;
  margin-bottom: 1rem;
}

/* Incubating-venture links now render as <a> when a URL exists — same visual
   weight as the static (non-linked) version, color shift + underline-on-hover
   from the global link rules is the only affordance change needed. */
a.entry-title-static {
  color: var(--color-ink);
}

/* Scholar citation stats — manually maintained, not live-fetched (Google
   Scholar has no reliable public API and blocks simple server-side scraping).
   Shown with an explicit as-of date and a link to the live profile so
   visitors can always check the current number themselves. */
.scholar-stats {
  margin-top: 0.25rem;
}
.stats-date {
  color: var(--color-ink-muted);
}

/* --- Launch feedback round 3 additions --- */

/* About page: 2-column portrait + bio intro on desktop */
.about-intro-grid {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.about-intro-grid .headshot {
  flex-shrink: 0;
  margin-top: 0.25rem;
}
.about-intro-grid .bio-text p {
  font-size: var(--text-body-lg);
  line-height: 1.6;
}
@media (max-width: 640px) {
  .about-intro-grid {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
}

/* Publications summary stats — replaces the plain jumbled meta line */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1.75rem;
  margin: 1rem 0 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--color-bg-raised);
  border-radius: 8px;
}
.stat {
  display: flex;
  flex-direction: column;
}
.stat-value {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  color: var(--color-ink);
  line-height: 1.1;
}
.stat-value a {
  color: inherit;
}
.stat-label {
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  color: var(--color-ink-muted);
  margin-top: 0.15rem;
}
.stats-asof {
  width: 100%;
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  color: var(--color-ink-muted);
  margin-top: 0.25rem;
}

/* Tag filter — helper text + live result count, guiding first-time use */
.tag-filter-helper {
  font-size: var(--text-meta);
  color: var(--color-ink-muted);
  margin: 1.5rem 0 0.5rem;
}
.tag-filter-count {
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  color: var(--color-ink-muted);
  margin: 0.5rem 0 1.5rem;
}
