/* ---------------------------------------------------------------------
   Design tokens
--------------------------------------------------------------------- */
:root {
  --color-bg: #ffffff;
  --color-bg-alt: #f4f5f7;
  --color-text: #1a1d21;
  --color-text-muted: #565d66;
  --color-accent: #1f5fd6;
  --color-border: #dde1e6;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2.5rem;
  --space-6: 4rem;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.75rem;
  --text-2xl: 2.5rem;

  --content-width: 42rem;
  --page-width: 72rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #14161a;
    --color-bg-alt: #1c1f24;
    --color-text: #eceef1;
    --color-text-muted: #9aa2ad;
    --color-accent: #7ea6ff;
    --color-border: #2c3038;
  }
}

/* ---------------------------------------------------------------------
   Reset
--------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
}

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

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

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

main.wrap {
  max-width: var(--content-width);
  padding-block: var(--space-5);
}

/* ---------------------------------------------------------------------
   Header
--------------------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--color-border);
}

.site-header__inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-block: var(--space-3);
}

.site-header__brand {
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
}

.site-nav ul {
  list-style: none;
  display: flex;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
}

.site-nav a {
  color: var(--color-text);
  text-decoration: none;
  font-size: var(--text-sm);
}

.site-nav a:hover,
.site-nav a:focus-visible {
  color: var(--color-accent);
}

/* Language switcher: plain links, one per language in the registry */
.lang-switcher ul {
  list-style: none;
  display: flex;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
}

.lang-switcher a {
  font-size: var(--text-sm);
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  text-decoration: none;
}

.lang-switcher a:hover,
.lang-switcher a:focus-visible {
  color: var(--color-accent);
}

.lang-switcher a[aria-current="page"] {
  color: var(--color-text);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

@media (min-width: 40rem) {
  .site-header__inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

/* ---------------------------------------------------------------------
   Footer
--------------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-6);
}

.site-footer__inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-block: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.site-footer__social {
  list-style: none;
  display: flex;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
}

@media (min-width: 40rem) {
  .site-footer__inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

/* ---------------------------------------------------------------------
   Typography
--------------------------------------------------------------------- */
h1 {
  font-size: var(--text-2xl);
  line-height: 1.2;
  margin-block: 0 var(--space-3);
}

h2 {
  font-size: var(--text-xl);
  line-height: 1.3;
  margin-block: var(--space-5) var(--space-2);
}

p {
  margin-block: 0 var(--space-3);
  color: var(--color-text);
}

.lede {
  font-size: var(--text-lg);
  color: var(--color-text-muted);
}

/* Notice on fallback pages: content shown in its original language */
.fallback-banner {
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg-alt);
  border-left: 3px solid var(--color-accent);
  border-radius: 0.25rem;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* ---------------------------------------------------------------------
   Forms (contact page)
--------------------------------------------------------------------- */
.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

label {
  font-size: var(--text-sm);
  font-weight: 600;
}

input,
textarea {
  font: inherit;
  color: var(--color-text);
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
  padding: var(--space-2);
}

button {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--color-accent);
  border: none;
  border-radius: 0.25rem;
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
}

/* Inline result of a fetch-submitted contact form (contact-form.js) */
.form-status {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg-alt);
  border-left: 3px solid var(--color-accent);
  border-radius: 0.25rem;
  font-size: var(--text-sm);
}

.form-status-error {
  border-left-color: #c43d3d;
}

/* ---------------------------------------------------------------------
   Cards (project/article indexes and tag pages)
--------------------------------------------------------------------- */
.card-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-3);
}

.card {
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  padding: var(--space-3);
  background: var(--color-bg-alt);
}

.card-title {
  font-size: var(--text-lg);
  line-height: 1.3;
  margin: 0 0 var(--space-1);
}

.card-title a {
  color: var(--color-text);
  text-decoration: none;
}

.card-title a:hover,
.card-title a:focus-visible {
  color: var(--color-accent);
}

.card-meta {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

.card-description {
  margin: 0;
}

/* Badge on index cards whose item isn't translated into the page language */
.lang-badge {
  display: inline-block;
  vertical-align: middle;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  font-weight: 400;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: 0.25rem;
  padding: 0 var(--space-1);
  margin-left: var(--space-2);
}

/* ---------------------------------------------------------------------
   Detail pages (single project/article)
--------------------------------------------------------------------- */
.detail-meta {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.tag-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  padding: 0;
}

.tag {
  display: inline-block;
  font-size: var(--text-sm);
  font-family: var(--font-mono);
  color: var(--color-text);
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0 var(--space-2);
  text-decoration: none;
}

.tag:hover,
.tag:focus-visible {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

/* ---------------------------------------------------------------------
   Search (<site-search> web component in the header)
--------------------------------------------------------------------- */
site-search {
  position: relative;
  display: block;
}

/* No JS, no search: the component stays hidden until its class is defined */
site-search:not(:defined) {
  display: none;
}

site-search input {
  width: 100%;
  font-size: var(--text-sm);
}

.search-results {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  z-index: 10;
  width: min(24rem, calc(100vw - 2 * var(--space-3)));
  max-height: 60vh;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: var(--space-2);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.15);
}

.search-results > li {
  padding: var(--space-2);
  border-radius: 0.25rem;
}

.search-results > li:not(.search-browse):hover,
.search-results > li:not(.search-browse):focus-within {
  background: var(--color-bg-alt);
}

.search-results a {
  font-weight: 600;
  color: var(--color-text);
  text-decoration: none;
}

.search-results a:hover,
.search-results a:focus-visible {
  color: var(--color-accent);
}

.search-results p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.search-result-meta {
  margin-left: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
}

.search-empty {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.search-more {
  font-size: var(--text-sm);
}

/* Empty-query "browse by tag" view inside the dropdown */
.search-browse-label {
  display: block;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-1);
}

.search-tag-group {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
}

/* ---------------------------------------------------------------------
   /search/ page (<search-page> web component)
--------------------------------------------------------------------- */
search-page {
  display: block;
}

search-page input[type="search"] {
  width: 100%;
}

/* Without JS the input and mode toggle are inert, so hide them; the tag
   chips remain plain links to the build-time tag pages and still work. */
search-page:not(:defined) input[type="search"],
search-page:not(:defined) .search-mode {
  display: none;
}

.search-filters {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.search-mode {
  border: none;
  margin: 0;
  padding: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.search-mode legend {
  padding: 0;
  font-weight: 600;
  margin-bottom: var(--space-1);
}

.search-mode label {
  margin-right: var(--space-3);
  font-weight: 400;
}

.search-count {
  margin: var(--space-3) 0 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* Selected filter chip */
.tag--active,
.tag--active:hover,
.tag--active:focus-visible {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-bg);
}

/* The page reuses the dropdown's result markup, minus the popover chrome */
.search-results--page {
  position: static;
  width: auto;
  max-height: none;
  overflow: visible;
  margin-top: var(--space-2);
  padding: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: none;
}

@media (min-width: 40rem) {
  site-search input {
    width: 14rem;
  }
}

/* Honeypot field: hidden from sighted users, still present in the DOM for bots to fill in */
.hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
