/* Quire — styles. System fonts only (no downloads). */
:root {
  --bg: #f4f1ea;
  --bg-2: #ebe6db;
  --surface: #fffdf9;
  --surface-2: #f0ece3;
  --line: rgba(40, 32, 20, .12);
  --text: #1d1b17;
  --muted: #6a645a;
  --accent: #d2401f;
  --accent-ink: #ffffff;
  --accent-soft: rgba(210, 64, 31, .12);
  --ok: #18865a;
  --shadow: 0 1px 2px rgba(40, 30, 10, .08), 0 8px 24px -8px rgba(40, 30, 10, .18);
  --shadow-lg: 0 24px 60px -20px rgba(30, 20, 5, .45);
  --radius: 18px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111114; --bg-2: #18181c; --surface: #1c1c21; --surface-2: #26262c; --line: rgba(255, 255, 255, .1);
    --text: #f3f0ea; --muted: #a39e94; --accent: #ff6b4a; --accent-ink: #1a0b06; --accent-soft: rgba(255, 107, 74, .16);
    --ok: #4cc98f; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -10px rgba(0, 0, 0, .7); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111114; --bg-2: #18181c; --surface: #1c1c21; --surface-2: #26262c; --line: rgba(255, 255, 255, .1);
  --text: #f3f0ea; --muted: #a39e94; --accent: #ff6b4a; --accent-ink: #1a0b06; --accent-soft: rgba(255, 107, 74, .16);
  --ok: #4cc98f; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -10px rgba(0, 0, 0, .7); color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none; overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 12px; }
[hidden] { display: none !important; }
.sprite { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.sm { width: 16px; height: 16px; }
.noscript { padding: 2rem; text-align: center; }

/* ---------- Views & transitions ---------- */
#app { position: fixed; inset: 0; overflow: hidden; }
.view {
  position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg);
  padding: var(--safe-t) var(--safe-r) 0 var(--safe-l); overflow: hidden;
}
.view.dark { background: #0a0a0c; color: #f5f3ee; --text: #f5f3ee; --muted: #b1aca2; --line: rgba(255, 255, 255, .14); }
.view.enter { animation: view-in .42s var(--ease) both; }
.view.enter-back { animation: view-in-back .42s var(--ease) both; }
.view.leave { animation: view-out .32s var(--ease) both; pointer-events: none; z-index: 0; }
.view.leave-back { animation: view-out-back .32s var(--ease) both; pointer-events: none; z-index: 0; }
.view.enter, .view.enter-back { z-index: 1; }
@keyframes view-in { from { transform: translate3d(28px, 0, 0); opacity: 0; } }
@keyframes view-in-back { from { transform: translate3d(-28px, 0, 0); opacity: 0; } }
@keyframes view-out { to { transform: translate3d(-20px, 0, 0); opacity: 0; } }
@keyframes view-out-back { to { transform: translate3d(20px, 0, 0); opacity: 0; } }
.view.zoom-in { animation: zoom-in .45s var(--ease) both; z-index: 1; }
@keyframes zoom-in { from { transform: scale(.94); opacity: 0; border-radius: 28px; } }

/* ---------- Common controls ---------- */
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%;
  transition: transform .2s var(--spring), background-color .2s;
}
.icon-btn:active { transform: scale(.88); }
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn.lg { width: 52px; height: 52px; }
.icon-btn-spacer { width: 44px; }
.glass { background: rgba(20, 20, 24, .45); color: #fff; backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4); }
.icon-btn.glass:hover { background: rgba(40, 40, 46, .6); }
.pill { height: 36px; padding: 0 14px; border-radius: 18px; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; transition: background-color .25s, color .25s, transform .2s var(--spring); }
.pill:active { transform: scale(.94); }
.pill[aria-pressed="true"] { background: #fff; color: #111; }
.text-btn { min-height: 44px; padding: 0 12px; font-weight: 500; border-radius: 12px; }
.text-btn.strong { font-weight: 700; color: var(--accent); }
.view.dark .text-btn.strong { color: #ff8a6e; }

.btn {
  min-height: 52px; padding: 0 22px; border-radius: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 650; font-size: 17px; transition: transform .2s var(--spring), box-shadow .2s, background-color .2s;
}
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 8px 20px -8px var(--accent); }
.btn.secondary { background: var(--surface-2); }
.btn.danger { background: #c62f2f; color: #fff; }

.bar {
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 4px; padding: 6px 8px; min-height: 56px; flex: none;
}
.bar-title { margin: 0; text-align: center; font-size: 17px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.glass-bar { position: relative; z-index: 2; }
.bar .text-btn:first-child { justify-self: start; }
.bar .text-btn:last-child { justify-self: end; }
.bar:has(.text-btn) { grid-template-columns: auto 1fr auto; }

/* ---------- Library ---------- */
#v-library { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.lib-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 20px 6px; }
.wordmark { margin: 0; font: italic 600 40px/1.05 var(--serif); letter-spacing: -.02em; }
.wordmark::after { content: "."; color: var(--accent); font-style: normal; }
.tagline { margin: 6px 0 0; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.search { margin: 10px 20px 4px; display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 14px; padding: 0 14px; color: var(--muted); }
.search input { flex: 1; border: 0; background: none; outline: none; height: 44px; color: var(--text); min-width: 0; }
.search:focus-within { box-shadow: 0 0 0 2px var(--accent); }
.doc-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 16px;
  padding: 16px 20px calc(130px + var(--safe-b));
}
.doc-card { position: relative; display: flex; flex-direction: column; gap: 10px; text-align: left; animation: rise .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 45ms); border-radius: 14px; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
.doc-thumb {
  position: relative; aspect-ratio: 3 / 4; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow);
  transition: transform .35s var(--spring), box-shadow .3s;
}
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; border-radius: 12px; display: block; }
.doc-thumb.multi::before, .doc-thumb.multi::after {
  content: ""; position: absolute; inset: 0; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); z-index: -1;
  transform: rotate(-3deg) translate(-3px, 3px); transition: transform .35s var(--spring);
}
.doc-thumb.multi::after { transform: rotate(2.5deg) translate(4px, 2px); z-index: -2; opacity: .8; }
.doc-card:hover .doc-thumb, .doc-card:focus-visible .doc-thumb { transform: translateY(-3px); }
.doc-card:hover .doc-thumb.multi::before { transform: rotate(-6deg) translate(-8px, 4px); }
.doc-card:hover .doc-thumb.multi::after { transform: rotate(5deg) translate(9px, 3px); }
.doc-card:active .doc-thumb { transform: scale(.97); }
.doc-card .count { position: absolute; right: 8px; bottom: 8px; background: rgba(15, 15, 18, .72); color: #fff; font-size: 12px; font-weight: 650; padding: 2px 8px; border-radius: 10px; backdrop-filter: blur(6px); }
.doc-info { padding: 0 2px; min-width: 0; }
.doc-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-date { color: var(--muted); font-size: 13px; }
.doc-card.removing { animation: shrink .35s var(--ease) forwards; }
@keyframes shrink { to { transform: scale(.85); opacity: 0; } }

.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 32px 160px; animation: rise .6s var(--ease) both; }
.empty h2 { font: 600 26px/1.2 var(--serif); margin: 28px 0 8px; }
.empty p { color: var(--muted); margin: 0; max-width: 32ch; }
.empty-art { position: relative; width: 150px; height: 190px; }
.ea-page { position: absolute; inset: 14px; background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); padding: 22px 16px; display: flex; flex-direction: column; gap: 9px; transform: rotate(-4deg); }
.ea-page.small { inset: 8px; padding: 14px 10px; gap: 6px; transform: none; }
.ea-page i { display: block; height: 6px; border-radius: 3px; background: var(--line); }
.ea-page i.short { width: 55%; }
.ea-beam { position: absolute; left: 6px; right: 6px; top: 10px; height: 3px; border-radius: 2px; background: var(--accent); box-shadow: 0 0 16px 3px var(--accent); animation: beam 2.6s ease-in-out infinite; opacity: .9; }
@keyframes beam { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(160px); } }
.tp-art .ea-beam { animation-name: beam-s; }
@keyframes beam-s { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(96px); } }
.ea-c { position: absolute; width: 26px; height: 26px; border: 3px solid var(--accent); animation: pulse 2.6s ease-in-out infinite; }
.ea-c.tl { left: 0; top: 0; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.ea-c.tr { right: 0; top: 0; border-left: 0; border-bottom: 0; border-radius: 0 8px 0 0; }
.ea-c.br { right: 0; bottom: 0; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }
.ea-c.bl { left: 0; bottom: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 8px; }
@keyframes pulse { 50% { transform: scale(1.08); opacity: .6; } }

.dock {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; align-items: center; gap: 12px;
  padding: 16px 20px calc(16px + var(--safe-b)); pointer-events: none;
  background: linear-gradient(to top, var(--bg) 55%, transparent);
}
.dock > * { pointer-events: auto; }
.dock-btn {
  height: 60px; min-width: 60px; border-radius: 30px; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font-weight: 700; font-size: 17px; transition: transform .25s var(--spring), box-shadow .25s; box-shadow: var(--shadow); white-space: nowrap;
}
.dock-btn:active { transform: scale(.93); }
.dock-btn.primary { background: var(--accent); color: var(--accent-ink); padding: 0 30px; box-shadow: 0 12px 30px -10px var(--accent); }
.dock-btn.secondary { background: var(--surface); }
.dock-btn.wide { padding: 0 22px; }
#btn-scan { min-width: 160px; }
#btn-scan .ic { width: 26px; height: 26px; }

/* ---------- Camera ---------- */
#v-camera { padding: 0; background: #000; }
#cam-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.cam-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#cam-quad { fill: rgba(255, 107, 74, .16); stroke: #ff6b4a; stroke-width: 3; stroke-linejoin: round; transition: opacity .25s, fill .3s, stroke .3s; filter: drop-shadow(0 0 6px rgba(255, 107, 74, .6)); }
#cam-quad.locked { fill: rgba(76, 201, 143, .2); stroke: #4cc98f; filter: drop-shadow(0 0 10px rgba(76, 201, 143, .8)); }
#cam-quad.hidden { opacity: 0; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cam-flash.go { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }
.cam-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) 10px calc(12px + var(--safe-l)); z-index: 2; }
.cam-top-right { display: flex; gap: 8px; align-items: center; }
.cam-status {
  position: absolute; left: 50%; top: calc(76px + var(--safe-t)); transform: translateX(-50%); white-space: nowrap;
  padding: 8px 16px; border-radius: 20px; font-size: 15px; font-weight: 600; color: #fff;
  background: rgba(20, 20, 24, .55); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); transition: background-color .3s;
}
.cam-status.good { background: rgba(24, 134, 90, .8); }
.cam-msg { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 16px; padding: 40px; z-index: 1; }
.cam-msg p { max-width: 30ch; color: #ddd; margin: 0; }
.cam-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; justify-items: center;
  padding: 24px 24px calc(28px + var(--safe-b)); background: linear-gradient(to top, rgba(0, 0, 0, .6), transparent); z-index: 2;
}
.shutter { position: relative; width: 80px; height: 80px; border-radius: 50%; display: grid; place-items: center; }
.shutter svg { position: absolute; inset: 0; width: 80px; height: 80px; transform: rotate(-90deg); }
.shutter .ring { fill: none; stroke: #fff; stroke-width: 4; }
.shutter .prog { fill: none; stroke: #4cc98f; stroke-width: 5; stroke-linecap: round; stroke-dasharray: 226.2; stroke-dashoffset: 226.2; transition: stroke-dashoffset .12s linear; }
.shutter .core { width: 62px; height: 62px; border-radius: 50%; background: #fff; transition: transform .2s var(--spring), background-color .2s; }
.shutter:active .core { transform: scale(.85); }
.shutter.snap .core { animation: snap .35s var(--spring); }
@keyframes snap { 40% { transform: scale(.78); } }
.cam-stack { position: relative; width: 56px; height: 56px; border-radius: 12px; transition: transform .3s var(--spring); }
.cam-stack:disabled { opacity: 0; transform: scale(.6); }
.stack-img { position: absolute; inset: 0; border-radius: 10px; background: #333 center / cover no-repeat; border: 2px solid #fff; box-shadow: 0 6px 18px rgba(0, 0, 0, .5); }
.cam-stack .badge { position: absolute; top: -8px; right: -8px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px; background: #ff6b4a; color: #1a0b06; font-size: 13px; font-weight: 800; display: grid; place-items: center; }
.cam-stack .done-lbl { position: absolute; top: calc(100% + 4px); left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 700; color: #fff; }
.cam-stack.bump { animation: bump .45s var(--spring); }
@keyframes bump { 40% { transform: scale(1.18); } }
.fly { position: fixed; z-index: 50; pointer-events: none; border-radius: 6px; box-shadow: 0 12px 40px rgba(0, 0, 0, .5); background: #fff center / cover no-repeat; transform-origin: 0 0; }

/* ---------- Document ---------- */
#v-doc { padding-bottom: 0; }
.title-input {
  border: 0; background: transparent; text-align: center; font-weight: 650; font-size: 17px; min-width: 0; width: 100%; padding: 8px; border-radius: 10px;
  text-overflow: ellipsis;
}
.title-input:focus { outline: none; background: var(--surface-2); }
.doc-meta { margin: 0; text-align: center; color: var(--muted); font-size: 13px; }
.page-grid {
  list-style: none; margin: 0; padding: 18px 20px calc(130px + var(--safe-b)); display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px 16px;
  overflow-y: auto; flex: 1; align-content: start;
}
.page-card { position: relative; animation: rise .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms); touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.page-card button.pc-open { display: block; width: 100%; aspect-ratio: 3 / 4; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; transition: transform .3s var(--spring), box-shadow .3s; }
.page-card img { width: 100%; height: 100%; object-fit: contain; display: block; background: var(--surface); }
.page-card .pnum { position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); min-width: 26px; height: 22px; padding: 0 8px; border-radius: 11px; background: var(--text); color: var(--bg); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.page-card.dragging { z-index: 10; }
.page-card.dragging button.pc-open { transform: scale(1.06) rotate(-1.5deg); box-shadow: var(--shadow-lg); }
.page-card.processing button.pc-open::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .45) 50%, transparent 70%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
li > .page-add { width: 100%; }
.page-add { aspect-ratio: 3 / 4; border-radius: 10px; border: 2px dashed var(--line); color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font-weight: 600; font-size: 14px; transition: border-color .2s, color .2s, transform .25s var(--spring); }
.page-add:hover { border-color: var(--accent); color: var(--accent); }
.page-add:active { transform: scale(.96); }

/* ---------- Page viewer ---------- */
.page-stage { position: relative; flex: 1; overflow: hidden; touch-action: pan-y; }
.page-track { position: absolute; inset: 0; display: flex; transition: transform .38s var(--ease); will-change: transform; }
.page-track.drag { transition: none; }
.page-slide { flex: 0 0 100%; height: 100%; display: grid; place-items: center; padding: 12px 20px; }
.page-slide img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; box-shadow: 0 20px 50px rgba(0, 0, 0, .6); background: #fff; transition: opacity .25s, transform .3s var(--ease); }
.page-slide img.swap { opacity: .25; transform: scale(.985); }
.busy { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .25); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.page-tools { flex: none; padding: 8px 0 calc(10px + var(--safe-b)); background: linear-gradient(to top, rgba(0, 0, 0, .4), transparent); }
.filters { display: flex; gap: 12px; padding: 4px 20px 10px; overflow-x: auto; scrollbar-width: none; justify-content: center; }
.filters::-webkit-scrollbar { display: none; }
.filter-chip { flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: #cfcac0; transition: color .2s; }
.filter-chip .fc-img { width: 58px; height: 74px; border-radius: 10px; background: #2a2a30 center / cover no-repeat; border: 2px solid transparent; transition: border-color .25s, transform .3s var(--spring); }
.filter-chip[aria-checked="true"] { color: #fff; }
.filter-chip[aria-checked="true"] .fc-img { border-color: #ff6b4a; transform: translateY(-3px); }
.filter-chip:active .fc-img { transform: scale(.94); }
.tool-row { display: flex; justify-content: space-around; padding: 4px 8px; }
.tool { min-width: 60px; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; font-weight: 600; border-radius: 14px; transition: background-color .2s, transform .2s var(--spring); }
.tool:active { transform: scale(.9); background: rgba(255, 255, 255, .08); }
.tool:hover { background: rgba(255, 255, 255, .06); }

/* ---------- Crop ---------- */
.crop-stage { position: relative; flex: 1; margin: 8px 16px; touch-action: none; }
#crop-canvas { position: absolute; border-radius: 4px; }
.crop-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.crop-svg .shade { fill: rgba(0, 0, 0, .55); fill-rule: evenodd; }
.crop-svg .edge { fill: none; stroke: #ff6b4a; stroke-width: 2.5; }
.crop-svg.invalid .edge { stroke: #ff3b3b; stroke-dasharray: 6 5; }
.crop-svg .handle { cursor: grab; outline: none; }
.crop-svg .handle .hit { fill: transparent; }
.crop-svg .handle .dot { fill: rgba(255, 255, 255, .15); stroke: #fff; stroke-width: 2.5; transition: r .2s var(--spring); filter: drop-shadow(0 1px 4px rgba(0, 0, 0, .6)); }
.crop-svg .handle.mid .dot { fill: #fff; stroke: none; }
.crop-svg .handle.active .dot, .crop-svg .handle:focus-visible .dot { r: 15; fill: rgba(255, 107, 74, .35); stroke: #ff6b4a; }
.loupe { position: absolute; width: 120px; height: 120px; border-radius: 50%; overflow: hidden; border: 3px solid #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, .6); pointer-events: none; opacity: 0; transform: scale(.6); transition: opacity .15s, transform .2s var(--spring); left: 0; top: 0; }
.loupe.on { opacity: 1; transform: scale(1); }
.loupe canvas { width: 120px; height: 120px; display: block; }
.crop-hint { margin: 0; text-align: center; color: #b9b4aa; font-size: 14px; min-height: 20px; }
.crop-tools { padding-bottom: calc(10px + var(--safe-b)); }

/* ---------- Text ---------- */
#v-text { padding-bottom: 0; }
.text-progress { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 0 40px 120px; text-align: center; }
.tp-art { position: relative; width: 100px; height: 124px; }
.text-progress p { margin: 0; font-weight: 600; }
.text-progress .fine { font-weight: 400; color: var(--muted); font-size: 13px; display: flex; gap: 6px; align-items: center; }
.bar-track { width: 100%; max-width: 280px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 3px; background: var(--accent); transition: width .3s var(--ease); }
.text-out {
  flex: 1; margin: 8px 16px 0; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  resize: none; font: 16px/1.6 var(--serif); padding-bottom: calc(110px + var(--safe-b)); animation: rise .4s var(--ease) both;
}
.text-out:focus { outline: none; border-color: var(--accent); }

/* ---------- Settings ---------- */
.settings { overflow-y: auto; padding: 4px 16px calc(40px + var(--safe-b)); }
.set-group { margin: 18px 0 0; }
.set-group h3 { margin: 0 6px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
.set-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; min-height: 56px; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row .lbl { display: flex; flex-direction: column; min-width: 0; }
.set-row small { color: var(--muted); font-size: 13px; }
.set-row.stack { flex-direction: column; align-items: stretch; gap: 10px; }
.set-row .seg { width: 100%; }
.text-btn { white-space: nowrap; }
.set-row.btn-row { width: 100%; text-align: left; font-weight: 600; }
.set-row.btn-row.danger { color: #d23a3a; }
.set-note { color: var(--muted); font-size: 13px; padding: 10px 6px 0; margin: 0; display: flex; gap: 8px; }
.set-note .ic { color: var(--ok); }
.status-ok { color: var(--ok); font-weight: 650; font-size: 14px; }

/* segmented & switches */
.seg-field { border: 0; padding: 0; margin: 0 0 14px; }
.seg-field legend { font-size: 13px; font-weight: 650; color: var(--muted); margin-bottom: 6px; padding: 0; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; min-height: 38px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); transition: background-color .25s, color .25s, box-shadow .25s; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
input[role="switch"] {
  appearance: none; -webkit-appearance: none; flex: none; width: 52px; height: 32px; border-radius: 16px; background: var(--line); position: relative; cursor: pointer; transition: background-color .25s; margin: 0;
}
input[role="switch"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); transition: transform .3s var(--spring); }
input[role="switch"]:checked { background: var(--ok); }
input[role="switch"]:checked::after { transform: translateX(20px); }

/* ---------- Sheets / dialogs ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 92vh; background: var(--surface); color: var(--text);
  border-radius: 26px 26px 0 0; box-shadow: var(--shadow-lg); overflow: auto;
}
dialog.sheet[open] { animation: sheet-in .42s var(--ease) both; }
dialog.sheet.closing { animation: sheet-out .28s var(--ease) both; }
dialog.sheet::backdrop { background: rgba(10, 8, 5, .45); backdrop-filter: blur(3px); animation: fade .3s both; }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 26px; } }
.sheet-body { padding: 10px 20px calc(20px + var(--safe-b)); }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet-body h2 { margin: 0 0 16px; font: 600 24px/1.2 var(--serif); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 13px; font-weight: 650; color: var(--muted); }
.field input { height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 14px; }
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; cursor: pointer; }
.switch-row span { display: flex; flex-direction: column; }
.switch-row small { color: var(--muted); font-size: 13px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.sheet-actions.single { grid-template-columns: 1fr; }
.ex-progress { margin-top: 12px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.ex-progress .bar-track { max-width: none; }
.ex-progress p { margin: 0; font-size: 14px; color: var(--muted); }
.menu-item { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 54px; padding: 0 8px; border-radius: 12px; font-weight: 600; font-size: 16px; text-align: left; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: #d23a3a; }
.confirm-text { color: var(--muted); margin: -8px 0 6px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(100px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; max-width: 480px; padding: 12px 12px 12px 18px; border-radius: 16px;
  background: #1f1d1a; color: #f5f2ec; box-shadow: var(--shadow-lg); font-size: 15px; animation: toast-in .4s var(--spring) both;
}
.toast.out { animation: toast-out .25s ease-in both; }
.toast button { color: #ff8a6e; font-weight: 700; padding: 6px 10px; border-radius: 10px; }
@keyframes toast-in { from { transform: translateY(20px) scale(.95); opacity: 0; } }
@keyframes toast-out { to { transform: translateY(10px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .ea-beam { display: none; }
}
@media (min-width: 900px) {
  .doc-grid { padding-left: max(20px, calc((100vw - 900px) / 2)); padding-right: max(20px, calc((100vw - 900px) / 2)); }
  .lib-head, .search { margin-left: max(0px, calc((100vw - 900px) / 2)); margin-right: max(0px, calc((100vw - 900px) / 2)); }
}
