/* ============================================================================
   Knots 3D — Phase 6 look & feel design system (standalone stylesheet)
   Editorial, dark-first, brand-gold accent. Replaces the Bootstrap 2 / launched
   stack for rebuilt page types. Tokens + [data-mode] theming + components,
   translated from the approved mockups (spec v4, §3–§6).
   Dark is the :root default; light via [data-mode="light"] (script) OR the no-JS
   prefers-color-scheme fallback below.
   ============================================================================ */

/* ---- Design tokens: DARK (default) ---- */
:root {
  --ground:#1B1A17;   --ink:#ECE6D8;      --muted:#A69D8B;
  --surface:#232220;  --hair:#33312C;
  --chrome:#0F0F0E;   --chrome-ink:#ECE6D8;
  --primary:#D4A017;  --primary-solid:#D4A017; --primary-ink:#1E1A10; --secondary:#CBA24C;
  --warn:#E4594E;

  --sans:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  --wrap:1040px;
  --nav-h:52px;
  --radius:6px;
  color-scheme: dark;
}

/* ---- Design tokens: LIGHT (explicit, set by the no-FOUC script) ---- */
[data-mode="light"] {
  --ground:#FAF6EC;   --ink:#23211D;      --muted:#6E675C;
  --surface:#FFFFFF;  --hair:#E7E0D1;
  --chrome:#2C2A26;   --chrome-ink:#EFEBE2;
  --primary:#996515;  --primary-solid:#D4A017; --primary-ink:#241D08; --secondary:#996515;
  --warn:#B0282C;
  color-scheme: light;
}

/* ---- No-JS fallback: honor OS preference when the script never runs ---- */
@media (prefers-color-scheme: light) {
  :root:not([data-mode]) {
    --ground:#FAF6EC;   --ink:#23211D;      --muted:#6E675C;
    --surface:#FFFFFF;  --hair:#E7E0D1;
    --chrome:#2C2A26;   --chrome-ink:#EFEBE2;
    --primary:#996515;  --primary-solid:#D4A017; --primary-ink:#241D08; --secondary:#996515;
    --warn:#B0282C;
    color-scheme: light;
  }
}

/* ---- Reset / base ---- */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--ground); }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 2px; }
h1, h2, h3, h4 { font-family: var(--sans); }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 22px; }

/* Body prose renders in --ink (product content); muted is metadata only (§10.1). */

