/* Obsidian look (site/shim/obsidian.css) */
/*
 * Obsidian look for the browser demo: the CSS variables the plugin's styles use (light + dark, following the
 * system setting) and base styles for the elements Obsidian normally styles (buttons, inputs, menus, dialogs,
 * notices, settings). Element styles are scoped to the demo and to the plugin's own elements, so the landing
 * page around the demo is not affected.
 */
:root {
    --accent-h: 124;
    --interactive-accent: #4f7552;
    --interactive-accent-hover: #3e5d41;
    --text-on-accent: #ffffff;
    --text-accent: #44664a;
    --text-accent-hover: #3e5d41;
    --background-primary: #ffffff;
    --background-primary-alt: #fafafa;
    --background-secondary: #f1f3f7;
    --background-secondary-alt: #e6e9f0;
    --background-modifier-border: #dde1ea;
    --background-modifier-border-hover: #c8cedb;
    --background-modifier-hover: rgba(15, 30, 70, 0.07);
    --background-modifier-active-hover: rgba(79, 117, 82, 0.14);
    --background-modifier-form-field: #ffffff;
    --background-modifier-error: #e93147;
    --background-modifier-success: #08b94e;
    --interactive-normal: #ffffff;
    --interactive-hover: #f1f3f7;
    --text-normal: #1f2328;
    --text-muted: #5b6270;
    --text-faint: #9aa0ab;
    --text-error: #d62839;
    --text-success: #08a045;
    --font-interface: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-text: var(--font-interface);
    --font-monospace: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
    --font-ui-smaller: 12px;
    --font-ui-small: 13px;
    --font-ui-medium: 15px;
    --icon-size: 16px;
    --radius-s: 4px;
    --radius-m: 8px;
    --radius-l: 12px;
    --input-height: 32px;
    --shadow-s: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-l: 0 8px 30px rgba(10, 15, 30, 0.18), 0 2px 6px rgba(10, 15, 30, 0.08);
    --notice-bg: #1a1a1a;
    --notice-text: #ffffff;
    --modal-backdrop: rgba(10, 12, 20, 0.45);
}

/* Dark mode: set by site/theme.js (follows the system unless the toggle was used). */
:root[data-theme="dark"] {
    --interactive-accent: #4f7552;
    --interactive-accent-hover: #618c65;
    --text-on-accent: #ffffff;
    --text-accent: #9cc7a0;
    --text-accent-hover: #b5d6b8;
    --background-primary: #1a1a1a;
    --background-primary-alt: #1e1e1e;
    --background-secondary: #111111;
    --background-secondary-alt: #262626;
    --background-modifier-border: rgba(255, 255, 255, 0.15);
    --background-modifier-border-hover: rgba(255, 255, 255, 0.25);
    --background-modifier-hover: rgba(255, 255, 255, 0.08);
    --background-modifier-active-hover: rgba(111, 158, 116, 0.28);
    --background-modifier-form-field: #222222;
    --interactive-normal: #262626;
    --interactive-hover: #303030;
    --text-normal: #ffffff;
    --text-muted: #cccccc;
    --text-faint: #777777;
    --text-error: #ff6b7a;
    --shadow-l: 0 8px 30px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
    --notice-bg: #262626;
    --modal-backdrop: rgba(0, 0, 0, 0.6);
}

/* ---- scope: the demo and everything the plugin / shim appends to <body> ---- */
:where(.demo-app, .menu, .modal-container, .notice-container, [class^="hw-"], [class*=" hw-"]) {
    font-family: var(--font-interface);
    color: var(--text-normal);
}
:where(.demo-app, .menu, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(*, *::before, *::after) { box-sizing: border-box; }

:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(button) {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: var(--input-height); padding: 4px 12px;
    font: inherit; font-size: var(--font-ui-small); font-weight: 500; line-height: 1.2;
    color: var(--text-normal); background: var(--interactive-normal);
    border: 1px solid var(--background-modifier-border); border-radius: var(--radius-s);
    box-shadow: var(--shadow-s); cursor: pointer; user-select: none; -webkit-user-select: none;
    touch-action: manipulation;
}
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(button:hover) { background: var(--interactive-hover); }
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(button:disabled) { opacity: 0.5; cursor: default; }
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible) {
    outline: 2px solid var(--interactive-accent); outline-offset: 1px;
}
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(button.mod-cta) {
    background: var(--interactive-accent); color: var(--text-on-accent); border-color: transparent;
}
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(button.mod-cta:hover) { background: var(--interactive-accent-hover); }
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(button.mod-warning) {
    background: var(--background-modifier-error); color: #fff; border-color: transparent;
}
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(input[type="text"], input[type="number"], input[type="search"], input:not([type]), textarea, select) {
    font: inherit; font-size: 14px; color: var(--text-normal);
    background: var(--background-modifier-form-field);
    border: 1px solid var(--background-modifier-border); border-radius: var(--radius-s);
    padding: 4px 8px; min-height: var(--input-height); max-width: 100%;
}
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(input[type="text"], input[type="number"], input[type="search"], input:not([type]), textarea, select):focus {
    border-color: var(--interactive-accent); outline: none; box-shadow: 0 0 0 2px var(--background-modifier-active-hover);
}
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(select) { padding-right: 24px; cursor: pointer; }
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(input[type="range"]) { accent-color: var(--interactive-accent); width: 140px; }
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(input[type="color"]) {
    width: 32px; height: 28px; padding: 0 2px; border: 1px solid var(--background-modifier-border); border-radius: var(--radius-s);
    background: var(--background-modifier-form-field); cursor: pointer;
}
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(input[type="checkbox"]) { accent-color: var(--interactive-accent); }
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(a) { color: var(--text-accent); }
:where(.demo-app, .modal-container, [class^="hw-"], [class*=" hw-"]) :where(kbd, code) { font-family: var(--font-monospace); font-size: 0.9em; }

.svg-icon { width: var(--icon-size); height: var(--icon-size); flex-shrink: 0; display: block; }

.clickable-icon {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 4px; border-radius: var(--radius-s); color: var(--text-muted);
    background: transparent; border: 0; box-shadow: none; cursor: pointer; min-height: 0;
}
.clickable-icon:hover { background: var(--background-modifier-hover); color: var(--text-normal); }
.clickable-icon.is-disabled { opacity: 0.4; cursor: default; }

/* ---- toggle (Setting.addToggle) ---- */
.checkbox-container {
    position: relative; display: inline-block; flex: 0 0 auto; width: 40px; height: 22px; border-radius: 22px;
    background: var(--background-modifier-border-hover); cursor: pointer; transition: background 0.15s ease;
}
.checkbox-container input { display: none; }
.checkbox-container::after {
    content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.15s ease;
}
.checkbox-container.is-enabled { background: var(--interactive-accent); }
.checkbox-container.is-enabled::after { transform: translateX(18px); }
.checkbox-container.is-disabled { opacity: 0.5; cursor: default; }

