:root {
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e2e8f0;
  background: #06101f;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color-scheme: dark;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: #06101f;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 10% -10%, rgba(34, 211, 238, 0.13), transparent 28rem),
    radial-gradient(circle at 90% 0%, rgba(249, 115, 22, 0.11), transparent 24rem),
    #06101f;
}

button,
select,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 5px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid rgba(96, 165, 250, 0.6);
  outline-offset: 2px;
}

.app-shell {
  width: min(1840px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 12px 0 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #f8fafc;
  letter-spacing: -0.03em;
}

.brand-link {
  color: inherit;
  text-decoration: none;
  transition:
    color 0.18s ease,
    opacity 0.18s ease,
    transform 0.18s ease;
}

.brand-link:hover {
  opacity: 0.86;
}

.brand-link:hover .brand-text {
  color: #bae6fd;
}

.brand-logo {
  display: inline-flex;
}

.brand img {
  display: block;
  width: 34px;
  height: 34px;
  flex: none;
  object-fit: contain;
  border-radius: 8px;
}

.brand-text {
  font-size: 22px;
  line-height: 1;
}

.brand span {
  font-weight: 600;
}

.brand strong {
  color: #7dd3fc;
  font-weight: 900;
}

.top-actions,
.pane-actions,
.quick-actions,
.main-buttons,
.metric-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.control-card,
.pane,
.info-card {
  border: 1px solid rgba(148, 163, 184, 0.17);
  border-radius: 7px;
  background: rgba(15, 23, 42, 0.78);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
}

.control-card {
  display: grid;
  grid-template-columns: minmax(360px, 1.25fr) minmax(340px, 0.95fr);
  align-items: start;
  gap: 10px;
  margin-bottom: 10px;
  padding: 10px;
}

.type-control,
.format-control,
.expression-control,
.flags-control {
  display: grid;
  gap: 5px;
}

.flags-control {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  grid-column: 2;
}

.flags-control > label {
  flex: none;
  padding-top: 7px;
}

label,
.field-label {
  color: #94a3b8;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

select,
.text-field,
#expressionInput {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 5px;
  padding: 8px 9px;
  color: #e2e8f0;
  background: #0b1220;
}

.text-field,
#expressionInput {
  outline: 0;
}

.text-field:focus,
#expressionInput:focus {
  border-color: rgba(125, 211, 252, 0.58);
  box-shadow: 0 0 0 2px rgba(125, 211, 252, 0.1);
}

.primary,
.primary-btn {
  border-color: rgba(14, 165, 233, 0.55);
  color: #07111f;
  background: #7dd3fc;
}

.primary:hover:not(:disabled),
.primary-btn:hover:not(:disabled) {
  background: #bae6fd;
}

.primary.secondary {
  border-color: rgba(45, 212, 191, 0.48);
  background: #5eead4;
}

.ghost,
.ghost-btn,
.tab {
  color: #dbeafe;
  background: rgba(15, 23, 42, 0.72);
}

.ghost:hover:not(:disabled),
.ghost-btn:hover:not(:disabled),
.tab:hover:not(:disabled) {
  border-color: rgba(96, 165, 250, 0.55);
  background: rgba(59, 130, 246, 0.12);
}

.ghost.danger,
.ghost-btn.danger {
  color: #fecaca;
}

.status-row {
  min-height: 34px;
  margin: 0;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 5px;
  padding: 8px 9px;
  color: #cbd5e1;
  background: rgba(2, 6, 23, 0.4);
  font-size: 12px;
  line-height: 1.35;
}

.status-row.ok {
  color: #bbf7d0;
  border-color: rgba(34, 197, 94, 0.25);
  background: rgba(34, 197, 94, 0.09);
}

.status-row.error {
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.25);
  background: rgba(239, 68, 68, 0.09);
}

.status-row.warn {
  color: #fde68a;
  border-color: rgba(234, 179, 8, 0.25);
  background: rgba(234, 179, 8, 0.09);
}

.expression-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
}

.slash {
  color: #64748b;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 900;
}

#expressionInput {
  min-height: 36px;
  max-height: 110px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
}

.expression-row .CodeMirror,
.expression-codemirror {
  height: auto;
  min-height: 52px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 5px;
  background: #0b1220;
  box-shadow: inset 0 0 0 1px rgba(2, 6, 23, 0.18);
  font-size: 16px;
}

.expression-row .CodeMirror-scroll {
  min-height: 52px;
  max-height: 112px;
}

