/* UI2 — reading pages, content chrome, link states. Tokens: --link* in tokens.css. */

/* —— Links (per-theme tokens; WCAG AA ≥ 4.5 on --bg) —— */
a {
  color: var(--link);
  text-decoration-thickness: from-font;
  text-underline-offset: 0.2em;
  transition: color 160ms ease, text-decoration-color 160ms ease, text-underline-offset 160ms ease;
}
a:hover {
  color: var(--link-hover);
  text-underline-offset: 0.28em;
}
a:visited { color: var(--link-visited); }
a:active { color: var(--link-hover); }
a:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
  border-radius: 4px;
}
a:hover:visited { color: var(--link-hover); }

/* Glossary / thuật ngữ — distinct from body links */
a.term-ref,
.article-body a.term-ref {
  color: var(--seal);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 0.22em;
  font-weight: 600;
}
a.term-ref:hover,
.article-body a.term-ref:hover {
  color: var(--link-hover);
  text-decoration-style: solid;
}
a.term-ref:visited { color: var(--seal); }

@media (prefers-reduced-motion: reduce) {
  a,
  .hub-card,
  .c-card,
  .panel,
  .article-card,
  .article-toc-rail a,
  .button,
  .c-chip,
  .theme-choice,
  .tool-link-btn,
  .footer-chip {
    transition: none !important;
    animation: none !important;
  }
}

/* —— Article typography (research: lichngaytot / Medium / MDN / Smashing) —— */
:root {
  --article-measure: 70ch; /* 65–75ch reading measure */
  --article-body-lh: 1.75; /* Vietnamese diacritics need air */
  --article-h1-size: clamp(1.85rem, 4vw, 2.4rem);
  --article-h2-size: 1.6rem;
  --article-h3-size: 1.28rem;
  --article-heading-lh: 1.35;
}

.article-layout {
  display: block;
  max-width: 100%;
}
.article-main {
  max-width: min(42rem, var(--article-measure));
  margin: 0 auto;
}
.article-page {
  max-width: 100%;
}
.article-body.reading {
  font-size: var(--article-body-size, 1.125rem);
  line-height: var(--article-body-lh);
  max-width: var(--article-measure);
  color: var(--ink);
}
.article-body.reading p { margin: 0 0 1.05rem; }
.article-body h2 {
  font-size: var(--article-h2-size);
  line-height: var(--article-heading-lh);
  margin: 1.85rem 0 0.7rem;
}
.article-body h3 {
  font-size: var(--article-h3-size);
  line-height: var(--article-heading-lh);
  margin: 1.45rem 0 0.55rem;
}
.article-header h1 {
  font-size: var(--article-h1-size);
  line-height: 1.28;
  letter-spacing: -0.01em;
}
.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.35rem;
  align-items: baseline;
  color: var(--muted);
  font-size: 0.95rem;
}
.article-category {
  font-weight: 650;
  color: var(--seal);
}

/* Sticky TOC rail (MDN-style) — desktop */
.article-toc-rail {
  display: none;
}
.article-toc-rail-label {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.article-toc-rail ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
  border-left: 2px solid var(--line);
}
.article-toc-rail li { margin: 0; }
.article-toc-rail a {
  display: block;
  padding: 4px 0 4px 12px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  line-height: 1.35;
  border-left: 2px solid transparent;
  margin-left: -2px;
}
.article-toc-rail a:hover,
.article-toc-rail a:focus-visible {
  color: var(--link-hover);
  border-left-color: var(--seal);
}
.article-toc-rail .toc-level-3 a {
  padding-left: 22px;
  font-size: 0.84rem;
}

@media (min-width: 1100px) {
  .article-layout.has-toc {
    display: grid;
    grid-template-columns: minmax(11rem, 14rem) minmax(0, 42rem);
    gap: 2rem;
    align-items: start;
    justify-content: center;
    max-width: 68rem;
    margin: 0 auto;
  }
  .article-toc-rail {
    display: block;
    position: sticky;
    top: 5.5rem;
    max-height: calc(100vh - 6.5rem);
    overflow: auto;
    padding: 4px 0 12px;
  }
  .article-main { margin: 0; max-width: none; }
  /* Inline Mục lục duplicates the rail on wide screens */
  .article-layout.has-toc .article-toc-heading,
  .article-layout.has-toc .article-body > ol.article-toc {
    display: none;
  }
}

