/* ============================================================
   ruimarques.dev - Design System (warm paper / oxblood)
   ============================================================ */

:root {
  /* Palette */
  --bg: #faf6f0;
  --surface: #ffffff;
  --text-primary: #2b2422;
  --text-secondary: #5c4f49;
  --text-muted: #796a62;
  --accent: #9a3038;
  --accent-hover: #7f262d;
  --accent-light: #f3e3e1;
  --border: #e6dcd1;
  --line: #d8cabb;

  /* Typography */
  --font-heading: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-body: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --font-brand: "BenchNine", "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Layout */
  --content-width: 960px;
  --reading-width: 650px;
  --gutter: 2rem;

  /* Radii + motion */
  --radius: 8px;
  --radius-sm: 6px;
  --ease: 0.2s ease;
}

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

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

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg);
  padding: 0 var(--gutter);
  max-width: var(--content-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main { flex: 1; padding: 3rem 0; }

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

h1, h2, h3, h4, h5 {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.25;
}

h1 { font-size: 2.25rem; letter-spacing: -0.02em; margin-bottom: 1rem; }
h2 { font-size: 1.75rem; letter-spacing: -0.02em; margin-bottom: 0.75rem; }
h3 { font-size: 1.35rem; letter-spacing: -0.02em; margin-bottom: 0.5rem; }
h4 { font-size: 1.1rem; margin-bottom: 0.5rem; }
h5 { font-size: 1rem; margin-bottom: 0.5rem; }

p { color: var(--text-secondary); margin-bottom: 1.25rem; }
p:last-child { margin-bottom: 0; }

strong, b { font-weight: 600; color: var(--text-primary); }

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

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--accent-light);
  color: var(--text-primary);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

pre {
  background: var(--text-primary);
  color: #f0e9e3;
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-x: auto;
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
}

pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* ---------- Syntax highlighting (Prism tokens) ---------- */

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: #8f8378;
}

.token.punctuation {
  color: #f0e9e3;
}

.token.property,
.token.tag,
.token.constant,
.token.symbol,
.token.deleted {
  color: #f0a08a;
}

.token.boolean,
.token.number {
  color: #8ec9c9;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
  color: #b6cf8a;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string,
.token.variable {
  color: #f0e9e3;
}

.token.atrule,
.token.attr-value,
.token.function {
  color: #e6c884;
}

.token.keyword {
  color: #c9a3c9;
}

.token.regex,
.token.important {
  color: #e6c884;
}

.token.important,
.token.bold {
  font-weight: 600;
}

.token.italic {
  font-style: italic;
}

.token.entity {
  cursor: help;
}

.highlight-line {
  display: inline-block;
  width: 100%;
}

.highlight-line-active {
  background: rgba(243, 227, 225, 0.12);
}

.highlight-line-add {
  background: rgba(182, 207, 138, 0.15);
  text-decoration: none;
}

.highlight-line-remove {
  background: rgba(240, 160, 138, 0.15);
  text-decoration: none;
}

blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 1.25rem;
}

hr { border: none; border-top: 1px solid var(--line); margin: 2rem 0; }

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

ul, ol { margin: 0 0 1.25rem 1.25rem; color: var(--text-secondary); }
li { margin-bottom: 0.35rem; }

/* ---------- Links (underline-grow) ---------- */

.u-link {
  color: var(--accent);
  position: relative;
  text-decoration: none;
}

.u-link::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent);
  transition: width var(--ease);
}

.u-link:hover::after,
.u-link:focus-visible::after { width: 100%; }

.u-link.muted { color: var(--text-muted); }
.u-link.muted::after { background: var(--accent); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-block;
  padding: 0.7rem 1.6rem;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
}

