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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1d23;
    color: #e0e0e0;
    min-height: 100vh;
    overflow: hidden;
    user-select: none;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Titlebar */
#titlebar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 36px;
    background: linear-gradient(180deg, #3a3f4a 0%, #2a2e38 100%);
    padding: 0 10px;
    border-bottom: 1px solid #1a1d23;
    -webkit-app-region: drag;
}

#titlebar .title {
    font-size: 13px;
    font-weight: 600;
    color: #ccc;
}

#titlebar .menu {
    display: flex;
    gap: 5px;
    -webkit-app-region: no-drag;
}

#titlebar .menu-btn {
    background: transparent;
    border: none;
    color: #aaa;
    padding: 5px 12px;
    font-size: 12px;
    cursor: pointer;
    border-radius: 4px;
}

#titlebar .menu-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

/* Toolbar */
#toolbar {
    display: flex;
    align-items: center;
    height: 48px;
    background: #252931;
    padding: 0 10px;
    gap: 10px;
    border-bottom: 1px solid #1a1d23;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tool-btn {
    width: 32px;
    height: 32px;
    background: #3a3f4a;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.tool-btn svg {
    width: 18px;
    height: 18px;
    fill: #aaa;
}

.tool-btn:hover {
    background: #4a4f5a;
}

.tool-btn:hover svg {
    fill: #fff;
}

.tool-btn.active {
    background: #4a9eff;
}

.tool-btn.active svg {
    fill: #fff;
}

.toolbar-divider {
    width: 1px;
    height: 28px;
    background: #3a3f4a;
    margin: 0 5px;
}

.colors-group .current-color {
    display: flex;
    align-items: center;
    gap: 4px;
}

.color-preview {
    width: 28px;
    height: 28px;
    border: 2px solid #555;
    border-radius: 4px;
    cursor: pointer;
}

#color-picker {
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    cursor: pointer;
    background: transparent;
}

#color-picker::-webkit-color-swatch-wrapper {
    padding: 0;
}

#color-picker::-webkit-color-swatch {
    border: 2px solid #555;
    border-radius: 4px;
}

.brush-label {
    font-size: 12px;
    color: #888;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brush-label input[type="range"] {
    width: 80px;
    accent-color: #4a9eff;
}

#canvas-size {
    background: #3a3f4a;
    border: none;
    color: #fff;
    padding: 5px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

#canvas-size:focus {
    outline: 1px solid #4a9eff;
}

/* Main Area */
#main-area {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#left-panel {
    width: 180px;
    background: #252931;
    border-right: 1px solid #1a1d23;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #1a1d23;
    overflow: hidden;
}

#right-panel {
    width: 220px;
    background: #252931;
    border-left: 1px solid #1a1d23;
    overflow-y: auto;
}

/* Panel Sections */
.panel-section {
    padding: 10px;
    border-bottom: 1px solid #3a3f4a;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.panel-btn {
    width: 20px;
    height: 20px;
    background: #3a3f4a;
    border: none;
    border-radius: 3px;
    color: #aaa;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}

.panel-btn:hover {
    background: #4a4f5a;
    color: #fff;
}

/* Layers */
.layer-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.layer {
    padding: 8px 10px;
    background: #3a3f4a;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

.layer:hover {
    background: #4a4f5a;
}

.layer.active {
    background: #4a9eff;
    color: #fff;
}

/* Frames */
.frame-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.frame {
    width: 36px;
    height: 36px;
    background: #3a3f4a;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    cursor: pointer;
}

.frame:hover {
    background: #4a4f5a;
}

.frame.active {
    background: #4a9eff;
    color: #fff;
}

/* Animation Controls */
.animation-controls {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.animation-controls button {
    flex: 1;
    padding: 6px;
    font-size: 11px;
}

.fps-control {
    font-size: 11px;
    color: #888;
}

.fps-control input {
    width: 100%;
    accent-color: #4a9eff;
}

/* Canvas Container */
#canvas-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    background: 
        linear-gradient(45deg, #222 25%, transparent 25%),
        linear-gradient(-45deg, #222 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #222 75%),
        linear-gradient(-45deg, transparent 75%, #222 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: #1a1d23;
    padding: 20px;
}

#main-canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: crosshair;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

#canvas-info {
    display: flex;
    justify-content: space-between;
    padding: 5px 10px;
    background: #252931;
    font-size: 11px;
    color: #666;
}

/* Right Panel */
.palette-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 3px;
    margin-bottom: 10px;
}

.palette-swatch {
    aspect-ratio: 1;
    border-radius: 3px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s;
}

.palette-swatch:hover {
    transform: scale(1.1);
}

.palette-swatch.selected {
    border-color: #fff;
}

.palette-controls {
    display: flex;
    gap: 5px;
}

.palette-controls button {
    flex: 1;
    padding: 5px;
    font-size: 10px;
}

/* Preview */
.preview-container {
    background: #1a1d23;
    border-radius: 4px;
    padding: 10px;
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}

#preview-canvas {
    image-rendering: pixelated;
    border: 1px solid #3a3f4a;
}

.preview-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 11px;
}

.preview-controls select {
    background: #3a3f4a;
    border: none;
    color: #fff;
    padding: 4px;
    border-radius: 3px;
    font-size: 11px;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.action-buttons button {
    flex: 1;
    min-width: 45%;
    padding: 6px;
    font-size: 11px;
}

/* Export */
.export-controls button {
    width: 100%;
    margin-bottom: 5px;
}

#export-links {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#export-links a {
    color: #4a9eff;
    font-size: 11px;
    text-decoration: none;
}

#export-links a:hover {
    text-decoration: underline;
}

/* Button Styles */
button {
    background: #3a3f4a;
    border: none;
    border-radius: 4px;
    color: #ccc;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s;
}

button:hover {
    background: #4a4f5a;
    color: #fff;
}

.btn-primary {
    background: #4a9eff;
    color: #fff;
}

.btn-primary:hover {
    background: #3a8eef;
}

.btn-success {
    background: #28a745;
    color: #fff;
}

.btn-success:hover {
    background: #218838;
}

.btn-danger {
    background: #dc3545;
    color: #fff;
}

.btn-danger:hover {
    background: #c82333;
}

/* Tool Options Panel */
#tool-options {
    display: none;
    position: absolute;
    background: #252931;
    border: 1px solid #3a3f4a;
    border-radius: 6px;
    padding: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 100;
}

#tool-options.visible {
    display: block;
}

.tool-option-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.tool-option-row:last-child {
    margin-bottom: 0;
}

.tool-option-row label {
    font-size: 11px;
    color: #888;
    min-width: 50px;
}

/* Selection rectangle */
.selection-box {
    position: absolute;
    border: 1px dashed #4a9eff;
    background: rgba(74, 158, 255, 0.1);
    pointer-events: none;
}
