:root {
  --g: #2fe08a;
  --g-dim: rgba(47, 224, 138, .22);
  --g-glow: rgba(47, 224, 138, .55);
  --bg: #000;
  --fg: #e9f7f0;
  --dim: #6d7d78;
  --warn: #ffc453;
  --pad-t: env(safe-area-inset-top);
  --pad-b: env(safe-area-inset-bottom);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body { position: fixed; inset: 0; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  background: #000;
}

.screen.is-active { display: block; }

.stage {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  will-change: transform;
}

.stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.cam-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--pad-t) + 12px) 14px 12px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, .55), transparent);
  pointer-events: none;
}

.cam-top > * { pointer-events: auto; }

.grow { flex: 1; }

.pill {
  font-size: 13px;
  font-weight: 600;
  color: var(--g);
  background: rgba(0, 0, 0, .45);
  border: 1px solid var(--g-dim);
  border-radius: 999px;
  padding: 6px 12px;
  backdrop-filter: blur(6px);
}

.ghost {
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(0, 0, 0, .45);
  color: var(--fg);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(6px);
  cursor: pointer;
  min-height: 38px;
}

.ghost:active { background: rgba(0, 0, 0, .75); }
.ghost.accent { color: var(--g); border-color: var(--g-dim); }

.live-hint {
  position: absolute;
  left: 50%;
  top: calc(var(--pad-t) + 70px);
  transform: translateX(-50%);
  z-index: 5;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--g);
  text-shadow: 0 0 14px var(--g-glow);
  pointer-events: none;
  white-space: nowrap;
}

.cam-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 22px calc(var(--pad-b) + 26px);
  background: linear-gradient(to top, rgba(0, 0, 0, .6), transparent);
}

.cam-spacer { flex: 1; }

.import {
  margin-left: auto;
  width: 56px;
  height: 58px;
  padding: 0;
  border: 1.5px solid rgba(255, 255, 255, .22);
  border-radius: 10px;
  background: rgba(0, 0, 0, .45);
  color: var(--fg);
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.import:active { background: rgba(0, 0, 0, .75); }

.no-cam {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  width: min(320px, calc(100% - 48px));
  text-align: center;
  background: rgba(8, 11, 10, .92);
  border: 1px solid var(--g-dim);
  border-radius: 14px;
  padding: 22px 18px 18px;
}

.no-cam[hidden] { display: none; }
.no-cam-title { margin: 0 0 6px; font-size: 15px; font-weight: 700; color: var(--g); }
.no-cam-text { margin: 0 0 16px; font-size: 13px; color: var(--fg); opacity: .8; line-height: 1.45; }
.no-cam-actions { display: grid; gap: 8px; }
.no-cam .act { width: 100%; }

.last-page {
  position: relative;
  width: 46px;
  height: 58px;
  padding: 0;
  border: 1.5px solid rgba(255, 255, 255, .22);
  border-radius: 6px;
  background: rgba(255, 255, 255, .06);
  overflow: visible;
  cursor: pointer;
}

.last-page img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}

.badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--g);
  color: #02140c;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.shutter {
  flex: none;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .9);
  background: rgba(255, 255, 255, .12);
  position: relative;
  cursor: pointer;
  transition: transform .1s ease;
}

.shutter::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--g);
  box-shadow: 0 0 20px var(--g-glow);
  transition: transform .1s ease;
}

.shutter:active { transform: scale(.93); }
.shutter:active::after { transform: scale(.86); }

.review-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--pad-t) + 10px) 12px 10px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, .6), transparent);
}

.review-stage {
  position: absolute;
  inset: 0;
  touch-action: none;
  background: #000;
}

.review-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.handle {
  position: absolute;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border-radius: 50%;
  border: 2.5px solid var(--g);
  background: rgba(0, 0, 0, .55);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .6), 0 0 16px var(--g-glow);
  cursor: grab;
  touch-action: none;
}

.handle::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: var(--g);
}

.handle.is-active { background: rgba(47, 224, 138, .3); }

.loupe {
  position: absolute;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: 2px solid var(--g);
  box-shadow: 0 0 0 1px #000, 0 10px 30px rgba(0, 0, 0, .6);
  pointer-events: none;
  z-index: 8;
  background: #000;
}

.review-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 14px calc(var(--pad-b) + 14px);
  background: linear-gradient(to top, rgba(0, 0, 0, .72), transparent);
}

.filter-strip {
  flex: 1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px;
}

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

.filter {
  flex: none;
  width: 58px;
  border: 1.5px solid rgba(255, 255, 255, .14);
  border-radius: 8px;
  background: rgba(255, 255, 255, .04);
  padding: 3px 3px 4px;
  cursor: pointer;
  color: var(--fg);
  font: inherit;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .2px;
  text-transform: uppercase;
}

