/* regex-railroad — own lightweight brand. Light + dark via prefers-color-scheme.
   No external fonts, no @import, no url() network references. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dbe2ea;
  --text: #0f172a;
  --muted: #5a6b82;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-weak: #eaf1ff;
  --danger-bg: #fdecec;
  --danger-bd: #f2b8b5;
  --danger-tx: #a01919;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 6px 18px rgba(15, 23, 42, .06);

  /* diagram palette handed to renderSvg */
  --dg-bg: #ffffff;
  --dg-stroke: #334155;
  --dg-text: #1e293b;
  --dg-accent: #2563eb;
  --dg-node: #f1f5f9;
  --dg-group: #eef4ff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1c;
    --surface: #131b2e;
    --surface-2: #0f1626;
    --border: #2a3650;
    --text: #e7edf6;
    --muted: #94a3b8;
    --accent: #6ea8fe;
    --accent-ink: #06152e;
    --accent-weak: #1a2740;
    --danger-bg: #3a1618;
    --danger-bd: #6d2529;
    --danger-tx: #ffb4ac;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);

    --dg-bg: #0f1626;
    --dg-stroke: #b9c6db;
    --dg-text: #e7edf6;
    --dg-accent: #6ea8fe;
    --dg-node: #1c2942;
    --dg-group: #16233c;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding: 0 clamp(12px, 4vw, 40px);
}

.skip {
  position: absolute;
  left: -999px;
}
.skip:focus {
  left: 8px; top: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 6px 10px;
  border-radius: 6px;
  z-index: 20;
}

/* ---- header (kept compact so the input stays above the fold) ---- */
.site-head {
  max-width: 1160px;
  margin: 0 auto;
  padding: 14px 0 6px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  color: var(--accent);
  display: inline-flex;
}
.site-head h1 {
  font-size: clamp(1.15rem, 2.6vw, 1.5rem);
  margin: 0;
  letter-spacing: -.01em;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
.trust {
  margin: 0;
  color: var(--muted);
  font-size: .82rem;
}

main {
  max-width: 1160px;
  margin: 0 auto;
}

/* ---- controls ---- */
.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
  margin-top: 6px;
  display: grid;
  gap: 12px;
}
.field-label {
  display: block;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}
.pattern-box {
  display: flex;
  align-items: stretch;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 10px;
}
.pattern-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
.slash {
  color: var(--muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 1.25rem;
  align-self: center;
  user-select: none;
}
.pattern-input, .flags-input {
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 1rem;
  padding: 10px 2px;
  outline: none;
  min-width: 0;
}
.pattern-input {
  flex: 1 1 auto;
}
.flags-input {
  flex: 0 0 4.5em;
  width: 4.5em;
  border-left: 1px solid var(--border);
  padding-left: 10px;
  color: var(--accent);
}
@media (max-width: 460px) {
  .pattern-box { padding: 4px 8px; gap: 4px; }
  .flags-input { flex-basis: 3.8em; width: 3.8em; padding-left: 6px; }
  .slash { font-size: 1.1rem; }
}
.pattern-input::placeholder, .flags-input::placeholder {
  color: var(--muted);
  opacity: .7;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.btn {
  font: inherit;
  font-size: .88rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .04s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-accent {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn-accent:hover { filter: brightness(1.05); }
.toast {
  font-size: .82rem;
  color: var(--accent);
  min-height: 1em;
  transition: opacity .2s;
}

.error {
  max-width: 1160px;
  margin: 12px auto 0;
  background: var(--danger-bg);
  border: 1px solid var(--danger-bd);
  color: var(--danger-tx);
  border-radius: 10px;
  padding: 10px 14px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .88rem;
}

/* ---- results ---- */
.results {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin: 16px 0 8px;
}
@media (min-width: 900px) {
  .results {
    grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr);
    align-items: start;
  }
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
  min-width: 0;
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.panel-head h2 {
  font-size: .95rem;
  margin: 0;
  letter-spacing: .01em;
}
.hint {
  font-size: .74rem;
  color: var(--muted);
}
.diagram {
  background: var(--dg-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  overflow: auto;
  min-height: 120px;
}
.diagram svg {
  display: block;
  max-width: 100%;
  height: auto;
}
.diagram.empty, .explanation.empty {
  color: var(--muted);
  font-style: italic;
}
.explanation {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
}
.explanation .flag-note {
  color: var(--muted);
}

/* ---- match tester ---- */
.match-panel {
  margin: 16px 0 8px;
}
.match-subject {
  width: 100%;
  resize: vertical;
  min-height: 78px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .95rem;
  line-height: 1.5;
  padding: 10px 12px;
  outline: none;
}
.match-subject:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
.match-subject::placeholder { color: var(--muted); opacity: .7; }

.match-results { margin-top: 12px; }
.match-msg {
  margin: 0;
  color: var(--muted);
  font-size: .9rem;
}
.match-msg.empty { font-style: italic; }
.match-msg.error {
  background: var(--danger-bg);
  border: 1px solid var(--danger-bd);
  color: var(--danger-tx);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .85rem;
}
.match-msg.truncated {
  margin-top: 10px;
  color: var(--muted);
  font-size: .82rem;
}
.match-summary {
  margin: 0 0 10px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
}

.match-hl {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .92rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-height: 220px;
  overflow: auto;
}
.match-hl .m-hit {
  background: var(--accent-weak);
  color: var(--text);
  border-radius: 4px;
  padding: 1px 2px;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.match-hl .zero-mark {
  display: inline-block;
  width: 0;
  border-left: 2px solid var(--accent);
  height: 1.05em;
  margin: 0 1px;
  vertical-align: text-bottom;
}

.match-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-size: .86rem;
}
.match-table th, .match-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.match-table thead th {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.match-table td:first-child, .match-table td:nth-child(2) {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.match-table code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  word-break: break-word;
}
.match-table code.is-empty, .match-table .is-none {
  color: var(--muted);
  font-style: italic;
}
.grp-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  margin: 0 6px 6px 0;
}
.grp-lab {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .78rem;
  color: var(--accent);
  font-weight: 600;
}
.grp-chip.grp-null .grp-lab { color: var(--muted); }
.grp-chip.grp-null .grp-val { color: var(--muted); font-style: italic; }

/* ---- search & replace pane ---- */
.sub-panel {
  margin: 16px 0 8px;
}
.sub-intro {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.6;
  max-width: 74ch;
}
.sub-intro code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  font-size: .82em;
  color: var(--accent);
  white-space: nowrap;
}
.sub-replacement {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .95rem;
  line-height: 1.5;
  padding: 10px 12px;
  outline: none;
}
.sub-replacement:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
.sub-replacement::placeholder { color: var(--muted); opacity: .7; }

.sub-output-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 6px;
}
.sub-output-head .field-label { margin-bottom: 0; }
.sub-count {
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.sub-copy { margin-left: auto; padding: 6px 12px; font-size: .82rem; }

.sub-output {
  margin: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .92rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-height: 260px;
  overflow: auto;
}
.sub-output.is-empty { color: var(--muted); font-style: italic; }
.sub-output.empty { color: var(--muted); font-style: italic; }
.sub-output.error {
  background: var(--danger-bg);
  border-color: var(--danger-bd);
  color: var(--danger-tx);
  font-size: .85rem;
}

.site-foot {
  max-width: 1160px;
  margin: 8px auto 28px;
  color: var(--muted);
  font-size: .8rem;
}
.site-foot a {
  color: var(--accent);
  text-decoration-color: var(--border);
  text-underline-offset: 2px;
}
.site-foot a:hover { text-decoration-color: var(--accent); }
.site-foot code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
}
