:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8faff;
  --ink: #152033;
  --muted: #647087;
  --line: #d9e0ec;
  --accent: #2463eb;
  --accent-strong: #1749b3;
  --accent-soft: #edf3ff;
  --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"] {
  color-scheme: dark;
  --bg: #0c111b;
  --surface: #151d2a;
  --surface-2: #101722;
  --ink: #edf1f8;
  --muted: #a5afc0;
  --line: #303b4f;
  --accent: #7fa2f4;
  --accent-strong: #a9c1ff;
  --accent-soft: #1d2d50;
  --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; }
button, select, input { 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); }
.brand-mark { display: block; width: 40px; height: 40px; flex: 0 0 40px; border-radius: 11px; overflow: hidden; box-shadow: 0 7px 20px color-mix(in srgb, var(--accent) 28%, transparent); }
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: contain; }
.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); }
#theme-button::before { width: 16px; height: 16px; border: 2px solid currentColor; border-radius: 50%; content: ""; box-shadow: inset -5px -3px 0 -2px var(--surface), 5px -3px 0 -4px currentColor; }

.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 { flex-wrap: wrap; gap: 8px; }
.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.quiet { color: var(--muted); background: transparent; }
.button.small { min-height: 32px; padding: 5px 10px; font-size: 12px; }
.encode-options { display: flex; width: 100%; padding-top: 10px; align-items: center; gap: 18px; border-top: 1px solid var(--line); }
.encode-options label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; }
.encode-options select { min-height: 34px; padding: 5px 30px 5px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }

.editor-grid, .results-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.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; }
.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); }
.output-card textarea { color: color-mix(in srgb, var(--ink) 92%, 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; }
.safe-output { 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(6, 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: 14px 16px; border-right: 1px solid var(--line); }
.metric-strip article:last-child { border-right: 0; }
.metric-strip span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.metric-strip strong { font-size: 20px; }
.metric-strip .warning-value { color: var(--warning); font-size: 16px; }

.section-heading h2 { margin-top: 3px; font-size: 17px; }
.eyebrow { display: block; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
.badge { padding: 5px 9px; border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 11px; font-weight: 750; white-space: nowrap; }
.table-wrap { max-height: 330px; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; border-bottom: 1px solid var(--line); text-align: left; }
th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: var(--surface-2); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; }
td code, .layer-list pre { color: var(--ink); font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.empty-state { margin: 0; padding: 32px 18px; color: var(--muted); text-align: center; }
.diagnostic-list { min-height: 145px; margin: 0; padding: 14px; list-style: none; }
.diagnostic-list li { display: flex; padding: 10px; gap: 10px; border-bottom: 1px solid var(--line); }
.diagnostic-list li:last-child { border-bottom: 0; }
.diagnostic-list li > span { display: grid; width: 22px; height: 22px; flex: 0 0 22px; place-items: center; border-radius: 50%; color: var(--accent); background: var(--accent-soft); font-weight: 800; }
.diagnostic-list li.warning > span { color: var(--warning); background: var(--warning-soft); }
.diagnostic-list p { display: grid; margin: 0; gap: 3px; }
.diagnostic-list small { color: var(--muted); line-height: 1.45; }
.context-button { display: flex; width: calc(100% - 28px); margin: 0 14px 14px; padding: 12px 14px; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); border-radius: 10px; color: var(--ink); background: var(--accent-soft); text-align: left; }
.context-button span { display: grid; gap: 2px; }
.context-button small { color: var(--muted); }
.context-button b { color: var(--accent); font-size: 18px; }

.layers-card { margin-top: 16px; }
.layer-list { display: grid; padding: 14px; gap: 10px; }
.layer-list article { position: relative; display: grid; padding: 12px; gap: 9px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.layer-list article > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.layer-list article span { color: var(--success); font-size: 11px; font-weight: 750; }
.layer-list pre { max-height: 160px; margin: 0; padding: 11px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; border-radius: 7px; background: var(--surface); }
.layer-list .text-button { justify-self: end; }
.privacy-strip { display: flex; margin-top: 16px; padding: 15px 17px; align-items: center; gap: 12px; border: 1px solid color-mix(in srgb, var(--success) 32%, var(--line)); border-radius: 12px; color: var(--muted); background: var(--success-soft); }
.privacy-strip p { margin: 0; line-height: 1.5; }
.privacy-strip strong { color: var(--ink); }
.privacy-icon { position: relative; display: grid; width: 28px; height: 28px; flex: 0 0 28px; place-items: center; border-radius: 50%; color: white; background: var(--success); }
.privacy-icon::after { width: 9px; height: 5px; border-bottom: 2px solid white; border-left: 2px solid white; content: ""; transform: translateY(-1px) rotate(-45deg); }

.context-dialog { width: min(780px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: var(--surface); box-shadow: 0 25px 80px rgba(0,0,0,.3); }
.context-dialog::backdrop { background: rgba(8, 14, 28, 0.64); backdrop-filter: blur(3px); }
.dialog-shell { display: grid; }
.dialog-heading { padding: 17px 20px; justify-content: space-between; border-bottom: 1px solid var(--line); }
.dialog-heading h2 { margin: 3px 0 0; font-size: 19px; }
.dialog-intro { margin: 0; padding: 15px 20px 0; color: var(--muted); }
.excerpt-options { display: grid; padding: 14px 20px; gap: 9px; }
.excerpt-options label { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.excerpt-options small { margin-left: auto; color: var(--muted); font-weight: 400; }
.preview-label { padding: 0 20px 7px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
#context-preview { width: calc(100% - 40px); min-height: 280px; margin: 0 20px; padding: 14px; resize: vertical; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--surface-2); font: 12px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; }
.sensitive-warning { margin: 14px 20px 0; padding: 12px; border: 1px solid color-mix(in srgb, var(--warning) 45%, var(--line)); border-radius: 10px; color: var(--warning); background: var(--warning-soft); }
.sensitive-warning p { margin: 5px 0 9px; }
.dialog-actions { display: flex; padding: 16px 20px 20px; justify-content: flex-end; gap: 9px; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 30; max-width: min(360px, calc(100% - 36px)); padding: 11px 14px; border-radius: 9px; color: white; background: #172033; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .18s ease, transform .18s ease; }
.toast[data-tone="error"] { background: var(--danger); }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .editor-grid, .results-grid { grid-template-columns: 1fr; }
  .metric-strip { grid-template-columns: repeat(3, 1fr); }
  .metric-strip article:nth-child(3) { border-right: 0; }
  .metric-strip article:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 600px) {
  .app-header { align-items: flex-start; }
  .app-brand small, .local-pill { display: none; }
  .workspace { padding: 12px; }
  .toolbar { align-items: stretch; }
  .mode-switch { width: 100%; }
  .mode-switch button { flex: 1; }
  .action-row { width: 100%; }
  .action-row .button { flex: 1 1 calc(50% - 8px); }
  .encode-options { align-items: flex-start; flex-direction: column; }
  .editor-card textarea { min-height: 240px; }
  .metric-strip { grid-template-columns: repeat(2, 1fr); }
  .metric-strip article { border-bottom: 1px solid var(--line); }
  .metric-strip article:nth-child(2n) { border-right: 0; }
  .metric-strip article:nth-last-child(-n+2) { border-bottom: 0; }
  .card-heading, .section-heading { padding: 12px; }
  th, td { padding: 9px 10px; }
  .excerpt-options label { align-items: flex-start; flex-wrap: wrap; }
  .excerpt-options small { width: 100%; margin-left: 24px; }
  .dialog-actions .button { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
