:root {
  --bg: #f4f4f1; --surface: #ffffff; --ink: #1c1c1a; --muted: #6b6b66; --line: #e2e1dc;
  --accent: #1d4ed8; --accent-ink: #ffffff; --accent-soft: rgba(29, 78, 216, .12);
  --danger: #b42318; --warn: #9a5b00; --stage: #e7e6e1;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .08);
  --radius: 12px; --bar: 56px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514; --surface: #1f1f1d; --ink: #ecebe6; --muted: #9c9b95; --line: #2e2e2b;
    --accent: #7aa2ff; --accent-ink: #0b1020; --accent-soft: rgba(122, 162, 255, .16);
    --danger: #ff8a7a; --warn: #f5b454; --stage: #0f0f0e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
.bar { position: sticky; top: 0; z-index: 20; height: var(--bar); display: flex; align-items: center; gap: 6px; padding: 0 16px; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.spacer { flex: 1; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; flex: none; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; flex: none; }
.icon-btn:hover:not(:disabled) { background: var(--accent-soft); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.icon-btn svg, .btn svg { width: 20px; height: 20px; }
.btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.doc-name { font: inherit; font-weight: 600; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 1px solid transparent; border-radius: 8px; background: none; padding: 4px 8px; cursor: text; text-align: left; }
.doc-name:hover { border-color: var(--line); background: var(--accent-soft); }
.doc-name-input { width: min(34vw, 520px); font-weight: 600; }
.login { max-width: 360px; margin: 48px auto 0; display: grid; gap: 12px; padding: 28px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.login h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.01em; }
.login .input { width: 100%; height: 40px; }
.login .btn { justify-content: center; height: 40px; }
.login-message { margin: 0; min-height: 1.4em; color: var(--danger); font-size: 14px; }
.zoom { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

.library { max-width: 880px; margin: 0 auto; padding: 32px 16px 64px; }
.drop { display: grid; place-items: center; gap: 8px; padding: 44px 16px; border: 1.5px dashed color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 16px; background: var(--surface); text-align: center; cursor: pointer; transition: background .15s, border-color .15s; }
.drop:hover, .drop.over, .drop:focus-visible { background: var(--accent-soft); border-color: var(--accent); outline: none; }
.drop > svg { width: 32px; height: 32px; color: var(--accent); }
.drop h2 { margin: 4px 0 0; font-size: 18px; letter-spacing: -.01em; }
.drop p { margin: 0; color: var(--muted); }
.status { display: grid; justify-items: center; gap: 8px; width: 100%; cursor: default; }
.status:empty { display: none; }
.progress { width: min(320px, 80%); height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.password { display: flex; gap: 8px; }
.input { height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); }
.docs { list-style: none; margin: 28px 0 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.doc.picked { border-color: var(--accent); background: var(--accent-soft); }
.doc input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; cursor: pointer; }
.merge-panel { margin-top: 20px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); display: grid; gap: 10px; }
.merge-panel[hidden] { display: none; }
.merge-panel h3 { margin: 0; font-size: 16px; letter-spacing: -.01em; }
.merge-panel ol { margin: 0; padding: 0 0 0 22px; display: grid; gap: 6px; }
.merge-panel li { display: flex; align-items: center; gap: 8px; min-width: 0; }
.merge-panel li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merge-panel .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.merge-panel .input { flex: 1; min-width: 180px; }
.merge-panel .icon-btn { width: 30px; height: 30px; }
.task { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-top: 8px; }
.task .progress { flex: 1; }
.doc { min-width: 0; display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.doc > svg { width: 22px; height: 22px; color: var(--muted); flex: none; }
.doc a.title { flex: 1; min-width: 0; color: var(--ink); text-decoration: none; }
.doc .name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info { color: var(--muted); font-size: 13px; }
.doc .actions { display: flex; gap: 6px; align-items: center; }
.empty { padding: 28px 0; color: var(--muted); text-align: center; }

body.is-editor { background: var(--stage); }
.stage { display: flex; flex-direction: column; align-items: center; gap: 20px; padding: 24px 16px 96px; overflow-x: auto; }
.page { position: relative; background: #fff; box-shadow: var(--shadow); flex: none; }
.page canvas { display: block; }
.page.saving::after { content: ""; position: absolute; inset: 0; background: rgba(255, 255, 255, .35); cursor: progress; }
.layer { position: absolute; inset: 0; }
.layer.adding { cursor: text; }
.para { position: absolute; border-radius: 3px; cursor: text; }
.para:hover { outline: 1.5px solid color-mix(in srgb, var(--accent) 55%, transparent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.para.locked { cursor: not-allowed; }
.para.locked:hover { outline: 1.5px dashed var(--muted); background: transparent; }
.layer.editing .para, .layer.adding .para { pointer-events: none; }
.notice { position: absolute; left: 16px; right: 16px; top: 16px; padding: 10px 12px; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); font-size: 13px; }
.textframe { position: absolute; z-index: 5; }
.textbox { position: relative; white-space: pre-wrap; overflow-wrap: break-word; outline: 2px solid #1d4ed8; outline-offset: 1px; box-shadow: 0 0 0 5px rgba(29, 78, 216, .14); caret-color: #1d4ed8; color: #000; }
.grip { position: absolute; top: -3px; bottom: -3px; width: 14px; cursor: ew-resize; touch-action: none; z-index: 6; }
.grip.left { left: -15px; }
.grip.right { right: -15px; }
.grip::after { content: ""; position: absolute; left: 5px; top: 50%; width: 4px; height: min(30px, 80%); transform: translateY(-50%); border-radius: 2px; background: #1d4ed8; box-shadow: 0 0 0 2px rgba(255, 255, 255, .9); }
.grip:hover::after { background: #1e40af; }
.format { position: absolute; z-index: 6; display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line); white-space: nowrap; }
.format .icon-btn { width: 32px; height: 32px; }
.format select, .format input[type=number] { height: 30px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 13px; padding: 0 6px; }
.format select { max-width: 150px; }
.format input[type=number] { width: 62px; }
.format input[type=color] { width: 30px; height: 30px; padding: 0; border: 0; background: none; cursor: pointer; }
.hint { position: fixed; left: 50%; top: calc(var(--bar) + 12px); transform: translateX(-50%); padding: 8px 14px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 13px; z-index: 15; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); max-width: min(560px, calc(100vw - 32px)); padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; font-size: 14px; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }
@media (max-width: 640px) {
  .bar { gap: 2px; padding: 0 8px; }
  .zoom, .btn span { display: none; }
  .doc-name { max-width: 38vw; }
  .stage { padding: 12px 8px 80px; align-items: flex-start; }
}
