@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600&family=Dancing+Script:wght@400;500;600;700&family=Inter:wght@400;500;600&family=Mali:wght@400;500;600&family=Noto+Sans:wght@400;500;600&family=Noto+Serif:wght@400;500;600&family=Nunito:wght@400;500;600&family=Roboto:wght@400;500;700&display=swap');

:root {
    --primary: #5c5cff;
    --canvas-bg: #ffffff;
    --grid-color: #e5e5e5;
    --panel-bg: #e8eef6;
    --panel-border: #c7d3e3;
    --text-main: #333333;
    --text-muted: #6b7280;
    --hover-bg: #d9e4f2;
    --shadow-sm: 0 2px 5px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.12);
    --input-bg: #f7f9fc;
}

body.dark-mode {
    --primary: #7676ff;
    --panel-bg: #1e1e1e;
    --panel-border: #333333;
    --text-main: #e0e0e0;
    --text-muted: #9e9e9e;
    --hover-bg: #2d2d2d;
    --input-bg: #2a2a2a;
}

/* Theme màu giấy định nghĩa sẵn cố định lớp tương phản mờ */
body.paper-yellow {
    --canvas-bg: #FFF9C4;
    --grid-color: rgba(230, 224, 170, 0.6);
}

body.paper-blue {
    --canvas-bg: #E3F2FD;
    --grid-color: rgba(187, 222, 251, 0.6);
}

body.paper-green {
    --canvas-bg: #1B5E20;
    --grid-color: rgba(43, 117, 48, 0.4);
}

body.paper-black {
    --canvas-bg: #000000;
    --grid-color: rgba(34, 34, 34, 0.7);
}


* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    overflow: hidden;
    background-color: var(--canvas-bg);
    color: var(--text-main);
    transition: 0.3s;
}

.canvas-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    touch-action: none;
}

#main-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
}

.canvas-text-editor {
    position: fixed;
    z-index: 2000;
    min-width: 24px;
    min-height: 30px;
    resize: none;
    overflow: hidden;
    white-space: pre;
    border: 1.5px solid var(--primary);
    outline: none;
    padding: 8px;
    background: rgba(255, 255, 255, 0.92);
    color: #111111;
    caret-color: var(--primary);
    pointer-events: auto;
    box-shadow: var(--shadow-sm);
    tab-size: 4;
}

.canvas-text-editor *,
.canvas-text-editor font {
    font-family: inherit !important;
}

.canvas-text-editor.note-editor {
    min-width: 220px;
    min-height: 106px;
    resize: none;
}

.note-resize-handle {
    position: fixed;
    z-index: 2002;
    width: 10px;
    height: 10px;
    background: #5c5cff;
    border: 1.5px solid #ffffff;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
    transform: translate(-50%, -50%);
    pointer-events: auto;
    transition: transform 0.12s ease, background 0.12s ease;
}

.note-resize-handle:hover {
    transform: translate(-50%, -50%) scale(1.3);
    background: #3c3cff;
}

.note-resize-handle.nw { cursor: nwse-resize; }
.note-resize-handle.ne { cursor: nesw-resize; }
.note-resize-handle.sw { cursor: nesw-resize; }
.note-resize-handle.se { cursor: nwse-resize; }

.note-editor-header {
    position: fixed;
    z-index: 2001;
    min-width: 220px;
    height: 34px;
    border: 1px solid rgba(0, 0, 0, 0.14);
    border-bottom: none;
    pointer-events: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 8px;
    box-shadow: var(--shadow-sm);
    cursor: move;
}

.note-editor-action {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border: 1px solid rgba(0, 0, 0, 0.22);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.72);
    color: #111111;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    transition: transform 0.08s ease, background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.note-editor-action:hover {
    background: rgba(255, 255, 255, 0.94);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}

.note-editor-action:active {
    transform: translateY(0) scale(0.94);
}

.note-editor-action.active {
    background: rgba(92, 92, 255, 0.22);
    border-color: var(--primary);
    color: var(--primary);
}

.ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.ui-layer>* {
    pointer-events: auto;
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-sm);
}


/* =========================================
   UI COMPONENTS & ANIMATIONS
========================================= */

/* --- SIDEBAR PANEL --- */
.sidebar {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    gap: 8px;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
}

.tool-btn {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-main);
    font-size: 15px;
    cursor: pointer;
    transition: 0.2s;
}

