/* ====================================================================
 * Documentation chrome — kept entirely separate from the framework
 * classes being demonstrated. Examples below use ONLY vanilla HTML/CSS
 * plus the classes wiki-styles-2 ships.
 * ================================================================== */

:root {
  --font-body: RooneySansWeb, "Source Sans 3", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --paper: #faf7f0;
  --paper-sunk: #f2ede1;
  --ink: #16140e;
  --ink-muted: #6c6757;
  --ink-faint: #a8a394;
  --rule: #e6dfc9;
  --rule-strong: #d4cbb0;
  --accent: var(--c-pcwiki, #3461a2);
  --accent-deep: var(--c-pcwiki-dark, #1f3d6b);
  --code-bg: #14161d;
  --code-ink: #e9e6dd;
  --code-rule: #262934;

  --shadow-1: 0 1px 0 rgb(0 0 0 / 0.03), 0 1px 2px rgb(0 0 0 / 0.04);
  --shadow-2: 0 2px 0 rgb(0 0 0 / 0.04), 0 6px 18px rgb(0 0 0 / 0.06);

  --topbar-h: 3.5rem;
  --side-w: 17rem;
  --max-w: 78rem;
  --gutter: clamp(1rem, 4vw, 2.5rem);

  color-scheme: light;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 1rem);
}

:root[data-theme="dark"] {
  --paper: #0f1116;
  --paper-sunk: #181b22;
  --ink: #ece8dc;
  --ink-muted: #948e7d;
  --ink-faint: #555248;
  --rule: #262933;
  --rule-strong: #353846;
  --accent: var(--c-pcwiki-light, #6b94d4);
  --accent-deep: var(--c-pcwiki, #3461a2);
  --code-bg: #08090d;
  --code-ink: #dcd8cb;
  --code-rule: #1b1d26;

  --shadow-1: 0 1px 0 rgb(0 0 0 / 0.3), 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-2: 0 2px 0 rgb(0 0 0 / 0.3), 0 6px 18px rgb(0 0 0 / 0.5);

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* paper texture — invisible noise to break the flatness */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
  background-image: url("data:image/svg+xml;utf8,<svg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

:root[data-theme="dark"] body::before {
  opacity: 0.6;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--accent-deep);
}

code,
kbd,
pre,
samp {
  font-family: var(--font-mono);
}

:not(pre) > code {
  font-size: 0.85em;
  padding: 0.1em 0.35em;
  border-radius: 0.25rem;
  background: var(--paper-sunk);
  border: 1px solid var(--rule);
  color: var(--ink);
  white-space: nowrap;
}

/* ===== Top bar ===== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 var(--gutter);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 1.85rem;
  height: 1.85rem;
  display: inline-grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.7rem;
  color: var(--paper);
  background: var(--ink);
  border-radius: 0.45rem;
  letter-spacing: -0.02em;
}

:root[data-theme="dark"] .brand-mark {
  background: var(--accent);
}

.brand-name {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.85rem;
}

.brand-sub {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--ink-muted);
  padding-left: 0.5rem;
  margin-left: 0.5rem;
  border-left: 1px solid var(--rule);
}

@media (max-width: 720px) {
  .brand-sub {
    display: none;
  }
}

.topbar-spacer {
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.icon-btn,
.topbar-actions a {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 0.5rem;
  color: var(--ink-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover,
.topbar-actions a:hover {
  background: var(--paper-sunk);
  color: var(--ink);
  border-color: var(--rule);
}

.icon-btn svg,
.topbar-actions a svg {
  width: 1.05rem;
  height: 1.05rem;
}

.nav-toggle {
  display: none;
}

/* ===== Layout shell ===== */

.shell {
  position: relative;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

@media (max-width: 960px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    padding: 0 var(--gutter);
  }
  .nav-toggle {
    display: inline-grid;
  }
}

/* ===== Sidebar ===== */

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 2rem 1.25rem 3rem 0;
  font-size: 0.875rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-strong) transparent;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--rule-strong);
  border-radius: 3px;
}

.sidebar h6 {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 1.5rem 0 0.4rem;
  padding: 0 0.5rem;
}

.sidebar h6:first-child {
  margin-top: 0;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
}

.sidebar nav a {
  display: block;
  padding: 0.3rem 0.75rem;
  margin: 0 -0.25rem;
  border-radius: 0.4rem;
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 500;
  line-height: 1.4;
  position: relative;
}

.sidebar nav a:hover {
  color: var(--ink);
  background: var(--paper-sunk);
}

.sidebar nav a.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.sidebar nav a.active::before {
  content: "";
  position: absolute;
  left: -0.25rem;
  top: 0.5rem;
  bottom: 0.5rem;
  width: 2px;
  background: var(--accent);
  border-radius: 1px;
}

@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    /* dvh handles mobile browser-chrome resize; vh fallback for old engines */
    height: calc(100vh - var(--topbar-h));
    height: calc(100dvh - var(--topbar-h));
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--paper);
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    padding: 1.25rem var(--gutter) 4rem;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-2);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
}

