/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #111;
  --bg2:       #1c1c1c;
  --bg3:       #242424;
  --bg4:       #2e2e2e;
  --border:    #333;
  --text:      #e8e8e8;
  --text-dim:  #888;
  --accent:    #f5b942;
  --accent2:   #e8a830;
  --danger:    #e05252;
  --panel-w:   280px;
  --header-h:  52px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 13px; overflow: hidden; user-select: none; }

/* ── App shell ── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Header ── */
#header {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--header-h); padding: 0 16px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 10;
}

#logo { display: flex; align-items: center; gap: 8px; }
#logo-icon { color: var(--accent); font-size: 20px; }
#logo-text { font-size: 17px; font-weight: 600; letter-spacing: .5px; }

#header-center { flex: 1; text-align: center; }
#filename-label { color: var(--text-dim); font-size: 12px; }

#header-actions { display: flex; align-items: center; gap: 6px; }

.hdr-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 6px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text); cursor: pointer; font-size: 13px;
  transition: background .15s, border-color .15s;
}
.hdr-btn:hover:not(:disabled) { background: var(--bg3); border-color: #555; }
.hdr-btn:disabled { opacity: .35; cursor: not-allowed; }
.hdr-btn.accent { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 600; }
.hdr-btn.accent:hover:not(:disabled) { background: var(--accent2); border-color: var(--accent2); }

/* ── Main layout ── */
#main {
  display: flex; flex: 1; overflow: hidden;
}

/* ── Canvas area ── */
#canvas-wrap {
  flex: 1; position: relative; overflow: hidden;
  background: #0a0a0a;
  display: flex; align-items: center; justify-content: center;
}

/* ── Drop zone ── */
#drop-zone {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
}
#drop-zone.drag-over::after {
  content: ''; position: absolute; inset: 12px;
  border: 2px dashed var(--accent); border-radius: 12px; pointer-events: none;
}
#drop-zone-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#drop-zone-inner p { color: var(--text-dim); font-size: 15px; }
#drop-zone-inner p.sub { font-size: 12px; color: #444; }
#open-btn {
  margin-top: 4px; padding: 10px 24px;
  background: var(--accent); color: #111; font-weight: 700; font-size: 14px;
  border: none; border-radius: 8px; cursor: pointer;
  transition: background .15s;
}
#open-btn:hover { background: var(--accent2); }

/* ── Canvas container ── */
#canvas-container {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
}
#main-canvas {
  max-width: 100%; max-height: 100%;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* ── Crop overlay ── */
#crop-overlay {
  position: absolute; inset: 0;
  background: transparent;
  pointer-events: none;
}
#crop-box {
  position: absolute;
  border: 1.5px solid rgba(255,255,255,.85);
  cursor: move;
  box-sizing: border-box;
  /* Darkens the area OUTSIDE the crop box */
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
  pointer-events: all;
}
.crop-handle {
  position: absolute; width: 14px; height: 14px;
  background: #fff; border-radius: 2px;
}
.crop-handle[data-pos="tl"] { top: -7px; left: -7px; cursor: nw-resize; }
.crop-handle[data-pos="tr"] { top: -7px; right: -7px; cursor: ne-resize; }
.crop-handle[data-pos="bl"] { bottom: -7px; left: -7px; cursor: sw-resize; }
.crop-handle[data-pos="br"] { bottom: -7px; right: -7px; cursor: se-resize; }
#crop-grid { position: absolute; inset: 0; }
.crop-grid-line { position: absolute; background: rgba(255,255,255,.25); }
.crop-grid-line.h { left: 0; right: 0; height: 1px; }
.crop-grid-line.v { top: 0; bottom: 0; width: 1px; }

/* ── Curves overlay ── */
#curves-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
#curves-canvas { pointer-events: all; }

/* ── Processing spinner ── */
#processing {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; background: rgba(0,0,0,.5);
  color: var(--text-dim); font-size: 13px;
}
#processing-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Right panel ── */
#panel {
  width: var(--panel-w); flex-shrink: 0;
  background: var(--bg2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  position: relative;
}

.panel-view { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; transition: opacity .18s, transform .18s; }
.panel-view:not(.active) { opacity: 0; pointer-events: none; transform: translateX(16px); }
.panel-view.active { opacity: 1; pointer-events: all; transform: none; }

.panel-section-title {
  padding: 10px 14px 6px;
  font-size: 10px; font-weight: 700; letter-spacing: 1.2px;
  color: var(--text-dim);
}

/* ── Styles strip ── */
#styles-section { flex-shrink: 0; }
#styles-strip {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 4px 14px 10px; scrollbar-width: thin;
  scrollbar-color: var(--bg4) transparent;
}
#styles-strip::-webkit-scrollbar { height: 4px; }
#styles-strip::-webkit-scrollbar-track { background: transparent; }
#styles-strip::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }

.style-card {
  flex-shrink: 0; width: 72px; cursor: pointer;
  border-radius: 8px; overflow: hidden;
  border: 2px solid transparent;
  transition: border-color .15s, transform .1s;
  background: var(--bg3);
}
.style-card:hover { transform: translateY(-2px); }
.style-card.active { border-color: var(--accent); }
.style-card-thumb {
  width: 72px; height: 54px; display: block;
  object-fit: cover; background: var(--bg4);
}
.style-card-canvas { width: 72px; height: 54px; display: block; }
.style-card-name {
  text-align: center; font-size: 10px; color: var(--text-dim);
  padding: 4px 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.style-card.active .style-card-name { color: var(--accent); }

/* ── Tools grid ── */
#tools-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 1px; overflow-y: auto; flex: 1;
  padding: 0 0 8px;
  background: var(--border);
  scrollbar-width: thin; scrollbar-color: var(--bg4) transparent;
}

