:root {
  --bg: #f4f6fb; --card: #ffffff; --text: #14181f; --muted: #6a7384; --line: #e3e7ef;
  --brand: #1769ff; --brand-text: #fff; --danger: #d92d3a; --shadow: 0 2px 10px rgba(20, 30, 60, .12);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1116; --card: #181c24; --text: #eef1f6; --muted: #98a1b3; --line: #2a303b; --shadow: 0 2px 10px rgba(0, 0, 0, .5); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, system-ui, Segoe UI, Roboto, sans-serif; }
body { min-height: 100dvh; overscroll-behavior: none; }
#app { min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
h1, h2 { margin: 0; }
h2 { font-size: 1.15rem; margin-bottom: 12px; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .err { color: var(--danger); min-height: 1.4em; margin: 6px 0; }

button { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; cursor: pointer; }
button:active { opacity: .7; }
button.primary { background: var(--brand); color: var(--brand-text); border-color: var(--brand); font-weight: 600; }
button.danger { color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; color: var(--brand); padding: 8px 10px; }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; margin-top: 18px; font-size: .9rem; }
button.wide { width: 100%; margin-bottom: 10px; }
.grow { flex: 1; } .row { display: flex; gap: 10px; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px; background: var(--bg); border-bottom: 1px solid var(--line); }
.bar h1 { font-size: 1.1rem; } .ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; text-align: center; }
.content { padding: 12px; flex: 1; }
.actions { position: sticky; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.actions.row { display: flex; }

.search { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; margin-bottom: 12px; }
.list { display: grid; gap: 10px; }
.card { display: flex; gap: 12px; align-items: center; text-align: left; padding: 10px; width: 100%; box-shadow: var(--shadow); }
.card .meta { display: flex; flex-direction: column; min-width: 0; } .card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb { width: 56px; height: 72px; flex: none; border-radius: 8px; overflow: hidden; background: var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.empty { text-align: center; padding: 64px 16px; } .empty .big { font-size: 3.5rem; }
.fab { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom)); background: var(--brand); color: #fff;
  border: 0; border-radius: 999px; padding: 15px 32px; font-weight: 700; box-shadow: 0 6px 18px rgba(23, 105, 255, .45); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.pg { position: relative; padding: 0; background: var(--card); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); display: block; }
.pg img, .pg canvas { width: 100%; display: block; }
.num { position: absolute; left: 6px; bottom: 6px; background: rgba(0, 0, 0, .6); color: #fff; font-size: .75rem; padding: 1px 8px; border-radius: 999px; }
.x { position: absolute; right: 4px; top: 4px; padding: 2px 8px; border-radius: 999px; background: rgba(0, 0, 0, .6); color: #fff; border: 0; }

.stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 12px; min-height: 0; background: #0006; overflow: hidden; }
.stage > canvas { max-width: 100%; max-height: calc(100dvh - 230px); object-fit: contain; box-shadow: var(--shadow); background: #fff; }
.stack { position: relative; max-width: 100%; line-height: 0; }
.stack canvas { max-width: 100%; max-height: calc(100dvh - 220px); display: block; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; overflow: visible; }
.quad { fill: rgba(23, 105, 255, .18); stroke: var(--brand); }
.handle { fill: #fff; stroke: var(--brand); cursor: grab; touch-action: none; }
.hint { text-align: center; color: var(--muted); margin: 8px 0 0; font-size: .9rem; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px; }
.chip { white-space: nowrap; border-radius: 999px; padding: 8px 14px; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.lock { margin: auto; text-align: center; padding: 24px; width: min(340px, 100%); }
.logo { font-size: 3rem; color: var(--brand); } .lock h1 { margin: 6px 0; } .lock p { margin: 6px 0; }
.dots { display: flex; gap: 14px; justify-content: center; margin: 18px 0 6px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.dots i.on { background: var(--brand); border-color: var(--brand); }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.pad button { font-size: 1.6rem; padding: 16px 0; border-radius: 50%; aspect-ratio: 1; }

.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: min(520px, 100%); background: var(--bg); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 85dvh; overflow: auto; }
.text { white-space: pre-wrap; word-break: break-word; background: var(--card); border: 1px solid var(--line); padding: 12px; border-radius: 10px; max-height: 45dvh; overflow: auto; font: .9rem/1.45 ui-monospace, monospace; user-select: text; }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #222; color: #fff; padding: 10px 18px; border-radius: 999px; opacity: 0; transition: .25s; pointer-events: none; z-index: 40; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#busy { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .55); display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; gap: 12px; }
#busy[hidden] { display: none; }
.spin { width: 42px; height: 42px; border: 4px solid #fff5; border-top-color: #fff; border-radius: 50%; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.keep { display: flex; gap: 10px; align-items: center; margin: 16px 2px 4px; color: var(--muted); font-size: .95rem; }
.keep input { width: 20px; height: 20px; accent-color: var(--brand); }
