/* =========================================================
   PindaiKu — design system
   ========================================================= */
:root {
  --bg: #0d0b14;
  --bg-2: #15121f;
  --surface: rgba(255, 255, 255, 0.055);
  --surface-2: rgba(255, 255, 255, 0.09);
  --surface-solid: #1b1727;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f3f0fa;
  --text-2: #a9a2bd;
  --text-3: #6f6885;
  --accent: #ff7a59;
  --accent-2: #b86bff;
  --accent-3: #4fd1c5;
  --grad: linear-gradient(120deg, #ff7a59 0%, #ff4f8b 45%, #b86bff 100%);
  --ok: #3ddc97;
  --danger: #ff5470;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
  color-scheme: dark;
}
html[data-theme="light"] {
  --bg: #f6f3ee;
  --bg-2: #ffffff;
  --surface: rgba(20, 14, 40, 0.045);
  --surface-2: rgba(20, 14, 40, 0.08);
  --surface-solid: #ffffff;
  --line: rgba(20, 14, 40, 0.1);
  --text: #1a1525;
  --text-2: #5e5672;
  --text-3: #958ea6;
  --shadow: 0 20px 50px -24px rgba(40, 20, 80, 0.35);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

/* ---------- aurora background ---------- */
.aurora { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
/* radial gradients instead of filter: blur() — cheap to paint on low-end phones */
.aurora span { position: absolute; border-radius: 50%; opacity: .5; will-change: transform; animation: drift 22s ease-in-out infinite alternate; }
.aurora span:nth-child(1) { width: 70vmax; height: 70vmax; background: radial-gradient(circle, rgba(255,122,89,.75), rgba(255,122,89,0) 65%); top: -32vmax; left: -22vmax; }
.aurora span:nth-child(2) { width: 60vmax; height: 60vmax; background: radial-gradient(circle, rgba(184,107,255,.75), rgba(184,107,255,0) 65%); top: -18vmax; right: -26vmax; animation-delay: -7s; }
.aurora span:nth-child(3) { width: 56vmax; height: 56vmax; background: radial-gradient(circle, rgba(79,209,197,.5), rgba(79,209,197,0) 65%); bottom: -30vmax; left: 16vmax; opacity: .4; animation-delay: -14s; }
html.lite .aurora span { animation: none; }
html[data-theme="light"] .aurora span { opacity: .22; }
@keyframes drift { to { transform: translate(6vmax, 4vmax) scale(1.12); } }

/* ---------- views ---------- */
.view { position: fixed; inset: 0; z-index: 1; display: none; flex-direction: column; overflow: hidden; }
.view.active { display: flex; animation: viewIn .35s cubic-bezier(.2, .8, .2, 1); }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } }
#view-home { overflow-y: auto; padding-bottom: calc(110px + var(--safe-b)); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(14px + var(--safe-t)) 18px 12px;
  position: sticky; top: 0; z-index: 5;
}
#view-home .topbar { backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); background: color-mix(in srgb, var(--bg) 55%, transparent); }
.topbar.dark { background: #0b0a10; color: #fff; }
.topbar h3 { flex: 1; margin: 0; font-size: 17px; font-weight: 700; }
.brand { display: flex; align-items: center; gap: 12px; flex: 1; }
.brand-logo { width: 42px; height: 42px; border-radius: 13px; box-shadow: 0 8px 20px -6px rgba(255, 79, 139, .6); }
.brand h1 { margin: 0; font-size: 21px; font-weight: 800; letter-spacing: -.02em; }
.brand h1 em { font-family: var(--serif); font-style: italic; font-weight: 400; font-size: 25px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; padding-left: 1px; }
.brand .sub { margin: 0; font-size: 12px; color: var(--text-2); }
.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); transition: transform .15s, background .2s;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.glass { background: rgba(10, 8, 18, .45); border-color: rgba(255, 255, 255, .15); color: #fff; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.icon-btn.glass.on { background: #ffd34d; color: #111; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 14px; font-weight: 600; font-size: 14.5px;
  border: 1px solid var(--line); background: var(--surface); transition: transform .15s, filter .2s, background .2s;
  white-space: nowrap; cursor: pointer; user-select: none;
}
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--grad); border: 0; color: #fff; box-shadow: 0 10px 30px -10px rgba(255, 79, 139, .7); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: rgba(255, 84, 112, .14); color: var(--danger); border-color: rgba(255, 84, 112, .3); }
.btn.lg { padding: 15px 22px; font-size: 15.5px; border-radius: 16px; }
.btn.sm { padding: 8px 13px; font-size: 13.5px; border-radius: 12px; }
.btn.sm svg { width: 18px; height: 18px; }
.link-btn { color: var(--accent); font-weight: 600; font-size: 13px; padding: 6px 0; }

