:root {
  color-scheme: dark;
  --bg: #10141b;
  --bg-raise: #171d27;
  --bg-inset: #0d1117;
  --line: #313a4b;
  --line-strong: #455066;
  --text: #e7edf6;
  --muted: #b7c2d2;
  --faint: #8e9aab;
  --amber: #e6a15c;
  --amber-ink: #1b1208;
  --teal: #3dbeb0;
  --danger: #ffb4b4;
  --danger-bg: #3a2228;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --mono: ui-monospace, "Liberation Mono", "DejaVu Sans Mono", Consolas, monospace;
  --sans: "Segoe UI", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
}

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

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

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

.topbar {
  height: 48px;
  min-height: 48px;
  max-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(16, 20, 27, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: #24190f;
  color: var(--amber);
  display: inline-grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 12px;
  border: 1px solid #6a4a28;
}

.lang-menu { position: relative; margin-left: auto; }

.lang-menu summary {
  list-style: none;
  height: 28px;
  min-width: 52px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--bg-raise);
  font-size: 12px;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.lang-menu summary::-webkit-details-marker { display: none; }

.lang-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 168px;
  padding: 6px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.lang-panel a {
  color: var(--text);
  text-decoration: none;
  padding: 7px 8px;
  border-radius: 7px;
  font-size: 14px;
}

.lang-panel a:hover,
.lang-panel a[aria-current="page"] { background: #2a241c; color: #f0c48a; }

.first-screen {
  display: grid;
  align-content: start;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-columns: minmax(0, 1fr);
  height: calc(100vh - 48px);
  height: calc(100dvh - 48px);
  padding: 8px 16px 0;
  gap: 8px;
}

h1 {
  margin: 0;
  font-size: 18px;
  line-height: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  min-width: 0;
}

.regex-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 4px 8px 4px 10px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 10px;
  position: relative;
}

.pattern-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.delim {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 16px;
}

.pattern,
#replacement,
.sample {
  font-family: var(--mono);
}

.pattern {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 22px;
  padding: 4px 2px;
}

.pattern:focus { outline: none; }

.flags { display: flex; gap: 4px; }

.flag,
.preset,
.tabs button,
#copy-snippet {
  font: inherit;
  cursor: pointer;
}

.flag {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
  padding: 0;
}

.flag[aria-pressed="true"] {
  background: var(--amber);
  color: var(--amber-ink);
  border-color: var(--amber);
  font-weight: 700;
}

.match-badge {
  margin: 0 0 0 4px;
  font-variant-numeric: tabular-nums;
  background: #2c241b;
  color: #f0c48a;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.match-badge.is-bad { background: var(--danger-bg); color: var(--danger); }

.error-banner {
  position: absolute;
  left: 8px;
  right: 8px;
  top: calc(100% + 4px);
  margin: 0;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #8a4450;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  z-index: 6;
}

.error-banner[hidden] { display: none; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(0, 0.88fr);
  gap: 10px;
  min-height: 0;
  min-width: 0;
}

.test-pane,
.explain-pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px 6px;
}