/* ---- Menu ---- */
.menu {
    position: fixed; left: 0; top: 0; z-index: 2000; min-width: 180px; max-width: min(340px, calc(100vw - 12px));
    overflow-y: auto; padding: 5px;
    background: var(--background-primary); border: 1px solid var(--background-modifier-border-hover);
    border-radius: var(--radius-m); box-shadow: var(--shadow-l); font-size: 14px;
    user-select: none; -webkit-user-select: none; touch-action: pan-y;
}
.menu-item {
    display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: var(--radius-s);
    cursor: pointer; color: var(--text-normal); outline: none; white-space: nowrap;
}
.menu-item.selected:not(.is-disabled), .menu-item:focus-visible { background: var(--background-modifier-hover); }
.menu-item.is-disabled { opacity: 0.45; cursor: default; }
.menu-item.is-warning { color: var(--text-error); }
.menu-item-icon { display: flex; align-items: center; color: var(--text-muted); width: 16px; flex: 0 0 16px; }
.menu-item-icon:empty { visibility: hidden; }
.menu-item-icon.mod-checked { margin-left: auto; color: var(--interactive-accent); }
.menu-item-title { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
.menu-separator { height: 1px; margin: 4px -5px; background: var(--background-modifier-border); }
.menu.mod-no-icon .menu-item-icon:not(.mod-checked) { display: none; }
@media (pointer: coarse) {
    .menu-item { padding: 10px 12px; font-size: 15px; }
}

/* ---- Modal ---- */
.modal-container {
    position: fixed; inset: 0; z-index: 1500; display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.modal-bg { position: absolute; inset: 0; background: var(--modal-backdrop); }
.modal {
    position: relative; display: flex; flex-direction: column;
    width: min(560px, 100%); max-width: 100%; max-height: min(88vh, 100%); overflow: auto;
    padding: 18px 20px 20px; background: var(--background-primary); color: var(--text-normal);
    border: 1px solid var(--background-modifier-border); border-radius: var(--radius-l); box-shadow: var(--shadow-l);
    outline: none; overscroll-behavior: contain;
}
.modal-close-button {
    position: absolute; top: 10px; right: 10px; z-index: 5; display: flex; padding: 6px; border-radius: var(--radius-s);
    color: var(--text-muted); cursor: pointer;
}
.modal-close-button:hover { background: var(--background-modifier-hover); color: var(--text-normal); }
.modal-title { font-size: 18px; font-weight: 600; margin: 0 32px 12px 0; line-height: 1.3; }
.modal-title:empty { display: none; }
.modal-content { flex: 1 1 auto; min-height: 0; }
.modal.hw-demo-settings { width: min(780px, 100%); }
@media (max-width: 600px) {
    .modal-container { padding: 8px; align-items: flex-end; }
    .modal { width: 100%; max-height: 92vh; padding: 16px 14px 18px; }
}
@supports (max-height: 92dvh) { @media (max-width: 600px) { .modal { max-height: 92dvh; } } }

/* ---- Suggest (Go to page…) ---- */
.modal.prompt { align-self: flex-start; margin-top: 10vh; width: min(600px, 100%); padding: 0; overflow: hidden; }
.prompt-input-container { padding: 10px; border-bottom: 1px solid var(--background-modifier-border); }
.prompt-input-container .prompt-input { width: 100%; min-height: 40px; font-size: 16px; }
.prompt-results { max-height: 50vh; overflow-y: auto; padding: 6px; }
.suggestion-item { padding: 8px 12px; border-radius: var(--radius-s); cursor: pointer; }
.suggestion-item.is-selected { background: var(--background-modifier-hover); }
.suggestion-highlight { font-weight: 700; color: var(--text-accent); }
.suggestion-empty { padding: 10px 12px; color: var(--text-muted); }
.prompt-instructions { display: flex; gap: 12px; padding: 6px 12px; font-size: 12px; color: var(--text-muted); }
.prompt-instructions:empty { display: none; }

/* ---- Notice ---- */
.notice-container {
    position: fixed; top: 16px; right: 16px; z-index: 3000; display: flex; flex-direction: column; align-items: flex-end;
    gap: 8px; max-width: min(380px, calc(100vw - 32px)); pointer-events: none;
}
.notice {
    pointer-events: auto; padding: 10px 14px; border-radius: var(--radius-m);
    background: var(--notice-bg); color: var(--notice-text); box-shadow: var(--shadow-l);
    font-size: 14px; line-height: 1.4; cursor: pointer; animation: hw-demo-notice-in 0.18s ease-out;
    overflow-wrap: anywhere;
}
@keyframes hw-demo-notice-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@media (max-width: 600px) {
    .notice-container { top: auto; bottom: 16px; left: 16px; right: 16px; max-width: none; align-items: stretch; }
}

/* ---- Settings ---- */
.vertical-tab-content { font-size: 14px; }
.setting-item {
    display: flex; align-items: center; gap: 16px; padding: 12px 0;
    border-top: 1px solid var(--background-modifier-border);
}
.setting-item:first-child { border-top: 0; }
.setting-item-info { flex: 1 1 auto; min-width: 0; }
.setting-item-name { font-size: var(--font-ui-medium); color: var(--text-normal); }
.setting-item-description { font-size: var(--font-ui-small); color: var(--text-muted); padding-top: 3px; line-height: 1.4; }
.setting-item-description:empty { display: none; }
.setting-item-control { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; flex: 0 1 auto; }
.setting-item-heading .setting-item-name { font-weight: 600; }
.setting-item.is-disabled { opacity: 0.55; }
.hw-demo-slider-value { min-width: 2.5em; text-align: right; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
@media (max-width: 600px) {
    .setting-item { flex-wrap: wrap; gap: 8px; }
    .setting-item-control { width: 100%; justify-content: flex-start; }
}

/* Plugin styles (src/styles.css) */
.handwriting-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--background-secondary);
    user-select: none;
    -webkit-user-select: none;
}

/* --- TOOLBAR --- */
.hw-toolbar {
    padding: 10px;
    background: var(--background-primary);
    border-bottom: 1px solid var(--background-modifier-border);
    display: flex;
    gap: 15px;
    flex-shrink: 0;
    z-index: 30;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
}
.hw-toolbar::-webkit-scrollbar { display: none; }
.hw-toolbar > * { flex-shrink: 0; }
.hw-toolbar > .hw-toolbar-spacer { flex: 1 1 auto; min-width: 8px; }

@media (max-height: 520px), (max-width: 700px) {
    .hw-toolbar { padding: 4px 6px; gap: 8px; }
    .hw-tool-section { gap: 4px; }
    .hw-tool-btn { padding: 4px 6px; }
    .hw-toolbar-divider { height: 18px; }
}

.hw-tool-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hw-toolbar-divider {
    width: 2px;
    height: 25px;
    background-color: var(--background-modifier-border);
}

.hw-tool-btn {
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--text-normal);
    display: flex;
    align-items: center;
    justify-content: center;
}

.hw-tool-btn.hw-tool-btn.hw-tool-btn.active {
    background: var(--interactive-accent);
    border-color: var(--interactive-accent);
    color: var(--text-on-accent);
}

.hw-tool-btn svg {
    pointer-events: none;
}

/* --- PRESET THICKNESSES --- */
.hw-thickness-presets {
    display: flex;
    gap: 5px;
    align-items: center;
}

.hw-thickness-btn {
    width: 28px; 
    height: 28px;
    border-radius: 14px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.hw-thickness-btn.hw-thickness-btn.hw-thickness-btn.active {
    background: var(--interactive-accent);
    border-color: var(--interactive-accent);
}
.hw-thickness-btn.active .hw-dot { background: var(--text-on-accent); }

.hw-dot {
    background: var(--text-normal);
    border-radius: 50%;
}

.hw-dot-sm { width: 4px; height: 4px; }
.hw-dot-md { width: 8px; height: 8px; }
.hw-dot-lg { width: 14px; height: 14px; }

/* --- COLOR PALETTE --- */
.hw-color-palette {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px;   /* room for the selection ring (a scrolling toolbar would clip it) */
}

button.hw-swatch.hw-swatch.hw-swatch {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
    border-radius: 50%;
    border: none;
    padding: 0;
    cursor: pointer;
    background: var(--sw);
    box-shadow: inset 0 0 0 1px rgba(128,128,128,0.45);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
button.hw-swatch:hover { transform: scale(1.1); }
/* same specificity as the base rule above (otherwise its box-shadow hid the ring of the chosen colour) */
button.hw-swatch.hw-swatch.hw-swatch.active {
    box-shadow: inset 0 0 0 1px rgba(128,128,128,0.45),
                0 0 0 2px var(--background-primary),
                0 0 0 4px var(--interactive-accent);
}

button.hw-swatch-add.hw-swatch-add.hw-swatch-add {
    flex: 0 0 22px;
    -webkit-appearance: none;
    appearance: none;
    min-width: 22px;
    min-height: 22px;
    box-shadow: none;
    position: relative;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    background: conic-gradient(#e74c3c, #f1c40f, #2ecc71, #3498db, #9b59b6, #e74c3c);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    padding: 0;
}
.hw-swatch-add::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    /* plus drawn with two bars – exactly centred, independent of the font */
    background:
        linear-gradient(var(--text-normal), var(--text-normal)) center / 8px 1.6px no-repeat,
        linear-gradient(var(--text-normal), var(--text-normal)) center / 1.6px 8px no-repeat,
        var(--background-primary);
}

.hw-color-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* --- SHAPES MENU --- */
.hw-shapes-section {
    position: relative;
    display: flex;
    align-items: center;
}

.hw-menu {
    position: fixed;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 10px 12px;
    background: var(--background-primary);
    border: 1px solid var(--background-modifier-border);
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.2);
    width: max-content;
}

.hw-menu-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.hw-menu-row {
    display: flex;
    gap: 4px;
}

.hw-menu-btn {
    border-color: var(--background-modifier-border);
}

.hw-menu-btn:hover {
    background: var(--background-modifier-hover);
}

.hw-menu-btn.hw-menu-btn.hw-menu-btn.active {
    background: var(--interactive-accent);
    border-color: var(--interactive-accent);
    color: var(--text-on-accent);
}

/* --- WORKSPACE & PAGES --- */
.hw-scroll-area {
    flex: 1;
    overflow: hidden;
    position: relative;
    touch-action: none; 
}

.hw-pages-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px; /* Smaller gap between pages */
    padding: 20px 0;
    transform-origin: top left;
    width: 800px; /* Fixed width for correct centring */
    position: absolute; /* Makes smooth camera locking easier */
    top: 0;
    left: 0;
}
/* while panning / zooming: the page column is one compositor layer, so moving it does not repaint the pages */
.hw-pages-wrapper.hw-moving { will-change: transform; }

.hw-single-page-container {
    position: relative;
    display: flex;
    justify-content: center;
}

.handwriting-container:focus {
    outline: none;
}

.hw-tool-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.hw-page-a4.hw-page-a4.hw-page-a4 {
    /* page size: A4 or custom (--hw-pw / --hw-ph set for landscape and "endless" pages) */
    width: var(--hw-pw, 800px);
    height: var(--hw-ph, 1131px);
    min-height: var(--hw-ph, 1131px);
    max-height: var(--hw-ph, 1131px);
    background-color: var(--hw-paper, #ffffff);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    position: relative;
    flex-shrink: 0; 
}

.hw-layer-highlighter { z-index: 1; opacity: 0.4; }
.hw-layer-bottom { z-index: 2; }
.hw-layer-top { z-index: 3; }

.hw-page-a4 canvas {
    position: absolute;
    top: 0;
    left: 0;
    touch-action: none;
    display: block;
}
/* Inserted images (screenshots, graphics) – below strokes, above the background */
.hw-image-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}
.hw-page-image {
    position: absolute;
    display: block;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}
.hw-page-bg.hw-page-bg.hw-page-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    object-fit: contain; /* Keeps the PDF proportions */
}
/* PDF actions are always visible directly on the handwriting toolbar. */
.hw-pdf-actions {
    margin-left: auto;
    gap: 6px;
}
.hw-pdf-actions .hw-tool-btn {
    border-color: var(--background-modifier-border);
}
.hw-pdf-actions .hw-tool-btn:hover {
    background: var(--background-modifier-hover);
}

/* --- TOOLBAR: style button (colour + thickness) and panel --- */
.hw-style-btn { gap: 4px; }
.hw-style-btn .hw-style-dot {
    display: block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--sw, var(--text-faint));
    box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.45);
}
.hw-style-btn::after {
    content: "";
    border: 4px solid transparent;
    border-top-color: var(--text-muted);
    margin-top: 4px;
}
.hw-style-inline { gap: 15px; }
.hw-style-pop { gap: 14px; }
.hw-style-pop .hw-style-inline {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
}
.hw-tool-btn { min-width: 34px; min-height: 34px; }
.hw-compact.hw-toolbar { gap: 8px; }
.hw-compact .hw-tool-section { gap: 4px; }

