/* Document Scanner — a dark, native-feeling mobile camera app. Deliberately
   distinct from the framework website: no marketing hero, app chrome only. */
:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1c2128;
  --line: #2a313a;
  --ink: #f2f5f8;
  --muted: #8b95a1;
  --accent: #4cc2ff;
  --accent-ink: #05121a;
  --danger: #ff5d5d;
  --ok: #35d07f;
  --shutter: #ffffff;
  --safe-b: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  overscroll-behavior: none;
}

.scanner-app { display: flex; flex-direction: column; min-height: 100dvh; width: min(100%, 560px); margin: 0 auto; }

/* App bar */
.app-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.app-title { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.app-title i { color: var(--accent); font-size: 20px; }
.app-count { padding: 4px 10px; border-radius: 999px; background: var(--panel-2); color: var(--muted); font: 700 12px/1 ui-monospace, monospace; }

.app-main { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 14px 14px calc(28px + var(--safe-b)); }

/* Viewfinder */
.viewfinder {
  position: relative; aspect-ratio: 3 / 4; width: 100%;
  border-radius: 22px; overflow: hidden; background: #000;
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame-guide { position: absolute; inset: 20px; pointer-events: none; }
.corner { position: absolute; width: 30px; height: 30px; border: 3px solid rgba(255, 255, 255, .92); }
.corner.tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 10px 0 0 0; }
.corner.tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 10px 0 0; }
.corner.bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 10px; }
.corner.br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 10px 0; }
.view-status {
  position: absolute; left: 12px; bottom: 12px; right: 12px;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 12px;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(6px);
  color: #fff; font: 600 12px/1.2 ui-monospace, monospace;
}
.view-status i { color: var(--accent); }
.view-idle {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px;
  padding: 24px; text-align: center; background: linear-gradient(180deg, #12161b, #0b0d10);
  color: var(--muted);
}
.view-idle i { font-size: 40px; color: var(--accent); }
.view-idle p { margin: 0; max-width: 240px; font-size: 14px; line-height: 1.4; }
.view-idle.hidden { display: none; }

/* Shutter bar */
.shutter-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; justify-items: center; gap: 12px; padding: 4px 0; }
.tool-btn {
  display: inline-grid; place-items: center; width: 56px; height: 56px;
  border: 1px solid var(--line); border-radius: 18px; background: var(--panel-2); color: var(--ink);
  font-size: 22px; cursor: pointer;
}
.tool-btn input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.tool-btn:active { background: var(--panel); transform: scale(.96); }
.shutter {
  display: grid; place-items: center; width: 78px; height: 78px; padding: 0;
  border-radius: 50%; border: 4px solid rgba(255, 255, 255, .25); background: transparent; cursor: pointer;
}
.shutter .shutter-ring { width: 58px; height: 58px; border-radius: 50%; background: var(--shutter); transition: transform .1s; }
.shutter:active .shutter-ring { transform: scale(.88); }
.shutter:disabled { opacity: .4; cursor: not-allowed; }
.shutter:disabled .shutter-ring { background: var(--muted); }

/* Section chrome */
.pages-panel, .library-panel { display: flex; flex-direction: column; gap: 10px; }
.strip-head { display: flex; align-items: center; justify-content: space-between; }
.strip-title { font-weight: 800; font-size: 15px; letter-spacing: -.01em; }
.lib-count { color: var(--muted); font: 700 13px ui-monospace, monospace; }
.strip-actions { display: flex; gap: 8px; }
.strip-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); color: var(--ink);
  font: 800 13px inherit; cursor: pointer;
}
.strip-btn.export { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.strip-btn:disabled { opacity: .4; cursor: not-allowed; }
.scanner-title-input {
  width: 100%; min-height: 46px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink);
  font: 500 15px inherit;
}
.scanner-title-input::placeholder { color: var(--muted); }
.scanner-title-input:focus { outline: none; border-color: var(--accent); }

.empty-state { margin: 0; padding: 22px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 16px; font-size: 14px; }
.empty-state.hidden { display: none; }

/* Page cards (filmstrip) */
.page-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.page-card { display: grid; grid-template-columns: 116px 1fr; gap: 12px; padding: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.scan-thumb { display: grid; place-items: center; aspect-ratio: 3 / 4; overflow: hidden; background: #fff; border-radius: 10px; }
.scan-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform .2s, filter .2s; }
.page-tools { display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font: 700 12px ui-monospace, monospace; }
.edit-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.edit-row.secondary { grid-template-columns: repeat(3, 1fr); }
.edit-row button { min-height: 40px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-2); color: var(--ink); font-size: 16px; cursor: pointer; }
.edit-row button:active { transform: scale(.95); }
.edit-row .danger { background: color-mix(in srgb, var(--danger) 22%, var(--panel-2)); color: #ffd7d7; }

/* Library */
.library-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.doc-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.doc-info { display: grid; gap: 4px; min-width: 0; }
.doc-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.doc-meta { color: var(--muted); font: 700 12px ui-monospace, monospace; }
.doc-actions { display: flex; align-items: center; gap: 8px; }
.doc-open { display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 0 14px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font: 800 13px inherit; text-decoration: none; }
.doc-actions button { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); color: var(--ink); cursor: pointer; }
.doc-actions .danger { background: color-mix(in srgb, var(--danger) 22%, var(--panel-2)); color: #ffd7d7; }

.scan-error { display: grid; gap: 8px; padding: 40px 24px; text-align: center; color: var(--danger); }

/* Boot screen */
.boot-screen { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 12px; padding: 24px; text-align: center; background: var(--bg); color: var(--ink); }
.boot-screen strong { font-size: 18px; }
.boot-screen span { color: var(--muted); font-size: 14px; }
.boot-spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--panel-2); border-top-color: var(--accent); animation: boot-spin .9s linear infinite; }
@keyframes boot-spin { to { transform: rotate(360deg); } }
#boot-recovery { margin-top: 12px; display: grid; gap: 10px; justify-items: center; }
#boot-recovery p { margin: 0; max-width: 280px; color: var(--muted); font-size: 13px; }
#boot-reset { min-height: 44px; padding: 0 18px; border: 1px solid var(--accent); border-radius: 12px; background: var(--accent); color: var(--accent-ink); font: 800 14px inherit; cursor: pointer; }

@media (prefers-reduced-motion: reduce) { .boot-spinner { animation: none; } * { transition: none !important; } }

@media (min-width: 620px) {
  .scanner-app { min-height: auto; margin-top: 20px; margin-bottom: 20px; border: 1px solid var(--line); border-radius: 28px; overflow: hidden; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
}
