:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --panel-alt: #1f2430;
  --border: #2a3140;
  --border-arrow: #3a4150;
  --text: #e6e9ef;
  --muted: #9aa4b2;
  --accent: #7aa2ff;
  --accent-soft: rgba(122, 162, 255, 0.18);
  --success: #6ee7b7;
  --warning: #fca5a5;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
  --sans: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
figure,
dl,
dd,
ul,
ol,
pre {
  margin: 0;
}

ul,
ol {
  padding: 0;
}

img,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  background: radial-gradient(circle at top, #1a1f2b 0%, var(--bg) 45%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

html {
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  color: var(--accent);
}

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px 48px;
  min-height: 100vh;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

#app .app-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.brand {
  display: flex;
  flex-direction: column;
}

.brand h1 {
  font-size: 48px;
  letter-spacing: -0.02em;
  font-weight: 700;
  font-family: 'Playfair Display', 'Georgia', serif;
  background: linear-gradient(120deg, #9b8cff 0%, #7aa2ff 35%, #6ee7b7 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 12px 30px rgba(122, 162, 255, 0.25);
  line-height: 1.1;
  padding-bottom: 4px;
}

.brand p {
  color: var(--muted);
  font-size: 15px;
}

.muted {
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.button {
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: border 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.button-subtle {
  padding: 8px 12px;
  font-size: 12px;
}

.button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.button-warning {
  border-color: rgba(252, 165, 165, 0.6);
  color: #fca5a5;
}

.button-warning:hover {
  border-color: #fca5a5;
  color: #fca5a5;
}

.button-github {
  border-color: rgba(167, 139, 250, 0.6);
  background: rgba(139, 92, 246, 0.2);
  color: #c4b5fd;
}

.button-github:hover {
  border-color: #a78bfa;
  color: #ede9fe;
}

.button.button-confirm {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.button-warning.button-confirm {
  background: #fca5a5;
  border-color: #fca5a5;
  color: var(--bg);
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  grid-template-rows: auto 1fr;
  gap: 24px;
  flex: 1;
  align-content: stretch;
  min-height: 0;
}

.panel-wide {
  grid-column: 1 / -1;
}

.panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.panel-scroll {
  min-height: 0;
  height: 100%;
}

.panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.panel h2 {
  font-size: 18px;
  margin-bottom: 16px;
  font-weight: 600;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header-compact {
  margin-bottom: 10px;
}

.panel-actions {
  display: flex;
  gap: 10px;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.field label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  border-radius: 999px;
  background: rgba(122, 162, 255, 0.2);
  border: 1px solid rgba(122, 162, 255, 0.5);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  vertical-align: middle;
}

input[type='text'],
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  outline: none;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

input[type='text']:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  min-height: 190px;
  resize: none;
  margin-top: -8px;
}

.inline-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 90px;
  gap: 12px;
  align-items: end;
}

.field-separator {
  padding-bottom: 10px;
  font-family: var(--mono);
  font-size: 16px;
  color: var(--muted);
}

.notice {
  background: rgba(252, 165, 165, 0.1);
  border: 1px solid rgba(252, 165, 165, 0.4);
  color: var(--warning);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  margin-bottom: 16px;
}

.section {
  margin-top: 24px;
}

.match-output {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  min-height: calc(1.5 * 1em + 26px);
  overflow-y: hidden;
}

.match-output-scroll {
  white-space: pre;
  overflow-x: auto;
}

.match-output-wrap {
  white-space: pre-wrap;
  word-break: break-word;
}

.match-output .match {
  background: rgba(110, 231, 183, 0.2);
  border-bottom: 1px solid rgba(110, 231, 183, 0.6);
  position: relative;
  border-radius: 3px;
}

.match-output .match:hover {
  background: rgba(110, 231, 183, 0.35);
}

.groups {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flags-group {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
}

.group-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--panel-alt);
}

.group-card h4 {
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--muted);
}

.group-card ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
  font-family: var(--mono);
  font-size: 13px;
}

.group-index {
  color: #6b7382;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
}

.reference-card {
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  font-family: var(--mono);
  font-size: 12px;
  transition: background 0.2s ease, border 0.2s ease;
  cursor: help;
}

