:root {
  color-scheme: light;
  --background: 48 30% 96%;
  --foreground: 30 8% 10%;
  --card: 45 25% 93%;
  --secondary: 45 22% 90%;
  --muted-foreground: 40 6% 39%;
  --accent: 217 84% 46%;
  --accent-foreground: 0 0% 98%;
  --destructive: 4 70% 47%;
  --warn: 32 90% 38%;
  --border: 45 18% 85%;
  /* match tints (alternating) + group tints */
  --m1: 217 84% 46% / 0.18;
  --m2: 160 60% 34% / 0.2;
  --g1: 32 90% 50% / 0.35;
  --g2: 290 60% 50% / 0.3;
  --g3: 4 70% 50% / 0.3;
  --g4: 190 80% 40% / 0.32;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-display: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --background: 30 8% 8%;
    --foreground: 45 25% 90%;
    --card: 30 7% 11%;
    --secondary: 30 6% 15%;
    --muted-foreground: 40 8% 62%;
    --accent: 217 90% 64%;
    --accent-foreground: 30 8% 8%;
    --destructive: 4 80% 62%;
    --warn: 38 90% 60%;
    --border: 30 6% 20%;
    --m1: 217 90% 64% / 0.26;
    --m2: 160 60% 50% / 0.24;
    --g1: 38 90% 55% / 0.38;
    --g2: 290 60% 65% / 0.34;
    --g3: 4 80% 62% / 0.34;
    --g4: 190 80% 55% / 0.34;
  }
}

*, *::before, *::after { box-sizing: border-box; border-radius: 0 !important; }
html, body { margin: 0; }
body {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: var(--font-mono);
  font-variant-ligatures: none;
  font-size: 13.5px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: hsl(var(--accent)); }
button, input, select, textarea { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 1px solid hsl(var(--accent)); outline-offset: 1px; }

.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 20px; border-bottom: 1px solid hsl(var(--border));
}
.brand { font-family: var(--font-display); font-weight: 700; font-size: 20px; color: hsl(var(--foreground)); text-decoration: none; letter-spacing: -0.01em; }
.glyph { color: hsl(var(--accent)); font-weight: 400; }
.tag { color: hsl(var(--muted-foreground)); font-size: 12.5px; }
.top-actions { margin-left: auto; display: flex; gap: 8px; }

button, select {
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  padding: 5px 10px; cursor: pointer; font-size: 12.5px;
  transition: border-color .15s, background-color .15s;
}
button:hover, select:hover { border-color: hsl(var(--accent)); }
select { appearance: none; padding-right: 22px; background-image: none; }
.lib { position: relative; }
.lib::after { content: "▾"; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); pointer-events: none; color: hsl(var(--muted-foreground)); font-size: 11px; }

.grid {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
}
.col { padding: 20px; min-width: 0; }
.left { border-right: 1px solid hsl(var(--border)); }
@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .left { border-right: 0; border-bottom: 1px solid hsl(var(--border)); }
  .tag { display: none; }
}

.section-heading {
  font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: -0.01em;
  margin: 22px 0 8px;
}
.section-heading::before { content: "■ "; color: hsl(var(--accent)); font-weight: 400; }

.pattern-row {
  display: flex; align-items: center; gap: 4px;
  border: 1px solid hsl(var(--border)); background: hsl(var(--card));
  padding: 0 10px; font-size: 16px;
}
.pattern-row:focus-within { border-color: hsl(var(--accent)); }
.pattern-row.bad { border-color: hsl(var(--destructive)); }
.slash { color: hsl(var(--muted-foreground)); }
.pfield { position: relative; flex: 1; min-width: 0; display: flex; }
#pattern, .phl { font-family: var(--font-mono); font-size: 16px; letter-spacing: 0; padding: 12px 2px; white-space: pre; font-variant-ligatures: none; }
#pattern { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; color: transparent; caret-color: hsl(var(--accent)); position: relative; z-index: 1; }
#pattern::placeholder { color: hsl(var(--muted-foreground)); opacity: .6; }
#pattern::selection { background: hsl(var(--accent) / 0.3); color: transparent; }
.phl { position: absolute; inset: 0; overflow: hidden; pointer-events: none; color: hsl(var(--foreground)); }
.s-esc { color: hsl(160 60% 36%); }
.s-cls { color: hsl(290 50% 50%); }
.s-grp { color: hsl(var(--warn)); }
.s-q { color: hsl(var(--accent)); }
.s-anc, .s-ref { color: hsl(var(--destructive)); }
.s-alt { color: hsl(var(--accent)); }
@media (prefers-color-scheme: dark) { .s-esc { color: hsl(160 55% 58%); } .s-cls { color: hsl(290 60% 72%); } }
.flags-out { color: hsl(var(--accent)); min-width: 1ch; }

.flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.flag { display: inline-flex; gap: 6px; align-items: baseline; }
.flag[aria-pressed="true"] { border-color: hsl(var(--accent)); background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.flag b { font-weight: 600; }
.flag span { font-size: 11px; opacity: .75; }

.status { margin: 10px 0 0; min-height: 1.5em; font-size: 12.5px; color: hsl(var(--muted-foreground)); }
.status .err { color: hsl(var(--destructive)); }
.status .warn { color: hsl(var(--warn)); }
.status .ok { color: hsl(var(--foreground)); }

.editor { position: relative; border: 1px solid hsl(var(--border)); background: hsl(var(--card)); height: 260px; }
.editor:focus-within { border-color: hsl(var(--accent)); }
.editor .backdrop, .editor textarea {
  position: absolute; inset: 0; margin: 0; padding: 12px;
  font-family: var(--font-mono); font-size: 14px; line-height: 1.6; font-variant-ligatures: none;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
  overflow: auto; tab-size: 4;
}
.editor .backdrop { color: transparent; pointer-events: none; }
.editor textarea { background: transparent; border: 0; resize: none; outline: none; caret-color: hsl(var(--accent)); }
.backdrop mark { color: transparent; background: hsl(var(--m1)); }
.backdrop mark.alt { background: hsl(var(--m2)); }
.backdrop mark.empty { box-shadow: inset 2px 0 0 hsl(var(--accent)); background: transparent; }
.backdrop mark i { font-style: normal; }
.backdrop mark i.g1 { background: hsl(var(--g1)); }
.backdrop mark i.g2 { background: hsl(var(--g2)); }
.backdrop mark i.g3 { background: hsl(var(--g3)); }
.backdrop mark i.g4 { background: hsl(var(--g4)); }

.replace-head { display: flex; align-items: center; justify-content: space-between; }
.switch { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; color: hsl(var(--muted-foreground)); font-size: 12.5px; }
.switch input { accent-color: hsl(var(--accent)); }
.replace-box input { width: 100%; border: 1px solid hsl(var(--border)); background: hsl(var(--card)); padding: 10px 12px; outline: none; }
.replace-box input:focus { border-color: hsl(var(--accent)); }
.replaced, .code {
  margin: 8px 0 0; padding: 12px; border: 1px solid hsl(var(--border)); background: hsl(var(--secondary));
  white-space: pre-wrap; word-break: break-word; font-size: 13.5px; max-height: 260px; overflow: auto;
}
.caption { color: hsl(var(--muted-foreground)); font-size: 12.5px; margin: 16px 0 0; }

.tabs { display: flex; gap: 0; border-bottom: 1px solid hsl(var(--border)); }
.tabs button { border: 0; background: transparent; padding: 8px 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; color: hsl(var(--muted-foreground)); }
.tabs button[aria-selected="true"] { color: hsl(var(--foreground)); border-bottom-color: hsl(var(--accent)); }
.count { color: hsl(var(--accent)); }
.panel { padding-top: 14px; }

.matches { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 190px); overflow: auto; }
.matches li { border: 1px solid hsl(var(--border)); background: hsl(var(--card)); padding: 8px 10px; cursor: pointer; }
.matches li:hover { border-color: hsl(var(--accent)); }
.matches .mh { display: flex; gap: 10px; align-items: baseline; }
.matches .mi { color: hsl(var(--muted-foreground)); font-size: 11px; white-space: nowrap; }
.matches .mt { word-break: break-all; }
.matches .mt.hl { background: hsl(var(--m1)); }
.matches li:nth-child(even) .mt.hl { background: hsl(var(--m2)); }
.matches table { margin-top: 6px; border-collapse: collapse; width: 100%; font-size: 12.5px; }
.matches td { padding: 2px 8px 2px 0; vertical-align: top; }
.matches td:first-child { color: hsl(var(--muted-foreground)); white-space: nowrap; width: 1%; }
.matches td.v { word-break: break-all; }
.matches .sw { display: inline-block; width: 8px; height: 8px; margin-right: 6px; }
.sw.g1 { background: hsl(var(--g1)); } .sw.g2 { background: hsl(var(--g2)); } .sw.g3 { background: hsl(var(--g3)); } .sw.g4 { background: hsl(var(--g4)); }
.undef { color: hsl(var(--muted-foreground)); }
.empty-note { color: hsl(var(--muted-foreground)); }

