/* PhoneScan — dark, paper-and-ink design language */

:root {
  --bg: #0c0e13;
  --surface: #151922;
  --surface-2: #1c2230;
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9edf4;
  --muted: #94a0b4;
  --accent: #2dd4bf;
  --accent-ink: #063f39;
  --danger: #f87171;
  --radius: 16px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button:disabled { opacity: 0.35; cursor: default; }
svg { width: 22px; height: 22px; display: block; }
.hidden { display: none !important; }

/* ---------- Screens ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}
.screen.active { display: flex; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.screen.active > * { animation: screen-in 0.22s ease both; }

/* ---------- Home ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 20px 14px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 26px; height: 26px; color: var(--text); }
.brand h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }

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

.chip {
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 700;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.danger { color: var(--danger); }
.icon-btn.glass {
  background: rgba(12, 14, 19, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
}

.home-main {
  flex: 1;
  overflow-y: auto;
  padding: 4px 20px 24px;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding-bottom: 40px;
}
.empty-art { width: 150px; height: 150px; margin-bottom: 8px; }
.empty-state h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.empty-state p { color: var(--muted); font-size: 14.5px; line-height: 1.55; max-width: 300px; }

.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 14px;
  padding-top: 6px;
}

.page-card {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  aspect-ratio: 3 / 4;
  transition: transform 0.12s ease;
}
.page-card:active { transform: scale(0.96); }
.page-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.page-card .page-num {
  position: absolute;
  left: 6px;
  bottom: 6px;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(10, 12, 16, 0.72);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.add-card {
  border-radius: 12px;
  border: 1.5px dashed rgba(255, 255, 255, 0.18);
  aspect-ratio: 3 / 4;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.add-card svg { width: 28px; height: 28px; }
.add-card:active { background: var(--surface); }

/* ---------- Bottom bar (home) ---------- */

.bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 12px 24px calc(14px + var(--safe-bottom));
  background: linear-gradient(to top, rgba(12, 14, 19, 0.98), rgba(12, 14, 19, 0.86));
  border-top: 1px solid var(--line);
}

.side-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  width: 76px;
  padding: 6px 0;
  border-radius: 12px;
  transition: color 0.15s;
}
.side-action:active { color: var(--text); }

.shutter {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 22px rgba(45, 212, 191, 0.35);
  transition: transform 0.12s ease;
}
.shutter svg { width: 28px; height: 28px; }
.shutter:active { transform: scale(0.93); }

/* ---------- Camera ---------- */

#screen-camera { background: #000; }

#camera-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#camera-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.camera-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px;
}

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

.icon-btn.glass[aria-pressed="true"] {
  color: var(--accent);
  box-shadow: inset 0 0 0 1.5px rgba(45, 212, 191, 0.55);
}

#capture-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  /* Must beat `.screen.active > *`, whose screen-in animation (fill: both)
     would otherwise pin this fullscreen white overlay at opacity 1. */
  animation: none;
}
#capture-flash.flash { animation: cap-flash 0.32s ease-out; }
@keyframes cap-flash {
  0% { opacity: 0.85; }
  100% { opacity: 0; }
}

.camera-hint {
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(12, 14, 19, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  transition: color 0.2s;
}
.camera-hint.found { color: var(--accent); }

.camera-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 40px calc(28px + var(--safe-bottom));
}

.camera-spacer { width: 42px; }

.capture-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  position: relative;
  transition: transform 0.1s ease;
}
.capture-btn::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #fff;
  transition: background 0.15s;
}
.capture-btn:active { transform: scale(0.92); }
.capture-btn:active::after { background: var(--accent); }

/* ---------- Tool screens (crop / enhance) ---------- */

.tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  min-height: calc(54px + var(--safe-top));
}
.tool-header h2 {
  font-size: 16px;
  font-weight: 700;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.tool-header-spacer { width: 60px; }

.text-btn {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  padding: 8px 6px;
  min-width: 60px;
  text-align: left;
}
.text-btn.subtle { color: var(--muted); font-size: 13px; text-align: center; min-width: 0; }

.tool-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 20px calc(16px + var(--safe-bottom));
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 14.5px;
  font-weight: 650;
  color: var(--text);
  transition: transform 0.12s ease, background 0.15s;
}
.pill-btn svg { width: 19px; height: 19px; }
.pill-btn:active { transform: scale(0.96); }
.pill-btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}
.pill-btn.danger {
  background: var(--danger);
  border-color: transparent;
  color: #3b0a0a;
}

/* ---------- Cropper ---------- */

.cropper-container {
  position: relative;
  flex: 1;
  overflow: hidden;
  touch-action: none;
}

.cropper-img,
.cropper-overlay {
  position: absolute;
}
.cropper-overlay { inset: 0; touch-action: none; }

.cropper-loupe {
  position: absolute;
  display: none;
  pointer-events: none;
  border-radius: 50%;
  box-shadow: var(--shadow);
  z-index: 5;
}

/* ---------- Enhance ---------- */

.enhance-preview-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px 16px;
}

#enhance-preview {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  box-shadow: var(--shadow);
  background: #fff;
}

.enhance-controls {
  padding: 10px 20px calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.enhance-toolbar {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.mini-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  transition: color 0.15s, border-color 0.15s;
}
.mini-btn svg { width: 17px; height: 17px; }
.mini-btn:active, .mini-btn[aria-expanded="true"] {
  color: var(--accent);
  border-color: rgba(45, 212, 191, 0.4);
}

.adjust-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slider-row {
  display: grid;
  grid-template-columns: 82px 1fr 36px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.slider-row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
}

.filter-chips {
  display: flex;
  gap: 12px;
  justify-content: center;
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }

.filter-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}
.filter-chip canvas {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--surface-2);
  object-fit: cover;
  transition: border-color 0.15s, transform 0.12s;
}
.filter-chip.selected { color: var(--accent); }
.filter-chip.selected canvas {
  border-color: var(--accent);
  transform: scale(1.04);
}

.cta {
  padding: 15px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 750;
  letter-spacing: 0.01em;
  box-shadow: 0 6px 22px rgba(45, 212, 191, 0.25);
  transition: transform 0.12s ease;
}
.cta:active { transform: scale(0.98); }

/* ---------- Sheets & dialogs ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 20;
  animation: fade-in 0.18s ease both;
}
@keyframes fade-in { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--line);
  padding: 10px 22px calc(22px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: sheet-up 0.24s cubic-bezier(0.2, 0.9, 0.3, 1) both;
  max-width: 560px;
  margin: 0 auto;
}
@keyframes sheet-up { from { transform: translateY(100%); } }

.sheet-grip {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.18);
  margin: 2px auto 0;
}

.sheet h2 { font-size: 18px; font-weight: 700; }

.count-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 4px;
}

.field { display: flex; flex-direction: column; gap: 7px; }
.field span { font-size: 12.5px; font-weight: 650; color: var(--muted); }
.field input {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  outline: none;
  user-select: text;
}
.field input:focus { border-color: rgba(45, 212, 191, 0.5); }

.seg-group {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
}
.seg {
  padding: 10px 0;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.seg.selected { background: var(--accent); color: var(--accent-ink); }

.sheet-note { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin-top: -6px; }

.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sheet-actions .pill-btn { justify-content: center; }

.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 21;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  width: min(320px, calc(100vw - 48px));
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: var(--shadow);
  animation: fade-in 0.15s ease both;
}
.dialog p { font-size: 15px; line-height: 1.5; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-actions .pill-btn { justify-content: center; }

/* ---------- Spinner & toast ---------- */

.spinner-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(8, 10, 14, 0.72);
  backdrop-filter: blur(3px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3.5px solid var(--surface-2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + var(--safe-bottom));
  transform: translate(-50%, 16px);
  z-index: 40;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  max-width: calc(100vw - 48px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Larger screens: center content column */
@media (min-width: 720px) {
  .home-main, .bottom-bar { padding-left: max(20px, calc(50vw - 330px)); padding-right: max(20px, calc(50vw - 330px)); }
}
