/* CatLab — styles for the CatLab pages (/catlab/, /catlab/chaos/).
   Loaded AFTER the official assets/css/styles.css, which provides the shared site UI
   (skip link, container, header, nav, hamburger, footer, focus ring). Nothing here
   restyles those parts except the few lines in section 1, which only make them
   follow CatLab's own Dark/Light display switch instead of the OS setting.
   Based on CatLab Prototype v5 (shared/lab.css, adopted by the Owner 2026-11-26).
   Class names that the official stylesheet also uses (hero, card, button, note)
   are prefixed with "lab-" here so the two stylesheets cannot collide. */

/* ---- 1. Official site tokens, keyed to the CatLab display switch ----
   Values are the official ones (styles.css :root and its prefers-color-scheme: dark
   block). The QA checks that they stay identical to styles.css. */
:root[data-theme="dark"] {
  --color-bg: #121a1b;
  --color-surface: #182324;
  --color-surface-muted: #1e2b2c;
  --color-text: #eaf0ef;
  --color-text-muted: #a3b3b2;
  --color-border: #2b3a3b;
  --color-accent: #6cc0c3;
  --color-accent-contrast: #0f1718;
  --color-focus: #b7b8de;
  --color-accent-tint: #2e2f47;
}
:root[data-theme="light"] {
  --color-bg: #fafaf9;
  --color-surface: #ffffff;
  --color-surface-muted: #eef2f2;
  --color-text: #1d2b2c;
  --color-text-muted: #4f5f60;
  --color-border: #e1e2e2;
  --color-accent: #1b6b6f;
  --color-accent-contrast: #ffffff;
  --color-focus: #6f70a3;
  --color-accent-tint: #9293bd;
}
/* CatLab pages are a 2-level structure inside the CatLab nav item */
.site-nav__list a[aria-current="true"] { color: var(--color-accent); text-decoration: underline; }
/* Keep the official header/footer metrics (official body line-height 1.7) */
.site-header, .site-footer, .skip-link { line-height: 1.7; -webkit-font-smoothing: antialiased; }
/* The open mobile menu must stay above the CatLab hero (which is positioned) */
.site-header { z-index: 20; }

/* ---- 2. CatLab tokens ---- */
:root,
:root[data-theme="dark"] {
  --brand-teal: #1b6b6f;
  --ui-bg: #0e1516;
  --ui-surface: #152021;
  --ui-surface-muted: #1b2a2b;
  --ui-text: #eaf0ef;
  --ui-text-muted: #a3b3b2;
  --ui-border: #2b3a3b;
  --ui-border-strong: #6a7c7d;
  --ui-link: #6cc0c3;
  --ui-link-hover: #84cdd0;
  --ui-accent: #6cc0c3;
  --ui-on-accent: #0f1718;
  --ui-accent-soft: #1d3537;
  --lab-plot-bg: #0a1011;
  --lab-series-a: #6cc0c3;
  --lab-series-b: #b7b8de;
  --lab-marker: #e8c46a;
  --lab-glow: rgba(27, 107, 111, 0.28);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --ui-bg: #fafaf9;
  --ui-surface: #ffffff;
  --ui-surface-muted: #eef2f2;
  --ui-text: #1d2b2c;
  --ui-text-muted: #4f5f60;
  --ui-border: #e1e2e2;
  --ui-border-strong: #7d8b8b;
  --ui-link: #1b6b6f;
  --ui-link-hover: #144f52;
  --ui-accent: #1b6b6f;
  --ui-on-accent: #ffffff;
  --ui-accent-soft: #e3eff0;
  --lab-plot-bg: #ffffff;
  --lab-series-a: #1b6b6f;
  --lab-series-b: #5f6098;
  --lab-marker: #a3561b;
  --lab-glow: rgba(27, 107, 111, 0.10);
  color-scheme: light;
}

/* ---- 3. Base (overrides the official body/section rules on CatLab pages only) ---- */
body {
  background: var(--ui-bg);
  color: var(--ui-text);
  line-height: 1.75;
  -webkit-font-smoothing: auto;
}
a { color: var(--ui-link); text-underline-offset: 0.2em; }
a:hover { color: var(--ui-link-hover); }
h1, h2, h3 { line-height: 1.35; margin: 0 0 0.6em; letter-spacing: 0.01em; }
h1 { font-size: clamp(1.9rem, 5vw, 2.9rem); font-weight: 650; }
h2 { font-size: clamp(1.3rem, 3vw, 1.65rem); font-weight: 650; }
h3 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0 0 1em; }
section { padding: 36px 0; }
section + section { border-top: 0; }