/* ---- Top navigation (chrome bar, always sticky) ---- */
.sticky-head { position: sticky; top: 0; z-index: 40; }
.topnav {
  position: relative;
  z-index: 2;
  background: var(--chrome);
  color: var(--chrome-ink);
}
/* Bars are full-bleed; their content is width-aligned with the page body (§W-9). */
.bar-inner { max-width: var(--wrap); margin: 0 auto; padding: 12px 22px; display: flex; align-items: center; gap: 16px; }
.topnav .bar-inner { gap: 18px; min-height: var(--nav-h); }
.titlebar .bar-inner { padding: 18px 22px 15px; }
.cat-title .bar-inner { padding: 20px 22px 18px; }
.condbar .bar-inner { padding: 9px 22px; gap: 14px; }
[id] { scroll-margin-top: calc(var(--nav-h) + 52px); }
.ic { display: block; width: 20px; height: 20px; }
.nav-burger { display: none; background: transparent; border: 0; color: var(--chrome-ink); cursor: pointer; padding: 5px; border-radius: 6px; align-items: center; }
.nav-burger:hover { background: color-mix(in srgb, var(--chrome-ink) 10%, transparent); }
.topnav__logo {
  display: inline-flex; align-items: stretch; flex: none;
  border-radius: 5px; overflow: hidden;
  font-weight: 800; letter-spacing: .05em; font-size: 12.5px; text-transform: uppercase;
  white-space: nowrap;
}
.topnav__logo:hover { text-decoration: none; }
.topnav__logo .d3 {
  background: var(--primary-solid); color: var(--primary-ink);
  font-weight: 800; font-size: 9px; padding: 2px 4px; border-radius: 3px;
}
/* Two-tone wordmark badge: white text on the complete-list red ("Knots") + gold ("3D") */
.topnav__logo .lm-word { background: #8B2500; color: #fff; padding: 4px 8px; display: inline-flex; align-items: center; }
/* Darker gold than --primary-solid so white "3D" clears WCAG AA (4.79:1 vs 2.38:1).
   Scoped to the wordmark badge only — other gold accents keep the brighter --primary-solid. */
.topnav__logo .lm-3d { background: #906D10; color: #fff; padding: 4px 8px; display: inline-flex; align-items: center; }
.topnav__links { display: flex; gap: 4px; align-items: center; }
.topnav__tools { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* Nav dropdowns (accessible disclosure, CSS + tiny JS) */
.navmenu { position: relative; }
.navmenu > button {
  border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 700;
  color: color-mix(in srgb, var(--chrome-ink) 88%, transparent);
  padding: 7px 10px; border-radius: 5px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
}
.navmenu > button:hover { color: var(--chrome-ink); background: color-mix(in srgb, var(--chrome-ink) 10%, transparent); }
.navmenu > button .caret, .lang-select > button .caret { font-size: 18px; opacity: .85; line-height: 1; }
.navmenu[aria-current="page"] > button, .navmenu.is-current > button {
  color: var(--chrome-ink); border-bottom: 2px solid var(--primary); border-radius: 5px 5px 0 0;
}
.navmenu__panel {
  position: absolute; top: 100%; left: 0; margin-top: 4px; z-index: 50;
  min-width: 200px; max-height: 70vh; overflow: auto;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--hair); border-radius: 8px;
  box-shadow: 0 18px 40px -20px rgba(0,0,0,.55);
  padding: 6px; display: none;
}
.navmenu__panel.is-open { display: block; }
.navmenu__panel a {
  display: block; padding: 7px 10px; border-radius: 5px;
  font-size: 13px; color: var(--ink);
}
.navmenu__panel a:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); text-decoration: none; }
.navmenu__sep { height: 1px; margin: 5px 6px; background: var(--hair); }

/* Expandable nav search: magnifier reveals a text box to its left; Enter/submit
   routes to the complete-list page with ?search=, which filters there. */
.nav-search { display: flex; align-items: center; }
.nav-search__input {
  width: 0; min-width: 0; padding: 0; border: 0; margin: 0;
  background: color-mix(in srgb, var(--chrome-ink) 12%, transparent);
  color: var(--chrome-ink); font: inherit; font-size: 13px; line-height: 1.2;
  border-radius: 999px; opacity: 0; outline: none;
  transition: width .25s ease, padding .25s ease, opacity .2s ease;
}
.nav-search__input::placeholder { color: color-mix(in srgb, var(--chrome-ink) 55%, transparent); }
.nav-search.is-open .nav-search__input { width: 190px; padding: 6px 12px; opacity: 1; }
.nav-search__btn {
  background: transparent; border: 0; cursor: pointer; padding: 5px; border-radius: 6px;
  display: inline-flex; align-items: center;
  color: color-mix(in srgb, var(--chrome-ink) 78%, transparent);
}
.nav-search__btn:hover { color: var(--chrome-ink); background: color-mix(in srgb, var(--chrome-ink) 12%, transparent); }

/* Complete-list / category filter box (reads ?search= from the nav, then live-filters) */
.knot-filter { margin-bottom: 14px; }
.knot-filter input {
  width: 100%; max-width: 340px; padding: 9px 15px; font: inherit; font-size: 14px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--hair); border-radius: 999px; outline: none;
}
.knot-filter input::placeholder { color: var(--muted); }
.knot-filter input:focus-visible { border-color: var(--primary); outline: 2px solid var(--primary); outline-offset: 1px; }

/* Theme toggle */
.mode-toggle {
  background: transparent; border: 0; cursor: pointer; padding: 5px; border-radius: 6px;
  display: inline-flex; align-items: center;
  color: color-mix(in srgb, var(--chrome-ink) 78%, transparent);
}
.mode-toggle:hover { color: var(--chrome-ink); background: color-mix(in srgb, var(--chrome-ink) 12%, transparent); }
.mode-toggle svg { width: 20px; height: 20px; }