/* ===== Main column ===== */

main {
  position: relative;
  padding: 3rem 0 8rem;
  min-width: 0;
}

@media (min-width: 961px) {
  main {
    padding-left: 2.5rem;
    padding-right: 1rem;
  }
}

/* ===== Hero ===== */

.hero {
  padding-bottom: 3rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 3rem;
}

.hero .eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 1rem;
}

.hero .eyebrow::before {
  content: "";
  width: 1.5rem;
  height: 1px;
  background: var(--ink-faint);
}

.hero h1 {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: clamp(2.25rem, 5vw, 3.75rem);
  line-height: 1.05;
  letter-spacing: -0.025em;
  margin: 0 0 1.25rem;
}

.hero h1 .accent {
  color: var(--accent);
}

.hero p {
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--ink-muted);
  max-width: 42rem;
  margin: 0 0 1.5rem;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 1.25rem;
  max-width: 36rem;
}

.hero-stat {
  border-top: 1px solid var(--rule-strong);
  padding-top: 0.6rem;
}

.hero-stat .num {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
  display: block;
  line-height: 1;
}

.hero-stat .lbl {
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-top: 0.3rem;
  display: block;
}

/* ===== Sections ===== */

section.doc {
  padding: 4rem 0;
  scroll-margin-top: calc(var(--topbar-h) + 1.5rem);
}

section.doc + section.doc {
  border-top: 1px solid var(--rule);
}

.section-head {
  margin-bottom: 1.5rem;
}

.section-num {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  text-transform: uppercase;
  margin-bottom: 0.5rem;
  display: block;
}

h2.section-title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: clamp(1.5rem, 3vw, 2rem);
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0 0 0.5rem;
  color: var(--ink);
}

h2.section-title code {
  font-size: 0.7em;
  font-weight: 500;
  background: var(--paper-sunk);
  border: 1px solid var(--rule);
  padding: 0.15em 0.4em;
  border-radius: 0.3rem;
  vertical-align: 0.15em;
  white-space: nowrap;
}

.section-lede {
  font-size: 1.05rem;
  color: var(--ink-muted);
  max-width: 44rem;
  margin: 0;
}

h3.sub-title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.15rem;
  margin: 2.5rem 0 0.75rem;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.sub-lede {
  color: var(--ink-muted);
  margin: 0 0 1.25rem;
  max-width: 44rem;
}

/* ===== Example block — tabs at TOP ===== */

.example {
  margin: 1.25rem 0;
  border: 1px solid var(--rule);
  border-radius: 0.85rem;
  overflow: hidden;
  background: var(--paper);
  box-shadow: var(--shadow-1);
}

.example-tabs {
  display: flex;
  border-bottom: 1px solid var(--rule);
  background: var(--paper-sunk);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0 0.5rem;
  min-height: 2.4rem;
  align-items: stretch;
}

.example-tabs button {
  background: none;
  border: 0;
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: inherit;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.example-tabs button:hover {
  color: var(--ink);
}

.example-tabs button.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.example-tabs .copy-btn {
  margin-left: auto;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: inherit;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: none;
  border: 0;
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.example-tabs .copy-btn:hover {
  color: var(--ink);
}

.example-tabs .copy-btn.copied {
  color: var(--accent);
}

.example-preview {
  padding: 2rem;
  background:
    radial-gradient(circle at 1px 1px, var(--rule) 1px, transparent 0) 0 0 / 16px 16px,
    var(--paper);
  position: relative;
  min-height: 5rem;
}

.example-preview.compact {
  padding: 1rem;
}

.example-preview.dim {
  background: var(--paper-sunk);
}

.example-source {
  background: var(--code-bg);
  max-height: 24rem;
  overflow: auto;
}

.example-source pre {
  margin: 0;
  padding: 1rem 1.25rem;
  background: transparent;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--code-ink);
}

.example-source pre code {
  background: transparent;
  border: 0;
  padding: 0;
  font-size: inherit;
  white-space: pre;
}

.example-source pre[class*="language-"] {
  background: transparent;
  color: var(--code-ink);
  text-shadow: none;
}

.example-source .token.tag,
.example-source .token.keyword {
  color: #f08aab;
}
.example-source .token.attr-name {
  color: #f5d76e;
}
.example-source .token.attr-value,
.example-source .token.string {
  color: #a4d9a1;
}
.example-source .token.punctuation {
  color: #8b8779;
}
.example-source .token.comment {
  color: #555248;
  font-style: italic;
}

/* ===== Class reference table ===== */

.classref {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin: 0.5rem 0 1.5rem;
  border: 1px solid var(--rule);
  border-radius: 0.6rem;
  overflow: hidden;
  background: var(--paper);
}

.classref caption {
  caption-side: top;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 0 0 0.5rem;
}

.classref th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  background: var(--paper-sunk);
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--rule);
}

