/**
 * PX3k Pixel Art — Frontend Viewer
 * Visualisateur de pixel art moderne
 * Variables CSS pour la taille du canvas
 */

/* ============================================
   CSS VARIABLES — Paramètres configurables
   ============================================ */
.px3k-pixel-art-block {
    --px3k-canvas-w: 320px;
    --px3k-canvas-h: 320px;
    --px3k-accent: #ff6b9d;
    --px3k-accent-light: rgba(255, 107, 157, 0.15);
    --px3k-toolbar-bg: #1e1e2e;
    --px3k-toolbar-text: #cdd6f4;
    --px3k-border-radius: 12px;
    --px3k-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* ============================================
   FONTS
   ============================================ */
.px3k-font-press-start-2p { font-family: 'Press Start 2P', cursive; }
.px3k-font-silkscreen { font-family: 'Silkscreen', cursive; }
.px3k-font-vt323 { font-family: 'VT323', monospace; }
.px3k-font-pixelify-sans { font-family: 'Pixelify Sans', sans-serif; }
.px3k-font-inherit { font-family: inherit; }

/* ============================================
   BLOCK CONTAINER
   ============================================ */
.px3k-pixel-art-block {
    margin: 2em auto;
    max-width: 100%;
}
.px3k-align-center { text-align: center; }
.px3k-align-left { text-align: left; }
.px3k-align-right { text-align: right; }

/* ============================================
   VIEWER — Le widget complet
   ============================================ */
.px3k-pixel-art-block,
.px3k-pixel-art-gallery {
    text-align: center;
}

.px3k-viewer {
    display: inline-block;
    text-align: left;
    border-radius: var(--px3k-border-radius);
    overflow: hidden;
    box-shadow: var(--px3k-shadow);
    border: 1px solid rgba(255, 107, 157, 0.15);
    background: #fff;
    transition: box-shadow 0.3s ease;
}
.px3k-viewer:hover {
    box-shadow: 0 12px 40px rgba(255, 107, 157, 0.2);
}

/* Layout horizontal : canvas à gauche, palette à droite */
.px3k-viewer-body {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 0;
}

.px3k-viewer-left {
    display: flex;
    flex-direction: column;
}

.px3k-viewer-sidebar {
    display: flex;
    flex-direction: column;
    padding: 12px 16px;
    background: #f4f4f4;
    border-left: 1px solid rgba(0,0,0,.06);
    min-width: 180px;
    max-width: 220px;
}

/* ============================================
   TOOLBAR — Toujours visible, hors du canvas
   ============================================ */
.px3k-viewer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--px3k-toolbar-bg);
    color: var(--px3k-toolbar-text);
    gap: 8px;
    user-select: none;
    border-bottom: 1px solid rgba(255, 107, 157, 0.2);
}

.px3k-toolbar-left,
.px3k-toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.px3k-toolbar-icon {
    display: flex;
    align-items: center;
    opacity: 0.5;
    margin-right: 4px;
}

.px3k-toolbar-sep {
    width: 1px;
    height: 18px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0 4px;
}

.px3k-toolbar-info {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    opacity: 0.6;
    letter-spacing: 0.5px;
}

.px3k-toolbar-color {
    display: flex;
    align-items: center;
    gap: 6px;
}

.px3k-toolbar-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    transition: background-color 0.1s;
}

.px3k-toolbar-hex {
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    opacity: 0.7;
    min-width: 56px;
    text-transform: uppercase;
}

/* Boutons de zoom dans la toolbar */
.px3k-zoom-btn {
    background: rgba(255, 255, 255, 0.08);
    color: var(--px3k-toolbar-text);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 5px 10px;
    font-family: 'Press Start 2P', cursive;
    font-size: 7px;
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
}
.px3k-zoom-btn:hover {
    background: rgba(255, 107, 157, 0.3);
    border-color: rgba(255, 107, 157, 0.5);
    color: #fff;
}
.px3k-zoom-btn.active {
    background: var(--px3k-accent);
    border-color: var(--px3k-accent);
    color: #fff;
    box-shadow: 0 0 8px rgba(255, 107, 157, 0.4);
}
.px3k-btn-fit svg {
    opacity: 0.7;
}
.px3k-btn-fit:hover svg {
    opacity: 1;
}

/* ============================================
   CANVAS — Zone de visualisation fixe
   ============================================ */
.px3k-viewer-canvas {
    width: var(--px3k-canvas-w);
    height: var(--px3k-canvas-h);
    overflow: auto;
    position: relative;
    cursor: grab;
    /* Centrer l'image */
    display: flex;
    align-items: center;
    justify-content: center;
    /* Scrollbars personnalisées */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 107, 157, 0.4) rgba(0, 0, 0, 0.05);
}
.px3k-viewer-canvas:active {
    cursor: grabbing;
}

