:root {
  --bg: #080808;
  --surface: #101010;
  --surface2: #141414;
  --border: #1c1c1c;
  --border2: #242424;
  --text: #e8e8e8;
  --muted: #888;
  --faint: #555;
  --accent: #ffffff;
  --radius: 14px;
  --preview-h: 44vh;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  background: var(--bg); color: var(--text);
  font-family: 'Courier New', monospace;
  min-height: 100vh;
}

/* ── TOP NAV ── */
.topnav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(8,8,8,0.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
}
.topnav a {
  font-size: 11px; color: #aaa; text-decoration: none;
  letter-spacing: 0.05em; display: flex; align-items: center; gap: 4px;
  font-size: 12px;
}
.topnav a:hover { color: #fff; }
.topnav .tool-title {
  flex: 1; text-align: center; font-size: 13px;
  font-weight: 700; color: var(--text); letter-spacing: 0.03em;
}

/* ── STICKY PREVIEW ── */
.preview-sticky {
  position: sticky; top: 45px; z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  height: var(--preview-h);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.preview-sticky.empty {
  background: var(--surface);
}
.preview-placeholder {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: #555;
}
.preview-placeholder .icon { font-size: 32px; opacity: 0.4; }
.preview-placeholder .text { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }

/* Before/After inside preview */
.ba-wrap {
  width: 100%; height: 100%; position: relative; overflow: hidden;
}
.ba-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#cv-after { clip-path: inset(0 0 0 50%); }
.ba-divider {
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 2px; background: rgba(255,255,255,0.6);
  z-index: 10; transform: translateX(-50%); cursor: ew-resize;
}
.ba-handle {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: 28px; height: 28px; border-radius: 50%;
  background: #fff; display: flex; align-items: center;
  justify-content: center; font-size: 10px; color: #000;
  font-weight: 700; user-select: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.ba-label {
  position: absolute; bottom: 8px;
  font-size: 9px; letter-spacing: 0.15em;
  background: rgba(0,0,0,0.6); color: #fff;
  padding: 3px 8px; border-radius: 6px; pointer-events: none;
}
.ba-label-before { left: 8px; }
.ba-label-after  { right: 8px; }

/* Single canvas preview */
.preview-canvas-wrap {
  width: 100%; height: 100%; display: flex;
  align-items: center; justify-content: center;
}
.preview-canvas-wrap canvas {
  max-width: 100%; max-height: 100%; object-fit: contain;
  border-radius: 0;
}

/* ── CONTROLS PANEL ── */
.controls-panel {
  padding: 20px 16px 80px;
  max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 12px;
}

/* Upload button (top of controls) */
.upload-area {
  display: flex; gap: 10px; align-items: center;
}
.btn-upload {
  flex: 1; background: #fff; color: #000; border: none;
  padding: 13px 20px; border-radius: 10px;
  cursor: pointer; font-size: 13px; font-family: inherit;
  font-weight: 700; letter-spacing: 0.04em;
  touch-action: manipulation; transition: opacity 0.2s;
}
.btn-upload.loaded {
  background: var(--surface2); color: #aaa;
  border: 1px solid var(--border2);
  font-weight: 400;
}
.btn-upload:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-save {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border2);
  padding: 13px 16px; border-radius: 10px;
  cursor: pointer; font-size: 13px; font-family: inherit;
  touch-action: manipulation;
}

/* Card */
.ctrl-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.ctrl-card-label {
  font-size: 9px; letter-spacing: 0.3em; color: #666;
  text-transform: uppercase; margin-bottom: 14px;
}

/* Slider */
.slider-group { display: flex; flex-direction: column; gap: 12px; }
.slider-item { display: flex; flex-direction: column; gap: 6px; }
.slider-row  { display: flex; justify-content: space-between; align-items: baseline; }
.slider-name { font-size: 12px; color: #aaa; }
.slider-val  { font-size: 13px; color: var(--text); font-weight: 700; }
input[type=range] { width: 100%; accent-color: #fff; cursor: pointer; height: 18px; }

/* Pills */
.pill-row { display: flex; gap: 7px; flex-wrap: wrap; }
.pill {
  padding: 7px 14px; border-radius: 20px;
  background: var(--surface2); border: 1px solid var(--border2);
  color: #aaa; cursor: pointer; font-family: inherit;
  font-size: 12px; transition: all 0.15s; touch-action: manipulation;
}
.pill.active { background: #fff; color: #000; border-color: #fff; }

/* Theme grid */
.theme-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.theme-btn {
  border-radius: 10px; padding: 10px 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  border: 2px solid transparent; transition: border-color 0.15s;
}
.theme-btn.active { border-color: #fff !important; }
.theme-dot { width: 20px; height: 20px; border-radius: 50%; }
.theme-name { font-size: 11px; font-family: inherit; }

/* Format row */
.fmt-row { display: flex; gap: 8px; }
.fmt-btn {
  flex: 1; background: var(--surface2); color: #aaa;
  border: 1px solid var(--border2); border-radius: 8px;
  padding: 10px 6px; cursor: pointer; font-family: inherit;
  text-align: center; transition: all 0.15s;
}
.fmt-btn.active { background: #fff; color: #000; border-color: #fff; }
.fmt-ratio { font-weight: 700; font-size: 13px; }
.fmt-name  { font-size: 10px; opacity: 0.8; margin-top: 2px; }

/* Progress */
.progress-bar-wrap {
  height: 2px; background: var(--border); border-radius: 2px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%; background: #fff; border-radius: 2px;
  transition: width 0.1s;
}
.progress-label { font-size: 11px; color: #aaa; text-align: center; margin-top: 6px; }

/* Save hint */
.save-hint {
  background: #fff; color: #000;
  border-radius: 10px; padding: 14px 16px;
  font-size: 13px; text-align: center; font-weight: 700;
  line-height: 1.5;
}
.save-hint span { font-weight: 400; color: #666; font-size: 12px; }

.tip { font-size: 11px; color: #555; text-align: center; line-height: 1.7; }

.error-msg { color: #ef4444; font-size: 12px; text-align: center; }