.tool-btn:hover {
    background: var(--hover-bg);
}

.tool-btn.keyboard-selected:not(.active) {
    background: var(--hover-bg);
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.tool-btn.active {
    background: var(--primary);
    color: white;
}

.shape-tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.shape-tool-text {
    color: currentColor;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0;
    line-height: 1;
}

.divider {
    width: 60%;
    height: 1px;
    background: var(--panel-border);
    margin: 4px 0;
}

.shape-submenu {
    position: absolute;
    left: 75px;
    top: 50%;
    transform: translateY(-50%) translateX(-8px);
    width: 52px;
    border-radius: 10px;
    padding: 8px 0;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.16s ease, transform 0.16s ease;
    z-index: 90;
}

.shape2d-library {
    width: 396px;
    max-height: min(620px, calc(100vh - 32px));
    padding: 10px;
    display: none;
    grid-template-columns: repeat(4, 1fr);
    align-items: stretch;
    overflow-y: auto;
    gap: 8px;
}

.shape3d-library {
    width: 300px;
    max-height: min(620px, calc(100vh - 32px));
    padding: 10px;
    display: none;
    grid-template-columns: repeat(3, 1fr);
    align-items: stretch;
    overflow-y: auto;
    gap: 8px;
}

.shape3d-library .shape-menu-item {
    width: auto;
    height: 66px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 5px 2px;
    background: rgba(92, 92, 255, 0.04);
    border: 1px solid var(--panel-border);
    font-size: 9.2px;
    line-height: 1.05;
    text-align: center;
    border-radius: 8px;
    transition: 0.2s;
}

.shape3d-library .shape-menu-item span {
    display: -webkit-box;
    max-width: 100%;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    word-break: keep-all;
    overflow-wrap: break-word;
}

.shape-submenu.show {
    display: flex;
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.shape2d-library.show,
.shape3d-library.show {
    display: grid;
}

.shape-menu-item {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    transition: 0.2s;
}

.shape2d-library .shape-menu-item {
    width: auto;
    height: 66px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 5px 2px;
    background: rgba(92, 92, 255, 0.04);
    border: 1px solid var(--panel-border);
    font-size: 9.2px;
    line-height: 1.05;
    text-align: center;
}

.shape2d-library .shape-menu-item span {
    display: -webkit-box;
    max-width: 100%;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    word-break: keep-all;
    overflow-wrap: break-word;
}

.shape-menu-icon {
    width: 39px;
    height: 27px;
    overflow: visible;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.shape-menu-item:hover,
.shape-menu-item:focus-visible,
.shape-menu-item.active {
    background: var(--hover-bg);
    color: var(--primary);
    outline: none;
}

.shape-menu-item.keyboard-selected {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.shape-menu-item.keyboard-selected:not(.active) {
    background: var(--hover-bg);
    color: var(--primary);
}

.shape2d-library .shape-menu-item:hover,
.shape2d-library .shape-menu-item:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

.active-shape-indicator {
    min-width: auto;
    display: inline-flex;
    align-items: center;
    color: var(--primary);
    white-space: nowrap;
}

.active-shape-indicator .shape-menu-icon {
    width: 34px;
    height: 24px;
}

#tb-shape .shape-snap-toggle {
    width: 38px;
    min-width: 38px;
}

.hidden-control {
    display: none !important;
}

#tb-shape .shape-fill-colors .custom-color,
#tb-shape .shape-stroke-colors .custom-color {
    display: inline-block;
}

@media (max-width: 1360px) {
    #tb-shape .shape-fill-colors .color-dot {
        display: none;
    }

    #tb-shape .shape-fill-opacity input[type="range"] {
        display: none;
    }

}

@media (max-width: 1240px) {
    #tb-shape.active {
        gap: 9px;
    }

    #tb-shape .control-divider {
        margin: 0 1px;
    }

    #tb-shape .shape-size-control input[type="range"] {
        display: none;
    }
}

@media (max-width: 1280px) {
    #tb-shape .shape-stroke-colors .color-dot {
        display: none;
    }
}

@media (max-width: 760px) {
    .shape2d-library {
        width: 210px;
        grid-template-columns: 1fr;
    }

    .shape2d-library .shape-menu-item {
        height: 34px;
        flex-direction: row;
        justify-content: flex-start;
        padding: 0 10px;
        font-size: 12px;
    }

    .shape2d-library .shape-menu-icon {
        display: none;
    }
}