/* ---- 4. CatLab bar: breadcrumb + display switch ---- */
.theme-switch { display: inline-flex; border: 1px solid var(--ui-border-strong); border-radius: 999px; overflow: hidden; font-size: 0.78rem; }
.theme-switch button { background: none; border: 0; color: var(--ui-text-muted); padding: 4px 12px; cursor: pointer; font: inherit; min-height: 36px; }
.theme-switch button[aria-pressed="true"] { background: var(--ui-accent-soft); color: var(--ui-text); }
.lab-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding-top: 14px; }
.lab-bar .crumbs { padding-top: 0; }
.theme-switch__label { font-size: 0.78rem; color: var(--ui-text-muted); margin-right: 6px; }
.lab-bar__switch { display: inline-flex; align-items: center; }
.crumbs { font-size: 0.85rem; color: var(--ui-text-muted); padding-top: 18px; }
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs li + li::before { content: "/"; margin-right: 6px; color: var(--ui-border-strong); }
.crumbs a { color: var(--ui-text-muted); }

/* ---- 5. Hero ---- */
.lab-hero { position: relative; padding: 40px 0 32px; overflow: hidden; }
.lab-hero::before {
  content: ""; position: absolute; inset: -20% -10% auto auto; width: 70%; height: 140%;
  background: radial-gradient(closest-side, var(--lab-glow), transparent 70%);
  pointer-events: none;
}
.lab-hero__grid { display: grid; gap: 28px; align-items: center; position: relative; }
@media (min-width: 860px) { .lab-hero__grid { grid-template-columns: 1fr 1.05fr; gap: 40px; } .lab-hero { padding: 64px 0 48px; } }
.eyebrow { font-size: 0.8rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ui-accent); margin: 0 0 12px; font-weight: 600; }
.lead { font-size: 1.06rem; color: var(--ui-text-muted); max-width: 36rem; }
.lab-hero--menu { padding-bottom: 12px; }
.lab-hero--menu .lead { max-width: 44rem; }

/* ---- 6. Badges, sections, cards, buttons ---- */
.badge { display: inline-block; font-size: 0.72rem; line-height: 1.4; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; font-weight: 600; letter-spacing: 0.02em; }
.badge--calc { color: var(--ui-accent); }
.badge--status { color: var(--ui-text-muted); }
.badge--soon { color: var(--lab-marker); }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.section-head p { margin: 0; color: var(--ui-text-muted); font-size: 0.9rem; }
.rule { border: 0; border-top: 1px solid var(--ui-border); margin: 0; }
.concepts { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .concepts { grid-template-columns: repeat(3, 1fr); } }
.concept { border-left: 2px solid var(--ui-accent); padding: 4px 0 4px 16px; }
.concept h3 { margin-bottom: 4px; }
.concept p { margin: 0; color: var(--ui-text-muted); font-size: 0.93rem; }
.cards { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .cards--2 { grid-template-columns: 1fr 1fr; } }
.lab-card { background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 8px; position: relative; }
.lab-card--feature { border-color: var(--ui-border-strong); }
.lab-card--muted { background: transparent; border-style: dashed; }
.lab-card__meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 0.8rem; color: var(--ui-text-muted); }
.lab-card h3 { margin: 0; font-size: 1.15rem; }
.lab-card p { margin: 0; color: var(--ui-text-muted); font-size: 0.93rem; }
.lab-card__action { margin-top: auto; padding-top: 8px; }
.lab-button { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 999px; background: var(--ui-accent); color: var(--ui-on-accent); text-decoration: none; font-weight: 600; font-size: 0.95rem; border: 1px solid var(--ui-accent); }
.lab-button:hover { color: var(--ui-on-accent); filter: brightness(1.08); }
.lab-button--ghost { background: transparent; color: var(--ui-text); border-color: var(--ui-border-strong); }
.lab-button--ghost:hover { color: var(--ui-text); background: var(--ui-surface-muted); }
.no-link { font-size: 0.85rem; color: var(--ui-text-muted); }
.lab-note { font-size: 0.82rem; color: var(--ui-text-muted); }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* ---- 7. Home: verbs, rooms, play board ---- */
.verbs { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--ui-border); border: 1px solid var(--ui-border); border-radius: 14px; overflow: hidden; }
.verb { background: var(--ui-surface); padding: 20px 18px; min-height: 120px; display: flex; flex-direction: column; gap: 4px; }
.verb__en { font-size: 0.72rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ui-accent); font-weight: 600; }
.verb__ja { font-size: 1.35rem; font-weight: 650; }
.verb p { margin: 0; font-size: 0.85rem; color: var(--ui-text-muted); line-height: 1.6; }
.room-no { font-family: ui-monospace, Menlo, monospace; font-size: 0.78rem; color: var(--ui-accent); letter-spacing: 0.08em; }
.fields { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 12px 0 0; }
.fields li { font-size: 0.85rem; padding: 4px 12px; border-radius: 999px; border: 1px dashed var(--ui-border-strong); color: var(--ui-text-muted); }
.verbs--row { margin: 0; }
@media (min-width: 720px) { .verbs--row { grid-template-columns: repeat(4, 1fr); } }
.verbs-row { padding-top: 0; }
.play { background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: 16px; padding: 16px; display: grid; gap: 12px; }
.play__head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; justify-content: space-between; }
.play__title { margin: 0; font-weight: 650; font-size: 1.05rem; }
.play .badge { white-space: normal; font-weight: 500; }
.board { position: relative; aspect-ratio: 4 / 3; background: var(--lab-plot-bg); border: 1px solid var(--ui-border); border-radius: 12px; overflow: hidden; }
.board__label { position: absolute; transform: translate(-50%, -50%); font-size: 0.72rem; color: var(--ui-text-muted); letter-spacing: 0.06em; opacity: 0; transition: opacity .3s ease; pointer-events: none; white-space: nowrap; }
.board__label.is-on { opacity: 1; }
.tok { position: absolute; transform: translate(-50%, -50%); width: 44px; height: 44px; padding: 0; border: 0; background: none; cursor: pointer; display: grid; place-items: center; border-radius: 50%;
  transition: left .55s cubic-bezier(.3,.7,.2,1), top .55s cubic-bezier(.3,.7,.2,1), opacity .25s ease; color: var(--tok-color); -webkit-tap-highlight-color: transparent; }