/* --- Dropping the selection on another page --- */
.hw-page-a4.hw-drop-target {
    outline: 3px solid var(--interactive-accent);
    outline-offset: -3px;
}

/* --- Narrow screen: thickness and colours in a menu --- */
.hw-compact .hw-style-inline { gap: 8px; }

/* --- PAGE PATTERNS. Geometry and colours are computed by templateCssVars() (templates.ts) and set as the page's CSS variables:
   --hw-a-* = main pattern (::before), --hw-b-* = extras: accent lines, small squares (::after). --- */
.hw-page-a4::before,
.hw-page-a4::after {
    content: "";
    position: absolute;
    z-index: 0;
    pointer-events: none;
}
.hw-page-a4::before {
    left: var(--hw-a-l, 0); top: var(--hw-a-t, 0); width: var(--hw-a-w, 0); height: var(--hw-a-h, 0);
    background-image: var(--hw-a-img, none);
    background-size: var(--hw-a-size, auto);
    background-position: var(--hw-a-pos, 0 0);
    background-repeat: var(--hw-a-rep, repeat);
}
.hw-page-a4::after {
    left: var(--hw-b-l, 0); top: var(--hw-b-t, 0); width: var(--hw-b-w, 0); height: var(--hw-b-h, 0);
    background-image: var(--hw-b-img, none);
    background-size: var(--hw-b-size, auto);
    background-position: var(--hw-b-pos, 0 0);
    background-repeat: var(--hw-b-rep, no-repeat);
}
.hw-page-a4.hw-page-a4.hw-page-a4.hw-has-bg::before,
.hw-page-a4.hw-page-a4.hw-page-a4.hw-has-bg::after { display: none; }

/* --- PDF export dialog --- */
.hw-pdf-modal .hw-pdf-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.hw-pdf-modal .hw-pdf-row input { width: 100%; }
.hw-pdf-modal .hw-pdf-buttons { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* --- "Page continues" hints at the view edges --- */
.hw-edge {
    position: absolute;
    pointer-events: none;
    z-index: 20;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.hw-edge.hw-edge-on { opacity: 1; }
.hw-edge-top, .hw-edge-bottom { left: 0; width: 100%; height: 26px; }
.hw-edge-left, .hw-edge-right { top: 0; bottom: 0; width: 26px; }
.hw-edge-top { top: 0; background: linear-gradient(to bottom, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0)); }
.hw-edge-bottom { bottom: 0; background: linear-gradient(to top, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0)); }
.hw-edge-left { left: 0; background: linear-gradient(to right, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0)); }
.hw-edge-right { right: 0; background: linear-gradient(to left, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0)); }

/* Eraser circle (DOM element instead of a drawing on the canvas) */
.hw-eraser-cursor {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 6;
    box-sizing: border-box;
    border-style: solid;
    border-color: rgba(0, 0, 0, 0.75);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.06);
    pointer-events: none;
    will-change: transform;
}

