/* UI1 — shell polish: mega, drawer, article measure, footer.
   Link triad (--link*) lives in tokens.css (UI2). Base link/focus in ui2.css. */

.site-header {
  transition: box-shadow 160ms ease, background-color 160ms ease;
}
.site-header.is-scrolled {
  box-shadow: 0 6px 20px color-mix(in srgb, var(--ink) 10%, transparent);
}
@media (min-width: 801px) {
  .site-header.is-scrolled .header-row {
    box-shadow: 0 10px 28px color-mix(in srgb, var(--ink) 12%, transparent);
  }
  .header-row { position: relative; }
  .site-header.is-mega-open .header-row,
  .site-header:has(.mega[open]) .header-row {
    overflow: visible;
    z-index: 45;
  }
  .nav-group a.is-active,
  .nav-group a[aria-current="page"] {
    background: color-mix(in srgb, var(--seal) 14%, var(--card));
    color: var(--ink);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--seal) 35%, var(--line));
  }
}

.mega-backdrop {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: color-mix(in srgb, var(--ink) 28%, transparent);
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
}
.mega-backdrop[hidden] { display: none !important; }

.drawer-open {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
}

/* Default mark-icon size — without this, SVGs with only a viewBox fill the
   page column (~1080px) on hubs that do not load tools.css (platform-home). */
.mark-icon {
  width: 24px;
  height: 24px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  overflow: visible;
}
.tool-mark {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--seal);
}
.tool-mark .mark-icon { width: 28px; height: 28px; }

/* Mega disclosure — full header-row width, fixed 4-col ≥1100 */
.mega-panel {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.mega[open] > .mega-panel {
  opacity: 1;
  transform: none;
}
.mega summary[aria-expanded="true"] .icon {
  transform: rotate(180deg);
}
.mega summary .icon { transition: transform 160ms ease; }
.mega-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(240px, 1fr));
  gap: 14px 16px;
  align-items: start;
  width: 100%;
}
.mega-group {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.mega-group h2 {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  font-size: 0.92rem;
  margin: 0 0 8px;
  line-height: 1.25;
  min-width: 0;
}
.mega-group-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--chip) 80%, var(--card));
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--seal);
}
.mega-group-icon .mark-icon {
  width: 16px;
  height: 16px;
  stroke-width: 1.75;
}
.mega-group-copy { display: grid; gap: 2px; min-width: 0; }
.mega-group-name {
  font-family: "Source Serif 4", serif;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mega-group-lead {
  display: block;
  font-size: 0.75rem;
  font-weight: 450;
  color: var(--muted);
  line-height: 1.3;
}
.mega-panel ul { gap: 2px; }
.mega-link {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 6px 6px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 500;
  min-height: 40px;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}
.mega-link:hover,
.mega-link:focus-visible {
  background: color-mix(in srgb, var(--chip) 70%, var(--card));
  color: var(--ink);
  text-decoration: none;
}
.mega-link:visited { color: var(--ink); }
.mega-link-icon {
  width: 28px;
  height: 28px;
  color: var(--seal);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.mega-link-icon .mark-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
}
.mega-link-text {
  display: grid;
  gap: 2px;
  min-width: 0;
  max-width: 100%;
  align-content: start;
  overflow: hidden;
}
.mega-link-text strong {
  font-weight: 600;
  font-size: 0.88rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.mega-lead {
  display: block;
  font-size: 0.74rem;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.mega-footer {
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  text-align: right;
}
.mega-footer a {
  font-weight: 650;
  color: var(--link);
  text-decoration: none;
}
.mega-footer a:hover { text-decoration: underline; }
@media (max-width: 1099px) and (min-width: 900px) {
  .mega-grid { grid-template-columns: repeat(3, minmax(200px, 1fr)); }
}
@media (max-width: 899px) and (min-width: 769px) {
  .mega-grid { grid-template-columns: repeat(2, minmax(200px, 1fr)); }
}

/* Mobile drawer */
.nav-drawer {
  width: min(100%, 420px);
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0 0 0 auto;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
}
.nav-drawer::backdrop {
  background: color-mix(in srgb, var(--ink) 42%, transparent);
}
.nav-drawer[open] {
  animation: ui1-drawer-in 180ms ease;
}
@keyframes ui1-drawer-in {
  from { transform: translateX(12px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}
.nav-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 1;
}
.nav-drawer-head button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  padding: 0 14px;
  font: inherit;
  font-weight: 600;
}
.nav-drawer-body {
  padding: 8px 12px 28px;
  overflow: auto;
  max-height: calc(100% - 64px);
}
.drawer-section {
  margin: 10px 0 14px;
  padding: 10px 10px 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--card) 88%, var(--bg));
}
.drawer-section h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 0.98rem;
}
.drawer-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--chip);
  color: var(--seal);
  border: 1px solid var(--line);
}
.drawer-icon .mark-icon {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
}
.drawer-section ul {
  list-style: none;
  margin: 0;
  padding: 0 0 6px;
  display: grid;
  gap: 2px;
}
.drawer-section a {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 6px 8px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 500;
}
.drawer-section a:hover,
.drawer-section a:focus-visible {
  background: color-mix(in srgb, var(--chip) 75%, transparent);
  color: var(--ink);
}