.tree { font-size: 13px; }
.tree ul { list-style: none; margin: 0; padding-left: 16px; border-left: 1px solid hsl(var(--border)); }
.tree > ul { padding-left: 0; border-left: 0; }
.tree li { padding: 3px 0; }
.tree .row { display: flex; gap: 10px; align-items: baseline; padding: 1px 4px; cursor: default; }
.tree .row:hover { background: hsl(var(--secondary)); }
.tree code { color: hsl(var(--accent)); white-space: pre; font-family: var(--font-mono); }
.tree .d { color: hsl(var(--muted-foreground)); }
.tree .t-group > .row code { color: hsl(var(--warn)); }
.tree .t-anchor > .row code, .tree .t-backref > .row code { color: hsl(var(--destructive)); }
.tree .risk > .row .d { color: hsl(var(--warn)); }
.panel-actions { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.cheats h3 { font-family: var(--font-display); font-size: 14px; font-weight: 700; margin: 14px 0 6px; }
.cheats h3:first-child { margin-top: 0; }
.cheat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.cheat-grid button { display: flex; gap: 10px; align-items: baseline; text-align: left; padding: 6px 8px; }
.cheat-grid code { color: hsl(var(--accent)); font-family: var(--font-mono); white-space: nowrap; }
.cheat-grid span { color: hsl(var(--muted-foreground)); font-size: 12px; }

.export-tabs { display: flex; gap: 6px; }
.export-tabs button[aria-pressed="true"] { border-color: hsl(var(--accent)); color: hsl(var(--accent)); }
.export-tabs .copy { margin-left: auto; }

.foot { display: flex; gap: 18px; flex-wrap: wrap; padding: 12px 20px; border-top: 1px solid hsl(var(--border)); color: hsl(var(--muted-foreground)); font-size: 11px; }
.foot .sub { margin-left: auto; }
kbd { font-family: var(--font-mono); border: 1px solid hsl(var(--border)); padding: 0 4px; font-size: 11px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 10px); opacity: 0;
  background: hsl(var(--foreground)); color: hsl(var(--background)); padding: 8px 14px; font-size: 12.5px;
  transition: opacity .15s, transform .15s; pointer-events: none;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.phl-on { background: hsl(var(--accent) / 0.22); color: inherit; }
.test-sum { color: hsl(var(--muted-foreground)); font-size: 12.5px; }
.test-sum.all { color: hsl(160 60% 40%); }
.test-sum.some { color: hsl(var(--destructive)); }
.tests textarea { width: 100%; border: 1px solid hsl(var(--border)); background: hsl(var(--card)); padding: 10px 12px; outline: none; resize: vertical; font-size: 13.5px; line-height: 1.6; }
.tests textarea:focus { border-color: hsl(var(--accent)); }
.test-results { list-style: none; margin: 6px 0 0; padding: 0; font-size: 12.5px; }
.test-results li { display: flex; gap: 10px; padding: 2px 0; align-items: baseline; }
.test-results .tk { width: 1ch; }
.test-results .pass .tk { color: hsl(160 60% 40%); }
.test-results .fail .tk, .test-results .fail .ts { color: hsl(var(--destructive)); }
.test-results .tw { color: hsl(var(--muted-foreground)); width: 8ch; flex: none; }
.test-results .ts { word-break: break-all; }
.backdrop mark.hot { outline: 1px solid hsl(var(--accent)); }
.tabs { overflow-x: auto; } .tabs button { white-space: nowrap; flex: none; }
@media (max-width: 480px) { .tabs button { padding: 8px 10px; } }
