/* Public presentation only. The game/lobby renderer and existing tokens are untouched. */
body[data-public="true"] {
  --pub-bg: #090e10;
  --pub-panel: #111b1f;
  --pub-text: #f1f0e8;
  --pub-muted: #b3c0c2;
  --pub-teal: #76d9c4;
  --pub-gold: #d0b47b;
  --pub-border: #34484e;
  --pub-radius: 14px;
  --pub-outer: 1200px;
  --pub-reading: 760px;
  /* One type scale and header geometry for every public route. Rules below read
     these tokens; route-specific pixel sizes are not allowed (publicTypography.test.js). */
  --pub-header-h: 76px;
  --pub-fs-body: 17px;
  --pub-lh-body: 1.7;
  --pub-fs-small: 15px;
  --pub-fs-ui: 16px;
  --pub-fw-ui: 500;
  --pub-fs-brand: 23px;
  --pub-fs-eyebrow: 12px;
  --pub-fs-h1: clamp(32px, 3vw, 44px);
  --pub-fs-h2: clamp(24px, 2.3vw, 30px);
  --pub-fs-h3: 22px;
  --pub-fs-card-title: 22px;
  --pub-fs-card-body: 16px;
  --pub-lh-card-body: 1.6;
  background: radial-gradient(ellipse at 80% 0%, #12302e66, transparent 65%), var(--pub-bg);
  color: var(--pub-text);
  font-family: var(--font-sans);
  font-size: var(--pub-fs-body);
  line-height: var(--pub-lh-body);
  margin: 0;
  height: auto;
  min-height: 100vh;
  overflow: auto;
}
.public-header, .public-footer { display: none; }
body[data-public="true"] :is(.public-header, .public-footer) { display: block; }
body[data-public="true"] > :is(.site-footer) { display: none; }
body[data-public="true"] :is(.public-header-inner, .public-footer-inner) {
  width: min(var(--pub-outer), calc(100% - 48px)); margin: 0 auto;
}
body[data-public="true"] .public-header { border-bottom: 1px solid var(--pub-border); }
body[data-public="true"] .public-brand { display: inline-flex; align-items: center; gap: 12px; color: var(--pub-text); text-decoration: none; font: 500 var(--pub-fs-brand)/1.2 var(--font-serif); }
body[data-public="true"] .public-brand img { width: 48px; height: 48px; object-fit: contain; flex: none; }
body[data-public="true"] .public-footer nav { display: flex; flex-wrap: wrap; gap: 8px 24px; }
body[data-public="true"] .public-footer nav a { color: var(--pub-muted); text-decoration: none; padding: 8px 0; font-size: var(--pub-fs-ui); border-bottom: 2px solid transparent; }
body[data-public="true"] .public-footer nav a[aria-current="page"] { color: var(--pub-teal); border-color: var(--pub-teal); }
body[data-public="true"] .public-footer { border-top: 1px solid var(--pub-border); margin-top: 40px; }
body[data-public="true"] .public-footer-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 20px 40px; padding: 28px 0; }
body[data-public="true"] .public-footer p { font-size: var(--pub-fs-small); color: var(--pub-muted); margin: 8px 0 0; }
body[data-public="true"] .public-footer .public-fineprint { flex-basis: 100%; max-width: var(--pub-reading); }
body[data-public="true"] :is(main.shell, main.guide-main, main.legal-shell) { width: min(var(--pub-outer), calc(100% - 48px)); max-width: var(--pub-outer); margin: 0 auto; padding: 32px 0; min-height: 0; display: block; }
body[data-public="true"] :is(.platform-route-page, .legal-card) { padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; min-height: 0; }
body[data-public="true"] :is(.platform-route-page, .legal-card, .guide-main > article, .guide-related, .guide-reference, .lesson-pager, .learning-overview) { width: 100%; max-width: var(--pub-reading); margin-left: auto; margin-right: auto; }
body[data-public="true"] :is(.guide-breadcrumb, .legal-back) { display: block; max-width: var(--pub-reading); margin: 0 auto 24px; font-size: var(--pub-fs-small); color: var(--pub-muted); }
body[data-public="true"] main :is(h1, h2, h3) { color: var(--pub-text); font-family: var(--font-serif); font-weight: 500; letter-spacing: -.02em; }
body[data-public="true"] main h1 { font-size: var(--pub-fs-h1); line-height: 1.15; margin: 12px 0 20px; max-width: 24ch; }
body[data-public="true"] main h2 { font-size: var(--pub-fs-h2); line-height: 1.25; margin: 28px 0 12px; }
body[data-public="true"] main h3 { font-size: var(--pub-fs-h3); line-height: 1.3; margin: 24px 0 10px; }
body[data-public="true"] :is(main.shell, main.guide-main, main.legal-shell) :is(p, li) { font-size: var(--pub-fs-body); line-height: var(--pub-lh-body); color: var(--pub-muted); }
body[data-public="true"] main p { margin: 12px 0; max-width: var(--pub-reading); }
body[data-public="true"] main :is(strong, b) { color: var(--pub-text); }
body[data-public="true"] .eyebrow { font: 600 var(--pub-fs-eyebrow)/1.6 var(--font-sans); letter-spacing: .12em; color: var(--pub-gold); }
body[data-public="true"] a { color: var(--pub-teal); text-underline-offset: 4px; }
body[data-public="true"] :is(a, button, summary, [tabindex]):focus-visible { outline: 3px solid var(--pub-teal); outline-offset: 4px; }
body[data-public="true"] .guide-skip { z-index: 101; }
/* Skip link: visually hidden until focused. The base rule parks it at top:-100px, which is not enough once text is enlarged (3x text leaves it over the header, where it
   intercepted clicks on the dots). Unfocused it is a fully clipped 1px box (no hit area, still focusable and announced); focused it is a complete, in-viewport control. */