.expression-row .CodeMirror-lines {
  padding: 12px 0;
}

.expression-row .CodeMirror pre.CodeMirror-line,
.expression-row .CodeMirror pre.CodeMirror-line-like {
  padding: 0 9px;
  line-height: 1.35;
}

.expression-row .CodeMirror-focused {
  border-color: rgba(125, 211, 252, 0.58);
  box-shadow: 0 0 0 2px rgba(125, 211, 252, 0.1);
}

.expression-hint {
  min-height: 30px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 5px;
  padding: 7px 9px;
  color: #bfdbfe;
  background: rgba(2, 6, 23, 0.34);
  font-size: 12px;
  line-height: 1.35;
}

.expression-hint strong {
  color: #fde68a;
  font-family: var(--mono);
}

.expression-hint span {
  color: #67e8f9;
  font-weight: 800;
}

.flags {
  display: flex;
  flex-wrap: wrap;
  flex: 1;
  gap: 6px;
}

.expression-control {
  grid-column: 1;
  grid-row: 1 / span 3;
}

.main-buttons,
.status-row {
  grid-column: 2;
}

.flags label {
  display: inline-grid;
  grid-template-columns: auto auto;
  grid-template-areas:
    "check flag"
    "check name";
  align-items: center;
  gap: 1px 5px;
  min-width: 96px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 5px;
  padding: 6px 8px;
  color: #cbd5e1;
  background: rgba(2, 6, 23, 0.3);
  line-height: 1;
  text-transform: none;
  letter-spacing: 0;
}

.flags input {
  grid-area: check;
  accent-color: #7dd3fc;
}

.flags strong {
  grid-area: flag;
  color: #f8fafc;
  font-family: var(--mono);
  font-size: 13px;
}

.flags span {
  grid-area: name;
  color: #94a3b8;
  font-size: 10px;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(310px, 0.9fr);
  gap: 10px;
  align-items: start;
}

.pane {
  min-width: 0;
  overflow: hidden;
}

.pane-header,
.info-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  padding: 10px;
}

.pane-header > div:first-child,
.info-card header > div:first-child {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.pane-header strong,
.info-card strong {
  color: #f8fafc;
  font-size: 15px;
}

.pane-header span,
.info-card header span,
.metric-list span {
  overflow: hidden;
  color: #94a3b8;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-list span {
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 5px;
  padding: 5px 7px;
  background: rgba(2, 6, 23, 0.28);
}

#textInput {
  display: none;
}

.CodeMirror {
  height: 420px;
  background: #0b1220;
  color: #dbeafe;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
}

.CodeMirror-scroll {
  min-height: 420px;
}

.CodeMirror-lines {
  padding: 10px 0;
}

.CodeMirror pre.CodeMirror-line,
.CodeMirror pre.CodeMirror-line-like {
  padding: 0 12px;
}

.CodeMirror-gutters {
  background: #080f1d;
  color: #64748b;
  border-right: 1px solid rgba(148, 163, 184, 0.14);
}

.CodeMirror-linenumber {
  color: #64748b;
}

.CodeMirror-cursor {
  border-left: 2px solid #67e8f9;
}

.CodeMirror-selected,
.CodeMirror-focused .CodeMirror-selected {
  background: rgba(147, 197, 253, 0.34) !important;
}

