:root {
  --bg: #0e0f12;
  --surface: #171920;
  --surface-2: #222530;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f3f4f8;
  --muted: #9aa0b2;
  --accent: #ff6b6b;
  --accent-2: #feca57;
  --good: #2ecc71;
  --warn: #f39c12;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  background: var(--bg);
}

/* Header */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: rgba(14, 15, 18, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 10px rgba(255, 107, 107, 0.6);
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  line-height: 1.15;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
  max-width: 170px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent-2);
}

/* Main View Container */
.main-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.view {
  display: none;
  min-height: 100%;
  padding: 12px 12px 24px;
}

.view.active {
  display: block;
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  color: var(--text);
  background: none;
}

.btn-primary {
  background: linear-gradient(135deg, #ff6b6b, #ff8e53);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.28);
  transition: transform 0.12s ease;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  padding: 9px 12px;
  border-radius: 10px;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 600;
  border-radius: 10px;
  padding: 7px 11px;
}

.btn-sm {
  font-size: 12px;
  padding: 6px 10px;
}

.btn-xs {
  font-size: 12px;
  padding: 5px 8px;
}

.btn-lg {
  font-size: 16px;
  padding: 14px 24px;
  width: 100%;
  max-width: 280px;
}

.btn-full {
  width: 100%;
}

.btn-link {
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 600;
}

/* Empty State */
.empty-card {
  margin: 28px auto;
  padding: 28px 20px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}

.empty-card.compact {
  padding: 22px 16px;
}

.empty-icon {
  font-size: 46px;
  margin-bottom: 10px;
}

.empty-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.empty-card p {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

.feature-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.feature-chips span {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: #cfd5e6;
}

/* Scan Progress */
.scan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}

.scan-header {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 10px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.15s ease;
}

.scan-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* Run Smart Pick Banner (Lightroom two-stage pipeline) */
.run-pick-banner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid rgba(254, 202, 87, 0.35);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.run-pick-actions {
  display: grid;
  grid-template-columns: 1fr 1.15fr 0.85fr;
  gap: 6px;
}

.run-pick-actions button {
  padding: 8px 5px;
  font-size: 11px;
  white-space: nowrap;
}

.run-pick-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.run-pick-info strong {
  font-size: 13px;
  color: var(--accent-2);
}

.last-import-marker {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  margin-bottom: 10px;
}

.last-import-marker img {
  width: 34px;
  height: 42px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.last-import-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.last-import-text strong {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.load-more-wrap {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
}

/* Picker Toolbar */
.picker-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.quick-pick-row {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.quick-pick-row::-webkit-scrollbar {
  display: none;
}

.label-muted {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.chip-btn {
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: #dbe0ee;
}

.chip-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: 11px;
  border: 1px solid var(--border);
}

.seg-btn {
  padding: 7px 6px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  color: var(--muted);
}

.seg-btn.active {
  background: var(--surface-2);
  color: var(--text);
}

/* Photo Grid */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding-bottom: 72px;
}

.group-header {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-2);
  padding: 10px 4px 4px;
}

.photo-card {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  border: 2px solid transparent;
  cursor: pointer;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  content-visibility: auto;
  contain-intrinsic-size: 120px 160px;
}

.photo-card.selected {
  border-color: var(--accent);
}

.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  pointer-events: none;
}

.photo-zoom-btn {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.photo-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
}

.photo-card.selected .photo-check {
  background: var(--accent);
  border-color: var(--accent);
}

.photo-score {
  position: absolute;
  left: 5px;
  bottom: 5px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.68);
  color: #fff;
}

.photo-tag {
  position: absolute;
  left: 5px;
  top: 5px;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(46, 204, 113, 0.88);
  color: #092012;
}

.photo-tag.warn {
  background: rgba(243, 156, 18, 0.9);
  color: #1f1300;
}

.sticky-cta {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(66px + var(--safe-bottom));
  width: calc(100% - 24px);
  max-width: 576px;
  z-index: 15;
}

/* Ultra-compact Editor Mode: maximize photo preview & settings space */
body.mode-editor .top-bar {
  padding: calc(4px + var(--safe-top)) 10px 4px;
}

