/*
 * Whetstone for Docs
 * ------------------
 * MkDocs Material adapter for the kensan-lab Whetstone design tokens.
 * Keep this file limited to documentation-site chrome and Markdown
 * rendering. App component rules still live in packages/design-tokens/.
 */

:root {
  --whetstone-font-sans: "Inter", "Hiragino Sans", "Noto Sans JP", ui-sans-serif, system-ui, sans-serif;
  --whetstone-font-serif: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --whetstone-font-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;
  --whetstone-radius: 0.5rem;
  --whetstone-shadow-sm: 0 1px 3px 0 hsl(30 20% 10% / 0.08), 0 1px 2px -1px hsl(30 20% 10% / 0.04);

  /* Mermaid diagrams are dark in both schemes — see the .md-typeset .mermaid
     block for why they cannot follow the palette. These mirror the slate
     scheme's values so the diagram panel reads as one surface with them. */
  --diagram-background: 30 10% 13%;
  --diagram-surface: 30 10% 15%;
  --diagram-foreground: 40 27% 94%;
  --diagram-muted-foreground: 30 8% 72%;
  --diagram-border: 30 10% 24%;
  --diagram-accent: 199 89% 60%;
  --diagram-accent-muted: 199 40% 25%;
  --diagram-accent-foreground: 30 10% 13%;
}

[data-md-color-scheme="default"] {
  --background: 40 27% 94%;
  --foreground: 36 11% 9%;
  --card: 40 38% 98%;
  --card-foreground: 36 11% 9%;
  --muted: 40 22% 90%;
  --muted-foreground: 32 8% 45%;
  --accent: 199 70% 92%;
  --accent-foreground: 199 89% 25%;
  --border: 36 23% 85%;
  --border-strong: 36 23% 78%;
  --brand: 199 89% 40%;
  --brand-foreground: 40 38% 98%;
  --brand-muted: 199 70% 92%;
  --success: 145 40% 36%;
  --warning: 32 80% 45%;
  --destructive: 4 70% 48%;
  --info: 199 89% 40%;
}

[data-md-color-scheme="slate"] {
  --background: 30 10% 13%;
  --foreground: 40 27% 94%;
  --card: 30 10% 15%;
  --card-foreground: 40 27% 94%;
  --muted: 30 10% 18%;
  --muted-foreground: 30 8% 72%;
  --accent: 199 40% 22%;
  --accent-foreground: 199 89% 80%;
  --border: 30 10% 24%;
  --border-strong: 30 10% 32%;
  --brand: 199 89% 60%;
  --brand-foreground: 30 10% 13%;
  --brand-muted: 199 40% 25%;
  --success: 145 45% 52%;
  --warning: 32 90% 62%;
  --destructive: 4 65% 52%;
  --info: 199 89% 60%;
}

[data-md-color-scheme] {
  --md-default-bg-color: hsl(var(--background));
  --md-default-fg-color: hsl(var(--foreground));
  --md-default-fg-color--light: hsl(var(--muted-foreground));
  --md-default-fg-color--lighter: hsl(var(--muted-foreground) / 0.72);
  --md-default-fg-color--lightest: hsl(var(--muted-foreground) / 0.42);
  --md-primary-fg-color: hsl(var(--card));
  --md-primary-bg-color: hsl(var(--foreground));
  --md-accent-fg-color: hsl(var(--brand));
  --md-typeset-a-color: hsl(var(--brand));
  --md-code-bg-color: hsl(var(--muted));
  --md-code-fg-color: hsl(var(--foreground));
  --md-code-hl-color: hsl(var(--brand) / 0.18);
  --md-footer-bg-color: hsl(var(--card));
  --md-footer-bg-color--dark: hsl(var(--background));
  --md-footer-fg-color: hsl(var(--foreground));
  --md-footer-fg-color--light: hsl(var(--muted-foreground));
  --md-footer-fg-color--lighter: hsl(var(--muted-foreground) / 0.72);
  --md-shadow-z1: none;
  --md-shadow-z2: var(--whetstone-shadow-sm);
  --md-shadow-z3: var(--whetstone-shadow-sm);
}

body {
  font-family: var(--whetstone-font-sans);
  font-feature-settings: "ss01", "cv11";
  text-rendering: optimizeLegibility;
}

.md-header {
  border-bottom: 1px solid hsl(var(--border));
  box-shadow: none;
}

.md-header,
.md-tabs {
  background-color: hsl(var(--card));
  color: hsl(var(--foreground));
}

.md-header__title,
.md-tabs__link {
  color: hsl(var(--foreground));
}

.md-search__form {
  background-color: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  border-radius: var(--whetstone-radius);
}

.md-search__form:hover {
  background-color: hsl(var(--card));
}

/* Material's placeholder color assumes a dark indigo header; ours is light in
   the default scheme, so the inherited white-on-light placeholder is
   unreadable until the search box is focused. */
