/* ========================================================================
   style.css — Glassmorphism dark theme for Perspective Corrector
   ======================================================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
  --bg-deep: #08080e;
  --bg-surface: rgba(255, 255, 255, 0.04);
  --bg-glass: rgba(255, 255, 255, 0.06);
  --bg-glass-hover: rgba(255, 255, 255, 0.10);
  --bg-glass-active: rgba(255, 255, 255, 0.14);
  --border-glass: rgba(255, 255, 255, 0.10);
  --border-glass-hover: rgba(255, 255, 255, 0.18);
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #555568;

  --guide-v1: #22ff88;
  --guide-v2: #00c5ff;
  --guide-h1: #ffcc33;
  --guide-h2: #ff7f50;

  --accent: #7c6aff;
  --accent-glow: rgba(124, 106, 255, 0.25);
  --danger: #ff4466;
  --success: #22ff88;

  --glass-blur: 16px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 180ms ease;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto, Helvetica, Arial, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-deep);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* Subtle noise background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(124, 106, 255, 0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(0, 197, 255, 0.03) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ---------- App Layout ---------- */
.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--border-glass);
  z-index: 10;
  flex-shrink: 0;
}

.toolbar-brand {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-right: 12px;
  color: #f0f0ff;
  text-shadow:
    0 0 6px rgba(240, 240, 255, 0.6),
    0 0 18px rgba(220, 220, 255, 0.3),
    0 0 40px rgba(200, 200, 255, 0.15);
}

.toolbar-separator {
  width: 1px;
  height: 24px;
  background: var(--border-glass);
  margin: 0 4px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-glass-hover);
  border-color: var(--border-glass-hover);
  transform: translateY(-1px);
}

.btn:active {
  background: var(--bg-glass-active);
  transform: translateY(0);
}

.btn-icon {
  font-size: 14px;
  line-height: 1;
}

.btn-accent {
  background: rgba(124, 106, 255, 0.15);
  border-color: rgba(124, 106, 255, 0.3);
}

.btn-accent:hover {
  background: rgba(124, 106, 255, 0.25);
  border-color: rgba(124, 106, 255, 0.5);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-small {
  padding: 4px 10px;
  font-size: 11px;
}

.toolbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---------- Workspace ---------- */
.workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ---------- Canvas ---------- */
.canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none; /* prevent Chrome default gestures stealing pointer events */
}

#main-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-left: 1px solid var(--border-glass);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 5;
}

.sidebar-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 12px;
  transition: border-color var(--transition);
  min-width: 0;
  overflow: hidden;
}

.sidebar-section:hover {
  border-color: var(--border-glass-hover);
}

.sidebar-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

/* ---------- Guide list ---------- */
.guide-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 2px;
}

.guide-item:hover, .guide-item.active {
  background: var(--bg-glass-hover);
}

.guide-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}

.guide-label {
  font-size: 12px;
  font-weight: 500;
  flex: 1;
}

.guide-angle {
  font-size: 10px;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  color: var(--text-secondary);
}

/* ---------- Aspect Ratio Section ---------- */
.aspect-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.aspect-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  width: 16px;
  flex-shrink: 0;
}

.aspect-input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--border-glass);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition);
}

.aspect-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.aspect-input::placeholder {
  color: var(--text-muted);
}

.aspect-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.preset-btn {
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 500;
  border: 1px solid var(--border-glass);
  border-radius: 4px;
  background: var(--bg-glass);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.preset-btn:hover {
  background: var(--bg-glass-hover);
  color: var(--text-primary);
}

.preset-btn.active {
  background: rgba(124, 106, 255, 0.2);
  border-color: rgba(124, 106, 255, 0.4);
  color: var(--text-primary);
}

/* ---------- Options / Toggles ---------- */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.toggle-label {
  font-size: 11px;
  color: var(--text-secondary);
}

.toggle {
  position: relative;
  width: 34px;
  height: 18px;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 9px;
  cursor: pointer;
  transition: background var(--transition);
  border: none;
  outline: none;
}

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all var(--transition);
}

.toggle:checked {
  background: rgba(124, 106, 255, 0.4);
}

.toggle:checked::after {
  left: 18px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ---------- Status Bar ---------- */
.statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 5px 14px;
  background: var(--bg-glass);
  backdrop-filter: blur(var(--glass-blur));
  border-top: 1px solid var(--border-glass);
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
  z-index: 10;
}

.status-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-zoom {
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 10px;
  color: var(--text-muted);
}

.status-dims {
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 10px;
  color: var(--text-muted);
}

/* ---------- Drop Overlay ---------- */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 14, 0.85);
  backdrop-filter: blur(20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease;
}

.drop-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 60px 80px;
  border: 2px dashed rgba(124, 106, 255, 0.5);
  border-radius: var(--radius-lg);
  animation: dropPulse 2s ease-in-out infinite;
}

.drop-icon {
  font-size: 48px;
  filter: drop-shadow(0 0 20px var(--accent-glow));
}

.drop-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.drop-hint {
  font-size: 12px;
  color: var(--text-secondary);
}

@keyframes dropPulse {
  0%, 100% {
    border-color: rgba(124, 106, 255, 0.3);
    box-shadow: 0 0 30px rgba(124, 106, 255, 0.05);
  }
  50% {
    border-color: rgba(124, 106, 255, 0.6);
    box-shadow: 0 0 60px rgba(124, 106, 255, 0.15);
  }
}

/* ---------- Loupe ---------- */
.loupe {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  border: 2px solid var(--border-glass-hover);
  border-radius: var(--radius-md);
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  overflow: hidden;
  opacity: 0;
  transition: opacity 150ms ease;
}