/* Language selector (far right) — server-rendered <a> list in a disclosure */
.lang-select { position: relative; display: flex; align-items: center; }
.lang-select > button {
  border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 700; line-height: 1;
  color: color-mix(in srgb, var(--chrome-ink) 88%, transparent);
  padding: 5px 6px; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; white-space: nowrap;
}
.lang-select > button:hover { color: var(--chrome-ink); }
.lang-select .navmenu__panel { left: auto; right: 0; }

/* ---- Two-layer sticky title bar (CLS-safe, spec §6a) ----
   .titlebar: full title block, NORMAL FLOW — scrolls away (never a layout shift).
   .condbar: compact one-line bar, absolutely positioned just below the nav and
   hidden behind it (translateY(-100%)); revealed via transform on .is-condensed
   (an IntersectionObserver sentinel toggles it). No height/font animation → no CLS. */
.titlebar {
  background: var(--ground);
  border-bottom: 1px solid var(--hair);
}
.titlebar__meta { min-width: 0; }
.breadcrumb { font-size: 11.5px; color: var(--muted); letter-spacing: .03em; text-transform: uppercase; margin: 0 0 9px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { opacity: .5; }
.breadcrumb b, .breadcrumb .cur { color: var(--primary); font-weight: 700; }
.page-title { font-weight: 800; letter-spacing: -.015em; line-height: 1.08; font-size: 34px; margin: 0 0 4px; }
.page-sub { font-size: 12.5px; color: var(--muted); margin: 0; white-space: nowrap; text-overflow: ellipsis; }

.condbar {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 1;
  transform: translateY(-100%);
  visibility: hidden;
  background: var(--ground);
  border-bottom: 1px solid var(--hair);
  box-shadow: 0 10px 22px -16px rgba(0,0,0,.6);
}
.condbar__title { font-weight: 800; font-size: 20px; letter-spacing: -.01em; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sticky-head.is-condensed .condbar { transform: translateY(0); visibility: visible; }
@media (prefers-reduced-motion: no-preference) {
  .condbar { transition: transform .22s ease, visibility 0s .22s; }
  .sticky-head.is-condensed .condbar { transition: transform .22s ease, visibility 0s 0s; }
}

/* ---- Condense-on-scroll morph (matches the POC): the sticky title bar shrinks in
   place — breadcrumb + sub-line collapse, title + icon shrink, padding tightens.
   This changes header height on scroll (an accepted, measured CLS tradeoff for the
   in-place feel). ---- */
.breadcrumb, .page-sub, .cat-sub, .cat-count { max-height: 2em; overflow: hidden; }
.sticky-head.is-condensed .breadcrumb,
.sticky-head.is-condensed .page-sub,
.sticky-head.is-condensed .cat-sub,
.sticky-head.is-condensed .cat-count { max-height: 0; opacity: 0; margin-top: 0; margin-bottom: 0; }
.sticky-head.is-condensed .page-title,
.sticky-head.is-condensed .cat-title h1 { font-size: 22px; }
.sticky-head.is-condensed .titlebar .bar-inner,
.sticky-head.is-condensed .cat-title .bar-inner { padding-top: 10px; padding-bottom: 10px; }
.sticky-head.is-condensed .caticon { width: 42px; height: 42px; }
.sticky-head.is-condensed .caticon img { padding: 1px; }
/* Transitions are ALWAYS on (not gated by prefers-reduced-motion) so the condense eases
   smoothly even if the OS "Reduce Motion" setting is on — matches the POC. The morph is
   subtle and non-essential, so animating it regardless is acceptable. */
.titlebar .bar-inner, .cat-title .bar-inner { transition: padding .22s ease; }
.page-title, .cat-title h1 { transition: font-size .22s ease; }
.caticon { transition: width .22s ease, height .22s ease; }
.caticon img { transition: padding .22s ease; }
.breadcrumb, .page-sub, .cat-sub, .cat-count { transition: max-height .22s ease, opacity .18s ease, margin .22s ease; }

/* App CTA pill (title bar / condensed bar) */
.pill {
  margin-left: auto; flex: none;
  border: 1px solid color-mix(in srgb, var(--primary) 55%, var(--hair));
  color: var(--ink); background: transparent;
  font-size: 12.5px; font-weight: 700; padding: 8px 15px; border-radius: 999px;
  white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.pill:hover { text-decoration: none; border-color: var(--primary); }
.pill .star { color: var(--secondary); }

/* ---- Content grids (knot page, §6a) ---- */
.knot-body { padding: 18px 22px 26px; }
.top-grid {
  display: grid; grid-template-columns: 1fr 300px; gap: 15px; align-items: stretch; margin-bottom: 15px;
  grid-template-areas: "media getapp" "media details";
}
.bot-grid { display: grid; grid-template-columns: 1fr 300px; gap: 15px; align-items: start; }
.col-main, .col-side { display: flex; flex-direction: column; gap: 15px; min-width: 0; }
.area-media   { grid-area: media; }
.area-getapp  { grid-area: getapp; }
.area-details { grid-area: details; }

/* ---- Cards ---- */
.card { border: 1px solid var(--hair); border-radius: var(--radius); background: var(--surface); padding: 15px 17px; }
.card-head {
  margin: 0 0 11px; font-weight: 700; font-size: 12px; letter-spacing: .13em;
  text-transform: uppercase; color: var(--ink);
}
.card p { font-size: 15px; color: var(--ink); line-height: 1.62; margin: 0; }
/* Article card: stacked sections with hairline dividers between them (§6a) */
.article .card-head:not(:first-child) { margin-top: 18px; padding-top: 15px; border-top: 1px solid var(--hair); }
/* Landing overview (Show more): match the knot-detail Details/article treatment — a hairline
   divider above every section header (incl. the first, to separate it from the welcome intro),
   same 18px/15px/hair spacing as .article. */
.collapsible .card-head { margin-top: 18px; padding-top: 15px; border-top: 1px solid var(--hair); }
/* Rich-text content fields (knot.usage/history/structure/strength/note render raw HTML) */
.prose { font-size: 13.5px; color: var(--ink); line-height: 1.62; }
.prose p { margin: 0 0 10px; }
.prose p:last-child { margin-bottom: 0; }
.prose a { text-decoration: underline; }

/* Warning card (own card; red heading/border, body in --ink) */
.card--warn { border-color: color-mix(in srgb, var(--warn) 42%, var(--hair)); }
.card--warn .card-head { color: var(--warn); }

/* CJK: section headers don't uppercase / letter-space; bump size a touch (§4) */
:lang(ja) .card-head, :lang(ko) .card-head, :lang(zh) .card-head,
:lang(ja) .breadcrumb, :lang(ko) .breadcrumb, :lang(zh) .breadcrumb {
  letter-spacing: 0; text-transform: none;
}
:lang(ja) .card-head, :lang(ko) .card-head, :lang(zh) .card-head { font-size: 13px; }

/* ---- Detail rows (key/value) ---- */
.detail-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--hair); }
.detail-row:last-child { border-bottom: 0; }
.detail-row .k { color: var(--muted); }
.detail-row .v { color: var(--ink); font-weight: 600; text-align: right; }

/* ---- "Also known as" / English names chips (non-links) ---- */
.aka { padding: 8px 0 1px; }
.aka__label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips--plain span {
  font-size: 11px; font-weight: 600; color: var(--ink);
  background: color-mix(in srgb, var(--ink) 9%, transparent);
  border-radius: 4px; padding: 3px 7px;
}

/* ---- Link chips (Related / Found-in — real <a>) ---- */
.chips--link { gap: 9px; }
.chips--link a {
  border: 1px solid var(--hair); border-radius: 999px; padding: 6px 12px;
  font-size: 11.5px; font-weight: 600; color: var(--ink);
  display: inline-flex; align-items: center; gap: 7px;
}
.chips--link a:hover { border-color: var(--primary); color: var(--ink); text-decoration: none; background: color-mix(in srgb, var(--primary) 8%, transparent); }

/* ---- Bulleted lists (Common uses) ---- */
.dot-list { margin: 0; padding: 0; list-style: none; }
.dot-list li { position: relative; padding-left: 16px; font-size: 12.5px; color: var(--muted); line-height: 1.55; margin-bottom: 6px; }
.dot-list li:last-child { margin-bottom: 0; }
.dot-list li::before { content: ""; position: absolute; left: 1px; top: 9px; width: 5px; height: 5px; border-radius: 50%; background: var(--secondary); }
/* use_cases fragments are stored lowercase — capitalize first letter at render (Latin only) */
.dot-list li::first-letter { text-transform: uppercase; }

/* ---- App rating line ---- */
.rating { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); font-weight: 600; }
.rating .stars { color: var(--secondary); letter-spacing: 1px; }
.rating .num { font-variant-numeric: tabular-nums; }
.rating .cnt { color: var(--muted); font-weight: 400; }

