:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.85);
  --bg-card-hover: rgba(31, 41, 55, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.6);
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: rgba(99, 102, 241, 0.15);
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.95);
  --bg-card-hover: rgba(241, 245, 249, 0.9);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-focus: rgba(99, 102, 241, 0.5);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-light: rgba(79, 70, 229, 0.08);
  --success: #059669;
  --success-bg: rgba(5, 150, 105, 0.1);
  --warning: #d97706;
  --warning-bg: rgba(217, 119, 6, 0.1);
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.1);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.app-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  width: 100%;
  flex: 1;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #6366f1, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  text-decoration: none;
}
.btn-icon:hover {
  color: var(--text-primary);
  border-color: var(--border-focus);
  background: var(--bg-card-hover);
}

/* Language picker — same chrome as .btn-icon, but sized to its content and kept a
   native <select> so it stays keyboard- and screen-reader-friendly. */
.lang-select {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  height: 38px;
  padding: 0 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
.lang-select:hover {
  color: var(--text-primary);
  border-color: var(--border-focus);
  background: var(--bg-card-hover);
}
.lang-select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* Privacy Banner */
.privacy-banner {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--success);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.privacy-text {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: var(--text-secondary);
}
.privacy-text strong {
  color: var(--text-primary);
}

.engine-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}
.engine-status-badge.server-mode {
  background: var(--accent-light);
  color: var(--accent);
  border-color: rgba(99, 102, 241, 0.25);
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* Navigation Tabs */
.tabs-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--bg-card);
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  width: fit-content;
}

.tab-btn {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
}
.tab-btn.active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}
.tab-btn:hover:not(.active) {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

/* Tab Content Cards */
.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
  animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.main-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px);
  margin-bottom: 32px;
}

/* Text Mode Layout */
.text-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
@media (max-width: 768px) {
  .text-grid { grid-template-columns: 1fr; }
}

.text-box-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.textarea-wrapper {
  position: relative;
  flex: 1;
  min-height: 280px;
  display: flex;
  flex-direction: column;
}

textarea {
  width: 100%;
  height: 100%;
  min-height: 280px;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.output-preview {
  width: 100%;
  height: 100%;
  min-height: 280px;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Options Panel */
.options-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  margin-bottom: 20px;
}

.options-group {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.checkbox-label:hover {
  color: var(--text-primary);
}
.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Inspection Report Badge */
.report-box {
  margin-top: 16px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  display: none;
}
.report-box.show {
  display: block;
  animation: fadeIn 0.2s ease;
}
.report-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tag-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font-mono);
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.25);
}
.tag-badge.clean {
  background: var(--success-bg);
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.25);
}

/* Actions */
.actions-bar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  text-decoration: none;
}
.btn-primary {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-secondary {
  background: var(--bg-card-hover);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}
.btn-secondary:hover {
  border-color: var(--border-focus);
}

/* File Dropzone */
.dropzone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-secondary);
  transition: all 0.2s ease;
  margin-bottom: 20px;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.dropzone-icon {
  font-size: 48px;
  margin-bottom: 12px;
  color: var(--accent);
}
.dropzone-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}
.dropzone-desc {
  font-size: 13px;
  color: var(--text-muted);
}

/* File Items List */
.file-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  gap: 16px;
  flex-wrap: wrap;
}
.file-info {
  display: flex;
  align-items: center;
  gap: 14px;
}
.file-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}
.file-name {
  font-size: 14px;
  font-weight: 600;
}
.file-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Footer */
footer {
  text-align: center;
  padding: 32px 20px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}
footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
footer a:hover {
  text-decoration: underline;
}
.footer-links {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* Accessibility & focus */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone:focus-visible { border-color: var(--accent); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Settings panel */
.settings-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
@media (max-width: 720px) { .settings-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.field input[type="text"], .field input[type="password"], .field input[type="url"] {
  font: inherit; font-size: 13px; padding: 8px 10px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-color);
  background: var(--bg-secondary); color: var(--text-primary);
}
.field input:focus { border-color: var(--border-focus); outline: none; }
.settings-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.settings-note { font-size: 12px; color: var(--text-muted); margin-top: 10px; line-height: 1.5; }
.settings-note code { font-family: var(--font-mono); font-size: 11.5px; }
.engine-select { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; }
.engine-select label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.file-card.error { border-color: var(--danger); }
.file-card.error .file-icon { background: var(--danger-bg); color: var(--danger); }
.file-card .file-meta.error { color: var(--danger); }
.file-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.file-findings { font-size: 12px; color: var(--text-secondary); margin-top: 6px; line-height: 1.5; }
.tag-badge.warn { background: var(--warning-bg); color: var(--warning); border-color: var(--warning); }
.mode-note { font-size: 12px; color: var(--text-muted); margin-top: 10px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---- optional AI rewrite panel ---- */
.rewrite-box { display: block; }          /* not gated on .show; JS toggles [hidden] */
.output-preview.compact { min-height: 160px; }
/* The rewrite output sits under the two-column grid, so it must not inherit the
   280px min-height those side-by-side boxes need — that left a dead gap between
   the output and the copy button. */
.rewrite-box .textarea-wrapper { min-height: 0; flex: none; }
.rewrite-box .output-preview.compact { height: auto; }
.rewrite-prompt summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}
.rewrite-prompt textarea {
  min-height: 96px;
  height: auto;
  margin-top: 8px;
  font-size: 12.5px;
}
.rewrite-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.rewrite-controls label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.rewrite-controls input {
  flex: 1 1 180px;
  min-width: 140px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.rewrite-hint { color: var(--text-secondary); }

.mt-20 { margin-top: 20px; }
.mt-14 { margin-top: 14px; }
.engine-select { margin-top: 12px; }
.footnote { margin-top: 8px; font-size: 11.5px; }


/* [hidden] has to beat the display rules on .btn / .checkbox-label / .rewrite-box:
   the UA sheet's display:none loses to any class that sets display, which left
   JS-hidden controls (Cancel, the detection-key selector) visible while idle. */
[hidden] { display: none !important; }

/* ---- Watermark Inspector ---- */
.inspect-intro { font-size: 13px; color: var(--text-secondary); line-height: 1.55; margin-bottom: 14px; }
.inspect-input { min-height: 0; }
.inspect-input .textarea-wrapper { min-height: 0; }
.inspect-input textarea { min-height: 160px; height: auto; }
.inspect-key select, .rewrite-controls select, .rewrite-controls input[type="number"] {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.rewrite-controls input[type="number"] { flex: 0 0 90px; min-width: 70px; }
.rewrite-controls input[type="text"] { flex: 1 1 260px; }
.inspect-results { margin-top: 18px; }
.inspect-layer + .inspect-layer { margin-top: 18px; }
.inspect-layer h3 { font-size: 13px; font-weight: 700; margin-bottom: 8px; color: var(--text-primary); }
.inspect-table-wrap { overflow-x: auto; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-secondary); }
.inspect-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.inspect-table th, .inspect-table td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border-color); }
.inspect-table th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.inspect-table tbody tr:last-child td { border-bottom: 0; }
.inspect-table tr.row-detected td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.inspect-table tr.row-uncertain td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.inspect-table tr.row-clean td:first-child { box-shadow: inset 3px 0 0 var(--success); }
.inspect-name { min-width: 180px; font-weight: 600; }
.inspect-flags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.flag { font-size: 10px; font-weight: 500; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--border-color); color: var(--text-muted); font-family: var(--font-mono); }
.flag-heuristic { color: var(--warning); border-color: rgba(245, 158, 11, 0.4); }
.inspect-score { font-family: var(--font-mono); font-size: 12px; color: var(--text-secondary); white-space: nowrap; margin-top: 4px; }
td.inspect-score { margin-top: 0; }
.tag-badge.status-clean { background: var(--success-bg); color: var(--success); border-color: rgba(16, 185, 129, 0.25); }
.tag-badge.status-detected { background: var(--danger-bg); color: var(--danger); border-color: rgba(239, 68, 68, 0.3); }
.tag-badge.status-uncertain { background: var(--warning-bg); color: var(--warning); border-color: rgba(245, 158, 11, 0.3); }
.tag-badge.status-unavailable, .tag-badge.status-not_tested, .tag-badge.status-not_applicable {
  background: transparent; color: var(--text-muted); border-color: var(--border-color);
}
.tag-badge.status-error { background: var(--danger-bg); color: var(--danger); border-style: dashed; }
.inspect-evidence { color: var(--text-secondary); max-width: 520px; }
.inspect-evidence details summary { cursor: pointer; font-size: 12px; color: var(--accent); }
.inspect-evidence ul { margin: 6px 0 0 16px; padding: 0; font-size: 12px; line-height: 1.5; }
.inspect-evidence code { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-primary); }
.inspect-offsets { color: var(--text-muted); font-family: var(--font-mono); font-size: 11px; }
.inspect-note { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; line-height: 1.45; }
.inspect-delta { font-weight: 600; white-space: nowrap; }
.inspect-delta.same { color: var(--text-muted); }
.inspect-delta.changed { color: var(--warning); }
.inspect-overall-lines p { font-size: 13px; line-height: 1.55; margin: 0; }
.inspect-overall-lines p + p { margin-top: 4px; }
#inspect-overall { margin-top: 16px; }
#stat-demo-box { margin-top: 18px; }

/* Keyed-Gumbel key entry. A <details> because the key is an advanced control
   that most visitors never have, but it stays available on the hosted page:
   unlike the sidecar detectors, this one needs no local service. */
.gumbel-panel {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  padding: 10px 14px;
}
.gumbel-panel summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}
.gumbel-panel .footnote { margin-bottom: 0; }
.gumbel-panel input[type="password"] { flex: 1 1 220px; }
.gumbel-panel input[type="text"] { flex: 0 0 110px; min-width: 90px; }
