:root {
    --bg: #eef0f3;
    --panel: #ffffff;
    --panel-2: #f6f7f9;
    --border: #dfe2e7;
    --text: #1d2330;
    --muted: #6b7280;
    --accent: #3f5bd9;
    --accent-text: #ffffff;
    --danger: #c0392b;
    --focus: #3f5bd9;
    --radius: 8px;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
    font-size: 13px;
    color: var(--text);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #17191e;
        --panel: #22252c;
        --panel-2: #2a2e36;
        --border: #363b45;
        --text: #e8eaee;
        --muted: #9aa1ad;
        --accent: #7d93f2;
    }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
    display: grid;
    grid-template-columns: 240px 1fr 280px;
    grid-template-rows: 52px 1fr 56px;
    grid-template-areas:
        "top top top"
        "left work right"
        "left pages right";
    background: var(--bg);
    overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 10px;
    cursor: pointer;
    line-height: 1.3;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
a.button-link {
    display: inline-block;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 10px;
    line-height: 1.3;
    color: inherit;
    text-decoration: none;
}
a.button-link:hover { border-color: var(--muted); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

input, select, textarea {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 6px;
    min-width: 0;
}
input.invalid { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--panel)); }

/* Top bar */
.topbar {
    grid-area: top;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
.topbar-group { display: flex; gap: 4px; }
.topbar-spacer { flex: 1; }
.design-name { font-weight: 600; font-size: 14px; border-color: transparent; width: 220px; }
.design-name:hover, .design-name:focus { border-color: var(--border); }
.status { color: var(--muted); font-size: 12px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.error { color: var(--danger); }
#zoom-label { min-width: 58px; }

/* Side panels */
.sidebar { background: var(--panel); overflow-y: auto; padding: 12px; }
.sidebar.left { grid-area: left; border-right: 1px solid var(--border); }
.sidebar.right { grid-area: right; border-left: 1px solid var(--border); }
.sidebar section { margin-bottom: 18px; }
.sidebar h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 8px; }
.add-btn { display: block; width: 100%; text-align: left; margin-bottom: 6px; padding: 8px 10px; }
.add-heading { font-size: 18px; font-weight: 700; }
.add-subheading { font-size: 15px; font-weight: 600; }
.shape-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.shape-grid button { aspect-ratio: 1; padding: 0; display: grid; place-items: center; }
.ico { display: block; width: 22px; height: 22px; background: var(--muted); }
.ico-rect { width: 24px; height: 18px; }
.ico-rounded { width: 24px; height: 18px; border-radius: 5px; }
.ico-ellipse { border-radius: 50%; }
.ico-triangle { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.ico-line { height: 3px; width: 24px; }

.font-list { list-style: none; padding: 0; margin: 0 0 10px; max-height: 180px; overflow-y: auto; }
.font-list li { display: flex; align-items: center; gap: 6px; padding: 4px 0; font-size: 14px; }
.font-list li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.font-list li small { color: var(--muted); font-family: system-ui, sans-serif; font-size: 11px; }
.font-list button { padding: 0 6px; }
.font-upload { display: grid; gap: 6px; padding: 8px; background: var(--panel-2); border-radius: var(--radius); }
.font-upload label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }

/* Properties panel */
.prop-section { border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 12px; }
.prop-section:last-child { border-bottom: none; }
.prop-row { display: flex; align-items: center; gap: 6px; margin-bottom: 7px; }
.prop-row > label { flex: 0 0 82px; color: var(--muted); font-size: 12px; }
.prop-row > .grow { flex: 1; min-width: 0; }
.prop-row > .grow > input:not([type="color"]):not([type="range"]), .prop-row > .grow > select { width: 100%; }
.prop-section > textarea { width: 100%; resize: vertical; }
.prop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; margin-bottom: 7px; }
.num-field { display: flex; align-items: center; gap: 4px; }
.num-field span { color: var(--muted); font-size: 11px; width: 14px; text-align: center; }
.num-field input { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 4px; }
.btn-row button { flex: 1 1 auto; padding: 4px 6px; min-width: 32px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; }
input[type="range"] { flex: 1; padding: 0; }