/* --- CONTEXTUAL TOPBAR (PROPERTY MENU) --- */
.topbar {
    position: absolute;
    top: 15px;
    left: 80px;
    border-radius: 10px;
    padding: 8px 15px 8px 8px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;

    min-height: 48px;
    width: fit-content;
    max-width: calc(100vw - 110px);
    max-height: calc(100vh - 30px);
    overflow: visible;
    box-sizing: border-box;
}

.topbar.hidden {
    display: none;
    pointer-events: none;
}

/* Trạng thái thu gọn */
.topbar.collapsed {
    width: 48px;
    height: 48px;
    padding-right: 8px;
    overflow: hidden;
}

/* Nút bấm thu gọn */
.toggle-topbar-btn {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-main);
    transition: 0.2s;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.toggle-topbar-btn:hover {
    background: var(--hover-bg);
}

/* Vùng chứa nội dung bên trong thanh Topbar */
.topbar-inner {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    white-space: normal;
    flex-wrap: wrap;
}

.topbar.collapsed .topbar-inner {
    pointer-events: none;
    display: none;
}

.tb-content {
    display: none;
    align-items: center;
    gap: 15px;
    min-width: 0;
    flex-wrap: wrap;
    row-gap: 8px;
    max-width: 100%;
}

.tb-content.active {
    display: flex;
}

#tb-shape.active {
    gap: 12px;
    align-items: center;
}

#tb-shape .control-group,
#tb-shape .range-group,
#tb-shape .ui-checkbox,
#tb-shape .creation-mode-control {
    flex-wrap: nowrap;
    white-space: nowrap;
}

#tb-shape .range-group input[type="number"] {
    flex-shrink: 0;
}

.topbar.is-wrapping .control-divider {
    display: none;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.control-divider {
    width: 1px;
    height: 24px;
    background: var(--panel-border);
    margin: 0 4px;
    flex-shrink: 0;
}

.color-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    flex-shrink: 0;
}

.color-dot.active {
    border-color: var(--primary);
    transform: scale(1.1);
}

.color-dot.transparent-dot {
    background:
        linear-gradient(45deg, rgba(120, 120, 120, 0.35) 25%, transparent 25% 75%, rgba(120, 120, 120, 0.35) 75%),
        linear-gradient(45deg, rgba(120, 120, 120, 0.35) 25%, transparent 25% 75%, rgba(120, 120, 120, 0.35) 75%);
    background-color: #ffffff;
    background-position: 0 0, 6px 6px;
    background-size: 12px 12px;
}

.custom-color {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: linear-gradient(135deg, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #8b00ff) !important;
    flex-shrink: 0;
}

.custom-color::-webkit-color-swatch-wrapper {
    padding: 0 !important;
}

.custom-color::-webkit-color-swatch {
    border: none !important;
    border-radius: inherit !important;
    background: transparent !important;
}

.custom-color::-moz-color-swatch {
    border: none !important;
    border-radius: inherit !important;
    background: transparent !important;
}

.inline-color-popover {
    position: fixed;
    z-index: 2500;
    width: 220px;
    padding: 10px;
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    background: var(--panel-bg);
    box-shadow: var(--shadow-md);
}

.inline-color-sv {
    position: relative;
    height: 120px;
    border-radius: 8px;
    overflow: hidden;
    cursor: crosshair;
    background:
        linear-gradient(to top, #000, transparent),
        linear-gradient(to right, #fff, transparent),
        hsl(var(--picker-hue, 0), 100%, 50%);
}

.inline-color-cursor {
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.inline-color-hue {
    width: 100%;
    height: 16px;
    margin-top: 10px;
    border-radius: 999px;
    appearance: none;
    background: linear-gradient(to right, red, yellow, lime, cyan, blue, magenta, red);
}

.inline-color-hue::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: hsl(var(--picker-hue, 0), 100%, 50%);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.inline-color-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 10px;
}

.inline-color-preview {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--panel-border);
    flex-shrink: 0;
}

.inline-color-hex {
    min-width: 0;
    flex: 1;
    height: 30px;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 0 8px;
    background: var(--input-bg);
    color: var(--text-main);
    font: 600 12px Inter, sans-serif;
}

.shape-fill-style-picker {
    position: relative;
    flex-shrink: 0;
}

.shape-fill-style-trigger {
    width: 36px;
    height: 32px;
    border: none;
    border-radius: 9px;
    background: var(--hover-bg);
    color: var(--text-main);
    cursor: pointer;
}

.shape-fill-style-trigger:hover,
.shape-fill-style-picker.open .shape-fill-style-trigger {
    color: var(--primary);
}

.shape-fill-style-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    display: none;
    min-width: 138px;
    padding: 6px;
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    background: var(--panel-bg);
    box-shadow: var(--shadow-md);
    z-index: 120;
}

.shape-fill-style-picker.open .shape-fill-style-menu {
    display: grid;
    gap: 3px;
}

.shape-fill-style-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 30px;
    border: none;
    border-radius: 7px;
    padding: 0 8px;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    font: 600 12px Inter, sans-serif;
    text-align: left;
}