@media (max-width: 800px) {
  .drawer-open { display: inline-flex; }
  .header-row .drawer-open { order: 5; }
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--chip) 35%, var(--bg));
  padding-top: 32px;
}
.footer-grid {
  grid-template-columns: minmax(180px, 1.2fr) repeat(4, minmax(120px, 1fr));
  gap: 16px 20px;
}
.footer-brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  margin-bottom: 8px;
}
.footer-brand-link .mark,
.footer-brand-link .mark svg { width: 32px; height: 32px; }
.footer-brand-link strong {
  font-family: "Source Serif 4", serif;
  font-size: 1.05rem;
}
.footer-tagline {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 28ch;
}
.footer-theme-grid {
  display: grid;
  grid-template-columns: repeat(5, 28px);
  gap: 6px;
}
.footer-theme-swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}
.footer-theme-swatch .swatch {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  font-size: 0;
}
.footer-theme-swatch[aria-pressed="true"] {
  outline: 2px solid var(--seal);
  outline-offset: 1px;
  box-shadow: 0 0 0 1px var(--card);
}
.footer-theme-swatch[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 2px var(--seal);
  pointer-events: none;
}
.footer-store {
  display: grid;
  gap: 8px;
  justify-items: start;
}
.store-badge {
  display: inline-block;
  line-height: 0;
  border-radius: 8px;
  text-decoration: none;
  overflow: hidden;
  border: 0;
  background: transparent;
  padding: 0;
}
.store-badge img {
  display: block;
  width: 155px;
  height: 46px;
  max-width: 100%;
}
.store-badge:hover,
.store-badge:focus-visible {
  outline: 2px solid var(--seal);
  outline-offset: 2px;
}
.footer-copy {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}
.footer-col {
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0;
}
@media (max-width: 900px) {
  .footer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.footer-col > summary {
  list-style: none;
  cursor: default;
  font-family: "Source Serif 4", serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 8px;
}
.footer-col > summary::-webkit-details-marker { display: none; }
.footer-col ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.footer-col a {
  color: var(--ink);
  text-decoration: none;
}
.footer-col a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}
.footer-prefs { margin-top: 12px; }
.footer-prefs-label {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: var(--muted);
}
.footer-prefs-row { display: flex; flex-wrap: wrap; gap: 6px; }
.footer-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.footer-chip:hover,
.footer-chip:focus-visible {
  border-color: color-mix(in srgb, var(--seal) 45%, var(--line));
  color: var(--ink);
  text-decoration: none;
}
.footer-chip.is-on {
  background: color-mix(in srgb, var(--seal) 12%, var(--card));
  border-color: color-mix(in srgb, var(--seal) 40%, var(--line));
}
.footer-note p:first-child { color: var(--muted); max-width: 68ch; }

@media (max-width: 700px) {
  .footer-col {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: color-mix(in srgb, var(--card) 70%, var(--bg));
    padding: 4px 12px 8px;
  }
  .footer-col > summary {
    cursor: pointer;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0;
  }
  .footer-col > summary::after {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
    transition: transform 160ms ease;
  }
  .footer-col[open] > summary::after {
    transform: rotate(225deg);
  }
  .footer-col:not([open]) ul,
  .footer-col:not([open]) .footer-prefs { display: none; }
  .footer-col[open] { padding-bottom: 12px; }
}

/* Articles + shared page headers — measure/TOC/related refined in ui2.css */
.article-body.reading,
.article-excerpt {
  max-width: var(--article-measure);
}
.tool-hero, .tool-head, .article-header, .page-head {
  margin-bottom: 1rem;
}
.hub-card, .c-card, .panel, .article-card {
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}
.hub-card:hover, .c-card:hover, a.hub-card:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--ink) 8%, transparent);
  border-color: color-mix(in srgb, var(--seal) 35%, var(--line));
}
.hub-card:active, .button:active, .theme-choice:active, .footer-chip:active {
  transform: translateY(0);
}
.button, .c-chip, .theme-choice, .tool-link-btn {
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 100ms ease;
}

.md-table th, .md-table td {
  border-color: color-mix(in srgb, var(--ink) 14%, transparent);
}
[data-theme="muc"] .md-table th,
[data-theme="dark"] .md-table th,
[data-theme="go"] .md-table th,
[data-theme="thuy"] .md-table th {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

@media (prefers-reduced-motion: reduce) {
  .mega-panel,
  .nav-drawer[open],
  .hub-card,
  .c-card,
  .panel,
  .mega summary .icon {
    transition: none !important;
    animation: none !important;
  }
}
