:root {
  --primary: #5645d4;
  --primary-pressed: #4534b3;
  --link-blue: #0075de;
  --link-blue-pressed: #005bab;
  --canvas: #ffffff;
  --surface: #f6f5f4;
  --surface-soft: #fafaf9;
  --hairline: #e5e3df;
  --hairline-soft: #ede9e4;
  --hairline-strong: #c8c4be;
  --ink: #1a1a1a;
  --charcoal: #37352f;
  --slate: #5d5b54;
  --steel: #787671;
  --stone: #a4a097;
  --muted: #bbb8b1;
  --on-dark: #ffffff;
  --semantic-success: #1aae39;
  --semantic-error: #e03131;
  --card-tint-sky: #dcecfa;
  --card-tint-mint: #d9f3e1;
  --rounded-sm: 6px;
  --rounded-md: 8px;
  --rounded-lg: 12px;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;
  --shadow-card: rgba(15, 15, 15, 0.08) 0px 4px 12px 0px;
  --shadow-mockup: rgba(15, 15, 15, 0.2) 0px 24px 48px -8px;
  --bar-height: 48px;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--charcoal);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link-blue); text-decoration: none; }
a:hover { color: var(--link-blue-pressed); text-decoration: underline; }

/* ── App shell ── */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}

.bar {
  flex: 0 0 var(--bar-height);
  height: var(--bar-height);
  min-height: var(--bar-height);
  max-height: var(--bar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--hairline);
  background: var(--canvas);
}

.bar-start,
.bar-end {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.bar-end { flex-shrink: 0; }

.bar-title,
.bar-home {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.bar-home {
  color: inherit;
  text-decoration: none;
}

.bar-home:hover {
  color: inherit;
  text-decoration: none;
}

.bar-title strong {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.bar-title span {
  font-size: 13px;
  color: var(--steel);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  height: 32px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  color: var(--steel);
  text-decoration: none;
  padding: 0 10px;
  border-radius: var(--rounded-sm);
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-link:hover {
  color: var(--charcoal);
  background: var(--surface);
  text-decoration: none;
}

.nav-link.is-active {
  color: var(--charcoal);
  background: var(--surface);
}

.bar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--steel);
  white-space: nowrap;
}

.bar-meta span + span::before {
  content: "·";
  margin-right: 10px;
  color: var(--muted);
}

.main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(252px, 288px) 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--hairline);
  background: var(--canvas);
  padding: 10px 10px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 12px;
}

.sidebar .block {
  gap: 6px;
}

.sidebar .block h2 {
  font-size: 10px;
  letter-spacing: 0.06em;
}

.sidebar .input {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 6px;
}

.sidebar select.input {
  background-position: right 6px center;
  background-size: 10px;
  padding-right: 22px;
}

.sidebar .mono {
  font-size: 10px;
  line-height: 1.35;
}

.sidebar .source-note {
  font-size: 11px;
  line-height: 1.35;
}

.sidebar .source-stats {
  gap: 6px;
}

.sidebar .source-stats div {
  padding: 5px 7px;
  border-radius: 6px;
}

.sidebar .source-stats dt {
  font-size: 9px;
  margin-bottom: 1px;
}

.sidebar .source-stats dd {
  font-size: 11px;
}

.sidebar .grid2 {
  gap: 6px;
}

.sidebar .field {
  gap: 3px;
}

.sidebar .field span {
  font-size: 10px;
}

.sidebar .field output {
  font-size: 10px;
}

.sidebar .field input[type="range"] {
  height: 18px;
}

.sidebar .btn {
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 6px;
}

.sidebar .btn.primary {
  margin-top: 2px;
}

.sidebar .btn.block {
  margin-top: 2px;
}

.sidebar .block-share .field {
  margin-bottom: 2px;
}

.sidebar .share-row {
  gap: 5px;
}

.block {
  display: grid;
  gap: 10px;
}

.block h2 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--steel);
}

.sidebar .share-row .btn {
  min-width: 44px;
  padding-inline: 6px;
}

.input {
  width: 100%;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--rounded-md);
  font: inherit;
  font-size: 14px;
  background: var(--canvas);
  color: var(--charcoal);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder { color: var(--muted); }

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(86, 69, 212, 0.15);
}

select.input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23787671' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.mono {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
}

.source-note {
  color: var(--stone);
  font-size: 13px;
  line-height: 1.45;
}

.source-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.source-stats div {
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--rounded-md);
  background: var(--surface-soft);
}