.classref td {
  padding: 0.5rem 0.85rem;
  vertical-align: top;
  border-top: 1px solid var(--rule);
  color: var(--ink-muted);
}

.classref tbody tr:first-child td {
  border-top: 0;
}

.classref tbody tr:hover {
  background: color-mix(in srgb, var(--paper-sunk) 50%, transparent);
}

.classref td:first-child {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink);
  white-space: nowrap;
  width: 1%;
}

.classref td.css {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

.classref code {
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.classref .muted {
  color: var(--ink-faint);
}

@media (max-width: 540px) {
  .classref {
    font-size: 0.78rem;
  }
  .classref th,
  .classref td {
    padding: 0.45rem 0.65rem;
  }
  .classref td.css {
    white-space: normal;
  }
}

/* ===== Controls panel ===== */

.controls-panel {
  margin: 0.75rem 0 1.25rem;
  padding: 1rem 1.25rem;
  background: var(--paper-sunk);
  border: 1px solid var(--rule);
  border-radius: 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1rem 1.25rem;
  align-items: end;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.control-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.control-value {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 0.72rem;
}

.control input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  background: transparent;
  height: 1.5rem;
}

.control input[type="color"] {
  width: 100%;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: 0.4rem;
  background: var(--paper);
  cursor: pointer;
}

.control input[type="search"],
.control input[type="text"],
.control select {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  color: var(--ink);
  border-radius: 0.4rem;
  font-family: inherit;
  font-size: 0.875rem;
}

.control .checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--ink);
  padding: 0.5rem 0;
}

.control input[type="checkbox"] {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
}

/* ===== Color tokens grid (variant strips) ===== */

.tokens {
  margin-top: 0.5rem;
}

.token-group {
  margin-top: 1.5rem;
}

.token-group:first-of-type {
  margin-top: 0;
}

.token-group-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
  margin-bottom: 0.5rem;
}

.token-group-head h4 {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  margin: 0;
}

.token-group-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-faint);
}

.token-group-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 0.15rem 1.25rem;
}

.token-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.5rem;
  border-radius: 0.4rem;
  position: relative;
}

.token-row:hover {
  background: var(--paper-sunk);
}

.token-name {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.token-name.is-alias::after {
  content: "→";
  color: var(--ink-faint);
  margin-left: 0.35rem;
  font-weight: 700;
}

.token-variants {
  display: inline-flex;
  gap: 2px;
  flex-shrink: 0;
}

.token-variant {
  width: 1.35rem;
  height: 1.55rem;
  border-radius: 0.25rem;
  cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
  position: relative;
  transition: transform 0.1s ease;
}

.token-variant:hover {
  transform: translateY(-1px);
  z-index: 2;
}

.token-variant[data-empty="1"] {
  background: repeating-linear-gradient(
    45deg,
    var(--rule) 0 3px,
    var(--paper-sunk) 3px 6px
  );
  cursor: default;
  opacity: 0.4;
}

.token-variant[data-empty="1"]:hover {
  transform: none;
}

.token-row[data-hidden="1"] {
  display: none;
}

.token-group[data-empty="1"] {
  display: none;
}

.token-variant-legend {
  display: flex;
  gap: 0.85rem;
  margin: 0.85rem 0 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-muted);
  flex-wrap: wrap;
}

.token-variant-legend span::before {
  content: "";
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 0.15rem;
  margin-right: 0.35rem;
  vertical-align: -0.05rem;
  border: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
}

.token-toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(2rem);
  background: var(--ink);
  color: var(--paper);
  padding: 0.5rem 0.9rem;
  border-radius: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  box-shadow: var(--shadow-2);
}

.token-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Helpers for example surfaces ===== */

.demo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.5rem;
}

.demo-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.demo-box {
  min-width: 4.5rem;
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.demo-box.placeholder {
  background: var(--rule);
  color: var(--ink-muted);
  border-radius: 0.35rem;
}

.demo-stage {
  background: light-dark(rgb(255 255 255 / 0.5), rgb(0 0 0 / 0.2));
  border: 1px dashed var(--rule-strong);
  border-radius: 0.5rem;
  padding: 0.5rem;
}

.alert {
  display: flex;
  gap: 0.85rem;
  padding: 1rem 1.15rem;
  background: color-mix(in srgb, var(--accent) 6%, var(--paper));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--rule));
  border-left: 3px solid var(--accent);
  border-radius: 0.5rem;
  font-size: 0.92rem;
  color: var(--ink);
  margin: 1rem 0 1.25rem;
}