/* ---- Store badges (official art dropped in via <img>) ---- */
.badges { display: flex; flex-direction: column; gap: 8px; }
.badges img { height: 44px; width: auto; }
/* Adaptive: knots3d.js tags <html> .platform-ios/.platform-android */
html.platform-ios .badge-android { display: none; }
html.platform-android .badge-ios { display: none; }

/* ---- Get-the-app sidebar / animation-adjacent CTA card ---- */
.card--cta { border-color: color-mix(in srgb, var(--primary) 45%, var(--hair)); }
.card--cta .note { font-size: 11.5px; color: var(--muted); margin: 0 0 12px; line-height: 1.5; }
.card--cta .rating { margin-bottom: 13px; }

/* ---- Animation pane (CreateJS canvas lives here; refined per real markup in build) ---- */
.anim-pane {
  /* Fixed literal (= dark --chrome / nav bar). Must match the baked CreateJS canvas fill in
     k3danimation.js — keep the two in sync; can't be a theme var since the canvas is drawn once. */
  grid-area: media; background: #0F0F0E; position: relative;
  border: 1px solid var(--hair); border-radius: var(--radius);
  min-height: 250px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.anim-pane .animation-container { background: transparent; border-radius: 0; padding: 0; }
.anim-controls {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 3px; background: rgba(20,20,18,.55);
  border: 1px solid rgba(255,255,255,.13); border-radius: 999px; padding: 5px 7px; z-index: 10;
}
.anim-controls button {
  border: 0; background: transparent; color: #e8e2d4; font-size: 14px; line-height: 1;
  width: 30px; height: 26px; border-radius: 999px; cursor: pointer; display: grid; place-items: center;
}
.anim-controls button:hover { background: rgba(255,255,255,.14); }
.anim-controls button.play { background: var(--primary-solid); color: var(--primary-ink); }
.anim-controls button.play:hover { background: var(--primary-solid); }
/* HTML copyright overlay — bottom aligned to the control bar (.anim-controls bottom:14px) */
.anim-watermark { position: absolute; right: 16px; bottom: 14px; font-size: 15px; line-height: 1; color: #B2B2B2; font-variant: small-caps; letter-spacing: .03em; font-family: Verdana, Arial, sans-serif; pointer-events: none; }
/* CreateJS integration (preserved from the legacy template): static img is the
   download source (hidden), the canvas container, and the right-click menu. */
.knot-image { display: none; }
.animation-container { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.animation-container canvas { max-width: 100%; max-height: 100%; display: block; }
.anim-controls .material-icons { font-size: 18px; line-height: 1; }
#customMenu {
  position: fixed; display: none; z-index: 1000; padding: 8px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--hair); border-radius: 8px; box-shadow: 0 10px 24px -10px rgba(0,0,0,.5);
}
#customMenu button { display: block; width: 100%; margin: 4px 0; padding: 6px 12px; border: 0; background: none; color: var(--ink); text-align: left; cursor: pointer; border-radius: 5px; font: inherit; font-size: 13px; }
#customMenu button:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }

/* ---- Footer (charcoal, bookends the nav) ---- */
.site-footer {
  background: var(--chrome); color: color-mix(in srgb, var(--chrome-ink) 62%, transparent);
  padding: 18px 26px; display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; font-size: 12px; margin-top: 8px;
}
.site-footer a { color: color-mix(in srgb, var(--chrome-ink) 72%, transparent); }
.site-footer a:hover { color: var(--chrome-ink); }
.site-footer .sep { opacity: .5; }

/* ---- Motion / theme transitions (respect reduced-motion) ---- */
@media (prefers-reduced-motion: no-preference) {
  body, .card, .topnav, .titlebar, .condbar, .site-footer, .navmenu__panel {
    transition: background-color .25s ease, color .25s ease, border-color .25s ease;
  }
  .pill { transition: transform .12s ease, border-color .2s ease; }
  .pill:hover { transform: translateY(-1px); }
}

/* ---- Responsive: tablet → phone stacks (§6 Mobile) ---- */
@media (max-width: 860px) {
  .top-grid { grid-template-columns: 1fr; grid-template-areas: "media" "getapp" "details"; }
  .bot-grid { grid-template-columns: 1fr; }
  /* Mobile nav: hamburger reveals the Activity/Type/Support links as a full-width panel */
  .nav-burger { display: inline-flex; }
  .topnav__links {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0; z-index: 55;
    flex-direction: column; align-items: stretch; gap: 2px;
    background: var(--chrome);
    border-top: 1px solid color-mix(in srgb, var(--chrome-ink) 15%, transparent);
    padding: 8px;
  }
  .topnav.nav-open .topnav__links { display: flex; }
  .topnav__links .navmenu { width: 100%; }
  .topnav__links .navmenu > button { width: 100%; justify-content: space-between; }
  .topnav__links .navmenu__panel { position: static; box-shadow: none; border: 0; background: transparent; max-height: none; margin: 0; padding: 2px 0 6px 14px; }
  .topnav__links .navmenu__panel a { color: var(--chrome-ink); }
}
@media (max-width: 560px) {
  .page-title { font-size: 27px; }
  .knot-body { padding: 15px 14px 22px; }
  .bar-inner { padding-left: 14px; padding-right: 14px; }
  /* Phones: drop the app pill below the meta block so the breadcrumb, title, and
     synonym sub-line get the full width instead of being squeezed by the pill —
     which reserved its column width and forced the text to wrap/truncate while
     leaving whitespace to its right. Applies to the knot title bar (.titlebar__meta)
     and the category/landing title bar (.ct-head = caticon + ct-meta). */
  .titlebar .bar-inner, .cat-title .bar-inner { flex-direction: column; align-items: flex-start; }
  .titlebar__meta, .ct-head { width: 100%; }
  .titlebar .pill, .cat-title .pill { margin-left: 0; }
}

/* Very small phones: reclaim horizontal space so the brand title never clips.
   Show the language globe only (still opens the menu) and tighten the nav gap.
   420px covers the reported cut-offs (320-390px) with headroom for longer
   localized language names than "English" (e.g. "Nederlands"). */
@media (max-width: 420px) {
  .lang-select .lang-name, .lang-select > button .caret { display: none; }
  .lang-select > button { padding: 5px; }
  .topnav .bar-inner { gap: 10px; }
}

/* ============================================================================
   Category / Type + Landing components (§6b, §6c) — reuse the two-layer sticky,
   .topnav, .card, .site-footer, .pill from above.
   ============================================================================ */
.cat-title { background: var(--ground); border-bottom: 1px solid var(--hair); }
.caticon { width: 76px; height: 76px; flex: none; border-radius: 13px; background: var(--surface); display: grid; place-items: center; overflow: hidden; }
.caticon img { width: 100%; height: 100%; object-fit: contain; padding: 2px; }
.ct-head { display: flex; align-items: center; gap: 16px; flex: 1 1 auto; min-width: 0; }
.cat-title .ct-meta { min-width: 0; flex: 1; }
.cat-title .breadcrumb { margin: 0 0 6px; }
.cat-title h1 { font-size: 30px; font-weight: 800; letter-spacing: -.015em; margin: 0; line-height: 1.08; }
.cat-sub { font-size: 14px; color: var(--ink); margin: 5px 0 0; font-weight: 400; white-space: nowrap; text-overflow: ellipsis; }
.cat-count { font-size: 12px; color: var(--muted); margin-top: 4px; }

.cat-body { max-width: var(--wrap); margin: 0 auto; padding: 20px 22px 26px; display: flex; flex-direction: column; gap: 22px; }
.sec-h { font-weight: 700; font-size: 12px; letter-spacing: .13em; text-transform: uppercase; color: var(--ink); display: flex; align-items: center; gap: 12px; margin: 0 0 13px; }
.sec-h::after { content: ""; flex: 1; height: 1px; background: var(--hair); }
:lang(ja) .sec-h, :lang(ko) .sec-h, :lang(zh) .sec-h { letter-spacing: 0; text-transform: none; font-size: 13px; }

.catgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 13px; }
.knotcard { border: 1px solid var(--hair); border-radius: var(--radius); overflow: hidden; background: var(--surface); display: block; color: var(--ink); }
.knotcard:hover { border-color: var(--primary); text-decoration: none; }
.knotcard .thumb { aspect-ratio: 4/3; background: var(--chrome); display: grid; place-items: center; overflow: hidden; }
.knotcard .thumb img { width: auto; height: auto; max-width: 62%; max-height: 74%; }
.knotcard .kname { display: block; padding: 9px 10px 4px; font-size: 12.5px; font-weight: 600; color: var(--ink); text-align: center; }
.knotcard .kdesc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; padding: 0 10px 10px; font-size: 11.5px; color: var(--muted); text-align: center; line-height: 1.45; }