.tok[data-tone="a"] { --tok-color: var(--lab-series-a); }
.tok[data-tone="b"] { --tok-color: var(--lab-series-b); }
.tok__g { display: block; width: var(--s); height: var(--s); }
.tok[data-kind="dot"] .tok__g { border-radius: 50%; background: currentColor; }
.tok[data-kind="shape"][data-form="tri"] .tok__g { background: currentColor; clip-path: polygon(50% 6%, 96% 92%, 4% 92%); }
.tok[data-kind="shape"][data-form="sq"] .tok__g { border: 2px solid currentColor; border-radius: 2px; }
.tok[data-kind="char"] .tok__g { width: auto; height: auto; font-size: var(--s); line-height: 1; font-weight: 600; }
.tok[data-size="1"] { --s: 12px; } .tok[data-size="2"] { --s: 18px; } .tok[data-size="3"] { --s: 26px; }
.tok[data-kind="char"][data-size="1"] { --s: 13px; } .tok[data-kind="char"][data-size="2"] { --s: 19px; } .tok[data-kind="char"][data-size="3"] { --s: 27px; }
.tok:hover { background: color-mix(in srgb, var(--tok-color) 14%, transparent); }
.board.has-sel .tok { opacity: 0.28; }
.board.has-sel .tok.is-related { opacity: 1; }
.tok.is-related::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; border: 1px dashed var(--tok-color); }
.tok[aria-pressed="true"]::after { border-style: solid; border-width: 2px; inset: 2px; }
.sorts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sorts__label { font-size: 0.85rem; color: var(--ui-text-muted); }
.sorts button { font: inherit; font-size: 0.88rem; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--ui-border-strong); background: transparent; color: var(--ui-text); cursor: pointer; }
.sorts button[aria-pressed="true"] { background: var(--ui-accent-soft); border-color: var(--ui-accent); }
.play__readout { margin: 0; font-size: 0.88rem; color: var(--ui-text-muted); min-height: 3.2em; line-height: 1.6; }
.play__readout b { color: var(--ui-text); font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .tok, .board__label { transition: none !important; } }

