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

:root {
  --bg:         #0a0a0a;
  --surface:    #111111;
  --surface2:   #1a1a1a;
  --border:     #222222;
  --accent:     #f4a7b9;
  --text:       #d4d4d4;
  --text-muted: #555555;
  --error:      #ff6b6b;
  --sidebar-w:  240px;
  --header-h:   44px;
  --transition: 0.1s ease;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

@media (min-width: 1440px) {
  html, body { font-size: 15px; }
  :root { --sidebar-w: 260px; --header-h: 48px; }
}

@media (min-width: 1920px) {
  html, body { font-size: 18px; }
  :root { --sidebar-w: 300px; --header-h: 54px; }
}

#app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-columns: var(--sidebar-w) 1fr var(--sidebar-w);
  grid-template-areas:
    "header  header  header"
    "sidebar main    params";
  height: 100vh;
}

header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.2em;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.header-title {
  font-size: 1em;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.header-btn {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.4em 1em;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 2px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85em;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.header-btn:hover { color: var(--text); border-color: var(--text-muted); }

.header-btn svg {
  width: 0.9em;
  height: 0.9em;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#resetBtn { display: none; }
#compareBtn { display: none; }
#compareBtn.active { color: var(--accent); border-color: var(--accent); }

/* ── Compare (split-slider) overlay ─────────────────────────────────── */
#compareOverlay {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}
#compareOverlay.active { display: block; pointer-events: auto; }

/* The original-image canvas sits on top of the WebGL canvas, clipped to
   the left of the divider. */
#originalCanvas {
  position: absolute;
  top: 0; left: 0;
  /* width/height set by JS to match glCanvas */
}

/* Vertical divider line */
#compareDivider {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: var(--accent);
  cursor: ew-resize;
  /* Widen the hit-target without changing visual width */
  padding: 0 8px;
  margin-left: -8px;
  box-sizing: content-box;
}

/* Handle knob on the divider */
#compareDivider::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 1.4em;
  height: 1.4em;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}

/* Labels */
#compareLabels {
  display: none;
  justify-content: space-between;
  width: 100%;
  font-size: 0.8em;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  user-select: none;
}
#compareLabels.active { display: flex; }

#sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-section {
  padding: 0.9em 1em 0.6em;
  font-size: 0.75em;
  font-weight: 400;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

#filterList {
  flex: 1;
  overflow-y: auto;
  padding: 0.3em;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#filterList::-webkit-scrollbar       { width: 3px; }
#filterList::-webkit-scrollbar-track { background: transparent; }
#filterList::-webkit-scrollbar-thumb { background: var(--border); }

.filter-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5em 0.8em;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 0;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1em;
  font-weight: 300;
  transition: color var(--transition), background var(--transition);
  margin-bottom: 1px;
}
.filter-btn:hover { color: var(--text); background: var(--surface2); }
.filter-btn.active {
  color: var(--accent);
  background: transparent;
  font-weight: 400;
}

#paramsSidebar {
  grid-area: params;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

#paramsPanel {
  flex: 1;
  overflow-y: auto;
  padding: 0.8em 1em 1em;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#paramsPanel::-webkit-scrollbar       { width: 3px; }
#paramsPanel::-webkit-scrollbar-track { background: transparent; }
#paramsPanel::-webkit-scrollbar-thumb { background: var(--border); }

.params-empty,
.params-loading {
  color: var(--text-muted);
  font-size: 0.85em;
  padding: 0.5em 0;
}

.error {
  color: var(--error);
  font-size: 0.85em;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.param-row { margin-bottom: 1em; }
.param-row:last-child { margin-bottom: 0; }

.param-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4em;
  font-size: 0.85em;
  color: var(--text-muted);
}

.param-value {
  font-size: 0.85em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  min-width: 2.5em;
  text-align: right;
}

.param-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
.param-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 0.75em;
  height: 0.75em;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}
.param-slider::-moz-range-thumb {
  width: 0.75em;
  height: 0.75em;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

main {
  grid-area: main;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
}

main.drag-over #dropOverlay {
  border-color: var(--accent);
}

#imageView {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#canvasWrapper {
  position: relative;
}

#glCanvas {
  display: block;
  max-width: calc(100vw - var(--sidebar-w) * 2 - 48px);
  max-height: calc(100vh - var(--header-h) - 72px);
  width: auto;
  height: auto;
}

#imageActions {
  display: none;
  gap: 8px;
  justify-content: center;
}
#imageActions.visible { display: flex; }

#dropOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5em;
  background: transparent;
  user-select: none;
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6em;
  padding: 2em 3em;
  border: 1px dashed var(--border);
  cursor: pointer;
  transition: border-color var(--transition);
}
.drop-zone:hover { border-color: var(--text-muted); }

.drop-title {
  font-size: 1em;
  font-weight: 400;
  color: var(--text-muted);
}

.drop-sub {
  font-size: 0.85em;
  color: var(--border);
}

.preset-label {
  font-size: 0.75em;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

#presetGrid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  justify-content: center;
  max-width: 480px;
}

.preset-btn {
  padding: 0.3em 0.8em;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85em;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.preset-btn:hover { color: var(--text); border-color: var(--text-muted); }
