/* ============================================================
   Regex Lab — styles
   Dark, polished, responsive developer tool.
   ============================================================ */

:root {
  /* surfaces */
  --bg: #0b0f14;
  --bg-grad-a: #0c1118;
  --bg-grad-b: #0a0d12;
  --surface: #121821;
  --surface-2: #0f141c;
  --border: #1e2733;
  --border-soft: #18202b;

  /* text */
  --text: #e6edf3;
  --text-muted: #8b97a7;
  --text-faint: #5d6b7c;

  /* accents */
  --accent: #6ea8fe;
  --accent-hover: #8cbcff;
  --accent-dim: rgba(110, 168, 254, 0.14);

  /* status */
  --success: #3fb950;
  --warning: #d29922;
  --error: #f85149;

  /* group tints (for capture sub-highlights) */
  --g1: #3fb950;
  --g2: #d29922;
  --g3: #bc8cff;
  --g4: #f778ba;
  --g5: #56d4dd;
  --g6: #ff9d5c;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 36px -18px rgba(0, 0, 0, 0.8);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --t-fast: 130ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-med: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--ui);
  color: var(--text);
  background:
    radial-gradient(1100px 620px at 82% -8%, rgba(110, 168, 254, 0.08), transparent 60%),
    radial-gradient(900px 560px at 6% 4%, rgba(188, 140, 255, 0.06), transparent 55%),
    linear-gradient(180deg, var(--bg-grad-a), var(--bg-grad-b));
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

.mono { font-family: var(--mono); }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #06101f;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  z-index: 50;
  font-weight: 600;
}
.skip-link:focus { left: 12px; top: 12px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 32px);
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  line-height: 1;
  box-shadow: var(--shadow);
}
.brand-star { color: var(--accent); }

.brand-text h1 {
  font-size: 20px;
  margin: 0;
  letter-spacing: -0.01em;
}
.tagline {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.match-count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 11px;
  border-radius: 999px;
  white-space: nowrap;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.match-count.has-matches { color: var(--accent); border-color: rgba(110, 168, 254, 0.4); }
.match-count.is-error { color: var(--error); border-color: rgba(248, 81, 73, 0.4); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--ui);
  font-size: 13px;
  font-weight: 600;
  color: #07111f;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 13px;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast), color var(--t-fast);
  min-height: 38px;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn .btn-icon { font-size: 14px; line-height: 1; }

.btn-ghost {
  color: var(--text-muted);
  background: var(--surface);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); border-color: var(--accent); }

.btn.is-confirmed { background: var(--success); color: #052e10; }

button:focus-visible,
.tab:focus-visible,
.chip:focus-visible,
.flag-chip:focus-visible,
.footer-link:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- examples ---------- */
.examples {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 32px);
  border-bottom: 1px solid var(--border-soft);
  overflow-x: auto;
  scrollbar-width: thin;
}
.examples-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 700;
  flex: none;
}
.example-chips { display: flex; gap: 8px; flex-wrap: nowrap; }

.chip {
  flex: none;
  font-family: var(--ui);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.chip:hover { color: var(--text); border-color: var(--accent); background: var(--accent-dim); }
.chip:active { transform: translateY(1px); }
.chip.is-active { color: var(--accent); border-color: rgba(110, 168, 254, 0.5); background: var(--accent-dim); }

/* ---------- workspace ---------- */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 32px) 8px;
  min-height: 0;
}

.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; min-height: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-grow { flex: 1; }

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 11px;
}
.panel-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0;
  font-weight: 700;
}
.hint { font-size: 11.5px; color: var(--text-faint); }

/* ---------- pattern input ---------- */
.pattern-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.pattern-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.pattern-row.is-invalid { border-color: var(--error); }
.pattern-row.is-invalid:focus-within { box-shadow: 0 0 0 3px rgba(248, 81, 73, 0.18); }

.slash { color: var(--text-faint); font-family: var(--mono); font-size: 16px; user-select: none; }

.pattern-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14.5px;
  padding: 12px 0;
}
.pattern-input:focus { outline: none; }
.pattern-input::placeholder { color: var(--text-faint); }

.flags-echo { color: var(--accent); font-size: 13px; white-space: nowrap; }

.pattern-error {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--error);
  background: rgba(248, 81, 73, 0.08);
  border: 1px solid rgba(248, 81, 73, 0.32);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-family: var(--mono);
}

