:root {
  --bg: #F6F5F2;
  --card: #FFFFFF;
  --ink: #17181C;
  --muted: #6B6E76;
  --line: #E4E2DD;
  --accent: #F2542D;
  --accent-ink: #FFFFFF;
  --ok: #1F9D6B;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--ink);
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; overflow: auto; }
.screen.dark { background: #000; color: #fff; overflow: hidden; }

/* home */
#home { padding: calc(28px + var(--safe-t)) 20px calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; max-width: 520px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand h1 { font-size: 24px; margin: 0; letter-spacing: -0.02em; }
.brand .tag { margin: 0; color: var(--muted); font-size: 14px; }
.proto { margin-left: auto; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 3px 8px; }
.big { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 58px; border-radius: 16px; font-weight: 600; font-size: 17px; }
.primary { background: var(--accent); color: var(--accent-ink); border-radius: 14px; padding: 12px 18px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.primary:active { filter: brightness(.92); }
.secondary { background: var(--card); border: 1px solid var(--line); cursor: pointer; }
.note { color: var(--muted); font-size: 15px; margin: 8px 2px 0; }
.draft { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.link { color: var(--accent); font-weight: 600; }
.fine { margin-top: auto; color: var(--muted); font-size: 13px; text-align: center; }

/* camera */
#video, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#video { object-fit: cover; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .35s ease-out; }
#flash.on { opacity: .85; transition: none; }
.cam-top { position: absolute; top: calc(12px + var(--safe-t)); left: 12px; right: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.round { width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,.45); display: grid; place-items: center; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.round.on { background: #fff; color: #000; }
.seg { display: flex; background: rgba(0,0,0,.45); border-radius: 99px; padding: 3px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.seg button { padding: 8px 14px; border-radius: 99px; font-size: 14px; font-weight: 600; color: rgba(255,255,255,.8); }
.seg button.on { background: #fff; color: #000; }
.hint { position: absolute; left: 50%; top: calc(72px + var(--safe-t)); transform: translateX(-50%); background: rgba(0,0,0,.6); padding: 8px 14px; border-radius: 99px; font-size: 15px; font-weight: 500; white-space: nowrap; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: background .2s; }
.hint.good { background: var(--accent); }
#debug { position: absolute; left: 8px; top: calc(120px + var(--safe-t)); margin: 0; font: 11px/1.3 ui-monospace, monospace; background: rgba(0,0,0,.6); padding: 6px 8px; border-radius: 6px; pointer-events: none; }
.cam-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 24px calc(22px + var(--safe-b)); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 4px solid #fff; display: grid; place-items: center; }
.shutter span { width: 60px; height: 60px; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active span { transform: scale(.88); }
.tray { justify-self: start; width: 52px; height: 52px; border-radius: 10px; background: rgba(255,255,255,.12); position: relative; overflow: visible; }
.tray img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; border: 2px solid #fff; display: none; }
.tray.has img { display: block; }
.tray span { position: absolute; top: -7px; right: -7px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; background: var(--accent); font-size: 12px; font-weight: 700; display: none; place-items: center; }
.tray.has span { display: grid; }
.tray.pop { animation: pop .35s ease-out; }
@keyframes pop { 40% { transform: scale(1.18); } }
.done { justify-self: end; font-weight: 700; font-size: 17px; padding: 10px 6px; }

/* review */
.bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 12px 10px; background: rgba(246,245,242,.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.bar h2 { font-size: 18px; margin: 0; flex: 1; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; }
.chip-btn { display: inline-flex; align-items: center; gap: 4px; padding: 8px 12px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); font-weight: 600; font-size: 14px; }
.chip-btn svg { width: 18px; height: 18px; }
.pages { padding: 16px 16px 120px; display: grid; gap: 16px; max-width: 640px; margin: 0 auto; }
.page { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.page .img { background: #EDEBE6; display: grid; place-items: center; padding: 12px; }
.page img { max-width: 100%; max-height: 62vh; display: block; box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.page .row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; flex-wrap: wrap; }
.page .num { font-weight: 700; color: var(--muted); font-size: 13px; margin-right: 4px; }
.filters { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 99px; }
.filters button { padding: 6px 11px; border-radius: 99px; font-size: 13px; font-weight: 600; color: var(--muted); }
.filters button.on { background: var(--ink); color: #fff; }
.page .tools { margin-left: auto; display: flex; gap: 2px; }
.page .tools button { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); }
.page .tools svg { width: 20px; height: 20px; }
.page.busy img { opacity: .45; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.rev-actions { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 10px; justify-content: space-between; padding: 12px 16px calc(12px + var(--safe-b)); background: rgba(246,245,242,.95); border-top: 1px solid var(--line); }
.rev-actions .primary { flex: 1; max-width: 320px; margin-left: auto; min-height: 50px; }
.ghost { color: var(--muted); font-weight: 600; padding: 0 8px; }

/* crop */
.crop-stage { position: absolute; inset: 0 0 calc(76px + var(--safe-b)); touch-action: none; }
#crop-canvas { width: 100%; height: 100%; display: block; }
#loupe { position: absolute; width: 110px; height: 110px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 12px rgba(0,0,0,.5); pointer-events: none; display: none; }
.crop-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; align-items: center; padding: 12px 12px calc(12px + var(--safe-b)); background: #111; }
.crop-bar .primary { margin-left: auto; }
.ghost-dark { color: #ddd; font-weight: 600; padding: 10px 8px; white-space: nowrap; border-radius: 10px; font-size: 15px; }

.toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; z-index: 10; max-width: calc(100% - 32px); text-align: center; }