body[data-public="true"] .guide-skip:not(:focus) { position: absolute; top: 0; left: 0; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
body[data-public="true"] .guide-skip:focus { box-sizing: border-box; max-width: calc(100vw - 32px); outline: 3px solid var(--pub-teal); outline-offset: 2px; }
body[data-public="true"] .route-doc { max-width: var(--pub-reading); gap: 24px; margin-top: 28px; }
body[data-public="true"] :is(.guide-note, .route-engine, .legal-notice) { background: var(--pub-panel); border: 1px solid var(--pub-border); border-left: 3px solid var(--pub-teal); border-radius: var(--pub-radius); padding: 20px; margin: 24px 0; color: var(--pub-muted); }
body[data-public="true"] :is(.guide-note, .route-engine) h2 { margin-top: 0; }
body[data-public="true"] :is(.legal-meta, .guide-main .guide-reference, .lesson-position figcaption, .guide-main .diagram-help) { font-size: var(--pub-fs-small); line-height: var(--pub-lh-body); color: var(--pub-muted); }
body[data-public="true"] :is(.about-pillars, .public-value-grid) { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
body[data-public="true"] :is(.about-pillar, .public-value-card, .public-plans) { padding: 24px; background: var(--pub-panel); border: 1px solid var(--pub-border); border-radius: var(--pub-radius); }
body[data-public="true"] :is(.about-pillar, .public-value-card) h2, body[data-public="true"] .about-pillar h3 { margin-top: 12px; }
body[data-public="true"] .about-pillars { grid-template-columns: 1fr; }
body[data-public="true"] .about-chip { font-size: var(--pub-fs-small); color: var(--pub-muted); border-color: var(--pub-border); }
body[data-public="true"] .public-home { display: block; padding: 0; background: none; border: 0; }
body[data-public="true"] .public-hero { max-width: 850px; padding: 12px 0 36px; }
body[data-public="true"] .public-hero p { max-width: 680px; }
body[data-public="true"] .public-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
body[data-public="true"] :is(.public-button, .inline-link) { display: inline-flex; justify-content: center; align-items: center; padding: 10px 20px; min-height: 46px; border: 1px solid var(--pub-teal); border-radius: 8px; background: var(--pub-teal); color: var(--pub-bg); font: 600 var(--pub-fs-ui)/1.5 var(--font-sans); text-decoration: none; }
body[data-public="true"] .public-button-secondary { color: var(--pub-teal); background: transparent; }
body[data-public="true"] .public-section-heading h2 { margin-top: 8px; }
body[data-public="true"] .game-launch-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin: 24px 0 36px; }
body[data-public="true"] .game-launch-card { width: 100%; min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 16px; padding: 22px 18px; border: 1px solid var(--pub-border); border-radius: var(--pub-radius); background: var(--pub-panel); color: var(--pub-text); box-shadow: none; text-align: left; opacity: 1; }
body[data-public="true"] button.game-launch-card:hover { border-color: var(--pub-teal); transform: none; }
body[data-public="true"] .game-launch-card > span:last-child { display: flex; flex-direction: column; gap: 8px; }
body[data-public="true"] .game-launch-card .game-symbol { width: 40px; height: 40px; display: grid; place-items: center; font-size: 26px; color: var(--pub-gold); background: none; }
body[data-public="true"] .game-launch-card small { font-size: 11px; color: var(--pub-gold); letter-spacing: .06em; }
body[data-public="true"] .game-launch-card strong { font: 500 var(--pub-fs-card-title)/1.3 var(--font-serif); }
body[data-public="true"] .game-launch-card em { font: normal var(--pub-fs-card-body)/var(--pub-lh-card-body) var(--font-sans); color: var(--pub-muted); }
body[data-public="true"] .public-plans { margin-top: 24px; border-top: 2px solid var(--pub-gold); }
body[data-public="true"] .public-plans h2 { margin-top: 10px; }
body[data-public="true"] .learning-game-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 280px)); gap: 20px; margin: 28px 0; }
body[data-public="true"] .learning-game-card { border: 1px solid var(--pub-border); border-radius: var(--pub-radius); background: var(--pub-panel); text-decoration: none; }
body[data-public="true"] .learning-game-card > img { width: 100%; height: 150px; aspect-ratio: 3 / 2; object-fit: contain; display: block; }
body[data-public="true"] .learning-game-card > div { padding: 28px; }
body[data-public="true"] .learning-game-card h2 { margin: 10px 0; }
body[data-public="true"] .learning-card-action { font-size: var(--pub-fs-ui); color: var(--pub-teal); }
body[data-public="true"] .lesson-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 20px; }
body[data-public="true"] .lesson-grid a { padding: 24px; border-radius: var(--pub-radius); border-color: var(--pub-border); background: var(--pub-panel); }
body[data-public="true"] .lesson-grid h2 { margin: 12px 0; }
body[data-public="true"] .lesson-number { color: var(--pub-gold); }
body[data-public="true"] .learning-overview { padding: 20px; border-color: var(--pub-border); border-radius: var(--pub-radius); }
body[data-public="true"] .learning-overview .route-doc { margin-top: 20px; }
body[data-public="true"] .lesson-pager a { border-color: var(--pub-border); border-radius: 8px; }
body[data-public="true"] .guide-main table { font-size: var(--pub-fs-ui); color: var(--pub-text); }
body[data-public="true"] .guide-main :is(th, td) { border-color: var(--pub-border); }
body[data-public="true"] .guide-main th { background: var(--pub-panel); }
@media (max-width: 900px) {
  body[data-public="true"] .game-launch-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 1fr; }
  body[data-public="true"] .lesson-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body[data-public="true"] .public-value-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  body[data-public="true"] :is(main.shell, main.guide-main, main.legal-shell, .public-footer-inner) { width: calc(100% - 32px); }
  body[data-public="true"] .public-footer nav { gap: 6px 18px; }
    body[data-public="true"] .learning-game-card > div { padding: 20px; }
  body[data-public="true"] .lesson-grid { grid-template-columns: 1fr; grid-auto-rows: auto; }
  body[data-public="true"] .game-launch-card { padding: 18px 14px; }
}

