@font-face { font-family: "Caveat"; src: url("../vendor/fonts/caveat-latin-400-normal.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Dancing Script"; src: url("../vendor/fonts/dancing-script-latin-400-normal.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Homemade Apple"; src: url("../vendor/fonts/homemade-apple-latin-400-normal.woff2") format("woff2"); font-display: swap; }

:root {
  --ink: #16181d; --ink2: #2a2e36; --paper: #f6f4ef; --desk: #d6d2c8; --line: #dcd7cc; --panel: #ebe8e0;
  --red: #d6402b; --red-d: #b8331f; --blue: #1a73d6; --text: #1d1f23; --mute: #6a6861;
  --ui: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 var(--ui); color: var(--text); background: var(--paper);
  display: grid; grid-template-rows: auto auto auto minmax(0, 1fr); grid-template-areas: "top" "tools" "props" "work";
  height: 100vh; height: 100dvh; overflow: hidden; overscroll-behavior: none; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: .35; cursor: default; }
[hidden] { display: none !important; }
body.empty .doc-only { display: none !important; }
body:not(.empty) #welcome { display: none; }

/* ---------- top bar ---------- */
#top { grid-area: top; display: flex; align-items: center; gap: 6px; height: 50px; padding: 0 10px; background: var(--ink); color: #fff; min-width: 0; }
.brand { display: flex; align-items: center; gap: 7px; font: italic 600 20px/1 Georgia, "Times New Roman", serif; letter-spacing: .2px; margin-right: 6px; flex: none; }
.fname { min-width: 0; flex: 0 1 auto; max-width: 30vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #c9c6be; font-size: 13px; padding-right: 6px; }
.grp { display: flex; align-items: center; flex: none; }
.sp { flex: 1; }
.ib { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 6px; flex: none; }
#top .ib:hover:not(:disabled), #top .zoomval:hover { background: rgba(255, 255, 255, .12); }
.zoomval { min-width: 54px; height: 32px; border-radius: 6px; font-variant-numeric: tabular-nums; font-size: 13px; }
.pagenav { gap: 6px; color: #c9c6be; font-size: 13px; margin-left: 6px; font-variant-numeric: tabular-nums; }
.pagenav input { width: 44px; height: 30px; text-align: center; border: 1px solid #454a54; border-radius: 6px; background: var(--ink2); color: #fff; }
.primary { background: var(--red); color: #fff; font-weight: 600; border-radius: 6px; padding: 9px 16px; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.primary:hover { background: var(--red-d); }
.ghost { border: 1px solid #c4bfb3; border-radius: 6px; padding: 8px 14px; background: #fff; font-weight: 500; }
.ghost:hover { border-color: var(--ink); }
.danger { background: #fff; border: 1px solid var(--red); color: var(--red-d); border-radius: 6px; padding: 8px 14px; font-weight: 600; }
.big { padding: 13px 22px; font-size: 16px; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

/* ---------- tools ---------- */
#tools { grid-area: tools; display: flex; align-items: center; gap: 2px; padding: 5px 8px; background: var(--paper); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
#tools::-webkit-scrollbar, #props::-webkit-scrollbar { display: none; }
.tb { flex: none; min-width: 58px; height: 52px; padding: 4px 6px 3px; border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: #33353a; }
.tb span { white-space: nowrap; }
.tb:hover { background: #e7e3d9; }
.tb.on { background: var(--ink); color: #fff; }
.tsep { flex: none; width: 1px; height: 30px; background: var(--line); margin: 0 5px; }

/* ---------- options bar ---------- */
#props { grid-area: props; display: flex; align-items: center; gap: 6px; min-height: 46px; padding: 5px 12px; background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; white-space: nowrap; }
.pb { flex: none; height: 34px; min-width: 34px; padding: 0 7px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; }
.pb:hover { background: #f0ede6; }
.pb.on { background: var(--ink); color: #fff; }
.pb.wide { border-color: #c4bfb3; padding: 0 12px; font-weight: 500; }
.pb.danger { color: var(--red-d); border-color: transparent; background: none; padding: 0 7px; }
.pb.sw { border-color: #d5d0c5; padding: 0 9px 0 6px; font-size: 13px; }
.pb.sw i { width: 20px; height: 20px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .28); display: block; }
.none { background: linear-gradient(135deg, #fff 45%, var(--red) 46%, var(--red) 54%, #fff 55%) !important; }
.psel, .pnum { flex: none; height: 34px; border: 1px solid #d5d0c5; border-radius: 6px; background: #fff; padding: 0 6px; }
.pnum { width: 54px; text-align: center; -moz-appearance: textfield; }
.pnum::-webkit-inner-spin-button { display: none; }
.pgrp { display: inline-flex; align-items: center; gap: 1px; flex: none; }
.psep { flex: none; width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.hint { color: var(--mute); font-size: 13px; line-height: 1.25; white-space: normal; }

/* ---------- work area ---------- */
#work { grid-area: work; display: flex; min-height: 0; min-width: 0; }
#side { width: 192px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); min-height: 0; }
body.side-hidden #side { display: none; }
.side-head { display: none; }
.page-acts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 8px; border-bottom: 1px solid var(--line); }
.pa-note { grid-column: 1 / -1; font-size: 12px; color: var(--mute); display: flex; justify-content: space-between; padding: 0 2px 3px; }
.linkbtn { color: var(--red-d); text-decoration: underline; font-size: 12px; }
.pa { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px 4px; border-radius: 6px; font-size: 10.5px; color: #33353a; }
.pa:hover { background: #dcd8ce; }
.pa.danger { border: 0; background: none; font-weight: inherit; }
.pa.danger:hover { color: var(--red-d); background: #dcd8ce; }
#thumbs { flex: 1; overflow-y: auto; padding: 10px 14px 30px; display: grid; grid-template-columns: 1fr; gap: 6px; align-content: start; overscroll-behavior: contain; }
.th { position: relative; padding: 8px 14px 3px; border-radius: 6px; cursor: pointer; user-select: none; -webkit-user-select: none; }
.th:hover { background: #dedad0; }
.th.cur { background: #fff; box-shadow: inset 0 0 0 2px var(--ink); }
.th.picked { background: #f8dcd6; box-shadow: inset 0 0 0 2px var(--red); }
.th.moving { opacity: .3; }
.th-pic { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .28); overflow: hidden; }
.th-pic canvas { width: 100%; height: 100%; display: block; }
.th-n { display: block; text-align: center; font-size: 11.5px; color: var(--mute); padding-top: 3px; font-variant-numeric: tabular-nums; }
.th-chk { position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; border-radius: 5px; background: #fff; border: 1.5px solid #9c978b; color: transparent; display: none; place-items: center; }
.th:hover .th-chk, .th.picked .th-chk { display: grid; }
.th.picked .th-chk { background: var(--red); border-color: var(--red); color: #fff; }
.th-grip { position: absolute; right: 2px; top: 4px; width: 26px; height: 30px; display: none; place-items: center; color: #55534d; background: rgba(255, 255, 255, .92); border-radius: 5px; touch-action: none; cursor: grab; }
.th-ghost { position: fixed; z-index: 90; pointer-events: none; opacity: .92; transform: rotate(-2deg); background: #fff; box-shadow: 0 8px 22px rgba(0, 0, 0, .35); margin: 0; }
.th-ghost .th-chk, .th-ghost .th-grip { display: none !important; }
.th-bar { position: fixed; z-index: 91; background: var(--red); border-radius: 2px; pointer-events: none; }

#view { overflow-anchor: none; flex: 1; min-width: 0; overflow: auto; background: var(--desk); touch-action: pan-x pan-y; overscroll-behavior: contain; outline: 0; }
#pages { --zoom: 1; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 18px 28px 90px; width: max-content; min-width: 100%; }
.pg { position: relative; flex: none; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .22), 0 6px 18px rgba(40, 34, 20, .16); width: calc(var(--w) * var(--zoom) * 1px); height: calc(var(--h) * var(--zoom) * 1px); overflow: clip; overflow-clip-margin: 16px; }
.pc { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#pages.drawmode .pg { cursor: crosshair; touch-action: none; }
#pages[data-tool="text"] .pg { cursor: text; }

.ob { position: absolute; left: 0; top: 0; pointer-events: none; }
.ob > * { position: absolute; }
.hit { pointer-events: auto; cursor: move; }
.sv { overflow: visible; pointer-events: none; }
.sv .hit { pointer-events: visiblePainted; }
.sv .hs { pointer-events: stroke; }
.ob.sel .hit { touch-action: none; }
.drawmode .hit, .drawmode .fw, .temp, .temp * { pointer-events: none !important; }
.txt, .txt-edit { transform-origin: 0 0; }
.txt { white-space: pre; unicode-bidi: plaintext; user-select: none; -webkit-user-select: none; }
#pages[data-tool="text"] .txt, #pages[data-tool="edittext"] .txt { cursor: text; }
.ob.editing .txt { visibility: hidden; }
.cover { pointer-events: none; }
.cover.hit { pointer-events: auto; }
.txt-edit { position: absolute; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; resize: none; overflow: hidden; white-space: pre; unicode-bidi: plaintext; outline: calc(1.5px / var(--zoom)) dashed var(--red); outline-offset: calc(3px / var(--zoom)); caret-color: var(--red); }
.mk.hl { opacity: .45; }
.ob img { user-select: none; -webkit-user-drag: none; }
.lnk { border: calc(1.5px / var(--zoom)) dashed var(--blue); background: rgba(26, 115, 214, .09); overflow: hidden; }
.lnk span { display: block; font-size: 8px; line-height: 1.3; color: #0e4f9a; padding: 1px 3px; white-space: nowrap; }
.temp { opacity: .85; }

.selbox { position: absolute; pointer-events: none; outline: calc(1.5px / var(--zoom)) solid var(--blue); }
.selbox.free { left: 0; top: 0; width: 0; height: 0; outline: 0; }
.hd { position: absolute; width: calc(11px / var(--zoom)); height: calc(11px / var(--zoom)); margin: calc(-5.5px / var(--zoom)) 0 0 calc(-5.5px / var(--zoom)); background: #fff; border: calc(1.5px / var(--zoom)) solid var(--blue); border-radius: 50%; pointer-events: auto; touch-action: none; cursor: nwse-resize; }
.hd.nw { left: 0; top: 0; } .hd.n { left: 50%; top: 0; cursor: ns-resize; } .hd.ne { left: 100%; top: 0; cursor: nesw-resize; }
.hd.e { left: 100%; top: 50%; cursor: ew-resize; } .hd.se { left: 100%; top: 100%; } .hd.s { left: 50%; top: 100%; cursor: ns-resize; }
.hd.sw { left: 0; top: 100%; cursor: nesw-resize; } .hd.w { left: 0; top: 50%; cursor: ew-resize; }
.selbox.free .hd { cursor: move; }

.fw { position: absolute; margin: 0; padding: 0 2px; border: 0; border-radius: 0; background: rgba(26, 115, 214, .11); font-family: Arial, Helvetica, sans-serif; color: #111; line-height: 1.15; }
textarea.fw { resize: none; padding: 2px; scrollbar-width: none; }
textarea.fw::-webkit-scrollbar { display: none; }
.fw:focus { outline: calc(1.5px / var(--zoom)) solid var(--blue); background: rgba(255, 255, 255, .6); }
.fchk { cursor: pointer; }
.fchk.on::after { content: ""; position: absolute; inset: 10%; background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 12.500l5 5L20 6.500' fill='none' stroke='%23111' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.fchk.radio { border-radius: 50%; }
.fchk.radio.on::after { inset: 24%; background: #111; border-radius: 50%; }
.run { position: absolute; cursor: text; border-bottom: calc(1px / var(--zoom)) dashed rgba(214, 64, 43, .6); }
.run:hover { background: rgba(214, 64, 43, .13); outline: calc(1px / var(--zoom)) solid var(--red); }

/* ---------- welcome ---------- */
#welcome { grid-row: 1 / -1; grid-column: 1; overflow: auto; display: grid; place-items: center; padding: 24px 16px; background: var(--paper) repeating-linear-gradient(0deg, transparent 0 35px, rgba(22, 24, 29, .045) 35px 36px); }
.w-card { width: min(600px, 100%); padding: 38px 34px 30px; background: #fff; border: 2px dashed #b9b3a5; border-radius: 10px; cursor: pointer; }
.w-card > * { cursor: auto; }
.w-mark { margin-bottom: 14px; cursor: pointer; }
.w-card h1 { font: 600 34px/1.12 Georgia, "Times New Roman", serif; margin: 0 0 10px; letter-spacing: -.3px; }
.w-sub { margin: 0 0 22px; font-size: 16px; color: #45443f; }
.w-btns { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 26px; }
.w-facts { list-style: none; margin: 0; padding: 18px 0 0; border-top: 1px solid var(--line); display: grid; gap: 8px; color: #45443f; }
.w-facts b { color: var(--text); }
#dropHint { display: none; position: fixed; inset: 0; z-index: 200; background: rgba(22, 24, 29, .72); place-items: center; pointer-events: none; }
#dropHint div { color: #fff; font: 600 30px Georgia, serif; border: 3px dashed #fff; border-radius: 12px; padding: 40px 60px; }
body.dropping #dropHint { display: grid; }

/* ---------- dialogs, menus, toasts ---------- */
.m-back { position: fixed; inset: 0; z-index: 150; background: rgba(22, 24, 29, .5); display: grid; place-items: center; padding: 12px; }
.m-box { width: min(440px, 100%); max-height: calc(100dvh - 24px); display: flex; flex-direction: column; background: #fff; border-radius: 10px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.m-box.wide { width: min(640px, 100%); }
.m-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 8px 18px; font-size: 16px; }
.m-head .ib:hover { background: #f0ede6; }
.m-body { padding: 4px 18px 12px; overflow-y: auto; }
.m-body p { margin: 0 0 12px; }
.m-body h3 { font-size: 14px; margin: 14px 0 8px; }
.m-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 10px 18px 16px; }
.field { width: 100%; height: 42px; border: 1px solid #b9b3a5; border-radius: 6px; padding: 0 12px; font-size: 16px; margin-bottom: 10px; }
.small { font-size: 12.5px; color: var(--mute); }
.plain { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.keys { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 18px; }
.keys div { display: flex; gap: 8px; align-items: baseline; }
kbd { font: 12px ui-monospace, Consolas, monospace; background: #f0ede6; border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; white-space: nowrap; }
.chk { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 13px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { padding: 8px 14px; border-bottom: 3px solid transparent; font-weight: 500; color: var(--mute); }
.tabs button.on { border-color: var(--red); color: var(--text); }
.sig-pad { width: 100%; aspect-ratio: 1200 / 420; background: #fbfaf7; border: 1px solid #b9b3a5; border-radius: 6px; touch-action: none; cursor: crosshair; display: block; }
.sig-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.inkrow { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--mute); }
.dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #b9b3a5; }
.dot.on { box-shadow: 0 0 0 2px var(--ink); }
.sig-fonts { display: grid; gap: 6px; }
.sig-font { text-align: left; font-size: 28px; line-height: 2; padding: 0 14px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sig-font.on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.sig-prev { min-height: 150px; display: grid; place-items: center; text-align: center; padding: 14px; border: 1px dashed #b9b3a5; border-radius: 6px; color: var(--mute); background: #fbfaf7; }
.sig-prev img { max-width: 100%; max-height: 180px; }
.sig-saved { display: grid; gap: 8px; }
.sig-item { display: flex; align-items: center; gap: 6px; }
.sig-use { flex: 1; height: 84px; border: 1px solid var(--line); border-radius: 6px; background: #fbfaf7; display: grid; place-items: center; padding: 8px; }
.sig-use:hover { border-color: var(--ink); }
.sig-use img { max-width: 100%; max-height: 66px; }

.pop { position: fixed; z-index: 160; min-width: 210px; background: #fff; border: 1px solid #cfc9bd; border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .22); padding: 5px; color: var(--text); }
.pop-it { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 5px; text-align: left; }
.pop-it:hover, .pop-it.on { background: #f0ede6; }
.pop-it kbd { margin-left: auto; }
.pop-sep { height: 1px; background: var(--line); margin: 4px 0; }
.pop-sw { min-width: 0; }
.swatches { display: grid; grid-template-columns: repeat(6, 30px); gap: 6px; padding: 5px; }
.swatches button { width: 30px; height: 30px; border-radius: 5px; border: 1px solid rgba(0, 0, 0, .3); }
.swatches button:hover { transform: scale(1.1); }
.swatches .custom { grid-column: span 2; height: 30px; display: flex; align-items: center; gap: 5px; font-size: 12px; cursor: pointer; position: relative; }
.swatches .custom input { width: 30px; height: 30px; padding: 0; border: 1px solid rgba(0, 0, 0, .3); border-radius: 5px; background: none; cursor: pointer; }

#toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 170; display: grid; gap: 8px; width: min(460px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--ink); color: #fff; border-radius: 8px; padding: 11px 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); font-size: 13.5px; border-left: 4px solid #6f7480; }
.toast.ok { border-left-color: #3fb46a; }
.toast.warn { border-left-color: #f0a51c; }
.toast button { color: #ffb4a6; font-weight: 600; white-space: nowrap; text-decoration: underline; }
#busy { position: fixed; inset: 0; z-index: 180; background: rgba(246, 244, 239, .72); display: grid; place-items: center; }
.busy-box { background: var(--ink); color: #fff; padding: 16px 22px; border-radius: 8px; display: flex; gap: 14px; align-items: center; font-weight: 500; }
.spin { width: 20px; height: 20px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .25); border-top-color: #fff; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- touch devices ---------- */
@media (pointer: coarse) {
  .pop-it kbd { display: none; }
  .hd { width: calc(20px / var(--zoom)); height: calc(20px / var(--zoom)); margin: calc(-10px / var(--zoom)) 0 0 calc(-10px / var(--zoom)); }
  .th-chk, .th-grip { display: grid; }
  .pb, .psel, .pnum { height: 40px; min-width: 40px; }
}

/* ---------- phones and small tablets ---------- */
@media (max-width: 759px) {
  body { grid-template-rows: auto minmax(0, 1fr) auto auto; grid-template-areas: "top" "work" "props" "tools"; }
  #top { height: 48px; gap: 2px; padding: 0 6px 0 10px; }
  .brand span, .zoomgrp, .pagenav, .xs-hide { display: none; }
  .fname { max-width: none; flex: 1 1 0; }
  .sp { display: none; }
  .primary { padding: 9px 12px; }
  #tools { border-bottom: 0; border-top: 1px solid var(--line); padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); }
  .tb { min-width: 56px; height: 50px; }
  #props { border-bottom: 0; border-top: 1px solid var(--line); min-height: 48px; padding: 4px 8px; }
  #pages { padding: 10px 8px 60px; gap: 10px; }
  #side { position: fixed; inset: 48px 0 0 0; width: auto; z-index: 100; border: 0; transform: translateY(102%); transition: transform .22s ease; visibility: hidden; }
  body.side-open #side { transform: none; visibility: visible; }
  body.side-hidden #side { display: flex; }
  .side-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 0 14px; font-size: 16px; }
  .side-head .ib:hover { background: #dcd8ce; }
  .page-acts { grid-template-columns: repeat(6, 1fr); }
  .pa { font-size: 10px; }
  #thumbs { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 10px 8px 40px; }
  .th { padding: 8px 8px 3px; }
  #toasts { bottom: calc(118px + env(safe-area-inset-bottom)); }
  .w-card { padding: 26px 20px 22px; }
  .w-card h1 { font-size: 27px; }
  .w-btns .big { flex: 1 1 100%; justify-content: center; }
  .keys { grid-template-columns: 1fr; }
  .m-back { align-items: end; padding: 0; }
  .m-box, .m-box.wide { width: 100%; border-radius: 12px 12px 0 0; max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom); }
  .m-foot button { flex: 1; justify-content: center; }
  #dropHint div { font-size: 22px; padding: 26px 30px; }
}
@media (max-width: 400px) { .fname { display: none; } .sp { display: block; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 1.5s !important; } }
