/* =========================================================
   PIXEL ART · lienzo compartido
   ========================================================= */
.px {
    --bg: #140d09;
    --surface: rgba(36, 26, 20, .78);
    --surface-2: rgba(255, 255, 255, .05);
    --line: rgba(255, 170, 148, .16);
    --line-strong: rgba(238, 128, 34, .45);
    --text: #fcece8;
    --muted: #bca199;
    --accent: #ee8022;
    --accent-2: #ff7d7c;
    --stage: #211610;
    --check: rgba(255, 255, 255, .025);

    position: relative;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 14px;
    height: 100vh;
    height: 100svh;
    min-height: 560px;
    padding: 82px clamp(12px, 2.5vw, 28px) 18px;
    background:
        radial-gradient(60% 50% at 15% 0%, rgba(238, 128, 34, .10), transparent 70%),
        radial-gradient(50% 50% at 100% 100%, rgba(255, 125, 124, .12), transparent 70%),
        var(--bg);
    color: var(--text);
    font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
:root[data-theme="light"] .px {
    --bg: #f9f1ee;
    --surface: rgba(255, 255, 255, .86);
    --surface-2: rgba(30, 20, 14, .04);
    --line: rgba(71, 44, 29, .13);
    --line-strong: rgba(144, 69, 14, .45);
    --text: #261a13;
    --muted: #75605a;
    --accent: #90450e;
    --accent-2: #ca3d38;
    --stage: #eee4e1;
    --check: rgba(30, 20, 14, .035);
}
.px *, .px *::before, .px *::after { box-sizing: border-box; }
.px .sr {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Cabecera ---------- */
.px-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 6px 24px;
}
.px-title {
    margin: 0;
    font: 700 clamp(1.7rem, 3.4vw, 2.5rem) / 1 'Chakra Petch', system-ui, sans-serif;
    letter-spacing: .01em;
    background: linear-gradient(110deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.px-lead { margin: 6px 0 0; color: var(--muted); font-size: .95rem; }
.px-stats {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    margin: 0;
    color: var(--muted);
    font-size: .88rem;
}
.px-stats strong { color: var(--text); font-variant-numeric: tabular-nums; }
.px-live { display: inline-flex; align-items: center; gap: 7px; color: var(--text); font-weight: 600; }
.px-live i { color: #34d399; font-size: .85em; }
.px-live.is-off { color: var(--muted); }
.px-live.is-off i { color: #f59e0b; }
.px-coord { font-variant-numeric: tabular-nums; min-width: 5.5em; }

/* tinta: píxeles disponibles (se recarga sola) */
.px-ink { display: inline-flex; align-items: center; gap: 7px; }
.px-ink[hidden] { display: none; }
.px-ink > i { color: var(--accent); }
.px-ink strong { min-width: 2.2em; font-variant-numeric: tabular-nums; }
.px-ink-bar {
    position: relative;
    width: 70px;
    height: 7px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    overflow: hidden;
}
.px-ink-bar i {
    position: absolute;
    inset: 0 auto 0 0;
    width: calc(var(--ink, 1) * 100%);
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    border-radius: inherit;
}
.px-ink.is-low > i, .px-ink.is-low strong { color: #f59e0b; }
.px-ink.is-low .px-ink-bar i { background: #f59e0b; }
.px-ink.is-empty { animation: pxShake .35s ease; }
@keyframes pxShake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* ---------- Lienzo ---------- */
.px-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 18px;
    background:
        conic-gradient(var(--check) 25%, transparent 0 50%, var(--check) 0 75%, transparent 0) 0 0 / 28px 28px,
        var(--stage);
}
.px-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: crosshair;
    outline: none;
}
.px-canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 18px; }
.px[data-tool="move"] .px-canvas,
.px.is-panning .px-canvas { cursor: grab; }
.px.is-dragging .px-canvas { cursor: grabbing; }
.px[data-tool="picker"] .px-canvas { cursor: copy; }

.px-loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    grid-auto-flow: column;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-weight: 600;
    pointer-events: none;
    transition: opacity .3s ease;
}
.px-loading span {
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid var(--line); border-top-color: var(--accent);
    animation: pxSpin .8s linear infinite;
}
.px-loading.is-done { opacity: 0; }
@keyframes pxSpin { to { transform: rotate(360deg); } }

.px-hint {
    position: absolute;
    left: 50%;
    bottom: 12px;
    margin: 0;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: .8rem;
    white-space: nowrap;
    transform: translateX(-50%);
    pointer-events: none;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: opacity .5s ease;
}
.px-hint.is-gone { opacity: 0; }
.px-hint-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
    .px-hint-desk { display: none; }
    .px-hint-touch { display: inline; }
}

/* ---------- Barra de herramientas ---------- */
.px-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px 18px;
    align-self: center;
    max-width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}
.px-group { display: flex; align-items: center; gap: 6px; }

.px-btn {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
}
.px-btn:hover { border-color: var(--line-strong); color: var(--accent); }
.px-btn:active { transform: scale(.94); }
.px-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.px-btn.is-on,
.px-btn[aria-pressed="true"]:not([data-tool]) {
    border-color: transparent;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
}
.px-btn[aria-pressed="true"]:not([data-tool]) { background: var(--surface-2); color: var(--accent); border-color: var(--line-strong); }
.px-btn:disabled { opacity: .35; cursor: default; transform: none; color: var(--text); border-color: var(--line); }

.px-colors { gap: 10px; }
.px-current {
    position: relative;
    display: block;
    width: 44px;
    height: 44px;
    flex: none;
    border-radius: 12px;
    border: 1px solid var(--line-strong);
    background:
        conic-gradient(#ccc 25%, #fff 0 50%, #ccc 0 75%, #fff 0) 0 0 / 10px 10px;
    cursor: pointer;
    overflow: hidden;
}
.px-current-sw { position: absolute; inset: 0; }
.px-current::after {                       /* icono de «más colores» */
    content: "";
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .3);
}
.px-current input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    border: 0;
    padding: 0;
}
.px-current:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.px-palette {
    display: grid;
    grid-template-columns: repeat(16, 24px);
    grid-auto-rows: 20px;
    gap: 4px;
}
.px-sw {
    width: 24px;
    height: 20px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, .25);
    border-radius: 6px;
    cursor: pointer;
    transition: transform .1s ease;
}
:root[data-theme="dark"] .px-sw { border-color: rgba(255, 255, 255, .14); }
.px-sw:hover { transform: scale(1.15); }
.px-sw:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.px-sw[aria-checked="true"] {
    transform: scale(1.12);
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
    z-index: 1;
}