/* Scrollbars Webkit */
.px3k-viewer-canvas::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.px3k-viewer-canvas::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.03);
}
.px3k-viewer-canvas::-webkit-scrollbar-thumb {
    background: rgba(255, 107, 157, 0.35);
    border-radius: 3px;
}
.px3k-viewer-canvas::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 107, 157, 0.6);
}

/* ============================================
   BACKGROUND PATTERNS — Toujours visibles
   ============================================ */
.px3k-bg-checkerboard {
    background-image:
        linear-gradient(45deg, #d4d4d8 25%, transparent 25%),
        linear-gradient(-45deg, #d4d4d8 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d4d4d8 75%),
        linear-gradient(-45deg, transparent 75%, #d4d4d8 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-color: #e4e4e7;
}
.px3k-bg-dark {
    background-color: #1a1a2e;
}
.px3k-bg-light {
    background-color: #f8f9fa;
}
.px3k-bg-none {
    background-color: transparent;
}

/* ============================================
   IMAGE — Pixel Perfect, taille réelle × zoom
   ============================================ */
.px3k-viewer-img {
    display: block;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    -ms-interpolation-mode: nearest-neighbor;
    cursor: crosshair;
    /* Pas de max-width ! L'image peut dépasser le canvas */
    max-width: none;
    /* La taille est gérée par JS : width = naturalWidth * zoom */
}

/* ============================================
   STATUS BAR — Barre d'état sous le canvas
   ============================================ */
.px3k-viewer-statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: #1e1e2e;
    color: #cdd6f4;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    border-top: 1px solid rgba(255, 107, 157, 0.2);
    user-select: none;
    width: 100%;
    box-sizing: border-box;
}

.px3k-status-left,
.px3k-status-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.px3k-status-zoom-info {
    opacity: 0.8;
}

.px3k-status-zoom-level {
    color: var(--px3k-accent);
    font-weight: bold;
}

.px3k-status-sep {
    opacity: 0.3;
    margin: 0 4px;
}

.px3k-status-palette-info {
    display: flex;
    align-items: center;
    gap: 6px;
}

.px3k-status-palette-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    transition: background-color 0.1s;
}

.px3k-status-palette-hex {
    opacity: 0.7;
    min-width: 56px;
    text-transform: uppercase;
}

/* ============================================
   VIEWER FOOTER — Métadonnées sous le canvas
   ============================================ */
.px3k-viewer-footer {
    padding: 16px 20px;
    background: #fafafa;
    border-top: 1px solid #e5e7eb;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.px3k-placeholder {
    color: #9ca3af;
    font-style: italic;
    opacity: 0.7;
}

.px3k-caption {
	font-size: 11px;
	margin: 4px auto;
	color: #374151;
	line-height: 1.6;
	word-wrap: anywhere;
	max-width: 360px;
	text-align: left;
	justify-content: center;
	display: flex;
	align-content: center;
	align-items: center;
	background: #e7e7e7;
	padding: 5px;
	border-radius: 12px;
}

.px3k-font-press-start-2p .px3k-caption,
.px3k-font-silkscreen .px3k-caption,
.px3k-font-vt323 .px3k-caption,
.px3k-font-pixelify-sans .px3k-caption {
    font-size: 9px;
}
.px3k-author {
    font-size: 10px;
    color: #6b7280;
    margin: 4px 0;
}
.px3k-canvas-size {
    font-size: 8px;
    color: var(--px3k-accent);
    margin: 4px 0;
}
.px3k-meta-label {
    font-weight: 100;
    color: #6b7280;
    font-size: 9px;
}

/* ============================================
   PALETTE
   ============================================ */
.px3k-palette {
    margin-top: 8px;
}
.px3k-palette .px3k-meta-label {
    font-size: 9px;
    display: block;
    margin-bottom: 8px;
}
.px3k-palette-count {
    font-weight: normal;
    color: #9ca3af;
}
.px3k-palette-swatches {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    max-width: 160px;
    margin: 0 auto;
}
.px3k-swatch {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    position: relative;
}
.px3k-swatch-placeholder {
    background: #f3f4f6;
    border-color: #e5e7eb;
    cursor: default;
    opacity: 0.5;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.px3k-swatch:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(255, 107, 157, 0.3);
    z-index: 1;
    border-color: var(--px3k-accent);
}

/* Palette mini (galerie) */
.px3k-palette-mini {
    display: flex;
    gap: 2px;
    justify-content: center;
    margin-top: 6px;
}
.px3k-swatch-mini {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* ============================================
   GALLERY GRID
   ============================================ */
.px3k-pixel-art-gallery {
    margin: 2em 0;
}

/* ============================================
   GALLERY FILMSTRIP
   ============================================ */
.px3k-gallery-filmstrip {
    display: flex;
    flex-direction: row;
    gap: 6px;
    padding: 10px 12px;
    background: #1a1a2e;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 107, 157, 0.4) rgba(0,0,0,0.1);
    border-top: 1px solid rgba(255, 107, 157, 0.2);
}
.px3k-gallery-filmstrip::-webkit-scrollbar {
    height: 4px;
}
.px3k-gallery-filmstrip::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
}
.px3k-gallery-filmstrip::-webkit-scrollbar-thumb {
    background: rgba(255, 107, 157, 0.4);
    border-radius: 2px;
}

.px3k-filmstrip-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    flex-shrink: 0;
    padding: 4px;
    border-radius: 6px;
    border: 2px solid transparent;
    transition: border-color 0.15s, background 0.15s;
}
.px3k-filmstrip-item:hover {
    background: rgba(255, 107, 157, 0.1);
    border-color: rgba(255, 107, 157, 0.4);
}
.px3k-filmstrip-item.active {
    border-color: var(--px3k-accent);
    background: rgba(255, 107, 157, 0.15);
}

