/* DarkPixel - Professional Pixel Art Studio */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-900: #0d0d0d;
    --bg-800: #141414;
    --bg-700: #1a1a1a;
    --bg-600: #222222;
    --bg-500: #2a2a2a;
    --bg-400: #333333;
    --bg-300: #444444;
    --surface: #1e1e2e;
    --surface-hover: #262638;
    --surface-active: #2d2d44;
    --border: #3a3a4a;
    --border-subtle: #2a2a3a;
    --text: #e0e0e8;
    --text-dim: #8888a0;
    --text-muted: #5a5a6e;
    --accent: #6c8cff;
    --accent-hover: #8aa4ff;
    --accent-dim: rgba(108, 140, 255, 0.15);
    --accent-glow: rgba(108, 140, 255, 0.3);
    --danger: #ff5c5c;
    --danger-dim: rgba(255, 92, 92, 0.15);
    --success: #4ccc6a;
    --warning: #ffb84d;
    --radius: 6px;
    --radius-sm: 4px;
    --transition: 150ms ease;
    --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font); background: var(--bg-900); color: var(--text); font-size: 13px; line-height: 1.4; }

/* ===== App Layout ===== */
.app { display: flex; flex-direction: column; height: 100vh; }

/* ===== Menu Bar ===== */
.menubar {
    display: flex; align-items: center; justify-content: space-between;
    height: 40px; padding: 0 8px;
    background: var(--bg-800); border-bottom: 1px solid var(--border-subtle);
    user-select: none; -webkit-user-select: none;
    flex-shrink: 0;
}
.menubar-left, .menubar-right { display: flex; align-items: center; gap: 2px; }
.menubar-center { display: flex; align-items: center; gap: 12px; }
.app-logo {
    font-weight: 800; font-size: 14px; color: var(--accent);
    background: var(--accent-dim); padding: 3px 8px; border-radius: var(--radius-sm);
    letter-spacing: 1px; margin-right: 8px;
}
.menu-group { display: flex; align-items: center; gap: 1px; }
.menu-separator { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }
.menu-btn {
    display: flex; align-items: center; gap: 4px;
    background: transparent; border: none; color: var(--text-dim);
    padding: 5px 8px; border-radius: var(--radius-sm); cursor: pointer;
    font-size: 11px; font-family: var(--font); transition: all var(--transition);
}
.menu-btn:hover { background: var(--surface-hover); color: var(--text); }
.menu-btn:active { background: var(--surface-active); }
.menu-btn .icon { width: 14px; height: 14px; flex-shrink: 0; }
.toggle-btn.active { color: var(--accent); background: var(--accent-dim); }
.canvas-dimensions { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.zoom-display {
    font-family: var(--font-mono); font-size: 11px; color: var(--accent);
    background: var(--accent-dim); padding: 2px 6px; border-radius: var(--radius-sm);
}

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

/* ===== Left Toolbar ===== */
.toolbar {
    width: 90px; background: var(--bg-800); border-right: 1px solid var(--border-subtle);
    display: flex; flex-direction: column; align-items: center; padding: 6px 4px;
    gap: 2px; overflow-y: auto; flex-shrink: 0;
}
.tool-section {
    display: grid; grid-template-columns: 1fr 1fr; gap: 2px; width: 100%;
}
.tool-divider { width: 64px; height: 1px; background: var(--border); margin: 4px 0; align-self: center; }
.tool-btn {
    width: 100%; height: 36px; display: flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
    cursor: pointer; color: var(--text-dim); transition: all var(--transition);
}
.tool-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border); }
.tool-btn.active {
    background: var(--accent-dim); color: var(--accent); border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent-glow);
}
.tool-icon { width: 20px; height: 20px; }

