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

:root {
  /* Surfaces */
  --bg:        #f2f2f7;   /* page background */
  --surface:   #ffffff;   /* sidebar, panels */
  --border:    #d1d1e0;   /* dividers, input borders */
  --canvas-bg: #e4e4ee;   /* image preview well */

  /* Accent — #3737d6 on white = 7.74 : 1  (WCAG AAA) */
  --accent:    #3737d6;
  --accent-hi: #2828b8;   /* hover / pressed (darker = higher contrast on light bg) */
  --accent-tint: #eeeeff; /* very light tint for secondary actions */

  /* Text — both pass WCAG AA on --surface and --bg */
  --text:      #1a1a2e;   /* primary  ~17 : 1 on white */
  --muted:     #5c5c7a;   /* secondary ~5.9 : 1 on white */

  /* Buttons */
  --btn-bg:    #3737d6;
  --btn-text:  #ffffff;   /* white on --accent = 7.74 : 1 ✓ */

  --radius:    6px;
  --font-ui:   'DM Sans', system-ui, sans-serif;
  --font-mono: 'Lilex', 'JetBrains Mono', monospace;
}

body {
  font-family: var(--font-ui);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Header ──────────────────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  min-height: 42px;
}

header h1 {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
}

header .subtitle {
  color: var(--muted);
  font-size: 12px;
}

/* ─── Mode tabs ───────────────────────────────────────────────────────────── */

.mode-tabs {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

.mode-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 12px 12px 10px;
  text-transform: uppercase;
  transition: color 0.15s, border-color 0.15s;
}

.mode-tab:hover:not(.active) { color: var(--accent-hi); }
.mode-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── Layout ──────────────────────────────────────────────────────────────── */

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */

.sidebar {
  width: 264px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  box-shadow: 1px 0 0 var(--border);
}

.sidebar-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section h2 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);  /* 5.9:1 on white ✓ */
  margin-bottom: 10px;
}

/* ─── Drop zones ──────────────────────────────────────────────────────────── */

#drop-zone, #video-drop-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  background: var(--bg);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  user-select: none;
}

#drop-zone:hover, #drop-zone.drag-over,
#video-drop-zone:hover, #video-drop-zone.drag-over {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-tint);
}

/* ─── Form controls ───────────────────────────────────────────────────────── */

.field {
  margin-bottom: 10px;
}

.field:last-child { margin-bottom: 0; }

.field label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 12px;
}

.field label .val {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);   /* 7.74:1 on white ✓ */
  min-width: 30px;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: background 0.15s;
  box-shadow: 0 1px 3px rgba(55,55,214,0.30);
}

input[type="range"]:hover::-webkit-slider-thumb { background: var(--accent-hi); }

input[type="text"], input[type="number"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
}

input[type="text"]:focus, input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(55,55,214,0.12);
}

select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 8px;
  font-family: var(--font-ui);
  font-size: 12px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(55,55,214,0.12);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 13px; height: 13px;
  cursor: pointer;
}

/* ─── Texture controls ────────────────────────────────────────────────────── */

.tex-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.tex-row label.file-btn {
  display: inline-block;
  padding: 5px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}

.tex-row label.file-btn:hover { border-color: var(--accent); color: var(--accent); }

#tex-label {
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.clear-link {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  text-decoration: underline;
  white-space: nowrap;
}

.clear-link:hover { color: var(--accent); }

/* ─── Batch file btn ──────────────────────────────────────────────────────── */

label.file-btn {
  display: block;
  padding: 10px;
  text-align: center;
  background: var(--bg);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

label.file-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-tint);
}

/* ─── Action buttons ──────────────────────────────────────────────────────── */

.actions {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-bottom: 1px solid var(--border);
}

.btn {
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}

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

/* Primary — accent fill, white text, 7.74:1 ✓ */
.btn-primary { background: var(--btn-bg); color: var(--btn-text); }
.btn-primary:not(:disabled):hover {
  background: var(--accent-hi);
  box-shadow: 0 2px 6px rgba(55,55,214,0.30);
}

/* Secondary — light gray fill, dark text, ~11:1 ✓ */
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:not(:disabled):hover { background: #c0c0d4; }

/* Download — accent tint fill, accent text, 7.74:1 ✓ */
.btn-download { background: var(--accent-tint); color: var(--accent); border: 1px solid var(--accent); }
.btn-download:not(:disabled):hover { background: var(--accent); color: #fff; }

/* ─── Progress ────────────────────────────────────────────────────────────── */

#progress-wrap {
  padding: 0 14px 10px;
}

.progress-track {
  background: var(--border);
  border-radius: 3px;
  height: 4px;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s ease;
  border-radius: 3px;
}

#frame-progress-bar {
  height: 100%;
  background: var(--accent-hi);
  width: 0%;
  transition: width 0.1s ease;
  border-radius: 3px;
}

#status-text {
  color: var(--muted);
  font-size: 11px;
  padding: 8px 14px 4px;
  font-family: var(--font-mono);
}

/* ─── Canvas area ─────────────────────────────────────────────────────────── */

.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: var(--canvas-bg);
  position: relative;
}

#placeholder {
  position: absolute;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
  user-select: none;
}

#output-canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  image-rendering: pixelated;
  box-shadow: 0 4px 24px rgba(55,55,214,0.10), 0 1px 4px rgba(0,0,0,0.08);
}

/* ─── Scrollbar ───────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a8a8c4; }

/* ─── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .app-body { flex-direction: column; }
  .sidebar { width: 100%; max-height: 50vh; border-right: none; border-bottom: 1px solid var(--border); }
}