.reference-card:hover {
  background: rgba(122, 162, 255, 0.16);
  border-color: rgba(122, 162, 255, 0.4);
}

.reference-card span {
  color: var(--muted);
  display: block;
  margin-top: 4px;
  font-family: var(--sans);
  font-size: 11px;
}

.regex-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.regex-token {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(122, 162, 255, 0.12);
  border: 1px solid rgba(122, 162, 255, 0.35);
  font-family: var(--mono);
  font-size: 13px;
  cursor: help;
  transition: background 0.2s ease, border 0.2s ease;
  min-height: 32px;
  display: inline-block;
  align-items: center;
  white-space: pre;
}

.regex-token:hover {
  background: rgba(122, 162, 255, 0.3);
  border-color: rgba(122, 162, 255, 0.65);
}

.regex-token-invalid {
  background: rgba(252, 165, 165, 0.18);
  border-color: rgba(252, 165, 165, 0.6);
  color: #fca5a5;
}

.regex-token-invalid:hover {
  background: rgba(252, 165, 165, 0.26);
  border-color: rgba(252, 165, 165, 0.8);
}

.tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 5;
  margin-top: 8px;
  width: max-content;
  max-width: 320px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}


.tooltip strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--accent);
}

.tooltip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.tooltip-token {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  background: var(--panel-alt);
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.tooltip-detail {
  display: block;
  margin-bottom: 8px;
  padding: 4px 0 6px;
  color: var(--text);
}

.tooltip-simple .tooltip-detail {
  margin-bottom: 0;
  padding: 2px 0 4px;
}

.tooltip-inline-code {
  display: inline-flex;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(15, 17, 21, 0.6);
  border: 1px solid rgba(122, 162, 255, 0.4);
  font-family: var(--mono);
  margin: 0 2px;
}

.tooltip-snippet {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 10px;
}

.tooltip-snippet-label {
  font-size: 11px;
  color: var(--muted);
}

.tooltip-example {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  padding: 0;
  border-radius: 8px;
  background: rgba(122, 162, 255, 0.12);
  border: 1px solid rgba(122, 162, 255, 0.3);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text);
}

.tooltip-example-title {
  font-size: 11px;
  color: var(--text);
  background: rgba(15, 17, 21, 0.6);
  border-bottom: 1px solid rgba(122, 162, 255, 0.35);
  padding: 6px 8px;
  border-radius: 8px 8px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
}

.tooltip-example-lines {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tooltip-example-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.tooltip-example-code {
  display: inline-flex;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(15, 17, 21, 0.6);
  border: 1px solid rgba(122, 162, 255, 0.4);
  font-family: var(--mono);
}

.tooltip-example-text {
  color: var(--text);
}

.tooltip-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.reference-card {
  width: 100%;
}

.match-output .tooltip {
  white-space: nowrap;
}

@media (hover: hover) {
  .tooltip-anchor:hover .tooltip {
    opacity: 1;
    transform: translateY(0);
  }
}

.tooltip-anchor.tooltip-touch-active .tooltip {
  opacity: 1;
  transform: translateY(0);
}

.footer {
  margin-top: 32px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
  }

  body,
  html {
    overflow-y: auto;
  }

  #app {
    min-height: auto;
    height: auto;
    padding: 16px 12px 32px;
  }

  #app .app-inner {
    height: auto;
    padding-bottom: 0;
  }

  .header {
    gap: 12px;
  }

  .brand h1 {
    font-size: 36px;
  }

  .brand p {
    font-size: 13px;
  }

  .header-actions {
    width: 100%;
    justify-content: right;
  }

  .panel {
    padding: 16px;
    border-radius: 14px;
  }

  .layout {
    gap: 16px;
  }

  .inline-fields {
    grid-template-columns: minmax(0, 1fr) auto 70px;
    gap: 8px;
  }

  textarea {
    min-height: 120px;
  }

  .reference-grid {
    grid-template-columns: repeat(auto-fit, minmax(85px, 1fr));
    gap: 8px;
  }

  .reference-card {
    padding: 6px 8px;
    font-size: 11px;
  }

  .footer {
    margin-top: 20px;
  }
}