.color-field { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; }
.color-field input[type="color"] { width: 30px; height: 28px; padding: 1px; flex: none; cursor: pointer; }
.color-field input[type="text"] { width: 84px; font-family: ui-monospace, Menlo, monospace; text-transform: lowercase; }
.color-field .none-btn { padding: 2px 6px; font-size: 11px; }
.color-field .eyedrop-btn { width: 28px; height: 28px; padding: 0; flex: none; display: grid; place-items: center; }
.color-field .eyedrop-btn.active { background: var(--accent); color: #ffffff; }
/* Eyedropper fallback (browsers without a built-in one): crosshair + color preview */
body.eyedropper-active, body.eyedropper-active * { cursor: crosshair !important; }
.eyedropper-swatch {
    position: fixed;
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 4px 4px;
    border-radius: 6px;
    background: #ffffff;
    color: #111827;
    font: 600 12px/1 ui-monospace, Menlo, monospace;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    pointer-events: none;
}
.eyedropper-swatch::before {
    content: '';
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    background: var(--picked);
}
.eyedropper-swatch[hidden] { display: none; }
.color-field.is-none input[type="color"] { opacity: 0.3; }
.swatches { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 8px 88px; }
.swatches button { width: 20px; height: 20px; padding: 0; border-radius: 50%; border: 1px solid var(--border); }

/* Workspace & page */
.workspace {
    grid-area: work;
    overflow: auto;
    position: relative;
}
.page-stage {
    min-width: 100%;
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: 40px;
    width: max-content;
}
.page {
    position: relative;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18), 0 8px 24px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    /* Fonts must never be faked: mPDF can't synthesize bold/italic either. */
    font-synthesis: none;
}

.el {
    position: absolute;
    transform-origin: 50% 50%;
    user-select: none;
    font-synthesis: none;
    -webkit-font-smoothing: antialiased;
}
.el.locked { pointer-events: none; }
.el svg { display: block; overflow: visible; width: 100%; height: 100%; }
.el img { display: block; width: 100%; height: 100%; pointer-events: none; }
.el .text-line { white-space: pre; overflow: visible; }
.el .text-editor { white-space: pre-wrap; overflow-wrap: break-word; outline: none; min-height: 1em; user-select: text; cursor: text; }
.el table { border-collapse: collapse; table-layout: fixed; }
.el td { vertical-align: top; line-height: 1.2; overflow-wrap: break-word; white-space: pre-wrap; }
.el td[contenteditable="true"] { outline: none; user-select: text; cursor: text; }
.el td[contenteditable="true"]:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.el.editing { cursor: text; }

.page-outline { position: absolute; inset: 0; pointer-events: none; outline: 1px dashed rgba(0, 0, 0, 0.08); }

