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

body {
  background: #f3f4f6;
  color: #111827;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
}

.ad-banner-top {
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  padding: 15px;
  text-align: center;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
}

.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 24px;
}

.nav {
  margin-bottom: 24px;
}

.nav a {
  color: #6b7280;
  text-decoration: none;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s;
}

.nav a:hover {
  color: #111827;
}

.header {
  margin-bottom: 28px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #e5f2ff;
  color: #1d4ed8;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.logo-wordmark {
  font-weight: 700;
  letter-spacing: -0.06em;
}

.header h1 {
  font-size: clamp(1.8rem, 3vw, 2.2rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

.subtitle {
  color: #4b5563;
  font-size: 0.95rem;
  max-width: 560px;
}

/* Tool section */
.tool-section {
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  padding: 24px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.05);
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: #374151;
}

/* Pattern row */
.pattern-row {
  display: flex;
  align-items: center;
  gap: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.pattern-row:focus-within {
  border-color: #1d4ed8;
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1);
}

.pattern-row.has-error {
  border-color: #fca5a5;
}

.regex-delim {
  padding: 10px 12px;
  background: #f3f4f6;
  color: #6b7280;
  font-family: monospace;
  font-size: 1rem;
  font-weight: 600;
  flex-shrink: 0;
  border-right: 1px solid #e5e7eb;
  user-select: none;
  line-height: 1.4;
}

.regex-delim.right {
  border-right: none;
  border-left: 1px solid #e5e7eb;
}

#regex-pattern {
  flex: 1;
  padding: 10px 12px;
  border: none;
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  color: #111827;
  background: #fff;
  outline: none;
  min-width: 0;
}

/* Flags */
.flags-wrap {
  display: flex;
  gap: 2px;
  padding: 6px 8px;
  background: #f9fafb;
  border-left: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.flag-label {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 7px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: monospace;
  font-weight: 600;
  color: #6b7280;
  border: 1px solid transparent;
  transition: all 0.15s;
  user-select: none;
}

.flag-label:has(input:checked) {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.flag-label input {
  display: none;
}

/* Pattern error */
.pattern-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  margin-top: 8px;
  font-family: monospace;
}

/* Test string highlight overlay */
.test-string-wrap {
  position: relative;
  margin-bottom: 0;
}

#test-input {
  width: 100%;
  min-height: 160px;
  padding: 12px;
  resize: vertical;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  color: #111827;
  background: transparent;
  position: relative;
  z-index: 1;
  caret-color: #111827;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#test-input:focus {
  outline: none;
  border-color: #1d4ed8;
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1);
}

#test-input::placeholder {
  color: #9ca3af;
}

#test-highlighted {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  color: transparent;
  white-space: pre-wrap;
  word-break: break-all;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

#test-highlighted mark {
  background: rgba(253, 224, 71, 0.65);
  color: transparent;
  border-radius: 2px;
}

/* Results area */
.results-area {
  margin-top: 0;
}

.match-count {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.match-count.has-matches {
  color: #15803d;
}

.match-count.no-matches {
  color: #9ca3af;
}

.match-count.has-error {
  color: #dc2626;
}

/* Match table */
.match-table-wrap {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
}

.match-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.match-table th {
  padding: 8px 12px;
  background: #f9fafb;
  border-bottom: 2px solid #e5e7eb;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

.match-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
  vertical-align: top;
}

.match-table tr:last-child td {
  border-bottom: none;
}

.match-table tr:nth-child(even) {
  background: #fafafa;
}

.match-table code {
  background: #f0f4ff;
  color: #1d4ed8;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.82rem;
  font-family: 'Courier New', monospace;
  word-break: break-all;
}

/* Keyboard tip */
.keyboard-tip {
  font-size: 0.8rem;
  color: #9ca3af;
  margin-top: 10px;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.78rem;
  color: #374151;
  box-shadow: 0 1px 0 #c8ccd0;
  line-height: 1.4;
}

/* FAQ accordion */
.faq {
  margin-top: 40px;
}

.faq-title {
  font-size: 1rem;
  font-weight: 600;
  color: #111827;
  margin-bottom: 14px;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.faq-item {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
}

.faq-question {
  padding: 14px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #111827;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  user-select: none;
}

.faq-question::-webkit-details-marker { display: none; }

.faq-question::after {
  content: '+';
  font-size: 1.1rem;
  color: #9ca3af;
  flex-shrink: 0;
  line-height: 1;
}

details[open] > .faq-question::after {
  content: '−';
}

.faq-answer {
  padding: 12px 16px 14px;
  font-size: 0.875rem;
  color: #4b5563;
  line-height: 1.65;
  border-top: 1px solid #f3f4f6;
}

.faq-answer code {
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.82rem;
  font-family: 'Courier New', monospace;
}

/* Related tools */
.related-tools {
  margin-top: 32px;
}

.related-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.related-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 16px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  text-decoration: none;
  transition: all 0.15s;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.related-card:hover {
  border-color: #93c5fd;
  box-shadow: 0 4px 12px rgba(29, 78, 216, 0.1);
  transform: translateY(-1px);
}

.related-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1d4ed8;
}

.related-desc {
  font-size: 0.82rem;
  color: #6b7280;
}

/* Bottom ad + footer */
.ad-banner-bottom {
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
  padding: 20px;
  text-align: center;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 32px;
}

.footer {
  margin-top: 12px;
  text-align: center;
  font-size: 0.78rem;
  color: #9ca3af;
  padding-bottom: 20px;
}

@media (max-width: 640px) {
  .page { padding: 24px 16px; }
  .header h1 { font-size: 1.6rem; }
  .related-grid { grid-template-columns: 1fr; }
  .flags-wrap { gap: 1px; padding: 4px; }
  .flag-label { padding: 3px 5px; font-size: 0.75rem; }
  .match-table th,
  .match-table td { padding: 6px 8px; font-size: 0.8rem; }
}