.btn-primary { background: var(--accent); color: #fff; border: 1px solid var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-outline { background: transparent; color: var(--accent); border: 1px solid var(--border); font-weight: 500; }
.btn-outline:hover { border-color: var(--accent); color: var(--accent-hover); }

/* ---------- Header / Nav ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.5rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.site-brand {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.site-nav { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.site-nav > a { font-size: 0.95rem; line-height: 1; color: var(--text-secondary); }
.site-nav > a:hover, .site-nav > a[aria-current="page"] { color: var(--text-primary); }

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  margin-top: 3rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.site-footer p { margin: 0; }

.footer-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.footer-row-main { justify-content: space-between; }

.footer-row-main nav { display: flex; align-items: center; gap: 0.5rem; }

.footer-row-main nav a + a::before {
  content: "·";
  color: var(--line);
  margin-right: 0.5rem;
}

.footer-row-meta { justify-content: space-between; }
.footer-social { display: flex; gap: 0.5rem; }

.footer-brand {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 1.15em;
  line-height: 1;
  color: var(--text-primary);
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  transition: border-color var(--ease);
}

.card:hover { border-color: var(--line); }

.card-title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 1.2rem;
  margin-bottom: 0.35rem;
}

.card-title a { color: var(--text-primary); }
.card-title a:hover { color: var(--accent); }

.card-meta {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.card-excerpt { color: var(--text-secondary); font-size: 0.95rem; }

/* Book cards */
.card-book { display: flex; gap: 1.25rem; align-items: flex-start; }
.card-book .book-cover {
  width: 96px;
  flex-shrink: 0;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.card-book .book-body { flex: 1; }

.rating { color: var(--line); letter-spacing: 0.1em; font-size: 0.95rem; line-height: 1; }
.rating .rating-stars { position: relative; display: inline-block; }
.rating .rating-base { color: var(--line); }
.rating .rating-fill {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  white-space: nowrap;
  color: var(--accent);
}

/* Video cards */
.card-video .video-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  object-fit: cover;
}

/* ---------- Note callout ---------- */

.note {
  padding: 1.25rem 1.5rem;
  background: var(--accent-light);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin: 2rem 0;
}

.note strong { color: var(--text-primary); font-weight: 600; }

/* ---------- Post / Reading ---------- */

.post { max-width: var(--reading-width); }
.post-header { margin-bottom: 2rem; }
.post-meta { font-family: var(--font-mono); font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.post-body > * + * { margin-top: 1.25rem; }
.post-body h2 { margin-top: 2.5rem; }
.post-body h3 { margin-top: 2rem; }
.post-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 2.5rem;
  font-size: 0.9rem;
}

.toc-title {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.toc ul { list-style: none; margin: 0; }
.toc li { margin-bottom: 0.3rem; }
.toc-h3 { padding-left: 1rem; }
.toc a { color: var(--text-secondary); }
.toc a:hover { color: var(--accent); }

/* ---------- Page hero (home) ---------- */

.hero { display: flex; gap: 2.75rem; align-items: center; margin-bottom: 3.5rem; flex-wrap: wrap; }
.hero-photo {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.hero-body { flex: 1; min-width: 260px; }
.hero-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; flex-wrap: wrap; }

.stats {
  list-style: none;
  margin: 1rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.55rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.stats li { margin: 0; }
.stats li + li::before { content: "·"; color: var(--line); margin-right: 0.55rem; }

/* ---------- Contact form ---------- */

.contact-form { display: flex; flex-direction: column; gap: 0.35rem; max-width: 32rem; }
.contact-form label { font-size: 0.875rem; font-weight: 600; color: var(--text-primary); margin-top: 0.75rem; }
.contact-form input,
.contact-form textarea {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  transition: border-color var(--ease);
}
.contact-form input:focus,
.contact-form textarea:focus { border-color: var(--accent); }
.contact-form textarea { resize: vertical; }
.contact-form .btn { margin-top: 1rem; align-self: flex-start; }
.contact-form .botcheck { display: none; }

.section { margin-bottom: 3rem; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 1.25rem;
}
.section-head h2 { margin: 0; font-size: 1.35rem; }

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

.page-title { margin-bottom: 2rem; }
.stack > * + * { margin-top: 1rem; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }

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

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

a:focus-visible,
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 200;
}

.skip-link:focus { left: 0; }

/* ---------- Search ---------- */

.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  transition: border-color var(--ease), color var(--ease);
}

.site-nav .search-trigger { margin-left: 0.5rem; }

.search-trigger:hover { border-color: var(--line); color: var(--text-primary); }

.search-trigger kbd {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
}

.search-modal { position: fixed; inset: 0; z-index: 100; }

.search-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(43, 36, 34, 0.45);
}

.search-modal-panel {
  position: relative;
  max-width: 640px;
  margin: 10vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.25rem 1.25rem;
  box-shadow: 0 18px 50px rgba(43, 36, 34, 0.18);
  max-height: 75vh;
  overflow-y: auto;
}

