:root {
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --bg-color: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --text-color: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --accent-color: #0ea5e9;
  --code-bg: #f1f5f9;
  --code-color: #0f172a;
  --card-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --card-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 2rem;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  padding: 0;
  margin: 0;
}

/*
 * ==========================================================================
 * PRE-UPGRADE STYLING (FALLBACK)
 * Applied to <mermaid-element> before the Custom Element is defined in the browser.
 * ==========================================================================
 */
mermaid-element:not(:defined) {
  display: block;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
  background-color: var(--code-bg);
  color: var(--code-color);
  padding: 1.25rem;
  border-radius: 8px;
  border: 1px dashed var(--border-color);
  overflow-x: auto;
}

.simulated-fouc {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
  background-color: var(--code-bg);
  color: var(--code-color);
  padding: 1.25rem;
  border-radius: 8px;
  border: 1px dashed var(--border-color);
  overflow-x: auto;
}

/* Container */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 2rem 1.5rem 5rem;
}

/* Header */
header {
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.title-group h1 {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.title-tag {
  font-family: var(--font-mono);
  color: var(--primary-color);
}

.description {
  font-size: 1.125rem;
  color: var(--text-muted);
  max-width: 800px;
  line-height: 1.6;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.github-btn,
.npm-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-color);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  text-decoration: none;
  transition: all 0.2s ease;
}

.github-btn:hover,
.npm-btn:hover {
  background: var(--bg-surface-elevated);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.github-btn svg,
.npm-btn svg {
  flex-shrink: 0;
}

/* Page Layout & Sidenav (Scrollspy) */
.page-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 3rem;
  align-items: start;
}

@media (max-width: 800px) {
  .page-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 2rem;
  }
}

.sidebar {
  position: sticky;
  top: 1.5rem;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  padding-right: 0.5rem;
}

@media (max-width: 800px) {
  .sidebar {
    position: static;
    max-height: none;
    overflow-y: visible;
    padding-right: 0;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
  }
}

.sidenav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidenav-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 0.75rem 0.25rem;
}

/* Scroll target group scrollspy per https://una.im/scroll-target-group */
.sidenav-list {
  scroll-target-group: auto;
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidenav-list li {
  list-style: none;
}

.sidenav-list a {
  display: block;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidenav-list a:hover {
  color: var(--text-color);
  background: var(--bg-surface-elevated);
}

.sidenav-list a:target-current,
.sidenav-list a.is-active {
  color: var(--primary-color);
  font-weight: 600;
  border-left-color: var(--primary-color);
  background: rgba(37, 99, 235, 0.08);
}

.sidenav-divider {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0.75rem 0.75rem 0.25rem;
  border-top: 1px solid var(--border-color);
  margin-top: 0.5rem;
}

.main-content {
  min-width: 0;
}

/* Badges */
.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.badge-primary {
  background-color: rgba(37, 99, 235, 0.1);
  color: var(--primary-color);
  border-color: rgba(37, 99, 235, 0.2);
}

.badge-error {
  background-color: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

/* Sections & Cards */
section {
  margin-bottom: 3rem;
}

section h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

section p.section-desc {
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--card-shadow-lg);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.card-meta {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-muted);
  background: var(--bg-surface-elevated);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

/* Code Snippets */
pre, code {
  font-family: var(--font-mono);
}

code {
  background-color: var(--code-bg);
  color: var(--code-color);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-size: 0.875em;
}

pre {
  background-color: var(--code-bg);
  color: var(--code-color);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.5;
  border: 1px solid var(--border-color);
  margin-top: 0.75rem;
}

/* Callout Box */
.callout {
  border-left: 4px solid var(--primary-color);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-left-width: 4px;
  border-left-color: var(--primary-color);
  border-radius: 6px;
  padding: 1.25rem;
  margin: 1.5rem 0;
}

.callout h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--primary-color);
}

/* Grid */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

/* Playground */
.playground-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 800px) {
  .playground-layout {
    grid-template-columns: 1fr;
  }
}

.playground-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 600;
}

.form-control {
  font-family: var(--font-mono);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

textarea.form-control {
  min-height: 220px;
  resize: vertical;
  line-height: 1.4;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8125rem;
  color: var(--text-muted);
  padding-top: 0.5rem;
}

.playground-preview {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1.5rem;
  min-height: 350px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
}

.preview-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: auto;
}

/* Features Grid */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.feature-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.feature-card h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-color);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.feature-card p {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* API Table */
.api-table-wrapper {
  overflow-x: auto;
  margin-top: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.api-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.api-table th,
.api-table td {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.api-table tr:last-child td {
  border-bottom: none;
}

.api-table th {
  background: var(--bg-surface-elevated);
  color: var(--text-color);
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.api-table tr:hover td {
  background: var(--bg-surface-elevated);
}

.api-table code {
  font-size: 0.8125rem;
}

/* Example 7: Shadow Parts Demo */
mermaid-element.styled-part-example::part(container) {
  padding: 1.5rem;
  background: var(--bg-surface-elevated);
  border: 2px dashed var(--primary-color);
  border-radius: 10px;
}

/* Footer */
footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
}

footer a {
  color: var(--primary-color);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}
