/* Regex Tester — self-contained, no external dependencies.
   Shares the site tool tokens; light default + dark via prefers-color-scheme + toggle. */
:root {
  color-scheme: light;
  --bg: #f4f5f8; --surface: #ffffff; --surface-2: #f6f7fb;
  --ink: #1a1c25; --muted: #475063; --faint: #5b6472; --line: #e4e6ef;
  --accent: #4f46e5; --accent-ink: #ffffff; --accent-soft: rgba(79,70,229,.10);
  --mark: #fde68a; --mark-ink: #422006; --good: #06744a; --bad: #b91c1c;
  --shadow: 0 1px 2px rgba(20,24,40,.05), 0 10px 28px -14px rgba(20,24,40,.18);
  --mono: 'SF Mono','JetBrains Mono',ui-monospace,Menlo,Consolas,monospace;
  --sans: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,system-ui,sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0b0d13; --surface: #141822; --surface-2: #1a1f2b;
    --ink: #e8eaf2; --muted: #b7bccd; --faint: #99a1b3; --line: #262a38;
    --accent: #8d89f6; --accent-ink: #0b0d13; --accent-soft: rgba(141,137,246,.14);
    --mark: #7c5e18; --mark-ink: #fde9b8; --good: #35c08a; --bad: #f0666b;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 14px 32px -16px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d13; --surface: #141822; --surface-2: #1a1f2b;
  --ink: #e8eaf2; --muted: #b7bccd; --faint: #99a1b3; --line: #262a38;
  --accent: #8d89f6; --accent-ink: #0b0d13; --accent-soft: rgba(141,137,246,.14);
  --mark: #7c5e18; --mark-ink: #fde9b8; --good: #35c08a; --bad: #f0666b;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 14px 32px -16px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
/* the `hidden` attribute must win over author display rules (e.g. .rt-replace-row{display:flex}) */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; overflow-x: hidden; max-width: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Header shell (shared look with the other tools) */
.pg-header {
  display: flex; align-items: center; gap: 16px; padding: 0 18px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.pg-brand { display: flex; align-items: center; gap: 10px; flex: 1 1 auto; }
.pg-logo { color: var(--accent); display: inline-flex; }
.pg-title { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.pg-header-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.pg-icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  cursor: pointer; text-decoration: none; transition: background .15s, color .15s;
}
.pg-icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-moon { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .icon-sun { display: none; } :root:not([data-theme]) .icon-moon { display: inline; } }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: inline; }
:root[data-theme="light"] .icon-sun { display: inline; }
:root[data-theme="light"] .icon-moon { display: none; }

/* Regex layout */
.rt-main { max-width: 1000px; margin: 0 auto; padding: 24px 20px 56px; }
.rt-pattern-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.rt-pattern-field {
  flex: 1 1 320px; display: flex; align-items: center; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px;
}
.rt-pattern-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rt-slash { color: var(--faint); font-family: var(--mono); font-size: 18px; }
.rt-pattern-input { flex: 1 1 auto; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font-family: var(--mono); font-size: 15px; padding: 8px 6px; outline: none; }
.rt-flags-input { width: 64px; border: 0; background: transparent; color: var(--accent); font-family: var(--mono);
  font-size: 15px; padding: 8px 4px; outline: none; }
.rt-flag-toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.rt-flag-toggles button {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  font-family: var(--mono); font-size: 13px; font-weight: 600; width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
}
.rt-flag-toggles button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.rt-status { min-height: 22px; margin: 12px 2px 4px; font-family: var(--mono); font-size: 13px; }
.rt-status.err { color: var(--bad); }
.rt-status.ok { color: var(--good); }

.rt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 8px; }
@media (max-width: 720px) { .rt-grid { grid-template-columns: 1fr; } }
.rt-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); min-width: 0; }
.rt-pattern-field { min-width: 0; }
.rt-panel-label {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 14px;
  font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--faint);
  border-bottom: 1px solid var(--line);
}
.rt-count { text-transform: none; letter-spacing: 0; font-family: var(--mono); font-weight: 700; color: var(--accent); }