.px3k-filmstrip-thumb {
    width: 56px;
    height: 56px;
    object-fit: contain;
    image-rendering: pixelated;
    display: block;
    border-radius: 3px;
    background: repeating-conic-gradient(#c8c8c8 0% 25%, #fff 0% 50%) 0 0 / 8px 8px;
}
.px3k-filmstrip-item.active .px3k-filmstrip-thumb {
    box-shadow: 0 0 0 2px var(--px3k-accent);
}

.px3k-filmstrip-label {
    font-family: 'Press Start 2P', cursive;
    font-size: 5px;
    color: rgba(255,255,255,0.5);
    text-align: center;
    max-width: 64px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}
.px3k-filmstrip-item.active .px3k-filmstrip-label {
    color: var(--px3k-accent);
}

/* Galerie ancienne (grid) — conservée si besoin */
.px3k-gallery-grid {
    display: grid;
    grid-template-columns: repeat(var(--px3k-columns, 3), 1fr);
    gap: var(--px3k-gap, 16px);
}
.px3k-gallery-item {
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: box-shadow 0.3s ease, transform 0.2s ease;
}
.px3k-gallery-item:hover {
    box-shadow: 0 4px 20px rgba(255, 107, 157, 0.15);
    transform: translateY(-2px);
}
.px3k-gallery-image-wrapper {
    position: relative;
    display: inline-block;
}
.px3k-gallery-item-meta {
    margin-top: 8px;
    text-align: center;
}
.px3k-gallery-item-meta .px3k-caption {
    font-size: 8px;
    margin: 2px 0;
}
.px3k-gallery-item-meta .px3k-canvas-size {
    font-size: 7px;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    /* Garder le layout horizontal, max 360px de large */
    .px3k-viewer {
        max-width: 360px;
        width: 360px;
    }
    .px3k-pixel-art-block {
        --px3k-canvas-w: 220px;
        --px3k-canvas-h: 220px;
    }
    .px3k-viewer-sidebar {
        min-width: 0;
        flex: 1;
        padding: 8px;
    }
    .px3k-viewer-toolbar {
        flex-wrap: wrap;
        padding: 6px 8px;
        gap: 4px;
    }

    /* Cacher labels Canevas et Palette (N couleurs) pour gagner la place */
    .px3k-viewer-sidebar .px3k-canvas-size,
    .px3k-viewer-sidebar .px3k-palette > .px3k-meta-label {
        display: none;
    }

    /* Palette en 2 colonnes, espacement minimum */
    .px3k-viewer-sidebar .px3k-palette-swatches {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 3px;
    }
    .px3k-viewer-sidebar .px3k-swatch {
        width: 100%;
        height: 24px;
        border-radius: 3px;
    }
    .px3k-viewer-sidebar .px3k-palette {
        margin-top: 0;
    }
}
@media (max-width: 480px) {
    .px3k-gallery-grid {
        grid-template-columns: 1fr;
    }
    .px3k-toolbar-right {
        display: none;
    }
}

/* ============================================
   COPIED FEEDBACK
   ============================================ */
.px3k-copied-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--px3k-accent, #ff6b9d);
    color: #fff;
    padding: 8px 20px;
    border-radius: 8px;
    font-family: 'Press Start 2P', cursive;
    font-size: 9px;
    z-index: 99999;
    animation: px3k-toast-in 0.3s ease, px3k-toast-out 0.3s ease 1.5s forwards;
    box-shadow: 0 4px 16px rgba(255, 107, 157, 0.4);
}
@keyframes px3k-toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes px3k-toast-out {
    from { opacity: 1; }
    to   { opacity: 0; }
}


@media (max-width: 480px) {

    body .navigation, body .inner-box {
        padding-left: 2rem;
        padding-right: 2rem;
    }
    .px3k-viewer-sidebar .px3k-palette-swatches {
        display: grid;
        grid-template-columns: 1fr;
        gap: 3px;
    }
    .px3k-viewer {
        max-width: 290px;
        width: 360px;
    }
    body .px3k-viewer-sidebar .px3k-swatch {
        width: 16px;
        height: 16px;
        border-radius: 3px;
    }
}