: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 <rich-input> before the Custom Element is defined in the browser.
 * ==========================================================================
 */
rich-input:not(:defined) {
  display: block;
  font-family: var(--font-sans);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.625rem 0.875rem;
  color: var(--text-muted);
}

/*
 * ==========================================================================
 * CSS CUSTOM HIGHLIGHT API STYLES
 * Highlighting keyword search values inside <rich-input>
 * ==========================================================================
 */
::highlight(label) {
  background-color: oklch(0.92 0.08 240);
  color: oklch(0.28 0.14 240);
  text-decoration: 2px underline solid oklch(0.5 0.15 240 / 0.5);
}

::highlight(year) {
  background-color: oklch(0.93 0.1 85);
  color: oklch(0.35 0.14 85);
}

::highlight(artist) {
  background-color: oklch(0.92 0.1 320);
  color: oklch(0.32 0.14 320);
}

::highlight(style) {
  background-color: oklch(0.93 0.08 190);
  color: oklch(0.3 0.12 190);
}

::highlight(genre) {
  background-color: oklch(0.93 0.1 145);
  color: oklch(0.3 0.14 145);
}

::highlight(rich-input-keyword) {
  color: #64748b;
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.15);
}

::highlight(rich-input-invalid) {
  text-decoration: underline wavy #ef4444;
  -webkit-text-decoration: underline wavy #ef4444;
  text-decoration-line: underline;
  -webkit-text-decoration-line: underline;
  text-decoration-style: wavy;
  -webkit-text-decoration-style: wavy;
  text-decoration-color: #ef4444;
  -webkit-text-decoration-color: #ef4444;
  text-decoration-skip-ink: none;
}

/*
 * ==========================================================================
 * ::PART() STYLING THEMES
 * Demonstrating full stylability through Shadow Parts
 * ==========================================================================
 */

/* Theme 1: Pill / Modern Minimal */
rich-input.theme-pill::part(control) {
  border-radius: 9999px;
  padding: 0 1.25rem;
  background: #ffffff;
  border: 2px solid #3b82f6;
  box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.1);
}

rich-input.theme-pill::part(input) {
  font-weight: 500;
}

rich-input.theme-pill::part(popover) {
  border-radius: 16px;
  border: 2px solid #bfdbfe;
  box-shadow: 0 20px 25px -5px rgba(59, 130, 246, 0.15);
}

/* Theme 2: Terminal / Cyber */
rich-input.theme-terminal::part(control) {
  background: #0f172a;
  border: 1px solid #22c55e;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.2);
}

rich-input.theme-terminal::part(icon) {
  color: #22c55e;
}

rich-input.theme-terminal::part(input) {
  font-family: var(--font-mono);
  color: #4ade80;
}

rich-input.theme-terminal::part(input)::placeholder {
  color: #166534;
}

rich-input.theme-terminal::part(popover) {
  background: #0f172a;
  border: 1px solid #22c55e;
  color: #4ade80;
  border-radius: 4px;
}

rich-input.theme-terminal::part(suggestions-header) {
  background: #1e293b;
  color: #22c55e;
  border-color: #334155;
}

rich-input.theme-terminal::part(suggestion-item-active) {
  background: #1e293b;
}

/* Suggestion Image Styling via ::part */
rich-input::part(suggestion-image) {
  width: 2.5em;
  height: 2.5em;
  border-radius: 50%;
  object-fit: cover;
  outline: 1px solid #ccc;
}

/* 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: 840px;
  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;
}

/* API Banner */
.api-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-top: 0.5rem;
  border: 1px solid transparent;
}

.api-banner.supported {
  background-color: oklch(0.96 0.05 145);
  border-color: oklch(0.85 0.1 145);
  color: oklch(0.28 0.12 145);
}

.api-banner.fallback,
.api-banner.warning {
  background-color: oklch(0.96 0.05 60);
  border-color: oklch(0.85 0.1 60);
  color: oklch(0.3 0.1 60);
}

.api-banner.unsupported,
.api-banner.danger {
  background-color: oklch(0.96 0.04 25);
  border-color: oklch(0.85 0.12 25);
  color: oklch(0.35 0.15 25);
}

.api-banner-badge {
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.08);
}

/* 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;
}

.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-accent {
  background-color: rgba(14, 165, 233, 0.1);
  color: var(--accent-color);
  border-color: rgba(14, 165, 233, 0.2);
}

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

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;
}

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

.feature-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem;
}

.feature-item h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

/* 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 {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-left: 4px solid 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);
}

.callout p {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Data Table */
.data-table-wrapper {
  overflow-x: auto;
  margin: 1rem 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  text-align: left;
}

.data-table th {
  background-color: var(--bg-surface-elevated);
  padding: 0.625rem 0.75rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

.data-table tr:hover td {
  background-color: rgba(0, 0, 0, 0.02);
}

/* Preset Buttons */
.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  transition: all 0.15s ease;
}

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

.btn-primary {
  background: var(--primary-color);
  color: #ffffff;
  border-color: var(--primary-color);
}

.btn-primary:hover {
  background: var(--primary-hover);
  color: #ffffff;
}

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

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

.inspector-box {
  background: #0f172a;
  color: #f8fafc;
  border-radius: 8px;
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  max-height: 380px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.token-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 0.375rem;
  margin-bottom: 0.375rem;
}

.token-pill.pill-keyword {
  background: #dbeafe;
  color: #1e40af;
}

.token-pill.pill-text {
  background: #f1f5f9;
  color: #475569;
}

.caret-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
}
