:root {
  --bg: #fafafa;
  --panel: #fff;
  --border: #d0d0d0;
  --text: #1a1a1a;
  --muted: #666;
  --accent: #2c5aa0;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0e1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
}
:root[data-theme="dark"] #output .line.lc-V .content { color: #6e7681; }
:root[data-theme="dark"] #output .line.lc-W .content { background: rgba(240, 160, 32, 0.10); }
:root[data-theme="dark"] #output .line.lc-E .content { background: rgba(224, 64, 64, 0.14); }
:root[data-theme="dark"] #output .line.lc-F .content { background: rgba(176, 0, 32, 0.20); }
:root[data-theme="dark"] .group { background: #1c2128; }
:root[data-theme="dark"] .kw-chip { background: rgba(255,255,255,0.08); }
:root[data-theme="dark"] .add-group button:hover,
:root[data-theme="dark"] .header-btn:hover,
:root[data-theme="dark"] .presets button:hover:not(:disabled),
:root[data-theme="dark"] .share-banner button:hover { background: #21262d; }
:root[data-theme="dark"] kbd { background: #21262d; color: var(--text); }
:root[data-theme="dark"] .share-banner { background: #2d2a1d; border-bottom-color: #5c4a1a; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 16px; font-weight: 600; }
.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  font-size: 13px;
  background: var(--panel);
}
.mode-toggle button {
  padding: 6px 14px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--text);
}
.mode-toggle button.active {
  background: var(--accent);
  color: #fff;
}
main {
  flex: 1;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
  min-height: 0;
}
.left {
  display: grid;
  grid-template-rows: minmax(160px, auto) 1fr;
  gap: 12px;
  min-height: 0;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.panel h2 {
  margin: 0;
  padding: 8px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.panel-body {
  padding: 10px 12px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.group {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  background: #fcfcfc;
}
.group .swatch {
  width: 14px; height: 14px; border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
  margin-top: 3px;
}
.group .kws {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
}
.kw-chip {
  background: rgba(0,0,0,0.06);
  border-radius: 3px;
  padding: 1px 4px 1px 6px;
  font-family: var(--mono);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.kw-chip button {
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); padding: 0 2px; line-height: 1; font-size: 13px;
}
.kw-chip button:hover { color: #d33; }
.group .remove {
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 18px; line-height: 1; padding: 0 2px;
}
.group .remove:hover { color: #d33; }
.add-group {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.add-group input {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  min-width: 0;
  background: var(--panel);
  color: var(--text);
}
.add-group button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.add-group button:hover { background: #f0f0f0; }
#input {
  width: 100%;
  height: 100%;
  border: 0;
  resize: none;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12px;
  outline: none;
  background: var(--panel);
  color: var(--text);
}
#output {
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}
#output .line {
  display: grid;
  grid-template-columns: 48px 1fr;
  padding: 1px 0;
  align-items: baseline;
}
#output .line .ln {
  text-align: right;
  padding-right: 10px;
  color: var(--muted);
  user-select: none;
  font-variant-numeric: tabular-nums;
}
#output .line.lc { padding-left: 0; }
#output .line.lc .content { border-left: 3px solid transparent; padding-left: 6px; }
#output .line.lc-V .content { border-left-color: #b0b0b0; color: #666; }
#output .line.lc-D .content { border-left-color: #5a9fd4; }
#output .line.lc-I .content { border-left-color: #4caf50; }
#output .line.lc-W .content { border-left-color: #f0a020; background: rgba(240, 160, 32, 0.06); }
#output .line.lc-E .content { border-left-color: #e04040; background: rgba(224, 64, 64, 0.07); }
#output .line.lc-F .content { border-left-color: #b00020; background: rgba(176, 0, 32, 0.10); font-weight: 600; }
#output .line.lc-A .content { border-left-color: #8a4dff; background: rgba(138, 77, 255, 0.07); }
#output .sep { color: var(--muted); text-align: center; padding: 4px 0; user-select: none; }
.placeholder { color: var(--muted); font-family: inherit; font-size: 13px; line-height: 1.6; }
.placeholder small { display: inline-block; margin-top: 6px; font-size: 11px; opacity: 0.8; }
.placeholder kbd {
  font-family: var(--mono);
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11px;
}
:root[data-theme="dark"] .placeholder kbd { background: rgba(255, 255, 255, 0.12); }
mark { padding: 0 1px; border-radius: 2px; color: #000; }

.presets {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
}
.presets select {
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  font: inherit;
  color: var(--text);
}
.presets button {
  padding: 5px 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}
.presets button:hover:not(:disabled) { background: #f0f0f0; }
.presets button:disabled { opacity: 0.5; cursor: not-allowed; }
.presets #presetDelete { padding: 5px 8px; }

.share-banner {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 16px;
  background: #fff8d4;
  border-bottom: 1px solid #e0c060;
  font-size: 13px;
}
.share-banner[hidden] { display: none; }
.share-banner-text { flex: 1; }
.share-banner button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}
.share-banner button:hover { background: #f0f0f0; }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}
.header-btn:hover { background: #f0f0f0; }

.guide-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.guide-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}
.guide-dialog {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(720px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
}
.guide-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.guide-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.guide-close {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}
.guide-close:hover { color: #d33; }
.guide-body {
  padding: 12px 18px 18px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.55;
}
.guide-body section { margin-bottom: 14px; }
.guide-body section:last-child { margin-bottom: 0; }
.guide-body h3 {
  margin: 6px 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.guide-body p { margin: 4px 0; }
.guide-body ul { margin: 4px 0; padding-left: 20px; }
.guide-body li { margin: 2px 0; }
.guide-body code {
  font-family: var(--mono);
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}
.guide-body kbd {
  font-family: var(--mono);
  background: #f3f3f3;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11px;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.08);
}
.guide-levels { list-style: none; padding-left: 0; }
.guide-levels li { display: flex; align-items: center; gap: 8px; }
.guide-levels .lvl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 12px;
  border-left: 3px solid transparent;
}
.guide-levels .lvl-V { border-left-color: #b0b0b0; color: #666; }
.guide-levels .lvl-D { border-left-color: #5a9fd4; }
.guide-levels .lvl-I { border-left-color: #4caf50; }
.guide-levels .lvl-W { border-left-color: #f0a020; background: rgba(240, 160, 32, 0.12); }
.guide-levels .lvl-E { border-left-color: #e04040; background: rgba(224, 64, 64, 0.14); }
.guide-levels .lvl-F { border-left-color: #b00020; background: rgba(176, 0, 32, 0.18); font-weight: 700; }
.guide-levels .lvl-A { border-left-color: #8a4dff; background: rgba(138, 77, 255, 0.14); }

.editor-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.editor-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}
.editor-dialog {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(520px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
}
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.editor-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.editor-close {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}
.editor-close:hover { color: #d33; }
.editor-body {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
}
.editor-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.editor-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.editor-field input,
.editor-field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel);
  color: var(--text);
  outline: none;
}
.editor-field input:focus,
.editor-field textarea:focus {
  border-color: var(--accent);
}
.editor-field textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.5;
}
.editor-hint {
  font-size: 11px;
  color: var(--muted);
}
.editor-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.editor-footer button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}
.editor-footer button:hover:not(:disabled) { background: #f0f0f0; }
.editor-footer button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.editor-footer button.primary:hover:not(:disabled) { background: #234a85; }
.editor-footer button:disabled { opacity: 0.5; cursor: not-allowed; }

.match-count {
  font-size: 11px;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  margin-left: 8px;
  color: var(--muted);
}
.match-count[hidden] { display: none; }
#output mark.mark-current {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
