:root {
  --bg: #050505;
  --bg-soft: #0b0b0d;
  --panel: rgba(18, 18, 21, 0.94);
  --panel-strong: rgba(14, 14, 16, 0.98);
  --stroke: rgba(255,255,255,0.08);
  --stroke-strong: rgba(255,255,255,0.14);
  --text: #f5f3f1;
  --muted: #a19ca0;
  --muted-2: #787377;
  --red: #ff2800;
  --red-strong: #ff3d19;
  --red-soft: rgba(255, 40, 0, 0.18);
  --red-glow: rgba(255, 40, 0, 0.34);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow: 0 28px 60px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(255,40,0,0.08), transparent 26%),
    linear-gradient(180deg, #090909 0%, #050505 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body { overscroll-behavior: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }
strong { font-weight: 780; }

.app-shell {
  min-height: 100dvh;
  max-width: 980px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 18px calc(96px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 0 22px;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.07), 0 12px 24px rgba(0,0,0,0.3);
  flex: 0 0 auto;
}
.brand-copy { min-width: 0; }
.brand-kicker {
  display: block;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.brand h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(28px, 4vw, 34px);
  font-weight: 700;
  letter-spacing: -0.03em;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.top-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  color: #ddd8d5;
  background: rgba(255,255,255,0.03);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.install-button { min-height: 40px; padding: 0 16px; }

main { display: block; }
.view { display: none; }
.view.active { display: block; }

.premium-card {
  background: linear-gradient(180deg, rgba(20,20,23,0.96), rgba(10,10,12,0.96));
  border: 1px solid var(--stroke);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.thin-card {
  border-radius: 20px;
  padding: 14px 16px;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, .8fr);
  gap: 16px;
}
.hero-card { padding: 28px; }
.hero-copy { margin-bottom: 22px; }
.eyebrow {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--red-strong);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 800;
}
.hero-copy h2 {
  margin: 0 0 14px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(34px, 7vw, 56px);
  line-height: 0.98;
  letter-spacing: -0.04em;
}
.hero-copy p {
  margin: 0;
  max-width: 620px;
  color: #b8b2b5;
  font-size: 15px;
  line-height: 1.65;
}
.hero-copy p strong { color: #f2edeb; }
.hero-actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
.hero-footnote {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}
.hero-footnote span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--stroke);
  color: #dad5d2;
  font-size: 12px;
}
.spec-card {
  padding: 18px;
  display: flex;
  align-items: stretch;
}
.spec-list { display: grid; gap: 12px; width: 100%; }
.spec-item {
  padding: 16px;
  border-radius: 20px;
  border: 1px solid var(--stroke);
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.015));
}
.spec-item strong {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
}
.spec-item span { color: var(--muted); line-height: 1.55; font-size: 13px; }

.highlights {
  margin-top: 16px;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.highlight-box {
  padding: 18px;
  border-radius: 20px;
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--stroke);
}
.highlight-label {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--red-strong);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}
.highlight-box strong { display: block; margin-bottom: 6px; font-size: 16px; }
.highlight-box p { margin: 0; color: var(--muted); line-height: 1.6; font-size: 13px; }

.primary, .secondary, .ghost, .text-action {
  border: 0;
  min-height: 52px;
  border-radius: 18px;
  padding: 0 18px;
  font-weight: 760;
}
.primary {
  color: #fff;
  background: linear-gradient(180deg, var(--red-strong), #d91f00);
  box-shadow: 0 14px 34px rgba(255, 40, 0, 0.28);
}
.primary:active { transform: translateY(1px); }
.secondary {
  color: var(--text);
  background: rgba(255,255,255,0.035);
  border: 1px solid var(--stroke-strong);
}
.ghost {
  color: #e3ddda;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.06);
}
.text-action {
  min-height: 44px;
  color: var(--red-strong);
  background: transparent;
  padding-inline: 8px;
}
.small { min-height: 38px; padding: 0 14px; }
.compact { min-height: 42px; padding: 0 16px; }
.scan-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 16px;
}
.scan-symbol { font-size: 25px; line-height: 1; }
.import-btn { width: 100%; }