/* --- Image cropping --- */
.hw-crop-overlay {
    position: absolute;
    z-index: 7;
    overflow: hidden;
    touch-action: none;
    cursor: default;
}
.hw-crop-box {
    position: absolute;
    box-sizing: border-box;
    border: calc(2px / var(--hw-zoom, 1)) solid var(--interactive-accent);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    cursor: move;
}
.hw-crop-handle {
    position: absolute;
    width: calc(20px / var(--hw-zoom, 1));
    height: calc(20px / var(--hw-zoom, 1));
    margin: calc(-10px / var(--hw-zoom, 1)) 0 0 calc(-10px / var(--hw-zoom, 1));
    border-radius: calc(4px / var(--hw-zoom, 1));
    background: var(--interactive-accent);
    border: calc(2px / var(--hw-zoom, 1)) solid #fff;
    box-sizing: border-box;
}
.hw-crop-h-nw { left: 0; top: 0; cursor: nwse-resize; }
.hw-crop-h-n { left: 50%; top: 0; cursor: ns-resize; }
.hw-crop-h-ne { left: 100%; top: 0; cursor: nesw-resize; }
.hw-crop-h-e { left: 100%; top: 50%; cursor: ew-resize; }
.hw-crop-h-se { left: 100%; top: 100%; cursor: nwse-resize; }
.hw-crop-h-s { left: 50%; top: 100%; cursor: ns-resize; }
.hw-crop-h-sw { left: 0; top: 100%; cursor: nesw-resize; }
.hw-crop-h-w { left: 0; top: 50%; cursor: ew-resize; }
.hw-crop-bar {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 10px;
    background: var(--background-primary);
    border: 1px solid var(--background-modifier-border);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.hw-crop-title { font-weight: 600; margin-right: 4px; }

/* --- Calculator --- */
.hw-calc-modal { width: max-content; max-width: 96vw; }
.hw-calc-row { display: flex; align-items: stretch; gap: 10px; }
.hw-calc-main { width: 320px; flex: 0 0 auto; }
.hw-calc-histpane { position: relative; width: 230px; flex: 0 0 auto; border-right: 1px solid var(--background-modifier-border); padding-right: 10px; }
.hw-calc-histinner { position: absolute; inset: 0 10px 0 0; display: flex; flex-direction: column; min-height: 0; }
.hw-calc-histhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; flex: 0 0 auto; }
.hw-calc-histtitle { font-weight: 600; font-size: 0.9em; color: var(--text-muted); }
.hw-calc-histclear { display: inline-flex; align-items: center; gap: 4px; font-size: 0.8em; padding: 3px 8px; }
.hw-calc-histclear svg, .hw-calc-histicon svg { width: 14px; height: 14px; }
.hw-calc-histbtn { display: inline-flex; align-items: center; gap: 4px; }
.hw-calc-histicon { display: inline-flex; }
.hw-calc-histbtn.is-active { background: var(--interactive-accent); color: var(--text-on-accent); }
.hw-calc-history { flex: 1 1 0; min-height: 0; overflow-y: auto; font-size: 0.9em; }
.hw-calc-histempty { color: var(--text-faint); font-size: 0.85em; padding: 6px 2px; }
.hw-calc-hrow { display: flex; flex-direction: column; align-items: flex-end; gap: 0; padding: 6px 6px; border-radius: 6px; cursor: pointer; }
.hw-calc-hrow:hover { background: var(--background-modifier-hover); }
.hw-calc-hexpr { color: var(--text-muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85em; }
.hw-calc-hres { font-weight: 600; font-size: 1.15em; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; border-radius: 4px; }
.hw-calc-hres:hover { background: var(--background-modifier-hover); }
.hw-calc-input { width: 100%; font-size: 1.25em; padding: 8px; font-family: var(--font-monospace); }
.hw-calc-result { min-height: 1.8em; text-align: right; font-size: 1.4em; font-weight: 600; padding: 4px 2px; color: var(--interactive-accent); }
.hw-calc-result.is-error { color: var(--text-error); font-size: 0.95em; font-weight: 400; }
.hw-calc-top { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.hw-calc-tabs { display: flex; gap: 2px; padding: 2px; border-radius: 8px; background: var(--background-secondary); }
.hw-calc-tab { padding: 3px 8px; font-size: 0.82em; background: transparent; box-shadow: none; border: none; }
.hw-calc-tab.is-active { background: var(--interactive-accent); color: var(--text-on-accent); }
.hw-calc-topspace { flex: 1 1 auto; }
.hw-calc-mode { font-size: 0.78em; padding: 3px 7px; font-family: var(--font-monospace); }
.hw-calc-icon { padding: 3px 6px; display: inline-flex; align-items: center; }
.hw-calc-icon svg { width: 15px; height: 15px; }
.hw-calc-icon.is-active { background: var(--interactive-accent); color: var(--text-on-accent); }
.hw-calc-pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.hw-calc-pad6 { grid-template-columns: repeat(6, 1fr); margin-bottom: 5px; }
.hw-calc-pad button { padding: 8px 0; font-size: 1em; min-width: 0; }
.hw-calc-pad6 button { padding: 6px 0; font-size: 0.85em; background: var(--background-secondary); }
.hw-calc-main.is-sci { width: 320px; }
.hw-calc-unitsbar { display: flex; margin: 2px 0 5px; }
.hw-calc-unitsbtn { display: inline-flex; align-items: center; gap: 2px; font-size: 0.8em; padding: 3px 8px; }
.hw-calc-unitsbtn svg { width: 14px; height: 14px; }
.hw-calc-units { display: flex; flex-direction: column; gap: 5px; padding: 6px; margin-bottom: 6px; border: 1px solid var(--background-modifier-border); border-radius: 8px; }
.hw-calc-units select { font-size: 0.85em; min-width: 0; }
.hw-calc-urow { display: flex; align-items: center; gap: 4px; min-width: 0; }
.hw-calc-urow select { flex: 1 1 0; }
.hw-calc-uval { flex: 0 0 70px; width: 70px; min-width: 0; font-family: var(--font-monospace); }
.hw-calc-uout { text-align: right; font-weight: 600; color: var(--interactive-accent); cursor: pointer; font-size: 0.95em; min-height: 1.2em; }
.hw-calc-help { font-size: 0.72em; color: var(--text-faint); margin: 0 0 6px; line-height: 1.35; }
.hw-calc-polar { font-size: 0.7em; font-weight: 400; color: var(--text-muted); }
.hw-calc-matrix { display: inline-grid; gap: 2px 14px; justify-items: end; padding: 2px 10px; border-left: 2px solid currentColor; border-right: 2px solid currentColor; font-size: 0.85em; }
.hw-calc-result { overflow-x: auto; }
.hw-calc-op { background: var(--background-modifier-hover); }
.hw-calc-eq { grid-column: auto; }

/* --- Function plots --- */
.modal.mod-plot { width: min(720px, 96vw); max-width: 96vw; max-height: 94vh; }
.hw-plot-modal { max-height: calc(94vh - 80px); overflow-y: auto; overflow-x: hidden; }
.hw-plot-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.hw-plot-tabs button { flex: 1; }
.hw-plot-tabs button.is-active { background: var(--interactive-accent); color: var(--text-on-accent); }
.hw-plot-wrap { display: flex; flex-direction: column; gap: 12px; }
.hw-plot-right { order: -1; }
.hw-plot-form { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.hw-plot-preview { display: block; width: 100%; max-height: 34vh; object-fit: contain; background: #fff; border: 1px solid var(--background-modifier-border); border-radius: 6px; }
.hw-plot-error { color: var(--text-error); min-height: 1.2em; font-size: 0.85em; margin-top: 2px; }
.hw-plot-curve { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; min-width: 0; }
.hw-plot-curve input[type=color] { flex: 0 0 34px; width: 34px; height: 30px; padding: 0; border: none; background: none; }
.hw-plot-curve > span { flex: 0 0 auto; }
.hw-plot-expr { flex: 1 1 0; min-width: 0; width: 100%; font-family: var(--font-monospace); }
.hw-plot-del { flex: 0 0 auto; padding: 0 10px; }
.hw-plot-range { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; }
.hw-plot-num { display: flex; align-items: center; gap: 6px; min-width: 0; }
.hw-plot-num span { flex: 0 0 auto; color: var(--text-muted); font-size: 0.85em; }
.hw-plot-num input { flex: 1 1 0; min-width: 0; width: 100%; }
.hw-plot-opts { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.hw-plot-opts label { display: flex; align-items: center; gap: 4px; }
.hw-plot-slider { display: flex; align-items: center; gap: 8px; }
.hw-plot-slider span:first-child { flex: 0 0 52px; color: var(--text-muted); }
.hw-plot-slider input { flex: 1 1 0; min-width: 0; }
.hw-plot-slider-val { flex: 0 0 42px; text-align: right; }
.hw-plot-help { font-size: 0.78em; color: var(--text-faint); }
.hw-plot-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
/* "Insert / Cancel" buttons always visible at the bottom of the dialog (the form scrolls under them). */
.hw-plot-modal .hw-plot-buttons { position: sticky; bottom: 0; z-index: 3; background: var(--background-primary); padding: 10px 0 2px; border-top: 1px solid var(--background-modifier-border); box-shadow: 0 -10px 14px -10px rgba(0, 0, 0, .45), 0 24px 0 0 var(--background-primary); }
@media (min-width: 900px) {
    .modal.mod-plot { width: min(1080px, 96vw); }
    .hw-plot-wrap { flex-direction: row; align-items: flex-start; }
    .hw-plot-right { position: sticky; top: 0; z-index: 2; flex: 0 0 50%; min-width: 0; background: var(--background-primary); }
    .hw-plot-form { flex: 1 1 0; }
    .hw-plot-preview { max-height: 62vh; }
}
@media (max-width: 899px) {
    .hw-plot-right { position: sticky; top: 0; z-index: 2; background: var(--background-primary); padding-bottom: 4px; }
    .hw-plot-preview { max-height: 28vh; }
}

/* --- Add page button at the bottom of the note --- */
.hw-add-page-row { display: flex; justify-content: center; padding: 18px 0 70px; width: 100%; }
.hw-add-page-btn { padding: 12px 28px; font-size: 1.05em; border-radius: 999px; background: var(--background-secondary); border: 1px dashed var(--text-faint); color: var(--text-muted); cursor: pointer; }
.hw-add-page-btn:hover { border-color: var(--interactive-accent); color: var(--interactive-accent); }

/* --- Floating calculator --- */
.handwriting-container { position: relative; }
.hw-calc-float { position: absolute; z-index: 40; width: max-content; max-width: calc(100% - 8px); background: var(--background-primary); border: 1px solid var(--background-modifier-border); border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.35); overflow: hidden; touch-action: none; }
.hw-calc-float-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 12px; background: var(--background-secondary); cursor: grab; touch-action: none; user-select: none; }
.hw-calc-float-head:active { cursor: grabbing; }
.hw-calc-float-title { font-weight: 600; font-size: 0.9em; color: var(--text-muted); }
.hw-calc-float-close { background: transparent; border: none; box-shadow: none; font-size: 1.3em; line-height: 1; padding: 2px 10px; cursor: pointer; }
.hw-calc-float-body { padding: 8px 10px 10px; }
.hw-calc-float .hw-calc-main { width: 236px; }
.hw-calc-float .hw-calc-main.is-sci { width: 300px; }
.hw-calc-float .hw-calc-histpane { width: 200px; }
.hw-calc-float .hw-calc-input { font-size: 1.05em; padding: 6px; }
.hw-calc-float .hw-calc-result { font-size: 1.2em; min-height: 1.5em; }
.hw-calc-float .hw-calc-pad button { padding: 7px 0; font-size: 0.95em; }
.hw-calc-float .hw-calc-pad6 button { padding: 5px 0; font-size: 0.8em; }

.hw-quick-slots { display: flex; align-items: center; gap: inherit; flex: 0 0 auto; }
.hw-quick-slots:empty { display: none; }

/* --- Settings: About and sections --- */
.hw-about { display: flex; gap: 16px; align-items: center; padding: 14px; margin-bottom: 14px; border: 1px solid var(--background-modifier-border); border-radius: 12px; background: var(--background-secondary); }
.hw-about-logo { flex: 0 0 72px; width: 72px; height: 72px; border-radius: 16px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.hw-about-logo img { width: 100%; height: 100%; object-fit: contain; }
.hw-about-info { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.hw-about-name { font-size: 1.25em; font-weight: 700; }
.hw-about-version { color: var(--text-muted); }
.hw-about-text { font-size: 0.9em; color: var(--text-muted); }
.hw-about-ai { color: var(--text-normal); }
.hw-set-section { border: 1px solid var(--background-modifier-border); border-radius: 10px; margin-bottom: 8px; background: var(--background-primary); }
.hw-set-section > summary { cursor: pointer; padding: 12px 14px; font-weight: 600; font-size: 1.02em; list-style: none; }
.hw-set-section > summary::-webkit-details-marker { display: none; }
.hw-set-section > summary::before { content: '▸'; display: inline-block; width: 1.2em; color: var(--text-muted); }
.hw-set-section[open] > summary::before { content: '▾'; }
.hw-set-body { padding: 0 14px 10px; }
/* sub-headings inside a settings section (Setting.setHeading) */
.setting-item.hw-set-sub { margin-top: 14px; padding-bottom: 2px; border-top: none; }
.hw-set-sub .setting-item-name { font-size: 0.8em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

.hw-pdf-tabs { display: flex; gap: 6px; margin: 4px 0 10px; }
.hw-pdf-tabs button { flex: 1; }
.hw-pdf-tabs button.is-active { background: var(--interactive-accent); color: var(--text-on-accent); }
.hw-pdf-diskline { display: flex; gap: 6px; }
.hw-pdf-diskline input { flex: 1; min-width: 0; }

/* --- v3: read-only --- */
.hw-readonly-banner { padding: 6px 12px; font-size: 0.85em; background: var(--background-modifier-error, rgba(220, 38, 38, .15)); color: var(--text-normal); border-bottom: 1px solid var(--background-modifier-border); }

/* --- v3: aligning the selection --- */
.hw-align-pop { display: flex; }
.hw-align-pop .hw-menu-btn svg { width: 18px; height: 18px; }

/* --- v3: plots 2.0 --- */
.hw-plot-sec { display: flex; flex-direction: column; gap: 6px; }
.hw-plot-sectitle { font-size: 0.75em; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); border-bottom: 1px solid var(--background-modifier-border); padding-bottom: 2px; }
.hw-plot-curvebox { display: flex; flex-direction: column; gap: 4px; padding: 6px; margin-bottom: 6px; border: 1px solid var(--background-modifier-border); border-radius: 8px; }
.hw-plot-curvebox .hw-plot-curve { margin-bottom: 0; }
.hw-plot-type { flex: 1 1 auto; min-width: 0; }
.hw-plot-lbl.hw-plot-lbl.hw-plot-lbl { flex: 0 0 52px; color: var(--text-muted); font-size: 0.85em; text-align: right; }
.hw-plot-data { width: 100%; font-family: var(--font-monospace); font-size: 0.85em; resize: vertical; }
.hw-plot-period { font-weight: 600; }
.hw-plot-pern { width: 56px; }
.hw-plot-num input.is-invalid { border-color: var(--text-error); }
.hw-plot-opts select { min-width: 0; }

/* --- v3: version history --- */
.modal.mod-hw-history { width: min(820px, 96vw); max-width: 96vw; }
.hw-history-top { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.hw-history-hint { flex: 1 1 auto; font-size: 0.82em; color: var(--text-muted); }
.hw-history-save { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.hw-history-save svg { width: 15px; height: 15px; }
.hw-history-body { display: flex; gap: 14px; min-height: 0; }
.hw-history-list { flex: 0 0 240px; max-height: min(60vh, 560px); overflow-y: auto; border-right: 1px solid var(--background-modifier-border); padding-right: 8px; }
.hw-history-day { font-size: 0.75em; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 10px 4px 4px; }
.hw-history-day:first-child { margin-top: 0; }
.hw-history-row { display: flex; align-items: baseline; gap: 10px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.hw-history-row:hover { background: var(--background-modifier-hover); }
.hw-history-row.is-active { background: var(--interactive-accent); color: var(--text-on-accent); }
.hw-history-row.is-active .hw-history-reason { color: var(--text-on-accent); }
.hw-history-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.hw-history-reason { font-size: 0.82em; color: var(--text-muted); }
.hw-history-empty { color: var(--text-faint); font-size: 0.9em; padding: 8px; }
.hw-history-right { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.hw-history-preview { width: 100%; max-width: 360px; display: flex; justify-content: center; }
.hw-history-preview canvas { width: auto; height: auto; max-width: 100%; max-height: 46vh; border: 1px solid var(--background-modifier-border); border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.hw-history-pager { display: flex; align-items: center; gap: 10px; }
.hw-history-pagelabel { font-size: 0.85em; color: var(--text-muted); min-width: 90px; text-align: center; }
.hw-history-info { font-size: 0.85em; color: var(--text-muted); text-align: center; }
.hw-history-buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
@media (max-width: 640px) {
    .hw-history-body { flex-direction: column; }
    .hw-history-list { flex: 0 0 auto; max-height: 30vh; border-right: none; border-bottom: 1px solid var(--background-modifier-border); padding: 0 0 8px; }
}

/* --- Lasso loop preview (SVG above the page) --- */
.hw-lasso-svg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; overflow: visible; }
.hw-lasso-svg path { fill: var(--interactive-accent); fill-opacity: 0.1; stroke: var(--interactive-accent); stroke-width: 1.5; stroke-dasharray: 6 4; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.hw-lasso-svg path.is-rect { stroke-linejoin: miter; }
.hw-lasso-svg.is-hidden { display: none; }
/* the live highlighter preview is drawn at 40 % (the highlighter layer's opacity); no cursor over the eraser circle */
.hw-page-a4 canvas.hw-live-highlighter { opacity: 0.4; }
.hw-page-a4 canvas.hw-no-cursor { cursor: none; }

/* --- Pen opacity --- */
.hw-alpha-section { margin-left: 2px; }
.hw-alpha-btn.hw-alpha-btn.hw-alpha-btn {
    -webkit-appearance: none; appearance: none;
    position: relative; display: inline-block; width: 22px; height: 22px; min-width: 22px; min-height: 22px; padding: 0; border-radius: 50%;
    border: 1px solid var(--background-modifier-border); box-shadow: none; overflow: hidden; flex: 0 0 auto;
    /* checkerboard underneath shows how much shows through */
    background: repeating-conic-gradient(#cbd5e1 0% 25%, #ffffff 0% 50%) 50% / 8px 8px;
}
.hw-alpha-btn::after { content: ''; position: absolute; inset: 0; border-radius: 50%; background: var(--sw); opacity: var(--sa); }
/* Thickness / opacity button on the toolbar and its menu */
.hw-size-btn { display: inline-flex; align-items: center; justify-content: center; }
.hw-size-dot { display: block; border-radius: 50%; background: var(--sw, currentColor); box-shadow: 0 0 0 1px rgba(128,128,128,.45); }
.hw-size-pop { min-width: 0; }
.hw-size-pop .hw-thickness-presets { gap: 6px; }
.hw-alpha-opt { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 8px; height: auto; font-size: 0.78em; }
.hw-alpha-opt.active { background: var(--interactive-accent); color: var(--text-on-accent); }

/* v3.9: narrow screen – colours, thickness and opacity in one panel */
.hw-size-pop { z-index: 1001; }
.hw-style-pop { max-height: calc(100vh - 80px); overflow-y: auto; }
.hw-style-pop > .hw-menu-group { border-top: 1px solid var(--background-modifier-border); padding-top: 10px; width: 100%; }
.hw-style-pop .hw-alpha-row { flex-wrap: wrap; }

/* --- v3.10: custom toolbar layout --- */
.hw-toolbar.hw-toolbar.hw-toolbar .hw-hidden-item { display: none; }
.hw-tool-btn.hw-more-active { color: var(--interactive-accent); box-shadow: inset 0 -2px 0 var(--interactive-accent); }

/* --- v3.10: table of contents --- */
.hw-contents { width: 300px; max-width: calc(100vw - 16px); gap: 8px; }
.hw-contents-list { display: flex; flex-direction: column; gap: 2px; max-height: min(60vh, 420px); overflow-y: auto; }
button.hw-contents-item {
    display: flex; align-items: baseline; gap: 10px; width: 100%; height: auto;
    padding: 7px 8px; justify-content: space-between; text-align: left;
    background: transparent; box-shadow: none; border-radius: 6px; font-size: 0.92em;
}
button.hw-contents-item:hover { background: var(--background-modifier-hover); }
button.hw-contents-item.active { background: color-mix(in srgb, var(--interactive-accent) 16%, transparent); }
.hw-contents-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hw-contents-page { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 0.9em; }
.hw-contents-empty { color: var(--text-muted); font-size: 0.85em; line-height: 1.4; padding: 4px 2px 6px; }
.hw-contents-foot { display: flex; gap: 6px; border-top: 1px solid var(--background-modifier-border); padding-top: 8px; }
.hw-contents-foot button { flex: 1; font-size: 0.85em; }
.hw-title-input { width: 100%; font-size: 1.05em; padding: 8px 10px; }
.hw-title-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* --- v3.10: page formats --- */
/* --- v3.13: OLED care --- */
/* 1. Dark paper: JS computes the background (darkPaperColor), the filter inverts ink and PDF pages (the same as for the background). */

.hw-oled-dark .hw-page-bg { filter: invert(1) hue-rotate(180deg) brightness(0.88); }
.hw-oled-dark .hw-page-image { filter: brightness(0.85); }
.hw-oled-dark .hw-page-a4 { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08); }

/* 3. Pixel shift (the whole view by 1–2 px) */
.handwriting-container.hw-oled-shift > *:not(.hw-oled-veil) { transform: translate(var(--hw-shift-x, 0), var(--hw-shift-y, 0)); }
/* 4. Dim when idle */
.hw-oled-veil {
    position: absolute; inset: 0; z-index: 50; background: #000;
    opacity: 0; pointer-events: none; transition: opacity 2.5s ease;
}
.hw-oled-veil.hw-on { opacity: 0.92; pointer-events: auto; cursor: pointer; }
.handwriting-container { position: relative; }
/* highlighter on dark paper – slightly stronger so it stays visible */
.hw-oled-dark .hw-oled-inv .hw-layer-highlighter { opacity: 0.55; }

/* --- v3.14: scrolling toolbar on a very narrow screen --- */
.hw-tb-arrow {
    position: absolute; z-index: 31; width: 40px; display: none; align-items: center; justify-content: center;
    color: var(--text-muted); cursor: pointer;
}
/* the arrows also fade out the toolbar edge they sit on */
.hw-tb-arrow-left { justify-content: flex-start; padding-left: 4px; background: linear-gradient(to right, var(--background-primary) 55%, transparent); }
.hw-tb-arrow-right { justify-content: flex-end; padding-right: 4px; background: linear-gradient(to left, var(--background-primary) 55%, transparent); }
.hw-tb-arrow.hw-on { display: flex; }
.hw-tb-arrow-left { left: 0; }
.hw-tb-arrow-right { right: 0; }
.hw-tb-arrow:hover { color: var(--text-normal); }
.hw-tb-arrow svg { width: 18px; height: 18px; }
/* image of the dragged selection (moved with a CSS transform) */
.hw-page-a4 canvas.hw-drag-sprite { left: 0; top: 0; transform-origin: 0 0; z-index: 2; pointer-events: none; }
.hw-oled-dark .hw-oled-inv canvas.hw-drag-sprite { filter: invert(1) hue-rotate(180deg) brightness(0.88); }

/* --- v3.16: zoom button and panel --- */
.hw-tool-btn.hw-zoom-btn { min-width: 52px; font-size: 0.82em; font-variant-numeric: tabular-nums; padding: 4px 8px; }
.hw-zoom-panel { width: 236px; gap: 10px; }
.hw-zoom-row { display: flex; gap: 6px; align-items: center; }
.hw-zoom-row button { flex: 1; }
.hw-zoom-step.hw-zoom-step.hw-zoom-step { flex: 0 0 40px; font-size: 1.2em; }
.hw-zoom-value { flex: 1; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.hw-zoom-favs { display: flex; flex-wrap: wrap; gap: 6px; }
.hw-zoom-chip { display: flex; border-radius: 6px; overflow: hidden; border: 1px solid var(--background-modifier-border); }
.hw-zoom-chip.active { border-color: var(--interactive-accent); }
.hw-zoom-chip button { border-radius: 0; box-shadow: none; padding: 4px 8px; height: auto; }
.hw-zoom-chip-x.hw-zoom-chip-x.hw-zoom-chip-x { color: var(--text-muted); padding: 4px 6px; }
.hw-zoom-chip.active .hw-zoom-chip-go { background: color-mix(in srgb, var(--interactive-accent) 22%, transparent); }
.hw-zoom-add { font-size: 0.85em; padding: 4px 8px; height: auto; }
.hw-zoom-hint { font-size: 0.8em; color: var(--text-muted); line-height: 1.35; }
.hw-zoom-open { display: flex; align-items: center; gap: 4px; font-size: 0.85em; color: var(--text-muted); border-top: 1px solid var(--background-modifier-border); padding-top: 8px; }
.hw-zoom-open select { font-size: 1em; padding: 2px 4px; height: auto; }

/* --- v3.16.3: deleting versions --- */
.hw-history-row { position: relative; }
button.hw-history-rowdel {
    margin-left: auto; padding: 2px 6px; height: auto; background: transparent; box-shadow: none;
    color: var(--text-faint); opacity: 0; transition: opacity 0.15s;
}
.hw-history-row:hover button.hw-history-rowdel, .hw-history-row.is-active button.hw-history-rowdel, button.hw-history-rowdel.is-armed { opacity: 1; }
button.hw-history-rowdel svg { width: 14px; height: 14px; }
.hw-history-row.is-active button.hw-history-rowdel { color: var(--text-on-accent); }
button.hw-history-rowdel.is-armed, button.hw-history-delete.is-armed, button.hw-history-delall.is-armed { background: var(--background-modifier-error, #dc2626); color: #fff; opacity: 1; }
@media (hover: none) { button.hw-history-rowdel { opacity: 0.7; } }

/* --- v3.20: removing custom colours --- */
button.hw-swatch.custom { position: relative; }
.hw-swatch-x {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1;
    color: var(--text-on-accent, #fff);
    background: var(--text-muted);
    box-shadow: 0 0 0 1.5px var(--background-primary);
    cursor: pointer;
}
.hw-swatch-x:hover { background: var(--text-error, #e5484d); }
@media (hover: hover) {
    button.hw-swatch.custom:hover .hw-swatch-x { display: flex; }
}
.hw-zoom-panel .hw-zoom-add.hw-hidden { display: none; }

/* segmented buttons (scope and page size) */

/* --- v3.23: hidden frame used for printing --- */
iframe.hw-print-frame { position: fixed; right: 0; bottom: 0; width: 0; height: 0; border: 0; visibility: hidden; }

/* --- 3.13.0: what the eraser erases (eraser menu) --- */
.hw-erase-opts { min-width: 230px; }
.hw-erase-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 2px; cursor: default; }
.hw-erase-name { font-size: 0.9em; color: var(--text-normal); }
.hw-erase-seg { display: flex; padding: 2px; gap: 2px; border-radius: 8px; background: var(--background-modifier-form-field, var(--background-secondary)); border: 1px solid var(--background-modifier-border); }
.hw-erase-seg > button {
    height: auto; min-height: 28px; padding: 3px 9px; margin: 0; border: none; border-radius: 6px; box-shadow: none;
    background: transparent; color: var(--text-muted); font-size: 0.85em; cursor: pointer;
}
.hw-erase-seg > button:hover { background: var(--background-modifier-hover); color: var(--text-normal); }
.hw-erase-seg > button.active { background: var(--interactive-accent); color: var(--text-on-accent); }
.hw-style-pop.hw-style-pop.hw-style-pop .hw-no-colors { display: none; }
.hw-style-pop > .hw-no-colors + .hw-menu-group { border-top: none; padding-top: 0; }

/* --- 3.14.0: shape fill options --- */
.hw-menu-sep-v { width: 1px; align-self: stretch; margin: 2px 4px; background: var(--background-modifier-border); }
.hw-menu-btn:disabled { opacity: 0.35; cursor: default; }

/* --- 3.14.0: selection mode panel --- */
.hw-selmode-pop { gap: 6px; padding: 10px; min-width: 250px; max-width: calc(100vw - 16px); }
.hw-selmode-pop .hw-menu-title { margin: 0 2px 2px; }
button.hw-selmode-opt {
    display: flex; align-items: center; gap: 12px; width: 100%; height: auto; min-height: 52px;
    padding: 8px 10px; margin: 0; text-align: left; border-radius: 8px; cursor: pointer;
    background: transparent; box-shadow: none; border: 1px solid transparent; color: var(--text-normal);
}
button.hw-selmode-opt:hover { background: var(--background-modifier-hover); }
button.hw-selmode-opt.active { border-color: var(--interactive-accent); background: color-mix(in srgb, var(--interactive-accent) 12%, transparent); }
.hw-selmode-icon {
    flex: 0 0 auto; width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
    background: var(--background-secondary); color: var(--text-normal);
}
button.hw-selmode-opt.active .hw-selmode-icon { background: var(--interactive-accent); color: var(--text-on-accent); }
.hw-selmode-icon svg { width: 22px; height: 22px; }
.hw-selmode-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.hw-selmode-name { font-weight: 600; font-size: 0.95em; }
.hw-selmode-desc { font-size: 0.8em; color: var(--text-muted); white-space: normal; line-height: 1.3; }
.hw-selmode-check { flex: 0 0 auto; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--background-modifier-border-hover, #888); box-sizing: border-box; }
button.hw-selmode-opt.active .hw-selmode-check { border-color: var(--interactive-accent); background: radial-gradient(circle, var(--interactive-accent) 0 4px, transparent 4.5px); }


/* --- OLED care rules restored (ink inversion, toolbar fade) --- */
.hw-oled-dark .hw-oled-inv .hw-layer-bottom,
.hw-oled-dark .hw-oled-inv .hw-layer-top,
.hw-oled-dark .hw-oled-inv .hw-page-bg { filter: invert(1) hue-rotate(180deg) brightness(0.88); }
.handwriting-container .hw-toolbar { transition: opacity 0.6s ease; }
.hw-oled-ui-dim .hw-toolbar { opacity: 0.18; }
.hw-oled-dark .hw-pp-cell.hw-oled-inv canvas { filter: invert(1) hue-rotate(180deg) brightness(0.88); }

/* ============================================================
   3.15.0: page navigation – pages panel
   ============================================================ */
/* --- pages panel --- */
.hw-pp {
    position: absolute; top: 0; bottom: 0; z-index: 40; width: 292px; max-width: calc(100% - 24px);
    display: flex; flex-direction: column; background: var(--background-primary);
    box-shadow: 0 0 0 1px var(--background-modifier-border), 0 10px 40px rgba(0, 0, 0, 0.35);
    user-select: none; -webkit-user-select: none;
}
.hw-pp-right { right: 0; border-radius: 12px 0 0 12px; }
.hw-pp-left { left: 0; border-radius: 0 12px 12px 0; }
.hw-pp-sheet { left: 0; right: 0; top: auto; width: auto; max-width: none; height: 78%; border-radius: 16px 16px 0 0; }
.hw-pp-grip { align-self: center; width: 40px; height: 5px; margin: 8px 0 2px; border-radius: 3px; background: var(--background-modifier-border-hover, #666); }
.hw-pp-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px 14px; }
.hw-pp-title { font-weight: 700; font-size: 15px; color: var(--text-normal); }
.hw-pp-count { font-size: 13px; color: var(--text-muted); }
.hw-pp-spacer { flex: 1; }
button.hw-pp-icon { width: 32px; height: 32px; padding: 0; display: flex; align-items: center; justify-content: center; background: transparent; box-shadow: none; color: var(--text-muted); }
button.hw-pp-icon:hover { color: var(--text-normal); background: var(--background-modifier-hover); }
button.hw-pp-btn { height: 32px; padding: 0 12px; font-size: 13px; }
button.hw-pp-textbtn { height: 32px; padding: 0 6px; background: transparent; box-shadow: none; border: none; color: var(--text-accent); font-size: 13px; font-weight: 600; }
.hw-pp-search { display: flex; align-items: center; gap: 6px; margin: 0 12px 8px; padding: 0 10px; height: 34px; border-radius: 8px; border: 1px solid var(--background-modifier-border); background: var(--background-modifier-form-field, var(--background-secondary)); }
.hw-pp-search-icon { display: flex; color: var(--text-faint); }
.hw-pp-search-icon svg { width: 15px; height: 15px; }
.hw-pp-search.hw-pp-search.hw-pp-search input { flex: 1; min-width: 0; height: 30px; border: none; background: transparent; box-shadow: none; padding: 0; font-size: 13px; }
.hw-pp-list { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 2px 12px 12px; position: relative; overscroll-behavior: contain; touch-action: pan-y; }
.hw-pp-sec {
    display: flex; align-items: center; gap: 6px; width: 100%; height: auto; padding: 8px 2px 6px; margin: 2px 0 0;
    background: transparent; box-shadow: none; border: none; color: var(--text-normal); font-size: 12px; font-weight: 600; text-align: left; cursor: pointer;
}
.hw-pp-sec-chev { display: flex; color: var(--text-muted); }
.hw-pp-sec-chev svg { width: 14px; height: 14px; }
.hw-pp-sec-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hw-pp-sec-range { font-weight: 500; color: var(--text-faint); white-space: nowrap; }
.hw-pp-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 10px; padding: 4px 0 6px; }
.hw-pp-sheet .hw-pp-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.hw-pp-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; border-radius: 6px; outline: none; touch-action: pan-y; }
.hw-pp-thumb { position: relative; max-width: 100%; border-radius: 3px; box-shadow: 0 0 0 1px rgba(128, 128, 128, 0.35), 0 1px 3px rgba(0, 0, 0, 0.25); background: #fff; transition: transform 0.12s ease, box-shadow 0.12s ease; }
.hw-pp-thumb canvas { display: block; width: 116px; max-width: 100%; border-radius: 3px; }
.hw-pp-cell:hover .hw-pp-thumb { box-shadow: 0 0 0 1px var(--background-modifier-border-hover, #888), 0 2px 8px rgba(0, 0, 0, 0.3); }
.hw-pp-cell:focus-visible .hw-pp-thumb { box-shadow: 0 0 0 2px var(--interactive-accent); }
.hw-pp-cell.is-current .hw-pp-thumb { box-shadow: 0 0 0 3px var(--interactive-accent); }
.hw-pp-cell.is-current .hw-pp-num { color: var(--interactive-accent); font-weight: 700; }
.hw-pp-cell.is-flash .hw-pp-thumb { animation: hw-pp-flash 0.9s ease; }
@keyframes hw-pp-flash { 0%, 60% { box-shadow: 0 0 0 4px var(--interactive-accent); } 100% { box-shadow: 0 0 0 1px rgba(128,128,128,.35); } }
.hw-pp-cell.is-lifted .hw-pp-thumb { transform: scale(1.06); box-shadow: 0 0 0 2px var(--interactive-accent), 0 10px 24px rgba(0, 0, 0, 0.4); }
.hw-pp-cell.is-dragging { opacity: 0.35; }
.hw-pp-num { font-size: 12px; color: var(--text-muted); }
.hw-pp-num.has-title::before { content: "§ "; color: var(--interactive-accent); }
.hw-pp-badge { position: absolute; left: 4px; bottom: 4px; padding: 0 5px; border-radius: 4px; font-size: 10px; line-height: 16px; color: #334155; background: rgba(255, 255, 255, 0.85); }
.hw-pp-check { display: none; position: absolute; right: 5px; top: 5px; width: 20px; height: 20px; border-radius: 50%; box-sizing: border-box; border: 2px solid #94a3b8; background: rgba(255, 255, 255, 0.9); }
.hw-pp-selecting .hw-pp-check { display: block; }
.hw-pp-cell.is-selected .hw-pp-check { border-color: var(--interactive-accent); background: var(--interactive-accent) radial-gradient(circle, #fff 0 3px, transparent 3.5px); }
.hw-pp-cell.is-selected .hw-pp-thumb { box-shadow: 0 0 0 3px var(--interactive-accent); }
.hw-pp-drop.is-on { display: block; }
.hw-pp-drop { display: none; position: absolute; width: 4px; border-radius: 2px; background: var(--interactive-accent); pointer-events: none; z-index: 2; }
.hw-pp-ghost { position: fixed; z-index: 1000; pointer-events: none; opacity: 0.9; transform: rotate(-3deg); box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45); border-radius: 3px; background: #fff; }
.hw-pp-ghost canvas { display: block; width: 80px; border-radius: 3px; height: auto; }
.hw-pp-ghost-count { position: absolute; right: -8px; top: -8px; min-width: 22px; height: 22px; padding: 0 4px; box-sizing: border-box; border-radius: 11px; background: var(--interactive-accent); color: var(--text-on-accent); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.hw-pp-empty { padding: 20px 4px; color: var(--text-muted); font-size: 13px; text-align: center; }
.hw-pp-foot { display: flex; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--background-modifier-border); }
button.hw-pp-add { flex: 1; height: 36px; display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; }
button.hw-pp-add svg { width: 16px; height: 16px; }
.hw-pp-foot.hw-pp-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 8px; }
button.hw-pp-act { height: 50px; padding: 4px 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; background: transparent; box-shadow: none; color: var(--text-normal); }
button.hw-pp-act:hover:not(:disabled) { background: var(--background-modifier-hover); }
button.hw-pp-act svg { width: 18px; height: 18px; }
button.hw-pp-act:disabled { opacity: 0.4; }
button.hw-pp-act.hw-pp-danger { color: var(--text-error); }
.hw-pp-toast {
    display: none; align-items: center; gap: 10px; margin: 0 12px 8px; padding: 8px 8px 8px 12px; border-radius: 8px;
    background: var(--background-secondary-alt, var(--background-secondary)); border: 1px solid var(--background-modifier-border); font-size: 13px;
}
.hw-pp-toast.is-on { display: flex; }
.hw-pp-toast span { flex: 1; }
.hw-pp-toast button { height: 28px; padding: 0 10px; font-weight: 600; color: var(--text-accent); }
input.hw-pp-moveto { width: 100%; }

/* --- page style popover (from the pages panel) --- */
.hw-pp-style {
    position: absolute; z-index: 41; top: 12px; width: 300px; max-width: calc(100% - 24px); max-height: calc(100% - 24px); overflow-y: auto;
    padding: 12px; box-sizing: border-box; display: flex; flex-direction: column; gap: 8px;
    border-radius: 12px; background: var(--background-primary); border: 1px solid var(--background-modifier-border); box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
}
.hw-pp-style-right { right: 304px; }
.hw-pp-style-left { left: 304px; }
.hw-pp-style-sheet { left: 12px; right: 12px; top: auto; bottom: calc(78% + 8px); width: auto; max-height: 48%; }
.hw-pp-style-head { display: flex; align-items: center; gap: 8px; }
.hw-pp-style-title { flex: 1; font-weight: 700; font-size: 14px; }
.hw-pp-style-label { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); margin-top: 4px; }
.hw-pp-style-note { font-size: 12px; color: var(--text-muted); }
.hw-pp-seg { display: flex; padding: 3px; gap: 3px; border-radius: 10px; background: var(--background-modifier-form-field, var(--background-secondary)); border: 1px solid var(--background-modifier-border); }
.hw-pp-seg > button { flex: 1 1 0; min-width: 0; height: auto; min-height: 34px; padding: 4px; margin: 0; border: none; border-radius: 7px; box-shadow: none; background: transparent; color: var(--text-muted); font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.hw-pp-seg > button svg { width: 24px; height: 26px; }
.hw-pp-seg > button:hover:not(:disabled) { background: var(--background-modifier-hover); color: var(--text-normal); }
.hw-pp-seg > button.active { background: var(--interactive-accent); color: var(--text-on-accent); }
.hw-pp-seg > button:disabled { opacity: 0.45; }
.hw-pp-tpls { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
button.hw-pp-tpl { height: auto; min-width: 0; padding: 5px 2px 4px; margin: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; border-radius: 8px; box-shadow: none; border: 1px solid var(--background-modifier-border); background: var(--background-primary); color: var(--text-muted); font-size: 10.5px; line-height: 1.15; text-align: center; white-space: normal; }
button.hw-pp-tpl svg { width: 26px; height: 34px; flex: 0 0 auto; }
button.hw-pp-tpl:hover { background: var(--background-modifier-hover); color: var(--text-normal); }
button.hw-pp-tpl.active { border-color: var(--interactive-accent); box-shadow: inset 0 0 0 1px var(--interactive-accent); color: var(--text-normal); }
.hw-pp-papers { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 2px; }
.hw-pp-papers button.hw-swatch, .hw-pp-papers button.hw-swatch-add { width: 26px; height: 26px; min-width: 26px; min-height: 26px; }
.hw-pp-papers button.hw-swatch:hover { transform: none; }
.hw-pp-style-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--background-modifier-border); }
.hw-pp-style.hw-pp-style.hw-pp-style .hw-hidden, .hw-pp.hw-pp.hw-pp .hw-hidden { display: none; }

/* --- 3.15.1 fixes --- */
.hw-pp-right, .hw-pp-left { border-radius: 0; }
.hw-pp-foot button.hw-pp-foot-btn, .hw-pp-foot button.hw-pp-add { height: 36px; font-size: 14px; }
.hw-pp-foot button.hw-pp-foot-btn { padding: 0 14px; font-weight: 500; }
.hw-pp-grid { grid-template-columns: repeat(var(--hw-pp-cols, 2), minmax(0, 1fr)); }
.hw-pp-thumb canvas { max-width: 100%; }
.hw-pp-tabs { margin: 0 12px 8px; }
.hw-pp-tabs > button { flex-direction: row; min-height: 30px; font-size: 13px; }
button.hw-pp-toc { display: flex; align-items: center; gap: 10px; width: 100%; height: auto; min-height: 40px; padding: 8px 10px; margin: 0 0 2px; border-radius: 8px; background: transparent; box-shadow: none; border: none; color: var(--text-normal); text-align: left; font-size: 14px; }
button.hw-pp-toc:hover { background: var(--background-modifier-hover); }
button.hw-pp-toc.is-current { background: color-mix(in srgb, var(--interactive-accent) 16%, transparent); }
.hw-pp-toc-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hw-pp-toc-page { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
/* page style popover: beside the panel (any panel width), or at the side / bottom edge when the panel is closed */
.hw-pp-style-right { right: calc(var(--hw-pp-w, 292px) + 12px); }
.hw-pp-style-left { left: calc(var(--hw-pp-w, 292px) + 12px); }
.hw-pp-style-edge-right { right: 36px; }
.hw-pp-style-edge-left { left: 36px; }
.hw-pp-style-bottom { left: 12px; right: 12px; top: auto; bottom: 12px; width: auto; max-height: 70%; }
.hw-pp-scope > button { flex-direction: row; min-height: 30px; font-size: 12px; }
.hw-pp-pick { display: flex; align-items: center; gap: 6px; }
.hw-pp-pick button.hw-pp-icon { font-size: 18px; }
.hw-pp-pick-label { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; font-size: 13px; }
.hw-pp-pick-label input { width: 56px; height: 28px; text-align: center; }
/* switch (button, not a checkbox) */
button.hw-switch { flex: 0 0 auto; position: relative; width: 40px; height: 22px; min-width: 40px; padding: 0; margin: 0; border: none; border-radius: 11px; box-shadow: none; cursor: pointer; background: var(--background-modifier-border-hover, #666); transition: background 0.15s; }
button.hw-switch.is-on { background: var(--interactive-accent); }
.hw-switch-knob { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 0.15s; }
button.hw-switch.is-on .hw-switch-knob { transform: translateX(18px); }
/* thickness dots in the current colour */
.hw-thickness-btn .hw-dot { background: var(--dot, var(--text-normal)); }
.hw-thickness-btn.active .hw-dot { background: var(--dot, var(--text-on-accent)); box-shadow: 0 0 0 1.5px var(--text-on-accent); }
/* selection mode popover: icons only */
.hw-selmode-pop { min-width: 0; gap: 12px; padding: 10px 12px; }
/* settings: tool and shortcut chips */
.hw-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 12px; }
.hw-chips-label { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); margin-top: 2px; }
.hw-chips-empty { font-size: 13px; color: var(--text-faint); padding: 6px 2px; }
.hw-chip { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 17px; border: 1px solid var(--background-modifier-border); background: var(--background-primary); color: var(--text-muted); font-size: 13px; box-shadow: none; cursor: pointer; }
button.hw-chip:hover { color: var(--text-normal); border-color: var(--background-modifier-border-hover, #888); }
.hw-chip.is-on { border-color: var(--interactive-accent); color: var(--text-normal); background: color-mix(in srgb, var(--interactive-accent) 14%, var(--background-primary)); }
.hw-chips-on .hw-chip { padding: 0 4px; gap: 4px; cursor: default; }
.hw-chip-mark { font-weight: 700; color: var(--interactive-accent); }
.hw-chip-icon { display: inline-flex; }
button.hw-chip-btn { width: 26px; height: 26px; min-width: 26px; padding: 0; border-radius: 13px; background: transparent; box-shadow: none; border: none; color: var(--text-muted); font-size: 16px; line-height: 1; }
button.hw-chip-btn:hover:not(:disabled) { background: var(--background-modifier-hover); color: var(--text-normal); }
button.hw-chip-btn:disabled { opacity: 0.25; }
button.hw-chip-x:hover:not(:disabled) { color: var(--text-error); }

/* --- 3.15.1: current page frame in screen pixels (same at every zoom) --- */
.hw-current-frame {
    position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none; box-sizing: border-box;
    border-radius: 3px;
    box-shadow: 0 0 0 3px var(--interactive-accent), 0 0 16px 3px color-mix(in srgb, var(--interactive-accent) 40%, transparent);
    transition: opacity 0.2s ease;
}
/* pages other than the current one are slightly dimmed (a veil instead of opacity: no extra compositing of the canvases) */
.hw-page-dim {
    position: absolute; inset: 0; z-index: 5; pointer-events: none;
    background: rgba(0, 0, 0, 0.14); opacity: 0; transition: opacity 0.2s ease;
}
.hw-dim-others .hw-single-page-container:not(.hw-page-current) .hw-page-dim { opacity: 1; }
.hw-oled-dark .hw-page-dim { background: rgba(0, 0, 0, 0.4); }
button.hw-pp-cols { width: auto; padding: 0 6px; gap: 3px; }
.hw-pp-cols svg { width: 16px; height: 16px; }
.hw-pp-cols-n { font-size: 12px; font-weight: 600; }

/* --- wet ink layer (the stroke being written, screen-sized, above the pages) --- */
.hw-ink-layer { position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; }
.hw-oled-dark .hw-ink-layer.hw-ink-inv { filter: invert(1) hue-rotate(180deg) brightness(0.88); }
/* --- performance overlay (Settings → Advanced) --- */
.hw-perf {
    position: absolute; left: 8px; bottom: 8px; z-index: 30; pointer-events: none; white-space: pre;
    font: 11px/1.35 var(--font-monospace); padding: 4px 8px; border-radius: 6px;
    color: #fff; background: rgba(0, 0, 0, 0.72);
}

/* --- shape colours: outline / fill fields before the palette --- */
.hw-color-targets { display: flex; gap: 3px; padding: 2px; border-radius: 8px; background: var(--background-modifier-hover); }
button.hw-color-target.hw-color-target {
    width: 30px; height: 30px; min-width: 30px; padding: 0; display: flex; align-items: center; justify-content: center;
    border: none; border-radius: 6px; background: transparent; box-shadow: none; cursor: pointer;
}
button.hw-color-target.hw-color-target.active { background: var(--background-primary); box-shadow: 0 0 0 2px var(--interactive-accent); }
.hw-ct-chip { width: 16px; height: 16px; border-radius: 3px; box-sizing: border-box; }
.hw-ct-line .hw-ct-chip { border: 3px solid var(--c); box-shadow: 0 0 0 1px rgba(128, 128, 128, 0.45); }
.hw-ct-fill .hw-ct-chip { background: var(--c); box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.45); }
/* fill "same as outline": a small diagonal mark */
.hw-ct-fill.is-auto .hw-ct-chip { background: linear-gradient(135deg, var(--c) 0 45%, transparent 45% 55%, var(--c) 55%); }
.hw-color-palette-host { display: flex; align-items: center; }

/* --- current page indicator "12 / 40" (beside the page; tap = pages panel) --- */
button.hw-page-num.hw-page-num {
    position: absolute; left: 0; top: 0; z-index: 24; height: 26px; min-width: 0; padding: 0 9px; margin: 0;
    border-radius: 13px; border: 1px solid var(--background-modifier-border); box-shadow: none;
    background: var(--background-primary); color: var(--text-muted);
    font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; cursor: pointer;
    opacity: 0.7; transition: opacity 0.3s ease;
}
button.hw-page-num.hw-page-num:hover, button.hw-page-num.is-recent { opacity: 1; color: var(--text-normal); }
/* no room beside the page: over the page edge, only for a moment after scrolling */
button.hw-page-num.is-over { opacity: 0; pointer-events: none; }
button.hw-page-num.is-over.is-recent { opacity: 0.95; pointer-events: auto; }
.hw-pp-open-right .hw-page-num, .hw-pp-open-sheet .hw-page-num { visibility: hidden; }
.hw-oled-ui-dim .hw-page-num { opacity: 0.18; }

/* Demo page (site/demo/demo.css) */
/* Demo page: a slim bar on top, the plugin view fills the rest of the screen. */
html, body.demo-page { height: 100%; margin: 0; }
/* the dynamic viewport height (phone toolbars) where supported */
@supports (height: 100dvh) { body.demo-page { height: 100dvh; } }
body.demo-page {
    display: flex; flex-direction: column;
    height: 100vh;
    overflow: hidden; overscroll-behavior: none;
    font-family: var(--font-interface); color: var(--text-normal); background: var(--background-secondary);
    -webkit-text-size-adjust: 100%;
}
body.demo-page *, body.demo-page *::before, body.demo-page *::after { box-sizing: border-box; }

.demo-top {
    flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px 16px;
    padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top));
    padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right));
    background: var(--background-primary); border-bottom: 1px solid var(--background-modifier-border);
}
.demo-brand { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--text-normal); text-decoration: none; font-weight: 650; font-size: 15px; }
.demo-brand .logo { flex: 0 0 auto; display: block; filter: drop-shadow(0 0 6px rgba(79, 117, 82, 0.4)); }
.demo-brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.demo-brand:hover .demo-brand-name { text-decoration: underline; text-underline-offset: 2px; }
.demo-badge { flex: 0 0 auto; padding: 2px 8px; border-radius: 5px; font-size: 12px; font-weight: 600; color: var(--text-accent); background: var(--background-modifier-active-hover); }

.demo-bar { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.demo-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 5px 10px;
    font: inherit; font-size: 13px; font-weight: 600; line-height: 1; white-space: nowrap; text-decoration: none; cursor: pointer;
    color: var(--text-normal); background: var(--interactive-normal);
    border: 1px solid var(--background-modifier-border); border-radius: 8px; box-shadow: var(--shadow-s);
    touch-action: manipulation;
}
.demo-btn:hover { background: var(--interactive-hover); border-color: var(--background-modifier-border-hover); }
.demo-btn:focus-visible { outline: 2px solid var(--interactive-accent); outline-offset: 1px; }
.demo-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.demo-btn[aria-pressed="true"] { background: var(--background-modifier-active-hover); border-color: var(--interactive-accent); }
.demo-btn-primary { background: var(--interactive-accent); border-color: transparent; color: var(--text-on-accent); }
.demo-btn-primary:hover { background: var(--interactive-accent-hover); border-color: transparent; }

/* Narrow screens: icons only, the brand shrinks to its logo + badge. */
@media (max-width: 900px) { .demo-brand-name { display: none; } }
@media (max-width: 600px) {
    .demo-btn-label { display: none; }
    .demo-btn { width: 36px; min-height: 36px; padding: 0; }
    .demo-bar { gap: 4px; }
}

.demo-app {
    position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden;
    background: var(--background-secondary); font-size: 14px; isolation: isolate;
    padding-bottom: env(safe-area-inset-bottom);
}
/* The marble background (site/background.jpg, site/background-light.jpg) behind the pages, under a veil – the build sets --demo-bg-image. */
:root { --demo-veil: linear-gradient(180deg, rgba(241, 243, 247, 0.55), rgba(241, 243, 247, 0.7)); }
:root[data-theme="dark"] { --demo-veil: linear-gradient(180deg, rgba(17, 17, 17, 0.3), rgba(17, 17, 17, 0.5)); }
.demo-app { background: var(--demo-veil), var(--demo-bg-image, none) center / cover no-repeat, var(--background-secondary); }
.demo-app .handwriting-container { background: transparent; }
.demo-app > .workspace-leaf-content { display: flex; flex-direction: column; height: 100%; }
.demo-app .view-header { display: none; }
.demo-app .view-content { position: relative; flex: 1 1 auto; min-height: 0; }
.demo-app .handwriting-container { height: 100%; outline: none; }
/* Unselected tool buttons get their own fill, so they stand out from the toolbar (the plugin leaves them
   transparent and relies on the Obsidian theme). The selected one keeps the plugin's accent colour. */
:root { --demo-tool-bg: #e9edf4; --demo-tool-bg-hover: #dde3ee; --demo-tool-border: #cfd6e3; }
/* Dark mode: set by site/theme.js (follows the system unless the toggle was used). */
:root[data-theme="dark"] { --demo-tool-bg: #2b2b2b; --demo-tool-bg-hover: #363636; --demo-tool-border: rgba(255, 255, 255, 0.16); }
.hw-tool-btn:not(.active) {
    background: var(--demo-tool-bg);
    border-color: var(--demo-tool-border);
    box-shadow: none;
}
.hw-tool-btn:not(.active):not(:disabled):hover { background: var(--demo-tool-bg-hover); }

.demo-loading { display: flex; align-items: center; justify-content: center; height: 100%; margin: 0; color: var(--text-muted); font-size: 15px; }

/* light / dark switch: just the icon */
.demo-theme-toggle {
    display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0;
    border: 0; border-radius: 8px; background: transparent; color: var(--text-muted); cursor: pointer;
}
.demo-theme-toggle:hover { color: var(--text-accent); }
.demo-theme-toggle:focus-visible { outline: 2px solid var(--interactive-accent); outline-offset: 1px; }
.demo-theme-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (max-width: 600px) {
    .demo-btn { width: 38px; min-height: 36px; padding: 0; }
    .demo-theme-toggle { width: 30px; }
}
@media (max-width: 480px) { .demo-badge { display: none; } }
@media (max-width: 380px) {
    .demo-btn { width: 34px; }
    .demo-bar { gap: 2px; }
}
