/* ════════════════════════════════════════════════════════════════════════
   regexguide.com — design tokens, layout primitives, and components.
   Sibling stylesheet to crontabsheet.com but with indigo (#4f46e5) accent
   so the two sites read as a related family while staying distinct.
   ════════════════════════════════════════════════════════════════════════ */

:root {
  /* Brand palette ─ indigo as the accent, warm neutrals as the base */
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-deep: #312e81;

  /* Light theme neutrals */
  --bg: #fafaf8;
  --surface-1: #ffffff;
  --surface-2: #f5f5f4;
  --line: #e4e4e0;
  --ink: #1c1917;
  --ink-muted: #78716c;
  --ink-soft: #57534e;

  /* Type scale */
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Geist', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;

  /* Spacing & radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 36px rgba(0,0,0,0.10);

  --max-width: 1180px;
  --content-width: 760px;
}

[data-theme="dark"] {
  --bg: #18181b;
  --surface-1: #27272a;
  --surface-2: #1f1f23;
  --line: #3f3f46;
  --ink: #fafaf9;
  --ink-muted: #a1a1aa;
  --ink-soft: #d4d4d8;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { min-height: 100vh; }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s;
}
a:hover { color: var(--accent-hover); }

code, pre, .mono {
  font-family: var(--mono);
  font-size: 0.93em;
}

pre {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}

code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
}

pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

/* ─────────── LAYOUT ─────────── */

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

.section {
  padding: 64px 0;
}

@media (max-width: 768px) {
  .section { padding: 40px 0; }
  .wrap { padding: 0 18px; }
}

/* ─────────── NAVIGATION ─────────── */

.nav-bar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.nav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 19px;
  color: var(--ink);
}
.nav-brand:hover { color: var(--ink); }

.nav-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--accent);
  color: #ffffff;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  border-radius: 7px;
  letter-spacing: -0.02em;
}

.nav-brand-tld {
  color: var(--accent);
  font-weight: 400;
}

.nav-links {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0;
  gap: 4px;
  align-items: center;
}

.nav-links a:not(.btn) {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 7px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-links a:not(.btn):hover {
  background: var(--surface-2);
  color: var(--ink);
}

.theme-toggle {
  background: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  color: var(--ink-muted);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.mobile-nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 18px;
  cursor: pointer;
  color: var(--ink);
}

.mobile-nav {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  padding: 24px;
  flex-direction: column;
  gap: 8px;
}
.mobile-nav.open { display: flex; }
.mobile-nav ul {
  list-style: none;
  padding: 0;
  margin: 24px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mobile-nav a {
  display: block;
  padding: 14px 16px;
  font-size: 18px;
  border-radius: 8px;
  color: var(--ink);
}
.mobile-nav a:hover { background: var(--surface-2); }

@media (max-width: 980px) {
  .nav-links { display: none; }
  .mobile-nav-toggle { display: inline-block; }
}

/* ─────────── BUTTONS ─────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 8px;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.05s;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover {
  background: var(--accent-hover);
  color: white;
}

.btn-secondary {
  background: var(--surface-1);
  border-color: var(--line);
  color: var(--ink);
}
.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
}
.btn-ghost:hover { color: var(--ink); }

/* ─────────── ADSTERRA BANNER ─────────── */

.ad-banner {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  min-height: 100px;
}
.ad-banner-inner.desktop { display: block; width: 728px; height: 90px; max-width: 100%; }
.ad-banner-inner.mobile { display: none; width: 320px; height: 50px; }
@media (max-width: 768px) {
  .ad-banner { min-height: 70px; padding: 10px; }
  .ad-banner-inner.desktop { display: none; }
  .ad-banner-inner.mobile { display: block; }
}

/* ─────────── HERO ─────────── */

.hero {
  padding: 56px 0 32px;
}

.hero-eyebrow-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.hero-eyebrow {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

.hero h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(40px, 6vw, 64px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 22px 0;
  color: var(--ink);
}
.hero h1 em {
  color: var(--accent);
  font-style: italic;
  font-weight: 400;
}

.hero-h2 {
  font-family: var(--sans);
  font-size: clamp(20px, 2vw, 24px);
  font-weight: 400;
  line-height: 1.4;
  color: var(--ink-soft);
  margin: 0 0 18px 0;
  max-width: 64ch;
}
.hero-h2 em {
  color: var(--accent);
  font-style: italic;
  font-weight: 500;
}

.hero p {
  font-size: 17px;
  color: var(--ink-soft);
  max-width: 64ch;
  margin: 0 0 28px 0;
}

.hero-features {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
}
.hero-features span {
  display: inline-block;
  padding: 6px 14px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}
[data-theme="dark"] .hero-features span { color: var(--accent); }

/* PDF download CTA */
.cta-download {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.cta-download:hover {
  border-color: var(--accent);
  background: var(--surface-1);
  color: var(--ink);
  transform: translateY(-1px);
}
.cta-download-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}
.cta-download-text { display: flex; flex-direction: column; line-height: 1.2; }
.cta-download-text strong { font-size: 13px; font-weight: 600; }
.cta-download-text small {
  font-size: 10px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
  font-family: var(--mono);
}
@media (max-width: 640px) {
  .hero-eyebrow-row { flex-direction: column; align-items: flex-start; gap: 14px; }
  .cta-download { width: 100%; }
}

/* ─────────── EXPLAINER TOOL ─────────── */

.explainer-card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow);
  margin: 32px 0;
}

.explainer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.explainer-header h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 24px;
  color: var(--ink);
}
.explainer-actions { display: flex; flex-wrap: wrap; gap: 8px; row-gap: 6px; }