.tool-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 16px 8px;
  background: var(--bg2); cursor: pointer; border: none;
  color: var(--text); font-size: 11px; letter-spacing: .3px;
  transition: background .12s;
}
.tool-btn:hover { background: var(--bg3); }
.tool-btn.active { background: var(--bg3); color: var(--accent); }
.tool-icon {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--bg4); transition: background .12s;
}
.tool-btn:hover .tool-icon,
.tool-btn.active .tool-icon { background: rgba(245,185,66,.15); }
.tool-btn.active .tool-icon svg { stroke: var(--accent); }

/* ── Adjust panel ── */
#panel-adjust-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#active-tool-name { font-weight: 600; font-size: 14px; }

#cancel-tool-btn, #apply-tool-btn {
  width: 32px; height: 32px; border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s;
}
#cancel-tool-btn { background: var(--bg4); color: var(--text-dim); }
#cancel-tool-btn:hover { background: var(--danger); color: #fff; }
#apply-tool-btn { background: var(--accent); color: #111; }
#apply-tool-btn:hover { background: var(--accent2); }

#panel-adjust-body { flex: 1; overflow-y: auto; padding: 8px 0; scrollbar-width: thin; scrollbar-color: var(--bg4) transparent; }

/* ── Sliders ── */
.adjust-row {
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.adjust-label-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.adjust-label { font-size: 12px; color: var(--text-dim); }
.adjust-value { font-size: 12px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; min-width: 32px; text-align: right; }

/* Custom range slider */
.slider-wrap { position: relative; height: 4px; border-radius: 2px; background: var(--bg4); cursor: pointer; }
.slider-track { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: var(--accent); pointer-events: none; }
.slider-thumb {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent);
  cursor: grab; pointer-events: none;
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
  transition: box-shadow .1s;
}
.slider-wrap:active .slider-thumb { cursor: grabbing; box-shadow: 0 0 0 4px rgba(245,185,66,.25); }

/* Slider center line (for -100 to +100 ranges) */
.slider-wrap.bipolar::before {
  content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px;
  background: var(--border); pointer-events: none;
}

/* ── Select pills ── */
.select-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.select-pill {
  padding: 4px 12px; border-radius: 20px; font-size: 11px; cursor: pointer;
  background: var(--bg4); color: var(--text-dim); border: 1px solid transparent;
  transition: all .12s;
}
.select-pill:hover { background: var(--bg3); color: var(--text); }
.select-pill.active { background: rgba(245,185,66,.15); border-color: var(--accent); color: var(--accent); }

/* ── Curves editor ── */
#curves-editor-wrap { padding: 14px; }
#curves-canvas-editor {
  width: 100%; aspect-ratio: 1;
  border-radius: 6px; background: var(--bg3);
  cursor: crosshair; display: block;
}
.curves-channel-btns { display: flex; gap: 6px; justify-content: center; margin-top: 10px; }
.curves-ch-btn {
  padding: 4px 14px; border-radius: 20px; font-size: 11px; cursor: pointer;
  background: var(--bg4); color: var(--text-dim); border: 1px solid transparent;
  transition: all .12s;
}
.curves-ch-btn.active-ch-rgb { border-color: #aaa; color: #ddd; }
.curves-ch-btn.active-ch-r   { border-color: #e05252; color: #e05252; }
.curves-ch-btn.active-ch-g   { border-color: #52c052; color: #52c052; }
.curves-ch-btn.active-ch-b   { border-color: #5285e0; color: #5285e0; }
.curves-reset-btn {
  display: block; width: 100%; margin-top: 8px; padding: 6px;
  background: var(--bg4); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-dim); cursor: pointer; font-size: 11px;
  transition: background .12s;
}
.curves-reset-btn:hover { background: var(--bg3); color: var(--text); }

/* ── Crop aspect buttons ── */
.crop-options { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.crop-aspect-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.crop-aspect-btn {
  padding: 5px 12px; border-radius: 6px; font-size: 11px; cursor: pointer;
  background: var(--bg4); color: var(--text-dim); border: 1px solid transparent;
  transition: all .12s;
}
.crop-aspect-btn:hover { background: var(--bg3); color: var(--text); }
.crop-aspect-btn.active { border-color: var(--accent); color: var(--accent); }
.crop-section-label { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }

/* ── Film Look panel ── */
.filmlook-list {
  display: flex; flex-direction: column; padding: 8px 0;
}
.filmlook-item {
  display: flex; align-items: center; padding: 11px 16px;
  background: transparent; border: none; border-bottom: 1px solid rgba(255,255,255,.04);
  color: var(--text-dim); font-size: 13px; cursor: pointer; text-align: left;
  transition: background .1s, color .1s;
}
.filmlook-item:hover { background: var(--bg3); color: var(--text); }
.filmlook-item.active { color: var(--accent); background: rgba(245,185,66,.08); }
.filmlook-item.active::after { content: '✓'; margin-left: auto; font-size: 12px; }

/* ── Rotate tool ── */
.rotate-options { padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.rotate-btns { display: flex; gap: 8px; }
.rotate-btn {
  flex: 1; padding: 10px; border-radius: 8px; cursor: pointer;
  background: var(--bg4); border: 1px solid var(--border);
  color: var(--text); font-size: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: background .12s;
}
.rotate-btn:hover { background: var(--bg3); }
.flip-btns { display: flex; gap: 8px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }

/* ── Responsive: make panel overlay on narrow screens ── */
@media (max-width: 720px) {
  #panel { width: 100%; position: absolute; right: 0; top: 0; bottom: 0; transform: translateX(100%); transition: transform .2s; z-index: 20; }
  #panel.open { transform: none; }
}