/* Color Area */
.color-area { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0; }
.fg-bg-swatches { position: relative; width: 38px; height: 38px; }
.fg-swatch {
    position: absolute; top: 0; left: 0; width: 26px; height: 26px;
    border: 2px solid var(--text); border-radius: 3px; cursor: pointer; z-index: 2;
    background: #000; box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.bg-swatch {
    position: absolute; bottom: 0; right: 0; width: 26px; height: 26px;
    border: 2px solid var(--text-dim); border-radius: 3px; cursor: pointer; z-index: 1;
    background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.swap-btn {
    position: absolute; top: -2px; right: -2px; z-index: 3;
    width: 16px; height: 16px; padding: 0;
    background: var(--bg-600); border: 1px solid var(--border); border-radius: 3px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--text-dim);
}
.swap-btn:hover { color: var(--text); background: var(--bg-400); }
.icon-tiny { width: 10px; height: 10px; }
.hidden-picker { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.color-hex { font-family: var(--font-mono); font-size: 9px; color: var(--text-muted); }

/* Brush Area */
.brush-area { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.mini-label { font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.brush-val { font-family: var(--font-mono); font-size: 11px; color: var(--accent); }
.vertical-slider { writing-mode: vertical-lr; direction: rtl; width: 20px; height: 80px; }

/* ===== Canvas Area ===== */
.canvas-area {
    flex: 1; display: flex; flex-direction: column;
    background: var(--bg-900); overflow: hidden; position: relative;
}
.canvas-scroll {
    flex: 1; display: flex; align-items: center; justify-content: center;
    overflow: auto; position: relative;
}
#pixelCanvas {
    image-rendering: pixelated; image-rendering: crisp-edges;
    cursor: crosshair; touch-action: none;
    box-shadow: 0 0 0 1px var(--border), 0 4px 24px rgba(0,0,0,0.4);
}

/* Status Bar */
.status-bar {
    display: flex; align-items: center; gap: 12px;
    height: 28px; padding: 0 10px;
    background: var(--bg-800); border-top: 1px solid var(--border-subtle);
    font-size: 11px; font-family: var(--font-mono); color: var(--text-muted);
    flex-shrink: 0;
}
.status-bar #pixelInfo { min-width: 60px; }
.status-bar #toolInfo { color: var(--accent); }
.zoom-controls { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.zoom-btn {
    width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
    background: var(--bg-600); border: 1px solid var(--border); border-radius: 3px;
    color: var(--text-dim); cursor: pointer; font-size: 14px; font-weight: bold;
}
.zoom-btn:hover { background: var(--bg-400); color: var(--text); }
.zoom-slider { width: 80px; height: 4px; }

/* ===== Right Panel ===== */
.right-panel {
    width: 260px; background: var(--bg-800); border-left: 1px solid var(--border-subtle);
    overflow-y: auto; flex-shrink: 0; display: flex; flex-direction: column;
}
.panel { border-bottom: 1px solid var(--border-subtle); }
.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px; cursor: pointer; user-select: none; -webkit-user-select: none;
    transition: background var(--transition);
}
.panel-header:hover { background: var(--surface-hover); }
.panel-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-dim); }
.panel-toggle { font-size: 8px; color: var(--text-muted); transition: transform var(--transition); }
.panel.collapsed .panel-body { display: none; }
.panel.collapsed .panel-toggle { transform: rotate(-90deg); }
.panel-body { padding: 8px 12px 12px; }

/* Panel Toolbar */
.panel-toolbar { display: flex; gap: 2px; margin-bottom: 8px; }
.toolbar-spacer { flex: 1; }
.icon-btn {
    width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
    color: var(--text-dim); cursor: pointer; transition: all var(--transition);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border); }
.icon-btn.danger:hover { background: var(--danger-dim); color: var(--danger); border-color: var(--danger); }
.icon-btn.play-btn { color: var(--success); }
.icon-btn .icon { width: 14px; height: 14px; }

/* Palette Grid */
.palette-grid {
    display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
}
.palette-swatch {
    aspect-ratio: 1; border-radius: 2px; cursor: pointer;
    border: 1px solid transparent; transition: all 80ms ease;
}
.palette-swatch:hover { border-color: var(--text); transform: scale(1.15); z-index: 1; }
.palette-swatch.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* Layers List */
.layers-list { max-height: 180px; overflow-y: auto; border-radius: var(--radius-sm); }
.layer-item {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 8px; cursor: pointer;
    border-radius: var(--radius-sm); margin-bottom: 1px;
    transition: background var(--transition);
}
.layer-item:hover { background: var(--surface-hover); }
.layer-item.active { background: var(--accent-dim); }
.layer-visibility {
    width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
    font-size: 12px; cursor: pointer; border-radius: 3px; flex-shrink: 0;
}
.layer-visibility:hover { background: var(--bg-400); }
.layer-name { flex: 1; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-opacity-mini {
    width: 40px; height: 3px; appearance: none; -webkit-appearance: none;
    background: var(--bg-400); border-radius: 2px; cursor: pointer;
}
.layer-opacity-mini::-webkit-slider-thumb {
    appearance: none; -webkit-appearance: none;
    width: 8px; height: 8px; border-radius: 50%; background: var(--accent); cursor: pointer;
}
.layer-blend-mini {
    font-size: 9px; color: var(--text-muted); background: transparent; border: none;
    cursor: pointer; padding: 1px 2px;
}

/* Frames List */
.frames-list { max-height: 120px; overflow-y: auto; border-radius: var(--radius-sm); }
.frame-item {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 8px; cursor: pointer;
    border-radius: var(--radius-sm); margin-bottom: 1px;
    transition: background var(--transition); font-size: 11px;
}
.frame-item:hover { background: var(--surface-hover); }
.frame-item.active { background: var(--accent-dim); color: var(--accent); }
.frame-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frame-duration { font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); }

/* Canvas Size */
.canvas-size-row { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.size-input { display: flex; align-items: center; gap: 4px; flex: 1; }
.size-input label { font-size: 10px; color: var(--text-muted); font-weight: 600; }
.size-input input {
    width: 100%; padding: 4px 6px; font-size: 11px; font-family: var(--font-mono);
    background: var(--bg-600); border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); outline: none;
}
.size-input input:focus { border-color: var(--accent); }
.link-icon { width: 14px; height: 14px; color: var(--text-muted); flex-shrink: 0; }
.apply-btn {
    width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
    background: var(--accent-dim); border: 1px solid var(--accent); border-radius: var(--radius-sm);
    color: var(--accent); cursor: pointer; font-size: 14px; font-weight: bold;
}
.apply-btn:hover { background: var(--accent); color: white; }

