/* ── Pixel Art Editor - style.css ── */

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

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #16172b;
    --bg-tertiary: #1e1f3b;
    --bg-hover: #282a50;
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.3);
    --success: #00cec9;
    --warning: #fdcb6e;
    --danger: #ff7675;
    --text-primary: #e8e8f0;
    --text-secondary: #9a9abf;
    --text-muted: #5a5a80;
    --border: #2a2b50;
    --sidebar-width: 240px;
}

html {
    font-size: 16px;
    background: var(--bg-primary);
}

/* ── Focus Visible ── */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
    outline: none;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

.app-layout {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ──── Sidebar ──── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-section h3 {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

/* ──── Tools ──── */
.tools {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.tool {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.15s ease;
    position: relative;
}
.tool .shortcut {
    font-size: 0.55rem;
    opacity: 0.5;
    font-weight: 500;
}
.tool:hover { background: var(--bg-hover); color: var(--text-primary); }
.tool.active {
    background: var(--accent);
    border-color: var(--accent-light);
    color: #fff;
    box-shadow: 0 0 12px var(--accent-glow);
}
.tool.active .shortcut { opacity: 0.8; }

/* ──── Grid Size Presets ──── */
.grid-presets {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}
.grid-preset {
    padding: 6px 4px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 500;
    text-align: center;
    transition: all 0.15s ease;
}
.grid-preset:hover { background: var(--bg-hover); color: var(--text-primary); }
.grid-preset.active {
    background: var(--accent);
    border-color: var(--accent-light);
    color: #fff;
}

/* ──── Color ──── */
.current-color-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.color-preview-box {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 2px solid var(--border);
    flex-shrink: 0;
    background-image:
        linear-gradient(45deg, #ccc 25%, transparent 25%),
        linear-gradient(-45deg, #ccc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ccc 75%),
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0;
    position: relative;
    overflow: hidden;
}
.color-preview-inner {
    position: absolute;
    inset: 0;
    border-radius: 6px;
}
.color-hex-input {
    flex: 1;
    height: 36px;
    padding: 0 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: 'Inter', monospace;
    font-size: 0.8rem;
    outline: none;
}
.color-hex-input:focus { border-color: var(--accent); }
input[type="color"] {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    background: none;
    padding: 0;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border-radius: 4px; border: 1px solid var(--border); }

/* ──── Palette ──── */
.palette-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
}
.palette-swatch {
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.1s ease;
    position: relative;
}
.palette-swatch:hover { transform: scale(1.15); z-index: 1; box-shadow: 0 0 8px currentColor; }
.palette-swatch.active { border-color: #fff; box-shadow: 0 0 8px rgba(255,255,255,0.5); transform: scale(1.2); }

/* ──── Color History ──── */
.color-history-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}
.history-swatch {
    width: 22px;
    height: 22px;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.1s ease;
}
.history-swatch:hover { transform: scale(1.2); z-index: 1; border-color: #fff; }
.color-history-empty {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 4px 0;
}

/* ──── Action Buttons ──── */
.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    transition: all 0.15s ease;
    width: 100%;
    justify-content: center;
}
.action-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.action-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.checkbox-row input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
}

/* ──── Main Canvas Area ──── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    min-width: 0;
    position: relative;
}

.canvas-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.canvas-info {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.canvas-info span { display: flex; align-items: center; gap: 4px; }

.canvas-container {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 0 0 1px var(--border);
    background-image:
        linear-gradient(45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(-45deg, #2a2a2a 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #2a2a2a 75%),
        linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-color: #222;
}

#pixelCanvas {
    display: grid;
    position: relative;
    z-index: 1;
}
.pixel {
    cursor: crosshair;
    transition: none;
    touch-action: none;
}
.pixel:hover {
    outline: 1px solid rgba(255,255,255,0.3);
    outline-offset: -1px;
    z-index: 2;
}

/* ──── Footer ──── */
.app-footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 10px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--text-muted);
    flex-shrink: 0;
}
.app-footer a {
    color: var(--accent-light);
    text-decoration: none;
    font-weight: 500;
}
.app-footer a:hover { text-decoration: underline; }
.footer-shortcuts {
    display: flex;
    gap: 12px;
}
.footer-shortcuts span {
    display: flex;
    align-items: center;
    gap: 3px;
}
.footer-shortcuts kbd {
    display: inline-block;
    padding: 1px 5px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-family: 'Inter', monospace;
    font-size: 0.65rem;
    line-height: 1.4;
}

/* ──── Toast / Notification ──── */
.toast {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 0.8rem;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 100;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ──── Mobile ──── */
@media (max-width: 768px) {
    html { font-size: 15px; }
    .app-layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 10px;
        gap: 10px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow-y: visible;
        overflow-x: auto;
    }
    .sidebar-section {
        min-width: 0;
    }
    .sidebar-section.tools-section { flex: 0 0 auto; }
    .sidebar-section.color-section { flex: 0 0 auto; }
    .sidebar-section.palette-section { flex: 1 1 200px; }
    .sidebar-section.grid-section { flex: 0 0 auto; }
    .sidebar-section.history-section { flex: 1 1 150px; }
    .sidebar-section.actions-section { flex: 0 0 auto; }
    .palette-grid { grid-template-columns: repeat(8, 1fr); }
    .main { padding: 12px; }
    .footer-shortcuts { display: none; }
    .tool { min-width: 44px; min-height: 44px; }
    .grid-preset { min-height: 36px; padding: 8px 6px; }
    .action-btn { min-height: 44px; padding: 10px 12px; }
    .palette-swatch { min-width: 28px; min-height: 28px; }
    .history-swatch { min-width: 28px; min-height: 28px; }
    .color-hex-input { min-height: 44px; }
}
@media (max-width: 480px) {
    .sidebar { gap: 8px; padding: 8px; }
    .tools { grid-template-columns: repeat(5, 1fr); }
    .grid-presets { grid-template-columns: repeat(4, 1fr); }
    .app-footer { padding: 8px 12px; font-size: 0.68rem; flex-wrap: wrap; justify-content: center; gap: 4px; }
}

/* ── 375px breakpoint (small phones) ── */
@media (max-width: 375px) {
    .sidebar { padding: 6px; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