.shape-fill-style-menu button:hover,
.shape-fill-style-menu button.active {
    background: var(--hover-bg);
    color: var(--primary);
}

.range-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.range-group input[type="range"] {
    width: 70px;
}

.range-group input[type="number"] {
    width: 52px;
    padding: 2px 5px;
    border-radius: 4px;
    border: 1px solid var(--panel-border);
    text-align: center;
    background: var(--input-bg);
    color: var(--text-main);
}

.font-size-group input[type="number"] {
    width: 64px;
}

.ui-select {
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--panel-border);
    background: var(--input-bg);
    color: var(--text-main);
    outline: none;
}

.control-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    white-space: nowrap;
}

.point-style-select {
    min-width: 132px;
    height: 30px;
}

.ui-checkbox {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    cursor: pointer;
}

/* --- SEGMENTED CONTROLS --- */
.btn-group {
    display: inline-flex;
    background: var(--hover-bg);
    padding: 3px;
    border-radius: 10px;
    gap: 2px;
    align-items: center;
    flex-shrink: 0;
}

.eraser-mode-group {
    flex-wrap: wrap;
    flex-shrink: 1;
    max-width: 100%;
}

.btn-group button {
    padding: 6px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 7px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-group button:hover {
    color: var(--text-main);
}

.btn-group button.active {
    background: #e0e7ff;
    color: #4f46e5;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

body.dark-mode .btn-group button.active {
    background: #3730a3;
    color: #e0e7ff;
}

/* --- BOTTOM-RIGHT ICONS (SETTINGS CLUSTER) --- */
.bottom-right {
    position: absolute;
    bottom: 15px;
    right: 15px;
    display: flex;
    gap: 8px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    border: 1px solid var(--panel-border);
    background: var(--panel-bg);
    cursor: pointer;
    color: var(--text-main);
    transition: 0.2s;
    font-size: 16px;
}

.icon-btn:hover {
    background: var(--hover-bg);
}

.icon-btn.active {
    background: var(--primary);
    color: white;
}

#btn-random-close,
#btn-graph-close {
    color: #ef4444;
}

#btn-random-close:hover,
#btn-graph-close:hover {
    background: #ef4444 !important;
    color: #ffffff !important;
    border-color: #ef4444 !important;
}

.applications-panel {
    position: absolute;
    right: 15px;
    bottom: 66px;
    width: 300px;
    max-width: calc(100vw - 30px);
    display: none;
    padding: 14px;
    z-index: 110;
}

.applications-panel.show {
    display: block;
}

.app-list {
    display: grid;
    gap: 10px;
}

.app-row {
    display: grid;
    grid-template-columns: 32px 1fr 24px;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-main);
    cursor: pointer;
    font: 700 14px Inter, sans-serif;
    padding: 0 12px;
    text-align: left;
}

.app-row:hover {
    background: var(--hover-bg);
}

.app-row i:first-child {
    color: var(--primary);
}

.app-row i:last-child {
    justify-self: end;
    color: var(--text-muted);
    font-size: 12px;
}

.random-app-window {
    width: min(1180px, calc(100vw - 140px));
    height: min(820px, calc(100vh - 66px));
    min-width: 360px;
    min-height: 300px;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 12px;
    border-radius: 8px;
    resize: both;
    overflow: hidden;
}

.random-app-frame {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: var(--panel-bg);
}

.timer-app-window {
    width: 560px;
    height: 250px;
    min-width: 560px;
    min-height: 250px;
    max-width: 560px;
    max-height: 250px;
    display: block;
    padding: 0;
    resize: none;
    overflow: hidden;
    background: var(--panel-bg);
    border-radius: 8px;
}