/* highlight-over-textarea */
.rt-editor-wrap { position: relative; height: 300px; }
.rt-highlight, .rt-textarea {
  position: absolute; inset: 0; margin: 0; padding: 14px; border: 0;
  font-family: var(--mono); font-size: 14px; line-height: 1.6; tab-size: 2;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word; overflow: auto;
}
.rt-highlight { color: var(--ink); pointer-events: none; background: transparent; }
/* no horizontal padding: it would add inline width and drift the overlay off the textarea */
.rt-highlight mark { background: var(--mark); color: var(--mark-ink); border-radius: 3px; padding: 0; }
.rt-highlight mark.alt { background: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--ink); }
.rt-textarea { background: transparent; color: transparent; caret-color: var(--accent); resize: none; outline: none; }
.rt-textarea::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }

.rt-matches { padding: 6px; max-height: 300px; overflow: auto; }
.rt-match { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; margin: 6px; font-family: var(--mono); font-size: 13px; }
.rt-match-head { display: flex; justify-content: space-between; color: var(--faint); font-size: 11.5px; margin-bottom: 6px; }
.rt-match-text { color: var(--ink); word-break: break-word; }
.rt-match-text b { background: var(--mark); color: var(--mark-ink); border-radius: 3px; padding: 0 2px; font-weight: 400; }
.rt-groups { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 8px; display: grid; gap: 4px; }
.rt-group { display: flex; gap: 8px; color: var(--muted); }
.rt-group .gk { color: var(--accent); flex: 0 0 auto; }
.rt-empty { padding: 24px 14px; color: var(--faint); font-size: 13.5px; text-align: center; }

.rt-cheats { margin-top: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.rt-cheats summary { cursor: pointer; padding: 14px 16px; font-weight: 600; color: var(--ink); }
.rt-cheats-body { padding: 0 16px 18px; }
.rt-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.rt-presets button { appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  font-family: var(--sans); font-size: 12.5px; font-weight: 600; padding: 6px 12px; border-radius: 999px; cursor: pointer; }
.rt-presets button:hover { border-color: var(--accent); color: var(--accent); }
.rt-cheatsheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 16px; font-size: 13px; color: var(--muted); }
.rt-cheatsheet code { font-family: var(--mono); background: var(--surface-2); color: var(--ink); padding: 1px 6px; border-radius: 5px; margin-right: 6px; }

/* copy-regex button (sits at the end of the pattern row) */
.rt-copy-regex {
  appearance: none; display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  font-family: var(--sans); font-size: 12.5px; font-weight: 600; height: 34px; padding: 0 12px; border-radius: 8px; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.rt-copy-regex:hover { border-color: var(--accent); color: var(--accent); }
.rt-copy-regex svg { width: 14px; height: 14px; }

/* replace-with row (revealed only in Replace mode) */
.rt-replace-row {
  display: flex; align-items: center; gap: 10px; margin: 12px 0 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px 10px 3px 12px;
}
.rt-replace-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rt-repl-tag { flex: 0 0 auto; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }
.rt-replace-input {
  flex: 1 1 auto; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font-family: var(--mono); font-size: 14px; padding: 8px 4px; outline: none;
}
.rt-replace-input::placeholder { color: var(--faint); }

/* right-panel tabs (Matches / Replace) */
.rt-ptabs { display: flex; gap: 6px; margin: -2px 0; }
.rt-ptab {
  appearance: none; border: 0; background: transparent; cursor: pointer; font: inherit;
  font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--faint);
  padding: 4px 2px; border-bottom: 2px solid transparent; transition: color .15s, border-color .15s;
}
.rt-ptab:hover { color: var(--ink); }
.rt-ptab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* substitution result */
.rt-result-bar { display: flex; align-items: center; justify-content: space-between; padding: 7px 10px 7px 14px; border-bottom: 1px solid var(--line); }
.rt-result-lbl { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }
.rt-copy-result {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  font-family: var(--sans); font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 7px; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.rt-copy-result:hover { border-color: var(--accent); color: var(--accent); }
.rt-result {
  padding: 14px; max-height: 258px; overflow: auto; margin: 0;
  font-family: var(--mono); font-size: 14px; line-height: 1.6; tab-size: 2;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word; color: var(--ink);
}
.rt-result mark.rt-ins { background: color-mix(in srgb, var(--good) 34%, transparent); color: var(--ink); border-radius: 3px; padding: 0 1px; box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--good) 60%, transparent); }
/* matched text is click-to-copy */
.rt-match-text b { cursor: copy; }

