:where(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6) {
  font-weight: 800;
  hyphens: auto;
  letter-spacing: -0.02ch;
  line-height: 1.1;
  margin-block: 0;
  overflow-wrap: break-word;
  text-wrap: balance;
}

:where(h1, h2, h3, h4, h5, h6) {
  display: block;
}

:is(h1, h2, h3, h4, h5, h6) {
  margin-block: 0.65em;
}

:is(h1, .h1) {
  font-size: 2em;
}

:is(h2, .h2) {
  font-size: 1.5em;
}

:is(h3, .h3) {
  font-size: 1.17em;
}

:is(h4, .h4) {
  font-size: 1em;
}

:is(h5, .h5) {
  font-size: 0.83em;
}

:is(h6, .h6) {
  font-size: 0.67em;
}

:is(p, ul, ol, dl, blockquote, pre, figure, table, hr) {
  margin-block: 0.65lh;
  overflow-wrap: break-word;
  text-wrap: pretty;
}

.heading {
  position: relative;
}

.heading__link {
  --hover-size: 0;
  --opacity: 0.5;
  --size: 0.8em;

  background: url("/assets/link-e546a5df.svg") no-repeat center bottom 0.2em;
  background-size: var(--size);
  block-size: 1em;
  color: var(--color-link);
  display: inline-flex;
  font-size: var(--size);
  inline-size: var(--size);
  padding: 1em 0 0;
  opacity: var(--opacity);
  overflow: hidden;
  transition: opacity 300ms ease;
  vertical-align: middle;

  @media (hover: hover) {
    --opacity: 0;

    :is(h1, h2, h3, h4, h5, h6):hover & {
      --opacity: 0.5;
    }
  }

  @media (prefers-color-scheme: dark) {
    filter: invert(1);
  }
}

hr {
  border-color: var(--color-subtle-dark);
  border-style: var(--border-style, solid) none none;
  margin: 2lh auto;
}

b, strong {
  font-weight: 700;
}

:is(pre, code, .pre, .code) {
  background-color: var(--color-subtle-light);
  border: 1px solid var(--color-subtle);
  border-radius: 0.3em;
  font-family: var(--font-mono);
  font-size: 0.85em;
}

pre {
  overflow-x: auto;
  text-wrap: nowrap;
}

code {
  padding: 0.1em 0.3em;
}

:is(pre, .pre) {
  border-radius: 0.5em;
  padding: 0.5lh 2ch;

  :is(code, .code) {
    background-color: transparent;
    border: 0;
    font-size: 1em;
    padding: 0;
  }
}

p {
  hyphens: auto;
  letter-spacing: -0.005ch;
}

html[lang="ko"] p,
html[lang="ko"] :where(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6) {
  hyphens: manual;
  word-break: keep-all;
}

:is(blockquote, .quote) {
  font-style: italic;
  margin: 0 3ch;

  p {
    hyphens: none;
  }
}

table {
  border: 1px solid var(--color-subtle-dark);
  border-collapse: collapse;
  margin: 1lh 0;
}

th {
  font-weight: 700;
}

:where(th, td) {
  border: 1px solid var(--color-subtle-dark);
  padding: 0.2lh 1ch;
  text-align: start;
}

:where(th) {
  border-block-end-width: 3px;
}

/* Lexxy table style presets — mirror the PDF renderer
   (Layout::Table) so the editor + reading view preview the printed
   look. Driven by the data-pdf-table-style attribute on the wrapper
   figure. Default is :zebra (matches Layout::Table::DEFAULT_STYLE).

   Colors: header bg ~ rgb(237 240 245), zebra row ~ rgb(247 247 250)
   — same values the PDF renderer uses (HEADER_BG_RGB / ZEBRA_ROW_RGB
   converted from 0–1 floats to 0–255). */