/* ---------- flags ---------- */
.flags-block { display: flex; align-items: center; gap: 12px; margin-top: 13px; }
.flags-caption {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 700;
}
.flag-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.flag-chip {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  width: 38px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.flag-chip:hover { color: var(--text-muted); border-color: var(--accent); }
.flag-chip:active { transform: translateY(1px); }
.flag-chip.is-on {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: rgba(110, 168, 254, 0.55);
}

/* ---------- sample textarea ---------- */
.sample-input {
  flex: 1;
  width: 100%;
  resize: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.65;
  padding: 12px 14px;
  min-height: 180px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.sample-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.sample-input::placeholder { color: var(--text-faint); }

/* ---------- preview ---------- */
.preview {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  min-height: 160px;
}

.preview .ph { color: var(--text-faint); font-family: var(--ui); }

/* match highlight */
mark.m {
  background: rgba(110, 168, 254, 0.16);
  border-bottom: 2px solid var(--accent);
  border-radius: 3px;
  padding: 1px 0;
  color: var(--text);
  transition: background var(--t-fast);
}
mark.m.is-hot { background: rgba(110, 168, 254, 0.34); }

/* capture-group sub tints */
.g { border-radius: 3px; padding: 0 1px; }
.g1 { background: rgba(63, 185, 80, 0.26); }
.g2 { background: rgba(210, 153, 34, 0.26); }
.g3 { background: rgba(188, 140, 255, 0.26); }
.g4 { background: rgba(247, 120, 186, 0.26); }
.g5 { background: rgba(86, 212, 221, 0.26); }
.g6 { background: rgba(255, 157, 92, 0.26); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border-soft); }
.tab {
  font-family: var(--ui);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-faint);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 12px 10px;
  cursor: pointer;
  transition: color var(--t-fast), border-color var(--t-fast);
  margin-bottom: -1px;
}
.tab:hover { color: var(--text-muted); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { max-height: 320px; overflow-y: auto; }

/* ---------- match list ---------- */
.match-list { display: flex; flex-direction: column; gap: 8px; }

.match-row {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color var(--t-fast), background var(--t-fast);
  animation: rise var(--t-med) both;
}
.match-row.is-hot { border-color: var(--accent); background: var(--accent-dim); }

.match-row-head {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}
.match-badge {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 999px;
  padding: 2px 9px;
  flex: none;
}
.match-text {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(110, 168, 254, 0.1);
  border-radius: 3px;
  padding: 1px 5px;
}
.match-index {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  flex: none;
}

.groups { display: flex; flex-direction: column; gap: 4px; margin-top: 9px; }
.group-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
}
.group-name {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  flex: none;
  min-width: 78px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.group-swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; display: inline-block; }
.group-val { font-family: var(--mono); color: var(--text); word-break: break-all; }
.group-val.is-empty { color: var(--text-faint); }

.empty-state, .info-note {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 26px 16px;
}
.empty-state .es-emoji { font-size: 22px; display: block; margin-bottom: 8px; opacity: 0.8; }

.info-note {
  padding: 10px 12px;
  text-align: left;
  color: var(--warning);
  font-size: 12px;
  background: rgba(210, 153, 34, 0.08);
  border: 1px solid rgba(210, 153, 34, 0.3);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}

/* ---------- explanation ---------- */
.flags-prose {
  margin: 0 0 12px;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}
.flags-prose strong { color: var(--accent); font-weight: 600; }

.explain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.explain-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  animation: rise var(--t-fast) both;
}
.explain-item.depth-1 { margin-left: 16px; }
.explain-item.depth-2 { margin-left: 32px; }
.explain-item.depth-3 { margin-left: 48px; }

.tok {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 4px;
  padding: 2px 7px;
  flex: none;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tok.tok-struct { color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); }
.tok-desc { font-size: 12.5px; color: var(--text); line-height: 1.45; }

/* ---------- footer ---------- */
.site-footer {
  text-align: center;
  padding: 18px 16px 26px;
  margin-top: 8px;
}
.footer-link {
  font-size: 12.5px;
  color: var(--text-faint);
  text-decoration: none;
  border-bottom: 1px dashed transparent;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.footer-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(12px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-med), transform var(--t-med);
  z-index: 60;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- animations ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes flash {
  0% { box-shadow: 0 0 0 0 rgba(110, 168, 254, 0.0); }
  35% { box-shadow: 0 0 0 3px rgba(110, 168, 254, 0.35); }
  100% { box-shadow: 0 0 0 0 rgba(110, 168, 254, 0.0); }
}
.preview.just-updated { animation: flash 480ms ease; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .tab-panel { max-height: none; }
}

@media (max-width: 560px) {
  body { font-size: 13.5px; }
  .topbar { gap: 12px; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .btn-label { display: inline; }
  .brand-text h1 { font-size: 18px; }
  .workspace { padding: 12px; gap: 12px; }
  .panel { padding: 12px; }
}

/* scrollbars */
.preview::-webkit-scrollbar, .tab-panel::-webkit-scrollbar,
.examples::-webkit-scrollbar, .sample-input::-webkit-scrollbar { height: 8px; width: 8px; }
.preview::-webkit-scrollbar-thumb, .tab-panel::-webkit-scrollbar-thumb,
.examples::-webkit-scrollbar-thumb, .sample-input::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 999px;
}
.preview::-webkit-scrollbar-thumb:hover, .tab-panel::-webkit-scrollbar-thumb:hover { background: #2a3744; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
