/*
 * Public / preview rendering styles for Action Text (Lexxy) content.
 * Keep editor chrome in lexxy.css; this file styles published HTML.
 */

.field-site .article-body {
  --lexxy-color-ink: var(--field-reading);
  --lexxy-color-ink-medium: var(--field-muted);
  --lexxy-color-ink-light: var(--field-subtle);
  --lexxy-color-ink-lighter: var(--field-line);
  --lexxy-color-ink-lightest: var(--field-paper-muted);
  --lexxy-color-text: var(--field-reading);
  --lexxy-color-text-subtle: var(--field-muted);
  --lexxy-color-link: var(--field-accent-dark);
  --lexxy-color-code-bg: var(--field-paper-muted);
  --lexxy-color-table-header-bg: var(--field-paper-tint);
  --lexxy-color-table-cell-border: var(--field-line);

  /* The gem declares these once on :root using its own light-theme
     defaults; commit 50f32a6's dark-mode remap only covered the
     --field-*-derived variables above and missed these. Light values
     below also correct several that failed WCAG AA 4.5:1 as shipped
     (att/comment/operator/selector/variable) -- computed against
     --field-paper-muted, the code background these tokens render on. */
  --lexxy-color-code-token-att: #c0341f;
  --lexxy-color-code-token-comment: #5b6472;
  --lexxy-color-code-token-function: #6f42c1;
  --lexxy-color-code-token-operator: #c0341f;
  --lexxy-color-code-token-property: #005cc5;
  --lexxy-color-code-token-punctuation: #3a4452;
  --lexxy-color-code-token-selector: #166e2e;
  --lexxy-color-code-token-variable: #a34c02;
}

@media (prefers-color-scheme: dark) {
  .field-site .article-body {
    --lexxy-color-code-token-att: #ff7b72;
    --lexxy-color-code-token-comment: #9aa7b8;
    --lexxy-color-code-token-function: #d2a8ff;
    --lexxy-color-code-token-operator: #ff7b72;
    --lexxy-color-code-token-property: #79c0ff;
    --lexxy-color-code-token-punctuation: #c9d1d9;
    --lexxy-color-code-token-selector: #7ee787;
    --lexxy-color-code-token-variable: #ffa657;
  }
}

.article-body,
.lexxy-content {
  line-height: 1.82;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  overflow-x: clip;
}

.article-body *,
.lexxy-content * {
  box-sizing: border-box;
}

.article-body > *:first-child,
.lexxy-content > *:first-child {
  margin-top: 0;
}

.article-body > *:last-child,
.lexxy-content > *:last-child {
  margin-bottom: 0;
}

.article-body p,
.lexxy-content p {
  margin: 1em 0;
}

.article-body h2,
.lexxy-content h2 {
  margin: 1.75em 0 0.6em;
  font-family: var(--field-serif);
  font-size: 1.65rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--field-ink);
}

.article-body h3,
.lexxy-content h3 {
  margin: 1.5em 0 0.5em;
  font-family: var(--field-serif);
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--field-ink);
}

.article-body h4,
.lexxy-content h4 {
  margin: 1.25em 0 0.4em;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--field-ink);
}

.article-body ul,
.article-body ol,
.lexxy-content ul,
.lexxy-content ol {
  margin: 1em 0;
  padding-left: 1.5em;
}

.article-body li,
.lexxy-content li {
  margin: 0.35em 0;
}

.article-body blockquote,
.lexxy-content blockquote {
  margin: 1.25em 0;
  padding-left: 1em;
  border-left: 2px solid var(--field-accent);
  color: var(--field-muted);
}