/* ---- 8. Chaos Theory menu ---- */
.facts { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 22px; padding: 0; margin: 8px 0 0; font-size: 0.88rem; color: var(--ui-text-muted); }
.facts b { color: var(--ui-text); font-family: ui-monospace, Menlo, monospace; font-size: 1.05rem; }
.ex-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .ex-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .ex-grid { grid-template-columns: repeat(3, 1fr); } }
.ex-card { background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ex-card h3 { margin: 0; font-size: 1.1rem; display: flex; flex-direction: column; gap: 2px; }
.ex-card__ja { font-size: 0.88rem; font-weight: 600; color: var(--ui-text-muted); }
.ex-card p { margin: 0; color: var(--ui-text-muted); font-size: 0.92rem; }
.ex-card__meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ex-card__meta .badge { margin-left: auto; }
.ex-card__no { font-family: ui-monospace, Menlo, monospace; color: var(--ui-accent); font-size: 0.9rem; }
.ex-card .id { font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; color: var(--ui-text-muted); }
.ex-card--featured { border-color: var(--ui-accent); background: linear-gradient(135deg, var(--ui-accent-soft), var(--ui-surface) 70%); }
.ex-card--featured .featured__flag { margin: 0; font-size: 0.78rem; color: var(--ui-accent); font-weight: 600; letter-spacing: 0.04em; }
.ex-card__action { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: auto; padding-top: 6px; }
@media (min-width: 640px) { .ex-card--featured { grid-column: span 2; } }
.series-head { border-left: 3px solid var(--ui-accent); padding: 2px 0 2px 16px; margin-bottom: 20px; }
.series-head__no { margin: 0 0 2px; font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem; letter-spacing: 0.14em; color: var(--ui-accent); text-transform: uppercase; }
.series-head h2 { margin: 0 0 6px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.series-head__ja { font-size: 0.72em; color: var(--ui-text-muted); font-weight: 600; }
.series-head__lead { margin: 0 0 4px; color: var(--ui-text-muted); max-width: 44rem; }
.series-head .lab-note { margin: 0; }
.future { border: 1px dashed var(--ui-border-strong); border-radius: 14px; padding: 18px; }
.future__title { font-size: 1.05rem; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-bottom: 6px; }
.future__list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
@media (min-width: 760px) { .future__list { grid-template-columns: repeat(3, 1fr); } }
.future__list li { display: flex; flex-direction: column; gap: 2px; font-size: 0.88rem; color: var(--ui-text-muted); }
.future__list li span[lang="en"] { color: var(--ui-text); font-weight: 600; font-size: 0.95rem; }

/* ---- 9. Contact (both CatLab pages) ---- */
.lab-contact { background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: 14px; padding: 20px; display: grid; gap: 4px; max-width: 46rem; }
.lab-contact h2 { font-size: 1.15rem; margin: 0 0 4px; }
.lab-contact p { margin: 0; color: var(--ui-text-muted); font-size: 0.93rem; }
.lab-contact .lab-button { justify-self: start; margin-top: 12px; }

/* ---- 10. Same chrome details as the exhibit pages (CHAOS-0001 handoff 2026-11-26, common spec §5/§6) ----
   Dark: header and footer on the official site surface (#121a1b), exhibit hall #0e1516.
   CatLab-owned controls are at least 44 px high. */
.site-footer { background: var(--color-bg); }
.theme-switch button { min-height: 44px; }
.skip-link { min-height: 44px; display: inline-flex; align-items: center; }

/* CatLab rule: breadcrumb links are 44px high targets (2026-11-27). */
.crumbs a { display: inline-flex; align-items: center; min-height: 44px; }

/* CatLab rule: the home play-board buttons are 44px high targets (2026-11-27). */
.sorts button { min-height: 44px; }
/* Text 200%: the 4 ideas never get cut off (columns may shrink, words wrap) (2026-11-27). */
.verbs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .verbs--row { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.verb__en, .verb__ja, .verb p { overflow-wrap: anywhere; }

/* iPhone QA 2026-11-27: on phones the 4 "並べ方" buttons are a 2 x 2 grid, same width and height. */
@media (max-width: 719.98px) {
  .sorts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: auto 1fr 1fr; gap: 8px; align-items: stretch; }
  .sorts__label { grid-column: 1 / -1; }
  .sorts button { width: 100%; min-height: 44px; padding: 6px 10px; line-height: 1.3; overflow-wrap: anywhere; }
  /* 1fr rows: both button rows get the height of the tallest button, also at text 200%. */
}
