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

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'MS Sans Serif', 'Segoe UI', sans-serif;
    background: #c0c0c0;
    padding: 10px;
    height: 100%;
    overflow: hidden;
    /* Prevent layout shift during font loading */
    visibility: visible;
}

@media (max-width: 768px) {
    body {
        padding: 0;
    }
}

.app-container {
    display: flex;
    height: calc(100% - 20px);
    max-height: calc(100% - 20px);
    gap: 10px;
    max-width: 1400px;
    margin: 0 auto;
    box-sizing: border-box;
    overflow: hidden;
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column-reverse;
        height: 100%;
        max-height: 100%;
        gap: 0;
    }
}

.toolbar {
    background: #c0c0c0;
    border: 2px solid #808080;
    padding: 10px;
    width: 220px;
    min-width: 220px;
    max-width: 220px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .toolbar {
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        max-height: 40vh;
        border-left: none;
        border-right: none;
        border-bottom: none;
        border-top: 2px solid #808080;
        padding: 8px;
        gap: 10px;
    }
}

.tool-group {
    padding: 8px;
    background: #c0c0c0;
}

.tool-group:not(:first-child) {
    border-top: 1px solid #808080;
    padding-top: 15px;
    margin-top: 0;
}

.tool-group h3 {
    font-size: 11px;
    font-weight: bold;
    margin-bottom: 8px;
    color: #000;
}

.tools {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
}

.tool-btn {
    background: #c0c0c0;
    border: 2px solid #808080;
    padding: 8px;
    cursor: pointer;
    font-size: 16px;
    min-height: 40px;
    height: 40px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
    touch-action: manipulation;
}

@media (max-width: 768px) {
    .tool-btn {
        min-height: 44px;
        height: 44px;
        padding: 10px;
    }
}

.tool-btn:hover {
    background: #d4d0c8;
}

.tool-btn:active {
    border: 2px solid #808080;
    background: #a0a0a0;
}

.tool-btn.active {
    border: 2px solid #808080;
    background: #a0a0a0;
}

.tool-btn .icon {
    display: block;
    font-size: 24px;
    line-height: 1;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

#brushSize {
    width: 100%;
    margin: 5px 0;
}

#sizeDisplay {
    display: block;
    text-align: center;
    font-size: 11px;
    margin-top: 3px;
}

#colorPicker {
    width: 100%;
    height: 40px;
    border: 2px solid #808080;
    cursor: pointer;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 5px;
    width: 100%;
    box-sizing: border-box;
}

.zoom-btn {
    background: #c0c0c0;
    border: 2px solid #808080;
    padding: 2px 4px;
    cursor: pointer;
    font-size: 14px;
    min-width: 24px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.zoom-btn:hover {
    background: #d4d0c8;
}

.zoom-btn:active {
    border: 2px solid #808080;
    background: #a0a0a0;
}

.zoom-btn .icon {
    font-size: 16px;
    line-height: 1;
}

#zoomSlider {
    flex: 1;
    min-width: 0;
}

#zoomDisplay {
    display: block;
    text-align: center;
    font-size: 11px;
    margin-top: 3px;
}

.action-btn {
    width: 100%;
    padding: 8px;
    margin: 3px 0;
    background: #c0c0c0;
    border: 2px solid #808080;
    cursor: pointer;
    font-size: 11px;
    font-weight: bold;
    touch-action: manipulation;
}

@media (max-width: 768px) {
    .action-btn {
        padding: 12px;
        min-height: 44px;
        font-size: 13px;
    }
}

.action-btn:hover {
    background: #d4d0c8;
}

.action-btn:active {
    border: 2px solid #808080;
    background: #a0a0a0;
}

.canvas-container {
    flex: 1;
    background: #c0c0c0;
    border: 2px solid #808080;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    position: relative;
    box-sizing: border-box;
    min-width: 0;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    touch-action: none;
}

@media (max-width: 768px) {
    .canvas-container {
        flex: 1;
        min-height: 0;
        padding: 5px;
    }
}

.canvas-wrapper {
    position: relative;
    display: inline-block;
    transform-origin: center center;
    margin: 0;
    padding: 0;
    /* Prevent layout shift by setting minimum dimensions */
    min-width: 100px;
    min-height: 100px;
}

#canvas {
    background: #ffffff;
    border: 1px solid #000;
    cursor: none;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    display: block;
    margin: 0;
    padding: 0;
    /* Prevent layout shift - canvas will be sized by JS but container reserves space */
    min-width: 100px;
    min-height: 100px;
}

.cursor-indicator {
    position: fixed;
    pointer-events: none;
    border: 1px solid rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    display: none;
    z-index: 10;
}

.cursor-indicator.visible {
    display: block;
}

.cursor-indicator.brush {
    border-color: rgba(0, 0, 0, 0.5);
}

.cursor-indicator.eraser {
    border-color: rgba(0, 0, 0, 0.5);
}

.cursor-indicator.shape {
    border: none;
    border-radius: 0;
    width: 20px;
    height: 20px;
}

.cursor-indicator.shape::before,
.cursor-indicator.shape::after {
    content: '';
    position: absolute;
    background: rgba(0, 0, 0, 0.5);
}

.cursor-indicator.shape::before {
    width: 2px;
    height: 100%;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

.cursor-indicator.shape::after {
    width: 100%;
    height: 2px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
}

.cursor-indicator.fill {
    border: none;
    border-radius: 0;
    width: 24px;
    height: 24px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cursor-indicator.fill::before {
    content: 'format_color_fill';
    font-family: 'Material Symbols Outlined';
    font-size: 24px;
    line-height: 1;
    color: currentColor;
    filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.8)) drop-shadow(0 0 1px rgba(255, 255, 255, 0.8));
}

/* Modal Styles */
.modal {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: #c0c0c0;
    border: 2px solid #808080;
    min-width: 300px;
    max-width: 400px;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 140px;
}

.modal-body {
    padding: 16px;
    font-size: 13px;
    color: #000;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.modal-body p {
    margin: 0;
}

.modal-footer {
    padding-bottom: 16px;
    display: flex;
    justify-content: center;
    gap: 8px;
}

.modal-btn {
    background: #c0c0c0;
    border: 2px solid #808080;
    padding: 4px 16px;
    cursor: pointer;
    font-size: 11px;
    font-weight: bold;
    min-width: 75px;
}

.modal-btn:hover {
    background: #d4d0c8;
}

.modal-btn:active {
    border: 2px solid #808080;
    background: #a0a0a0;
}

.modal-btn-primary {
    background: #c0c0c0;
}