.pane-head h2,
.explain-block h2,
.replace-box h2 {
  margin: 0;
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.legend {
  display: flex;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-size: 11px;
}

.legend li { display: inline-flex; align-items: center; gap: 4px; }

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.swatch.hl-match { background: #e6a15c; }
.swatch.hl-g1 { background: #3dbeb0; }
.swatch.hl-g2 { background: #7ea2ff; }
.swatch.hl-g3 { background: #f07896; }

.editor {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--bg-inset);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.editor:focus-within { box-shadow: inset 0 0 0 1px var(--amber); }

.backdrop,
.sample {
  position: absolute;
  inset: 0;
  margin: 0;
  border: 0;
  padding: 10px 12px 16px;
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  tab-size: 2;
  scrollbar-gutter: stable;
}

.backdrop {
  overflow: hidden;
  color: var(--text);
  pointer-events: none;
}

.sample {
  width: 100%;
  height: 100%;
  resize: none;
  color: transparent;
  caret-color: #f4f7fb;
  background: transparent;
  overflow: auto;
}

.sample::selection { background: rgba(230, 161, 92, 0.35); }

.hl-match { background: rgba(230, 161, 92, 0.38); border-radius: 2px; }
.hl-g1 { background: rgba(61, 190, 176, 0.72); color: #04211e; border-radius: 2px; }
.hl-g2 { background: rgba(126, 162, 255, 0.75); color: #0c1224; border-radius: 2px; }
.hl-g3 { background: rgba(240, 120, 150, 0.75); color: #240810; border-radius: 2px; }
.hl-g4 { background: rgba(176, 214, 112, 0.78); color: #12180a; border-radius: 2px; }
.hl-gn { background: rgba(196, 160, 240, 0.75); color: #160d22; border-radius: 2px; }

.match-list {
  max-height: 38%;
  overflow: auto;
  padding: 8px 10px 10px;
}

.match-item { padding: 6px 0; border-bottom: 1px solid #2a3342; }
.match-item header { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; font-size: 13px; }
.match-item .pos,
.no-groups,
.empty-note { color: var(--faint); font-size: 12px; }
.match-item ol { margin: 4px 0 0; padding-left: 18px; }
.match-item code,
#replace-output { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.g-label { color: #f0c48a; font-family: var(--mono); font-size: 12px; }

.explain-block {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.explain-block h2,
.replace-box h2 { padding: 8px 10px 0; }

.token-list {
  list-style: none;
  margin: 0;
  padding: 6px 10px 8px;
  overflow: auto;
  min-height: 0;
}

.token-list li {
  display: grid;
  grid-template-columns: minmax(72px, 34%) minmax(0, 1fr);
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid #2a3342;
  font-size: 13px;
  align-items: start;
}

.token-raw {
  font-family: var(--mono);
  color: #f0c48a;
  overflow-wrap: anywhere;
}

.token-error { color: var(--danger); display: block; }
.token-empty { color: var(--faint); display: block; }

.replace-box {
  border-top: 1px solid var(--line);
  padding: 0 10px 10px;
  display: grid;
  gap: 6px;
}

.replace-label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

#replacement {
  width: 100%;
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
}

#replace-output {
  margin: 0;
  max-height: 72px;
  overflow: auto;
  white-space: pre-wrap;
  background: var(--bg-inset);
  border-radius: 8px;
  padding: 6px 8px;
  color: #d7efe9;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.preset-row h2 {
  margin: 0 4px 0 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.preset {
  border: 1px solid var(--line-strong);
  background: var(--bg-raise);
  color: var(--text);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  line-height: 18px;
}

.preset:hover { border-color: var(--amber); color: #f0c48a; }

.site-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 28px;
  min-height: 28px;
  max-height: 28px;
  white-space: nowrap;
  font-size: 12px;
  line-height: 28px;
  color: var(--muted);
  overflow: hidden;
}

.site-footer a { color: #f0b56a; text-underline-offset: 2px; }

.sponsored-label {
  color: #f0c48a;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 10px;
}

.foot-links { display: inline-flex; gap: 10px; align-items: center; }

.below {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 16px 72px;
}

.below h2 { font-size: 22px; line-height: 1.25; margin: 0 0 8px; letter-spacing: -0.02em; }
.lead { margin: 0 0 14px; color: var(--muted); }
.below section + section { margin-top: 36px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; }

.tabs button,
#copy-snippet {
  border: 1px solid var(--line-strong);
  background: var(--bg-raise);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
}

.tabs button[aria-selected="true"] {
  background: var(--amber);
  color: var(--amber-ink);
  border-color: var(--amber);
  font-weight: 700;
}

.snippet-wrap { position: relative; margin-top: 10px; }

.snippet-wrap pre {
  margin: 0;
  padding: 36px 14px 14px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
}

#copy-snippet { position: absolute; top: 8px; right: 8px; }

.cheat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.cheat-card {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px 6px;
  min-width: 0;
}

.cheat-card h3 { margin: 0 0 6px; font-size: 15px; }

.cheat-card table { width: 100%; border-collapse: collapse; }

.cheat-card th,
.cheat-card td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid #2a3342;
  vertical-align: top;
  font-size: 13px;
}

.cheat-card th { color: var(--faint); font-weight: 600; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; }
.cheat-card code { font-family: var(--mono); color: #f0c48a; white-space: nowrap; }

.faq details { border-bottom: 1px solid #2a3342; padding: 8px 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details p { margin: 8px 0 4px; color: var(--muted); }

.not-found { max-width: 720px; margin: 0 auto; padding: 48px 16px 80px; }
.not-found h1 { font-size: 32px; line-height: 1.2; white-space: normal; margin-bottom: 8px; }
.lang-list { padding-left: 18px; }
.lang-list li { margin: 6px 0; }

@media (min-width: 960px) {
  h1 { white-space: nowrap; }
}

@media (max-width: 959px) {
  .first-screen {
    height: auto;
    min-height: calc(100dvh - 48px);
    grid-template-rows: auto auto auto auto auto;
  }
  h1 { white-space: normal; }
  .workspace { grid-template-columns: 1fr; }
  .editor { min-height: 220px; }
  .match-list { max-height: none; }
  .site-footer {
    height: auto;
    max-height: none;
    min-height: 28px;
    white-space: normal;
    flex-wrap: wrap;
    padding-bottom: 8px;
  }
  .cheat-grid { grid-template-columns: 1fr; }
  .regex-bar { flex-wrap: wrap; }
  .match-badge { margin-left: auto; }
}

@media print {
  .topbar { position: static; }
  .first-screen { height: auto; }
  .flag, .preset, #copy-snippet { display: none; }
}