.pg-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 600; padding: 10px 18px;
  border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; box-shadow: var(--shadow);
}
.pg-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* About section — self-contained WCAG-AA palette (independent of theme toggle) */
.tool-about {
  --ab-bg: #ffffff; --ab-surface: #f6f7fb; --ab-text: #1a1c25;
  --ab-muted: #475063; --ab-faint: #5b6472; --ab-border: #e4e6ef; --ab-accent: #4f46e5;
  background: var(--ab-bg); color: var(--ab-text); border-top: 1px solid var(--ab-border);
  padding: 64px 24px 80px; font-size: 15px;
}
:root[data-theme="dark"] .tool-about {
  --ab-bg: #0f131a; --ab-surface: #1a1f2b; --ab-text: #e8eaf2;
  --ab-muted: #b7bccd; --ab-faint: #99a1b3; --ab-border: #262a38; --ab-accent: #8d89f6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .tool-about { --ab-bg: #0f131a; --ab-surface: #1a1f2b; --ab-text: #e8eaf2;
    --ab-muted: #b7bccd; --ab-faint: #99a1b3; --ab-border: #262a38; --ab-accent: #8d89f6; }
}
.tool-about-inner { max-width: 860px; margin: 0 auto; line-height: 1.65; }
.tool-about h1 { font-size: clamp(1.6rem, 3.5vw, 2.2rem); font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; color: var(--ab-text); }
.tool-about code { font-family: var(--mono); font-size: 0.88em; background: var(--ab-surface); padding: 1px 6px; border-radius: 5px; color: var(--ab-text); }
.about-lede { font-size: 1.05rem; color: var(--ab-muted); margin-top: 14px; max-width: 68ch; }
.about-cta-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.about-btn { display: inline-flex; align-items: center; padding: 10px 18px; border-radius: 10px; background: var(--ab-accent); color: #fff; text-decoration: none; font-weight: 600; font-size: 0.95rem; transition: transform .15s ease, box-shadow .15s ease; }
.about-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 18px -6px var(--ab-accent); }
.about-btn.ghost { background: transparent; color: var(--ab-accent); border: 1px solid var(--ab-border); }
.about-btn:focus-visible, .about-links a:focus-visible, .about-faq summary:focus-visible { outline: 2px solid var(--ab-accent); outline-offset: 2px; border-radius: 6px; }
.about-highlight { margin: 40px 0; padding: 22px 24px; background: var(--ab-surface); border: 1px solid var(--ab-border); border-left: 4px solid var(--ab-accent); border-radius: 12px; }
.about-highlight h2 { font-size: 1.15rem; margin: 0 0 8px; color: var(--ab-text); }
.about-highlight p { color: var(--ab-muted); margin: 0; }
.about-h2 { font-size: 1.3rem; font-weight: 700; margin: 40px 0 16px; color: var(--ab-text); }
.about-features { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2,1fr); gap: 12px 28px; }
.about-features li { position: relative; padding-left: 26px; color: var(--ab-muted); font-size: 0.95rem; }
.about-features li::before { content: "\2713"; position: absolute; left: 0; top: 0; color: #15803d; font-weight: 700; }
:root[data-theme="dark"] .about-features li::before { color: #35c08a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .about-features li::before { color: #35c08a; } }
.about-features strong { color: var(--ab-text); }
.about-faq { display: flex; flex-direction: column; gap: 10px; }
.about-faq details { border: 1px solid var(--ab-border); border-radius: 10px; background: var(--ab-surface); overflow: hidden; }
.about-faq summary { cursor: pointer; padding: 14px 18px; font-weight: 600; color: var(--ab-text); list-style: none; position: relative; }
.about-faq summary::-webkit-details-marker { display: none; }
.about-faq summary::after { content: "+"; position: absolute; right: 18px; color: var(--ab-accent); font-weight: 700; }
.about-faq details[open] summary::after { content: "\2013"; }
.about-faq details p { padding: 0 18px 16px; margin: 0; color: var(--ab-muted); }
.about-links ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.about-links li { color: var(--ab-muted); }
.about-links a { color: var(--ab-accent); font-weight: 600; text-decoration: none; }
.about-links a:hover { text-decoration: underline; }
.about-foot { margin-top: 44px; padding-top: 20px; border-top: 1px solid var(--ab-border); font-size: 0.9rem; color: var(--ab-faint); }
.about-foot a { color: var(--ab-accent); text-decoration: none; }
@media (max-width: 640px) { .about-features { grid-template-columns: 1fr; } .tool-about { padding: 48px 18px 64px; } }