.search-modal-close {
  position: absolute;
  top: 0.55rem;
  right: 0.85rem;
  padding: 0 0.25rem;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
}

.search-modal-close:hover { color: var(--text-primary); }

/* Pagefind theming */
.search-modal-panel .pagefind-ui {
  --pagefind-ui-primary: var(--accent);
  --pagefind-ui-text: var(--text-primary);
  --pagefind-ui-background: var(--surface);
  --pagefind-ui-border: var(--border);
  --pagefind-ui-border-radius: var(--radius-sm);
  --pagefind-ui-font: var(--font-body);
}

.search-modal-panel .pagefind-ui .pagefind-ui__search-input {
  border: 1px solid var(--border);
  box-shadow: none;
  font-weight: 400;
}

.search-modal-panel .pagefind-ui .pagefind-ui__search-input:focus {
  border-color: var(--accent);
  box-shadow: none;
  outline: 2px solid var(--accent-light);
  outline-offset: 0;
}

/* ---------- Video embed ---------- */

.video-embed {
  position: relative;
  aspect-ratio: 16 / 9;
  margin-bottom: 2.5rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.video-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* ---------- Post share ---------- */

.post-share {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font-size: 0.875rem;
}

.share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  transition: color var(--ease), border-color var(--ease), background var(--ease);
}

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

.share-native { color: var(--accent); border-color: var(--accent-light); }
.share-native:hover,
.share-native:focus-visible { background: var(--accent-light); }

.copy-link.is-copied { color: var(--accent); border-color: var(--accent); }

.share-fallback { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.share-fallback[hidden] { display: none; }

/* ---------- Comments (giscus) ---------- */

.post-comments {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.post-comments h2 { font-size: 1.35rem; margin-bottom: 0.5rem; }

.post-comments-note {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* ---------- Post navigation (newer / older) ---------- */

.post-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.post-nav-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1 1 12rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--ease);
}

a.post-nav-item:hover { border-color: var(--accent); }

.post-nav-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.post-nav-title {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.post-nav-older { text-align: right; align-items: flex-end; }
.post-nav-empty { background: none; border: none; }

/* ---------- Heading copy ---------- */

.post-body h2,
.post-body h3 { position: relative; }

.heading-copy {
  margin-left: 0.4rem;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-muted);
  opacity: 0;
  vertical-align: middle;
  transition: opacity var(--ease), color var(--ease);
}

.post-body h2:hover .heading-copy,
.post-body h3:hover .heading-copy,
.post-body h2:focus-within .heading-copy,
.post-body h3:focus-within .heading-copy { opacity: 1; }

.heading-copy:hover,
.heading-copy:focus-visible { color: var(--accent); }
.heading-copy.is-copied { color: var(--accent); opacity: 1; }

@media (hover: none) {
  .heading-copy { opacity: 1; }
}

/* ---------- Lightbox ---------- */

.post-body img.zoomable { cursor: zoom-in; }

.lightbox {
  border: none;
  padding: 0;
  background: transparent;
  max-width: none;
  max-height: none;
  margin: auto;
  overflow: visible;
}

.lightbox::backdrop { background: rgba(43, 36, 34, 0.75); }

.lightbox-image {
  max-width: 90vw;
  max-height: 90vh;
  width: auto;
  height: auto;
  border-radius: var(--radius);
  cursor: zoom-out;
}

/* ---------- Topics ---------- */

.post-kind {
  display: inline-block;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.5rem;
  margin-bottom: 0.5rem;
}

.topic-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  list-style: none;
  margin: 0.75rem 0 0;
  padding-left: 0;
}

.topic-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
}

.topic-pill:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Image loading ---------- */

img[loading="lazy"] { background: var(--accent-light); }

/* ---------- Reduced motion ---------- */

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

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  body { padding: 0 1.25rem; }
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.4rem; }
  h3 { font-size: 1.2rem; }
  .hero { gap: 1.5rem; }
  .hero-photo { width: 110px; height: 110px; }
  .card-book .book-cover { width: 72px; }
  .site-nav { width: 100%; }
  .site-nav .search-trigger {
    flex: 1 1 100%;
    margin-left: 0;
    justify-content: flex-start;
  }
  .search-trigger kbd { display: none; }
}