:root {
  color-scheme: light dark;
  --bg: #f3efe6;
  --bg-accent: #e7dfcf;
  --surface: #fffaf2;
  --ink: #1c1915;
  --muted: #5c564c;
  --line: #d9d0bf;
  --accent: #0f6e5c;
  --accent-soft: #d7f3eb;
  --warn-bg: #f8ecd0;
  --warn-ink: #6a4b00;
  --error-bg: #fde4e2;
  --error-ink: #8c1d18;
  --ok-bg: #dcefdc;
  --ok-ink: #1e5b32;
  --placeholder: #8a8376;
  --ad-bg: transparent;
  --shadow: 0 12px 40px rgba(40, 32, 18, 0.08);
  --radius: 16px;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Code", "SFMono-Regular", Menlo, monospace;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141b;
    --bg-accent: #18222d;
    --surface: #151d27;
    --ink: #e8eef4;
    --muted: #9aa8b7;
    --line: #2a3848;
    --accent: #3ee0b1;
    --accent-soft: #14352d;
    --warn-bg: #3a2e12;
    --warn-ink: #f0c35a;
    --error-bg: #3a1716;
    --error-ink: #ff9b94;
    --ok-bg: #163226;
    --ok-ink: #8ee0b0;
    --placeholder: #6d7c8b;
    --shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
  }
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3efe6;
  --bg-accent: #e7dfcf;
  --surface: #fffaf2;
  --ink: #1c1915;
  --muted: #5c564c;
  --line: #d9d0bf;
  --accent: #0f6e5c;
  --accent-soft: #d7f3eb;
  --warn-bg: #f8ecd0;
  --warn-ink: #6a4b00;
  --error-bg: #fde4e2;
  --error-ink: #8c1d18;
  --ok-bg: #dcefdc;
  --ok-ink: #1e5b32;
  --placeholder: #8a8376;
  --shadow: 0 12px 40px rgba(40, 32, 18, 0.08);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e141b;
  --bg-accent: #18222d;
  --surface: #151d27;
  --ink: #e8eef4;
  --muted: #9aa8b7;
  --line: #2a3848;
  --accent: #3ee0b1;
  --accent-soft: #14352d;
  --warn-bg: #3a2e12;
  --warn-ink: #f0c35a;
  --error-bg: #3a1716;
  --error-ink: #ff9b94;
  --ok-bg: #163226;
  --ok-ink: #8ee0b0;
  --placeholder: #6d7c8b;
  --shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--sans);
  background:
    radial-gradient(1200px 500px at 10% -10%, var(--bg-accent), transparent 60%),
    var(--bg);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--accent);
  color: var(--bg);
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  z-index: 10;
}

.skip-link:focus {
  top: 1rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header,
main,
.site-footer {
  width: min(1120px, calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  padding: 2.2rem 0 1.2rem;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.brand {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  font-weight: 500;
}

.theme-toggle,
.copy-btn,
.preset {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
}

.theme-toggle {
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
}

.theme-toggle:hover,
.copy-btn:hover,
.preset:hover {
  border-color: var(--accent);
}

.theme-toggle:focus-visible,
.copy-btn:focus-visible,
.preset:focus-visible,
.expr:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin: 0 0 0.6rem;
}

.lede {
  margin: 0;
  max-width: 46rem;
  color: var(--muted);
  font-size: 1.05rem;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.4rem 0 1.1rem;
}

.preset {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.preset[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.panels {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.8rem;
  align-items: stretch;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel.active {
  border-color: var(--accent);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.8rem;
  margin-bottom: 0.6rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.panel-sub {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.copy-btn {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.expr {
  width: 100%;
  resize: vertical;
  min-height: 7.5rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.98rem;
  line-height: 1.45;
}

.expr::placeholder {
  color: var(--placeholder);
}

.panel-status {
  min-height: 1.4rem;
  margin: 0.55rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.panel-status.error { color: var(--error-ink); }
.panel-status.warn { color: var(--warn-ink); }
.panel-status.ok { color: var(--ok-ink); }

.swap-col {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 1.6rem;
}

.explain,
.quirks {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-top: 1rem;
}

.explain h2,
.quirks h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.explain-body {
  margin: 0;
  font-size: 1.12rem;
}

.messages {
  list-style: none;
  margin: 0.8rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.messages:empty { margin: 0; }

.messages li {
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.messages .error { background: var(--error-bg); color: var(--error-ink); }
.messages .warn { background: var(--warn-bg); color: var(--warn-ink); }
.messages .note { background: var(--accent-soft); color: var(--ink); }

.quirks dl {
  margin: 0;
}

.quirks dt {
  font-weight: 600;
  margin-top: 0.85rem;
}

.quirks dt:first-child { margin-top: 0.2rem; }

.quirks dd {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bg-accent);
  padding: 0.05em 0.35em;
  border-radius: 5px;
}

.ad-placeholder {
  margin: 1.2rem 0;
  border: 1px dashed var(--line);
  border-radius: 12px;
  min-height: 72px;
  display: grid;
  place-items: center;
  color: var(--placeholder);
  font-size: 0.85rem;
}

.site-footer {
  padding: 0.4rem 0 2.4rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer a {
  color: var(--accent);
}

@media (max-width: 820px) {
  .panels {
    grid-template-columns: 1fr;
  }
  .swap-col {
    transform: rotate(90deg);
    height: 1.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