/* ---------- hero ---------- */
.hero { position: relative; z-index: 1; padding: 18px 20px 8px; max-width: 1100px; width: 100%; margin: 0 auto; }
.hero h2 { font-size: clamp(30px, 6.5vw, 54px); line-height: 1.04; letter-spacing: -.035em; margin: 10px 0 12px; font-weight: 800; max-width: 760px; }
.hero h2 .serif { font-family: var(--serif); font-style: italic; font-weight: 400; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; letter-spacing: -.01em; }
.hero p { color: var(--text-2); max-width: 540px; margin: 0 0 22px; line-height: 1.55; font-size: 15px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.stats { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.stat { padding: 10px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); min-width: 96px; }
.stat b { display: block; font-size: 20px; font-weight: 800; }
.stat span { font-size: 12px; color: var(--text-2); }

/* ---------- library ---------- */
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 26px 20px 12px; max-width: 1100px; margin: 0 auto; width: 100%; position: relative; z-index: 1; }
.lib-head h3 { margin: 0; font-size: 18px; }
.lib-tools { display: flex; gap: 8px; flex: 1; justify-content: flex-end; min-width: 240px; }
.search { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); flex: 1; max-width: 320px; }
.search svg { width: 18px; color: var(--text-3); }
.search input { border: 0; background: none; outline: none; padding: 10px 0; width: 100%; font-size: 14px; }
.select-sm, select { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 9px 10px; font-size: 13.5px; outline: none; }
select option { background: var(--surface-solid); color: var(--text); }

.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 16px; padding: 4px 20px 20px; max-width: 1100px; margin: 0 auto; width: 100%; position: relative; z-index: 1; }
.card { position: relative; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); overflow: hidden; cursor: pointer; transition: transform .2s, box-shadow .25s; animation: cardIn .4s backwards; }
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.card:active { transform: scale(.97); }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.card .cover { aspect-ratio: 3/4; background: #fff; position: relative; overflow: hidden; display: grid; place-items: center; }
.card .cover img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.card .cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 60%, rgba(0, 0, 0, .25)); }
.card .pages-badge { position: absolute; z-index: 1; right: 8px; bottom: 8px; background: rgba(10, 8, 18, .75); color: #fff; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 99px; backdrop-filter: blur(6px); }
.card .info { padding: 10px 12px 12px; }
.card .info b { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .info small { color: var(--text-2); font-size: 11.5px; }
.card .more { position: absolute; z-index: 2; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: rgba(10, 8, 18, .55); color: #fff; backdrop-filter: blur(6px); }
.card .more svg { width: 18px; }

.empty { text-align: center; padding: 30px 20px 60px; color: var(--text-2); position: relative; z-index: 1; }
.empty-art { width: 96px; height: 96px; margin: 0 auto 14px; border-radius: 28px; display: grid; place-items: center; background: var(--surface); border: 1px dashed var(--line); }
.empty-art svg { width: 44px; height: 44px; color: var(--accent); }
.empty h4 { color: var(--text); margin: 0 0 6px; font-size: 17px; }

.fab { position: fixed; z-index: 6; right: 20px; bottom: calc(22px + var(--safe-b)); width: 64px; height: 64px; border-radius: 22px; background: var(--grad); color: #fff; display: grid; place-items: center; box-shadow: 0 16px 40px -10px rgba(255, 79, 139, .8); transition: transform .2s; }
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: scale(.9); }

/* ---------- camera ---------- */
.camera { background: #000; color: #fff; }
#video, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#overlay { pointer-events: none; }
.grid-lines { position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,.18) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.18) 1px, transparent 1px);
  background-size: 33.333% 33.333%; background-position: -1px -1px; }
.flash-fx { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash-fx.go { animation: flash .35s 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: 10px; padding: calc(14px + var(--safe-t)) 14px 30px; background: linear-gradient(rgba(0,0,0,.55), transparent); }
.cam-top-r { display: flex; gap: 8px; }
.cam-status { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; padding: 8px 14px; border-radius: 99px; background: rgba(10, 8, 18, .5); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,.12); max-width: 46vw; }
.cam-status .txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #ffb547; flex: none; box-shadow: 0 0 0 4px rgba(255, 181, 71, .25); }
.cam-status.found .dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(61, 220, 151, .25); }
.cam-status.hold .dot { background: var(--accent-3); animation: pulse .7s infinite; }
@keyframes pulse { 50% { transform: scale(1.5); } }