.pages-section { margin-top: 24px; }
.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-heading h3 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.pages-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.empty-state {
  grid-column: 1 / -1;
  min-height: 210px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 18px;
  text-align: center;
  border-radius: var(--radius-xl);
  border: 1px dashed rgba(255,255,255,0.14);
  color: var(--muted);
  background: linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0.01));
}
.empty-state strong { color: #efebea; }
.empty-state-icon { font-size: 42px; color: var(--red-strong); }
.page-card {
  position: relative;
  aspect-ratio: .73;
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid var(--stroke);
  background: #101012;
  box-shadow: var(--shadow);
}
.page-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.page-number,
.remove-page {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 999px;
  backdrop-filter: blur(12px);
}
.page-number {
  top: 10px;
  left: 10px;
  padding: 0 10px;
  background: rgba(5,5,5,0.72);
  border: 1px solid rgba(255,255,255,0.09);
  font-size: 11px;
}
.remove-page {
  top: 10px;
  right: 10px;
  width: 34px;
  border: 0;
  background: rgba(5,5,5,0.78);
  color: #fff;
  font-size: 18px;
}

.bottom-actions {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  transform: translateX(-50%);
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1fr 1fr 1.15fr;
  gap: 8px;
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(5,5,5,0), rgba(5,5,5,0.88) 18%, #050505 48%);
}

.camera-view,
.crop-view,
.filter-view { padding-bottom: 8px; }
.camera-frame {
  position: relative;
  overflow: hidden;
  min-height: 68dvh;
  padding: 0;
}
#camera {
  width: 100%;
  height: 68dvh;
  display: block;
  object-fit: cover;
  background: #000;
}
.camera-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.camera-guide span {
  position: absolute;
  width: 48px;
  height: 48px;
  border: 4px solid var(--red);
}
.camera-guide span:nth-child(1){left:8%;top:9%;border-right:0;border-bottom:0;border-top-left-radius:16px}
.camera-guide span:nth-child(2){right:8%;top:9%;border-left:0;border-bottom:0;border-top-right-radius:16px}
.camera-guide span:nth-child(3){left:8%;bottom:9%;border-right:0;border-top:0;border-bottom-left-radius:16px}
.camera-guide span:nth-child(4){right:8%;bottom:9%;border-left:0;border-top:0;border-bottom-right-radius:16px}
.camera-badge {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100% - 36px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(5,5,5,0.72);
  border: 1px solid rgba(255,255,255,0.1);
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
}
.camera-actions {
  display: grid;
  grid-template-columns: 60px 1fr 60px;
  align-items: center;
  gap: 16px;
  padding: 18px 4px 0;
}
.round {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 999px;
}
.capture {
  justify-self: center;
  width: 86px;
  height: 86px;
  border-radius: 999px;
  border: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 45%, #fff 0%, #efeceb 58%, #d9d5d2 100%);
  box-shadow: 0 0 0 7px rgba(255,255,255,0.08), 0 18px 34px rgba(0,0,0,0.34);
}
.capture span {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  border: 4px solid rgba(0,0,0,0.15);
  display: block;
}

.editor-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.editor-title { text-align: center; }
.editor-title strong { display: block; font-size: 16px; }
.crop-stage {
  position: relative;
  min-height: 62dvh;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #0b0b0d;
}
.crop-stage canvas { display: block; max-width: 100%; max-height: 100%; border-radius: 18px; }
.crop-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.crop-overlay polygon {
  fill: rgba(255,40,0,0.14);
  stroke: var(--red);
  stroke-width: 3;
}
.crop-overlay line {
  stroke: rgba(255,255,255,0.42);
  stroke-width: 1.5;
  stroke-dasharray: 7 7;
}
.crop-overlay .handle {
  fill: var(--red);
  stroke: #fff;
  stroke-width: 3;
}
.crop-toolbar {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.crop-toolbar span { color: var(--muted); font-size: 13px; }

.preview-wrap {
  overflow: hidden;
  display: grid;
  place-items: center;
  min-height: 46dvh;
  margin-bottom: 14px;
  padding: 12px;
  background: #0b0b0d;
}
#previewCanvas {
  width: min(100%, 560px);
  height: auto;
  display: block;
  border-radius: 20px;
}
.filter-panel { padding: 18px; }
.panel-heading { margin-bottom: 14px; }
.panel-heading h3 { margin: 0; font-size: 18px; letter-spacing: -0.02em; }
.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.segmented button {
  min-height: 50px;
  border-radius: 16px;
  border: 1px solid var(--stroke-strong);
  background: rgba(255,255,255,0.03);
  color: #ebe6e4;
  font-weight: 740;
}
.segmented button.active {
  color: #fff;
  border-color: rgba(255, 61, 25, 0.6);
  background: linear-gradient(180deg, rgba(255,61,25,0.32), rgba(255,40,0,0.2));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), 0 12px 24px rgba(255,40,0,0.12);
}
.control-row,
.quality-row {
  margin-top: 14px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,0.025);
}
.control-row label,
.quality-row label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  font-weight: 650;
}
.control-row label span { color: var(--red-strong); }
input[type="range"] {
  width: 100%;
  accent-color: var(--red);
}
select {
  width: 100%;
  min-height: 50px;
  border-radius: 16px;
  border: 1px solid var(--stroke-strong);
  background: #121214;
  color: var(--text);
  padding: 0 14px;
  outline: none;
}
.filter-panel .bw-only { display: none; }
.filter-panel.bw-mode .bw-only { display: block; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(108px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(18px);
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(14,14,16,0.96);
  color: var(--text);
  border: 1px solid var(--stroke-strong);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: .22s ease;
  pointer-events: none;
  z-index: 50;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 860px) {
  .hero-grid,
  .highlights {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell { padding-inline: 14px; }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding-bottom: 18px;
  }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .hero-card { padding: 22px; }
  .hero-copy h2 { font-size: clamp(30px, 11vw, 44px); }
  .pages-grid { grid-template-columns: 1fr 1fr; }
  .crop-toolbar,
  .section-heading {
    flex-direction: column;
    align-items: stretch;
  }
  .camera-badge { white-space: normal; text-align: center; }
}

@media (max-width: 420px) {
  .pages-grid { grid-template-columns: 1fr; }
  .bottom-actions { grid-template-columns: 1fr; }
  .topbar-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .top-pill,
  .install-button { flex: 1 1 auto; justify-content: center; }
}