[data-md-color-scheme="default"] .md-search__input::placeholder {
  color: hsl(var(--muted-foreground));
  opacity: 1;
}

.md-nav__link--active,
.md-nav__link[aria-current="page"] {
  color: hsl(var(--brand));
  font-weight: 600;
}

.md-nav__item .md-nav__link--active {
  background-color: hsl(var(--brand-muted) / 0.34);
  border-radius: calc(var(--whetstone-radius) - 2px);
  padding-inline: 0.4rem;
}

/* Sticky section titles only mask their own line height; long nav labels
   that wrap to two lines can peek out from underneath as the sidebar
   scrolls. Same-color blur widens the masked area without looking like a
   shadow. */
.md-nav__title {
  background-color: hsl(var(--background));
  box-shadow: 0 0 0.4rem 0.4rem hsl(var(--background));
}

/* Search results reuse .md-typeset for teaser formatting, which also pulls
   in the h1/h2 serif rule below — reset it so result titles stay UI (sans),
   matching the 3-typeface rule (serif is for document headings only). */
.md-search-result__article.md-typeset h1,
.md-search-result__article.md-typeset h2,
.md-search-result__article.md-typeset h3 {
  font-family: var(--whetstone-font-sans);
  font-size: inherit;
  font-weight: 700;
}

.md-typeset {
  color: hsl(var(--foreground));
}

.md-typeset h1,
.md-typeset h2 {
  color: hsl(var(--foreground));
  font-family: var(--whetstone-font-serif);
  font-weight: 600;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.md-typeset h1 {
  font-size: clamp(2rem, 3.4vw, 2.65rem);
  line-height: 1.12;
  margin-bottom: 0.8em;
  word-break: break-word;
}

.md-typeset h2 {
  border-top: 1px solid hsl(var(--border));
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  line-height: 1.18;
  padding-top: 1.2rem;
}

.md-typeset h3,
.md-typeset h4 {
  color: hsl(var(--foreground));
  letter-spacing: 0;
}

.md-typeset a {
  color: hsl(var(--brand));
}

/* Material's .md-button inherits --md-primary-fg-color, which we point at
   the header's card background (not a real "primary" fill) — override with
   the actual brand/outline pairing from the Button component spec. */
.md-typeset .md-button,
.md-typeset .cta-row a {
  background-color: transparent;
  border: 1px solid hsl(var(--border-strong));
  border-radius: var(--whetstone-radius);
  color: hsl(var(--foreground));
  font-weight: 600;
}

.md-typeset .md-button:hover,
.md-typeset .cta-row a:hover {
  background-color: hsl(var(--muted));
  border-color: hsl(var(--border-strong));
  color: hsl(var(--foreground));
}

.md-typeset .md-button--primary,
.md-typeset .cta-row a:first-child {
  background-color: hsl(var(--brand));
  border-color: hsl(var(--brand));
  color: hsl(var(--brand-foreground));
}

.md-typeset .md-button--primary:hover,
.md-typeset .cta-row a:first-child:hover {
  background-color: hsl(var(--brand) / 0.88);
  border-color: hsl(var(--brand) / 0.88);
  color: hsl(var(--brand-foreground));
}

/* Home CTA. Material's `{ .md-button }` attr_list renders as literal text on
   GitHub (scripts/check-github-render.py), so the buttons are plain Markdown
   links — which both engines resolve — and the button shape comes from here.
   First link is the primary action; the row only ever holds the two. */
.md-typeset .cta-row > p {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 1.2em;
}

.md-typeset .cta-row a {
  display: inline-block;
  padding: 0.625em 2em;
  transition: background-color 125ms, border-color 125ms, color 125ms;
}

.md-typeset a:hover {
  color: hsl(var(--brand) / 0.82);
}

.md-typeset code,
.md-typeset kbd,
.md-typeset pre {
  font-family: var(--whetstone-font-mono);
}

.md-typeset code {
  border: 1px solid hsl(var(--border));
  border-radius: 4px;
}

.md-typeset pre > code {
  border: 1px solid hsl(var(--border));
  border-radius: var(--whetstone-radius);
}

.md-typeset table:not([class]) {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--whetstone-radius);
  box-shadow: none;
  overflow: hidden;
}

.md-typeset__scrollwrap {
  margin-inline: 0;
}

.md-typeset table:not([class]) th {
  background-color: hsl(var(--muted));
  color: hsl(var(--foreground));
  font-weight: 650;
}

.md-typeset table:not([class]) td {
  border-top: 1px solid hsl(var(--border));
}

.md-typeset table:not([class]) code {
  word-break: keep-all;
}

.md-typeset figure {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--whetstone-radius);
  margin-inline: 0;
  padding: 1rem;
}

.md-typeset figure img {
  border-radius: calc(var(--whetstone-radius) - 4px);
}

