:root {
  --bg-primary: #060913;
  --bg-secondary: #0b0f1e;
  --card-bg: rgba(255, 255, 255, 0.03);
  --card-border: rgba(255, 255, 255, 0.08);
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.15);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;

  --match-highlight: rgba(56, 189, 248, 0.25);
  --match-border: #38bdf8;

  /* 6 Distinct Color-Coded Capture Group Tiers */
  --group-highlight-1: rgba(16, 185, 129, 0.28);
  --group-border-1: #10b981;
  --group-text-1: #34d399;

  --group-highlight-2: rgba(245, 158, 11, 0.28);
  --group-border-2: #f59e0b;
  --group-text-2: #fbbf24;

  --group-highlight-3: rgba(168, 85, 247, 0.28);
  --group-border-3: #a855f7;
  --group-text-3: #c084fc;

  --group-highlight-4: rgba(244, 63, 94, 0.28);
  --group-border-4: #f43f5e;
  --group-text-4: #fb7185;

  --group-highlight-5: rgba(6, 182, 212, 0.28);
  --group-border-5: #06b6d4;
  --group-text-5: #38bdf8;

  --group-highlight-6: rgba(132, 204, 22, 0.28);
  --group-border-6: #84cc16;
  --group-text-6: #a3e635;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family:
    "Outfit",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* Aurora background glow */
.glow-bg {
  position: fixed;
  top: -20%;
  left: -20%;
  width: 140%;
  height: 140%;
  background:
    radial-gradient(
      circle at 20% 20%,
      rgba(56, 189, 248, 0.05) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 80% 80%,
      rgba(99, 102, 241, 0.05) 0%,
      transparent 45%
    );
  z-index: -1;
  pointer-events: none;
}

.app-container {
  max-width: 1500px;
  margin: 0 auto;
  padding: 2rem;
}

.app-header {
  margin-bottom: 2.5rem;
  text-align: center;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.logo .icon {
  font-size: 2.5rem;
}

.logo h1 {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #fff 0%, var(--text-muted) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
  font-weight: 300;
}

/* Main Grid Layout */
.workspace-grid {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 1.5rem;
  align-items: start;
}

.control-column,
.tester-column {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Card Styling */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.card h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Templates Card */
.template-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: #fff;
  transform: translateY(-1px);
}

.btn-small {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.btn-small.active {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

/* Pattern Input Row */
.regex-input-row {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  transition: border-color 0.2s ease;
}

.regex-input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.regex-slash {
  color: var(--text-muted);
  font-family: "Fira Code", monospace;
  font-size: 1.25rem;
  padding: 0 0.25rem;
  user-select: none;
}

#regexInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: "Fira Code", monospace;
  font-size: 1.05rem;
  padding: 0.25rem 0.5rem;
  outline: none;
}

.flag-picker input {
  width: 50px;
  background: transparent;
  border: none;
  color: var(--accent);
  font-family: "Fira Code", monospace;
  font-size: 1.05rem;
  outline: none;
  text-align: center;
}

/* Flag Checkboxes */
.flags-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.flag-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.flag-label input {
  cursor: pointer;
}

.error-banner {
  margin-top: 1rem;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid #ef4444;
  color: #f87171;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
}

/* Explanation Card */
.explanation-content {
  max-height: 250px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.explanation-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.explanation-item .token {
  font-family: "Fira Code", monospace;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
}

.explanation-item .desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.placeholder-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Tester Card */
.tester-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.badge {
  background: var(--accent);
  color: var(--bg-primary);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
}

/* Textarea & Highlight Sync Overlay */
.interactive-textarea-container {
  position: relative;
  width: 100%;
  height: 250px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  overflow: hidden;
}

.code-font {
  font-family: "Fira Code", monospace;
  font-size: 0.95rem;
  line-height: 1.6;
}

.highlights-overlay,
#testStringInput {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 1rem;
  border: none;
  outline: none;
  background: transparent;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
}

.highlights-overlay {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  color: transparent;
  pointer-events: none;
}

#testStringInput {
  position: relative;
  z-index: 2;
  color: var(--text-main);
  caret-color: var(--text-main);
  resize: none;
}

/* Match & Group Highlight Overlay Spans */
.hl-match {
  background-color: var(--match-highlight);
  border-bottom: 2px solid var(--match-border);
  border-radius: 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Group Pill Overlay Spans */
.hl-group-pill {
  border-radius: 4px;
  padding: 1px 2px;
  margin: 0 1px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: all 0.15s ease-in-out;
}

.hl-group-g1,
.hl-group-1 {
  background-color: var(--group-highlight-1);
  box-shadow: 0 0 0 1px var(--group-border-1);
}

.hl-group-g2,
.hl-group-2 {
  background-color: var(--group-highlight-2);
  box-shadow: 0 0 0 1px var(--group-border-2);
}

.hl-group-g3,
.hl-group-3 {
  background-color: var(--group-highlight-3);
  box-shadow: 0 0 0 1px var(--group-border-3);
}

.hl-group-g4 {
  background-color: var(--group-highlight-4);
  box-shadow: 0 0 0 1px var(--group-border-4);
}

.hl-group-g5 {
  background-color: var(--group-highlight-5);
  box-shadow: 0 0 0 1px var(--group-border-5);
}

.hl-group-g6 {
  background-color: var(--group-highlight-6);
  box-shadow: 0 0 0 1px var(--group-border-6);
}

.hl-group-pill.active-pill {
  outline: 2px solid #ffffff;
  box-shadow: 0 0 10px #ffffff;
  filter: brightness(1.3);
  z-index: 20;
}

/* Inspector Header and View Toggles */
.inspector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.inspector-view-toggles {
  display: flex;
  gap: 0.35rem;
}

/* Matches Card Details Table */
.matches-list-container {
  overflow-x: auto;
  max-height: 270px;
}

.matches-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.matches-table th,
.matches-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--card-border);
}