.alert::before {
  content: "i";
  flex-shrink: 0;
  width: 1.2rem;
  height: 1.2rem;
  display: inline-grid;
  place-items: center;
  font-family: var(--font-mono);
  font-style: italic;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--paper));
  border-radius: 50%;
}

/* ===== Nested roundy stage ===== */

.nested-stage {
  background: light-dark(#f2efe5, #1c1f27);
  border: 1px solid var(--rule);
  border-radius: 0.6rem;
  padding: 0.5rem;
  min-height: 16rem;
  display: flex;
}

.nested-stage > .roundy {
  flex: 1;
  min-height: 15rem;
}

.nested-stage .roundy {
  position: relative;
  display: flex;
  flex-direction: column;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: #fff;
}

.nested-stage .roundy > .roundy {
  flex: 1;
}

/* Labels at top-LEFT so they cascade diagonally as boxes inset.
   Show depth and computed --br-effective (populated via JS). */
.nested-stage .roundy::before {
  content: "L" attr(data-depth) " · " attr(data-eff);
  position: absolute;
  top: 0.3rem;
  left: 0.5rem;
  opacity: 0.92;
  font-weight: 700;
  pointer-events: none;
  z-index: 1;
  font-size: 0.66rem;
  letter-spacing: 0.02em;
  background: rgb(0 0 0 / 0.25);
  padding: 0.05rem 0.35rem;
  border-radius: 0.25rem;
}

.nested-stage > .roundy,
.nested-stage > .roundy > .roundy > .roundy,
.nested-stage > .roundy > .roundy > .roundy > .roundy > .roundy {
  background: var(--c-pcwiki-dark);
}

.nested-stage > .roundy > .roundy,
.nested-stage > .roundy > .roundy > .roundy > .roundy,
.nested-stage > .roundy > .roundy > .roundy > .roundy > .roundy > .roundy {
  background: var(--c-pcwiki);
}

/* Depth readout table — shows the subtraction math per level */
.depth-readout {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.82rem;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  overflow: hidden;
}

.depth-readout th,
.depth-readout td {
  padding: 0.4rem 0.75rem;
  text-align: left;
  border-top: 1px solid var(--rule);
}

.depth-readout th {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  background: var(--paper-sunk);
  border-top: 0;
}

.depth-readout td {
  font-family: var(--font-mono);
  color: var(--ink-muted);
}

.depth-readout td:first-child {
  color: var(--accent);
  font-weight: 600;
}

/* Responsive demo banners */

.responsive-banner {
  padding: 0.85rem 1rem;
  font-weight: 600;
  text-align: center;
  margin: 0.4rem 0;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.viewport-readout {
  position: absolute;
  top: 0.6rem;
  right: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  background: var(--code-bg);
  color: var(--code-ink);
  border-radius: 0.25rem;
  letter-spacing: 0.04em;
}

/* Roundy variant grid */

.roundy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.75rem, 1fr));
  gap: 0.5rem;
}

.roundy-grid > * {
  min-height: 3.5rem;
  background: var(--c-pcwiki-light);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

:root[data-theme="dark"] .roundy-grid > * {
  color: #fff;
}

/* ===== Footer ===== */

footer {
  border-top: 1px solid var(--rule);
  padding: 2.5rem 0 1.5rem;
  margin-top: 5rem;
  color: var(--ink-muted);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

footer .build-stamp {
  font-family: var(--font-mono);
}

/* Scroll-to-top floating button */
.to-top {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 30;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  border: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1.05rem;
  opacity: 0;
  transform: translateY(0.5rem);
  transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: var(--shadow-2);
}

.to-top.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Backdrop for mobile nav */
.nav-backdrop {
  display: none;
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgb(0 0 0 / 0.3);
  z-index: 35;
}

.nav-backdrop.visible {
  display: block;
}

@media (min-width: 961px) {
  .nav-backdrop {
    display: none !important;
  }
}

/* ===== Misc ===== */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15em 0.55em;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 0.3rem;
  background: var(--paper-sunk);
  color: var(--ink-muted);
  border: 1px solid var(--rule);
}

.pill.accent {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-color: color-mix(in srgb, var(--accent) 25%, var(--rule));
}

/* Prevent demo elements from breaking out of preview */
.example-preview > * {
  max-width: 100%;
}

/* Mobile tweaks */
@media (max-width: 540px) {
  .example-preview {
    padding: 1.25rem;
  }
  .controls-panel {
    padding: 0.85rem;
  }
  .sidebar nav a {
    padding: 0.45rem 0.75rem;
    font-size: 0.95rem;
  }
  .hero {
    padding-bottom: 2rem;
    margin-bottom: 2rem;
  }
  section.doc {
    padding: 2.5rem 0;
  }
  .token-group-list {
    grid-template-columns: 1fr;
  }
}
