:root {
    --win-gray: #c0c0c0;
    --win-white: #ffffff;
    --win-shadow-dark: #404040;
    --win-shadow-light: #808080;
    --win-blue: #000080;
    --win-text: #000000;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: "Tahoma", "MS Sans Serif", sans-serif;
    font-size: 12px;
    -webkit-font-smoothing: none;
}

body {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Window Shell */
.win95-window {
    width: 90vw;
    height: 90vh;
    display: flex;
    flex-direction: column;
    background-color: var(--win-gray);
    position: relative;
}

.modal-window {
    width: 300px !important;
    height: auto !important;
}

.title-bar {
    padding: 3px 2px 3px 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.title-bar-text {
    display: flex;
    align-items: center;
    gap: 4px;
}

.title-icon {
    width: 16px;
    height: 16px;
}

.title-bar-controls {
    display: flex;
    gap: 2px;
}

.title-bar-controls button {
    width: 16px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Menu Bar */
.menu-bar {
    display: flex;
    padding: 1px 2px;
    position: relative;
    z-index: 100;
}

.menu-item-container { position: relative; }
.menu-item { padding: 2px 8px; cursor: default; }

.dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 120px;
    padding: 2px;
    background-color: var(--win-gray); /* Fallback */
    border: 1px solid var(--win-shadow-light); /* Fallback */
}

.menu-item-container:hover .dropdown,
.menu-item-container.active .dropdown { display: block; }
.menu-sub-item { padding: 3px 12px; cursor: default; white-space: nowrap; background-color: inherit; }

.menu-sub-item-container { position: relative; }
.menu-sub-item-container::after {
    content: "►";
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 8px;
}

.side-dropdown {
    display: none;
    position: absolute;
    top: -2px;
    left: 100%;
    min-width: 100px;
    padding: 2px;
    background-color: var(--win-gray); /* Fallback */
    border: 1px solid var(--win-shadow-light); /* Fallback */
}

.menu-sub-item-container:hover .side-dropdown,
.menu-sub-item-container.active .side-dropdown { display: block; }

/* Workspace */
.workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.toolbar-container {
    width: 60px;
    padding: 4px;
}

.toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
}

.tool-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    outline: none;
}

.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 20px;
}

.canvas-container {
    position: relative;
    background-color: white;
    cursor: crosshair;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    image-rendering: pixelated;
}

#canvas-lower { z-index: 1; }
#canvas-upper { z-index: 2; pointer-events: auto; }

/* Bottom Controls */
.bottom-controls {
    padding: 4px;
    display: flex;
    gap: 10px;
}

.palette-panel { display: flex; flex-direction: column; gap: 2px; }
.palette-tabs { display: flex; gap: 2px; }
.palette-tab { padding: 1px 6px; cursor: pointer; }
.palette-display { display: flex; gap: 8px; padding: 2px; }

.color-indicators { position: relative; width: 32px; height: 48px; }
.color-indicator { position: absolute; width: 20px; height: 20px; border: 1px solid black; }
.color-indicator.primary { top: 0; left: 0; z-index: 2; }
.color-indicator.secondary { top: 12px; left: 12px; z-index: 1; }

#color-swap {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 32px;
    height: 14px;
    font-size: 10px;
    padding: 0;
    cursor: pointer;
}

.palette-grid-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(16, 12px);
    grid-template-rows: repeat(2, 12px);
    gap: 1px;
}

#custom-color-btn {
    height: 18px;
    padding: 0 4px;
    font-size: 10px;
    align-self: flex-start;
}

.color-swatch { width: 12px; height: 12px; cursor: pointer; }
.zoom-panel { display: flex; align-items: center; gap: 4px; }

/* Status Bar */
.status-bar { height: 20px; display: flex; gap: 2px; padding: 2px; }
.status-field { flex: 1; padding: 0 4px; display: flex; align-items: center; }
#status-coords { flex: 0 0 80px; }

/* Icons */
.icon-svg { width: 16px; height: 16px; display: block; }

