/* ========================================
   🌊 Underwater Photo Editor — Ocean Dark Theme
   ========================================
   Color Palette:
   - Deep Sea:       #051827  (darkest bg)
   - Ocean Night:    #0a1f35  (panel bg)
   - Deep Water:     #0d2b4a  (elevated surface)
   - Turquoise:      #00d4ff  (primary accent)
   - Cyan Glow:      #4fc3f7  (secondary accent)
   - Coral Warm:     #ff7e5f  (highlight/warning)
   - Sunlight:       #ffc947  (action/positive)
   - Foam:           #e3f2fd  (main text)
   - Mist:           #90caf9  (muted text)
   ======================================== */

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Pretendard', 'Apple SD Gothic Neo', sans-serif;
  font-size: 14px;
  background: linear-gradient(180deg, #051827 0%, #0a1f35 100%);
  color: #e3f2fd;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* ========== Header ========== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: rgba(10, 31, 53, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0, 212, 255, 0.15);
  flex-shrink: 0;
}

.title-group {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
  color: #e3f2fd;
  letter-spacing: -0.2px;
}

.app-header h1 .icon {
  margin-right: 6px;
}

.version {
  font-size: 11px;
  color: #90caf9;
  opacity: 0.7;
}

.status {
  display: inline-block;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.status.idle {
  background: rgba(0, 212, 255, 0.1);
  color: #4fc3f7;
  border: 1px solid rgba(0, 212, 255, 0.3);
}

.status.processing {
  background: rgba(255, 201, 71, 0.1);
  color: #ffc947;
  border: 1px solid rgba(255, 201, 71, 0.3);
}

.status.ready {
  background: rgba(102, 217, 163, 0.1);
  color: #66d9a3;
  border: 1px solid rgba(102, 217, 163, 0.3);
}

/* ========== Main Layout ========== */
.app-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ========== Control Panel (Left) ========== */
.control-panel {
  width: 320px;
  flex-shrink: 0;
  background: rgba(13, 43, 74, 0.4);
  border-right: 1px solid rgba(0, 212, 255, 0.12);
  overflow-y: auto;
  padding: 16px;
}

.control-panel::-webkit-scrollbar {
  width: 6px;
}

.control-panel::-webkit-scrollbar-track {
  background: transparent;
}

.control-panel::-webkit-scrollbar-thumb {
  background: rgba(0, 212, 255, 0.2);
  border-radius: 3px;
}

.panel-section {
  margin-bottom: 20px;
}

.panel-section:last-child {
  margin-bottom: 0;
}

.panel-title {
  font-size: 11px;
  font-weight: 600;
  color: #4fc3f7;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
  padding-left: 2px;
}

/* ========== Dropzone ========== */
.dropzone {
  border: 2px dashed rgba(0, 212, 255, 0.3);
  border-radius: 10px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: rgba(0, 212, 255, 0.03);
}

.dropzone:hover {
  border-color: rgba(0, 212, 255, 0.6);
  background: rgba(0, 212, 255, 0.06);
}

.dropzone.dragover {
  border-color: #00d4ff;
  background: rgba(0, 212, 255, 0.12);
  transform: scale(1.02);
}

.dropzone-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.dropzone-text {
  color: #e3f2fd;
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 4px;
}

.dropzone-hint {
  color: #90caf9;
  font-size: 10px;
  opacity: 0.6;
}

.file-info {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(0, 212, 255, 0.08);
  border-radius: 6px;
  font-size: 11px;
  display: flex;
  justify-content: space-between;
  color: #90caf9;
}

/* ========== Preset Buttons ========== */
.preset-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.preset-btn {
  padding: 10px 4px;
  background: rgba(13, 43, 74, 0.6);
  border: 1px solid rgba(0, 212, 255, 0.2);
  border-radius: 8px;
  color: #e3f2fd;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
  font-family: inherit;
}

.preset-btn:hover {
  background: rgba(0, 212, 255, 0.1);
  border-color: rgba(0, 212, 255, 0.5);
  transform: translateY(-1px);
}

.preset-btn.active {
  background: rgba(0, 212, 255, 0.15);
  border-color: #00d4ff;
  box-shadow: 0 0 0 1px #00d4ff, 0 0 12px rgba(0, 212, 255, 0.3);
}

.preset-icon {
  display: block;
  font-size: 18px;
  margin-bottom: 3px;
}

.preset-label {
  font-size: 10px;
  line-height: 1.3;
}

.preset-label small {
  color: #90caf9;
  font-size: 9px;
  opacity: 0.7;
}

/* ========== Panel title row (title + icon button) ========== */
.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.panel-title-row .panel-title {
  margin-bottom: 0;
}

.icon-btn {
  width: 22px;
  height: 22px;
  padding: 0;
  background: rgba(0, 212, 255, 0.15);
  border: 1px solid rgba(0, 212, 255, 0.35);
  border-radius: 50%;
  color: #00d4ff;
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.icon-btn:hover {
  background: rgba(0, 212, 255, 0.28);
  border-color: #00d4ff;
  transform: scale(1.08);
}

/* ========== Custom presets ========== */
.custom-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.custom-preset-btn {
  position: relative;
  padding: 8px 28px 8px 10px;
  background: rgba(13, 43, 74, 0.55);
  border: 1px solid rgba(0, 212, 255, 0.18);
  border-radius: 6px;
  color: #e3f2fd;
  font-family: inherit;
  font-size: 11px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-preset-btn:hover {
  background: rgba(0, 212, 255, 0.1);
  border-color: rgba(0, 212, 255, 0.45);
}

.custom-preset-btn.active {
  background: rgba(0, 212, 255, 0.2);
  border-color: #00d4ff;
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.3);
}

.custom-preset-btn .delete {
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 126, 95, 0.15);
  color: #ff9e7f;
  font-family: inherit;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}

.custom-preset-btn:hover .delete {
  opacity: 1;
}

.custom-preset-btn .delete:hover {
  background: rgba(255, 126, 95, 0.4);
  color: #ffffff;
}

.custom-presets-empty {
  grid-column: 1 / -1;
  font-size: 11px;
  color: #90caf9;
  opacity: 0.55;
  text-align: center;
  padding: 14px 8px;
  line-height: 1.5;
  border: 1px dashed rgba(0, 212, 255, 0.15);
  border-radius: 6px;
}

.custom-presets-empty b {
  color: #4fc3f7;
}

/* ========== Histogram ========== */
#histogram {
  width: 100%;
  height: 80px;
  display: block;
  background: linear-gradient(180deg, rgba(5, 24, 39, 0.9), rgba(10, 31, 53, 0.9));
  border: 1px solid rgba(0, 212, 255, 0.15);
  border-radius: 6px;
}