.matches-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.matches-table td {
  color: var(--text-main);
}

.matches-table tr.active-row {
  background: rgba(56, 189, 248, 0.08);
}

.table-placeholder {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 1.5rem !important;
}

/* Color-Coded Pill Overlays in Inspector Table */
.group-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: "Fira Code", monospace;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  margin: 0.15rem 0.25rem 0.15rem 0;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease;
  user-select: none;
  border: 1px solid transparent;
}

.group-pill:hover {
  transform: translateY(-1px);
  filter: brightness(1.25);
}

.group-pill.active-pill {
  box-shadow:
    0 0 0 2px #fff,
    0 0 10px rgba(56, 189, 248, 0.5);
  transform: translateY(-1px);
}

.pill-g1,
.tag-g1 {
  background: var(--group-highlight-1);
  color: var(--group-text-1);
  border-color: var(--group-border-1);
}

.pill-g2,
.tag-g2 {
  background: var(--group-highlight-2);
  color: var(--group-text-2);
  border-color: var(--group-border-2);
}

.pill-g3,
.tag-g3 {
  background: var(--group-highlight-3);
  color: var(--group-text-3);
  border-color: var(--group-border-3);
}

.pill-g4 {
  background: var(--group-highlight-4);
  color: var(--group-text-4);
  border-color: var(--group-border-4);
}

.pill-g5 {
  background: var(--group-highlight-5);
  color: var(--group-text-5);
  border-color: var(--group-border-5);
}

.pill-g6 {
  background: var(--group-highlight-6);
  color: var(--group-text-6);
  border-color: var(--group-border-6);
}

.pill-unmatched {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border-color: rgba(255, 255, 255, 0.15);
  font-style: italic;
}

.group-name-tag {
  color: var(--text-main);
  font-weight: 600;
}

/* Custom Scrollbar */
.explanation-content::-webkit-scrollbar,
.highlights-overlay::-webkit-scrollbar,
#testStringInput::-webkit-scrollbar,
.matches-list-container::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.explanation-content::-webkit-scrollbar-thumb,
.highlights-overlay::-webkit-scrollbar-thumb,
#testStringInput::-webkit-scrollbar-thumb,
.matches-list-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.explanation-content::-webkit-scrollbar-thumb:hover,
.highlights-overlay::-webkit-scrollbar-thumb:hover,
#testStringInput::-webkit-scrollbar-thumb:hover,
.matches-list-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.hidden {
  display: none !important;
}

/* Responsiveness */
@media (max-width: 1000px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-container {
    padding: 1rem;
  }

  .logo h1 {
    font-size: 1.6rem;
  }

  .logo .icon {
    font-size: 2rem;
  }

  .subtitle {
    font-size: 0.95rem;
  }

  .card {
    width: 100%;
    box-sizing: border-box;
    padding: 1rem;
  }

  .regex-input-row {
    flex-wrap: wrap;
  }

  #regexInput {
    min-width: 0;
    width: 100%;
    order: 1;
  }

  .regex-slash {
    order: 2;
  }

  .flag-picker {
    order: 3;
    margin-left: auto;
  }

  .flags-checkboxes {
    gap: 0.6rem;
  }

  .tester-header,
  .inspector-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}