body.mode-editor .brand h1 {
  display: none;
}

body.mode-editor .brand-sub {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  max-width: 190px;
}

body.mode-editor .bottom-nav {
  padding: 3px 6px calc(3px + var(--safe-bottom));
}

body.mode-editor .nav-btn {
  flex-direction: row;
  gap: 4px;
  padding: 5px 4px;
  font-size: 11px;
}

body.mode-editor .nav-btn .nav-ico {
  font-size: 14px;
}

/* STEP 2: EDITOR — Pinned Preview + Independent Scrollable Settings (Lightroom style) */
#view-editor.active {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  padding: 5px 8px 4px;
}

.editor-workspace {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.editor-controls-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 10px;
}

.thumb-strip {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding-bottom: 5px;
  flex-shrink: 0;
  scrollbar-width: none;
}

.thumb-strip::-webkit-scrollbar {
  display: none;
}

.thumb-item {
  width: 36px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
  position: relative;
}

.thumb-item.active {
  border-color: var(--accent-2);
}

.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--good);
}

.repair-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 10px;
  margin-bottom: 5px;
  border-radius: 8px;
  background: rgba(254, 202, 87, 0.14);
  border: 1px solid rgba(254, 202, 87, 0.45);
  font-size: 11px;
  color: var(--accent-2);
  flex-shrink: 0;
}

.repair-banner.hidden {
  display: none;
}

.canvas-stage {
  position: relative;
  width: 100%;
  height: 46dvh;
  min-height: 240px;
  max-height: 460px;
  flex-shrink: 0;
  background: #050608;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.crop-grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, transparent 33.1%, rgba(255, 255, 255, 0.35) 33.3%, transparent 33.6%, transparent 66.4%, rgba(255, 255, 255, 0.35) 66.6%, transparent 66.9%),
    linear-gradient(to bottom, transparent 33.1%, rgba(255, 255, 255, 0.35) 33.3%, transparent 33.6%, transparent 66.4%, rgba(255, 255, 255, 0.35) 66.6%, transparent 66.9%);
  border: 1px solid rgba(254, 202, 87, 0.45);
}

#editorCanvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  touch-action: none;
}

.stage-floating-top {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.stage-floating-right {
  display: flex;
  gap: 6px;
}

.ai-status-badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  font-size: 10px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(14, 15, 18, 0.78);
  border: 1px solid rgba(254, 202, 87, 0.35);
  color: var(--accent-2);
  backdrop-filter: blur(6px);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill-btn {
  pointer-events: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(14, 15, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(6px);
}

/* Leg Stretch Overlay */
.leg-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.leg-zone {
  position: absolute;
  left: 0;
  right: 0;
  background: rgba(254, 202, 87, 0.14);
  border-top: 1px dashed rgba(254, 202, 87, 0.7);
  border-bottom: 1px dashed rgba(254, 202, 87, 0.7);
}

.leg-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent-2);
  pointer-events: auto;
  cursor: ns-resize;
  touch-action: none;
}

.leg-line::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -16px;
  bottom: -16px;
}

.leg-handle {
  position: absolute;
  right: 10px;
  top: -12px;
  font-size: 10px;
  font-weight: 700;
  background: var(--accent-2);
  color: #161204;
  padding: 2px 8px;
  border-radius: 999px;
}

.brush-cursor {
  position: absolute;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

/* Editor Quick Actions Bar */
.editor-quick-bar {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1.1fr 0.85fr;
  gap: 6px;
  margin-top: 8px;
}

.editor-quick-bar button {
  padding: 8px 4px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-quick-bar button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-danger-soft {
  background: rgba(255, 82, 82, 0.16);
  color: #ff8a8a;
  border: 1px solid rgba(255, 82, 82, 0.3);
}

.paste-card {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
}

.paste-card.picked {
  border-color: var(--accent-2);
}

.paste-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
}

.paste-check {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.75);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.paste-card.picked .paste-check {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #161204;
}

/* Tool Tabs */
.tool-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin: 8px 0 6px;
  flex-shrink: 0;
}

