:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --color-bg: #ffffff;
  --color-surface: #f8fafc;
  --color-surface-alt: #eef2f6;
  --color-text: #1a2233;
  --color-muted: #334155;
  --color-border: #e2e8f0;

  --color-primary: #0d9488;
  --color-primary-dark: #0f766e;
  --color-accent: #f59e0b;

  --max-width: 1120px;
  --radius: 10px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* Sticky footer: main grows to fill any leftover space so the footer sits at the
   bottom of the viewport on short pages instead of leaving a blank gap below it. */
main { flex: 1 0 auto; }

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

a { color: var(--color-primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.6em; font-weight: 700; }
h1 { font-size: clamp(1.9rem, 1.4rem + 2vw, 2.75rem); }
h2 { font-size: clamp(1.5rem, 1.2rem + 1vw, 2rem); }
h3 { font-size: 1.25rem; }
p { margin: 0 0 1.2em; }

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem;
}

.prose-container { max-width: 760px; }

/* Header */
.site-header {
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--color-text);
}
.brand:hover { text-decoration: none; }
.brand-logo { height: 32px; width: auto; display: block; }

.nav { display: flex; align-items: center; gap: 1.5rem; }
.nav a { color: var(--color-muted); font-weight: 500; }
.nav a.active, .nav a:hover { color: var(--color-primary-dark); text-decoration: none; }

.nav-toggle {
  display: none;
  background: none;
  border: 0;
  color: var(--color-text);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.nav-search {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.3rem 0.3rem 0.3rem 0.85rem;
}
.nav-search input[type="search"] {
  border: none;
  background: none;
  font: inherit;
  font-size: 0.9rem;
  color: var(--color-text);
  width: 150px;
  min-width: 0;
}
.nav-search input[type="search"]:focus { outline: none; }
.nav-search input[type="search"]::-webkit-search-cancel-button { cursor: pointer; }
.nav-search button {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--color-primary);
  color: #ffffff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-search button:hover { background: var(--color-primary-dark); }

@media (max-width: 720px) {
  .nav {
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--color-bg);
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem 1.25rem;
    gap: 1rem;
    display: none;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 8px 16px rgba(15, 23, 42, 0.06);
  }
  .nav.open { display: flex; }
  .nav-toggle { display: block; }
  .nav-search { width: 100%; }
  .nav-search input[type="search"] { width: 100%; }
}

/* Hero */
.hero {
  background: linear-gradient(135deg, #f0fdfa 0%, #ffffff 55%, #ecfeff 100%);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 4.5rem 0 5rem;
}
.hero h1 { color: var(--color-text); max-width: 32ch; }
.hero .lead { color: var(--color-muted); max-width: 55ch; font-size: 1.1rem; }
.hero-actions { display: flex; gap: 1rem; margin-top: 1.75rem; flex-wrap: wrap; }

.btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-weight: 600;
  border: none;
  cursor: pointer;
  font-size: 1rem;
}
.btn-primary { background: var(--color-accent); color: #1a2233; }
.btn-primary:hover { background: #fbbf24; text-decoration: none; }
.btn-outline { border: 1.5px solid var(--color-border); color: var(--color-text); background: var(--color-bg); }
.btn-outline:hover { background: var(--color-surface); border-color: var(--color-primary); text-decoration: none; }

/* Sections */
.section { padding: 3.5rem 0; }
.section-alt { background: var(--color-surface); }
.section-title { text-align: center; margin-bottom: 2rem; }
.section-title p { color: var(--color-muted); max-width: 60ch; margin: 0 auto; }

/* Cards */
/* auto-fill (not auto-fit): a sparse grid (e.g. 1-2 search results) keeps its
   card at a normal column width instead of stretching to fill the whole row,
   which was cropping thumbnail diagrams down to an unreadable sliver. Grids
   that are already full (7 tutorials across 3-4 columns) look identical
   either way, since there are no empty tracks left to redistribute. */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.5rem;
}
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.section-alt .card { background: var(--color-bg); }
.card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08); }
a.card { display: block; color: inherit; text-decoration: none; }
a.card:hover { text-decoration: none; }
/* object-fit: contain, not cover: cover crops however much is needed to fill
   the box, and how much that is depends on how far each SVG's own aspect
   ratio diverges from the box's, cropping titles/rows off some diagrams while
   leaving others swimming in dead space. contain guarantees the whole diagram
   is always visible, no per-diagram margin tuning needed, at the cost of
   letterboxing (the surface-alt background fills the gap) on either side. */
