:root {
  --bg: #f3f2ef;
  --surface: #ffffff;
  --ink: #17191d;
  --muted: #6b6f78;
  --line: #dddbd5;
  --accent: #1f4fd1;
  --accent-ink: #ffffff;
  --danger: #c4372b;
  --sel: #1f4fd1;
  --radius: 12px;
  --tabs-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --ink: #eceae6;
    --muted: #9599a3;
    --line: #2f333b;
    --accent: #5b86f5;
    --accent-ink: #0d1020;
    --danger: #ef6b5f;
    --sel: #7aa0ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }
.spacer { flex: 1; }

.brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 6px; }
.logo { color: var(--danger); font-size: 18px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.who { color: var(--muted); font-size: 14px; }

.view { padding: 14px 16px calc(var(--tabs-h) + 190px + env(safe-area-inset-bottom)); max-width: 900px; margin: 0 auto; }
#view-login { padding-bottom: 16px; min-height: 100dvh; display: grid; place-items: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login .brand { font-size: 22px; }
.login p { margin: 0; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
label + label, label + button, label + .seg, .seg + button { margin-top: 10px; }
input:not([type]), input[type=password], input[type=text] {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%;
}
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; user-select: none;
  transition: transform .12s ease, background-color .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.big { min-height: 54px; padding: 0 24px; font-size: 17px; }

.row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }

.empty { text-align: center; padding: 18vh 8px 0; color: var(--muted); }
.empty p { margin-bottom: 18px; }

.docbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.docname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { color: var(--muted); font-size: 14px; margin: 6px 0 10px; }

.palette { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.palette::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; width: 84px; padding: 6px; border-radius: 10px;
  border: 2px solid var(--line); background: var(--surface); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--ink); font: inherit;
}
.chip img { width: 68px; height: 48px; object-fit: contain; }
.chip span { font-size: 11px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.on { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.chip.add { justify-content: center; color: var(--muted); font-size: 13px; }

.pages { display: flex; flex-direction: column; gap: 14px; }
.page { position: relative; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); user-select: none; -webkit-user-select: none; }
.page > img.bg { display: block; width: 100%; height: auto; pointer-events: none; }
.pageno { position: absolute; top: 6px; right: 8px; font-size: 12px; color: #555; background: rgba(255,255,255,.8); padding: 1px 6px; border-radius: 6px; pointer-events: none; }
.ov { position: absolute; touch-action: none; cursor: grab; }
.ov img { width: 100%; height: 100%; display: block; pointer-events: none; }
.ov.sel { outline: 2px dashed var(--sel); outline-offset: 2px; }
.sugg {
  position: absolute; z-index: 2; transform: translate(-50%, -50%);
  border: 2px dashed #e0473a; border-radius: 10px; background: rgba(224, 71, 58, .1);
  display: grid; place-items: center; cursor: pointer; padding: 0; font: inherit;
  animation: sugg-pulse 1.6s ease-in-out infinite;
}
.sugg.sig { z-index: 3; border-color: #1f4fd1; background: rgba(31, 79, 209, .1); }
.sugg.sig span { background: #1f4fd1; }
.sugg span { background: #e0473a; color: #fff; font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 6px; white-space: nowrap; }
@keyframes sugg-pulse { 50% { background: rgba(224, 71, 58, .22); } }
.small { font-size: 14px; }
.docbar .btn { flex: 0 0 auto; }

.selbar, .actionbar {
  position: fixed; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--surface); border-top: 1px solid var(--line);
}
.actionbar { bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); }
.actionbar .btn { flex: 1; }
.selbar { bottom: calc(var(--tabs-h) + 64px + env(safe-area-inset-bottom)); font-size: 14px; color: var(--muted);
  flex-direction: column; align-items: stretch; gap: 4px; padding: 6px 16px; }
.selrow { display: flex; align-items: center; gap: 10px; }
.selrow > span { width: 62px; flex: 0 0 auto; }
.selrow input { flex: 1; }
.rotval { width: 56px; font-variant-numeric: tabular-nums; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; height: var(--tabs-h); border: 0; background: none; color: var(--muted);
  font: inherit; font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tabs button span { font-size: 20px; line-height: 1; }
.tabs button.on { color: var(--accent); font-weight: 600; }

.assetgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.asset { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.asset .thumb { height: 110px; display: grid; place-items: center; border-radius: 8px;
  background: repeating-conic-gradient(#e9e9e9 0 25%, #fff 0 50%) 0 0 / 14px 14px; }
.asset .thumb img { max-width: 100%; max-height: 104px; }
.asset .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset .kind { font-size: 12px; color: var(--muted); }
.asset .acts { display: flex; gap: 4px; }
.asset .acts .btn { flex: 1; min-height: 32px; padding: 0 6px; font-size: 13px; }

.cropstage { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; background: #fff; margin-bottom: 12px; }
.cropstage img { display: block; width: 100%; pointer-events: none; }
#crop-rect { position: absolute; border: 2px solid var(--danger); background: rgba(196,55,43,.12); pointer-events: none; }
.croppanel { display: flex; flex-direction: column; }
.previewbox { margin: 12px 0; min-height: 90px; display: grid; place-items: center; border-radius: 8px;
  background: repeating-conic-gradient(#e9e9e9 0 25%, #fff 0 50%) 0 0 / 14px 14px; }
.previewbox img { max-width: 100%; max-height: 180px; }
.previewbox img:not([src]) { display: none; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; min-height: 40px; border: 0; background: var(--surface); color: var(--ink); font: inherit; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.userlist { list-style: none; padding: 0; margin: 0 0 14px; }
.userlist li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.userlist li b { flex: 1; }
.userlist .tag { font-size: 12px; color: var(--muted); }

#busy { position: fixed; inset: 0; z-index: 100; background: rgba(10,12,16,.55); display: grid; place-content: center; justify-items: center; color: #fff; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + 80px + env(safe-area-inset-bottom)); z-index: 90;
  max-width: 480px; margin: 0 auto; padding: 12px 14px; border-radius: 10px; background: var(--ink); color: var(--bg); text-align: center; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); width: min(92vw, 380px); padding: 20px; }
dialog::backdrop { background: rgba(10,12,16,.5); }
dialog p { margin-top: 0; word-break: break-word; }

@media (prefers-reduced-motion: reduce) { .btn { transition: none; } .spinner { animation-duration: 2s; } .sugg { animation: none; } }