.source-stats dt {
  color: var(--stone);
  font-size: 11px;
  font-weight: 500;
  margin-bottom: 2px;
}

.source-stats dd {
  color: var(--charcoal);
  font-size: 14px;
  font-weight: 500;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field span {
  font-size: 12px;
  font-weight: 500;
  color: var(--steel);
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.field output {
  font-size: 12px;
  color: var(--steel);
  font-variant-numeric: tabular-nums;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  padding: 8px 14px;
  border-radius: var(--rounded-md);
  border: 1px solid var(--hairline-strong);
  background: var(--canvas);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  color: var(--charcoal);
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover {
  background: var(--surface);
  text-decoration: none;
  color: var(--charcoal);
}

.btn.primary {
  width: 100%;
  background: var(--primary);
  color: var(--on-dark);
  border-color: var(--primary);
  margin-top: 4px;
}

.btn.primary:hover {
  background: var(--primary-pressed);
  border-color: var(--primary-pressed);
  color: var(--on-dark);
}

.btn.block {
  display: flex;
  width: 100%;
  margin-top: 4px;
}

.btn:disabled { opacity: 0.45; pointer-events: none; }

.block-share .field { margin-bottom: 4px; }

.share-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.share-row .input { flex: 1; min-width: 0; }

.share-row .btn {
  flex-shrink: 0;
  align-self: stretch;
}

.stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.preview-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 32px;
  min-height: 0;
}

.preview-frame {
  width: calc(var(--preview-display-w, 1) * 1px);
  height: calc(var(--preview-display-h, 1) * 1px);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview {
  display: block;
  width: 100%;
  height: 100%;
}

.empty {
  color: var(--steel);
  font-size: 15px;
  text-align: center;
  padding: 24px;
  max-width: 280px;
  line-height: 1.5;
}

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.72);
}

.spin {
  width: 28px;
  height: 28px;
  border: 2px solid var(--hairline);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.cache-pill.hit { color: var(--semantic-success); font-weight: 600; }

.hidden { display: none !important; }

/* ── Docs page ── */

.docs-page {
  min-height: 100%;
  overflow: auto;
}

.docs-page .bar {
  position: sticky;
  top: 0;
  z-index: 10;
  flex: 0 0 var(--bar-height);
}

.docs-layout {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

.docs-layout h1 {
  font-size: 40px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.5px;
  color: var(--ink);
  margin-bottom: 12px;
}

.docs-lead {
  font-size: 16px;
  line-height: 1.55;
  color: var(--slate);
  margin-bottom: 40px;
}

.docs-layout h2 {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
  margin: 40px 0 12px;
  padding-top: 8px;
}

.docs-layout h3 {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--charcoal);
  margin: 28px 0 10px;
}

.docs-layout p {
  font-size: 16px;
  line-height: 1.55;
  color: var(--charcoal);
  margin-bottom: 12px;
}

.docs-layout ul,
.docs-layout ol {
  font-size: 16px;
  line-height: 1.55;
  color: var(--charcoal);
  margin: 0 0 16px 1.25em;
}

.docs-layout li { margin-bottom: 6px; }

.docs-layout li::marker { color: var(--stone); }

.docs-layout code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--charcoal);
}

.docs-layout pre {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--rounded-md);
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0 20px;
}

.docs-layout pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--charcoal);
}

.docs-table-wrap {
  overflow-x: auto;
  margin: 16px 0 24px;
  border: 1px solid var(--hairline);
  border-radius: var(--rounded-md);
}

.docs-layout table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.5;
}

.docs-layout th,
.docs-layout td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--hairline-soft);
  vertical-align: top;
}

.docs-layout tr:last-child td,
.docs-layout tr:last-child th { border-bottom: none; }

.docs-layout th {
  background: var(--surface-soft);
  font-weight: 600;
  color: var(--charcoal);
  font-size: 13px;
}

.docs-layout td { color: var(--charcoal); }

.docs-callout {
  background: var(--card-tint-sky);
  border-radius: var(--rounded-md);
  padding: 14px 16px;
  margin: 20px 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--charcoal);
}

.docs-callout strong { font-weight: 600; }

.docs-footer {
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--hairline);
  font-size: 13px;
  color: var(--steel);
}

@media (max-width: 720px) {
  .main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar {
    max-height: 44vh;
    border-right: none;
    border-bottom: 1px solid var(--hairline);
  }
  .bar-title span { display: none; }
  .docs-layout { padding: 32px 16px 64px; }
  .docs-layout h1 { font-size: 32px; }
}