.timer-app-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: transparent;
    display: block;
}

/* --- BOTTOM-LEFT CONTROLS (ZOOM) --- */
.bottom-left {
    position: absolute;
    bottom: 15px;
    left: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 50;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.context-hint {
    max-width: min(460px, calc(100vw - 380px));
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
    line-height: 1.35;
    opacity: 0;
    transform: translateX(-6px);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
    white-space: normal;
}

.context-hint.show {
    opacity: 0.78;
    transform: translateX(0);
}

.pill-group {
    border-radius: 8px;
    display: flex;
    align-items: center;
    padding: 4px;
    position: relative;
}

.pill-group button {
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-main);
    transition: 0.2s;
}

.pill-group button:hover {
    background: var(--hover-bg);
}

.eraser-cursor {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1800;
    width: 0;
    height: 0;
    border: 1.5px solid #5c5cff;
    background: rgba(92, 92, 255, 0.08);
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -50%);
    transition: opacity 0.08s ease;
    will-change: transform, width, height;
}

.eraser-cursor.show {
    opacity: 1;
}

.eraser-cursor.circle {
    border-radius: 50%;
}

.eraser-cursor.square {
    border-radius: 3px;
}

.eraser-cursor.stroke {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.10);
}

.eraser-cursor.gap {
    border-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.08);
    border-style: dashed;
}

.pill-group button.shortcut-flash {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 0 4px rgba(92, 92, 255, 0.18);
}

.pill-group span {
    font-size: 13px;
    font-weight: 600;
    padding: 0 10px;
    cursor: pointer;
    user-select: none;
}

.pill-group span:hover {
    color: var(--primary);
}

.zoom-menu {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    border-radius: 8px;
    padding: 6px 0;
    display: none;
    flex-direction: column;
    z-index: 60;
}

.zoom-menu.show {
    display: flex;
}

.zoom-menu div {
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: 0.2s;
}

.zoom-menu div:hover {
    background: var(--hover-bg);
    color: var(--primary);
}

.object-context-menu {
    position: fixed;
    z-index: 2600;
    display: flex;
    flex-direction: column;
    min-width: 210px;
    padding: 6px;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
}

.object-context-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 34px;
    border: none;
    border-radius: 6px;
    padding: 0 10px;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
}

.object-context-item i {
    width: 16px;
    text-align: center;
    color: var(--text-muted);
}

.object-context-item:hover,
.object-context-item:focus-visible {
    background: var(--hover-bg);
    color: var(--primary);
    outline: none;
}

.object-context-item:hover i,
.object-context-item:focus-visible i {
    color: var(--primary);
}

.object-context-item:disabled {
    cursor: default;
    color: var(--text-muted);
    opacity: 0.45;
}

.object-context-item:disabled:hover {
    background: transparent;
    color: var(--text-muted);
}

.object-context-item:disabled i {
    color: var(--text-muted);
}

.object-context-separator {
    height: 1px;
    margin: 5px 4px;
    background: var(--panel-border);
}

.object-context-shortcut {
    margin-left: auto;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    opacity: 0.65;
    padding-left: 10px;
}

/* --- SETTINGS MENU --- */
.settings-menu {
    position: absolute;
    bottom: 65px;
    top: auto;
    right: 15px;
    transform-origin: bottom right;
    width: 300px;
    border-radius: 12px;
    padding: 20px;
    display: none;
    flex-direction: column;
    gap: 20px;
    z-index: 100;
}

.settings-menu.show {
    display: flex;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.action-grid button {
    background: transparent;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    height: 44px;
    color: var(--text-main);
    cursor: pointer;
    transition: 0.2s;
    font-size: 16px;
}

.action-grid button:hover {
    background: var(--hover-bg);
    border-color: var(--primary);
    color: var(--primary);
}

.toggle-flex {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.modern-toggle {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: 0.2s;
}

.modern-toggle:hover {
    background: var(--hover-bg);
}

.modern-toggle.active {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(92, 92, 255, 0.08);
}

.creation-mode-control {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.creation-mode-control span {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
}

#tb-shape .creation-mode-control > span {
    display: none;
}

.creation-mode-control .btn-group button {
    width: 34px;
    min-width: 34px;
}

.grid-btn {
    background: transparent;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    height: 44px;
    cursor: pointer;
    color: var(--text-main);
    font-size: 18px;
    transition: 0.2s;
}

.grid-btn:hover {
    background: var(--hover-bg);
}

.grid-btn.active {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(92, 92, 255, 0.05);
}

.paper-colors {
    display: flex;
    gap: 12px;
    align-items: center;
}

.p-color.circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--panel-border);
    cursor: pointer;
    transition: transform 0.2s;
}