/* ========== Sliders ========== */
.slider-group {
  margin-bottom: 14px;
  padding: 10px 12px;
  background: rgba(13, 43, 74, 0.3);
  border-radius: 8px;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}

.slider-group:hover {
  border-color: rgba(0, 212, 255, 0.15);
}

.slider-group.highlighted {
  background: rgba(255, 126, 95, 0.08);
  border-color: rgba(255, 126, 95, 0.2);
}

.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #e3f2fd;
  margin-bottom: 6px;
}

.slider-label small {
  color: #90caf9;
  font-size: 10px;
  font-weight: normal;
  opacity: 0.65;
  margin-left: 2px;
}

.slider-label .star {
  color: #ff7e5f;
  margin-left: 4px;
}

.slider-value {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 11px;
  color: #4fc3f7;
  font-weight: 600;
  min-width: 32px;
  text-align: right;
}

.slider {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(0, 212, 255, 0.2);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00d4ff 0%, #4fc3f7 100%);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.5);
  transition: transform 0.1s;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #00d4ff 0%, #4fc3f7 100%);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.5);
}

/* ========== Action Buttons ========== */
.export-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  padding: 10px 12px;
  background: rgba(13, 43, 74, 0.3);
  border-radius: 8px;
  border: 1px solid rgba(0, 212, 255, 0.1);
}

.export-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: #e3f2fd;
}

.export-label {
  flex-shrink: 0;
  min-width: 52px;
  font-size: 11px;
  color: #90caf9;
}

.select-mini {
  flex: 1;
  padding: 5px 8px;
  background: rgba(5, 24, 39, 0.8);
  border: 1px solid rgba(0, 212, 255, 0.25);
  border-radius: 5px;
  color: #e3f2fd;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  outline: none;
}

.select-mini:hover {
  border-color: rgba(0, 212, 255, 0.5);
}

.quality-row {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}