.filter canvas {
  width: 100%;
  height: 72px;
  object-fit: cover;
  border-radius: 5px;
  display: block;
  background: #000;
}

.filter.is-active {
  border-color: var(--g);
  color: var(--g);
  box-shadow: 0 0 14px rgba(47, 224, 138, .28);
}

.accept {
  flex: none;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: none;
  background: var(--g);
  position: relative;
  cursor: pointer;
  box-shadow: 0 0 22px var(--g-glow);
  transition: transform .1s ease;
}

.accept::after {
  content: "";
  position: absolute;
  left: 22px;
  top: 15px;
  width: 16px;
  height: 28px;
  border-right: 4px solid #02140c;
  border-bottom: 4px solid #02140c;
  transform: rotate(42deg);
}

.accept:active { transform: scale(.92); }

.sheet {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, .72);
  backdrop-filter: blur(3px);
}

.sheet[hidden] { display: none; }

.sheet-inner {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82%;
  display: flex;
  flex-direction: column;
  background: #080b0a;
  border-top: 1px solid rgba(47, 224, 138, .25);
  border-radius: 16px 16px 0 0;
  padding-bottom: var(--pad-b);
  animation: rise .18s ease-out;
}

@keyframes rise { from { transform: translateY(18px); opacity: .4; } to { transform: none; opacity: 1; } }

.sheet-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.sheet-title { font-size: 14px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--g); }

.sheet-bar .ghost { margin-left: auto; }
.sheet-bar .ghost + .ghost { margin-left: 0; }
.ghost.danger { color: #ff8a7a; border-color: rgba(255, 138, 122, .4); }

.doc-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 0;
  font-size: 12px;
  color: var(--fg);
  opacity: .9;
}

.doc-name {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 8px;
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
}

.doc-name:focus { outline: none; border-color: var(--g); }

.text-out {
  flex: 1;
  min-height: 220px;
  margin: 12px 14px 0;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 10px;
  color: var(--fg);
  font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 10px 12px;
  resize: none;
}

.text-out:focus { outline: none; border-color: var(--g); }
.text-note { margin: 8px 14px 0; font-size: 12px; color: var(--fg); opacity: .7; min-height: 1em; }

.page-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  padding: 12px 14px;
  align-content: start;
}

.page-grid .empty {
  grid-column: 1 / -1;
  color: var(--dim);
  font-size: 13px;
  text-align: center;
  padding: 28px 0;
}

.cell {
  position: relative;
  border: 1.5px solid rgba(255, 255, 255, .14);
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 3 / 4;
  touch-action: none;
}

.cell.is-selected { border-color: var(--g); box-shadow: 0 0 12px rgba(47, 224, 138, .3); }

.cell.is-dragging {
  opacity: .55;
  border-color: var(--g);
  transform: scale(1.04);
}

.cell img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }

.cell-num {
  position: absolute;
  left: 4px;
  bottom: 4px;
  background: rgba(0, 0, 0, .6);
  color: var(--fg);
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.cell-btn {
  position: absolute;
  top: 4px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, .62);
  color: var(--fg);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell-btn.del { right: 4px; color: var(--g); }
.cell-btn.img { left: 4px; }
.cell-btn.rot { right: 32px; }

.sheet-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}

.sheet-actions.two { grid-template-columns: repeat(2, 1fr); margin-top: 12px; }

.act {
  border: 1px solid var(--g-dim);
  background: rgba(47, 224, 138, .07);
  color: var(--g);
  border-radius: 10px;
  padding: 12px 4px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}

.act:disabled { opacity: .38; }

.act:active { background: rgba(47, 224, 138, .16); }

.busy {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.busy[hidden] { display: none; }

.busy-box { width: min(320px, 76vw); text-align: center; }

.busy-bar {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
}

.busy-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--g);
  box-shadow: 0 0 12px var(--g-glow);
  transition: width .18s ease;
}

.busy-bar.is-indeterminate i {
  width: 35%;
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide { 0% { margin-left: 0; } 50% { margin-left: 65%; } 100% { margin-left: 0; } }

.busy-text { margin: 12px 0 0; font-size: 13px; color: var(--fg); }

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--pad-b) + 34px);
  transform: translateX(-50%);
  z-index: 50;
  max-width: 86vw;
  background: rgba(10, 16, 14, .96);
  border: 1px solid var(--g-dim);
  color: var(--fg);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 13px;
  text-align: center;
}

.toast[hidden] { display: none; }

.hidden { display: none !important; }