.p-color.circle:hover {
    transform: scale(1.1);
}

.custom-color.square {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--panel-border);
    padding: 0;
    cursor: pointer;
}

/* --- MODAL WINDOWS --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.show {
    display: flex;
}

.modal-content {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    width: 400px;
    padding: 25px;
    box-shadow: var(--shadow-md);
}

.pdf-insert-modal {
    width: min(460px, calc(100vw - 32px));
    display: grid;
    gap: 14px;
}

.pdf-insert-modal h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.pdf-insert-modal p {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}

.pdf-insert-full,
.pdf-insert-custom,
.pdf-insert-cancel {
    min-height: 38px;
    border: none;
    border-radius: 8px;
    padding: 0 14px;
    cursor: pointer;
    font-weight: 700;
}

.pdf-insert-full,
.pdf-insert-custom {
    background: var(--primary);
    color: #ffffff;
}

.pdf-insert-cancel {
    background: var(--hover-bg);
    color: var(--text-main);
}

.pdf-insert-custom-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
}

.pdf-insert-input {
    min-width: 0;
    height: 38px;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 0 12px;
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 14px;
    outline: none;
}

.pdf-insert-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(92, 92, 255, 0.14);
}

.pdf-insert-error {
    min-height: 18px;
    color: #dc2626;
    font-size: 13px;
    font-weight: 600;
}

.pdf-insert-actions {
    display: flex;
    justify-content: flex-end;
}

.shortcuts-panel {
    width: min(680px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    overflow: auto;
    border-radius: 12px;
    padding: 22px;
    box-shadow: var(--shadow-md);
}

.shortcuts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.shortcuts-header h3 {
    font-size: 20px;
    font-weight: 600;
}

.shortcuts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px;
}

.shortcuts-grid h4 {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.shortcuts-grid p {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    margin: 0;
}

.shortcuts-grid p span {
    color: var(--text-main);
    font-size: 14px;
    margin-left: auto;
    text-align: right;
}

kbd {
    min-width: 28px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 12px;
    font-weight: 600;
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.08);
}

.btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-weight: 500;
}

.btn-insert {
    background: var(--primary);
    color: white;
}


/* =========================================
   RESPONSIVE DESIGN & ZEN MODE
========================================= */

/* Trượt cụm Zoom qua phải để tránh đè Sidebar khi màn hình nhỏ */
@media (max-width: 768px),
(max-height: 680px) {
    .bottom-left {
        left: 80px;
    }
}

@media (max-width: 520px) {
    .topbar {
        left: 70px;
        max-width: calc(100vw - 84px);
    }

    .control-divider {
        display: none;
    }

    .range-group input[type="range"] {
        width: 96px;
    }

    .context-hint {
        display: none;
    }
}

/* CLASS ZEN MODE (Trượt mượt các UI ra khỏi màn hình) */
body.zen-mode .sidebar {
    transform: translate(-100px, -50%);
    opacity: 0;
    pointer-events: none;
}

body.zen-mode .shape-submenu {
    transform: translateY(-50%) translateX(-100px);
    opacity: 0;
    pointer-events: none;
}

body.zen-mode .bottom-left {
    transform: translateY(100px);
    opacity: 0;
    pointer-events: none;
}

body.zen-mode .bottom-right {
    transform: translateY(100px);
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 640px) {
    .shortcuts-grid {
        grid-template-columns: 1fr;
    }
}

/* --- FOUNTAIN PEN SETTINGS POPOVER --- */
.fountain-settings-popover {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 16px;
    width: 280px;
    box-shadow: var(--shadow-lg);
    font-family: 'Inter', sans-serif;
    color: var(--text-main);
    z-index: 2100;
}

.fountain-settings-popover input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: var(--panel-border);
    outline: none;
    border-radius: 4px;
    height: 4px;
}

.fountain-settings-popover input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    transition: transform 0.1s;
}

.fountain-settings-popover input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.fountain-settings-popover input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    transition: transform 0.1s;
}

.fountain-settings-popover input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.2);
}