.card-thumbnail {
  display: block;
  width: calc(100% + 3rem);
  max-width: none; /* the global `img { max-width: 100% }` rule otherwise caps
    this back down, silently cancelling the +3rem bleed and leaving a gap on
    the right edge (the left edge stays flush since the negative margin still
    applies, only the width falls short) */
  aspect-ratio: 2.2;
  margin: -1.5rem -1.5rem 1rem -1.5rem;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
  object-fit: contain;
  object-position: center;
}
.card h3 { margin-bottom: 0.5rem; }
.card .tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--color-primary-dark);
  background: rgba(13, 148, 136, 0.1);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
}

/* Diagram figures (article content). These SVGs are authored at a fixed ~680px
   canvas with text sized for that resolution. Letting them shrink with the
   viewport (the default `img { max-width: 100% }` behavior) makes the embedded
   labels unreadably small on phones. Keep them at native size and let the
   figure scroll horizontally instead, same trade-off already used for the wide
   comparison tables below. */
.prose-card figure {
  margin: 0 0 1.5rem;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.prose-card figure img { max-width: none; }
.prose-card figcaption {
  font-size: 0.9rem;
  color: var(--color-muted);
  margin-top: 0.5rem;
}

/* Tables (article content) */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
  overflow-x: auto;
  display: block;
}
th, td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--color-border);
}
th {
  background: var(--color-surface);
  font-weight: 700;
}
tbody tr:nth-child(even) { background: var(--color-surface); }

/* Code blocks */
pre {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  padding: 1.25rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
}
code {
  font-family: var(--font-mono);
  background: var(--color-surface);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}
pre code { background: none; padding: 0; border: none; }

/* Footer */
/* No margin-top here: .section already has its own bottom padding (3.5rem),
   stacking a separate footer margin on top of that made the gap look doubled. */
.site-footer { background: var(--color-surface); border-top: 1px solid var(--color-border); color: var(--color-muted); padding: 2.5rem 0; }
.footer-grid { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 2rem; }
.footer-brand { color: var(--color-text); }
.footer-blurb { max-width: 32ch; margin-top: 0.5rem; }
.footer-nav { display: flex; gap: 1.25rem; flex-wrap: wrap; align-content: flex-start; }
.footer-nav a { color: var(--color-muted); }
.footer-nav a:hover { color: var(--color-primary-dark); }
.footer-bottom {
  text-align: center;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
}

/* Forms */
.form-field { margin-bottom: 1.25rem; }
.form-field label { display: block; font-weight: 600; margin-bottom: 0.35rem; }
.form-field input,
.form-field textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
}
.form-field textarea { min-height: 140px; resize: vertical; }
.form-success {
  background: rgba(13, 148, 136, 0.1);
  border: 1px solid var(--color-primary);
  color: var(--color-primary-dark);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
}

/* Social link badges (About page) */
.social-links { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.75rem; }
.social-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-weight: 600;
  color: var(--color-text);
}
.social-link:hover { border-color: var(--color-primary); background: var(--color-surface); text-decoration: none; }
.social-icon { width: 20px; height: 20px; flex-shrink: 0; }

/* Utility */
.text-muted { color: var(--color-muted); }
.breadcrumb { font-size: 0.85rem; color: var(--color-muted); margin-bottom: 1rem; }
.breadcrumb a { color: var(--color-muted); }
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-muted);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  margin-top: 2rem;
}