.cm-regex-escape { color: #67e8f9; font-weight: 800; }
.cm-regex-class { color: #fbbf24; }
.cm-regex-group { color: #c084fc; font-weight: 800; }
.cm-regex-quantifier { color: #fb7185; font-weight: 800; }
.cm-regex-alternation { color: #34d399; font-weight: 800; }
.cm-regex-anchor { color: #60a5fa; font-weight: 800; }
.cm-regex-dot { color: #f472b6; font-weight: 800; }
.cm-regex-literal { color: #dbeafe; }

.regex-token-tooltip {
  position: fixed;
  z-index: 20;
  width: min(320px, calc(100vw - 24px));
  border: 1px solid rgba(125, 211, 252, 0.28);
  border-radius: 7px;
  padding: 9px 10px;
  color: #dbeafe;
  background: rgba(2, 6, 23, 0.96);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.36);
  pointer-events: none;
}

.regex-token-tooltip strong {
  display: inline-block;
  margin-right: 8px;
  color: #fde68a;
  font-family: var(--mono);
}

.regex-token-tooltip span {
  color: #67e8f9;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.regex-token-tooltip p {
  margin: 7px 0 0;
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.4;
}

.cm-match {
  border-radius: 3px;
  background: rgba(125, 211, 252, 0.22);
  border-bottom: 1px solid rgba(125, 211, 252, 0.8);
}

.cm-match-active {
  background: rgba(45, 212, 191, 0.26);
  border-bottom-color: rgba(45, 212, 191, 0.95);
}

.cm-zero-match {
  border-left: 2px solid #fde68a;
  margin-left: -1px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  padding: 10px;
}

.tab {
  border-radius: 5px;
  padding: 8px 10px;
}

.tab.active {
  border-color: rgba(14, 165, 233, 0.55);
  color: #07111f;
  background: #7dd3fc;
}

.tab-panel {
  display: none;
  min-height: 420px;
  max-height: 560px;
  overflow: auto;
  padding: 10px;
}

.tab-panel.active {
  display: block;
}

.matches-list,
.explain-list {
  display: grid;
  gap: 8px;
}

.match-card,
.token-card,
.empty-state,
.ref-section,
.ref-item,
.output-box {
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 5px;
  background: rgba(2, 6, 23, 0.28);
}

.match-card,
.token-card,
.empty-state,
.ref-item {
  padding: 9px;
}

.match-card {
  cursor: pointer;
}

.match-card:hover {
  border-color: rgba(96, 165, 250, 0.42);
  background: rgba(59, 130, 246, 0.08);
}

.card-title,
.ref-item-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  color: #94a3b8;
  font-size: 12px;
}

.card-title strong,
.ref-item-title span:first-child {
  color: #f8fafc;
}

.mono,
code {
  color: #e0f2fe;
  font-family: var(--mono);
  overflow-wrap: anywhere;
}

.badge,
.ref-token {
  display: inline-flex;
  border: 1px solid rgba(14, 165, 233, 0.22);
  border-radius: 999px;
  padding: 3px 7px;
  color: #bae6fd;
  background: rgba(14, 165, 233, 0.09);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 800;
}

.group-list {
  display: grid;
  gap: 5px;
  margin-top: 8px;
  color: #cbd5e1;
  font-size: 12px;
}

.group-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
}

.group-row span:first-child {
  color: #94a3b8;
}

.field-label {
  display: block;
  margin: 12px 0 7px;
}

.output-box {
  min-height: 96px;
  max-height: 360px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  color: #cbd5e1;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
}

.export-note,
.empty-note,
.compact-help p {
  margin: 0;
  padding: 12px;
  color: #94a3b8;
  font-size: 13px;
  line-height: 1.5;
}

.export-note {
  margin: -2px 0 10px;
  padding: 0;
}

.reference-pane {
  max-height: 620px;
  overflow: auto;
}

.reference-toolbar {
  padding: 10px 10px 0;
}

.search {
  width: 100%;
}

.reference-tree {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.ref-section {
  overflow: hidden;
}

.ref-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  border-radius: 0;
  padding: 9px;
  color: #f8fafc;
  background: transparent;
  text-align: left;
}

.ref-body {
  display: none;
  gap: 8px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
  padding: 9px;
}

.ref-section.open .ref-body {
  display: grid;
}

.ref-item {
  display: grid;
  gap: 5px;
}

.ref-item-title {
  margin: 0;
}

.ref-desc {
  color: #94a3b8;
  font-size: 12px;
  line-height: 1.45;
}

.ref-desc code {
  color: #e0f2fe;
}

.insert-token {
  justify-self: start;
  border-color: rgba(45, 212, 191, 0.38);
  color: #07111f;
  background: #5eead4;
}

.details-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.info-card {
  min-width: 0;
  overflow: hidden;
}

.hidden-input {
  display: none;
}

@media (max-width: 1180px) {
  .control-card {
    grid-template-columns: 1fr;
  }

  .main-buttons,
  .status-row {
    grid-column: 1 / -1;
  }

  .expression-control,
  .flags-control {
    grid-column: 1;
    grid-row: auto;
  }

  .workspace,
  .details-grid {
    grid-template-columns: 1fr;
  }

  .reference-pane {
    max-height: none;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100vw - 14px, 1840px);
  }

  .topbar,
  .pane-header,
  .info-card header {
    align-items: flex-start;
    flex-direction: column;
  }

  .flags-control {
    display: grid;
  }

  .flags-control > label {
    padding-top: 0;
  }

  .brand span,
  .brand strong {
    font-size: 19px;
  }

  .expression-row {
    grid-template-columns: 1fr;
  }

  .slash {
    display: none;
  }
}