/* Compact public composition; existing header controls keep their handlers and state. */
body[data-public="true"] .noise { display: block; opacity: .025; pointer-events: none; }
.public-language-note { position: absolute; width: 1px; height: 1px; padding: 0; clip-path: inset(50%); overflow: hidden; }
body[data-public="true"] .public-home { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 24px 40px; align-items: center; }
body[data-public="true"] .public-hero { padding: 0; }
body[data-public="true"] .public-home p { line-height: 1.6; }
body[data-public="true"] .game-launch-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 18em), 1fr)); gap: 10px; margin: 16px 0 0; }
body[data-public="true"] .game-launch-card { flex-direction: row; align-items: center; gap: 10px; padding: 14px; }
body[data-public="true"] .game-launch-card > span:last-child { gap: 3px; }
body[data-public="true"] .game-launch-card .game-symbol { width: 28px; flex: none; }
body[data-public="true"] .public-progress { grid-column: 1 / -1; border-top: 1px solid var(--pub-border); padding-top: 16px; }
body[data-public="true"] .public-progress h2 { margin: 0 0 8px; }
body[data-public="true"] .public-progress p { max-width: 100%; margin: 0; }
body[data-public="true"] .public-plans { grid-column: 1 / -1; padding: 12px 16px; margin: 0; }
body[data-public="true"] .public-plans p { margin: 2px 0; }
body[data-public="true"] .public-footer { margin-top: 12px; }
body[data-public="true"] .public-footer-inner { padding: 16px 0; gap: 8px 24px; }
body[data-public="true"] .public-footer .public-brand { font-size: 20px; } /* footer mark is deliberately smaller than the header brand */
body[data-public="true"] .public-footer .public-brand img { width: 32px; height: 32px; }
body[data-public="true"] .public-footer .public-fineprint { max-width: 100%; margin: 0; }
body[data-public="true"] .learning-game-card { min-height: 280px; overflow: visible; }
body[data-public="true"] .learning-game-card > div { padding: 12px 16px; }
body[data-public="true"] .learning-game-card h2 { margin: 4px 0; }
body[data-public="true"] .learning-game-card p { margin: 4px 0; }
body[data-public="true"] .learning-placeholder { min-height: 150px; display: grid; place-items: center; font-size: 48px; color: var(--pub-gold); background: radial-gradient(ellipse, #24463e66, transparent); }
body[data-public="true"] .learning-game-card.unavailable:hover { border-color: var(--pub-border); }
@media (max-width: 900px) {
 body[data-public="true"] .public-home { grid-template-columns: 1fr; gap: 24px; }
 body[data-public="true"] .public-footer-inner { gap: 12px; }
}
@media (max-width: 440px) {
 body[data-public="true"] .game-launch-grid { grid-template-columns: 1fr; }
}

@media (min-width: 901px) {
 body[data-public="true"][data-route="home"] main.shell { padding: 20px 0; }
 body[data-public="true"] .public-home { gap: 16px 40px; }
 body[data-public="true"] .game-launch-card { padding: 10px 14px; }
 body[data-public="true"] .public-progress { padding-top: 12px; }
 body[data-public="true"][data-route="home"] .public-footer-inner { padding: 12px 0; }
}

/* Stable gutter space prevents short and long public
   documents from shifting their 1200px alignment when a scrollbar appears. */
html:has(body[data-public="true"]) { scrollbar-gutter: stable; }
body[data-public="true"] .learning-hub .guide-breadcrumb { max-width: none; margin-left: 0; margin-right: 0; }


/* Every Learn card uses the same artwork, status, title and detail rows. */
body[data-public="true"] .learning-game-card {
  display: grid;
  grid-template-rows: 150px minmax(130px, auto);
  align-content: start;
}
body[data-public="true"] .learning-card-art {
  width: 100%;
  height: 150px;
  min-height: 150px;
}
body[data-public="true"] .learning-game-card > .learning-card-art { padding: 0; }
body[data-public="true"] .learning-card-art img {
  display: block;
  width: auto;
  height: 100%;
  aspect-ratio: 3 / 2;
  margin: 0 auto;
  object-fit: contain;
}
body[data-public="true"] .learning-card-copy {
  display: grid;
  grid-template-rows: minmax(20px, auto) auto minmax(24px, auto);
  align-content: start;
  gap: 4px;
  padding: 12px 16px;
}
body[data-public="true"] .learning-card-copy :is(h2, p, .learning-card-action) { margin: 0; }

/* Long game names and enlarged text stay inside their card instead of
   painting through the adjacent column. Cards grow vertically as needed. */
body[data-public="true"] .game-launch-card > span:last-child {
  min-width: 0;
  max-width: 100%;
}
body[data-public="true"] .game-launch-card :is(small, strong, em) {
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* Public content only: standalone guides and hub reading links. */
.public-intro-links a, .public-guide-list a, .route-doc a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.public-guide-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; margin: 28px 0; }
.public-guide-list a { display: grid; gap: 8px; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.public-guide-list span { color: var(--muted); font-size: 14px; line-height: 1.6; }
.public-guide-page { margin: 0; min-height: 100vh; height: auto; overflow: auto; }
.public-guide-page a { color: var(--text); text-underline-offset: 4px; }
.public-guide-page a:focus-visible, .public-guide-list a:focus-visible { outline: 3px solid var(--teal); outline-offset: 5px; }
.guide-skip { position: absolute; left: 16px; top: -100px; z-index: 100; padding: 12px; background: var(--panel); }
.guide-skip:focus { top: 12px; }
.guide-header { max-width: 1120px; margin: auto; padding: 22px 24px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.guide-header nav, .guide-footer nav { display: flex; flex-wrap: wrap; gap: 14px 24px; }
.guide-header nav a, .guide-footer nav a { padding: 5px 0; }
.guide-main { width: min(900px, calc(100% - 32px)); margin: 24px auto 40px; overflow-wrap: anywhere; }
.guide-breadcrumb { margin-bottom: 22px; color: var(--muted); line-height: 1.8; }
.guide-main h1 { font-family: var(--font-serif); font-weight: 500; line-height: 1.18; margin: 14px 0 18px; }
.guide-main h2 { font-family: var(--font-serif); font-weight: 500; line-height: 1.25; margin: 36px 0 16px; }
.guide-main p, .guide-main li { color: var(--text-dim); }
.guide-main .guide-lead { font-size: 18px; color: var(--text); max-width: 72ch; }
.guide-main li { margin-bottom: 12px; }
.guide-main ol, .guide-main ul { padding-left: 24px; }
.guide-main table { border-collapse: collapse; width: 100%; margin: 24px 0; font-size: 15px; line-height: 1.6; }
.guide-main caption { text-align: left; color: var(--muted); margin-bottom: 12px; }
.guide-main th, .guide-main td { border: 1px solid var(--line); text-align: left; padding: 10px; vertical-align: top; }
.guide-main th { background: var(--panel2); }
.guide-figure { margin: 28px 0; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.guide-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; }
.guide-strip > span { display: grid; gap: 8px; padding: 14px 8px; text-align: center; border: 1px solid var(--line); border-radius: 8px; }
.guide-strip b { color: var(--amber); font-size: 20px; }
.guide-strip small { color: var(--text-dim); line-height: 1.5; }
.guide-figure figcaption { font-size: 14px; color: var(--muted); line-height: 1.7; margin-top: 16px; }
.guide-note { border-left: 3px solid var(--teal); padding: 4px 20px 12px; margin: 32px 0; background: var(--panel); }
.guide-note h2 { margin-top: 18px; }
.guide-related { border-top: 1px solid var(--line); margin-top: 40px; }
.guide-main .guide-reference { font-size: 14px; color: var(--muted); margin-top: 36px; }
.guide-footer { max-width: 1120px; margin: auto; padding: 24px; border-top: 1px solid var(--line); color: var(--muted); line-height: 1.7; }
.learning-game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 20px; margin: 24px 0; }
.learning-game-card { display: block; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); text-decoration: none; }
.learning-game-card > img { width: 100%; height: auto; display: block; }
.learning-game-card > div { padding: 18px; }
.learning-game-card h2 { margin: 10px 0; }
.learning-game-card p { margin: 0 0 16px; }
.learning-card-action { color: var(--teal); font-size: 15px; }
.learning-availability { color: var(--muted); font-size: 14px; }
.guide-main .lesson-grid { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 14px; margin: 24px 0; }
.lesson-grid li { margin: 0; display: flex; }
.lesson-grid a { display: flex; flex-direction: column; width: 100%; padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); text-decoration: none; }
.lesson-grid .lesson-number { color: var(--teal); font: 600 14px ui-monospace, monospace; }
.lesson-grid h2 { margin: 10px 0; }
.lesson-grid p { margin: 0 0 16px; }
.lesson-grid .learning-card-action { margin-top: auto; }
.learning-game-card:hover, .lesson-grid a:hover { border-color: var(--teal); }
.learning-overview { margin-top: 24px; padding: 18px; border: 1px solid var(--line); border-radius: 12px; }
.learning-overview summary { cursor: pointer; line-height: 1.6; }
.learning-overview .route-doc { max-width: none; margin-top: 24px; gap: 24px; }
.learning-overview summary:focus-visible, .lesson-board-scroll:focus-visible { outline: 3px solid var(--teal); outline-offset: 3px; }
.lesson-position { margin: 24px 0; min-width: 0; }
.lesson-board-key { display: flex; flex-wrap: wrap; gap: 12px 24px; font-size: 14px; }
.lesson-board-key span { display: inline-flex; align-items: center; gap: 8px; }
.lesson-board-key img { width: 28px; height: 28px; }
.guide-main .diagram-help { font-size: 13px; color: var(--muted); margin: 8px 0; line-height: 1.6; }
.lesson-board-scroll { max-width: 100%; overflow-x: auto; border-radius: 8px; background: var(--bg); }
.lesson-board-scroll svg { display: block; width: 100%; min-width: 640px; height: auto; }
.lesson-position figcaption { font-size: 14px; line-height: 1.7; color: var(--text-dim); margin-top: 12px; }
.lesson-pager { display: flex; flex-wrap: wrap; gap: 14px; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 24px; padding-top: 20px; }
.lesson-pager a { flex: 1 1 260px; padding: 12px; line-height: 1.6; border: 1px solid var(--line); border-radius: 8px; }

/* One card scale: titles and descriptions read the same tokens on Home, Learn and lesson hubs. */
body[data-public="true"] main :is(.learning-game-card h2, .lesson-grid h2, .about-pillar h2, .about-pillar h3, .public-value-card h2) { font-size: var(--pub-fs-card-title); line-height: 1.3; }
body[data-public="true"] main :is(.learning-game-card p, .lesson-grid p, .about-pillar p, .public-value-card p) { font-size: var(--pub-fs-card-body); line-height: var(--pub-lh-card-body); }

/* ==========================================================================
   Shared header (V11). ONE ROW at every width, on the app routes (Home, Shop, About, Support, Backgammon) and on the script-free static
   documents. Nothing here wraps: the header is a single non-wrapping flex row whose parts are the brand, the five primary links and the
   permanent three-dot menu.
   - Wide: brand | Play Learn Shop About Support | dots. The brand and menu slots are equal flex items, so the links are centred in the header.
   - Compact: brand | dots. The five links move, ALL TOGETHER, to the top of the dots panel (never split, never repeated).
   - Language, Sign in / Sign out, Privacy and Terms are ALWAYS in the dots panel and never in the header row.
   Compact is the default. Wide is an upgrade applied by the container queries at the end of this file only when the whole wide arrangement is
   measured to fit (thresholds come from real layout, written in em + px so text-only enlargement moves them exactly as far as it moves the text).
   They read only the header's own width, never the authentication state, so signed-out, signed-in and unresolved headers are identical.
   ========================================================================== */
:is(body[data-public="true"], body[data-route="backgammon"]) :is(.app-topbar, .public-header-inner) {
  --hdr-gutter: 24px;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 16px;
  box-sizing: border-box;
  height: auto;
  margin: 0;
}
body[data-public="true"] :is(.app-topbar, .public-header-inner) { min-height: var(--pub-header-h); }
body[data-public="true"] .app-topbar {
  position: relative;
  width: auto;
  padding: 0 max(var(--hdr-gutter), calc((100% - var(--pub-outer)) / 2));
  border-bottom: 1px solid var(--pub-border);
  background: rgba(9, 14, 16, .94);
  color: var(--pub-text);
}
body[data-public="true"] .public-header { background: rgba(9, 14, 16, .94); color: var(--pub-text); }
body[data-public="true"] .public-header-inner {
  position: relative;
  width: min(var(--pub-outer), calc(100% - 2 * var(--hdr-gutter)));
  margin: 0 auto;
  padding: 0;
  min-height: calc(var(--pub-header-h) - 1px);
}
@media (max-width: 600px) {
  :is(body[data-public="true"], body[data-route="backgammon"]) :is(.app-topbar, .public-header-inner) { --hdr-gutter: 16px; }
}
/* Backgammon keeps its previous header height and gutters (62px; 56px on short desktop viewports). */
body[data-route="backgammon"] .app-topbar { --hdr-gutter: clamp(12px, 5vw, 72px); min-height: 62px; padding-block: 6px; padding-inline: var(--hdr-gutter); }
@media (min-width: 1181px) and (max-height: 920px) { body[data-route="backgammon"] .app-topbar { min-height: 56px; } }
/* A sticky header taller than the space it leaves would make an open menu unreachable; on landscape-phone-sized viewports it scrolls with the page. */
@media (max-width: 600px) and (max-height: 600px) { body[data-route="backgammon"] .app-topbar { position: relative; } }

/* Brand: one line, never wrapped. */
:is(body[data-public="true"], body[data-route="backgammon"]) :is(.app-topbar, .public-header-inner) > .header-brand { display: flex; flex: 1 1 auto; justify-content: flex-start; min-width: 0; }
body[data-public="true"] :is(.premium-brand, .public-header .public-brand) {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  max-width: 100%;
  gap: 12px;
  color: var(--pub-text);
  font: 500 var(--pub-fs-brand)/1.2 var(--font-serif);
  letter-spacing: normal;
  text-decoration: none;
  white-space: nowrap;
}
body[data-public="true"] :is(.premium-brand, .public-header .public-brand) img { width: 48px; height: 48px; flex: 0 0 48px; object-fit: contain; filter: drop-shadow(0 4px 12px rgba(231, 190, 94, .16)); }
body[data-public="true"] :is(.premium-brand, .public-header .public-brand) span { display: inline; color: var(--pub-text); font: inherit; letter-spacing: inherit; font-variation-settings: "opsz" 23; }
body[data-route="backgammon"] .app-topbar .premium-brand { flex-wrap: nowrap; max-width: 100%; white-space: nowrap; }
body[data-route="backgammon"] .app-topbar .premium-brand span { display: inline; font-variation-settings: "opsz" 18; }
body[data-route="backgammon"] .app-topbar .premium-brand img { width: 42px; height: 42px; }

/* Primary navigation: absent by default (compact), shown by the wide container queries. */
body[data-public="true"] :is(.app-topbar > .platform-nav, .public-header-inner > nav),
body[data-route="backgammon"] .app-topbar > .platform-nav { display: none; flex: 0 0 auto; justify-content: center; gap: 24px; margin: 0; white-space: nowrap; }
body[data-route="backgammon"] .app-topbar > .platform-nav { gap: 4px; }
body[data-public="true"] :is(.app-topbar > .platform-nav, .public-header-inner > nav) a {
  padding: 8px 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--pub-muted);
  font: var(--pub-fw-ui) var(--pub-fs-ui)/1.5 var(--font-sans);
  text-decoration: none;
  white-space: nowrap;
}
body[data-public="true"] :is(.app-topbar > .platform-nav, .public-header-inner > nav) a:not(.active, [aria-current="page"]):hover { color: var(--pub-text); }
body[data-public="true"] :is(.app-topbar > .platform-nav, .public-header-inner > nav) a:is(.active, [aria-current="page"]) { border-bottom-color: var(--pub-teal); color: var(--pub-teal); }

