:root {
  --bg: #0a0a0f;
  --panel: #12121a;
  --panel-2: #1a1a24;
  --text: #e2e2e8;
  --text-dim: #7a7a8a;
  --accent: #00ff85;
  --accent-dim: rgba(0, 255, 133, 0.14);
  --accent-glow: rgba(0, 255, 133, 0.35);
  --danger: #ff4d6d;
  --border: rgba(0, 255, 133, 0.18);
  --radius: 2px;
  --font-mono: 'JetBrains Mono', monospace;
  --font-body: 'Space Grotesk', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
}

/* scanline overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 255, 133, 0.03) 2px,
    rgba(0, 255, 133, 0.03) 4px
  );
  z-index: 9999;
}

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

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 18px 4px var(--accent-glow); }
}

@keyframes scan {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100vh); }
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  animation: fadeIn 0.5s ease-out;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.04em;
  color: var(--accent);
  text-shadow: 0 0 12px var(--accent-glow);
}

.brand svg {
  width: 24px;
  height: 24px;
  stroke: var(--accent);
}

.mode-switch {
  display: flex;
  gap: 8px;
  background: var(--panel-2);
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.mode-switch button {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 18px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.2s ease;
}

.mode-switch button.active {
  background: var(--accent);
  color: #000;
  box-shadow: 0 0 12px var(--accent-glow);
}

.mode-switch button:not(.active):hover {
  color: var(--text);
}

main {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 360px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  animation: fadeIn 0.6s ease-out 0.1s both;
}

.panel-section {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.panel-section h3 {
  margin: 0 0 14px 0;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 18px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 20px var(--accent-glow);
}

.upload-zone svg {
  width: 40px;
  height: 40px;
  stroke: var(--accent);
  margin-bottom: 10px;
}

.upload-zone p {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}

.upload-zone .filename {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}

input[type="file"] { display: none; }

label.field {
  display: block;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-dim);
}

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

label.field span {
  display: block;
  margin-bottom: 6px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

select, input[type="text"], input[type="range"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select:focus, input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

input[type="range"] {
  padding: 0;
  height: 6px;
  -webkit-appearance: none;
  background: var(--bg);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 10px var(--accent-glow);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 10px var(--accent-glow);
}

.range-value {
  font-family: var(--font-mono);
  color: var(--accent);
  float: right;
}

.algo-desc {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  border-left: 2px solid var(--accent);
  padding-left: 10px;
}

.key-hint {
  margin: 10px 0 0 0;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 14px var(--accent-glow);
}

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

.btn.primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.btn.primary:hover:not(:disabled) {
  background: #33ff9f;
  box-shadow: 0 0 20px var(--accent-glow);
}

.preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  animation: fadeIn 0.7s ease-out 0.2s both;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.preview-toolbar .info {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

.preview-toolbar .info span { color: var(--accent); }

.view-toggle {
  display: flex;
  gap: 8px;
}

.view-toggle button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.2s ease;
}

.view-toggle button.active, .view-toggle button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.preview-stage {
  flex: 1;
  display: flex;
  min-height: 0;
  padding: 24px;
  gap: 24px;
  justify-content: center;
  align-items: center;
  position: relative;
}

.preview-box {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  position: relative;
}

.preview-box.hidden { display: none; }

.preview-label {
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

.preview-canvas-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
  padding: 16px;
  position: relative;
}

canvas {
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.compare-slider {
  position: absolute;
  inset: 0;
  display: none;
}

.compare-slider.active {
  display: block;
}

.compare-slider img, .compare-slider canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 48px);
  max-height: calc(100% - 48px);
}

.compare-slider .after-layer {
  clip-path: inset(0 50% 0 0);
}

.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 4px;
  background: var(--accent);
  cursor: ew-resize;
  box-shadow: 0 0 12px var(--accent-glow);
  z-index: 10;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  stroke: var(--text-dim);
  margin-bottom: 16px;
}

.empty-state p {
  margin: 0;
  font-size: 14px;
}

.processing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 15, 0.85);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 20;
}

.processing-overlay.active { display: flex; }

.processing-overlay .scan-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  animation: scan 1.2s linear infinite;
}

.processing-overlay p {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  z-index: 1;
}

.history {
  height: 130px;
  flex-shrink: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fadeIn 0.8s ease-out 0.3s both;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-header h3 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.history-header button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
}

.history-header button:hover { color: var(--danger); }

.history-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.history-item {
  flex-shrink: 0;
  width: 90px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.history-item:hover {
  transform: scale(1.05);
  border-color: var(--accent);
}

.history-item img {
  width: 100%;
  height: 56px;
  object-fit: cover;
  display: block;
}

.history-item .meta {
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
}

footer {
  flex-shrink: 0;
  padding: 8px 24px;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: var(--panel);
}

@media (max-width: 900px) {
  main { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 45vh;
  }
  .preview-stage { flex-direction: column; }
  .preview-box { width: 100%; }
}