.settings-menu input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: var(--panel-border);
    outline: none;
    border-radius: 4px;
    height: 4px;
    width: 100%;
}

.settings-menu input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    transition: transform 0.1s;
}

.settings-menu input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.settings-menu input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    transition: transform 0.1s;
}

.settings-menu input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.2);
}

/* --- CUSTOMIZE SHAPES MODAL --- */
#customize-shapes-modal .modal-content,
#customize-shapes3d-modal .modal-content {
    width: 440px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

#customize-shapes-modal .modal-body,
#customize-shapes3d-modal .modal-body {
    flex: 1;
    overflow-y: auto;
    margin: 15px 0;
    padding-right: 5px;
}

.modal-description {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 15px;
    line-height: 1.4;
}

.draggable-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.draggable-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--input-bg);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    cursor: grab;
    user-select: none;
    transition: background 0.2s, border-color 0.2s, opacity 0.2s;
}

.draggable-item:hover {
    background: var(--hover-bg);
    border-color: var(--primary);
}

.draggable-item.dragging {
    opacity: 0.5;
    background: var(--panel-border);
    cursor: grabbing;
}

.drag-handle {
    color: var(--text-muted);
    cursor: grab;
    font-size: 14px;
}

.draggable-item-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-main);
}

.draggable-item-content svg {
    width: 24px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    color: var(--primary);
}

.draggable-item-content circle[fill="currentColor"] {
    fill: var(--primary);
}

.draggable-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 12px;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.modal-close-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.modal-close-btn:hover {
    color: var(--primary);
}

.modal-footer {
    display: flex;
    justify-content: space-between;
    border-top: 1px solid var(--panel-border);
    padding-top: 12px;
    gap: 10px;
}

.modal-footer .btn {
    flex: 1;
    font-weight: 600;
    height: 38px;
    border-radius: 8px;
    font-size: 13px;
}

.modal-footer .btn-secondary {
    background: var(--hover-bg);
    color: var(--text-main);
    border: 1px solid var(--panel-border);
}

.modal-footer .btn-secondary:hover {
    background: var(--panel-border);
}

.modal-footer .btn-primary {
    background: var(--primary);
    color: white;
}

.modal-footer .btn-primary:hover {
    filter: brightness(1.1);
}

.draggable-item.drag-over {
    border: 2px dashed var(--primary);
    background: rgba(92, 92, 255, 0.04);
}

/* --- A4 WORKSPACE & PAGE NAVIGATION --- */
:root {
    --pasteboard-bg: #e9ecef;
}
body.dark-mode {
    --pasteboard-bg: #121212;
}

body.a4-mode .canvas-container {
    background-color: var(--pasteboard-bg);
}

.page-nav-bar {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 48px;
    padding: 0 16px;
    box-shadow: var(--shadow-md);
    transition: all 0.3s;
}

.page-manager-popover {
    position: absolute;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 110;
    width: 320px;
    padding: 16px;
    box-shadow: var(--shadow-lg);
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, transform 0.2s ease;
}

.page-manager-popover.grid-view {
    width: 480px;
    max-width: calc(100vw - 32px);
}

.page-manager-view-toggle button {
    border: none;
    background: transparent;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.page-manager-view-toggle button.active {
    background: var(--panel-bg);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.page-manager-view-toggle button:hover:not(.active) {
    color: var(--text-main);
    background: rgba(0, 0, 0, 0.05);
}

.dark-mode .page-manager-view-toggle button:hover:not(.active) {
    background: rgba(255, 255, 255, 0.05);
}

.page-manager-list {
    max-height: 240px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 2px;
}

.page-manager-list.grid-layout {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
    max-height: 340px;
}

.page-manager-grid-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    background: var(--input-bg);
    border: 1.5px solid var(--panel-border);
    border-radius: 8px;
    cursor: grab;
    user-select: none;
    transition: all 0.2s ease;
    gap: 6px;
}

.page-manager-grid-item:hover {
    background: var(--hover-bg);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.page-manager-grid-item.active {
    border-color: var(--primary);
    background: rgba(92, 92, 255, 0.05);
    box-shadow: 0 0 0 3px rgba(92, 92, 255, 0.15);
}

.page-manager-grid-item.dragging {
    opacity: 0.4;
    cursor: grabbing;
}

.page-manager-grid-item.drag-over {
    border: 2px dashed var(--primary);
    background: rgba(92, 92, 255, 0.08);
}

.page-manager-grid-thumbnail-container {
    width: 100%;
    aspect-ratio: 1 / 1.414; /* Default Portrait A4 aspect ratio */
    border-radius: 4px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.dark-mode .page-manager-grid-thumbnail-container {
    background: #1e1e1e;
}

.page-manager-grid-thumbnail {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.page-manager-grid-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.page-manager-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--input-bg);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    transition: all 0.2s;
}

.page-manager-item.active {
    border-color: var(--primary);
    background: rgba(92, 92, 255, 0.05);
}

.page-manager-item:hover {
    background: var(--hover-bg);
}

.page-manager-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    flex: 1;
}

.page-manager-item-actions {
    display: flex;
    gap: 4px;
}

.page-manager-action-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: 0.2s;
}

