:root {
  --accent: #7A5AF8;
  --accent-pressed: #6846E6;
  --ink: #1E1B2E;
  --muted: #8A8699;
  --success: #2FB67A;
  --warning: #E09A3C;
  --danger: #E2575A;
  --pill: #F1EFF7;
  --circle-idle: #E7E5F0;
  --grad-top: #EFEAFF;
  --grad-bot: #E6F5EE;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  color: var(--ink);
  background: #E9E7F0;
  -webkit-font-smoothing: antialiased;
}

/* Center the floating widget, like the Mac window on the desktop. */
.stage {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

/* The widget = the Mac's borderless rounded card (380 wide, gradient, radius 22). */
.widget {
  width: 380px; max-width: 100%;
  background: linear-gradient(135deg, var(--grad-top) 0%, #ffffff 50%, var(--grad-bot) 100%);
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(80, 60, 160, 0.18), 0 1px 0 rgba(255,255,255,0.6) inset;
  padding: 28px 30px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.hidden { display: none !important; }

/* Brand row: lighthouse + TOSAYN, centered. */
.brand { display: flex; align-items: center; gap: 9px; margin-bottom: 4px; }
.lighthouse { width: 30px; height: 30px; border-radius: 7px; }
.brandname { font-size: 18px; font-weight: 600; letter-spacing: 2px; color: var(--ink); }

/* Document / Photo segmented pill — hugs its text, centered. */
.pill {
  display: inline-flex; gap: 2px; padding: 4px;
  background: var(--pill); border-radius: 999px;
}
.seg {
  border: none; background: transparent; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--ink);
  padding: 11px 16px; border-radius: 999px; transition: color .2s;
}
.seg.active { background: var(--accent); color: #fff; }
.pill-thumb { display: none; }

/* Scan area — a faint 84px circle; white "Tap to find scanner" pill over it when idle,
   accent circle + viewfinder icon when a scanner is present. */
.scan-area {
  min-height: 104px; width: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
.scan-circle {
  position: relative; width: 84px; height: 84px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--circle-idle);
  box-shadow: 0 10px 22px rgba(0,0,0,0.18);
  display: flex; align-items: center; justify-content: center;
  transition: transform .3s cubic-bezier(.2,.8,.3,1), background .25s, box-shadow .25s;
  flex: none;
}
.scan-circle svg { width: 30px; height: 30px; display: none; }
.scan-circle .find-pill {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  white-space: nowrap; font-size: 12px; font-weight: 500; color: var(--ink);
  background: #fff; padding: 8px 16px; border-radius: 999px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}
/* Ready: a scanner is selected → the circle becomes the accent scan button. */
.scan-circle.ready { background: var(--accent); transform: scale(1.08); box-shadow: 0 16px 38px rgba(122,90,248,0.55); }
.scan-circle.ready .vf { display: block; }
.scan-circle.ready .find-pill { display: none; }
/* Scanning → accent circle with a stop glyph. */
.scan-circle.scanning { background: var(--accent); box-shadow: 0 14px 30px rgba(122,90,248,0.5); }
.scan-circle.scanning .stop { display: block; }
.scan-circle.scanning .find-pill { display: none; }
/* Success moment. */
.scan-circle.success { background: var(--success); box-shadow: 0 14px 30px rgba(47,182,122,0.5); }
.scan-circle.success .check { display: block; }
.scan-circle.success .find-pill { display: none; }

.scan-progress { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.success-count { font-size: 10px; font-weight: 600; color: var(--muted); }
.spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(122,90,248,0.25); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Device capsule (driver: name). */
.device-cap {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; border: none;
  background: var(--pill); color: var(--ink);
  padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; max-width: 100%;
}
.device-cap .scanner-ic { width: 15px; height: 15px; flex: none; }
.device-cap .chev { width: 12px; height: 12px; flex: none; color: var(--muted); }
.device-cap #device-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-cap.readonly { cursor: default; }

/* Bottom bar: gear · folder. */
.bottombar { display: flex; align-items: center; width: 100%; margin-top: 2px; }
.grow { flex: 1; }
.barbtn { position: relative; border: none; background: transparent; color: var(--muted); cursor: pointer; padding: 6px; }
.barbtn svg { width: 22px; height: 22px; display: block; }
.barbtn.on { color: var(--accent); }
.folder-badge {
  position: absolute; left: 50%; top: 55%; transform: translate(-50%, -50%);
  font-size: 8.5px; font-weight: 700; color: currentColor;
}

/* Pair screen (same card, brand on top). */
.pair-body { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 6px 0 14px; }
.lock { font-size: 40px; }
.pair-body h1 { font-size: 22px; margin: 0; font-weight: 700; }
.sub { color: var(--muted); font-size: 13px; text-align: center; margin: 0; line-height: 1.4; }
.sub.tiny { font-size: 11px; }
.code {
  font: 700 32px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 8px; text-align: center; color: var(--ink);
  width: 230px; max-width: 100%; padding: 13px 6px 13px 14px; margin-top: 4px;
  border: 1.5px solid rgba(122,90,248,0.4); border-radius: 14px; background: #fff; outline: none;
}
.code:focus { border-color: var(--accent); }
.cta {
  width: 100%; border: none; border-radius: 14px; font-size: 16px; font-weight: 600;
  padding: 15px; background: var(--accent); color: #fff; cursor: pointer;
}
.cta:disabled { background: #C9C4DE; }
.cta:active:not(:disabled) { background: var(--accent-pressed); }
.err { color: var(--danger); font-size: 13px; margin: 0; text-align: center; }

/* Result overlay + settings sheet */
.ghost { background: transparent; border: none; color: var(--accent); font-size: 14px; font-weight: 600; cursor: pointer; padding: 8px 10px; }
.ghost.danger { color: var(--danger); }
.overlay {
  position: fixed; inset: 0; z-index: 20; background: #E9E7F0;
  display: flex; flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.overlay-head { display: flex; align-items: center; gap: 8px; padding-bottom: 12px; }
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; overflow-y: auto; }
.pages img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 8px; border: 1px solid rgba(0,0,0,0.1); background: #fff; }

.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 30; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; margin: 0 auto; max-width: 480px;
  background: #fff; border-radius: 22px 22px 0 0; padding: 8px 20px calc(16px + env(safe-area-inset-bottom));
  max-height: 84vh; overflow-y: auto; box-shadow: 0 -8px 30px rgba(0,0,0,0.15);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; position: sticky; top: 0; background: #fff; }
.sheet-foot { display: flex; align-items: center; justify-content: space-between; padding: 14px 2px 4px; border-top: .5px solid rgba(0,0,0,0.08); margin-top: 8px; }
.settings-group { margin: 6px 0 16px; }
.settings-group h3 { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; margin: 0 0 6px; }
.settings-group .rows { background: var(--pill); border-radius: 14px; overflow: hidden; }
.srow { display: flex; align-items: center; justify-content: space-between; padding: 13px 14px; border-bottom: .5px solid rgba(0,0,0,0.05); }
.srow:last-child { border-bottom: none; }
.srow label { font-size: 15px; }
.srow select { border: none; background: transparent; font-size: 15px; color: var(--accent); font-weight: 600; text-align: right; appearance: none; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #D1D1D6; border-radius: 999px; transition: .2s; }
.slider::before { content: ""; position: absolute; width: 24px; height: 24px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }
