:root {
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface2: #ffffff;
  --border: #e3e8f0;
  --text: #0f172a;
  --muted: #5b6878;
  --accent: #2563eb;
  --success: #059669;
  --danger: #dc2626;
  --warn: #b45309;
  --radius: 8px;
  --match0: rgba(251,191,36,.35);
  --match1: rgba(108,140,255,.35);
  --match2: rgba(167,139,250,.35);
  --match3: rgba(52,211,153,.35);
  --match4: rgba(248,113,113,.35);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; min-height: 100vh; }

nav { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 20px; }
.nav-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; height: 52px; }
.logo { font-weight: 700; font-size: 1.1rem; }
.nav-badge { font-size: .75rem; color: var(--muted); background: var(--surface2); border: 1px solid var(--border); padding: 3px 10px; border-radius: 20px; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }

/* PATTERN ROW */
.pattern-row { margin-bottom: 8px; }
.pattern-wrap { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; transition: border-color .15s; }
.pattern-wrap:focus-within { border-color: var(--accent); }
.delim { color: var(--muted); padding: 0 8px; font-family: 'Consolas', monospace; font-size: 1.2rem; user-select: none; }
.pattern-input { flex: 1; background: transparent; border: none; color: var(--accent); font-family: 'Consolas', 'Monaco', monospace; font-size: 1rem; padding: 12px 4px; outline: none; min-width: 0; }
.flags-input { width: 70px; background: var(--surface2); border: none; border-left: 1px solid var(--border); color: var(--warn); font-family: monospace; font-size: .95rem; padding: 12px 10px; outline: none; }
.regex-error { font-size: .82rem; color: var(--danger); padding: 4px 0; min-height: 20px; }

/* FLAGS ROW */
.flags-row { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.flags-label { font-size: .78rem; color: var(--muted); }
.flag-btn { background: var(--surface2); border: 1px solid var(--border); color: var(--muted); width: 28px; height: 28px; border-radius: 5px; cursor: pointer; font-family: monospace; font-size: .85rem; font-weight: 700; transition: background .15s, color .15s, border-color .15s; }
.flag-btn.active { background: #1e2a50; border-color: var(--accent); color: var(--accent); }
.flag-desc { font-size: .78rem; color: var(--muted); margin-left: 8px; }

/* MODE TABS */
.mode-tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.mode-tab { background: var(--surface2); border: 1px solid var(--border); color: var(--muted); padding: 7px 18px; border-radius: var(--radius); cursor: pointer; font-size: .875rem; font-weight: 500; transition: background .15s, color .15s; }
.mode-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.mode-panel { display: none; }
.mode-panel.active { display: block; }

/* TWO COL */
.two-col { display: grid; grid-template-columns: 1fr 320px; gap: 14px; }
.col-left { display: flex; flex-direction: column; position: relative; }
.col-right { display: flex; flex-direction: column; }

/* PANEL HEADER */
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--surface2); border: 1px solid var(--border); border-bottom: none; border-radius: var(--radius) var(--radius) 0 0; }
.panel-label { font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.panel-actions { display: flex; align-items: center; gap: 8px; }
.match-badge { font-size: .78rem; background: var(--surface); border: 1px solid var(--border); padding: 2px 8px; border-radius: 10px; color: var(--text); }
.match-badge.has-matches { background: #162a1f; border-color: #05966944; color: var(--success); }
.btn-sm { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 4px 10px; border-radius: 5px; cursor: pointer; font-size: .78rem; transition: background .15s; }
.btn-sm:hover { background: var(--border); }

/* TEXTAREA + HIGHLIGHT */
.test-area { width: 100%; height: 260px; resize: vertical; background: transparent; border: 1px solid var(--border); color: var(--text); font-family: 'Consolas', 'Monaco', monospace; font-size: .9rem; padding: 12px; outline: none; line-height: 1.6; position: relative; z-index: 2; white-space: pre-wrap; word-break: break-word; overflow-y: auto; caret-color: var(--accent); }
.test-area:focus { border-color: var(--accent); }
.output-area { background: var(--surface2); color: var(--success); cursor: default; }

/* Highlight overlay — sits behind the textarea but aligned */
.col-left { position: relative; }
.highlight-layer { position: absolute; top: 37px; left: 0; right: 0; bottom: 0; padding: 12px; font-family: 'Consolas', 'Monaco', monospace; font-size: .9rem; line-height: 1.6; white-space: pre-wrap; word-break: break-word; pointer-events: none; color: transparent; overflow: hidden; z-index: 1; background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); }
.highlight-layer mark { border-radius: 2px; color: transparent; padding: 0; }
.m0 { background: var(--match0); }
.m1 { background: var(--match1); }
.m2 { background: var(--match2); }
.m3 { background: var(--match3); }
.m4 { background: var(--match4); }
.col-left textarea { background: transparent; border-radius: 0 0 var(--radius) var(--radius); }

/* MATCH DETAILS */
.match-details { background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); padding: 12px; overflow-y: auto; max-height: 310px; display: flex; flex-direction: column; gap: 10px; }
.match-item { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.match-item-header { padding: 6px 10px; font-size: .75rem; font-weight: 700; color: var(--muted); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; }
.match-full { padding: 8px 10px; font-family: monospace; font-size: .875rem; word-break: break-all; }
.match-groups { padding: 4px 10px 8px; display: flex; flex-direction: column; gap: 3px; }
.group-row { display: flex; gap: 8px; font-size: .8rem; }
.group-idx { color: var(--muted); min-width: 40px; font-family: monospace; }
.group-val { font-family: monospace; }
.no-matches { color: var(--muted); font-size: .875rem; padding: 12px; text-align: center; }

/* REPLACE */
.replace-bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface2); border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); }
.bar-label { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.replace-input { flex: 1; background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 6px 10px; border-radius: 5px; font-family: monospace; font-size: .875rem; outline: none; }
.replace-input:focus { border-color: var(--accent); }

/* CHEAT SHEET */
.cheatsheet { margin-top: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.cheatsheet summary { padding: 14px 18px; cursor: pointer; font-weight: 600; font-size: .9rem; user-select: none; list-style: none; }
.cheatsheet summary::-webkit-details-marker { display: none; }
.cheat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0; border-top: 1px solid var(--border); }
.cheat-group { padding: 16px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cheat-group:last-child { border-right: none; }
.cheat-title { font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.cheat-row { display: flex; align-items: baseline; gap: 8px; padding: 3px 0; font-size: .82rem; }
.cheat-row code { font-family: monospace; color: var(--accent); min-width: 80px; flex-shrink: 0; }
.cheat-row span { color: var(--muted); }
.cheat-clickable { cursor: pointer; border-radius: 4px; padding: 3px 4px; }
.cheat-clickable:hover { background: var(--surface2); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@media (max-width: 800px) {
  .two-col { grid-template-columns: 1fr; }
  .col-right { order: -1; }
  .match-details { max-height: 180px; }
}