/* Menu slot: the permanent three-dot button, always visible, always at the right edge. */
:is(body[data-public="true"], body[data-route="backgammon"]) :is(.app-topbar, .public-header-inner) > .top-actions { display: flex; flex: 0 0 auto; align-items: center; justify-content: flex-end; margin: 0 0 0 auto; min-width: 0; }
:is(body[data-public="true"], body[data-route="backgammon"]) :is(.app-topbar, .public-header-inner) .account-menu-wrap { display: block; position: static; flex: none; }
:is(body[data-public="true"], body[data-route="backgammon"]) :is(.app-topbar, .public-header-inner) .account-menu-button {
  display: grid;
  place-content: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, .035);
  list-style: none;
  cursor: pointer;
}
:is(body[data-public="true"], body[data-route="backgammon"]) .account-menu-button::-webkit-details-marker { display: none; }
:is(body[data-public="true"], body[data-route="backgammon"]) .account-menu-button::before { content: none; }
:is(body[data-public="true"], body[data-route="backgammon"]) .account-menu-button span { display: block; width: 4px; height: 4px; border-radius: 50%; background: var(--text); }
:is(body[data-public="true"], body[data-route="backgammon"]) :is(.account-menu-button:hover, .account-menu-button[aria-expanded="true"], .account-menu-wrap[open] > .account-menu-button) { border-color: #4c655f; background: rgba(95, 224, 192, .08); }
:is(body[data-public="true"], body[data-route="backgammon"]) .account-menu-button:focus-visible { outline: 3px solid var(--teal); outline-offset: 3px; box-shadow: none; border-radius: 11px; }

/* The panel hangs from the bottom edge of the header, right-aligned to its content edge, inside the viewport, and scrolls internally when space is short. */
:is(body[data-public="true"], body[data-route="backgammon"]) :is(.app-topbar, .public-header-inner) .account-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: auto;
  width: 320px;
  max-width: calc(100% - 2 * var(--hdr-gutter));
  max-height: max(120px, calc(100dvh - 100% - 12px));
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 12px; /* keyboard focus scrolls a control into the panel with its whole row (and focus ring) visible */
  box-sizing: border-box;
  z-index: 40;
}
body[data-public="true"] .app-topbar .account-menu { right: max(var(--hdr-gutter), calc((100% - var(--pub-outer)) / 2)); }
body[data-route="backgammon"] .app-topbar .account-menu { right: var(--hdr-gutter); }
body[data-public="true"] .public-header-inner .account-menu { right: 0; max-width: 100%; }