.tool-tab {
  font-size: 11px;
  font-weight: 600;
  padding: 8px 2px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}

.tool-tab.active {
  background: var(--surface-2);
  border-color: var(--accent);
  color: #fff;
}

.tool-panels {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 10px;
}

.tool-panel {
  display: none;
}

.tool-panel.active {
  display: block;
}

.panel-tip {
  display: none;
}

.slim-modes {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.slider-row {
  margin-bottom: 10px;
}

.slider-row:last-child {
  margin-bottom: 0;
}

.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #d6dbe8;
  margin-bottom: 4px;
}

.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 22px;
  margin: 0;
}

.slider-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.preset-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: none;
}

.preset-strip::-webkit-scrollbar {
  display: none;
}

.preset-chip {
  flex-shrink: 0;
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: #dbe0ee;
}

.preset-chip.active {
  background: linear-gradient(135deg, var(--accent), #ff8e53);
  border-color: transparent;
  color: #fff;
}

.panel-actions-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.editor-export-bar {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 8px;
  margin-top: 10px;
}

.editor-export-bar button {
  font-size: 13px;
  padding: 11px 10px;
}

/* STEP 3: COLLAGE */
.ratio-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.collage-stage-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #07080a;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  height: 44dvh;
  min-height: 260px;
  max-height: 430px;
  touch-action: none;
}

#collageCanvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  touch-action: none;
}

.slot-control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 8px 0;
  padding: 7px 10px;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border);
  min-height: 38px;
}

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

.slot-btns {
  display: flex;
  gap: 4px;
}

.section-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #d6dbe8;
  margin: 8px 2px 6px;
}

.layout-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.layout-strip::-webkit-scrollbar {
  display: none;
}

.layout-card {
  flex-shrink: 0;
  width: 68px;
  padding: 6px;
  border-radius: 10px;
  background: var(--surface);
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.layout-card.active {
  border-color: var(--accent-2);
  background: var(--surface-2);
}

.layout-card svg {
  width: 40px;
  height: 54px;
}

.layout-card span {
  font-size: 10px;
  color: #cfd5e6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.collage-style-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  margin-top: 4px;
}

.style-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.color-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
}

.swatch.active {
  border-color: var(--accent);
  transform: scale(1.15);
}

.caption-row input {
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  outline: none;
  margin-top: 8px;
}

.export-bar {
  margin-top: 12px;
}

/* Bottom Navigation */
.bottom-nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(20, 22, 28, 0.96);
  border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + var(--safe-bottom));
  z-index: 20;
}

/* Projects Hub */
.projects-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.projects-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.projects-search-row input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding-bottom: 24px;
}

.project-empty {
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.project-card.current {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px rgba(254, 202, 87, 0.3);
}

.project-cover-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #0a0b0e;
  overflow: hidden;
  cursor: pointer;
}

.project-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.project-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(14, 15, 18, 0.8);
  color: var(--accent-2);
  backdrop-filter: blur(4px);
}

.project-badge.exported {
  background: rgba(46, 204, 113, 0.9);
  color: #062111;
}

.project-card-body {
  padding: 9px 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.project-card-title {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-card-meta {
  font-size: 11px;
  color: var(--muted);
}

.project-card-actions {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 4px;
  margin-top: 2px;
}

.project-card-actions button {
  padding: 6px 6px;
  font-size: 11px;
  border-radius: 8px;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 10px;
}

.nav-btn .nav-ico {
  font-size: 18px;
}

.nav-btn.active {
  color: var(--accent-2);
  background: rgba(254, 202, 87, 0.08);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-sheet {
  width: 100%;
  max-width: 600px;
  max-height: 75dvh;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  overflow-y: auto;
  padding-bottom: 16px;
}

.modal-photo-grid img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 10px;
  cursor: pointer;
}

/* History Modal */
.history-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding-bottom: 12px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.history-item.current {
  border-color: var(--accent-2);
}

.history-thumb {
  width: 48px;
  height: 58px;
  border-radius: 8px;
  object-fit: cover;
  background: #0e0f12;
  flex-shrink: 0;
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-title {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.history-actions {
  display: flex;
  gap: 6px;
}

/* Full-res Lightbox Inspector */
.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: rgba(6, 7, 10, 0.98);
  z-index: 80;
  display: flex;
  flex-direction: column;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: none;
}

.lightbox-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: rgba(14, 15, 18, 0.92);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 3;
}

.lightbox-meta {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox-top-btns {
  display: flex;
  gap: 6px;
}

.lightbox-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

#lbImage {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  -webkit-touch-callout: none;
  pointer-events: none;
}

.lightbox-bottom {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  gap: 8px;
  padding: 10px 12px calc(12px + var(--safe-bottom));
  background: rgba(14, 15, 18, 0.9);
  border-top: 1px solid var(--border);
}

.lightbox-bottom button {
  font-size: 13px;
  padding: 11px 8px;
}

/* Tinder-style Swipe Culling Modal */
.swipe-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  background: #08090d;
  z-index: 88;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: none;
}

.swipe-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 8px;
  flex-shrink: 0;
}