.md-typeset figure figcaption {
  color: hsl(var(--muted-foreground));
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

.md-typeset .admonition,
.md-typeset details {
  background-color: hsl(var(--card));
  border-color: hsl(var(--border-strong));
  border-radius: var(--whetstone-radius);
  box-shadow: none;
}

.md-typeset .admonition-title,
.md-typeset summary {
  background-color: hsl(var(--muted));
  border-top-left-radius: var(--whetstone-radius);
  border-top-right-radius: var(--whetstone-radius);
}

.md-typeset .grid.cards > ul > li,
.md-typeset .grid > .card {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--whetstone-radius);
  box-shadow: none;
}

/* Mermaid diagrams stay dark in both schemes, framed as a deliberate dark
   figure in the light scheme.
   Two hard constraints make per-scheme re-coloring impossible from here:
   (1) Material renders every diagram into a *closed* shadow root, so no
       selector in this file reaches the SVG — only inherited properties and
       custom properties cross the boundary;
   (2) mermaid v11 emits classDef colors as inline `!important`, which outrank
       stylesheet `!important` in the cascade even without the shadow root.
   So the panel is styled from the outside and the palette is handed in through
   the --md-mermaid-* custom properties, pinned to dark values. Material derives
   those from --md-code-fg-color et al. at :root, where the substitution has
   already happened against the active scheme — they have to be re-derived here
   rather than re-pointed at their sources. */
.md-typeset .mermaid {
  background-color: hsl(var(--diagram-surface));
  border: 1px solid hsl(var(--diagram-border));
  border-radius: var(--whetstone-radius);
  box-sizing: border-box;
  contain: inline-size;
  max-width: 100%;
  overflow-x: auto;
  padding: 1rem;
  width: 100%;

  /* Material's themeCSS reads these two directly for subgraph clusters. */
  --md-default-fg-color--lighter: hsl(var(--diagram-muted-foreground) / 0.72);
  --md-default-fg-color--lightest: hsl(var(--diagram-muted-foreground) / 0.42);

  --md-mermaid-edge-color: hsl(var(--diagram-foreground));
  --md-mermaid-node-bg-color: hsl(var(--diagram-accent-muted));
  --md-mermaid-node-fg-color: hsl(var(--diagram-accent));
  --md-mermaid-label-bg-color: hsl(var(--diagram-background));
  --md-mermaid-label-fg-color: hsl(var(--diagram-foreground));

  --md-mermaid-sequence-actor-bg-color: var(--md-mermaid-label-bg-color);
  --md-mermaid-sequence-actor-fg-color: var(--md-mermaid-label-fg-color);
  --md-mermaid-sequence-actor-border-color: var(--md-mermaid-node-fg-color);
  --md-mermaid-sequence-actor-line-color: hsl(var(--diagram-muted-foreground) / 0.72);
  --md-mermaid-sequence-actorman-bg-color: var(--md-mermaid-label-bg-color);
  --md-mermaid-sequence-actorman-line-color: var(--md-mermaid-node-fg-color);
  --md-mermaid-sequence-box-bg-color: var(--md-mermaid-node-bg-color);
  --md-mermaid-sequence-box-fg-color: var(--md-mermaid-edge-color);
  --md-mermaid-sequence-label-bg-color: var(--md-mermaid-node-bg-color);
  --md-mermaid-sequence-label-fg-color: var(--md-mermaid-node-fg-color);
  --md-mermaid-sequence-loop-bg-color: var(--md-mermaid-node-bg-color);
  --md-mermaid-sequence-loop-fg-color: var(--md-mermaid-edge-color);
  --md-mermaid-sequence-loop-border-color: var(--md-mermaid-node-fg-color);
  --md-mermaid-sequence-message-fg-color: var(--md-mermaid-edge-color);
  --md-mermaid-sequence-message-line-color: var(--md-mermaid-edge-color);
  --md-mermaid-sequence-note-bg-color: var(--md-mermaid-label-bg-color);
  --md-mermaid-sequence-note-fg-color: var(--md-mermaid-edge-color);
  --md-mermaid-sequence-note-border-color: var(--md-mermaid-label-fg-color);
  --md-mermaid-sequence-number-bg-color: var(--md-mermaid-node-fg-color);
  --md-mermaid-sequence-number-fg-color: var(--md-mermaid-sequence-actor-bg-color);
}

.md-footer {
  border-top: 1px solid hsl(var(--border));
}

@media screen and (max-width: 44.984375em) {
  body {
    overflow-x: hidden;
  }

  .md-content__inner {
    box-sizing: border-box;
    margin-inline: 0;
    max-width: 100%;
    padding-inline: 1rem;
    width: auto;
  }

  .md-typeset {
    max-width: 100%;
  }

  .md-typeset h1 {
    font-size: clamp(1.75rem, 7.5vw, 2rem);
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .md-typeset h2 {
    font-size: clamp(1.25rem, 6vw, 1.5rem);
  }

  .md-typeset table:not([class]) {
    min-width: 36rem;
  }
}
