:root {
  color-scheme: dark;
  --bg: #0c0f14;
  --surface: #151a22;
  --surface-alt: #1b222d;
  --border: #2a3342;
  --border-focus: #5b9dff;
  --text: #eef2f7;
  --text-muted: #93a1b5;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --error: #ef4444;
  --radius: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at top, #131b29 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 24px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  color: #fff;
  flex-shrink: 0;
}

h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
}

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

.pill {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
}

.pill-ready {
  border-color: rgba(34, 197, 94, 0.4);
  background: rgba(34, 197, 94, 0.12);
  color: #86efac;
}

.pill-error {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
}

.workspace {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 24px 36px;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.drop-zone {
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 26px 16px;
  text-align: center;
  background: var(--surface-alt);
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.drag-over {
  border-color: var(--border-focus);
  background: rgba(59, 130, 246, 0.08);
  outline: none;
}

.drop-icon {
  font-size: 1.65rem;
  color: var(--border-focus);
  margin-bottom: 6px;
}

.drop-title {
  margin: 0;
  font-weight: 600;
  font-size: 0.95rem;
}

.drop-hint {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.badges {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.file-badge,
.detected-badge {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
}

.file-badge {
  background: rgba(59, 130, 246, 0.16);
  color: #bfdbfe;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.detected-badge {
  background: rgba(139, 92, 246, 0.18);
  color: #ddd6fe;
  border: 1px solid rgba(139, 92, 246, 0.35);
}

.pair-box {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.pair-box input[type="file"] {
  font-size: 0.82rem;
  color: var(--text);
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

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

.field-row output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

select {
  appearance: none;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.9rem;
  font-family: inherit;
}

select:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 1px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  padding-top: 2px;
}

.toggle-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.btn-primary,
.btn-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 9px;
  padding: 11px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 140ms ease, opacity 140ms ease;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
}

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

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

.btn-download {
  background: var(--success);
  color: #052e16;
  white-space: nowrap;
}

.btn-download:hover {
  background: #16a34a;
  color: #fff;
}

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.84rem;
}

.alert-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
}

.privacy-note {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.tabs {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}

.tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 11px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

.meta-text {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.canvas-stage {
  min-height: 360px;
  background: #090c10;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
}

#preview-canvas {
  max-width: 100%;
  max-height: 520px;
  width: auto;
  height: auto;
  border-radius: 6px;
  display: block;
}

.empty-stage {
  max-width: 380px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.empty-stage code {
  color: var(--text);
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: 5px;
}

.result-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 10px;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.35);
  flex-wrap: wrap;
}

.result-info {
  min-width: 0;
}

.result-info strong {
  display: block;
  font-size: 0.94rem;
  word-break: break-all;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .canvas-stage {
    min-height: 260px;
  }
}
