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

:where(body, h1, h2, h3, h4, h5, h6, p, figure) {
  margin: 0;
}

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

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

iframe,
embed,
object {
  max-width: 100%;
}

a {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 0.2em;
  transition: text-decoration-color var(--transition-fast);
}

a:hover,
a:focus-visible {
  color: var(--text-primary);
  text-decoration-color: var(--text-primary);
}

a:visited {
  color: var(--text-secondary);
}

a:visited:hover,
a:visited:focus-visible {
  color: var(--text-primary);
  text-decoration-color: var(--text-primary);
}

button {
  font: inherit;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
  cursor: pointer;
}

html {
  font-size: 100%;
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  /* Prefer small viewport height to avoid extra scroll space on mobile */
  min-height: 100vh;
  min-height: 100dvh;
  min-height: 100svh;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-body, var(--font-sans));
  line-height: 1.7;
  font-size: 1rem;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: touch;
}

p {
  max-width: 75ch;
  color: var(--text-secondary);
  margin: 0.75em 0;
}

p:first-child {
  margin-top: 0;
}

p:last-child {
  margin-bottom: 0;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  line-height: 1.3;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

h1:first-child,
h2:first-child,
h3:first-child,
h4:first-child,
h5:first-child,
h6:first-child {
  margin-top: 0;
}

h1 {
  font-size: clamp(2.5rem, 5vw, 3.75rem);
}

h2 {
  font-size: clamp(1.75rem, 3vw, 2.5rem);
  margin-top: 2em;
}

h3 {
  font-size: clamp(1.35rem, 2vw, 1.75rem);
  margin-top: 1.75em;
}

ul,
ol {
  padding-left: 1.625rem;
  margin: 0.75em 0;
  list-style-position: outside;
  color: var(--text-secondary);
}

ul ul,
ol ol,
ul ol,
ol ul {
  margin-top: 0.25em;
  margin-bottom: 0.25em;
}

li {
  margin: 0.25em 0;
  line-height: 1.7;
}

/* Mermaid diagrams */
.mermaid {
  margin: var(--space-lg) 0;
  text-align: center;
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  overflow-x: auto;
}

.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* Code blocks and inline code */
code {
  font-family: var(--font-mono, Monaco, Menlo, monospace);
  font-size: 0.9em;
  padding: 0.2em 0.4em;
  background: var(--code-bg);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}

pre {
  margin: 0.75em 0;
  padding: var(--space-lg);
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow-x: auto;
  line-height: 1.6;
}

pre code {
  padding: 0;
  background: transparent;
  border-radius: 0;
  font-size: 0.9em;
  color: inherit;
  display: block;
}

.highlight {
  background: transparent;
}

.highlight pre {
  margin: 0;
  padding: var(--space-lg);
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.highlighter-rouge {
  margin: var(--space-lg) 0;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-lg) 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

thead {
  background: rgba(128, 128, 128, 0.1);
}

th {
  padding: var(--space-md);
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border-color);
}

td {
  padding: var(--space-md);
  border-bottom: 1px solid color-mix(in srgb, var(--border-color) 30%, transparent);
  color: var(--text-secondary);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(128, 128, 128, 0.05);
}

/* Blockquotes - Notion style */
blockquote {
  margin: 0.75em 0;
  padding: 0;
  padding-left: 1.5em;
  border-left: 3px solid var(--border-color);
  background: transparent;
  border-radius: 0;
  color: var(--text-secondary);
  position: relative;
  font-style: normal;
}

blockquote p {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.7;
}

blockquote p:not(:last-child) {
  margin-bottom: 0.75em;
}

blockquote> :first-child {
  margin-top: 0;
}

blockquote> :last-child {
  margin-bottom: 0;
}

/* Horizontal rules (section dividers) */
hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 2em 0;
  width: 100%;
}

hr+h2,
hr+h3 {
  margin-top: 0.5em;
}

:focus-visible {
  outline: 2px solid var(--grey-4);
  outline-offset: 2px;
}

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

/* Mobile-specific improvements */
@media (width <=600px) {
  body {
    font-size: 0.95rem;
    line-height: 1.6;
  }

  h1 {
    font-size: clamp(1.75rem, 7vw, 2.25rem);
    line-height: 1.3;
    overflow-wrap: break-word;
  }

  .hero__title {
    font-size: clamp(1.5rem, 6vw, 2rem);
    line-height: 1.3;
  }

  h2 {
    font-size: clamp(1.5rem, 6vw, 2rem);
    margin-top: 1.5em;
  }

  h3 {
    font-size: clamp(1.25rem, 5vw, 1.5rem);
    margin-top: 1.25em;
  }

  hr {
    margin: 1.5em 0;
  }

  hr+h2,
  hr+h3 {
    margin-top: 0.5em;
  }

  p {
    max-width: 100%;
  }

  pre {
    padding: var(--space-md);
    font-size: 0.85rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  blockquote {
    padding: 0;
    padding-left: 1.25em;
    margin-inline: 0;
    border-left-width: 2px;
  }

  ul,
  ol {
    padding-left: var(--space-md);
  }

  .mermaid {
    padding: var(--space-md);
    margin: var(--space-md) 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}