/* Moveable theme */
.moveable-control-box { --moveable-color: var(--accent) !important; }
.moveable-control-box .moveable-line { background: var(--accent) !important; }
.moveable-control-box .moveable-control { border-color: #fff !important; background: var(--accent) !important; }
/* Only the round rotate knob and the handles catch the mouse; the outline and the
   line to the rotate knob let clicks through to elements underneath. */
.moveable-control-box .moveable-line,
.moveable-control-box .moveable-rotation { pointer-events: none !important; }
.moveable-control-box .moveable-rotation .moveable-control { pointer-events: auto !important; }
.selecto-selection { background: color-mix(in srgb, var(--accent) 15%, transparent) !important; border-color: var(--accent) !important; }

/* Page bar */
.pagebar {
    grid-area: pages;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    overflow-x: auto;
}
.pagebar .page-tab { min-width: 36px; }
.pagebar .sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

/* Dialogs */
dialog {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
    padding: 20px;
    width: min(560px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
dialog .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
dialog label { display: grid; gap: 4px; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.template-grid button { display: grid; gap: 6px; padding: 8px; text-align: left; }
.template-grid img, .template-grid .thumb { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--panel-2); border-radius: 6px; }
.template-grid small { color: var(--muted); }

@media (min-width: 761px) and (max-width: 900px) {
    body { grid-template-columns: 1fr; grid-template-rows: 52px auto 1fr auto 56px; grid-template-areas: "top" "left" "work" "right" "pages"; overflow: auto; }
    .sidebar { max-height: 38vh; }
    .topbar { overflow-x: auto; }
}

/* Phones: the page fills the screen; Add and Edit slide in from the sides. */
.mobile-bar { display: none; }
/* Phone-only controls (shown in the phone layout below). */
.nav-back, .more-button { display: none; }

/* ------------------------------------------------------------ phones: iOS layout */
@media (max-width: 760px) {
    :root {
        --bg: #e9e9ee;
        --panel: #ffffff;
        --panel-2: #f2f2f7;
        --border: #e3e3e8;
        --text: #111114;
        --muted: #6c6c72;
        font-size: 15px;
    }
    @media (prefers-color-scheme: dark) {
        :root:not([data-theme="light"]) { --bg: #000000; --panel: #1c1c1e; --panel-2: #2c2c2e; --border: #38383a; --text: #f5f5f7; --muted: #a1a1a6; }
    }
    body {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: calc(52px + env(safe-area-inset-top)) minmax(0, 1fr) 40px calc(66px + env(safe-area-inset-bottom));
        grid-template-areas: "top" "work" "pages" "dock";
    }
    /* Top bar: back, name, undo, more, Download */
    .topbar {
        gap: 4px; padding: env(safe-area-inset-top) 10px 0; overflow: visible;
        background: color-mix(in srgb, var(--panel) 92%, transparent); border-bottom: 1px solid var(--border);
        -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    }
    .topbar { min-width: 0; }
    .topbar > * { flex: none; }
    .topbar .topbar-group { display: contents; }
    .topbar .topbar-group > *, .topbar .topbar-spacer, .topbar .button-link { display: none; }
    .topbar [data-action="undo"], .topbar [data-action="more"], .topbar [data-action="download"] { display: flex; }
    .nav-back:not([hidden]) { display: flex; align-items: center; justify-content: center; width: 36px; height: 40px; color: var(--accent); }
    .nav-back svg { width: 11px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
    .design-name {
        flex: 1 1 auto; min-width: 0; width: auto; text-align: center; border: 0; background: transparent;
        font-size: 17px; font-weight: 600; padding: 6px 4px; border-radius: 8px;
    }
    .design-name:focus { background: var(--panel-2); outline: none; }
    .topbar button { border: 0; background: transparent; min-width: 38px; height: 38px; padding: 0 6px; align-items: center; justify-content: center; font-size: 20px; border-radius: 10px; }
    .more-button svg { width: 22px; height: 22px; fill: var(--text); }
    .topbar [data-action="download"] {
        background: var(--accent); color: #ffffff; border-radius: 999px; padding: 0 14px; height: 34px; font-size: 15px; font-weight: 600; margin-left: 2px;
    }
    .topbar .status:empty { display: none; }
    .topbar [data-action="download"] { flex: none; white-space: nowrap; }
    .status:not(:empty) {
        position: fixed; left: 12px; right: 12px; bottom: calc(120px + env(safe-area-inset-bottom)); z-index: 3400;
        max-width: none; white-space: normal; padding: 10px 14px; border-radius: 14px; text-align: center;
        background: #1c1c1e; color: #ffffff; border: 0; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); pointer-events: none;
    }
    /* Panels: bottom sheets */
    .sidebar.left, .sidebar.right {
        position: fixed; left: 0; right: 0; top: auto; bottom: calc(66px + env(safe-area-inset-bottom)); width: auto; max-height: none;
        height: min(58vh, 520px); z-index: 3200; border: 0; border-radius: 20px 20px 0 0; padding: 26px 16px 16px;
        transform: translateY(calc(100% + 80px + env(safe-area-inset-bottom))); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
        box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
    }
    .sidebar.left::before, .sidebar.right::before {
        content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px; background: #c7c7cc;
    }
    body.show-left-panel .sidebar.left, body.show-properties .sidebar.right { transform: none; }
    .sidebar .add-btn { min-height: 44px; border-radius: 12px; }
    /* Bottom tool bar */
    .mobile-bar {
        grid-area: dock; position: static; transform: none; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: start; padding: 6px 8px env(safe-area-inset-bottom); z-index: 3300;
        background: color-mix(in srgb, var(--panel) 94%, transparent); border-top: 1px solid var(--border);
        -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    }
    .mobile-bar button {
        border: 0; background: transparent; box-shadow: none; padding: 4px 0; border-radius: 10px;
        display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 500; color: var(--text);
    }
    .mobile-bar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
    body.show-left-panel .mobile-bar [data-drawer="left-panel"],
    body.show-properties .mobile-bar [data-drawer="properties"] { background: transparent; color: var(--accent); }
    .workspace { touch-action: pan-x pan-y; }
    .page-stage { padding: 20px 16px 28px; }
    /* Pages: a slim row */
    .pagebar {
        min-width: 0; padding: 0 8px; gap: 6px; overflow-x: auto; scrollbar-width: none; background: transparent; border: 0;
    }
    .pagebar::-webkit-scrollbar { display: none; }
    .pagebar button { flex: none; border: 0; background: var(--panel); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
    .pagebar .page-tab.active { background: var(--accent); color: #ffffff; }
    .pagebar .sep { display: none; }
    /* Bigger handles for fingers. */
    .moveable-control-box .moveable-control { width: 18px !important; height: 18px !important; margin-top: -9px !important; margin-left: -9px !important; }
    /* Dialogs: bottom sheets */
    dialog {
        width: 100%; max-width: 100%; min-width: 0; margin: auto 0 0; border: 0; border-radius: 20px 20px 0 0;
        padding: 22px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto;
    }
    dialog .dialog-actions { flex-direction: column-reverse; gap: 10px; }
    dialog .dialog-actions button { min-height: 50px; border-radius: 14px; font-size: 17px; }
    dialog label { font-size: 13px; }
    dialog input, dialog select { min-height: 44px; border-radius: 10px; font-size: 16px; }
    .download-dialog .segmented button { min-height: 36px; font-size: 15px; }
}

/* The More menu: an iOS action sheet */
dialog.as-sheet { background: transparent; border: 0; padding: 0 8px calc(8px + env(safe-area-inset-bottom)); box-shadow: none; max-height: none; overflow: visible; }
.action-sheet { display: flex; flex-direction: column; gap: 8px; }
.action-sheet .sheet-group { display: flex; flex-direction: column; background: var(--panel); border-radius: 14px; overflow-y: auto; max-height: calc(100vh - 150px - env(safe-area-inset-bottom)); }
.action-sheet .sheet-group button { flex: none; border: 0; border-radius: 0; background: transparent; min-height: 50px; font-size: 18px; color: var(--accent); }
.action-sheet .sheet-group button + button { border-top: 1px solid var(--border); }
.action-sheet .sheet-cancel { border: 0; border-radius: 14px; background: var(--panel); min-height: 56px; font-size: 18px; font-weight: 600; color: var(--accent); }

/* Move button above the selection (press and hold to drag) */
.move-handle {
    position: absolute;
    z-index: 3000;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 1px solid var(--border, #d0d5dd);
    border-radius: 50%;
    background: #ffffff;
    color: var(--accent);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    cursor: move;
    touch-action: none;
}
.move-handle:hover { background: var(--accent); color: #ffffff; }
.move-handle[hidden] { display: none; }

/* Resize handles like Canva: small dots on the corners, short bars on the middle of each side */
.moveable-control-box .moveable-control.moveable-direction {
    width: 12px !important;
    height: 12px !important;
    margin-top: -6px !important;
    margin-left: -6px !important;
    border: 2px solid #ffffff !important;
    background: var(--accent) !important;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.moveable-control-box .moveable-control.moveable-n,
.moveable-control-box .moveable-control.moveable-s {
    width: 20px !important;
    height: 7px !important;
    margin-top: -3.5px !important;
    margin-left: -10px !important;
    border-radius: 4px !important;
    z-index: 2;
}
.moveable-control-box .moveable-control.moveable-e,
.moveable-control-box .moveable-control.moveable-w {
    width: 7px !important;
    height: 20px !important;
    margin-top: -10px !important;
    margin-left: -3.5px !important;
    border-radius: 4px !important;
    z-index: 2;
}
/* A slightly bigger grab area than the visible bar/dot, but not further into the box. */
.moveable-control-box .moveable-control.moveable-direction::after {
    content: '';
    position: absolute;
    inset: -5px;
}
.moveable-control-box .moveable-control.moveable-n::after,
.moveable-control-box .moveable-control.moveable-s::after { inset: -2px -6px; }
.moveable-control-box .moveable-control.moveable-e::after,
.moveable-control-box .moveable-control.moveable-w::after { inset: -6px -2px; }

/* Live size while resizing */
.size-badge {
    position: absolute;
    z-index: 3001;
    padding: 3px 7px;
    border-radius: 6px;
    background: rgba(17, 24, 39, 0.9);
    color: #ffffff;
    font: 600 12px/1.2 system-ui, sans-serif;
    white-space: nowrap;
    pointer-events: none;
}
.size-badge[hidden] { display: none; }

/* Ratio lock toggle */
.ratio-lock { display: inline-flex; align-items: center; gap: 6px; }
.ratio-lock .lock-closed, .ratio-lock.active .lock-open { display: none; }
.ratio-lock.active .lock-closed { display: inline; }
.ratio-lock .lock-text::after { content: 'Unlocked'; }
.ratio-lock.active .lock-text::after { content: 'Locked'; }

/* Save button and My designs */
#save-button.unsaved { font-weight: 600; }
.design-list { display: flex; flex-direction: column; gap: 6px; min-width: min(560px, 80vw); max-height: 60vh; overflow: auto; }
.design-row { display: flex; align-items: stretch; gap: 6px; }
.design-row.current .design-open { border-color: var(--accent); }
.design-open { flex: 1; display: flex; align-items: center; gap: 12px; text-align: left; padding: 8px; min-width: 0; }
.design-thumb-box { width: 52px; height: 52px; display: grid; place-items: center; flex: none; }
.design-thumb { border: 1px solid var(--border); border-radius: 2px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.design-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.design-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.design-info small { color: var(--muted, #6b7280); }
.design-delete { flex: none; }

/* Canva font matching */
.font-match { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0; }
.font-match > span { display: flex; flex-direction: column; min-width: 0; }
.font-match small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.font-match select { max-width: 220px; }

/* Upload form: italic checkbox on one line */
.font-upload label.check { display: flex; align-items: center; gap: 6px; flex-direction: row; }
.font-upload label.check input { width: auto; margin: 0; }

/* "Squeeze letters" on: dotted selection outline */
.moveable-control-box.squeeze-mode .moveable-line:not(.moveable-rotation-line) {
    background: repeating-linear-gradient(to right, var(--accent) 0 3px, transparent 3px 6px) !important;
}
.squeeze-toggle.active { background: var(--accent); color: #ffffff; }

/* Selected table cells (while editing a table) */
.el td.cell-selected { box-shadow: inset 0 0 0 9999px color-mix(in srgb, var(--accent) 18%, transparent); }
.el td.cell-selected:focus { box-shadow: inset 0 0 0 9999px color-mix(in srgb, var(--accent) 18%, transparent), inset 0 0 0 2px var(--accent); }
.border-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.border-grid button { padding: 4px 0; font-size: 15px; line-height: 1; }
.prop-section h4.sub { margin: 12px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* Formula function list (Cells panel) */
.formula-help summary { cursor: pointer; font-size: 12px; color: var(--accent); margin: 2px 0 6px; }
.formula-help p { margin: 4px 0; }

/* Table column / row resize strips (drag, double-click to fit) */
.el .tbl-resizers { position: absolute; inset: 0; pointer-events: none; }
.el .tbl-resize { position: absolute; pointer-events: none; z-index: 2; }
.el.table-active .tbl-resize { pointer-events: auto; }
.el.table-active .tbl-resize.col { cursor: col-resize; }
.el.table-active .tbl-resize.row { cursor: row-resize; }
.el.table-active .tbl-resize::after { content: ''; position: absolute; background: var(--accent); opacity: 0; transition: opacity .1s; }
.el.table-active .tbl-resize.col::after { left: 2px; top: 0; bottom: 0; width: 2px; }
.el.table-active .tbl-resize.row::after { top: 2px; left: 0; right: 0; height: 2px; }
.el.table-active .tbl-resize:hover::after, .el .tbl-resize.dragging::after { opacity: .8; }

/* Open PDF: the two ways */
.pdf-import .import-choices { display: grid; gap: 10px; margin: 12px 0; }
.pdf-import .import-choice { display: grid; gap: 4px; text-align: left; padding: 12px 14px; border: 1px solid var(--border, #d5d9e0); border-radius: 8px; background: var(--panel, #fff); cursor: pointer; }
.pdf-import .import-choice:hover { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.pdf-import .import-choice strong { font-size: 15px; }
.pdf-import .import-choice span { font-size: 13px; opacity: .8; line-height: 1.35; }
.pdf-import .check { display: flex; gap: 6px; align-items: flex-start; font-size: 13px; margin: 4px 0 8px; }

/* Eraser */
.add-btn.eraser-btn.active { background: var(--accent); color: #fff; }
#page .erase-preview { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; overflow: visible; }
.erasing #page .el { pointer-events: none; }

/* Selected area: marching ants */
#page > .area-outline { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; overflow: visible; }
#page > .area-outline polygon { fill: color-mix(in srgb, var(--accent) 8%, transparent); stroke-width: 1.5; }
#page > .area-outline .ants-a { stroke: #fff; }
#page > .area-outline .ants-b { stroke: #1d2330; stroke-dasharray: 5 5; animation: ants .6s linear infinite; fill: none; }
@keyframes ants { to { stroke-dashoffset: -10; } }
.add-btn.area-btn.active { background: var(--accent); color: #fff; }

/* Invisible text: only in the file's text (not in the PDF's look); shown faintly here. */
.el.invisible { opacity: .4 !important; outline: 1px dashed #c00000; outline-offset: 1px; }

/* Text in the file */
.file-text .file-text-list { display: grid; gap: 8px; max-height: 55vh; overflow: auto; margin: 10px 0; }
.file-text .file-text-row { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: start; }
.file-text .file-text-row small { display: block; opacity: .75; margin-bottom: 3px; }
.file-text .file-text-row textarea { width: 100%; box-sizing: border-box; font: inherit; }
.file-text .file-text-row.is-hidden small { color: #c00000; opacity: 1; }
.file-text .file-text-row[hidden] { display: none; }

/* Download dialog: PDF or Image, then the image options */
.download-dialog { min-width: 300px; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--panel-2, #eef0f3); border-radius: 9px; padding: 2px; margin-bottom: 14px; }
.segmented button { border: 0; background: transparent; border-radius: 7px; padding: 7px 0; font-weight: 500; }
.segmented button.active { background: var(--panel, #fff); color: inherit; font-weight: 600; box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.download-image { display: grid; }
dialog label.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: inherit; }