.swipe-progress {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-2);
}

.swipe-done-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.swipe-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  overflow: hidden;
}

.swipe-card {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 520px;
  background: #11131a;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.65);
  will-change: transform;
  touch-action: none;
}

.swipe-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  transition: transform 0.16s ease;
}

.swipe-stamp {
  position: absolute;
  top: 26px;
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.8px;
  opacity: 0;
  pointer-events: none;
  border: 3px solid currentColor;
  background: rgba(0, 0, 0, 0.55);
}

.swipe-stamp.keep {
  left: 20px;
  color: #2ecc71;
  transform: rotate(-10deg);
}

.swipe-stamp.drop {
  right: 20px;
  color: #ff5e5e;
  transform: rotate(10deg);
}

.swipe-card-meta {
  position: absolute;
  left: 10px;
  bottom: 10px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.68);
  color: #e8ecf8;
}

.swipe-hint-bar {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 4px 10px 6px;
  flex-shrink: 0;
}

.swipe-controls {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 1.2fr;
  gap: 10px;
  padding: 4px 14px calc(12px + var(--safe-bottom));
  flex-shrink: 0;
}

.swipe-btn {
  padding: 13px 10px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 800;
}

.swipe-btn.drop {
  background: rgba(255, 94, 94, 0.18);
  border: 1px solid rgba(255, 94, 94, 0.45);
  color: #ff7a7a;
}

.swipe-btn.undo {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: #dbe0ee;
}

.swipe-btn.keep {
  background: rgba(46, 204, 113, 0.2);
  border: 1px solid rgba(46, 204, 113, 0.5);
  color: #4be38a;
}

/* Global Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 11, 15, 0.78);
  backdrop-filter: blur(4px);
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 210px;
  max-width: 82vw;
  text-align: center;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--accent-2);
  animation: spin 0.75s linear infinite;
}

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

.loading-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: pre-line;
  line-height: 1.45;
}

/* Toast */
.toast {
  position: fixed;
  top: calc(62px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 31, 40, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}

/* v42: AI Đánh flash qua Trạm Flash (MacBook + Gemini web) */
.flash-ai-box{border:1px solid rgba(255,200,80,.35);background:rgba(255,200,80,.07);border-radius:14px;padding:10px 12px;margin-bottom:12px}
.flash-ai-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px;font-size:14px}
.flash-ai-row{display:flex;gap:8px;flex-wrap:wrap}
.flash-ai-row .btn-primary{flex:1}
.flash-ai-status{margin-top:8px;font-size:12px;opacity:.8;line-height:1.4}
.flash-ai-status.err{color:#ff8a80;opacity:1}
.flash-ai-status.ok{color:#9be7a0;opacity:1}
.flash-pct-overlay{position:absolute;left:50%;bottom:16%;transform:translateX(-50%);color:#fff;font-size:34px;font-weight:700;text-align:center;text-shadow:0 2px 10px rgba(0,0,0,.6);pointer-events:none;line-height:1;z-index:5}
.flash-pct-overlay small{display:block;font-size:13px;font-weight:500;opacity:.85;margin-top:4px}
#flashAmountRow{margin-top:10px}
