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

:root {
  --bg: #0d0d0d;
  --surface: #1a1a1a;
  --border: #2e2e2e;
  --accent: #6c63ff;
  --accent-dim: #3d3880;
  --text: #e8e8e8;
  --text-muted: #888;
  --danger: #e05555;
  --success: #4caf72;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

.header-actions .btn {
  padding: 6px 14px;
  font-size: 13px;
}

h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.badges { display: flex; gap: 6px; }

.badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge.active { border-color: var(--accent); color: var(--accent); }
.badge.unavailable { border-color: var(--danger); color: var(--danger); }

main {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 24px;
  padding: 24px;
  min-height: calc(100vh - 49px - 32px);
}

/* Dropzone */
.dropzone {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 180px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.dropzone:hover, .dropzone.drag-over {
  border-color: var(--accent);
  background: rgba(108, 99, 255, 0.04);
}

.dropzone-icon { font-size: 48px; line-height: 1; }
.dropzone-label { font-size: 18px; font-weight: 600; }
.dropzone-sub { color: var(--text-muted); }
.dropzone-sub .link { color: var(--accent); text-decoration: underline; cursor: pointer; }
.dropzone-formats { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Info panel (home) */
#info-intro {
  grid-column: 1 / -1;
}

#info-tech {
  grid-column: 1 / -1;
}

.info-block {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid;
}

.info-combined {
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  color: var(--text);
}

.info-block strong { display: block; margin-bottom: 6px; }

.intro-bullets {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  margin: 0;
}

.intro-bullets li {
  padding-left: 14px;
  position: relative;
}

.intro-bullets li::before {
  content: '–';
  position: absolute;
  left: 0;
  color: var(--accent);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.info-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.info-value {
  font-size: 12px;
  font-family: monospace;
  color: var(--text);
}

a.info-value, .info-value a { color: var(--accent); }
a.info-value:hover, .info-value a:hover { text-decoration: underline; }
.info-block a { color: var(--accent); text-decoration: none; }
.info-block a:hover { text-decoration: underline; }

/* Processing view */
#processing-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.canvas-container {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
}

#output-canvas {
  width: 100%;
  height: auto;
  display: block;
  max-height: 60vh;
  object-fit: contain;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  font-size: 14px;
  color: var(--text-muted);
}

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

.progress-wrapper {
  position: relative;
  height: 24px;
  background: var(--surface);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}

.progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  mix-blend-mode: difference;
}

.stats {
  font-size: 12px;
  color: var(--text-muted);
  min-height: 18px;
}

.action-row {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { background: #7b73ff; }
.btn-secondary { background: var(--surface); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* Settings — hidden by default, shown only during confirm step */
aside#settings {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border);
  align-self: start;
}

/* In confirm mode processing-view takes column 1, settings column 2 */
/* Outside confirm mode, processing-view spans full width */
#main:not(.confirm) #processing-view { grid-column: 1 / -1; }

/* Start button below the canvas */
#confirm-bar {
  display: flex;
  gap: 12px;
  align-items: center;
}

.btn-start-bar {
  flex: 1;
  padding: 10px;
  font-size: 14px;
}

/* Note at the top of the settings panel */
.settings-note {
  font-size: 11px;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: 6px;
  padding: 7px 10px;
  line-height: 1.5;
  margin: 0;
}

aside#settings {
  overflow-y: auto;
  max-height: calc(100vh - 100px);
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  margin: 0;
}

.setting-field { display: flex; flex-direction: column; gap: 4px; }

.setting-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.setting-header label {
  font-size: 13px;
  font-weight: 500;
  cursor: default;
  user-select: none;
}

.setting-recommended {
  font-size: 10px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.setting-recommended:hover { border-color: var(--accent); color: var(--accent); }

.setting-description {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.setting-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-control input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.setting-control select {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
}

.setting-value {
  font-size: 12px;
  font-family: monospace;
  color: var(--text);
  min-width: 36px;
  text-align: right;
}

.setting-value.modified { color: #e09855; }

/* Status bar */
.status-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 28px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.status-bar.error { color: var(--danger); }
.status-bar.loading::before {
  content: '';
  display: inline-block;
  width: 10px; height: 10px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Review panel ──────────────────────────────────────────────────────── */
.scrubber-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scrubber-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.btn-icon {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 28px; height: 28px;
  border-radius: 4px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--border); }

.frame-counter {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 64px;
  text-align: right;
}

.detection-info {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
}

.det-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
  border: 1px solid;
}

.det-badge.real    { border-color: #e05555; color: #e05555; background: rgba(224,85,85,.08); }
.det-badge.gap     { border-color: #e09855; color: #e09855; background: rgba(224,152,85,.08); }
.det-badge.persist { border-color: #8b5cf6; color: #8b5cf6; background: rgba(139,92,246,.08); }
.det-badge.none    { border-color: var(--border); color: var(--text-muted); }

/* ── Tablet ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  main { grid-template-columns: 1fr 200px; gap: 16px; padding: 16px; }
  aside#settings { max-height: calc(100vh - 80px); }
}

/* ── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Header */
  header { padding: 10px 12px; gap: 8px; }
  h1 { font-size: 15px; }
  .header-actions .btn { padding: 6px 10px; font-size: 12px; }

  /* Single-column layout — settings stack below canvas */
  main {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
    min-height: auto;
  }

  /* Full-span rules become no-ops in single column — reset */
  .dropzone                              { grid-column: 1; }
  #main:not(.confirm) #processing-view   { grid-column: 1; }

  /* Dropzone: more compact */
  .dropzone     { min-height: 180px; }
  .dropzone-icon  { font-size: 36px; }
  .dropzone-label { font-size: 16px; }

  /* Canvas: portrait-friendly height cap */
  #output-canvas { max-height: 50vw; min-height: 120px; }

  /* Settings: full width, no height cap (page scrolls) */
  aside#settings {
    max-height: none;
    overflow-y: visible;
    align-self: auto;
  }

  /* Confirm bar: single full-width button */
  #confirm-bar { flex-direction: column; }
  .btn-start-bar { width: 100%; padding: 12px; font-size: 15px; }

  /* Action buttons: stack, full width */
  .action-row { flex-direction: column-reverse; }
  .action-row .btn { width: 100%; text-align: center; padding: 12px; }

  /* Progress label: hide frame count on tiny screens */
  .progress-label { font-size: 11px; }
  .stats { font-size: 11px; }

  /* Review scrubber */
  .scrubber-row { gap: 6px; }
  .btn-icon { width: 36px; height: 36px; font-size: 20px; }
  .frame-counter { min-width: 54px; font-size: 11px; }

  /* Detection badges: smaller */
  .det-badge { font-size: 10px; padding: 2px 6px; }

  /* Status bar */
  .status-bar { height: auto; padding: 5px 12px; font-size: 11px; }

  /* Sliders: taller hit area for touch */
  input[type="range"] { height: 20px; }

  /* Settings note: slightly larger for mobile readability */
  .settings-note { font-size: 12px; }

  /* Setting description: collapsed by default on mobile */
  .setting-description { font-size: 11px; }
}

/* ── Very small screens (≤ 380px) ────────────────────────────────────── */
@media (max-width: 380px) {
  header { padding: 10px 12px; }
  main   { padding: 10px; gap: 10px; }
  h1     { font-size: 15px; }
  .badge { display: none; }
}

.hidden { display: none !important; }