.lexxy-content__table-wrapper {
  table {
    border-color: rgb(140 148 161);
  }

  :where(th, td) {
    border-color: rgb(140 148 161);
  }

  /* Default = zebra: header bg + alternating body row fills.
     Lexxy puts the header row inside <tbody> with cells classed
     lexxy-content__table-cell--header, NOT inside <thead>. So we
     style header cells via the explicit class, and we tint body
     rows that fall at odd structural positions OTHER THAN the
     first row (which is the header). That mirrors the PDF's
     "second body row, fourth body row, …" pattern. */
  &:not(:has(> table[data-pdf-table-style])):not([data-pdf-table-style]),
  &[data-pdf-table-style="zebra"],
  &:has(> table[data-pdf-table-style="zebra"]) {
    thead :where(th, td),
    tbody .lexxy-content__table-cell--header,
    tbody :where(th):not(.lexxy-content__table-cell--header) {
      background-color: rgb(232 237 245);
    }

    tbody tr:nth-child(odd):not(:first-child) :where(th, td) {
      background-color: rgb(237 239 245);
    }
  }

  /* Grid: full borders + header bg, no zebra fills */
  &[data-pdf-table-style="grid"],
  &:has(> table[data-pdf-table-style="grid"]) {
    thead :where(th, td),
    tbody .lexxy-content__table-cell--header {
      background-color: rgb(232 237 245);
    }

    tbody tr:nth-child(odd):not(:first-child) :where(th, td) {
      background-color: transparent;
    }
  }

  /* Per-table style picker (editor only) — overlay rendered into
     document.body by table_style_picker_controller.js. */
}

/* Editor-only: Lexxy's live DOM has bare <table> (no figure
   wrapper). Same styling rules but anchored on the table itself
   so the editor preview matches the saved/PDF look. */
table[data-pdf-table-style="zebra"] tbody tr:nth-child(odd):not(:first-child) :where(th, td) {
  background-color: rgb(237 239 245);
}
table[data-pdf-table-style="zebra"] thead :where(th, td),
table[data-pdf-table-style="zebra"] tbody .lexxy-content__table-cell--header {
  background-color: rgb(232 237 245);
}
table[data-pdf-table-style="grid"] thead :where(th, td),
table[data-pdf-table-style="grid"] tbody .lexxy-content__table-cell--header {
  background-color: rgb(232 237 245);
}
table[data-pdf-table-style="grid"] tbody tr:nth-child(odd):not(:first-child) :where(th, td) {
  background-color: transparent;
}
table[data-pdf-table-style="minimal"] {
  border-inline: none;
}
table[data-pdf-table-style="minimal"] :where(th, td) {
  border-inline: none;
  border-block-start: none;
}
table[data-pdf-table-style="minimal"] thead :where(th, td),
table[data-pdf-table-style="minimal"] tbody .lexxy-content__table-cell--header {
  background-color: transparent;
  border-block-end-width: 2px;
}

.table-style-picker {
  align-items: center;
  background: white;
  border: 1px solid rgb(140 148 161);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.12);
  display: inline-flex;
  font-size: 12px;
  gap: 4px;
  padding: 4px 8px;
  pointer-events: auto;
  z-index: 1000;
}

.table-style-picker__label {
  color: rgb(80 88 100);
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-inline-end: 6px;
  text-transform: uppercase;
  font-size: 10px;
}

.table-style-picker__btn {
  background: rgb(243 244 246);
  border: 1px solid rgb(209 213 219);
  border-radius: 4px;
  color: rgb(55 65 81);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  text-transform: capitalize;
  transition: background 80ms ease, color 80ms ease;
}

.table-style-picker__btn:hover {
  background: rgb(229 231 235);
  border-color: rgb(156 163 175);
}

.table-style-picker__btn:active {
  transform: translateY(1px);
}

.table-style-picker__btn.is-active {
  background: rgb(37 99 235);
  border-color: rgb(29 78 216);
  box-shadow: 0 0 0 1px rgb(37 99 235);
  color: white;
}

.table-style-picker__btn.is-active:hover {
  background: rgb(29 78 216);
}

.table-style-picker__float {
  align-items: center;
  border-inline-start: 1px solid rgb(209 213 219);
  color: rgb(55 65 81);
  cursor: pointer;
  display: inline-flex;
  font-size: 12px;
  font-weight: 500;
  gap: 4px;
  margin-inline-start: 4px;
  padding-inline-start: 8px;

  &.is-saving {
    opacity: 0.6;
  }
}

.lexxy-content__table-wrapper {
  /* Minimal: only top, bottom, and header-separator lines */
  &[data-pdf-table-style="minimal"] {
    table {
      border-inline: none;
    }

    :where(th, td) {
      border-inline: none;
      border-block-start: none;
    }

    tr:last-child :where(th, td) {
      border-block-end: 1px solid rgb(140 148 161);
    }

    thead :where(th, td) {
      border-block-end-width: 2px;
    }
  }
}

del {
  background-color: oklch(var(--lch-red) / 0.1);
  color: var(--color-negative);
}

ins {
  background-color: oklch(var(--lch-green) / 0.1);
  color: var(--color-positive);
}