/* ---------- Aviso ---------- */
.px-toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    z-index: 60;
    padding: 10px 18px;
    border-radius: 12px;
    background: #251713;
    color: #fff;
    font-size: .9rem;
    font-weight: 600;
    box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .5);
    opacity: 0;
    transform: translate(-50%, 12px);
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease;
}
.px-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* deja sitio al botón de modo claro / oscuro (fijo abajo a la izquierda) */
@media (max-width: 1340px) and (min-width: 761px) {
    .px { padding-bottom: 72px; }
}

/* ---------- Móvil ---------- */
@media (max-width: 760px) {
    .px { padding: 76px 10px 84px; gap: 10px; min-height: 520px; }
    .px-lead { display: none; }
    .px-stats { font-size: .8rem; gap: 4px 12px; }
    .px-bar { gap: 8px; padding: 8px; }
    .px-btn { width: 36px; height: 36px; border-radius: 10px; }
    .px-colors { width: 100%; }
    .px-palette {
        grid-template-columns: none;
        grid-auto-flow: column;
        grid-template-rows: repeat(2, 22px);
        grid-auto-columns: 26px;
        overflow-x: auto;
        padding: 4px;
        scrollbar-width: thin;
    }
    .px-sw { width: 26px; height: 22px; }
    .px-coord { display: none; }
    .px-ink-bar { width: 46px; }
}

@media (prefers-reduced-motion: reduce) {
    .px *, .px *::before, .px *::after { animation: none !important; transition: none !important; }
}

/* el pie de página no hace falta debajo del lienzo */
body.tema-pixel .footer-portada { margin-top: 0; }