/* Prose elements */
.article-body blockquote {
  margin: 1.15rem 0;
  padding: 0.75rem 1rem 0.75rem 1.1rem;
  border-left: 3px solid var(--seal);
  background: color-mix(in srgb, var(--chip) 55%, transparent);
  border-radius: 0 12px 12px 0;
  color: var(--ink);
}
.article-body blockquote p { margin: 0; }
.article-body ul,
.article-body ol:not(.article-toc) {
  margin: 0 0 1.05rem;
  padding-left: 1.35rem;
}
.article-body li { margin: 0.2rem 0; }
.article-body li::marker { color: var(--seal); }
.article-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  padding: 0.1em 0.35em;
  border-radius: 6px;
  background: color-mix(in srgb, var(--chip) 70%, var(--card));
  border: 1px solid var(--line);
  color: var(--ink);
}
.article-body pre {
  margin: 1rem 0;
  padding: 12px 14px;
  overflow-x: auto;
  border-radius: 12px;
  background: color-mix(in srgb, var(--chip) 55%, var(--card));
  border: 1px solid var(--line);
}
.article-body pre code {
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 0.88rem;
}
.article-body .md-table-wrap {
  margin: 1rem 0 1.25rem;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.article-body .md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.article-body .md-table th,
.article-body .md-table td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.article-body .md-table th {
  font-weight: 650;
  background: color-mix(in srgb, var(--chip) 60%, var(--card));
  color: var(--ink);
}
.article-body .md-table tr:last-child td { border-bottom: 0; }
.article-body .article-figure {
  margin: 1.15rem 0 1.35rem;
}
.article-body .article-figure figcaption {
  margin-top: 0.45rem;
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.45;
}
.article-body .article-toc {
  margin: 0 0 1.35rem;
  padding: 12px 14px 12px 1.4rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--card) 85%, var(--bg));
}

/* Related */
.article-related {
  margin-top: 1.5rem;
  padding: 1rem 1.1rem;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 88%, var(--bg));
}
.article-related h2 {
  font-family: "Source Serif 4", serif;
  font-size: 1.25rem;
  margin: 0 0 0.75rem;
}
.article-related .post-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}
.article-related a {
  font-family: "Source Serif 4", serif;
  font-size: 1.12rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
}
.article-related a:hover {
  color: var(--link-hover);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* Breadcrumbs */
.crumbs a {
  color: var(--muted);
  text-decoration: none;
}
.crumbs a:hover {
  color: var(--link-hover);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.crumbs [aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
}

/* —— Module / tool content chrome —— */
.tool-page .tool-hero,
.hub-page .tool-hero {
  gap: 16px;
  padding: 18px 18px 16px;
}
/* Single border: drop the inset “double frame” that looked like a bug. */
.tool-page .tool-hero,
.hub-page .tool-hero {
  box-shadow: none;
  border: 1px solid color-mix(in srgb, var(--seal) 42%, var(--line));
}
.tool-page .tool-hero h1,
.hub-page .tool-hero h1 {
  letter-spacing: -0.01em;
}
.hub-card,
.c-card.month-card {
  border-radius: 16px;
  min-height: 100px;
}
/* Mobile / inline Mục lục: list like desktop rail (underline only on hover/focus). */
.article-body ol.article-toc {
  list-style: none;
  padding-left: 0;
}
.article-body ol.article-toc li {
  margin: 0;
  border-left: 2px solid var(--line);
}
.article-body ol.article-toc a {
  display: block;
  padding: 6px 0 6px 12px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  line-height: 1.4;
}
.article-body ol.article-toc a:hover,
.article-body ol.article-toc a:focus-visible {
  color: var(--link-hover);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  border-left-color: var(--seal);
}
.empty-card {
  text-align: left;
  gap: 12px;
  padding: 20px 18px;
}
.empty-card h2 {
  margin: 0;
  font-size: 1.25rem;
}
.empty-card p {
  margin: 0;
  color: var(--muted);
  max-width: 42ch;
  line-height: 1.55;
}
.empty-actions {
  margin-top: 4px;
}
.empty-card a.ghost:hover,
.empty-card a.ghost:focus-visible {
  border-color: color-mix(in srgb, var(--seal) 45%, var(--line));
  color: var(--link-hover);
}

/* Theme-consistent card surfaces (light + dark) */
[data-theme="muc"] .empty-card,
[data-theme="dark"] .empty-card,
[data-theme="go"] .empty-card,
[data-theme="thuy"] .empty-card,
[data-theme="muc"] .article-related,
[data-theme="dark"] .article-related,
[data-theme="go"] .article-related,
[data-theme="thuy"] .article-related {
  background: color-mix(in srgb, var(--card) 92%, var(--bg));
}