/* =========================================================
   ReDoS Complexity & Catastrophic Backtracking Meter Styles
   ========================================================= */
.redos-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.redos-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.redos-header h2 {
  margin-bottom: 0;
}

.redos-badges {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.badge-complexity {
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: "Fira Code", monospace;
  font-size: 0.82rem;
}

.badge-safe {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid #10b981;
  color: #34d399;
}

.badge-low {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid #3b82f6;
  color: #60a5fa;
}

.badge-moderate {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid #f59e0b;
  color: #fbbf24;
}

.badge-critical {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid #ef4444;
  color: #f87171;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.35);
  animation: pulse-critical 2s infinite ease-in-out;
}

@keyframes pulse-critical {
  0%, 100% {
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.3);
  }
  50% {
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.6);
  }
}

.redos-meter-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.redos-meter-track {
  height: 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.redos-meter-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.fill-safe {
  background: linear-gradient(90deg, #10b981, #34d399);
}

.fill-low {
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

.fill-moderate {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.fill-critical {
  background: linear-gradient(90deg, #ef4444, #f43f5e);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.6);
}

.redos-meter-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  user-select: none;
}

.redos-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.redos-diagnosis {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text-main);
}

.redos-recommendations-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}

.redos-recommendations-box h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.recommendations-list {
  padding-left: 1.25rem;
  font-size: 0.84rem;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  line-height: 1.45;
}

.redos-payload-box {
  background: rgba(239, 68, 68, 0.05);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.payload-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.76rem;
  color: #fca5a5;
  font-weight: 600;
}

.payload-code {
  font-family: "Fira Code", monospace;
  font-size: 0.82rem;
  color: #f87171;
  word-break: break-all;
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 10px;
  border-radius: 6px;
}

/* =========================================================
   Multi-Language Code Generation Card Styles
   ========================================================= */
.codegen-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.codegen-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.codegen-header h2 {
  margin-bottom: 0;
}

.lang-tabs-bar {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 0.5rem;
  overflow-x: auto;
}

.lang-tab {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 5px 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.lang-tab:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #ffffff;
}

.lang-tab.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 0 10px var(--accent-glow);
}

.codegen-snippet-container {
  background: #03050c;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 1rem;
  position: relative;
  overflow: hidden;
}

.codegen-pre {
  margin: 0;
  overflow-x: auto;
}

.codegen-pre code {
  font-family: "Fira Code", monospace;
  font-size: 0.84rem;
  line-height: 1.6;
  color: #e2e8f0;
  white-space: pre;
}

.btn-copied {
  background: #10b981 !important;
  border-color: #10b981 !important;
  color: #ffffff !important;
}

.btn-template-redos {
  border-color: rgba(239, 68, 68, 0.3) !important;
  color: #fca5a5 !important;
}

.btn-template-redos:hover {
  background: rgba(239, 68, 68, 0.15) !important;
  border-color: #ef4444 !important;
}

/* Reusable Regex Snippet Library */
.regex-library-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.library-subtitle {
  color: #94a3b8;
  font-size: 0.85rem;
}

.library-compatibility {
  margin: 0;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.07);
  color: #cbd5e1;
  font-size: 0.88rem;
  line-height: 1.6;
}

.regex-library-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.snippet-language-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.snippet-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.snippet-library-item {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.45);
}

.snippet-library-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.snippet-library-heading h3 {
  margin: 0.25rem 0 0;
  font-size: 1rem;
}

.snippet-category {
  color: #60a5fa;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.snippet-library-item p {
  margin: 0;
  color: #cbd5e1;
  font-size: 0.85rem;
  line-height: 1.5;
}

.snippet-pattern {
  display: block;
  overflow-wrap: anywhere;
  padding: 0.65rem;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.25);
  color: #a7f3d0;
  font-family: "Fira Code", monospace;
  font-size: 0.82rem;
}

.snippet-library-item .codegen-pre {
  max-width: 100%;
  padding: 0.75rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
}

.snippet-library-item .codegen-pre code {
  font-size: 0.78rem;
}

.snippet-engine-note {
  margin-top: auto !important;
  color: #94a3b8 !important;
  font-size: 0.78rem !important;
}

@media (max-width: 600px) {
  .snippet-cards {
    grid-template-columns: 1fr;
  }

  .snippet-library-heading {
    align-items: flex-start;
  }
}
