/* Pixels — HUD, pixel layer, ghost cursor, cosmetic hooks. See KB/04,05,07. */

@property --accent {
    syntax: '<color>';
    inherits: true;
    initial-value: #4DA3FF;
}
@property --accent-2 {
    syntax: '<color>';
    inherits: true;
    initial-value: #7C5CFF;
}

/* The UA stylesheet's [hidden] { display: none } loses specificity against
   ID selectors that set display below, so re-assert it explicitly. Without
   this, #px-panel and #px-modal would show on every page load. */
#px-chip[hidden],
#px-panel[hidden],
#px-modal[hidden],
#px-reveal[hidden] {
    display: none;
}

#px-sentinel {
    height: 48px;
    margin-top: 28px;
}

#px-root {
    --pixel-color: var(--accent);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    color: var(--text);
}

#pixel-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 9998;
}

.px-pixel {
    position: absolute;
    color: var(--pixel-color);
    font-size: 14px;
    line-height: 1;
    opacity: 0;
    transform: translate(-50%, -50%);
    animation: px-pixel 1500ms ease-out forwards;
    will-change: transform, opacity;
    pointer-events: none;
}

.px-pixel.px-rm {
    animation: px-pixel-rm 700ms ease-out forwards;
}

@keyframes px-pixel {
    0%   { opacity: 0; transform: translate(-50%, -50%); }
    10%  { opacity: 0.85; }
    35%  { transform: translate(-50%, calc(-50% + var(--dy, 6px))); opacity: 0.85; }
    70%  { opacity: 0.6; }
    100% { opacity: 0; transform: translate(-50%, calc(-50% + var(--dy, 6px) + 2px)); }
}

@keyframes px-pixel-rm {
    0%   { opacity: 0; }
    25%  { opacity: 0.7; }
    100% { opacity: 0; }
}

.px-cursor-trail .px-pixel {
    text-shadow: 0 0 6px var(--pixel-color);
    animation-duration: 2400ms;
}

/* HUD chip + panel */

#px-chip {
    position: fixed;
    right: 16px;
    bottom: 16px;
    min-width: 56px;
    height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    background: rgba(17, 20, 27, 0.86);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 12px;
    letter-spacing: 0.04em;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: transform .15s ease, border-color .2s ease, background .2s ease;
    animation: px-chip-in 420ms ease-out;
    z-index: 9999;
}

#px-chip:hover {
    border-color: var(--accent);
    background: rgba(17, 20, 27, 0.94);
    transform: translateY(-1px);
}

#px-chip:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@keyframes px-chip-in {
    from { transform: translateY(48px); opacity: 0; }
    to   { transform: none; opacity: 1; }
}

#px-panel {
    position: fixed;
    right: 16px;
    bottom: 16px;
    width: 280px;
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    background: rgba(17, 20, 27, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 12px;
    overflow: hidden;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 9999;
    animation: px-chip-in 220ms ease-out;
}

#px-panel header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#px-count {
    font-weight: 600;
    font-size: 14px;
    color: #F4F8FF;
}

#px-rate {
    color: var(--text-dim);
    font-size: 11px;
    margin-top: 2px;
}

#px-close {
    background: transparent;
    border: 0;
    color: var(--text-dim);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
}

#px-close:hover { color: var(--text); }
#px-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#px-upgrades {
    list-style: none;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    flex: 1 1 auto;
}

#px-upgrades li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 8px;
}

#px-upgrades li:hover { background: rgba(255, 255, 255, 0.04); }

.px-up-info { flex: 1 1 auto; min-width: 0; }
.px-up-name { color: var(--text); font-weight: 500; }
.px-up-lvl  { color: var(--text-dim); font-weight: 400; font-size: 10px; margin-left: 4px; }
.px-up-desc { color: var(--text-dim); font-size: 11px; margin-top: 2px; }

.px-up-buy {
    flex: 0 0 auto;
    min-width: 48px;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease;
}

.px-up-buy:hover:not(:disabled) {
    background: rgba(77, 163, 255, 0.15);
    border-color: rgba(77, 163, 255, 0.35);
}

.px-up-buy:disabled { opacity: 0.4; cursor: not-allowed; }
.px-up-buy:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#px-panel footer {
    padding: 6px 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: flex-end;
}

#px-help {
    background: transparent;
    border: 0;
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-family: inherit;
}

#px-help:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
#px-help:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Modal */

#px-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    z-index: 10000;
}

#px-modal-card {
    max-width: 380px;
    margin: 20px;
    background: var(--bg-2);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 20px;
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 13px;
    line-height: 1.55;
}

#px-modal-card h3 {
    margin-bottom: 8px;
    font-size: 14px;
    color: #F4F8FF;
}

#px-modal-card p { color: var(--text-dim); }
#px-modal-card p + p { margin-top: 8px; }

.px-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 14px;
}

.px-modal-actions button {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.px-modal-actions button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

#px-reset { color: var(--text-dim); }
#px-reset:hover { color: #ff8d8d; border-color: rgba(255, 141, 141, 0.4); }

/* Toast */

#px-toast {
    position: fixed;
    right: 16px;
    bottom: 64px;
    padding: 10px 14px;
    border-radius: 8px;
    background: rgba(17, 20, 27, 0.96);
    border: 1px solid rgba(77, 163, 255, 0.5);
    color: var(--text);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 12px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .3s ease, transform .3s ease;
    pointer-events: none;
    z-index: 9999;
}

#px-toast.px-toast-show {
    opacity: 1;
    transform: none;
}

/* Awakening reveal */

#px-reveal {
    position: fixed;
    left: 50%;
    bottom: 22%;
    transform: translateX(-50%);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 13px;
    color: var(--accent);
    letter-spacing: 0.08em;
    opacity: 0;
    transition: opacity .8s ease;
    pointer-events: none;
    z-index: 9999;
}

#px-reveal.px-reveal-show { opacity: 0.9; }

/* Ghost cursor */

#px-ghost {
    position: fixed;
    left: 0;
    top: 0;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.32;
    pointer-events: none;
    z-index: 9997;
    will-change: transform;
    box-shadow: 0 0 6px var(--accent);
}

/* Cosmetic body classes */

/* accent-shift is driven by JS (pixels.js manageAccentShift) via
   style.setProperty on :root — CSS animation on body had unreliable
   cross-browser custom-property inheritance to descendants. */

body.px-badge-glow .badge-year {
    box-shadow: 0 0 10px rgba(77, 163, 255, 0.45);
}

@media (prefers-reduced-motion: reduce) {
    #px-chip { animation: none; }
    #px-panel { animation: none; }
}

@media (max-width: 640px) {
    #px-panel { width: calc(100vw - 32px); }

    /* Respect iPhone home-indicator safe area */
    #px-chip  { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
    #px-panel { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
    #px-toast { bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }

    /* Larger touch targets inside the HUD */
    .px-up-buy {
        min-height: 36px;
        padding: 8px 10px;
    }
    #px-close {
        min-width: 36px;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}
