:root {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --text: #1f2528;
  --muted: #5c686f;
  --line: #d9dedc;
  --accent: #21695d;
  --accent-dark: #174a42;
  --code-bg: #f1f4f2;
  --error: #8f2f2f;
  --error-line: #b45353;
  color-scheme: light;
}

html[data-theme="light"] {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --text: #1f2528;
  --muted: #5c686f;
  --line: #d9dedc;
  --accent: #21695d;
  --accent-dark: #174a42;
  --code-bg: #f1f4f2;
  --error: #8f2f2f;
  --error-line: #b45353;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #111715;
  --panel: #18211e;
  --text: #e8efeb;
  --muted: #aab8b2;
  --line: #31413b;
  --accent: #6ed2bc;
  --accent-dark: #9ae3d2;
  --code-bg: #0d1412;
  --error: #ffb4b4;
  --error-line: #d67676;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
}

a {
  color: var(--accent);
}

a:hover {
  color: var(--accent-dark);
}

.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 24px;
}

.brand {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.header-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: flex-end;
}

.top-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.95rem;
}

.top-nav a {
  text-decoration: none;
}

.theme-control {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.theme-control select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  letter-spacing: 0;
  padding: 6px 8px;
  text-transform: none;
}

.site-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 34px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 30px 24px 56px;
}

.side-nav {
  border-right: 1px solid var(--line);
  padding-right: 24px;
}

.side-nav-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.side-nav a {
  display: block;
  padding: 6px 0;
  text-decoration: none;
}

.content {
  min-width: 0;
  max-width: 860px;
}

.content h1 {
  margin-top: 0;
  font-size: 2.6rem;
  line-height: 1.1;
}

.content h2 {
  margin-top: 2rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
}

.content pre,
.content code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.content pre {
  overflow-x: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--code-bg);
}

.content code {
  color: var(--text);
}

.copperlace-demo {
  display: grid;
  gap: 14px;
  min-width: 0;
  margin: 22px 0 30px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.demo-field,
.demo-rule {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.demo-field span,
.demo-rule span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.demo-field textarea,
.demo-rule input,
.demo-rule select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 0.95rem/1.5 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.demo-field textarea {
  min-height: 180px;
  padding: 12px;
  resize: vertical;
}

.demo-rule input,
.demo-rule select {
  padding: 9px 10px;
}

.demo-controls {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto;
  gap: 12px;
  align-items: end;
  min-width: 0;
}

.demo-controls button {
  min-height: 43px;
  padding: 0 18px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--panel);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.demo-controls button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.demo-output {
  display: block;
  min-width: 0;
  min-height: 52px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--code-bg);
  font-weight: 700;
  white-space: pre-wrap;
}

.demo-output.is-error {
  border-color: var(--error-line);
  color: var(--error);
}

.examples-demo-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0;
}

.examples-demo-source summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.examples-demo-source {
  min-width: 0;
}

.examples-demo-source pre {
  width: 100%;
  max-height: 360px;
  margin: 8px 0 0;
}

.example-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.example-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.example-card strong {
  display: block;
  margin-bottom: 6px;
}

.site-footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 24px 40px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 780px) {
  .site-header-inner,
  .site-shell {
    padding-left: 18px;
    padding-right: 18px;
  }

  .site-shell {
    display: block;
  }

  .site-header-inner {
    align-items: flex-start;
  }

  .header-controls {
    justify-content: flex-start;
  }

  .side-nav {
    margin-bottom: 24px;
    padding: 0 0 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content h1 {
    font-size: 2rem;
  }

  .demo-controls {
    grid-template-columns: 1fr;
  }
}
