.m4-scratchboard-surface {
    position: absolute;
    inset: 0 auto auto 0;
    z-index: 9000;
    display: block;
    max-width: none;
    max-height: none;
    pointer-events: none;
    background: transparent;
    overflow: hidden;
}

.m4-scratchboard-surface[data-mode="pen"] { cursor: crosshair; }
.m4-scratchboard-surface[data-mode="eraser"] { cursor: cell; }

#m4-scratchboard {
    position: fixed;
    left: max(8px, env(safe-area-inset-left, 0px));
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    z-index: 9001;
    display: flex;
    align-items: center;
    gap: 5px;
    width: max-content;
    max-width: calc(100vw - 16px);
    color: #344054;
    font: 500 12px/1.2 system-ui, sans-serif;
}

#m4-scratchboard [hidden] { display: none !important; }

#m4-scratchboard-tools,
#m4-scratchboard button[data-tool="toggle"],
#m4-scratchboard .m4-scratchboard-notice {
    background: rgba(255, 255, 255, .92);
    border: 1px solid rgba(52, 64, 84, .22);
    box-shadow: 0 1px 4px rgba(22, 32, 53, .12);
}

#m4-scratchboard-tools {
    display: flex;
    align-items: center;
    gap: 1px;
    padding: 2px;
    border-radius: 10px;
}

#m4-scratchboard button {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 32px;
    height: 32px;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: inherit;
    font: inherit;
    text-decoration: none;
    transform: none;
    box-shadow: none;
    cursor: pointer;
    touch-action: manipulation;
}

#m4-scratchboard button[data-tool="toggle"] {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, .78);
}
#m4-scratchboard button[data-tool="off"] { width: auto; padding-inline: 6px; }
#m4-scratchboard button[aria-pressed="true"] { color: #17439c; background: #e0ecff; }
#m4-scratchboard button:not(:disabled):hover { background-color: #e8edf4; }
#m4-scratchboard button:focus-visible { outline: 2px solid #245db4; outline-offset: 2px; }
#m4-scratchboard button:disabled { opacity: .35; cursor: default; }

#m4-scratchboard button svg {
    display: block;
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.7;
    pointer-events: none;
}

#m4-scratchboard .m4-scratchboard-notice {
    position: absolute;
    bottom: calc(100% + 5px);
    left: 0;
    padding: 5px 8px;
    white-space: nowrap;
    border-radius: 6px;
}

#m4-scratchboard .m4-scratchboard-dot {
    display: block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(52, 64, 84, .35);
}

#m4-scratchboard-colors {
    position: absolute;
    bottom: calc(100% + 5px);
    left: 40px;
    display: flex;
    gap: 2px;
    padding: 3px;
    border-radius: 10px;
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(52, 64, 84, .22);
    box-shadow: 0 2px 8px rgba(22, 32, 53, .16);
}

#m4-scratchboard-colors button {
    width: 28px;
    height: 28px;
}

#m4-scratchboard-colors button::before {
    content: "";
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--m4-swatch);
}

#m4-scratchboard-colors button[aria-pressed="true"] { background: #e0ecff; }
#m4-scratchboard-colors button[aria-pressed="true"]::before {
    box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--m4-swatch);
}

@media (pointer: coarse) {
    #m4-scratchboard-colors button { width: 38px; height: 38px; }
    #m4-scratchboard-colors { left: 48px; }
    #m4-scratchboard button,
    #m4-scratchboard button[data-tool="toggle"] { width: 42px; height: 42px; }
    #m4-scratchboard button[data-tool="off"] { width: auto; }
}

@media print {
    #m4-scratchboard,
    .m4-scratchboard-surface { display: none !important; }
}
