/* =====================================================================
   Visual identity: "Sign here" flags.
   Graphite ink on paper-grey, with the highlighter-yellow sticky flag used
   for the one thing to do next (open, finish, the selected item).
   Type: Thmanyah Serif Display for headings, Thmanyah Sans for the interface.
   ===================================================================== */

@font-face { font-family: 'thmanyah sans'; src: url('../fonts/thmanyah/thmanyahsans-Regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'thmanyah sans'; src: url('../fonts/thmanyah/thmanyahsans-Medium.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'thmanyah sans'; src: url('../fonts/thmanyah/thmanyahsans-Bold.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'thmanyah sans'; src: url('../fonts/thmanyah/thmanyahsans-Black.woff2') format('woff2'); font-weight: 800; font-display: swap; }
@font-face { font-family: 'thmanyah serif display'; src: url('../fonts/thmanyah/thmanyahserifdisplay-Regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'thmanyah serif display'; src: url('../fonts/thmanyah/thmanyahserifdisplay-Bold.woff2') format('woff2'); font-weight: 700; font-display: swap; }

/* ================= Tokens ================= */
:root {
    --bg: #F3F3F0;          /* paper grey */
    --surface: #FFFFFF;
    --surface-2: #F8F8F5;
    --surface-3: #EAEAE4;
    --text: #24262B;        /* graphite */
    --muted: #6B6E76;
    --border: #DEDED8;
    --ink: #24262B;         /* selection, focus, active states */
    --on-ink: #FFFFFF;
    --flag: #FFC83D;        /* highlighter yellow: the next step */
    --flag-hover: #F5B915;
    --flag-ink: #3D2F00;
    --flag-soft: #FFF3CC;
    --bar: #24262B;         /* editor bars */
    --on-bar: #FFFFFF;
    --bar-muted: #B9BBC2;
    --bar-hover: #34373E;
    --danger: #C2372B;
    --danger-soft: #FCEBE9;
    --success: #1E7A44;
    --viewer-bg: #E4E4DF;
    --shadow-sm: 0 1px 0 var(--border), 0 0 0 1px var(--border);
    --shadow: 0 6px 20px rgb(36 38 43 / 12%);
    --shadow-lg: 0 18px 44px rgb(36 38 43 / 20%);
    --radius: 10px;
    --radius-sm: 4px;
    --font: 'thmanyah sans', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
    --font-display: 'thmanyah serif display', 'thmanyah sans', Georgia, serif;
    --topbar-h: 56px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #17181B; --surface: #202226; --surface-2: #26282D; --surface-3: #303238;
        --text: #ECECE8; --muted: #A0A3AA; --border: #36383E;
        --ink: #ECECE8; --on-ink: #17181B;
        --flag-soft: #3A3220;
        --bar: #0E0F11; --bar-hover: #1F2125;
        --danger: #F07A6F; --danger-soft: #3A1E1C; --success: #5BC98A;
        --viewer-bg: #121315;
        --shadow: 0 6px 20px rgb(0 0 0 / 45%); --shadow-lg: 0 18px 44px rgb(0 0 0 / 60%);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #17181B; --surface: #202226; --surface-2: #26282D; --surface-3: #303238;
    --text: #ECECE8; --muted: #A0A3AA; --border: #36383E;
    --ink: #ECECE8; --on-ink: #17181B;
    --flag-soft: #3A3220;
    --bar: #0E0F11; --bar-hover: #1F2125;
    --danger: #F07A6F; --danger-soft: #3A1E1C; --success: #5BC98A;
    --viewer-bg: #121315;
    --shadow: 0 6px 20px rgb(0 0 0 / 45%); --shadow-lg: 0 18px 44px rgb(0 0 0 / 60%);
    color-scheme: dark;
}

/* ================= Base ================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-family: var(--font-display); font-weight: 700; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-xs { width: 13px; height: 13px; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 28px; height: 28px; }
.icon-xl { width: 44px; height: 44px; stroke-width: 1.6; }
[dir="rtl"] .flip-rtl { transform: scaleX(-1); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }

/* The sticky "sign here" flag: a yellow tab whose point aims where you go next. */
.flag-shape {
    --tip: 16px;
    clip-path: polygon(0 0, calc(100% - var(--tip)) 0, 100% 50%, calc(100% - var(--tip)) 100%, 0 100%);
    padding-inline-end: calc(var(--tip) + 14px) !important;
}
[dir="rtl"] .flag-shape {
    clip-path: polygon(var(--tip) 0, 100% 0, 100% 100%, var(--tip) 100%, 0 50%);
}
.flag-mark { width: 22px; height: 16px; background: var(--flag); display: inline-block; flex: none;
    clip-path: polygon(0 0, 72% 0, 100% 50%, 72% 100%, 0 100%); }
[dir="rtl"] .flag-mark { clip-path: polygon(28% 0, 100% 0, 100% 100%, 28% 100%, 0 50%); }

/* ================= Buttons ================= */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 42px; padding: 0 18px;
    border-radius: var(--radius-sm); border: 1px solid transparent;
    background: var(--surface-3); color: var(--text);
    font-weight: 500; white-space: nowrap;
    transition: background .15s, border-color .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--flag); color: var(--flag-ink); font-weight: 700; }
.btn-primary:hover { background: var(--flag-hover); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
.btn-outline { background: var(--surface); border-color: var(--border); }
.btn-outline:hover { border-color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; gap: 6px; }
.btn-lg { min-height: 54px; padding: 0 26px; font-size: 17px; }
.btn-block { width: 100%; }
.icon-btn {
    display: inline-grid; place-items: center;
    width: 40px; height: 40px; flex: none;
    border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text);
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.icon-btn.danger { color: var(--danger); }
.link-btn { background: none; border: 0; color: var(--text); padding: 0; text-decoration: underline; align-self: flex-start; font-size: 14px; }
.toggle {
    display: inline-grid; place-items: center; width: 40px; height: 40px;
    border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface);
}
.toggle[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }

/* ================= Forms ================= */
.input {
    width: 100%; min-height: 42px; padding: 8px 12px;
    border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--surface); color: var(--text);
}
.input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.input-lg { min-height: 50px; font-size: 17px; }
.input-num { width: 82px; }
textarea.input { resize: vertical; min-height: 64px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 500; font-size: 14px; }
.field-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }
.form-error { color: var(--danger); min-height: 1.4em; font-size: 14px; }
.check-row, .radio-row { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 40px; }
.check-row input, .radio-row input { width: 20px; height: 20px; accent-color: var(--ink); flex: none; }
.radio-list { display: flex; flex-direction: column; gap: 2px; }
.radio-list .input { margin-top: 4px; }
input[type="range"] { accent-color: var(--ink); width: 100%; min-height: 32px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.segmented { display: flex; gap: 2px; padding: 3px; background: var(--surface-3); border-radius: 6px; }
.seg-btn {
    flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px; padding: 0 14px; border: 0; border-radius: var(--radius-sm); background: transparent; font-weight: 500; color: var(--muted);
}
.seg-btn[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 700; box-shadow: 0 1px 2px rgb(0 0 0 / 12%); }
.segmented-sm .seg-btn { min-height: 34px; padding: 0 10px; }

.color-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.swatch {
    position: relative; width: 34px; height: 34px; flex: none; padding: 0;
    display: grid; place-items: center; cursor: pointer;
    border-radius: 50%; border: 0; background: var(--c, transparent);
    box-shadow: inset 0 0 0 1px rgb(0 0 0 / 15%);
}
.swatch-check { width: 18px; height: 18px; color: #fff; stroke-width: 3; opacity: 0; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.swatch[aria-checked="true"] .swatch-check { opacity: 1; }
.swatch-more { background: var(--surface); box-shadow: none; border: 2px dashed var(--muted); color: var(--muted); }
.swatch-more[aria-expanded="true"] { border-color: var(--ink); color: var(--ink); border-style: solid; }
.swatch-more.is-set { background: var(--c); border: 2px solid var(--surface); box-shadow: 0 0 0 2px var(--ink); color: #fff; }
.swatch-light { box-shadow: inset 0 0 0 1px var(--border); }
.swatch-light .swatch-check { color: #111; }
.color-picker { display: flex; flex-direction: column; gap: 10px; max-width: 100%; }
.color-extra { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }
.color-grid { display: grid; grid-template-columns: repeat(auto-fill, 30px); gap: 8px; }
.color-grid .swatch { width: 30px; height: 30px; }
.native-color { position: relative; display: block; height: 42px; border-radius: var(--radius-sm); cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); }
.native-color:hover { border-color: var(--ink); }
.native-color-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.native-color span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--text); font-weight: 500; font-size: 14px; pointer-events: none; }
.native-color span::before { content: ''; width: 18px; height: 18px; border-radius: 50%; flex: none;
    background: conic-gradient(#ef4444, #eab308, #22c55e, #06b6d4, #3b82f6, #8b5cf6, #ef4444); }
.hex-input { width: 110px; min-height: 36px; font-family: ui-monospace, monospace; }
.color-chip {
    min-height: 34px; padding: 0 12px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.color-chip[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); font-weight: 700; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }

/* Signatures are dark ink, so previews always sit on light "paper", even in dark mode. */
.checker {
    background-color: #fff;
    background-image: linear-gradient(45deg, #f0f0ec 25%, transparent 25%), linear-gradient(-45deg, #f0f0ec 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #f0f0ec 75%), linear-gradient(-45deg, transparent 75%, #f0f0ec 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.note {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 12px 14px; border-radius: 6px; background: var(--flag-soft); color: var(--text);
}
.note .btn { margin-inline-start: auto; }
.ios-install { grid-column: 1; align-items: flex-start; flex-wrap: nowrap; font-size: 14px; }
.ios-install .flag-mark { margin-top: 4px; }
.ios-install-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.share-glyph { vertical-align: -3px; }
.ios-install .icon-btn { width: 32px; height: 32px; margin: -6px -6px 0 0; }
.card { background: var(--surface); border-radius: 6px; padding: 20px; box-shadow: var(--shadow-sm); }

/* ================= Home ================= */
.home { min-height: 100%; display: flex; flex-direction: column; }
.appbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
    max-width: 960px; width: 100%; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 21px; }
.appbar-actions { display: flex; align-items: center; gap: 2px; }
.home-main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 16px 16px 56px; display: flex; flex-direction: column; gap: 28px; }
.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 40px; align-items: center; }
.hero h1 { font-size: clamp(28px, 4.4vw, 44px); line-height: 1.35; max-width: 16ch; }
.privacy { grid-column: 1; display: flex; align-items: flex-start; gap: 8px; font-size: 14px; color: var(--muted); max-width: 44ch; }
.privacy .icon { color: var(--success); margin-top: 3px; }

/* The drop zone is a sheet of paper with a "sign here" flag sticking out of it. */
.drop-zone {
    grid-column: 2; grid-row: 1 / span 2;
    position: relative; display: flex; flex-direction: column; gap: 12px;
    padding: 30px 26px 26px; min-height: 260px;
    background: #fff; border-radius: 3px; box-shadow: var(--shadow-sm), var(--shadow);
    cursor: pointer; color: #24262B;
}
.doc-lines { display: flex; flex-direction: column; gap: 11px; }
.doc-lines i { display: block; height: 7px; border-radius: 4px; background: #ECECE7; }
.doc-lines i.s { width: 58%; }
.drop-zone #open-pdf-btn { margin-top: auto; align-self: flex-end; margin-inline-end: -40px; min-height: 52px; font-size: 17px; }
.drop-zone .drop-hint { color: #6B6E76; font-size: 13px; }
.drop-zone:hover #open-pdf-btn { background: var(--flag-hover); }
.btn-flag { background: var(--flag); color: var(--flag-ink); font-weight: 700; }
.btn-flag:hover { background: var(--flag-hover); }

.how { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.how li { display: flex; gap: 12px; padding: 16px; background: var(--surface); border-radius: 3px; box-shadow: var(--shadow-sm); }
.how p { color: var(--muted); font-size: 14px; }
.how strong { font-weight: 700; }
.how-num { flex: none; font-family: var(--font-display); font-size: 26px; line-height: 1.1; font-weight: 700; }
.recent { display: flex; flex-direction: column; gap: 12px; }
.recent h2 { font-size: 20px; }
.drop-overlay { display: none; }
body.dragging[data-view="home"] .drop-overlay {
    display: grid; place-items: center; position: fixed; inset: 0; z-index: 50;
    background: rgb(36 38 43 / 40%); backdrop-filter: blur(2px);
}
.drop-overlay > div { display: flex; align-items: center; gap: 10px; padding: 22px 40px; background: var(--flag); color: var(--flag-ink); font-weight: 700; font-size: 20px; box-shadow: var(--shadow-lg); pointer-events: none; }

.doc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.doc-row { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.doc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.doc-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.doc-actions { display: flex; }

/* ================= Editor ================= */
.editor { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--viewer-bg); }
.topbar {
    height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
    display: flex; align-items: center; gap: 4px;
    background: var(--bar); color: var(--on-bar); z-index: 20;
}
.topbar .icon-btn { color: var(--on-bar); }
.topbar .icon-btn:hover { background: var(--bar-hover); }
.topbar .muted { color: var(--bar-muted); }
.doc-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; padding: 0 6px; }
#doc-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-group { display: flex; align-items: center; }
.zoom-group { margin: 0 4px; }
.zoom-level { border: 0; background: none; color: var(--on-bar); min-width: 54px; font-size: 13px; font-variant-numeric: tabular-nums; }
#finish-btn { margin-inline-start: 8px; min-height: 38px; }

.editor-body { flex: 1; min-height: 0; display: flex; position: relative; }
.viewer { flex: 1; min-width: 0; overflow: auto; position: relative; touch-action: pan-x pan-y; overscroll-behavior: contain; }
.pages-col { display: flex; flex-direction: column; align-items: center; gap: 22px; width: max-content; min-width: 100%; padding: 24px 24px 72px; }
.page { position: relative; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 12%), 0 8px 24px rgb(0 0 0 / 8%); flex: none; }
.page-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* Page not drawn yet: show a spinner instead of a blank sheet */
.page.is-loading::before {
    content: ''; position: absolute; top: 50%; left: 50%; width: 32px; height: 32px; margin: -16px 0 0 -16px;
    border-radius: 50%; border: 3px solid #E4E4DF; border-top-color: #24262B; animation: spin .8s linear infinite;
}
.page-overlay { position: absolute; inset: 0; }
.page-label {
    position: absolute; top: 100%; left: 50%; transform: translate(-50%, 4px);
    font-size: 12px; color: var(--muted); font-family: var(--font);
}

/* Thumbnails */
.thumbs {
    width: 0; overflow: hidden auto; flex: none;
    background: var(--surface); border-inline-end: 1px solid var(--border);
    display: flex; flex-direction: column; align-items: center; gap: 14px;
    transition: width .2s; padding: 0;
}
body.thumbs-open .thumbs { width: 150px; padding: 16px 0 120px; }
.thumb { border: 0; background: none; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; width: 104px; color: var(--text); }
.thumb-img { position: relative; width: 100%; background: #fff; border-radius: 2px; box-shadow: 0 0 0 1px var(--border); outline: 2px solid transparent; outline-offset: 3px; overflow: hidden; }
.thumb-img canvas { width: 100%; height: 100%; display: block; }
.thumb.active .thumb-img { outline-color: var(--ink); }
.thumb-num { font-size: 12px; color: var(--muted); }
.thumb.active .thumb-num { color: var(--text); font-weight: 700; }
.thumb-badge { position: absolute; top: 4px; inset-inline-end: 4px; min-width: 20px; height: 20px; border-radius: 3px; padding: 0 5px; background: var(--flag); color: var(--flag-ink); font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* Placed items. These sit on white paper in every theme, so they use fixed graphite. */
.item { position: absolute; touch-action: none; cursor: grab; outline: none; user-select: none; -webkit-user-select: none; }
.item:active { cursor: grabbing; }
.item-canvas { width: 100%; height: 100%; display: block; pointer-events: none; }
.item::before { content: ''; position: absolute; inset: -4px; border: 1.5px dashed transparent; pointer-events: none; }
.item:hover::before { border-color: rgb(36 38 43 / 40%); }
.item.selected::before { border: 2px solid #24262B; }
.item:focus-visible::before { border-color: #24262B; }
.sel-handle { display: none; position: absolute; z-index: 2; }
.item.selected .sel-handle { display: block; }
.sel-handle.corner {
    width: 16px; height: 16px; background: #fff; border: 2.5px solid #24262B; border-radius: 2px;
}
.sel-handle.corner::after { content: ''; position: absolute; inset: -12px; } /* bigger touch target */
.sel-handle.tl { top: -12px; left: -12px; cursor: nwse-resize; }
.sel-handle.br { bottom: -12px; right: -12px; cursor: nwse-resize; }
.sel-handle.tr { top: -12px; right: -12px; cursor: nesw-resize; }
.sel-handle.bl { bottom: -12px; left: -12px; cursor: nesw-resize; }
.sel-handle.rotate {
    top: -46px; left: 50%; transform: translateX(-50%);
    width: 28px; height: 28px; border-radius: 50%; background: #24262B; color: #FFC83D;
    display: none; place-items: center; cursor: grab;
}
.item.selected .sel-handle.rotate { display: grid; }
.sel-handle.rotate::before { content: ''; position: absolute; top: 100%; left: 50%; width: 2px; height: 14px; background: #24262B; transform: translateX(-50%); }
.sel-handle.rotate::after { content: ''; position: absolute; inset: -10px; }
/* Yellow flag naming the selected item, pointing at it */
.sel-tag {
    display: none; position: absolute; top: 50%; right: calc(100% + 16px); transform: translateY(-50%);
    background: #FFC83D; color: #3D2F00; font-size: 11px; font-weight: 700; white-space: nowrap;
    padding: 3px 14px 3px 8px; line-height: 1.4; pointer-events: none; font-family: var(--font);
    clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 50%, calc(100% - 9px) 100%, 0 100%);
}
.item.selected:not(.compact) .sel-tag { display: block; }
.guide { position: absolute; background: #E0457B; pointer-events: none; z-index: 999; }
.guide-v { top: 0; bottom: 0; left: 50%; width: 1px; }
.guide-h { left: 0; right: 0; top: 50%; height: 1px; }

/* Docked toolbar */
.toolbar {
    position: relative; flex: none; z-index: 25; /* docked under the pages, never covering them */
    background: var(--bar); color: var(--on-bar);
    padding: 6px 8px calc(6px + var(--safe-b));
}
.tools { display: flex; justify-content: center; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tools::-webkit-scrollbar { display: none; }
.toolbar .context { display: none; }
body.has-selection .toolbar .tools:not(.context) { display: none; }
body.has-selection .toolbar .context { display: flex; }
.tool {
    flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-width: 72px; min-height: 56px; padding: 6px 8px;
    border: 0; border-radius: var(--radius-sm); background: transparent; font-size: 12px; font-weight: 500; color: var(--bar-muted);
}
.tool:hover { background: var(--bar-hover); color: var(--on-bar); }
.tool .icon { width: 22px; height: 22px; }
.tool-primary { color: var(--flag); font-weight: 700; }
.tool-primary:hover { color: var(--flag); }
.tool-danger { color: #F07A6F; }
.tool[aria-expanded="true"] { background: var(--bar-hover); color: var(--on-bar); }
.shapes-menu {
    position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
    display: flex; gap: 2px; padding: 6px;
    background: var(--surface); color: var(--text); border-radius: 6px; box-shadow: var(--shadow-lg);
    animation: pop-in .15s ease;
}
.shapes-menu button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 64px; min-height: 58px; padding: 6px 8px;
    border: 0; border-radius: var(--radius-sm); background: transparent; font-size: 12px; font-weight: 500; color: var(--text);
}
.shapes-menu button:hover { background: var(--surface-3); }
.shapes-menu .icon { width: 22px; height: 22px; }

.hint {
    position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b));
    z-index: 24; max-width: min(92%, 520px); text-align: center;
    padding: 8px 14px; border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: 13px;
    box-shadow: var(--shadow); pointer-events: none; animation: fade-in .3s ease;
}

/* Properties panel */
.props-panel {
    width: 320px; flex: none; display: none; flex-direction: column;
    background: var(--surface); border-inline-start: 1px solid var(--border); z-index: 22;
}
body.props-open .props-panel { display: flex; }
.props-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 8px 18px; }
.props-head h2 { font-size: 19px; }
.props-body { overflow: hidden auto; padding: 4px 18px 120px; }
.props { display: flex; flex-direction: column; gap: 20px; }
.prop { display: flex; flex-direction: column; gap: 8px; }
.prop-label { font-size: 14px; font-weight: 700; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row output { min-width: 48px; text-align: end; font-variant-numeric: tabular-nums; font-size: 14px; }
.align-grid { display: grid; grid-template-columns: repeat(3, 44px); gap: 4px; }
.align-grid .icon-btn { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
.linked-box { padding: 12px; border-radius: 6px; background: var(--flag-soft); display: flex; flex-direction: column; gap: 8px; }
.linked-head { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; }
.prop-actions { padding-top: 12px; border-top: 1px solid var(--border); }

/* ================= Modals ================= */
dialog.modal {
    width: min(520px, calc(100% - 24px)); max-height: calc(100% - 24px);
    padding: 0; border: 0; border-radius: 8px;
    background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column; overflow: hidden;
    animation: pop-in .18s ease;
}
dialog.modal:not([open]) { display: none; }
dialog.modal.modal-lg { width: min(720px, calc(100% - 24px)); }
dialog.modal::backdrop { background: rgb(23 24 27 / 55%); }
dialog.modal.closing { animation: pop-out .15s ease forwards; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 18px 16px 8px 22px; }
.modal-head h2 { font-size: 22px; }
.modal-body { padding: 8px 22px 18px; overflow-y: auto; flex: 1; }
.modal-text { font-size: 16px; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 12px 18px calc(14px + var(--safe-b)); border-top: 1px solid var(--border); }

@keyframes pop-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes pop-out { to { opacity: 0; transform: translateY(10px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Signature creator */
.creator { display: flex; flex-direction: column; gap: 14px; }
.creator-pane .pane { display: flex; flex-direction: column; gap: 12px; }
.pane-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mini-range { display: inline-flex; align-items: center; gap: 8px; min-width: 140px; }
.mini-range.grow { flex: 1; }
.draw-wrap {
    position: relative; height: 220px; border-radius: 3px;
    background: #fff; box-shadow: 0 0 0 1px var(--border); overflow: hidden; /* always paper-white */
}
.draw-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; z-index: 1; }
.draw-baseline { position: absolute; left: 8%; right: 8%; bottom: 28%; border-bottom: 1.5px solid #D8D8D2; }
.draw-baseline::before { content: '×'; position: absolute; inset-inline-start: -2px; bottom: 2px; color: #9A9DA4; font-size: 18px; line-height: 1; }
.draw-placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 8px; color: #8A8D94; pointer-events: none; font-size: 17px; }
.font-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; max-height: 300px; overflow-y: auto; padding: 3px; }
.font-option {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px;
    border: 0; box-shadow: 0 0 0 1px var(--border); border-radius: 3px; background: #fff; min-height: 86px;
}
.font-option[aria-checked="true"] { box-shadow: 0 0 0 2px #24262B; }
.font-sample { font-size: 30px; line-height: 1.3; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.font-option small { font-family: var(--font); color: #6B6E76; font-size: 11px; }
.drop-mini {
    display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 36px 16px;
    border: 1.5px dashed var(--muted); border-radius: 6px; background: var(--surface-2); color: var(--text); text-align: center;
}
.drop-mini:hover { border-color: var(--ink); }
.drop-mini small { color: var(--muted); max-width: 340px; }
.upload-editor { display: flex; flex-direction: column; gap: 12px; }
.crop-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.crop-head small { flex: 1; min-width: 160px; }
.crop-stage { position: relative; align-self: center; max-width: 100%; line-height: 0; user-select: none; overflow: hidden; border-radius: 3px; }
.crop-img { max-width: 100%; max-height: 300px; display: block; }
.crop-box { position: absolute; border: 2px solid #FFC83D; box-shadow: 0 0 0 9999px rgb(0 0 0 / 50%); cursor: move; touch-action: none; }
.crop-handle { position: absolute; width: 22px; height: 22px; background: #FFC83D; border: 2px solid #24262B; border-radius: 2px; touch-action: none; }
.crop-handle.tl { top: -11px; left: -11px; cursor: nwse-resize; }
.crop-handle.tr { top: -11px; right: -11px; cursor: nesw-resize; }
.crop-handle.bl { bottom: -11px; left: -11px; cursor: nesw-resize; }
.crop-handle.br { bottom: -11px; right: -11px; cursor: nwse-resize; }
.extract-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.preview-box { min-height: 90px; display: grid; place-items: center; border-radius: 3px; box-shadow: 0 0 0 1px var(--border); padding: 10px; }
.extract-preview { max-width: 100%; max-height: 120px; }

/* Signature grids */
.sig-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.sig-tile {
    position: relative; height: 96px; padding: 10px; display: grid; place-items: center;
    border: 0; box-shadow: 0 0 0 1px var(--border); border-radius: 3px; color: var(--text);
}
button.sig-tile:hover { box-shadow: 0 0 0 2px var(--ink); }
.sig-tile img { max-width: 100%; max-height: 72px; }
.sig-new { background: var(--surface-2); box-shadow: none; border: 1.5px dashed var(--muted); font-weight: 500; gap: 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.tag { position: absolute; bottom: 6px; inset-inline-start: 6px; font-size: 11px; background: #F0F0EC; padding: 0 6px; border-radius: 3px; color: #6B6E76; }
.tile-del { position: absolute; top: 6px; inset-inline-end: 6px; width: 30px; height: 30px; border-radius: 3px; border: 0; background: #fff; color: #C2372B; display: grid; place-items: center; box-shadow: 0 0 0 1px #DEDED8; }

.vault { display: flex; flex-direction: column; gap: 26px; }
.vault-section { display: flex; flex-direction: column; gap: 10px; }
.vault-section h3 { font-size: 18px; }
.vault-section h4 { font-size: 16px; margin-top: 8px; }
.row.wrap { flex-wrap: wrap; }

.help-steps { margin: 0; padding-inline-start: 22px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; }
.help-steps li::marker { font-family: var(--font-display); font-weight: 700; }
.help-note { display: flex; gap: 8px; align-items: flex-start; margin-top: 16px; font-size: 14px; }
.help-note .icon { flex: none; margin-top: 2px; }
.help-version { margin-top: 18px; font-size: 13px; font-variant-numeric: tabular-nums; }
.summary { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.summary .icon { color: var(--success); }
.done { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 8px 0; }
.done-icon { color: var(--success); }
.done strong { word-break: break-all; font-weight: 500; }

/* Busy + toasts */
.busy { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; background: rgb(23 24 27 / 45%); animation: fade-in .2s; }
.busy-card { display: flex; align-items: center; gap: 14px; padding: 18px 24px; border-radius: 6px; background: var(--surface); box-shadow: var(--shadow-lg); font-weight: 500; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--flag); animation: spin .8s linear infinite; }
.toasts { position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(92%, 460px); pointer-events: none; }
.toast {
    pointer-events: auto; display: flex; align-items: center; gap: 12px;
    padding: 10px 16px; border-radius: var(--radius-sm); background: #24262B; color: #fff; box-shadow: var(--shadow);
    opacity: 0; transform: translateY(-8px); transition: opacity .25s, transform .25s; font-size: 14px;
    border-inline-start: 4px solid var(--flag);
}
.toast.show { opacity: 1; transform: none; }
.toast-success { border-inline-start-color: #5BC98A; }
.toast-error { border-inline-start-color: #F07A6F; }
.toast-warn { border-inline-start-color: var(--flag); }
.toast-action { border: 0; background: var(--flag); color: var(--flag-ink); border-radius: 3px; padding: 4px 10px; font-weight: 700; }

/* ================= Responsive ================= */
@media (max-width: 999px) {
    /* Properties become a bottom sheet on tablets and phones */
    .props-panel {
        position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 62vh;
        border-radius: 10px 10px 0 0; border: 0; box-shadow: var(--shadow-lg);
        z-index: 30; animation: sheet-up .2s ease;
    }
    .props-body { padding-bottom: calc(24px + var(--safe-b)); }
    /* Extra room so items near the bottom of the last page can scroll above the sheet */
    body.props-open .pages-col { padding-bottom: 65vh; }
    body.props-open .toolbar, body.props-open .hint { display: none; }
    body.thumbs-open .thumbs { position: absolute; inset-block: 0; inset-inline-start: 0; z-index: 21; box-shadow: var(--shadow-lg); }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }

@media (max-width: 760px) {
    .hero { grid-template-columns: 1fr; }
    .drop-zone { grid-column: 1; grid-row: auto; min-height: 210px; margin-inline-end: 14px; }
    .privacy { grid-column: 1; }
}

@media (max-width: 640px) {
    .how { grid-template-columns: 1fr; }
    .hide-xs { display: none !important; }
    .tool { min-width: 62px; min-height: 54px; font-size: 11px; }
    .tools { justify-content: space-between; }
    .pages-col { padding: 12px 8px 64px; gap: 14px; }
    .hint { bottom: calc(80px + var(--safe-b)); font-size: 12px; }
    dialog.modal, dialog.modal.modal-lg {
        width: 100%; max-width: 100%; max-height: 92%; margin: auto 0 0; border-radius: 10px 10px 0 0;
        animation: sheet-up .2s ease;
    }
    .modal-foot .btn { flex: 1; }
    .draw-wrap { height: 200px; }
    .sig-grid { grid-template-columns: repeat(2, 1fr); }
    .font-list { grid-template-columns: 1fr 1fr; }
    .font-sample { font-size: 24px; }
}

@media (hover: none) { .hide-touch { display: none; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