/* MacOS Global Menu Bar (Hidden by default) */
.macos-menu-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 22px;
    background: #FFFFFF;
    border-bottom: 1px solid #000000;
    z-index: 2000;
    padding: 0 10px;
    font-family: "Geneva", "Helvetica", sans-serif;
    font-size: 13px;
    align-items: center;
}

.macos-menu-bar .menu-item {
    padding: 0 10px;
    height: 100%;
    display: flex;
    align-items: center;
    cursor: default;
    font-weight: bold;
}

.macos-menu-bar .apple-menu {
    font-size: 18px;
    padding-bottom: 2px;
}


/* Tool Options */
.tool-options { margin-top: 10px; height: 64px; display: flex; flex-direction: column; padding: 2px; gap: 2px; display: none; }
.rect-option { flex: 1; display: flex; align-items: center; justify-content: center; cursor: default; }
.rect-preview { width: 20px; height: 12px; border: 1px solid black; }
.rect-preview.fill { background-color: #808080; border-color: black; }

/* Modals */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: transparent; display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { padding: 15px; display: flex; flex-direction: column; gap: 10px; }
.input-row { display: flex; align-items: center; justify-content: space-between; }
.input-row input { width: 60px; padding: 2px; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 5px; margin-top: 10px; }
.modal-buttons button { padding: 4px 12px; }

/* Mobile / Touch Optimizations */
@media (max-width: 768px) {
    .win95-window {
        width: 100vw;
        height: 100vh;
    }

    .status-bar {
        display: none;
    }

    .workspace {
        flex-direction: column-reverse;
    }

    .toolbar-container {
        width: 100%;
        height: auto;
        padding: 4px;
        border-right: none;
        border-top: 1px solid var(--win-shadow-light);
    }

    .toolbar {
        display: flex;
        justify-content: center;
        gap: 8px;
    }

    .tool-btn {
        width: 36px;
        height: 36px;
    }

    .canvas-area {
        padding: 10px;
    }

    .bottom-controls {
        flex-direction: column;
        gap: 8px;
        max-height: 60vh; /* More space for palette on tablets */
        overflow-y: auto;
        padding: 8px;
        background: var(--win-gray);
        border-top: 2px solid var(--win-white);
    }

    .palette-panel {
        width: 100%;
    }

    .palette-grid {
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
        width: 100%;
        gap: 4px;
    }

    .color-swatch {
        width: 100%;
        aspect-ratio: 1 / 1;
        min-height: 40px;
    }

    .palette-display {
        flex-direction: row;
        align-items: flex-start;
        gap: 8px;
    }

    .palette-grid-container {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .color-indicators {
        width: 44px;
        height: 44px;
        margin-bottom: 4px;
        cursor: pointer;
        position: relative; /* Ensure children are relative to this */
        display: block;
    }

    .color-indicators .color-indicator {
        position: absolute;
        width: 28px;
        height: 28px;
    }

    .color-indicators .color-indicator.primary {
        top: 0;
        left: 0;
        z-index: 10;
    }

    .color-indicators .color-indicator.secondary {
        bottom: 0;
        right: 0;
        z-index: 5;
    }

    #custom-color-btn {
        width: 44px;
        height: 30px;
        padding: 0;
        font-size: 8px;
    }

    .help-list {
        list-style: none;
        padding: 0;
        margin-top: 10px;
    }

    .help-list li {
        margin-bottom: 8px;
        font-size: 13px;
    }
    }

    .palette-tabs {
        gap: 4px;
        margin-bottom: 4px;
    }

    .palette-tab {
        padding: 4px 12px;
        font-size: 12px;
    }

    .zoom-panel {
        width: 100%;
        justify-content: space-between;
        padding: 12px 0;
        border-top: 1px solid var(--win-shadow-light);
    }

    .zoom-panel label {
        font-size: 14px;
        font-weight: bold;
    }

    .zoom-panel select {
        height: 40px;
        font-size: 16px; /* Prevents iOS zoom on focus */
        flex: 1;
        margin-left: 10px;
    }
}
