: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; }

/* Header */
.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, .section-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; }
.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 */
.workspace {
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 2.5vw, 28px);
  display: grid;
  gap: 16px;
}

/* Buttons */
.button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 700;
  transition: all 0.15s ease;
}
.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; }
.text-link-button {
  padding: 0;
  border: 0;
  color: var(--accent);
  background: transparent;
  font-weight: 700;
  text-decoration: underline;
}

/* Drop Zone & Input */
.input-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(20px, 3vw, 32px) 20px;
  gap: 12px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  margin: 10px;
  background: var(--surface-2);
  text-align: center;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
.drop-zone.dragover, .drop-zone:focus {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: 0;
}
.drop-icon { font-size: 42px; line-height: 1; }
.drop-content h3 { margin: 0 0 6px 0; font-size: 16px; font-weight: 750; }
.drop-content p { margin: 0; color: var(--muted); font-size: 13px; }
.input-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 6px; }

/* Error Message */
.error-message {
  padding: 12px 16px;
  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;
}

/* Preview Section */
.preview-section {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
.preview-section.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.section-heading {
  min-height: 56px;
  padding: 12px 18px;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.heading-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.section-heading h2 { margin: 2px 0 0 0; font-size: 17px; font-weight: 750; }

.preview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}
.preview-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  max-height: 260px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  /* Checkerboard pattern for transparent images */
  background-color: var(--surface-2);
  background-image: linear-gradient(45deg, rgba(128,128,128,0.1) 25%, transparent 25%),
                    linear-gradient(-45deg, rgba(128,128,128,0.1) 25%, transparent 25%),
                    linear-gradient(45deg, transparent 75%, rgba(128,128,128,0.1) 75%),
                    linear-gradient(-45deg, transparent 75%, rgba(128,128,128,0.1) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  overflow: hidden;
}
.preview-wrapper img {
  max-width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.svg-note {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
}
.svg-note span { font-size: 32px; }
.svg-note strong { color: var(--ink); font-size: 14px; }

.facts-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-content: start;
}
.fact-item {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.fact-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.fact-item strong { font-size: 15px; word-break: break-word; }

/* Mode switch tabs */
.format-section {
  display: flex;
  justify-content: center;
}
.mode-switch {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 600px;
}
.mode-switch button {
  flex: 1;
  padding: 9px 14px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  font-size: 13px;
  transition: all 0.15s ease;
}
.mode-switch button.active {
  color: white;
  background: var(--accent);
}

/* Diagnostics */
.diagnostics-section {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
  display: grid;
  gap: 12px;
}
.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
}
.metric-strip article {
  padding: 12px 16px;
  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;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.metric-strip strong { font-size: 18px; }
.overhead-tag { color: var(--warning); }

.warning-banner {
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--warning) 40%, var(--line));
  border-radius: 8px;
  color: var(--warning);
  background: var(--warning-soft);
  font-weight: 600;
  font-size: 13px;
}
.diagnostics-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* Output Code Card */
.output-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-heading {
  min-height: 54px;
  padding: 10px 16px;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.card-heading label { margin: 0; color: var(--ink); font-weight: 750; font-size: 15px; }
.copy-actions { display: flex; gap: 8px; align-items: center; }

.output-card textarea {
  display: block;
  width: 100%;
  min-height: 180px;
  padding: 16px;
  resize: vertical;
  border: 0;
  outline: 0;
  color: color-mix(in srgb, var(--ink) 92%, var(--accent));
  background: var(--surface-2);
  font: 13px/1.6 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  word-break: break-all;
}
.output-card textarea:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.editor-status {
  display: flex;
  min-height: 36px;
  padding: 8px 16px;
  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; }

/* Privacy Strip */
.privacy-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.privacy-strip strong { color: var(--ink); }
.privacy-icon { font-size: 18px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  padding: 10px 18px;
  border-radius: 10px;
  color: white;
  background: var(--ink);
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 13px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Responsive */
@media (max-width: 768px) {
  .preview-grid { grid-template-columns: 1fr; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-strip article:nth-child(2) { border-right: 0; }
  .metric-strip article { border-bottom: 1px solid var(--line); }
  .mode-switch { flex-wrap: wrap; }
  .mode-switch button { min-width: 45%; }
}
@media (max-width: 480px) {
  .facts-card { grid-template-columns: 1fr; }
  .input-actions { flex-direction: column; width: 100%; }
  .input-actions .button { width: 100%; }
  .copy-actions { flex-direction: column; width: 100%; }
  .copy-actions .button { width: 100%; }
}
