@source "../../../kumo/dist/**/*.{js,jsx,ts,tsx}";
@source "../../../kumo/src/**/*.{ts,tsx}";
@import "@cloudflare/kumo/styles";
@import "tailwindcss";
@plugin "@tailwindcss/typography";

@custom-variant dark (&:where([data-mode="dark"], [data-mode="dark"] *));

@theme {
  --font-sans:
    "Inter", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji",
    "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent CLS from font loading */
html {
  scroll-behavior: smooth;
  letter-spacing: -0.01em;
  line-height: 1.5;
  font-feature-settings: "cv02", "cv03", "cv04", "calt";
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Reset tracking for monospace/code elements and kumo component areas */
pre,
code,
kbd,
.font-mono {
  letter-spacing: normal;
}

/* ==========================================================================
   Kumo Prose — Tailwind Typography overrides using kumo semantic tokens
   Used on .kumo-prose wrapper in DocLayout and MdxDocLayout
   ========================================================================== */

.kumo-prose {
  /* Body text */
  --tw-prose-body: var(--text-color-kumo-default);
  /* Headings */
  --tw-prose-headings: var(--text-color-kumo-default);
  /* Lead paragraphs */
  --tw-prose-lead: var(--text-color-kumo-default);
  /* Link color */
  --tw-prose-links: var(--text-color-kumo-link);
  /* Bold text */
  --tw-prose-bold: var(--text-color-kumo-strong);
  /* List counters (ordered lists) */
  --tw-prose-counters: var(--text-color-kumo-subtle);
  /* Bullet markers */
  --tw-prose-bullets: var(--text-color-kumo-default);
  /* Horizontal rules */
  --tw-prose-hr: var(--color-kumo-hairline);
  /* Blockquote text */
  --tw-prose-quotes: var(--text-color-kumo-default);
  /* Blockquote left border */
  --tw-prose-quote-borders: var(--color-kumo-hairline);
  /* Figure captions */
  --tw-prose-captions: var(--text-color-kumo-subtle);
  /* Keyboard input */
  --tw-prose-kbd: var(--text-color-kumo-default);
  /* Keyboard shadow */
  --tw-prose-kbd-shadows: transparent;
  /* Inline code */
  --tw-prose-code: var(--text-color-kumo-default);
  /* Code inside pre blocks */
  --tw-prose-pre-code: var(--text-color-kumo-default);
  /* Pre block background */
  --tw-prose-pre-bg: var(--color-kumo-canvas);
  /* Table header borders */
  --tw-prose-th-borders: var(--color-kumo-hairline);
  /* Table cell borders */
  --tw-prose-td-borders: var(--color-kumo-hairline);

  /* Dark mode — same tokens, they auto-adapt via light-dark() */
  --tw-prose-invert-body: var(--text-color-kumo-default);
  --tw-prose-invert-headings: var(--text-color-kumo-default);
  --tw-prose-invert-lead: var(--text-color-kumo-default);
  --tw-prose-invert-links: var(--text-color-kumo-link);
  --tw-prose-invert-bold: var(--text-color-kumo-strong);
  --tw-prose-invert-counters: var(--text-color-kumo-subtle);
  --tw-prose-invert-bullets: var(--text-color-kumo-default);
  --tw-prose-invert-hr: var(--color-kumo-hairline);
  --tw-prose-invert-quotes: var(--text-color-kumo-default);
  --tw-prose-invert-quote-borders: var(--color-kumo-hairline);
  --tw-prose-invert-captions: var(--text-color-kumo-subtle);
  --tw-prose-invert-kbd: var(--text-color-kumo-default);
  --tw-prose-invert-kbd-shadows: transparent;
  --tw-prose-invert-code: var(--text-color-kumo-default);
  --tw-prose-invert-pre-code: var(--text-color-kumo-default);
  --tw-prose-invert-pre-bg: var(--color-kumo-canvas);
  --tw-prose-invert-th-borders: var(--color-kumo-hairline);
  --tw-prose-invert-td-borders: var(--color-kumo-hairline);
}

/* Reset prose styles inside not-prose wrappers */
.kumo-prose .not-prose {
  letter-spacing: normal;
  line-height: normal;
}

/* Inline code styling — match existing site style */
.kumo-prose :where(code):not(:where(pre code)) {
  font-weight: 500;
  font-size: 0.875em;
  background-color: var(--color-kumo-base);
  border: 1px solid var(--color-kumo-hairline);
  border-radius: 0.25rem;
  padding: 0.125rem 0.375rem;
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  letter-spacing: normal;
}

/* Remove backtick decoration from inline code */
.kumo-prose :where(code):not(:where(pre code))::before,
.kumo-prose :where(code):not(:where(pre code))::after {
  content: none;
}

/* Links — underline on hover only (skip .not-prose where components control their own styles) */
.kumo-prose :where(a):not(:where(.not-prose, .not-prose *)) {
  text-decoration: none;
}

.kumo-prose :where(a):not(:where(.not-prose, .not-prose *)):hover {
  text-decoration: underline;
}

/* Heading anchor links */
.kumo-prose :where(h2, h3, h4):not(:where(.not-prose, .not-prose *)) a {
  color: inherit;
  font-weight: inherit;
  text-decoration: none;
}

/* Headings — shared spacing and tracking */
.kumo-prose :where(h2, h3, h4):not(:where(.not-prose, .not-prose *)) {
  @apply tracking-tight;
  scroll-margin-top: 6rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

/* Adjacent sibling spacing after headings */
.kumo-prose :where(h2, h3, h4):not(:where(.not-prose, .not-prose *)) + * {
  margin-top: 0;
}

/* Paragraphs */
.kumo-prose :where(p):not(:where(.not-prose, .not-prose *)) {
  @apply text-base leading-normal;
}

/* Adjacent sibling spacing between paragraphs */
.kumo-prose :where(p + p):not(:where(.not-prose, .not-prose *)) {
  margin-top: 0.75rem;
}

/* Unordered and ordered lists */
.kumo-prose :where(ul, ol):not(:where(.not-prose, .not-prose *)) {
  @apply text-base;
  margin: 0;
  margin-bottom: 1rem;
}

/* List items */
.kumo-prose :where(li):not(:where(.not-prose, .not-prose *)) {
  @apply text-base leading-normal;
}

/* Horizontal rule */
.kumo-prose :where(hr):not(:where(.not-prose, .not-prose *)) {
  margin: 1.5rem 0;
}

/* kbd styling */
.kumo-prose :where(kbd) {
  background-color: var(--color-kumo-control);
  border: 1px solid var(--color-kumo-hairline);
  border-radius: 0.25rem;
  padding: 0.125rem 0.375rem;
  font-size: 0.875em;
  box-shadow: none;
}

/* Pre / code blocks — better defaults for changelog <pre> without affecting CodeBlock (wrapped in .not-prose) or Shiki blocks (inline styles override) */
.kumo-prose :where(pre):not(:where(.not-prose, .not-prose *)) {
  @apply text-base;
  background-color: var(--tw-prose-pre-bg);
  border: 1px solid var(--color-kumo-hairline);
  border-radius: 0.5rem;
  letter-spacing: normal;
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
}

/* Table styling */
.kumo-prose :where(table) {
  width: 100%;
}

/* Table header border */
.kumo-prose :where(thead) {
  border-bottom-color: var(--color-kumo-hairline);
}

/* Table header cells */
.kumo-prose :where(thead th) {
  color: var(--text-color-kumo-strong);
  font-weight: 600;
}

/* Blockquote */
.kumo-prose :where(blockquote) {
  border-left-color: var(--color-kumo-brand);
  color: var(--text-color-kumo-default);
  font-style: normal;
}

/* Non-prose sections inside prose (ComponentExample, Callout, etc.)
   These opt out of prose styling via not-prose */
.kumo-prose :where(.not-prose) {
  /* Reset any inherited typography transforms */
  font-size: inherit;
  line-height: inherit;
}

/* ==========================================================================
   Shiki code blocks — markdown code blocks use .astro-code class
   Dual theme support: light (github-light) and dark (vesper)
   ========================================================================== */

/* Code block inside wrapper — extra right padding so text clears the copy button */
.code-block .astro-code {
  padding: 0.875rem 2rem 0.875rem 1rem;
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  overflow-x: auto;
}

/* Container styling for standalone code blocks (not yet wrapped by JS) */
pre.astro-code {
  overflow: hidden;
  border-radius: 0.5rem;
  border: 1px solid var(--color-kumo-hairline);
  margin: 1rem 0;
}

/* Light mode (default) */
.astro-code,
.astro-code span {
  color: var(--shiki-light) !important;
  background-color: var(--shiki-light-bg) !important;
}

/* Dark mode — toggle via data-mode attribute */
[data-mode="dark"] .astro-code,
[data-mode="dark"] .astro-code span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
}

/* ==========================================================================
   Code block copy button
   ========================================================================== */

.code-block-copy-btn {
  @apply absolute top-3 right-3 flex items-center justify-center size-6.5 rounded-md cursor-pointer border-none shadow-none select-none focus-visible:ring-1;
  background: var(--color-kumo-base);
  color: var(--text-color-kumo-subtle);
  --tw-ring-color: var(--color-kumo-hairline);

  &:hover {
    background: var(--color-kumo-tint);
  }
}

/* Icon wrapper — relative + overflow-hidden for slide animation */
.code-block-copy-btn__icons {
  @apply relative overflow-hidden size-4;
}

/* Both icons stacked absolutely */
.code-block-copy-btn__icon {
  @apply absolute inset-0 flex items-center justify-center;
  transition:
    transform 200ms,
    opacity 200ms;
}

@media (prefers-reduced-motion: reduce) {
  .code-block-copy-btn__icon {
    transition: none;
  }
}

/* Check icon: hidden below by default, slides up when copied */
.code-block-copy-btn__icon--check {
  opacity: 0;
  transform: translateY(100%);
}

/* Copy icon: visible by default, slides up when copied */
.code-block-copy-btn__icon--copy {
  opacity: 1;
  transform: translateY(0);
}

/* Copied state */
.code-block-copy-btn[data-copied] .code-block-copy-btn__icon--check {
  opacity: 1;
  transform: translateY(0);
}

.code-block-copy-btn[data-copied] .code-block-copy-btn__icon--copy {
  opacity: 0;
  transform: translateY(-100%);
}