.regex-input {
  width: 100%;
  padding: 16px 18px;
  font-family: var(--mono);
  font-size: 18px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
  resize: vertical;
  min-height: 50px;
}
.regex-input:focus {
  border-color: var(--accent);
  background: var(--surface-1);
}

.input-label {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 18px 0 8px 0;
}

.intent-banner {
  margin-top: 20px;
  padding: 18px 22px;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  color: var(--accent-deep);
  font-size: 17px;
  line-height: 1.5;
}
[data-theme="dark"] .intent-banner { color: var(--ink); }
.intent-banner strong {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
  color: var(--accent);
  font-weight: 600;
}

.error-banner {
  margin-top: 20px;
  padding: 16px 18px;
  background: #fef2f2;
  border-left: 4px solid #ef4444;
  border-radius: 8px;
  color: #991b1b;
  font-family: var(--mono);
  font-size: 14px;
}
[data-theme="dark"] .error-banner { background: #3b1f1f; color: #fca5a5; }

.warnings-list {
  margin-top: 14px;
  padding: 12px 16px;
  background: #fffbeb;
  border-left: 4px solid #f59e0b;
  border-radius: 8px;
  font-size: 14px;
  color: #78350f;
}
.warnings-list ul { margin: 4px 0 0; padding-left: 18px; }
[data-theme="dark"] .warnings-list { background: #2d2410; color: #fcd34d; }

/* Tree explanation view */
.explain-tree {
  margin-top: 24px;
  padding: 0;
  list-style: none;
}
.explain-node {
  margin: 0;
  padding: 10px 12px 10px 14px;
  border-left: 2px solid var(--line);
  margin-left: 8px;
  position: relative;
}
.explain-node:hover { border-left-color: var(--accent); }
.explain-node-header {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.explain-token {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 4px;
}
.explain-role {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  font-family: var(--mono);
  font-weight: 600;
}
.explain-description {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.55;
}
.explain-children {
  margin-top: 8px;
  padding-left: 8px;
  list-style: none;
}

/* Test panel */
.test-panel { margin-top: 28px; }
.test-input {
  width: 100%;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  outline: none;
  min-height: 100px;
  resize: vertical;
}
.test-input:focus { border-color: var(--accent); }

.match-output {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.7;
  min-height: 60px;
}
.match-highlight {
  /* Subtle neutral highlight — visible but not visually competing with the
     "X matches found" status line, which is the primary success/fail signal. */
  background: var(--surface-1);
  border: 1px solid var(--line);
  padding: 1px 4px;
  border-radius: 3px;
  color: var(--ink);
}
[data-theme="dark"] .match-highlight {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--line);
}
.match-summary {
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-muted);
  font-family: var(--mono);
}
/* When matches are found, show the count in green. When no matches are
   found, show the message in a clear red. Bold weight so the status reads
   at a glance. Colors chosen to keep enough contrast on both light
   (default) and dark backgrounds; the greens match the existing
   .test-case.pass and .bench-verdict.good shades used elsewhere. */
.match-summary.success { color: #16a34a; font-weight: 600; }
.match-summary.fail    { color: #dc2626; font-weight: 600; }
[data-theme="dark"] .match-summary.success { color: #4ade80; }
[data-theme="dark"] .match-summary.fail    { color: #f87171; }

/* ─────────── SECTIONS ─────────── */

.section-eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 16px;
}

.section-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 36px 0;
  color: var(--ink);
}
.section-title em {
  color: var(--accent);
  font-style: italic;
  font-weight: 400;
}

/* Feature cards grid */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.feature-card {
  padding: 24px 22px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.15s, transform 0.15s;
}
.feature-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.feature-icon {
  font-size: 22px;
  margin-bottom: 12px;
}
.feature-card h3 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}
.feature-card p {
  margin: 0;
  font-size: 14px;
  color: var(--ink-muted);
  line-height: 1.5;
}

/* ─────────── PROSE (for content pages) ─────────── */

.prose {
  max-width: var(--content-width);
  margin: 0 auto;
}
.prose h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 28px;
  margin: 48px 0 18px 0;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.prose h3 {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 20px;
  margin: 36px 0 12px 0;
  color: var(--ink);
}
.prose p { margin: 0 0 16px 0; color: var(--ink-soft); font-size: 17px; line-height: 1.65; }
.prose ul, .prose ol { margin: 0 0 20px 0; padding-left: 24px; color: var(--ink-soft); font-size: 17px; line-height: 1.7; }
.prose li { margin-bottom: 8px; }
.prose strong { color: var(--ink); font-weight: 600; }
.prose code { font-size: 0.92em; }
.prose a { text-decoration: underline; text-decoration-color: rgba(79, 70, 229, 0.4); text-underline-offset: 3px; }
.prose a:hover { text-decoration-color: var(--accent); }

/* ─────────── PATTERN LIBRARY ─────────── */

.pattern-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 16px 0 32px;
}
.pattern-table th,
.pattern-table td {
  padding: 14px 18px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.pattern-table th {
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  font-weight: 600;
}
.pattern-table tr:last-child td { border-bottom: 0; }
.pattern-table tr:hover td { background: var(--surface-2); }
.pattern-table code {
  display: inline-block;
  background: var(--surface-2);
  padding: 3px 8px;
  font-size: 12px;
  border-radius: 4px;
  word-break: break-all;
  max-width: 360px;
}
.pattern-table .try-btn {
  display: inline-block;
  padding: 4px 12px;
  background: var(--accent);
  color: white;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.pattern-table .try-btn:hover { background: var(--accent-hover); color: white; }

/* ─────────── BREADCRUMB ─────────── */

.breadcrumb {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 12px;
}
.breadcrumb a { color: var(--ink); font-weight: 600; transition: color 0.15s; }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb span { margin: 0 10px; color: var(--ink-muted); }

/* ─────────── FOOTER ─────────── */

.footer {
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  padding: 56px 0 28px;
  margin-top: 64px;
}

.footer-grid {
  display: grid;
  gap: 32px;
  padding-bottom: 36px;
  border-bottom: 1px solid var(--line);
}

.footer-col h4 {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 14px 0;
}
.footer-col ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.footer-col li { margin-bottom: 8px; }
.footer-col a {
  color: var(--ink-soft);
  font-size: 14px;
}
.footer-col a:hover { color: var(--accent); }

.footer-bottom {
  padding-top: 22px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
  color: var(--ink-muted);
  font-family: var(--mono);
}

/* Footer-grid uses an inline `style="grid-template-columns: 1.5fr 1fr 1fr 1fr"`
   on hundreds of pages, so we use !important to win against the inline rule
   at narrow widths. Without this, the 4-column layout forces ~80px of
   horizontal overflow at 320px viewports. */
@media (max-width: 768px) {
  .footer-grid { grid-template-columns: 1fr 1fr !important; }
}
@media (max-width: 480px) {
  .footer-grid { grid-template-columns: 1fr !important; }
}

/* ─────────── UTILITY ─────────── */

.text-mono { font-family: var(--mono); }
.text-muted { color: var(--ink-muted); }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }

/* ═══════════════════════════════════════════════════════════════════
 * TOOL TABS + NEW PANELS (added v3)
 * ═══════════════════════════════════════════════════════════════════ */

/* Regex + flags input row */
.regex-input-row { display: flex; gap: 12px; align-items: flex-start; }
.regex-input-wrap { flex: 1 1 auto; min-width: 0; }
.flags-input-wrap { flex: 0 0 80px; }
.flags-input {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 16px;
  background: var(--surface-1);
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm, 8px);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
}
.flags-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

@media (max-width: 600px) {
  .regex-input-row { flex-direction: column; }
  .flags-input-wrap { flex: 0 0 auto; width: 100%; }
}

/* Tab bar */
.tab-bar {
  display: flex;
  gap: 4px;
  margin: 20px 0 16px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab-btn {
  background: transparent;
  border: none;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: block; }
.tab-panel[hidden] { display: none; }

/* Replace tab */
.replace-result {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}
.replace-result .replace-changed {
  background: var(--accent-soft);
  color: var(--accent-deep);
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 500;
}
.replace-summary {
  margin-top: 10px;
  font-size: 13px;
  color: var(--ink-muted);
  font-family: var(--mono);
}

/* Test suite */
.test-case {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  margin: 6px 0;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--line);
}
.test-case-status {
  flex: 0 0 80px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.test-case.pass .test-case-status { color: #16a34a; }
.test-case.fail .test-case-status { color: #dc2626; }
.test-case-expected {
  flex: 0 0 110px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.test-case-text {
  flex: 1 1 auto;
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 6px 8px;
}
.test-case-remove {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
}
.test-case-remove:hover { color: #dc2626; }
.test-suite-summary {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
}
.test-suite-summary.all-pass { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.test-suite-summary.some-fail { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* Code generator */
.code-flavor-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.code-flavor-tab {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 6px 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-muted);
  cursor: pointer;
  border-radius: 6px;
  white-space: nowrap;
  transition: all 0.15s;
}
.code-flavor-tab:hover { color: var(--ink); }
.code-flavor-tab.active { background: var(--accent); color: white; border-color: var(--accent); }

.code-output-wrap { position: relative; }
.code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  font-size: 12px;
  padding: 4px 10px;
}
.code-output {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  overflow-x: auto;
  margin: 0;
  white-space: pre;
}

/* Debug panel */
.debug-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: 8px;
}
.debug-view {
  margin-top: 14px;
  padding: 16px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--line);
}
.debug-input {
  font-family: var(--mono);
  font-size: 18px;
  line-height: 1.8;
  letter-spacing: 1px;
  white-space: pre-wrap;
  margin-bottom: 12px;
  padding: 10px;
  background: var(--surface-1);
  border-radius: 6px;
  border: 1px solid var(--line);
}
.debug-char { padding: 2px 1px; }
.debug-char.debug-cursor {
  background: var(--accent);
  color: white;
  border-radius: 3px;
  position: relative;
  font-weight: 600;
}
.debug-char.debug-cursor::after {
  content: '▾';
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--accent);
  font-size: 12px;
}
.debug-char.debug-matched { background: var(--accent-soft); color: var(--accent-deep); }
.debug-char.debug-eof { color: var(--ink-muted); opacity: 0.5; }
.debug-message {
  font-family: var(--mono);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
}
.debug-message.debug-try { background: var(--surface-1); color: var(--ink-muted); border: 1px solid var(--line); }
.debug-message.debug-match-start { background: var(--accent-soft); color: var(--accent-deep); }
.debug-message.debug-match-success { background: #dcfce7; color: #166534; font-weight: 500; }

/* Diagram */
.diagram-output {
  margin-top: 14px;
  padding: 24px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  text-align: center;
}
.diagram-output svg.railroad { max-width: 100%; height: auto; display: inline-block; }

/* Benchmark */
.bench-output {
  margin-top: 16px;
  padding: 16px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--line);
}
.bench-verdict { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.bench-verdict.good { color: #166534; }
.bench-verdict.warn { color: #b45309; }
.bench-verdict.bad { color: #991b1b; }
.bench-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.bench-stat {
  padding: 10px 12px;
  background: var(--surface-1);
  border-radius: 6px;
  border: 1px solid var(--line);
}
.bench-stat-label { font-size: 11px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.bench-stat-value { font-family: var(--mono); font-size: 17px; font-weight: 600; color: var(--ink); margin-top: 4px; }

.bench-growth-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-family: var(--mono); font-size: 13px; }
.bench-growth-table th, .bench-growth-table td { padding: 8px 12px; border: 1px solid var(--line); text-align: left; }
.bench-growth-table th { background: var(--surface-1); font-weight: 600; font-size: 11px; text-transform: uppercase; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: var(--ink);
  color: var(--surface-1);
  border-radius: 8px;
  font-size: 14px;
  z-index: 999;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  animation: toastIn 0.2s ease-out;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ═══════════════════════════════════════════════════════════════════
 * EXTRAS — match list, history, formatter, export (added v4)
 * ═══════════════════════════════════════════════════════════════════ */

/* Match list */
.match-list-section { margin-top: 20px; }
.match-list-details { background: var(--surface-2); border-radius: 10px; border: 1px solid var(--line); padding: 0; }
.match-list-details summary { padding: 12px 16px; cursor: pointer; font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); }
.match-list-details summary:hover { color: var(--ink); }
.match-list-table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface-1); }
.match-list-table th, .match-list-table td { padding: 8px 12px; border-top: 1px solid var(--line); text-align: left; }
.match-list-table th { background: var(--surface-2); font-weight: 600; font-size: 11px; text-transform: uppercase; color: var(--ink-muted); letter-spacing: 0.06em; }
.match-list-table td code { background: var(--accent-soft); color: var(--accent-deep); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.match-list-table td .muted { color: var(--ink-muted); opacity: 0.5; }

/* History panel */
.history-panel { margin-top: 12px; padding: 14px 16px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
.history-empty { font-size: 13px; color: var(--ink-muted); padding: 12px 0; }
.history-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.history-list { list-style: none; padding: 0; margin: 0; }
.history-item { display: flex; align-items: center; gap: 4px; padding: 4px 0; }
.history-restore { flex: 1; text-align: left; background: transparent; border: none; padding: 6px 8px; cursor: pointer; border-radius: 5px; color: inherit; }
.history-restore:hover { background: var(--surface-1); }
.history-pattern { display: block; font-size: 13px; word-break: break-all; }
.history-meta { display: block; font-size: 11px; color: var(--ink-muted); margin-top: 2px; font-family: var(--mono); }
.history-remove { background: transparent; border: none; color: var(--ink-muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 4px 8px; }
.history-remove:hover { color: #dc2626; }
.btn-sm { font-size: 12px; padding: 4px 10px; }

/* Format output */
.format-output { margin-top: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.format-output-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.format-output-header strong { flex: 1; font-size: 13px; }
.format-pre { background: var(--surface-1); border: 1px solid var(--line); border-radius: 6px; padding: 14px; overflow-x: auto; margin: 0; }
.format-pre code { font-family: var(--mono); font-size: 13px; line-height: 1.5; color: var(--ink); }
.format-note { font-size: 12px; color: var(--ink-muted); margin-top: 10px; line-height: 1.5; }
.format-note code { background: var(--accent-soft); padding: 1px 5px; border-radius: 3px; }

/* Cheat-sheet download CTA — compact, top-right, below ad-banner */
.cheatsheet-top-cta-wrap {
  margin: 10px auto 0;
  padding: 0;
}
.cheatsheet-top-cta-wrap .wrap {
  display: flex;
  justify-content: flex-end;
  padding-top: 0;
  padding-bottom: 0;
}
.cheatsheet-top-cta {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  text-decoration: none;
  color: #ffffff;
  transition: filter 0.15s, transform 0.1s, box-shadow 0.15s;
  font-size: 14px;
  max-width: 100%;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.18);
}
.cheatsheet-top-cta:hover {
  filter: brightness(1.08);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.28);
}
.cheatsheet-top-cta-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  flex-shrink: 0;
}
.cheatsheet-top-cta-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  min-width: 0;
}
.cheatsheet-top-cta-text strong {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
}
.cheatsheet-top-cta-sub {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.92);
  font-family: var(--mono);
  margin-top: 1px;
}
@media (max-width: 700px) {
  .cheatsheet-top-cta-wrap .wrap {
    justify-content: center;
    padding-left: 14px;
    padding-right: 14px;
  }
  .cheatsheet-top-cta {
    width: 100%;
    justify-content: center;
  }
  .cheatsheet-top-cta-sub {
    display: none;
  }
}

/* Mobile fixes for explainer toolbar */
@media (max-width: 640px) {
  .explainer-header { flex-wrap: wrap; gap: 8px; }
  .explainer-actions .btn { font-size: 12px; padding: 6px 10px; }
}

/* ═══════════════════════════════════════════════════════════════════
 * NARROW-VIEWPORT POLISH (added v5)
 * Fixes horizontal-overflow issues at ≤375px viewports (iPhone SE, older
 * Androids). Targets long inline code in prose, the cheat-sheet grid that
 * wouldn't collapse below 360px, and a few small touch-target tweaks.
 * ═══════════════════════════════════════════════════════════════════ */

/* Belt-and-suspenders: never let the page itself scroll horizontally.
   Using `overflow-x: clip` on body instead of `overflow-x: hidden` because
   `hidden` establishes a scroll context that breaks `position: sticky` on
   descendant elements (the nav bar). `clip` is supported in all modern
   browsers (Chrome 90+, Safari 16+, Firefox 81+) and doesn't have that
   side-effect. We keep `html` untouched so sticky works. */
body { overflow-x: clip; }
/* Fallback for older browsers that don't support `clip` (they get `hidden`,
   which is fine — the nav just won't be sticky on those browsers). */
@supports not (overflow-x: clip) {
  body { overflow-x: hidden; }
}

/* Long regex patterns inside <code> elements in prose used to overflow on
   pattern-detail pages, e.g. "regexp.MustCompile(pattern).MatchString(value)". */
.prose code,
.pattern-card-code,
.match-output,
.replace-result {
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Tablet/mobile breakpoint */
@media (max-width: 768px) {
  /* Cheat-sheet grid: minmax(360px, 1fr) was too wide for 320px viewports
     and forced horizontal scroll on the cheat-sheet cards. Stack to one
     column on mobile — the cards are already self-contained. */
  .cheat-grid { grid-template-columns: 1fr !important; }
  /* Grid items default to min-width: auto, which uses the content's
     intrinsic min-width and can overflow narrow containers. Force them
     to shrink. */
  .cheat-grid > .cheat-card { min-width: 0; }
  .cheat-card table { table-layout: fixed; }
  .cheat-card td:first-child { width: 32% !important; word-break: break-word; }
  .cheat-card td:nth-child(2) { word-break: break-word; }
  .cheat-card .ex { word-break: break-word; }

  /* Pattern-table tries to lay out as a wide table; on phones, let cells
     stack vertically and allow long code samples to wrap. */
  .pattern-table th,
  .pattern-table td { padding: 10px 12px; }
  .pattern-table code { max-width: 100%; }

  /* Hero/explainer paddings get a bit tighter so the tool card uses more
     of the available width. */
  .explainer-card { padding: 20px 16px; }
  .hero { padding: 36px 0 20px; }

  /* Prose code blocks should never push the page wide. */
  .prose pre { font-size: 12px; }
}

/* Very narrow phones — 360px and below (e.g. Galaxy S8, iPhone SE 1st gen). */
@media (max-width: 380px) {
  /* Brand becomes too cramped at 320px; drop the .com tld and rely on the
     brand mark + name. */
  .nav-brand { font-size: 17px; }
  .nav-brand-tld { display: none; }

  /* Reduce wrap padding so the explainer card has room to breathe. */
  .wrap { padding: 0 14px; }

  /* The flag/quantifier "Try sample / History" toolbar buttons get tiny labels. */
  .tab-btn { padding: 8px 10px; font-size: 13px; }

  /* Section paddings */
  .section { padding: 28px 0; }

  /* Slightly smaller hero headline at 320px so it doesn't dominate the screen. */
  .hero h1 { font-size: clamp(32px, 9vw, 40px); }
}

/* Tap targets: ensure all interactive elements meet ~44px minimum on touch
   devices. Applies to mobile nav links specifically. */
.mobile-nav a,
.mobile-nav button { min-height: 44px; }
