* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    overflow: hidden;
    background: #f8fafc;
    color: #333;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 400px;
    border-radius: 8px;
    text-align: center;
}

.modal-content h2 {
    margin-top: 0;
}

.modal-content button {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    background-color: #4CAF50;
    color: white;
    cursor: pointer;
}

.modal-content button:hover {
    background-color: #45a049;
}

.error-message {
    color: red;
    margin-bottom: 15px;
    display: none;
}

#top-header {
    display: none;
}

#canvas {
    display: block;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    cursor: grab;
    background: #ffffff;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

#canvas:active {
    cursor: grabbing;
}

#toolbar {
    position: fixed;
    bottom: 0;
    left: 50%;
    width: fit-content;
    max-width: calc(100vw - 260px);
    max-height: 156px;
    margin: 0;
    transform: translateX(-50%);
    background: #fff;
    border: 1px solid #e5e7eb;
    border-bottom: 0;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 10px 32px rgba(15, 23, 42, 0.12);
    z-index: 1300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 16px;
    padding: 14px 22px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
    -webkit-user-select: none;
    user-select: none;
}

.toolbar-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    align-self: center;
}

.icon-btn {
    background: #fff;
    color: #007bff;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    margin: 0 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
    cursor: pointer;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.icon-btn:hover,
.icon-btn:focus {
    background: #007bff;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0,123,255,0.12);
    outline: none;
}

#toolbar .toolbar-actions .icon-btn {
    width: 44px;
    height: 44px;
    margin: 0;
    flex: 0 0 44px;
    background: #fff;
    color: #1976f3;
    border: 0;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.1);
    font-size: 1.15em;
}

.toolbar-actions-popover {
    position: fixed;
    z-index: 5400;
    display: none;
    min-width: 220px;
    box-sizing: border-box;
    padding: 8px;
    border: 1px solid #dbe3ee;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.16);
}

.toolbar-actions-popover.is-open {
    display: block;
}

.toolbar-action-menu-item {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #1f2937;
    padding: 10px 12px;
    font: 700 14px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    text-align: left;
    cursor: pointer;
    touch-action: manipulation;
}

.toolbar-action-menu-item i {
    width: 20px;
    color: #007bff;
    text-align: center;
    font-size: 1.05em;
}

.toolbar-action-menu-item:hover,
.toolbar-action-menu-item:focus-visible {
    background: #eef6ff;
    outline: none;
}

.toolbar-item {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    cursor: grab;
    min-width: 76px;
    padding: 8px 8px 6px;
    border-radius: 8px;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    user-select: none;
    position: relative;
    touch-action: none;
}

.toolbar-item::before {
    content: '';
    position: absolute;
    top: 36px;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #f3f6fb;
    pointer-events: none;
    z-index: 0;
}

.toolbar-item:hover {
    background: #eef6ff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.toolbar-item:active {
    cursor: grabbing;
    transform: scale(0.95);
}

.toolbar-item img {
    width: 60px;
    height: 60px;
    pointer-events: none;
    image-rendering: crisp-edges;
    position: relative;
    z-index: 1;
    filter: drop-shadow(0 2px 5px rgba(15, 23, 42, 0.12));
}

.toolbar-item span {
    color: #516579;
    font: 700 15px/1.1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    pointer-events: none;
    text-align: center;
    position: relative;
    z-index: 1;
}

.dragging {
    cursor: grabbing !important;
}

.dragging .toolbar-item:not(.dragging-item) {
    opacity: 0.5;
}

.dreyfous-annotation-layer {
    z-index: 5100;
}

@media (min-width: 761px) and (max-width: 1100px) {
    body.dreyfous-shell-enabled #toolbar {
        max-width: calc(100vw - 24px);
    }
}

@media (max-width: 760px) {
    #toolbar {
        width: fit-content;
        max-width: calc(100vw - 24px);
        gap: 12px;
        padding: 12px 14px 10px;
    }

    .toolbar-item {
        min-width: 68px;
        padding-inline: 6px;
    }

    .toolbar-item img {
        width: 54px;
        height: 54px;
    }

    .toolbar-item::before {
        width: 58px;
        height: 58px;
        top: 33px;
    }

    .toolbar-item span {
        font-size: 13px;
    }

}