.quality-row .slider-label {
  display: flex;
  justify-content: space-between;
}

.slider-mini {
  margin-top: 2px;
}

.quality-row.hidden {
  display: none;
}

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

.btn {
  flex: 1;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%);
  color: #051827;
  box-shadow: 0 2px 8px rgba(0, 212, 255, 0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 212, 255, 0.5);
}

.btn-primary:disabled {
  background: rgba(0, 212, 255, 0.2);
  color: rgba(227, 242, 253, 0.3);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: rgba(0, 212, 255, 0.08);
  color: #90caf9;
  border: 1px solid rgba(0, 212, 255, 0.2);
}

.btn-secondary:hover {
  background: rgba(0, 212, 255, 0.15);
  border-color: rgba(0, 212, 255, 0.4);
}

/* ========== Preview Area (Right) ========== */
.preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at center, #0a2540 0%, #051827 100%);
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: rgba(5, 24, 39, 0.6);
  border-bottom: 1px solid rgba(0, 212, 255, 0.1);
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  gap: 4px;
}

.toolbar-btn {
  padding: 6px 12px;
  background: transparent;
  color: #90caf9;
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.toolbar-btn:hover {
  background: rgba(0, 212, 255, 0.08);
  color: #e3f2fd;
}

.toolbar-btn.active {
  background: rgba(0, 212, 255, 0.15);
  color: #00d4ff;
  border-color: rgba(0, 212, 255, 0.3);
}

.toolbar-info {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 11px;
  color: #90caf9;
  opacity: 0.7;
}

.preview-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.preview-canvas-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: hidden;
}

.preview-placeholder {
  text-align: center;
  color: #90caf9;
  opacity: 0.5;
}

.placeholder-icon {
  font-size: 48px;
  margin-bottom: 12px;
  letter-spacing: 4px;
  animation: swim 4s ease-in-out infinite;
}

@keyframes swim {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(8px); }
}

.preview-canvas-container {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
  max-height: 100%;
  --split-pos: 50%;
}

.preview-canvas-container canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 200px);
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(0, 212, 255, 0.2);
}

#canvas-before {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  clip-path: inset(0 calc(100% - var(--split-pos)) 0 0);
  pointer-events: none;
  z-index: 2;
}

#canvas-after {
  position: relative;
  z-index: 1;
}

/* Single (After only) view */
.preview-canvas-container.single-view #canvas-before,
.preview-canvas-container.single-view .split-handle,
.preview-canvas-container.single-view .label-before {
  display: none;
}

/* Before only view */
.preview-canvas-container.before-view #canvas-before {
  clip-path: none;                  /* Full image visible */
}
.preview-canvas-container.before-view .split-handle,
.preview-canvas-container.before-view .label-after {
  display: none;
}

/* Split handle */
.split-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--split-pos);
  width: 2px;
  background: #00d4ff;
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.6);
  cursor: ew-resize;
  transform: translateX(-50%);
  z-index: 10;
  touch-action: none;
}

.handle-line {
  position: absolute;
  inset: 0;
  width: 2px;
  background: #00d4ff;
}

.handle-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #00d4ff;
  color: #051827;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.6), 0 2px 8px rgba(0, 0, 0, 0.3);
  user-select: none;
  transition: transform 0.1s, box-shadow 0.15s;
}

.split-handle:hover .handle-knob,
.split-handle.dragging .handle-knob {
  transform: translate(-50%, -50%) scale(1.15);
  box-shadow: 0 0 28px rgba(0, 212, 255, 0.9), 0 2px 12px rgba(0, 0, 0, 0.4);
}

.label-before,
.label-after {
  position: absolute;
  top: 12px;
  padding: 4px 10px;
  background: rgba(5, 24, 39, 0.85);
  backdrop-filter: blur(8px);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  color: #e3f2fd;
  z-index: 5;
}

.label-before { left: 12px; }
.label-after  { right: 12px; color: #00d4ff; }

/* ========== Side Toolbar (Crop & future tools) ========== */
.side-toolbar {
  width: 64px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 8px;
  background: rgba(5, 24, 39, 0.6);
  border-left: 1px solid rgba(0, 212, 255, 0.12);
  overflow-y: auto;
}

.side-toolbar::-webkit-scrollbar {
  width: 4px;
}
.side-toolbar::-webkit-scrollbar-thumb {
  background: rgba(0, 212, 255, 0.2);
  border-radius: 2px;
}

.side-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  background: rgba(13, 43, 74, 0.5);
  border: 1px solid rgba(0, 212, 255, 0.15);
  border-radius: 6px;
  color: #e3f2fd;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.side-btn:hover:not(:disabled) {
  background: rgba(0, 212, 255, 0.12);
  border-color: rgba(0, 212, 255, 0.4);
}