/* Browse-other icon grids (categories / types) — colored square + icon art, real <a> */
.icongrid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px; }
.icontile { border-radius: 9px; aspect-ratio: 1; overflow: hidden; display: block; }
.icontile img { width: 100%; height: 100%; object-fit: contain; padding: 15%; }
/* Found-in: the knot's activity categories as colored icon tiles (was text pills).
   4-column grid so the tiles fill the card width evenly (equal margins); wraps after 4.
   max-width caps tile size when the sidebar goes full-width on mobile. */
.foundin { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; max-width: 264px; }
.fi-tile { aspect-ratio: 1; border-radius: 10px; overflow: hidden; display: grid; place-items: center; transition: transform .12s ease, filter .12s ease; }
.fi-tile:hover { text-decoration: none; transform: translateY(-1px); filter: brightness(1.08); }
.fi-tile img { width: 100%; height: 100%; object-fit: contain; padding: 16%; }
/* Related knots: mini knot-cards (render thumbnail + name label). 5-column grid so the cards
   fill the main column with even margins (like .foundin); the thumbnail sits on a warm medium
   dark tile (lighter than the near-black nav --chrome so the colorful ropes read against it). */
.relgrid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.rel-card { display: flex; flex-direction: column; gap: 7px; color: var(--ink); min-width: 0; }
.rel-card:hover { text-decoration: none; }
.rel-card:hover .rthumb { transform: translateY(-2px); }
.rel-card .rthumb { border-radius: 10px; overflow: hidden; background: #2B2924; display: block; transition: transform .12s ease; }
/* Square is driven by the img's own width-based aspect-ratio (definite), NOT by
   parent aspect-ratio + child height:100% — that pairing leaves a stale, oversized
   thumbnail during a live window resize in Safari/WebKit. */
.rel-card .rthumb img { display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: contain; padding: 7%; }
.rel-card .rname { font-size: 12px; font-weight: 600; color: var(--ink); text-align: center; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
@media (max-width: 860px) { .relgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .relgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Bottom app band */
.app-band { border: 1px solid color-mix(in srgb, var(--primary) 40%, var(--hair)); border-radius: var(--radius); background: var(--surface); padding: 16px 20px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.app-band .abtext strong { font-weight: 800; font-size: 15px; color: var(--ink); display: block; }
.app-band .abtext .r { font-size: 12px; color: var(--muted); margin-top: 3px; }
.app-band .abtext .r .st { color: var(--secondary); }
.app-band .abbadges { display: flex; gap: 10px; margin-left: auto; align-items: center; flex-wrap: wrap; }
.app-band .abbadges img { height: 40px; width: auto; }

/* Landing: category tiles / type tiles / reviews / show-more */
.tilegrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
/* Fully-colored category tiles: the whole tile IS the icon — background = the category's
   code.color (set inline in the template), white glyph + white label. --surface is only a
   fallback for a category with no color. Colors are mode-independent (white reads in both).
   Glyph sized ~92px to match the category-page .icontile icons. */
.ltile { border-radius: 12px; background: var(--surface); padding: 8px 8px 15px; display: flex; flex-direction: column; align-items: center; gap: 6px; color: #fff; transition: transform .12s ease, box-shadow .12s ease; }
.ltile:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.32); }
.ltile .plate { width: 92px; height: 92px; display: grid; place-items: center; }
.ltile .plate img { width: 100%; height: 100%; object-fit: contain; }
.ltile .tn { font-size: 13px; font-weight: 600; color: #fff; text-align: center; text-shadow: 0 1px 2px rgba(0,0,0,.28); }
/* Knot-type tiles (EXPERIMENT): gray --surface background, glyph colorized to the type's
   code.color, white label. Glyph is the white SVG used as a CSS mask over a background-color
   set inline to the type color (no per-color SVG assets needed). Same 4-up layout / 92px glyph
   / hover-lift as the category tiles. */
.typegrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
/* Glyph fill and border both use the raw type color (--gc, set inline from code.color) so they
   match. Colors that read too dark on the gray surface are lightened at the source in
   CategoryCode.java, not here — keeps each hue distinct instead of tinting them all toward white. */
.typetile { border: 2px solid var(--gc, #888); border-radius: 14px; background: var(--surface); padding: 8px 8px 15px; display: flex; flex-direction: column; align-items: center; gap: 6px; transition: transform .12s ease, box-shadow .12s ease; }
.typetile:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.32); }
.typetile .ti { width: 92px; height: 92px; display: block; background-color: var(--gc); }
.typetile .tnn { font-size: 13px; font-weight: 600; color: var(--ink); text-align: center; }
/* User reviews: a horizontal carousel showing 3 cards per view. The .reviews track scroll-snaps;
   theme.js reveals the prev/next arrows only when it overflows (>3 cards / narrow viewport) and
   disables them at the ends. Cards stretch to equal height; the author line sits at the bottom. */
.rvcarousel { position: relative; }
.reviews { display: flex; gap: 13px; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; -ms-overflow-style: none; padding-bottom: 2px; }
.reviews::-webkit-scrollbar { display: none; }
.reviews > .rvcard { flex: 0 0 calc((100% - 26px) / 3); scroll-snap-align: start; }
@media (prefers-reduced-motion: no-preference) { .reviews { scroll-behavior: smooth; } }
.rvcard { border: 1px solid var(--hair); border-radius: var(--radius); background: var(--surface); padding: 15px 16px; display: flex; flex-direction: column; }
.rvcard .rvstars { color: var(--secondary); font-size: 13px; letter-spacing: 1px; margin-bottom: 7px; }
.rvcard .rvtitle { font-weight: 700; font-size: 13px; color: var(--ink); margin-bottom: 5px; }
.rvcard .rvtext { font-size: 13px; color: var(--ink); line-height: 1.55; margin-bottom: 9px; }
.rvcard .rvby { font-size: 11px; color: var(--muted); margin-top: auto; }
.rvcard .rvby b { color: var(--ink); font-weight: 600; }
.rvnav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--hair); background: var(--chrome); color: var(--chrome-ink); display: grid; place-items: center; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,.35); transition: background .12s ease, opacity .12s ease; }
.rvnav[hidden] { display: none; }
.rvnav:hover { background: color-mix(in srgb, var(--chrome) 82%, #fff); }
.rvnav:disabled { opacity: .3; cursor: default; }
.rvnav--prev { left: 3px; }
.rvnav--next { right: 3px; }
.ovmore { text-align: right; margin-top: 10px; }
.ovmore button { background: transparent; border: 0; color: var(--primary); font: inherit; font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; cursor: pointer; padding: 0; }
.collapsible[hidden] { display: none; }

@media (max-width: 860px) {
  .catgrid, .tilegrid, .typegrid { grid-template-columns: repeat(3, 1fr); }
  .reviews > .rvcard { flex-basis: calc((100% - 13px) / 2); }
  .icongrid { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 560px) {
  .catgrid, .tilegrid, .typegrid { grid-template-columns: repeat(2, 1fr); }
  .reviews > .rvcard { flex-basis: 100%; }
  .icongrid { grid-template-columns: repeat(5, 1fr); }
  .cat-title h1 { font-size: 24px; }
  .cat-body, .cat-title { padding-left: 14px; padding-right: 14px; }
}