.article-body a,
.lexxy-content a {
  color: var(--field-accent-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.article-body pre,
.lexxy-content pre {
  display: block;
  max-width: 100%;
  margin: 1.25em 0;
  padding: 0.85em 1em;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
  line-height: 1.5;
  white-space: pre;
  background-color: var(--field-paper-muted);
  border-radius: 0.375rem;
}

.article-body code,
.lexxy-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
}

.article-body :not(pre) > code,
.lexxy-content :not(pre) > code {
  padding: 0.1em 0.35em;
  background-color: var(--field-paper-muted);
  border-radius: 0.25rem;
}

/* Mobile-friendly tables: horizontal scroll instead of layout blowout.
   display:block on <table> works for scrolling but strips its implicit
   ARIA table/row/cell roles, so header/cell association becomes invisible
   to screen readers even though the sanitizer allows scope/headers through
   (config/initializers/action_text.rb). public.js wraps each table in
   .field-table-scroll on boot; wrapped tables get their real display back
   below. This rule stays the fallback for no-JS and the brief pre-boot
   window, matching this file's normal display:block behavior today. */
.article-body table,
.lexxy-content table {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 1.5em 0;
  overflow-x: auto;
  border-collapse: collapse;
}

.field-table-scroll {
  max-width: 100%;
  margin: 1.5em 0;
  overflow-x: auto;
}

.field-table-scroll table {
  display: table;
  width: auto;
  min-width: 100%;
  max-width: none;
  margin: 0;
  overflow-x: visible;
}

.article-body thead,
.lexxy-content thead {
  background-color: var(--field-paper-tint);
}

.article-body th,
.article-body td,
.lexxy-content th,
.lexxy-content td {
  padding: 0.6em 0.85em;
  border: 1px solid var(--field-line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.article-body th,
.lexxy-content th {
  font-weight: 600;
  color: var(--field-ink);
  background-color: var(--field-paper-tint);
}

.article-body img,
.article-body video,
.article-body iframe,
.lexxy-content img,
.lexxy-content video,
.lexxy-content iframe {
  max-width: 100%;
  height: auto;
}

.article-body figure,
.lexxy-content figure {
  display: block;
  max-width: 100%;
  margin: 1.5em 0;
}

.article-body figure img,
.article-body figure iframe,
.lexxy-content figure img,
.lexxy-content figure iframe {
  display: block;
  max-width: 100%;
  height: auto;
}

.article-body figcaption,
.lexxy-content figcaption {
  margin-top: 0.5em;
  font-size: 0.9em;
  color: var(--field-muted);
  text-align: center;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.article-body .attachment,
.lexxy-content .attachment {
  display: inline-block;
  position: relative;
  max-width: 100%;
}

.article-body .attachment--preview,
.lexxy-content .attachment--preview {
  width: 100%;
  text-align: center;
}

.article-body .attachment__caption,
.lexxy-content .attachment__caption {
  margin-top: 0.4em;
  font-size: 0.9em;
  color: var(--field-muted);
  text-align: center;
}

/*
 * Table of contents.
 *
 * The block reuses the .field-topic-facts treatment (border, radius, tinted
 * paper) rather than introducing a surface of its own -- it sits in the same
 * reading column and should read as the same kind of aside. Links are left to
 * inherit `.article-body a` so a theme change moves both together.
 */
.article-toc {
  margin: clamp(1.75rem, 4vw, 2.5rem) 0;
  padding: 1.1rem 1.4rem;
  border: 1px solid var(--field-line);
  border-radius: var(--field-radius);
  background: var(--field-paper-tint);
}

.article-toc__title {
  margin: 0 0 0.35rem;
  color: var(--field-muted);
  font-family: var(--field-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.article-toc__list,
.article-toc__list ol {
  margin: 0;
  padding-left: 1.15rem;
}

.article-toc__list ol {
  margin-top: 0.1rem;
}

.article-toc__list li {
  margin: 0;
  padding: 0;
}

/* A vertical list of navigation links, so it follows .field-language-menu__item
   rather than in-prose link sizing: 44px rows, per DESIGN.md's target rule. */
.article-toc__list a {
  display: flex;
  min-height: 2.75rem;
  align-items: center;
  padding-block: 0.25rem;
  line-height: 1.4;
}

/* Long lists must not push the article itself off the first screen on a phone.
   18rem is about six rows, enough to show the shape of the guide before the
   reader decides to scroll inside it. */
@media (max-width: 47.99rem) {
  .article-toc__list {
    max-height: 18rem;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* The sticky header is 4.25rem plus its border (4rem below 48rem), so an anchor
   jump would land under it without this. Same value as .field-guides. */
.article-body h2[id],
.article-body h3[id] {
  scroll-margin-top: 5.25rem;
}

/*
 * Editor-side placeholder. The in-form preview injects the editor's own HTML,
 * where the block is still the bare marker div, so there is nothing to see
 * without this. It cannot match on a published page: the presenter either
 * replaces the marker with the nav or removes it, and neither leaves an empty
 * element behind. Korean is written directly because this only ever renders
 * inside the CMS.
 */
#table-of-contents:empty {
  display: block;
  margin: clamp(1.75rem, 4vw, 2.5rem) 0;
  padding: 1.1rem 1.4rem;
  border: 1px dashed var(--field-line);
  border-radius: var(--field-radius);
  background: var(--field-paper-tint);
  color: var(--field-muted);
}

#table-of-contents:empty::before {
  content: "목차";
  display: block;
  font-family: var(--field-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#table-of-contents:empty::after {
  content: "본문 H2·H3에서 자동 생성됩니다 (2개 이상일 때 표시)";
  display: block;
  margin-top: 0.35rem;
  font-size: 0.85rem;
}

/* Shared by the reader, body preview and Lexxy's YouTube decorator. */
.seoulized-youtube-player { width: 100%; min-width: 0; margin-block: 1.5rem; }
.seoulized-youtube-player iframe,
.lexxy-content .seoulized-youtube-player iframe {
  display: block;
  width: 100%;
  height: auto;
  min-height: 200px;
  aspect-ratio: 16 / 9;
  border: 0;
}
.seoulized-youtube-player a { display: inline-block; overflow-wrap: anywhere; margin-top: .5rem; }
.seoulized-youtube-editor button {
  display: inline-block;
  min-height: 44px;
  padding: .5rem .75rem;
  margin: .5rem .5rem 0 0;
  border: 1px solid currentColor;
  border-radius: .25rem;
  background: transparent;
  cursor: pointer;
}
.seoulized-youtube-editor button:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

.seoulized-youtube-editor--selected { outline: 2px solid currentColor; outline-offset: 3px; }

@media (max-width: 400px) {
  #article-body-edit-panel { padding-inline: 0; }
  #article-body-preview-panel { padding-inline: .5rem; }
}