.side-btn.active {
  background: rgba(0, 212, 255, 0.18);
  border-color: #00d4ff;
  box-shadow: 0 0 10px rgba(0, 212, 255, 0.35);
}

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

.side-btn.danger {
  background: rgba(255, 126, 95, 0.08);
  border-color: rgba(255, 126, 95, 0.25);
  color: #ff9e7f;
}

.side-btn.danger:hover:not(:disabled) {
  background: rgba(255, 126, 95, 0.18);
  border-color: rgba(255, 126, 95, 0.5);
}

.side-icon {
  font-size: 16px;
  line-height: 1;
}

.side-label {
  font-size: 9px;
  letter-spacing: 0.5px;
}

.side-sep {
  border: none;
  border-top: 1px solid rgba(0, 212, 255, 0.15);
  margin: 4px 2px;
}

.side-btn.positive {
  background: rgba(102, 217, 163, 0.1);
  border-color: rgba(102, 217, 163, 0.35);
  color: #66d9a3;
}
.side-btn.positive:hover:not(:disabled) {
  background: rgba(102, 217, 163, 0.22);
  border-color: rgba(102, 217, 163, 0.6);
}

.side-btn.ratio-btn.active {
  background: rgba(0, 212, 255, 0.2);
  border-color: #00d4ff;
  color: #00d4ff;
}

/* Side-toolbar inline slider (used for brush size) */
.side-slider-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 2px;
  text-align: center;
}

.side-slider-label {
  font-size: 9px;
  color: #90caf9;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.side-slider-value {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 11px;
  color: #4fc3f7;
  font-weight: 600;
}

.side-slider {
  width: 100%;
  height: 3px;
  margin: 2px 0;
}

/* ========== Crop Overlay ========== */
.crop-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  user-select: none;
  touch-action: none;
}

.crop-box {
  position: absolute;
  border: 1px solid #00d4ff;
  /* Darken everything outside this box using a huge outward shadow */
  box-shadow: 0 0 0 9999px rgba(5, 24, 39, 0.65);
  cursor: move;
}

.crop-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  pointer-events: none;
}

.crop-grid > div {
  border: 0.5px solid rgba(0, 212, 255, 0.25);
}

.crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #00d4ff;
  border: 2px solid #051827;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.7);
}

.crop-handle[data-handle="nw"] { top: -7px; left:  -7px; cursor: nwse-resize; }
.crop-handle[data-handle="ne"] { top: -7px; right: -7px; cursor: nesw-resize; }
.crop-handle[data-handle="sw"] { bottom: -7px; left:  -7px; cursor: nesw-resize; }
.crop-handle[data-handle="se"] { bottom: -7px; right: -7px; cursor: nwse-resize; }

/* Hide split handle, labels, after canvas interaction while cropping */
.preview-canvas-container.cropping .split-handle,
.preview-canvas-container.cropping .label-before,
.preview-canvas-container.cropping .label-after {
  display: none;
}

/* ========== Spot Heal Brush Cursor ========== */
.preview-canvas-container.spotting {
  cursor: none;  /* hide system cursor; the brush ring is the cursor */
}

.preview-canvas-container.spotting .split-handle,
.preview-canvas-container.spotting .label-before,
.preview-canvas-container.spotting .label-after {
  display: none;
}

.brush-cursor {
  position: absolute;
  pointer-events: none;
  border: 1px solid #4fc3f7;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 15;
}

/* ========== Footer ========== */
.app-footer {
  padding: 8px 24px;
  background: rgba(5, 24, 39, 0.8);
  border-top: 1px solid rgba(0, 212, 255, 0.1);
  text-align: center;
  font-size: 11px;
  color: #90caf9;
  opacity: 0.6;
  flex-shrink: 0;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .app-main {
    flex-direction: column;
  }
  .control-panel {
    width: 100%;
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid rgba(0, 212, 255, 0.12);
  }
}