/* Presets */
.preset-row { display: flex; gap: 3px; }
.preset-btn {
    flex: 1; padding: 4px 0; font-size: 10px; font-family: var(--font-mono);
    background: var(--bg-600); border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text-dim); cursor: pointer; transition: all var(--transition);
}
.preset-btn:hover { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

/* FPS */
.fps-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.fps-row label { font-size: 10px; color: var(--text-muted); font-weight: 600; }
.fps-slider { flex: 1; height: 4px; }
.fps-num {
    width: 40px; padding: 3px 4px; font-size: 11px; font-family: var(--font-mono);
    background: var(--bg-600); border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); text-align: center; outline: none;
}
.fps-num:focus { border-color: var(--accent); }

/* Onion Skin */
.onion-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.onion-row label { font-size: 10px; color: var(--text-muted); min-width: 32px; }
.onion-row input[type="range"] { flex: 1; height: 4px; }
.onion-row span { font-size: 10px; font-family: var(--font-mono); color: var(--text-dim); min-width: 28px; }
.tiny-num {
    width: 36px; padding: 3px; font-size: 11px; font-family: var(--font-mono);
    background: var(--bg-600); border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); text-align: center; outline: none;
}
.tiny-num:focus { border-color: var(--accent); }

/* Toggle Switch */
.panel-switch { position: relative; display: inline-block; width: 28px; height: 16px; }
.panel-switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
    position: absolute; cursor: pointer; inset: 0;
    background: var(--bg-400); border-radius: 8px; transition: var(--transition);
}
.switch-slider::before {
    content: ""; position: absolute;
    height: 12px; width: 12px; left: 2px; bottom: 2px;
    background: var(--text-dim); border-radius: 50%; transition: var(--transition);
}
.panel-switch input:checked + .switch-slider { background: var(--accent); }
.panel-switch input:checked + .switch-slider::before { transform: translateX(12px); background: white; }

/* Preview */
.preview-body { display: flex; justify-content: center; padding: 8px 12px; }
.preview-canvas {
    width: 100%; max-width: 200px; aspect-ratio: 1;
    image-rendering: pixelated; image-rendering: crisp-edges;
    background: var(--bg-900); border: 1px solid var(--border); border-radius: var(--radius-sm);
}

/* ===== Range Inputs ===== */
input[type="range"] {
    -webkit-appearance: none; appearance: none;
    background: var(--bg-400); border-radius: 2px; outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--accent); cursor: pointer; border: none;
    box-shadow: 0 0 4px rgba(108,140,255,0.3);
}
input[type="range"]::-moz-range-thumb {
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--accent); cursor: pointer; border: none;
}

/* ===== Scrollbars ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-400); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-300); }

/* ===== Responsive ===== */

/* Tablet (768-1024px) — larger tap targets */
@media (max-width: 1024px) {
    .menu-btn { padding: 8px 10px; font-size: 12px; min-height: 36px; }
    .menu-btn .icon { width: 18px; height: 18px; }
    .tool-btn { height: 42px; }
    .tool-icon { width: 24px; height: 24px; }
    .icon-btn { width: 36px; height: 36px; }
    .icon-btn .icon { width: 18px; height: 18px; }
    .toolbar { width: 100px; padding: 8px 5px; }
    .zoom-btn { width: 28px; height: 28px; font-size: 16px; }
    .preset-btn { padding: 6px 0; font-size: 11px; }
    .apply-btn { width: 36px; height: 36px; font-size: 16px; }
    .fg-swatch, .bg-swatch { width: 30px; height: 30px; }
    .fg-bg-swatches { width: 44px; height: 44px; }
    .swap-btn { width: 18px; height: 18px; }
}

@media (max-width: 900px) {
    .right-panel { width: 220px; }
    .menu-btn span { display: none; }
}

@media (max-width: 640px) {
    .workspace { flex-direction: column; }
    .toolbar { flex-direction: row; width: 100%; height: 54px; overflow-x: auto; overflow-y: hidden; border-right: none; border-bottom: 1px solid var(--border-subtle); }
    .tool-section { display: flex; grid-template-columns: none; flex-direction: row; }
    .tool-divider { width: 1px; height: 36px; margin: 0 4px; }
    .tool-btn { width: 44px; height: 44px; }
    .right-panel { width: 100%; max-height: 40vh; flex-direction: row; flex-wrap: wrap; }
    .right-panel .panel { flex: 1; min-width: 200px; }
    .brush-area { flex-direction: row; }
    .vertical-slider { writing-mode: horizontal-tb; direction: ltr; width: 60px; height: 20px; }
    .color-area { flex-direction: row; }
    .menubar { height: 44px; }
    .menu-btn { padding: 8px 6px; min-height: 38px; }
}
