:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --text: #18181b;
  --text-muted: #52525b;
  --text-subtle: #6b6b73;
  --border: #d4d4d8;
  --border-strong: #8a8a93;
  --brand: #facc15;
  --brand-strong: #a16207;
  --brand-soft: #fef9c3;
  --accent: #1d4ed8;
  --accent-soft: #dbeafe;
  --error: #b91c1c;
  --error-soft: #fef2f2;
  --warning: #92400e;
  --warning-soft: #fffbeb;
  --success: #15803d;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-xs: 0 1px 2px rgba(24, 24, 27, 0.05);
  --shadow-sm: 0 1px 3px rgba(24, 24, 27, 0.08), 0 1px 2px rgba(24, 24, 27, 0.05);
  --shadow-focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--brand-strong);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --surface: #18181b;
    --text: #fafafa;
    --text-muted: #d4d4d8;
    --text-subtle: #a1a1aa;
    --border: #3f3f46;
    --border-strong: #71717a;
    --brand: #facc15;
    --brand-strong: #fde047;
    --brand-soft: #422006;
    --accent: #93c5fd;
    --accent-soft: #1e3a8a;
    --error: #fca5a5;
    --error-soft: #450a0a;
    --warning: #fcd34d;
    --warning-soft: #451a03;
    --success: #86efac;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--brand-strong);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "cv11", "ss01", "ss03";
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(180%) blur(8px);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
}

.brand { display: inline-flex; align-items: center; }
.brand img { display: block; height: 32px; }

main.container { padding-top: 48px; padding-bottom: 96px; }

h1 {
  font-size: clamp(28px, 4vw, 36px);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.005em;
  margin: 0 0 16px;
}

.lede {
  color: var(--text-muted);
  margin: 0 0 40px;
  max-width: 640px;
  font-size: 16px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

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

.layout-main {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

.layout-aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 80px;
}

@media (max-width: 960px) {
  .layout-aside { position: static; }
}

.aside-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 4px;
}

table.reference {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

table.reference th {
  text-align: left;
  padding: 12px 16px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

table.reference td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  vertical-align: middle;
}

table.reference tr:last-child td { border-bottom: 0; }

table.reference td:first-child {
  width: 1%;
  white-space: nowrap;
  padding-right: 12px;
}

table.reference code {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-weight: 500;
}

.tester-input,
.tester-results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.tester-results h2 { margin-bottom: 12px; }

.tester-results h3 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 24px 0 12px;
}

.input-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.input-header h2 { margin: 0; }

.input-header a {
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.input-header a:hover {
  border-color: var(--text);
  background: var(--bg);
}

.input-header a:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.field { margin-bottom: 14px; }
.field:last-of-type { margin-bottom: 0; }

#regex-input,
#test-string-input {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

#regex-input::placeholder,
#test-string-input::placeholder {
  color: var(--text-subtle);
}

#regex-input:focus,
#test-string-input:focus {
  outline: none;
  border-color: var(--text);
  box-shadow: var(--shadow-focus);
}

#test-string-input {
  resize: vertical;
  min-height: 112px;
  line-height: 1.5;
}

.field.error #regex-input {
  border-color: var(--error);
  background: var(--error-soft);
}

.field.error #regex-input:focus {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--error);
}

.field.warning #regex-input {
  border-color: var(--warning);
  background: var(--warning-soft);
}

.field.success #test-string-input {
  border-color: var(--success);
}

.field-message {
  margin: 8px 2px 0;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 1.2em;
}

.field.error .field-message { color: var(--error); }
.field.warning .field-message { color: var(--warning); }

.match-message {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  min-height: 1.2em;
}

#pre-matched {
  margin: 12px 0 0;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.match-highlight {
  background: var(--brand);
  color: #18181b;
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 600;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.tester-groups dl { margin: 0; }

.tester-groups dt {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 16px;
}

.tester-groups dt:first-child { margin-top: 0; }

.tester-groups dd {
  margin: 6px 0 0;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  word-break: break-word;
}

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

::selection {
  background: var(--brand);
  color: #18181b;
}
