pe-dialog,
pe-tooltip,
pe-popover,
pe-tabs,
pe-accordion,
pe-collapsible {
  display: contents;
}

:root {
  color-scheme: light;

  /* shadcn-style tokens (zinc) */
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --radius: 0.5rem;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --max-width: 72rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font: inherit;
}

:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.container {
  width: min(var(--max-width), calc(100% - 2rem));
  margin-inline: auto;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--background) / 0.8);
  backdrop-filter: blur(8px);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 0.625rem;
  font-weight: 700;
}

.page-main {
  padding-block: 2rem 3rem;
}

/* Hero */
.hero {
  margin-bottom: 2rem;
}

.hero__eyebrow {
  margin: 0 0 0.5rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
  font-weight: 500;
}

.hero h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.875rem, 4vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.hero__lead {
  margin: 0;
  color: hsl(var(--muted-foreground));
  font-size: 1rem;
  line-height: 1.625;
}

/* Layout */
.demo-grid {
  display: grid;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 960px) {
  .demo-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Card / Panel */
.panel {
  padding: 1.5rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  box-shadow: var(--shadow-sm);
}

.panel--wide {
  margin-bottom: 1.5rem;
}

.panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel__header > div:first-child {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.panel__header h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.panel__header p {
  margin: 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.25rem;
  padding: 0 0.5rem;
  border: 1px solid transparent;
  border-radius: 9999px;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

/* Button */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding: 0 1rem;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.button:hover {
  background: hsl(240 5.9% 20%);
}

.button--ghost {
  border-color: hsl(var(--border));
  background: hsl(var(--background));
  color: hsl(var(--foreground));
}

.button--ghost:hover {
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.button--small {
  height: 2rem;
  padding: 0 0.75rem;
  font-size: 0.8125rem;
}

/* Form */
.field {
  display: grid;
  gap: 0.375rem;
}

.field span {
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  height: 2.25rem;
  padding: 0.25rem 0.75rem;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field textarea {
  height: auto;
  min-height: 4rem;
  padding-block: 0.5rem;
}

.field input::placeholder,
.field textarea::placeholder {
  color: hsl(var(--muted-foreground));
}

.field input:focus-visible,
.field textarea:focus-visible,
.field select:focus-visible {
  border-color: hsl(var(--ring));
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--muted) / 0.35);
}

.inline-form--wrap .field {
  min-width: 10rem;
}

.field--grow {
  flex: 1 1 12rem;
}

.stack-form {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--muted) / 0.35);
}

/* Alert / Checkpoint */
.checkpoint {
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--muted) / 0.5);
  font-size: 0.875rem;
}

.checkpoint strong {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.checkpoint ul {
  margin: 0;
  padding-left: 1.125rem;
  color: hsl(var(--muted-foreground));
}

.checkpoint li + li {
  margin-top: 0.25rem;
}

.checkpoint code {
  padding: 0.125rem 0.375rem;
  border-radius: calc(var(--radius) - 4px);
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
}

/* Tabs */
.playground-tabs {
  display: block;
}

.tabs-list {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  margin-bottom: 1rem;
  padding: 0.25rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--muted));
}

.tabs-list button {
  position: relative;
  z-index: 1;
  height: 2rem;
  padding: 0 0.75rem;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 4px);
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.tabs-list button:hover {
  color: hsl(var(--foreground));
}

.tabs-list button[aria-selected="true"] {
  border-color: hsl(var(--border));
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  box-shadow: var(--shadow-sm);
}

.tabs-indicator {
  display: none;
}

.tabs-panel {
  padding: 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--background));
}

/* Accordion */
.accordion-item {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--background));
}

.accordion-item + .accordion-item {
  margin-top: 0.5rem;
}

.accordion-item[open] {
  box-shadow: var(--shadow-sm);
}

.accordion-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.875rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  list-style: none;
  transition: background-color 0.15s ease;
}

.accordion-summary:hover {
  background: hsl(var(--muted) / 0.5);
}

.accordion-summary::-webkit-details-marker {
  display: none;
}

.accordion-body {
  padding: 0 1rem 1rem;
  border-top: 1px solid hsl(var(--border));
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

.accordion-body p {
  margin: 0.75rem 0 0;
}

/* Collapsible */
.stack {
  display: grid;
  gap: 0.5rem;
}

.collapsible-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: start;
  padding: 0.875rem 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--background));
}

.collapsible-card pe-collapsible {
  display: block;
  min-width: 0;
}

.collapsible-trigger {
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: hsl(var(--foreground));
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: left;
}

.collapsible-trigger:hover {
  color: hsl(var(--muted-foreground));
}

.collapsible-panel p {
  margin: 0.75rem 0 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

/* Dialog cards */
.card-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
}

.dialog-card,
.chip-card {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--background));
}

.chip-card {
  width: fit-content;
}

.chip-button {
  height: 2rem;
  padding: 0 0.875rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background-color 0.15s ease;
}

.chip-button:hover {
  background: hsl(var(--accent));
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.item-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
}

.item-row p {
  margin: 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

/* Dialog */
dialog::backdrop {
  background: rgb(0 0 0 / 0.8);
}

dialog {
  margin: auto;
  padding: 0;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) + 2px);
  background: hsl(var(--background));
  box-shadow: var(--shadow-md);
  color: hsl(var(--foreground));
}

.dialog-body {
  min-width: min(28rem, calc(100vw - 2rem));
  padding: 1.5rem;
}

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

.dialog-header h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.dialog-body > [data-dialog-description] {
  margin: 0 0 1rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
  line-height: 1.5;
}

.dialog-close {
  height: 2rem;
  padding: 0 0.75rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 500;
}

.dialog-close:hover {
  background: hsl(var(--accent));
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Tooltip & Popover */
[data-tooltip-content] {
  max-width: 16rem;
  padding: 0.375rem 0.75rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 0.75rem;
  line-height: 1.4;
  box-shadow: var(--shadow-md);
}

[data-popover-content] {
  min-width: 12rem;
  padding: 0.75rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--popover));
  color: hsl(var(--popover-foreground));
  box-shadow: var(--shadow-md);
}

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.popover-header h3 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

[data-popover-content] p {
  margin: 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.8125rem;
  line-height: 1.5;
}

/* Event log */
.event-stream {
  display: grid;
  gap: 0.375rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.event-stream li {
  display: grid;
  grid-template-columns: 11rem minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--muted) / 0.35);
  font-size: 0.8125rem;
}

.event-stream__source {
  color: hsl(var(--foreground));
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
}

.event-stream__message {
  color: hsl(var(--muted-foreground));
}

.event-stream__time {
  color: hsl(var(--muted-foreground));
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

@media (max-width: 720px) {
  .inline-form {
    display: grid;
  }

  .event-stream li {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 1rem;
  }
}