.loupe.visible {
  opacity: 1;
}

#loupe-canvas {
  display: block;
  border-radius: calc(var(--radius-md) - 2px);
}

/* ---------- Progress Overlay ---------- */
.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(8, 8, 14, 0.8);
  backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.progress-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.progress-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.progress-bar-track {
  width: 280px;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--guide-v1), var(--accent));
  border-radius: 2px;
  transition: width 100ms linear;
}

/* ---------- Empty State ---------- */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  pointer-events: auto;
  cursor: pointer;
}

.empty-state-icon {
  font-size: 56px;
  opacity: 0.3;
}

.empty-state-text {
  font-size: 16px;
  font-weight: 500;
}

.empty-state-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Keyboard shortcut hints ---------- */
kbd {
  display: inline-block;
  padding: 1px 5px;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  border-radius: 3px;
  color: var(--text-secondary);
}

/* ---------- Export format selector ---------- */
.format-select {
  padding: 5px 8px;
  border: 1px solid var(--border-glass);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}

.format-select:focus {
  border-color: var(--accent);
}

.format-select option {
  background: #1a1a22;
  color: var(--text-primary);
}

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

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

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

/* ---------- Mobile sidebar toggle (hidden on desktop) ---------- */
.mobile-sidebar-toggle {
  display: none; /* shown via media query */
}

/* ---------- Responsive: Mobile ---------- */
@media (max-width: 768px) {

  /* ── Toolbar: compact icon-only ── */
  .toolbar {
    flex-wrap: wrap;
    padding: 6px 8px;
    gap: 4px;
  }

  .toolbar-brand {
    font-size: 12px;
    margin-right: 6px;
  }

  .toolbar-separator {
    display: none;
  }

  /* Hide button text, show icons only */
  .btn {
    padding: 8px 10px;
    font-size: 0;       /* hides text */
    gap: 0;
  }

  .btn .btn-icon {
    font-size: 16px;    /* keep icon visible */
  }

  .btn-small {
    padding: 6px 8px;
  }

  .btn-small .btn-icon {
    font-size: 14px;
  }

  .toolbar-right {
    margin-left: auto;
    gap: 4px;
  }

  /* ── Workspace: stack vertically ── */
  .workspace {
    flex-direction: column;
    position: relative;
  }

  .canvas-container {
    flex: 1;
    min-height: 0;
  }

  /* ── Sidebar: slide-up bottom sheet ── */
  .sidebar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 70vh;
    border-left: none;
    border-top: 1px solid var(--border-glass);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 50;
    transform: translateY(100%);
    transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
    padding: 12px 12px env(safe-area-inset-bottom, 48px);
    gap: 6px;
    /* Glass bg with enough opacity to stay readable over bright images */
    background: rgba(12, 12, 20, 0.65);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  .sidebar::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    margin: 0 auto 8px;
    flex-shrink: 0;
  }

  .sidebar.mobile-open {
    transform: translateY(0);
  }

  /* Brighter text in mobile sidebar for contrast over any background */
  .sidebar .sidebar-title {
    color: rgba(255, 255, 255, 0.7);
  }
  .sidebar .toggle-label,
  .sidebar .aspect-label,
  .sidebar .guide-label,
  .sidebar .guide-angle {
    color: rgba(255, 255, 255, 0.85);
  }

  .sidebar-section {
    padding: 10px;
  }

  /* ── Floating gear toggle ── */
  .mobile-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    bottom: 24px;
    right: 16px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--border-glass-hover);
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
    z-index: 40;
    box-shadow:
      0 4px 20px rgba(0, 0, 0, 0.4),
      0 0 0 1px rgba(255, 255, 255, 0.06);
    transition: all var(--transition);
  }

  .mobile-sidebar-toggle:hover,
  .mobile-sidebar-toggle:active {
    background: var(--bg-glass-active);
    transform: scale(1.08);
  }

  .mobile-sidebar-toggle.active {
    background: rgba(124, 106, 255, 0.25);
    border-color: rgba(124, 106, 255, 0.5);
    box-shadow: 0 4px 24px var(--accent-glow);
  }

  /* ── Backdrop overlay behind open sidebar ── */
  .sidebar-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 45;
    opacity: 0;
    pointer-events: none;
    transition: opacity 300ms ease;
  }

  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* ── Status bar: compact ── */
  .statusbar {
    padding: 4px 10px;
    font-size: 10px;
    gap: 8px;
  }

  /* ── Hide shortcuts section on mobile (no keyboard) ── */
  .sidebar-section:last-child {
    display: none;
  }

  /* ── Loupe: smaller on mobile, repositioned above finger ── */
  .loupe {
    transform: scale(0.65);
    transform-origin: top left;
  }

  /* ── Drop overlay: mobile-friendly sizing ── */
  .drop-zone {
    padding: 40px 32px;
  }

  .drop-icon {
    font-size: 36px;
  }

  .drop-text {
    font-size: 15px;
  }

  .drop-hint {
    font-size: 11px;
  }

  /* ── Empty state: smaller on mobile ── */
  .empty-state-icon {
    font-size: 40px;
  }

  .empty-state-text {
    font-size: 14px;
  }

  .empty-state-hint {
    font-size: 11px;
  }
}

/* ---------- Very small screens (phone portrait) ---------- */
@media (max-width: 420px) {
  .toolbar-brand {
    display: none;
  }

  .toolbar {
    justify-content: center;
  }

  .sidebar {
    max-height: 65vh;
  }

  .mobile-sidebar-toggle {
    bottom: 12px;
    right: 12px;
    width: 42px;
    height: 42px;
    font-size: 20px;
  }
}
