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

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --accent: #e94560;
  --accent2: #0f3460;
  --text: #e8e8f0;
  --text-muted: #8888aa;
  --border: #2a2a4a;
  --handle: #ffd700;
  --handle-stroke: #ff8c00;
  --success: #4caf50;
  --radius: 12px;
  --touch-target: 48px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== Header ===== */
.app-header {
  background: var(--surface2);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.3px;
}

.step-indicator {
  display: flex;
  gap: 6px;
  align-items: center;
}

.step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s;
}

.step-dot.active {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

.step-dot.done {
  background: var(--success);
}

/* ===== Main Content ===== */
.app-main {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.step {
  display: none;
  flex-direction: column;
  height: 100%;
  padding: 16px;
  gap: 14px;
  overflow-y: auto;
}

.step.active {
  display: flex;
}

/* ===== Import Step ===== */
.import-tip {
  background: var(--surface2);
  border: 1px solid var(--accent2);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  flex-shrink: 0;
}

.import-tip strong {
  color: var(--text);
}

.import-zone {
  flex: 1;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  /* padding: 24px; */
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  min-height: 200px;
}

.import-zone:active {
  border-color: var(--accent);
  background: rgba(233,69,96,0.07);
}

.import-icon {
  font-size: 56px;
  line-height: 1;
}

.import-zone p {
  font-size: 15px;
  color: var(--text-muted);
  text-align: center;
}

.import-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

/* ===== Buttons ===== */
.btn {
  min-height: var(--touch-target);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 20px;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  opacity: 0.8;
  transform: scale(0.97);
}

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

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}

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

/* ===== Corner Edit Step ===== */
.corner-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000;
  min-height: 200px;
}

#sourceCanvas {
  position: absolute;
  display: block;
  pointer-events: none;
}

#overlayCanvas {
  position: absolute;
  touch-action: none;
  cursor: crosshair;
}

.corner-hint {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
}

.corner-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.corner-actions .btn {
  flex: 1;
}

/* ===== Adjust Step ===== */
.result-wrap {
  flex: 1;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

#resultCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.sliders-panel {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.sliders-panel h3 {
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 2px;
}

.slider-row {
  display: grid;
  grid-template-columns: 90px 1fr 44px;
  align-items: center;
  gap: 10px;
}

.slider-label {
  font-size: 13px;
  color: var(--text);
}

.slider-value {
  font-size: 13px;
  color: var(--accent);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
}

.slider-reset {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  cursor: pointer;
  text-decoration: underline;
}

.adjust-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.adjust-actions .btn {
  flex: 1;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 10px 22px;
  font-size: 14px;
  z-index: 999;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  white-space: nowrap;
  pointer-events: none;
  max-width: 90vw;
  white-space: normal;
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ===== Processing overlay ===== */
.processing-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

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

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.processing-overlay p {
  color: var(--text);
  font-size: 15px;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ===== Safe area ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .step {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ===== Magnifier loupe ===== */
.magnifier {
  position: fixed;
  display: none;
  border-radius: 50%;
  pointer-events: none;
  z-index: 300;
  box-shadow:
    0 0 0 3px #ffd700,
    0 6px 20px rgba(0, 0, 0, 0.8);
}
