:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-muted: #f9f9f7;
  --surface-hover: #f1f2ee;
  --border: #dfe2dc;
  --border-strong: #c6cbc2;
  --text: #14171a;
  --text-secondary: #4d5562;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-tint: #eef3ff;
  --primary-text: #1e40af;
  --success: #047857;
  --success-tint: #ecfdf5;
  --warn-tint: #fffbeb;
  --warn-border: #f5d061;
  --warn-text: #854d0e;
  --radius-panel: 12px;
  --radius-control: 8px;
  --focus-ring: 0 0 0 3px rgba(29, 78, 216, 0.22);
}

[data-theme="dark"] {
  --bg: #0c1016;
  --surface: #131922;
  --surface-muted: #19212d;
  --surface-hover: #212b3a;
  --border: #273142;
  --border-strong: #39465d;
  --text: #edf2f7;
  --text-secondary: #9aa7b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-tint: rgba(59, 130, 246, 0.16);
  --primary-text: #93c5fd;
  --success: #34d399;
  --success-tint: rgba(16, 185, 129, 0.14);
  --warn-tint: rgba(245, 158, 11, 0.14);
  --warn-border: rgba(245, 158, 11, 0.36);
  --warn-text: #fcd34d;
  --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

* {
  box-sizing: border-box;
}

::selection {
  background: var(--primary-tint);
  color: var(--primary-text);
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  text-wrap: balance;
}

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

.tabular {
  font-variant-numeric: tabular-nums;
}

.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.page {
  max-width: 1340px;
  margin: 0 auto;
  padding: 20px 20px 44px;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.03em;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-copy h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.archive-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}

.icon-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.icon-btn:focus-visible,
.btn:focus-visible,
.swap-btn:focus-visible,
.preset-chip:focus-visible,
.char-btn:focus-visible,
.select-input:focus-visible,
.inline-select select:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: var(--primary);
}

/* Panels (Border-only elevation, no ghost shadows) */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
}

.controls-panel {
  padding: 16px 18px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.selectors-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 12px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field-label-row label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
}

.badge-accent {
  background: var(--primary-tint);
  color: var(--primary-text);
}

.badge-neutral {
  background: var(--surface-muted);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.select-input,
.inline-select select {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  font-size: 0.93rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}

.select-input:hover,
.inline-select select:hover {
  border-color: var(--border-strong);
}

.swap-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.swap-btn:hover {
  background: var(--primary-tint);
  border-color: var(--primary);
  color: var(--primary-text);
}

.presets-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.preset-chip {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 150ms ease;
}

.preset-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--surface-hover);
}

.preset-chip.active {
  border-color: var(--primary);
  background: var(--primary-tint);
  color: var(--primary-text);
}

.options-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.86rem;
}

.options-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  color: var(--text);
}

.checkbox-field input {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
}

.inline-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
}

.inline-select select {
  width: auto;
  padding: 5px 10px;
  font-size: 0.84rem;
}

.supported-formats {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 0.81rem;
}

.supported-formats code {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 6px;
  color: var(--text);
  font-size: 0.78rem;
}

/* Progress */
.progress-panel {
  padding: 11px 15px;
  margin-bottom: 14px;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.84rem;
  font-weight: 600;
  margin-bottom: 7px;
}

.progress-track {
  height: 7px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 120ms linear;
}

/* Dual Editor */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}

.editor-grid.drag-over .editor-pane:first-child {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.editor-pane {
  display: flex;
  flex-direction: column;
  min-height: 440px;
  overflow: hidden;
}

.pane-head {
  padding: 11px 14px;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pane-heading h2 {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 700;
}

.meta-line {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.pane-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary {
  background: var(--primary-tint);
  border-color: transparent;
  color: var(--primary-text);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-tint);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-sm {
  padding: 4px 9px;
  font-size: 0.78rem;
}

.banner {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.84rem;
}

.banner-info {
  background: var(--primary-tint);
  color: var(--text);
}

.banner-warn {
  background: var(--warn-tint);
  border-bottom-color: var(--warn-border);
  color: var(--warn-text);
  font-weight: 500;
}

.banner-body {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.banner-body strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.route-tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--primary-text);
  border: 1px solid var(--border);
}

.editor-area {
  flex: 1;
  width: 100%;
  min-height: 330px;
  border: none;
  resize: vertical;
  padding: 14px 16px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.62;
  caret-color: var(--primary);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  outline: none;
}

.editor-area::placeholder {
  color: var(--text-secondary);
  opacity: 0.92;
}

.pane-foot {
  padding: 9px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
  min-height: 44px;
  display: flex;
  align-items: center;
}

.char-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.char-bar-label {
  font-size: 0.79rem;
  color: var(--text-secondary);
  margin-right: 3px;
}

.char-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.char-btn:hover {
  border-color: var(--primary);
  background: var(--primary-tint);
  color: var(--primary-text);
}

.status-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* Guide Section */
.guide-panel {
  padding: 18px 20px;
}

.guide-head h2 {
  margin: 0 0 6px;
  font-size: 1.06rem;
  font-weight: 700;
}

.guide-lead {
  margin: 0 0 14px;
  color: var(--text-secondary);
  font-size: 0.92rem;
  max-width: 60ch;
}

.diff-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.diff-item {
  padding: 12px 14px;
  border-right: 1px solid var(--border);
}

.diff-item:last-child {
  border-right: none;
}

.diff-item:first-child {
  padding-left: 2px;
}

.diff-letters {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 1.04rem;
  margin-bottom: 3px;
}

.diff-letters .arrow {
  color: var(--text-secondary);
}

.diff-letters strong {
  color: var(--primary-text);
}

.diff-example {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.alpha-details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--primary-text);
  padding: 4px 0;
}

.table-scroll {
  overflow-x: auto;
  margin-top: 12px;
}

.alpha-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.alpha-table th,
.alpha-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.alpha-table th {
  background: var(--surface-muted);
  font-weight: 700;
  color: var(--text-secondary);
}

.alpha-table tr.changed-row {
  background: var(--primary-tint);
}

.rules-notes {
  margin: 12px 0 0;
  padding-left: 18px;
  font-size: 0.86rem;
  color: var(--text-secondary);
  max-width: 75ch;
}

.rules-notes li + li {
  margin-top: 4px;
}

.hidden {
  display: none !important;
}

@media (max-width: 960px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .editor-grid {
    grid-template-columns: 1fr;
  }
  .diff-strip {
    grid-template-columns: repeat(2, 1fr);
  }
  .diff-item {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 11px 4px;
  }
  .diff-item:nth-child(odd) {
    padding-right: 12px;
    border-right: 1px solid var(--border);
  }
  .diff-item:nth-child(even) {
    padding-left: 12px;
  }
  .diff-item:nth-last-child(-n+2) {
    border-bottom: none;
  }
}

@media (max-width: 640px) {
  .page {
    padding: 14px 12px 32px;
  }
  .selectors-row {
    grid-template-columns: 1fr;
  }
  .swap-btn {
    width: 100%;
    height: 36px;
  }
  .diff-strip {
    grid-template-columns: 1fr;
  }
  .diff-item,
  .diff-item:nth-child(odd),
  .diff-item:nth-child(even) {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 2px;
  }
  .diff-item:last-child {
    border-bottom: none;
  }
  .supported-formats {
    display: none;
  }
}