.page-manager-action-btn:hover {
    background: var(--hover-bg);
    color: var(--primary);
}

.page-manager-action-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Zen mode transitions */
body.zen-mode .page-nav-bar {
    transform: translate(-50%, 100px);
    opacity: 0;
    pointer-events: none;
}
body.zen-mode .page-manager-popover {
    transform: translate(-50%, 100px);
    opacity: 0;
    pointer-events: none;
}

/* Custom Premium A4 Scrollbar */
.a4-scrollbar-track {
    position: absolute;
    right: 12px;
    top: 80px;
    bottom: 20px;
    width: 8px;
    background: rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-radius: 4px;
    z-index: 99;
    display: none;
    transition: opacity 0.3s, transform 0.3s, background 0.2s, width 0.2s;
    user-select: none;
}
.dark-mode .a4-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}
.a4-scrollbar-track:hover {
    background: rgba(0, 0, 0, 0.08);
    width: 10px;
}
.dark-mode .a4-scrollbar-track:hover {
    background: rgba(255, 255, 255, 0.08);
}
.a4-scrollbar-thumb {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}
.dark-mode .a4-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.25);
}
.a4-scrollbar-thumb:hover, .a4-scrollbar-thumb.dragging {
    background: rgba(0, 0, 0, 0.4);
}
.dark-mode .a4-scrollbar-thumb:hover, .dark-mode .a4-scrollbar-thumb.dragging {
    background: rgba(255, 255, 255, 0.4);
}

/* Zen mode scrollbar transition */
body.zen-mode .a4-scrollbar-track {
    opacity: 0;
    pointer-events: none;
    transform: translateX(20px);
}

/* --- TEXT FORMAT DROPDOWN PICKER --- */
.text-format-picker {
    position: relative;
    flex-shrink: 0;
}

.text-format-trigger {
    width: 36px;
    height: 32px;
    border: none;
    border-radius: 9px;
    background: var(--hover-bg);
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.2s, color 0.2s;
}

.text-format-trigger:hover,
.text-format-picker.open .text-format-trigger {
    background: var(--primary-light, rgba(92, 92, 255, 0.1));
    color: var(--primary);
}

.text-format-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    display: none;
    padding: 8px;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    background: var(--panel-bg);
    box-shadow: var(--shadow-md);
    z-index: 120;
    gap: 8px;
    align-items: center;
}

.text-format-picker.open .text-format-menu {
    display: flex;
}

.text-format-menu .btn-group {
    background: var(--hover-bg);
    padding: 2px;
    border-radius: 8px;
    display: flex;
    gap: 2px;
    margin: 0;
    border: none;
}

/* --- A4 PAGE CONTROLS (ROTATION & SEAMLESS TOGGLE OVERLAYS) --- */
.a4-rotate-btn,
.a4-gap-toggle-btn {
    position: absolute;
    pointer-events: auto;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--panel-bg);
    border: 1.5px solid var(--panel-border);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200;
}

.a4-rotate-btn:hover,
.a4-gap-toggle-btn:hover {
    background: var(--hover-bg);
    color: var(--primary);
    transform: translate(-50%, -50%) scale(1.15) !important;
    border-color: var(--primary);
    box-shadow: 0 6px 12px rgba(92, 92, 255, 0.2);
}

.a4-gap-toggle-btn.seamless {
    color: var(--primary);
    background: rgba(92, 92, 255, 0.1);
    border-color: var(--primary);
}

.a4-layout-picker {
    display: none !important;
}
body.a4-mode .a4-layout-picker {
    display: flex !important;
}
