/* ==============================================
   PixelCraft - Web Pixel Art Editor
   Stylesheet
   ============================================== */

/* --- CSS Variables --- */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-panel: #1e2a4a;
    --bg-canvas: #2a2a3e;
    --bg-hover: #283a5e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b8;
    --text-muted: #6a6a80;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --accent-secondary: #533483;
    --border: #2a3050;
    --border-light: #3a4060;
    --success: #4ecca3;
    --warning: #f0a500;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --radius-sm: 4px;
    --transition: 0.2s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* --- App Container --- */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
}

/* --- Header --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-title {
    font-size: 1.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #ff6b81, #f0a500);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.app-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 2px 8px;
    background: var(--bg-tertiary);
    border-radius: 10px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-separator {
    width: 1px;
    height: 20px;
    background: var(--border-light);
    margin: 0 4px;
}

.zoom-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: center;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-outline {
    background: transparent;
}

.btn-icon {
    padding: 6px;
    width: 32px;
    height: 32px;
}

.btn-sm {
    padding: 3px 8px;
    font-size: 0.7rem;
}

.btn-xs {
    padding: 2px 6px;
    font-size: 0.65rem;
    height: 24px;
}

/* --- Main Layout --- */
.app-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* --- Sidebars --- */
.sidebar {
    width: 220px;
    background: var(--bg-secondary);
    overflow-y: auto;
    flex-shrink: 0;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-left {
    border-right: 1px solid var(--border);
}

.sidebar-right {
    border-left: 1px solid var(--border);
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 2px;
}

/* --- Panels --- */
.panel {
    background: var(--bg-panel);
    border-radius: var(--radius);
    padding: 10px;
}

.panel-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* --- Tool Grid --- */
.tool-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.6rem;
    font-family: inherit;
    transition: all var(--transition);
}

.tool-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tool-btn.active {
    background: var(--accent-secondary);
    border-color: var(--accent);
    color: #fff;
}

.tool-btn svg {
    flex-shrink: 0;
}

.tool-btn span {
    line-height: 1;
}

/* --- Canvas Size Controls --- */
.canvas-size-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.size-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.custom-size {
    display: flex;
    align-items: center;
    gap: 4px;
}

.size-input {
    width: 48px;
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.7rem;
    text-align: center;
    font-family: inherit;
}

.size-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* --- Canvas Area --- */
.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-canvas);
    position: relative;
    overflow: hidden;
}

.canvas-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    overflow: hidden;
}

.canvas-wrapper.move-mode {
    cursor: grab;
}

.canvas-wrapper.move-mode:active {
    cursor: grabbing;
}

.canvas-inner {
    position: relative;
}

#pixel-canvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#grid-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.canvas-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 16px;
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    width: 100%;
}

/* --- Color Controls --- */
.color-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.active-colors {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-swatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.color-swatch span {
    font-size: 0.55rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.swatch-fill {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border-light);
    cursor: pointer;
    transition: border-color var(--transition);
}

.swatch-fill:hover {
    border-color: var(--accent);
}

.swap-btn {
    margin-top: 12px;
}

.color-picker-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

#color-picker {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: none;
    padding: 0;
}

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

#color-picker::-webkit-color-swatch {
    border: 2px solid var(--border-light);
    border-radius: var(--radius-sm);
}

.color-picker-label {
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* --- Palette --- */
.palette-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-bottom: 8px;
}

.palette-switcher .btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
}

.palette-color {
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
}

.palette-color:hover {
    border-color: #fff;
    transform: scale(1.15);
    z-index: 1;
}

.palette-color.active {
    border-color: var(--accent);
    box-shadow: 0 0 8px var(--accent);
}

/* --- Brush Size --- */
.brush-size-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brush-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--border-light);
    outline: none;
}

.brush-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

#brush-size-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    min-width: 28px;
}

/* --- Frames --- */
.frames-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.frame-actions {
    display: flex;
    gap: 3px;
}

.frames-list {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    max-height: 120px;
    overflow-y: auto;
}

.frame-thumb {
    width: 36px;
    height: 36px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    image-rendering: pixelated;
    background: repeating-conic-gradient(#333 0% 25%, #444 0% 50%) 50% / 8px 8px;
    transition: border-color var(--transition);
    flex-shrink: 0;
}

.frame-thumb:hover {
    border-color: var(--text-secondary);
}

.frame-thumb.active {
    border-color: var(--accent);
    box-shadow: 0 0 6px var(--accent);
}

.frame-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#frame-indicator {
    font-size: 0.7rem;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: center;
}

.animation-controls {
    display: flex;
    gap: 4px;
}

.fps-select {
    flex: 1;
    padding: 2px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.65rem;
    font-family: inherit;
}

/* --- Shortcuts --- */
.shortcuts-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.shortcut-item kbd {
    display: inline-block;
    padding: 1px 5px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: 3px;
    font-size: 0.6rem;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-primary);
    min-width: 50px;
    text-align: center;
}

/* --- Toast Notification --- */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: #000;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    z-index: 1000;
    animation: toast-in 0.3s ease, toast-out 0.3s ease 2s forwards;
    white-space: nowrap;
}

.toast.error {
    background: var(--accent);
    color: #fff;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(-50%) translateY(0); }
    to { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .sidebar {
        width: 180px;
        padding: 4px;
    }

    .app-title {
        font-size: 1rem;
    }

    .app-subtitle {
        display: none;
    }

    .tool-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    .app-main {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        max-height: 120px;
        overflow-y: auto;
    }

    .sidebar-left {
        border-right: none;
        border-bottom: 1px solid var(--border);
        order: -1;
        padding: 4px 8px;
    }

    .sidebar-right {
        border-left: none;
        border-top: 1px solid var(--border); /* [site patch] was display: none, which hid all colour controls on phones */
        order: 2;
        padding: 4px 8px;
    }

    .canvas-area {
        order: 1;
    }

    .app-header {
        flex-wrap: wrap;
        gap: 4px;
    }

    .tool-grid {
        display: flex;
        gap: 2px;
    }

    .tool-btn {
        padding: 4px 6px;
    }

    .tool-btn span {
        display: none;
    }
}