.cam-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 18px calc(22px + var(--safe-b)); background: linear-gradient(transparent, rgba(0,0,0,.7)); }
.cam-modes { display: flex; justify-content: center; gap: 8px; margin-bottom: 18px; }
.chip { padding: 7px 14px; border-radius: 99px; font-size: 13px; font-weight: 600; color: rgba(255,255,255,.75); background: rgba(10, 8, 18, .45); border: 1px solid rgba(255,255,255,.14); backdrop-filter: blur(8px); display: inline-flex; align-items: center; gap: 8px; }
.chip.active { background: #fff; color: #111; }
.chip .sw { width: 26px; height: 15px; border-radius: 99px; background: rgba(255,255,255,.3); position: relative; transition: background .2s; }
.chip .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px; border-radius: 50%; background: #fff; transition: transform .2s; }
.chip.toggle.on .sw { background: var(--ok); }
.chip.toggle.on .sw::after { transform: translateX(11px); }
.cam-controls { display: flex; align-items: center; justify-content: space-between; max-width: 420px; margin: 0 auto; }
.cam-thumb-btn { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; background: rgba(10,8,18,.5); border: 1px solid rgba(255,255,255,.18); cursor: pointer; }
.shutter { position: relative; width: 82px; height: 82px; border-radius: 50%; display: grid; place-items: center; }
.shutter .ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.shutter .ring circle { fill: none; stroke: #fff; stroke-width: 5; stroke-dasharray: 289; stroke-dashoffset: 0; transition: stroke .2s; }
.shutter.counting .ring circle { stroke: var(--ok); }
.shutter .core { width: 62px; height: 62px; border-radius: 50%; background: #fff; transition: transform .12s, background .2s; }
.shutter:active .core { transform: scale(.86); }
.shutter.counting .core { background: #dfffee; }
.cam-stack { position: relative; width: 54px; height: 54px; }
.stack-img { position: absolute; inset: 0; border-radius: 12px; background: rgba(255,255,255,.12) center/cover no-repeat; border: 2px solid #fff; transition: transform .3s; }
.cam-stack.pop .stack-img { animation: pop .45s; }
@keyframes pop { 40% { transform: scale(1.18) rotate(-4deg); } }
.cam-stack .badge { position: absolute; top: -8px; right: -8px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; background: var(--grad); font-size: 12px; font-weight: 800; display: grid; place-items: center; }

/* ---------- crop ---------- */
.crop { background: #0b0a10; color: #fff; }
.crop-stage { position: relative; flex: 1; margin: 10px; touch-action: none; overflow: hidden; }
#crop-canvas { position: absolute; }
#crop-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; stroke: none; }
#crop-svg .mask { fill: rgba(0, 0, 0, .55); fill-rule: evenodd; }
#crop-svg .poly { fill: rgba(79, 209, 197, .1); stroke: var(--accent-3); stroke-width: 2; }
#crop-svg .handle { fill: #fff; stroke: var(--accent-3); stroke-width: 3; cursor: grab; }
#crop-svg .handle-hit { fill: transparent; cursor: grab; }
#crop-svg .edge-handle { fill: var(--accent-3); stroke: #fff; stroke-width: 2; }
#loupe { position: absolute; top: 10px; left: 10px; width: 140px; height: 140px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 10px 30px rgba(0,0,0,.5); display: none; pointer-events: none; background: #000; }
#loupe.right { left: auto; right: 10px; }
.tool-row { display: flex; justify-content: space-around; gap: 4px; padding: 10px 10px calc(14px + var(--safe-b)); }
.tool { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; padding: 8px 6px; border-radius: 14px; min-width: 64px; color: inherit; opacity: .9; transition: background .2s; }
.tool:hover { background: var(--surface); }
.tool:active { transform: scale(.94); }
.tool.danger { color: var(--danger); }

/* ---------- document editor ---------- */
.doc { background: var(--bg); }
.doc .topbar { background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(14px); }
.doc-title { flex: 1; min-width: 0; }
.doc-title input { width: 100%; background: none; border: 0; outline: none; font-size: 17px; font-weight: 700; padding: 2px 0; border-bottom: 1px dashed transparent; }
.doc-title input:focus { border-bottom-color: var(--accent); }
.doc-title small { color: var(--text-2); font-size: 12px; }
.doc-main { flex: 1; display: flex; min-height: 0; position: relative; z-index: 1; }
.preview-wrap { flex: 1; position: relative; display: grid; place-items: center; padding: 14px 18px; min-height: 0; }
.preview-paper { position: absolute; inset: 14px 18px; display: flex; align-items: center; justify-content: center; min-height: 0; }
#preview-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.6), 0 0 0 1px var(--line); background: #fff; transition: opacity .2s; }
.processing { position: absolute; inset: 0; display: grid; place-items: center; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 3px solid rgba(255,255,255,.25); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.nav-arrow { position: absolute; top: 50%; translate: 0 -50%; width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; backdrop-filter: blur(8px); }
.nav-arrow.left { left: 10px; }
.nav-arrow.right { right: 10px; }
.nav-arrow.right svg { transform: scaleX(-1); }
.page-indicator { position: absolute; bottom: 18px; left: 50%; translate: -50% 0; background: rgba(10, 8, 18, .7); color: #fff; padding: 4px 12px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.doc-side { width: 340px; display: flex; flex-direction: column; gap: 12px; padding: 14px 18px 14px 0; overflow-y: auto; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.adj-toggle { display: none; }
.panel-h { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 700; color: var(--text-2); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .06em; }
.filters { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter { flex: none; width: 70px; text-align: center; font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.filter .fthumb { width: 70px; height: 88px; border-radius: 12px; background: #fff center/cover no-repeat; border: 2px solid transparent; margin-bottom: 5px; transition: border-color .2s, transform .2s; }
.filter.active { color: var(--text); }
.filter.active .fthumb { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 18px -8px rgba(255, 122, 89, .8); }
.sliders { display: grid; gap: 8px; margin: 10px 0 4px; }
.sliders label { display: grid; grid-template-columns: 78px 1fr; align-items: center; font-size: 12.5px; color: var(--text-2); }
input[type="range"] { -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px; background: var(--surface-2); outline: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.tool-row.compact { flex-wrap: wrap; justify-content: flex-start; padding: 6px 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.tool-row.compact .tool { flex: 1 0 30%; }

.filmstrip-wrap { display: flex; align-items: center; gap: 10px; padding: 10px 18px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(14px); position: relative; z-index: 2; }
.filmstrip { flex: 1; display: flex; gap: 10px; overflow-x: auto; padding: 6px 2px; scrollbar-width: thin; }
.film-item { flex: none; width: 64px; position: relative; cursor: pointer; }
.film-item .fi-img { width: 64px; height: 84px; border-radius: 10px; background: #fff center/cover no-repeat; border: 2px solid transparent; transition: border-color .2s; }
.film-item.active .fi-img { border-color: var(--accent); }
.film-item .num { position: absolute; left: 4px; bottom: 4px; background: rgba(10, 8, 18, .75); color: #fff; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.film-item.sortable-ghost { opacity: .35; }
.film-item.sortable-chosen .fi-img { transform: scale(1.06); }
.film-add { display: flex; gap: 8px; }
.add-tile { width: 54px; height: 84px; border-radius: 12px; border: 1.5px dashed var(--line); display: grid; place-items: center; color: var(--text-2); cursor: pointer; background: var(--surface); }
.add-tile:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(5, 3, 10, .55); backdrop-filter: blur(3px); opacity: 0; pointer-events: none; transition: opacity .25s; }
.scrim.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; z-index: 21; left: 50%; bottom: 0; width: min(560px, 100%); max-height: 88vh; overflow-y: auto;
  transform: translate(-50%, 105%); transition: transform .35s cubic-bezier(.2, .9, .25, 1);
  background: var(--surface-solid); border: 1px solid var(--line); border-bottom: 0; border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(22px + var(--safe-b)); box-shadow: 0 -20px 60px -20px rgba(0,0,0,.6);
}
.sheet.show { transform: translate(-50%, 0); }
.sheet.tall { height: 82vh; display: flex; flex-direction: column; }
.sheet-grip { width: 42px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 10px; }
.sheet h3 { margin: 4px 0 14px; font-size: 19px; }
.sheet-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-radius: 14px; padding: 4px; gap: 4px; border: 1px solid var(--line); }
.seg button { padding: 9px; border-radius: 10px; font-weight: 700; font-size: 13.5px; color: var(--text-2); }
.seg button.active { background: var(--grad); color: #fff; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0 6px; }
.form-grid label { display: grid; gap: 6px; font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.form-grid input, .set-col input { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; outline: none; font-size: 13.5px; }
.form-grid input:focus, .set-col input:focus { border-color: var(--accent); }
.exp-size-info { font-size: 12px; color: var(--text-3); min-height: 18px; margin: 6px 0 10px; }
.share-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 6px; }
.share-btn { display: flex; flex-direction: column; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 4px 0; }
.share-btn:active { transform: scale(.93); }
.sb-ico { width: 52px; height: 52px; border-radius: 17px; display: grid; place-items: center; color: #fff; }
.sb-ico.c1 { background: linear-gradient(135deg, #ff7a59, #ff4f8b); }
.sb-ico.c2 { background: linear-gradient(135deg, #b86bff, #6b5bff); }
.sb-ico.c3 { background: linear-gradient(135deg, #ffb547, #ff7a59); }
.sb-ico.c4 { background: linear-gradient(135deg, #64748b, #334155); }
.sb-ico.c5 { background: linear-gradient(135deg, #4fd1c5, #2b8cff); }
.sb-ico.wa { background: linear-gradient(135deg, #3ddc84, #128c7e); }
.sb-ico.tg { background: linear-gradient(135deg, #37bbfe, #007dbb); }
.sb-ico.gd { background: conic-gradient(from 200deg, #1fa463, #ffd04b, #4688f4, #1fa463); }
.progress { position: relative; height: 34px; border-radius: 12px; background: var(--surface); overflow: hidden; margin-top: 14px; border: 1px solid var(--line); }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--grad); opacity: .85; transition: width .2s; }
.progress .lbl { position: relative; display: grid; place-items: center; height: 100%; font-size: 12.5px; font-weight: 700; }

.settings { display: grid; gap: 16px; }
.set-group h5 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.set-col { display: grid; gap: 8px; font-size: 14px; padding: 8px 0; }
.set-col small { color: var(--text-3); font-size: 12px; line-height: 1.45; }
.danger-t { color: var(--danger); }
.about { font-size: 12px; color: var(--text-3); line-height: 1.5; text-align: center; }
.switch { -webkit-appearance: none; appearance: none; width: 44px; height: 26px; border-radius: 99px; background: var(--surface-2); position: relative; cursor: pointer; transition: background .2s; flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(18px); }

#ocr-text { flex: 1; width: 100%; resize: none; margin: 12px 0; padding: 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); outline: none; font-size: 14px; line-height: 1.55; }
.row-btns { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.row-btns .btn { flex: 1; }

#sign-pad { flex: 1; width: 100%; background: #fff; border-radius: 16px; touch-action: none; margin: 8px 0; min-height: 200px; }
.hint { font-size: 12.5px; color: var(--text-2); margin: 0 0 12px; }
.sign-colors { display: flex; gap: 8px; }
.sign-colors button { width: 28px; height: 28px; border-radius: 50%; background: var(--c); border: 3px solid var(--surface-solid); box-shadow: 0 0 0 2px var(--line); }
.sign-colors button.active { box-shadow: 0 0 0 2px var(--accent); }
.sign-placer { position: fixed; inset: 0; z-index: 30; background: rgba(5, 3, 10, .92); display: flex; flex-direction: column; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); }
.sp-stage { position: relative; flex: 1; display: grid; place-items: center; min-height: 0; }
#sp-page { max-width: 100%; max-height: 100%; background: #fff; border-radius: 4px; }
.sp-sig { position: absolute; border: 1.5px dashed var(--accent); touch-action: none; cursor: move; }
.sp-sig img { width: 100%; height: 100%; display: block; pointer-events: none; }
.sp-handle { position: absolute; right: -11px; bottom: -11px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; cursor: nwse-resize; }
.row-btns.floating { padding-top: 14px; max-width: 520px; width: 100%; margin: 0 auto; }

.dialog { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(5, 3, 10, .55); backdrop-filter: blur(4px); padding: 20px; animation: viewIn .2s; }
.dialog-card { width: min(400px, 100%); background: var(--surface-solid); border: 1px solid var(--line); border-radius: 22px; padding: 22px; box-shadow: var(--shadow); }
.dialog-card h4 { margin: 0 0 8px; font-size: 17px; }
.dialog-card p { margin: 0 0 16px; color: var(--text-2); font-size: 14px; line-height: 1.5; }
.dialog-card input { width: 100%; margin-bottom: 16px; padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); outline: none; }
.dialog-card input:focus { border-color: var(--accent); }

.menu { position: fixed; z-index: 35; min-width: 190px; background: var(--surface-solid); border: 1px solid var(--line); border-radius: 16px; padding: 6px; box-shadow: var(--shadow); animation: viewIn .15s; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border-radius: 10px; font-size: 14px; text-align: left; }
.menu button:hover { background: var(--surface); }
.menu button svg { width: 18px; color: var(--text-2); }
.menu button.danger { color: var(--danger); }
.menu button.danger svg { color: var(--danger); }

.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translate(-50%, 20px); background: rgba(20, 16, 30, .94); color: #fff; padding: 11px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; border: 1px solid rgba(255,255,255,.1); max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #5c1424; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .doc-main { flex-direction: column; }
  .doc-side { width: 100%; padding: 0 14px 6px; overflow: visible; flex: none; }
  .panel { padding: 8px 10px; position: relative; }
  .panel-h { position: absolute; right: 10px; top: -30px; margin: 0; text-transform: none; letter-spacing: 0; }
  .panel-h > span { display: none; }
  .adj-toggle { display: inline-block !important; background: var(--surface-2); padding: 4px 10px; border-radius: 99px; font-size: 11.5px; }
  .sliders { grid-template-columns: 1fr 1fr; gap: 12px; display: none; }
  .panel.adj .sliders { display: grid; }
  .filter { font-size: 10.5px; white-space: nowrap; }
  .sliders label { grid-template-columns: 1fr; gap: 4px; }
  .link-btn { display: none; }
  .tool-row.compact { flex-wrap: nowrap; overflow-x: auto; background: none; border: 0; padding: 0; }
  .tool-row.compact .tool { flex: 1 0 auto; min-width: 58px; font-size: 10.5px; }
  .preview-wrap { padding: 0; }
  .preview-paper { inset: 8px 14px; }
  .nav-arrow { display: none; }
  .filter { width: 52px; }
  .filter .fthumb { width: 52px; height: 64px; border-radius: 10px; margin-bottom: 3px; }
  .tool-row.compact .tool { padding: 4px; gap: 3px; }
  .tool-row.compact .tool svg { width: 20px; height: 20px; }
}
@media (max-width: 520px) {
  .form-grid { grid-template-columns: 1fr; }
  .lib-tools { min-width: 100%; }
  .search { max-width: none; }
  .library { grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 4px 14px 20px; }
  .hero, .lib-head { padding-left: 16px; padding-right: 16px; }
  .hero-actions .btn { flex: 1; }
  .tool { min-width: 56px; }
}
@media (min-width: 521px) { .fab { display: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
