:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8faff;
  --ink: #152033;
  --muted: #647087;
  --line: #d9e0ec;
  --accent: #4f46e5;
  --accent-strong: #3730a3;
  --accent-soft: #eef2ff;
  --success: #16805e;
  --success-soft: #eaf8f2;
  --warning: #a65a00;
  --warning-soft: #fff6e6;
  --danger: #b4233f;
  --shadow: 0 12px 34px rgba(28, 43, 74, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="dark"],
html[data-theme="dark"] body,
html[data-site-theme="dark"],
html[data-site-theme="dark"] body,
html[data-theme="dark"] .app,
html[data-site-theme="dark"] .app,
html[data-theme="dark"] .panel,
html[data-site-theme="dark"] .panel,
html[data-theme="dark"] .workspace,
html[data-site-theme="dark"] .workspace {
  background-color: #0c111b !important;
  color: #e8edf6 !important;
}

html[data-site-theme="dark"],
html[data-theme="dark"],
html.dark {
  color-scheme: dark;
  --bg: #0c111b;
  --surface: #151d2a;
  --surface-2: #101722;
  --ink: #edf1f8;
  --muted: #a5afc0;
  --line: #303b4f;
  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-soft: #1e1b4b;
  --success: #72dbb4;
  --success-soft: #17372d;
  --warning: #f2c16f;
  --warning-soft: #3a2e19;
  --danger: #ff8d9a;
  --shadow: 0 14px 38px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}

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

button {
  cursor: pointer;
}

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

button:focus-visible,
textarea:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 36%, transparent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-header {
  display: flex;
  min-height: 74px;
  padding: 15px clamp(16px, 3vw, 36px);
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
}

.app-brand,
.header-actions,
.card-heading,
.card-heading > div,
.section-heading,
.action-row,
.dialog-heading {
  display: flex;
  align-items: center;
}

.app-brand {
  gap: 12px;
}

.app-brand div {
  display: grid;
  gap: 2px;
}

.app-brand strong {
  font-size: 16px;
}

.app-brand small {
  color: var(--muted);
}

.app-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
}

.header-actions {
  gap: 12px;
}

.local-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--success);
  font-weight: 700;
  font-size: 12px;
}

.local-pill span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 14%, transparent);
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--surface);
}

.workspace {
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 3vw, 34px);
}

.toolbar {
  display: flex;
  padding: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mode-switch {
  display: inline-flex;
  padding: 4px;
  gap: 3px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.mode-switch button {
  min-width: 90px;
  padding: 8px 15px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.mode-switch button.active {
  color: white;
  background: var(--accent);
}

.action-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.select-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 600;
}

.select-label select,
.indent-select-wrap select {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
}

.button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 700;
}

.button:hover:not(:disabled),
.icon-button:hover {
  border-color: var(--accent);
}

.button.primary {
  color: white;
  border-color: var(--accent);
  background: var(--accent);
}

.button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.button.secondary {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  background: var(--accent-soft);
}

.button.quiet {
  color: var(--muted);
  background: transparent;
}

.button.small {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 12px;
}

.editor-grid,
.results-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.results-grid:has(#layers-section[hidden]) {
  grid-template-columns: 1fr;
}

.results-grid:has(#layers-section[hidden]) .diagnostics-card {
  grid-column: 1 / -1;
}

.editor-card,
.result-card,
.layers-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-heading,
.section-heading {
  min-height: 61px;
  padding: 13px 16px;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.card-heading > div {
  gap: 9px;
}

.output-actions-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.copy-pretty-status {
  padding: 8px 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--success) 24%, var(--line));
  color: var(--success);
  background: var(--success-soft);
  font-size: 12px;
  font-weight: 750;
  text-align: right;
}

.card-heading label,
.section-heading h2 {
  margin: 0;
  color: var(--ink);
  font-weight: 750;
}

.step {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border-radius: 7px;
  color: var(--accent);
  background: var(--accent-soft);
  font: 700 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.text-button {
  padding: 5px 0;
  border: 0;
  color: var(--accent);
  background: transparent;
  font-weight: 700;
  font-size: 12px;
}

.editor-card textarea {
  display: block;
  width: 100%;
  min-height: 300px;
  padding: 16px;
  resize: vertical;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: var(--surface-2);
  font: 13px/1.65 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.editor-card textarea:focus {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.editor-status {
  display: flex;
  min-height: 38px;
  padding: 9px 15px;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 11px;
}

.badge-neutral {
  color: var(--muted);
  font-weight: 700;
}

.badge-success {
  color: var(--success);
  font-weight: 700;
}

.error-message {
  margin-top: 12px;
  padding: 11px 14px;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--line));
  border-radius: 10px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 9%, var(--surface));
  font-weight: 700;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.metric-strip article {
  padding: 12px 14px;
  border-right: 1px solid var(--line);
}

.metric-strip article:last-child {
  border-right: 0;
}

.metric-strip span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-strip strong {
  font-size: 16px;
}

.section-heading h2 {
  font-size: 16px;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge {
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.diagnostic-list {
  margin: 0;
  padding: 16px 20px;
  list-style: none;
  display: grid;
  gap: 10px;
}

.diagnostic-list li {
  padding-left: 18px;
  position: relative;
  line-height: 1.5;
}

.diagnostic-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-size: 16px;
}

.warning-text {
  color: var(--warning);
  font-weight: 700;
}

.context-button {
  display: flex;
  width: 100%;
  padding: 14px 18px;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--accent);
  text-align: left;
}

.context-button:hover {
  background: var(--accent-soft);
}

.context-button strong {
  display: block;
  font-size: 14px;
}

.context-button small {
  color: var(--muted);
  font-size: 12px;
}

.layers-card {
  margin-top: 0;
}

.layer-list {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.layer-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.layer-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.layer-meta {
  color: var(--muted);
  font-size: 12px;
}

.layer-preview {
  margin: 0;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-all;
}

.privacy-strip {
  margin-top: 24px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.privacy-strip p {
  margin: 0;
}

.context-dialog {
  padding: 0;
  border: 0;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  background: var(--surface);
  color: var(--ink);
  max-width: 680px;
  width: 90vw;
}

.context-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.dialog-shell {
  padding: 24px;
  display: grid;
  gap: 16px;
}

.dialog-heading {
  justify-content: space-between;
}

.dialog-heading h2 {
  margin: 4px 0 0 0;
  font-size: 18px;
}

.dialog-intro {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.excerpt-options {
  display: grid;
  gap: 8px;
}

.excerpt-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.excerpt-options small {
  color: var(--muted);
  font-weight: normal;
}

.preview-label {
  font-weight: 700;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

#context-preview {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.sensitive-warning {
  padding: 12px;
  border: 1px solid var(--warning);
  border-radius: 10px;
  background: var(--warning-soft);
  color: var(--warning);
}

.sensitive-warning p {
  margin: 4px 0 8px 0;
  font-size: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--surface);
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.dth-guide-highlight {
  outline: 3px solid #6366f1 !important;
  outline-offset: 2px !important;
}

@media (max-width: 900px) {
  .editor-grid,
  .results-grid {
    grid-template-columns: 1fr;
  }
  .metric-strip {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 600px) {
  .metric-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}