/* Panel look (shared by the app panel and the static <details> panel). */
.account-menu { padding: 8px; background: #0c1214; border: 1px solid #344147; border-radius: 14px; box-shadow: 0 24px 60px rgba(0, 0, 0, .48); display: grid; gap: 0; }
.account-menu[hidden] { display: none; }
.account-menu .menu-group { display: grid; gap: 2px; }
.account-menu .menu-group + .menu-group { margin-top: 6px; padding-top: 6px; border-top: 1px solid #2c3b41; }
/* The five-link group is shown by default (compact) only on the routes this header owns; the remaining route keeps styles.css, which hides it once its header shows the links. */
:is(body[data-public="true"], body[data-route="backgammon"]) .account-menu .mobile-platform-nav { display: grid; gap: 2px; margin: 0 0 6px; padding: 0 0 6px; border-bottom: 1px solid #2c3b41; }
:is(body[data-public="true"], body[data-route="backgammon"]) .account-menu .mobile-platform-nav a, .account-menu .menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  margin: 0;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--pub-text, var(--text));
  font: 600 var(--pub-fs-ui, 16px)/1.4 var(--font-sans);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
:is(body[data-public="true"], body[data-route="backgammon"]) .account-menu .mobile-platform-nav a:hover, .account-menu .menu-item:hover { background: rgba(255, 255, 255, .06); color: var(--pub-text, var(--text)); }
:is(body[data-public="true"], body[data-route="backgammon"]) .account-menu .mobile-platform-nav a[aria-current="page"] { background: rgba(95, 224, 192, .08); color: var(--pub-teal, var(--teal)); }
:is(body[data-public="true"], body[data-route="backgammon"]) .account-menu .mobile-platform-nav a:focus-visible, .account-menu .menu-item:focus-visible, .account-menu .language-control:focus-within { outline: 2px solid var(--pub-teal, var(--teal)); outline-offset: -2px; box-shadow: none; border-radius: 10px; }
.account-menu .menu-item-label { flex: 1 1 auto; min-width: min-content; }
.account-menu .language-control { position: static; display: flex; flex-wrap: wrap; row-gap: 6px; height: auto; min-width: 0; overflow: visible; box-shadow: none; }
.account-menu .language-control::after { content: none; }
.account-menu .language-control .language-label { flex: none; color: var(--pub-muted, var(--muted)); font-weight: 500; }
.account-menu .language-control select {
  position: static;
  inset: auto;
  z-index: auto;
  flex: 0 1 auto;
  width: auto;
  max-width: 100%;
  height: auto;
  min-height: 36px;
  padding: 4px 8px;
  opacity: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .04);
  color: var(--pub-text, var(--text));
  font: 500 var(--pub-fs-ui, 16px)/1.4 var(--font-sans);
}
.account-menu .language-control select:focus-visible { outline: 1px solid transparent; box-shadow: none; }

/* Authentication controls follow ONE state: auth.js writes html[data-auth] = unresolved | signed-out | signed-in in a single statement, and these rules derive what may
   render from it (no attribute = unresolved = all hidden). Sign in exists only while signed-out; Sign out and the Backgammon Profile only while signed-in. The
   specificity beats every layout rule that sets display on these ids, so neither a reordered/interrupted per-element update nor a game-route selector can expose them. */
html:not([data-auth="signed-out"]) .app-topbar #loginBtn { display: none; }
html:not([data-auth="signed-in"]) .app-topbar #headerLogoutBtn { display: none; }
html:not([data-auth="signed-in"]) body[data-route] .game-status-bar .status-left > #profileBtn { display: none; }
/* The Backgammon Profile control honours [hidden] (styles.css gives .status-avatar-button display:flex, which would override the attribute). */
body[data-route] .game-status-bar .status-left > #profileBtn[hidden] { display: none; }
.app-topbar :is(#loginBtn, #headerLogoutBtn)[hidden] { display: none; }

/* The shared header chrome of the remaining route keeps styles.css; it only needs the menu to stay reachable now that Language and Sign in live in it. */
body[data-public="false"]:not([data-route="backgammon"]) .app-topbar .account-menu-wrap { display: block; }

@supports (container-type: inline-size) {
  :is(body[data-public="true"], body[data-route="backgammon"]) .app-topbar, body[data-public="true"] .public-header-inner { container-type: inline-size; container-name: tchdr; z-index: 30; }
  /* Public routes and static documents: wide (brand | five links | dots) exactly when the header content width can hold all of it: nav + 2 x brand + 2 gaps, measured from real layout at 1x-3x text, plus a 2px allowance. */
  @container tchdr (width >= calc(27.294em + 250.2px)) {
    body[data-public="true"] :is(.app-topbar, .public-header-inner) > :is(.header-brand, .top-actions) { flex: 1 1 0; }
    body[data-public="true"] :is(.app-topbar > .platform-nav, .public-header-inner > nav) { display: flex; }
    body[data-public="true"] .account-menu .mobile-platform-nav { display: none; }
  }
  /* Public routes and static documents: below this width even the compact row (brand + dots) cannot hold the full lockup, so the wordmark is dropped and the emblem stays; the link keeps its accessible name. */
  @container tchdr (width < calc(7.097em + 122.1px)) {
    body[data-public="true"] :is(.premium-brand, .public-header .public-brand) > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  }
  /* Backgammon route: wide (brand | five links | dots) exactly when the header content width can hold all of it: nav + 2 x brand + 2 gaps, measured from real layout at 1x-3x text, plus a 2px allowance. */
  @container tchdr (width >= calc(23.928em + 264px)) {
    body[data-route="backgammon"] :is(.app-topbar, .public-header-inner) > :is(.header-brand, .top-actions) { flex: 1 1 0; }
    body[data-route="backgammon"] :is(.app-topbar > .platform-nav, .public-header-inner > nav) { display: flex; }
    body[data-route="backgammon"] .account-menu .mobile-platform-nav { display: none; }
  }
  /* Backgammon route: below this width even the compact row (brand + dots) cannot hold the full lockup, so the wordmark is dropped and the emblem stays; the link keeps its accessible name. */
  @container tchdr (width < calc(6.147em + 113.9px)) {
    body[data-route="backgammon"] .app-topbar .premium-brand > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  }
}
