/* ===================================================================
   ppuzzl.bar — pixel-art honeycomb puzzle parlor
   Palette: #FFC857 #5B8DEF #E84A5F #1B1A33 #2E2C4D #FFF6E0 #9A88FF
   Type: Press Start 2P (display) + Fredoka (body) + Baloo 2 (meta)
   =================================================================== */

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

:root {
    --coin-gold: #FFC857;
    --plumber-blue: #5B8DEF;
    --berry-smash: #E84A5F;
    --cabinet-plum: #1B1A33;
    --dither-plum: #2E2C4D;
    --coaster-cream: #FFF6E0;
    --joystick-lilac: #9A88FF;

    --hex-flat: clamp(140px, 14vw, 200px);
    /* Hex height (point-to-point) for a hex with horizontal flats: width * 2/sqrt(3) ≈ 1.1547 */
    --hex-height: calc(var(--hex-flat) * 1.1547);
    /* Vertical step between rows (3/4 of height for tessellation) */
    --hex-row-step: calc(var(--hex-height) * 0.75);
    /* Horizontal step between columns */
    --hex-col-step: var(--hex-flat);

    --pixel-shadow: 4px 4px 0 var(--cabinet-plum);
    --pixel-shadow-hover: 4px 4px 0 var(--cabinet-plum), 8px 8px 0 rgba(0, 0, 0, 0.35);
}

html, body {
    background: var(--cabinet-plum);
    color: var(--coaster-cream);
    font-family: 'Fredoka', sans-serif;
    overflow-x: auto;
    overflow-y: hidden;
    height: 100vh;
    width: 100vw;
}

/* Global pixelation enforcement */
img, svg {
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    shape-rendering: crispEdges;
}

/* Backdrop dither pattern (Bayer-ish via repeating gradient) */
body {
    background-color: var(--cabinet-plum);
    background-image:
        repeating-conic-gradient(
            var(--cabinet-plum) 0% 25%,
            var(--dither-plum) 25% 50%
        );
    background-size: 8px 8px;
    background-position: 0 0;
}

/* ============== HUD: Coin counter ============== */
.hud {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--cabinet-plum);
    border: 3px solid var(--coin-gold);
    box-shadow: var(--pixel-shadow);
    font-family: 'Press Start 2P', monospace;
    font-size: 0.7rem;
    color: var(--coin-gold);
    letter-spacing: 0.05em;
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: grayscale;
    image-rendering: pixelated;
    clip-path: polygon(
        0 6px, 6px 0,
        calc(100% - 6px) 0, 100% 6px,
        100% calc(100% - 6px), calc(100% - 6px) 100%,
        6px 100%, 0 calc(100% - 6px)
    );
}

.hud-coin {
    display: inline-flex;
    width: 16px;
    height: 16px;
    animation: coin-spin 1.4s steps(3) infinite;
}

.hud-count {
    color: var(--coaster-cream);
    min-width: 1.6em;
    display: inline-block;
}

.hud-count.bumped {
    animation: count-bump 0.18s steps(2);
}

@keyframes coin-spin {
    0%   { transform: scaleX(1); }
    33%  { transform: scaleX(0.4); }
    66%  { transform: scaleX(0.1); }
    100% { transform: scaleX(1); }
}

@keyframes count-bump {
    0%   { transform: scale(1); color: var(--coin-gold); }
    50%  { transform: scale(1.3); color: var(--berry-smash); }
    100% { transform: scale(1); color: var(--coaster-cream); }
}

/* ============== Brand mark ============== */
.brand {
    position: fixed;
    top: 22px;
    right: 28px;
    z-index: 100;
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(1.4rem, 2.4vw, 2rem);
    color: var(--coin-gold);
    letter-spacing: 0.08em;
    -webkit-font-smoothing: none;
    text-shadow:
        2px 2px 0 var(--cabinet-plum),
        4px 4px 0 var(--berry-smash);
}

.brand-tld {
    color: var(--joystick-lilac);
    text-shadow:
        2px 2px 0 var(--cabinet-plum),
        4px 4px 0 var(--plumber-blue);
}

.brand-blink {
    display: inline-block;
    color: var(--coaster-cream);
    margin-left: 4px;
    animation: blink 1s steps(2) infinite;
}

@keyframes blink {
    0%, 50%   { opacity: 1; }
    50.01%, 100% { opacity: 0; }
}

/* ============== Reading hint ============== */
.reading-hint {
    position: fixed;
    bottom: 30px;
    left: 28px;
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--dither-plum);
    border: 3px solid var(--joystick-lilac);
    box-shadow: var(--pixel-shadow);
    font-family: 'Baloo 2', sans-serif;
    font-size: 0.75rem;
    color: var(--coaster-cream);
    font-weight: 500;
    letter-spacing: 0.04em;
}

.hint-arrow {
    color: var(--coin-gold);
    font-family: 'Press Start 2P', monospace;
    font-size: 0.65rem;
    animation: arrow-tap 1.6s steps(4) infinite;
}

@keyframes arrow-tap {
    0%, 60%   { transform: translateX(0); }
    70%       { transform: translateX(3px); }
    80%       { transform: translateX(0); }
    90%       { transform: translateX(3px); }
    100%      { transform: translateX(0); }
}

/* ============== Scroll hint ============== */
.scroll-hint {
    position: fixed;
    bottom: 30px;
    right: 28px;
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--dither-plum);
    border: 3px solid var(--coin-gold);
    box-shadow: var(--pixel-shadow);
    font-family: 'Press Start 2P', monospace;
    font-size: 0.6rem;
    color: var(--coin-gold);
    -webkit-font-smoothing: none;
    letter-spacing: 0.05em;
}

.scroll-hint-arrow {
    animation: scroll-arrow 1.2s steps(3) infinite;
    color: var(--berry-smash);
}

@keyframes scroll-arrow {
    0%   { opacity: 0.3; }
    33%  { opacity: 0.6; }
    66%  { opacity: 1; }
    100% { opacity: 0.3; }
}

/* ============== Honeycomb container ============== */
.honeycomb {
    perspective: 1200px;
    perspective-origin: 70% 30%;
    width: max-content;
    min-width: 100vw;
    min-height: 100vh;
    padding: 120px 200px 140px;
    position: relative;
}

.board {
    transform-style: preserve-3d;
    transform: rotateX(14deg) rotateY(-6deg);
    transform-origin: center center;
    transition: transform 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
    /* Grid for honeycomb */
    display: grid;
    grid-template-columns: repeat(8, var(--hex-flat));
    grid-auto-rows: var(--hex-row-step);
    gap: 0;
    position: relative;
}

/* Sprite defs hidden */
.sprite-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* ============== Hex base ============== */
.hex {
    width: var(--hex-flat);
    height: var(--hex-height);
    /* Regular hex with horizontal flat-top: alternative is point-top */
    /* Using point-top hex to match clip-path 25/75 spec from DESIGN */
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    grid-column: calc(var(--col) + 1);
    grid-row: calc(var(--row) + 1);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transform: translateZ(0) translateX(var(--row-offset, 0));
    transform-style: preserve-3d;
    transition:
        transform 180ms cubic-bezier(0.5, 0, 0.5, 1.6),
        filter 180ms steps(3);
    cursor: pointer;
    opacity: 0;
    will-change: transform;
}

/* Offset every other row by half a column for honeycomb */
.hex[style*="--row:1"],
.hex[style*="--row:3"],
.hex[style*="--row:5"] {
    --row-offset: calc(var(--hex-flat) / 2);
}

/* Reveal animation triggered by JS */
.hex.is-revealed {
    animation: hex-pop 380ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes hex-pop {
    0%   { opacity: 0; transform: translateZ(-100px) translateX(var(--row-offset, 0)) scale(0); }
    60%  { opacity: 1; transform: translateZ(20px) translateX(var(--row-offset, 0)) scale(1.12); }
    80%  { transform: translateZ(0) translateX(var(--row-offset, 0)) scale(0.96); }
    100% { opacity: 1; transform: translateZ(0) translateX(var(--row-offset, 0)) scale(1); }
}

/* ============== Decorative dithered hexes ============== */
.hex--decor {
    background:
        repeating-conic-gradient(
            from 45deg,
            var(--cabinet-plum) 0% 25%,
            var(--dither-plum) 25% 50%
        );
    background-size: 6px 6px;
    pointer-events: none;
}

.hex--decor.hex--dither-a {
    background:
        repeating-conic-gradient(
            from 0deg,
            var(--cabinet-plum) 0% 25%,
            var(--dither-plum) 25% 50%
        );
    background-size: 4px 4px;
}

.hex--decor.hex--dither-b {
    background:
        repeating-linear-gradient(
            45deg,
            var(--cabinet-plum) 0px 3px,
            var(--dither-plum) 3px 6px
        );
}

/* ============== Triadic color hexes ============== */
.hex--gold {
    background-color: var(--cabinet-plum);
    background-image:
        radial-gradient(circle at 50% 50%, var(--coin-gold) 0%, var(--coin-gold) 60%, var(--cabinet-plum) 60.1%);
    color: var(--cabinet-plum);
}

.hex--blue {
    background-color: var(--cabinet-plum);
    background-image:
        radial-gradient(circle at 50% 50%, var(--plumber-blue) 0%, var(--plumber-blue) 60%, var(--cabinet-plum) 60.1%);
    color: var(--coaster-cream);
}

.hex--red {
    background-color: var(--cabinet-plum);
    background-image:
        radial-gradient(circle at 50% 50%, var(--berry-smash) 0%, var(--berry-smash) 60%, var(--cabinet-plum) 60.1%);
    color: var(--coaster-cream);
}

/* ============== Puzzle hex content (sprites) ============== */
.hex--puzzle {
    flex-direction: column;
    gap: 8px;
}

.hex--puzzle .pixel-sprite {
    width: 60px;
    height: 60px;
    color: currentColor;
}

.hex-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.55rem;
    color: currentColor;
    -webkit-font-smoothing: none;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    margin-top: 4px;
    text-shadow: 1px 1px 0 var(--cabinet-plum);
}

/* ============== Speech hex content ============== */
.hex--speech {
    padding: 14% 18%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.hex-num {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.55rem;
    color: var(--cabinet-plum);
    background: var(--coaster-cream);
    padding: 3px 5px;
    -webkit-font-smoothing: none;
    position: absolute;
    top: 30%;
    left: 14%;
    letter-spacing: 0.05em;
}

.hex--blue .hex-num,
.hex--red .hex-num {
    color: var(--cabinet-plum);
    background: var(--coin-gold);
}

.hex--gold .hex-num {
    color: var(--coaster-cream);
    background: var(--berry-smash);
}

.hex-text {
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(0.7rem, 0.85vw, 0.92rem);
    line-height: 1.4;
    font-weight: 400;
    color: currentColor;
    max-width: 100%;
    word-break: break-word;
    text-shadow: 1px 1px 0 rgba(27, 26, 51, 0.45);
}

.hex-text strong,
.hex-text em {
    font-weight: 600;
    color: currentColor;
    font-style: normal;
    background: rgba(255, 246, 224, 0.18);
    padding: 1px 4px;
}

.hex--gold .hex-text strong,
.hex--gold .hex-text em {
    background: rgba(27, 26, 51, 0.25);
    color: var(--cabinet-plum);
}

/* ============== Speech-hex pixel tails ============== */
.hex-tail {
    position: absolute;
    width: 18px;
    height: 18px;
    pointer-events: none;
}

.hex-tail::before,
.hex-tail::after {
    content: '';
    position: absolute;
    background: currentColor;
}

.hex-tail--right {
    right: -8px;
    top: 60%;
    color: inherit;
}

.hex-tail--right::before {
    left: 0;
    top: 0;
    width: 4px;
    height: 4px;
    background: currentColor;
    box-shadow:
        4px 4px 0 currentColor,
        8px 8px 0 currentColor;
}

.hex-tail--down {
    bottom: 0;
    left: 50%;
    color: inherit;
}

.hex-tail--down::before {
    left: 0;
    bottom: 0;
    width: 4px;
    height: 4px;
    background: currentColor;
    box-shadow:
        4px 4px 0 currentColor,
        -4px 4px 0 currentColor;
}

/* ============== Hex hover (the lift) ============== */
.hex:not(.hex--decor):hover,
.hex:not(.hex--decor):focus {
    transform: translateZ(40px) translateX(var(--row-offset, 0)) scale(1.04);
    z-index: 5;
    filter: brightness(1.08) saturate(1.15);
}

.hex:not(.hex--decor):hover::after,
.hex:not(.hex--decor):focus::after {
    content: '';
    position: absolute;
    inset: 0;
    box-shadow:
        4px 4px 0 var(--cabinet-plum),
        8px 8px 0 rgba(0, 0, 0, 0.35);
    clip-path: inherit;
    pointer-events: none;
    z-index: -1;
    background: currentColor;
    opacity: 0.001;
}

/* Active state — pixel snap-down */
.hex:not(.hex--decor):active {
    transform: translateZ(10px) translateX(var(--row-offset, 0)) scale(0.98);
    transition: transform 80ms steps(2);
}

/* ============== Pixel strip footer ============== */
.pixel-strip {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 8px;
    display: flex;
    z-index: 50;
    pointer-events: none;
}

.pixel-strip-cell {
    flex: 1;
    height: 100%;
}

.pixel-strip-cell:nth-child(1)  { background: var(--coin-gold); }
.pixel-strip-cell:nth-child(2)  { background: var(--plumber-blue); }
.pixel-strip-cell:nth-child(3)  { background: var(--berry-smash); }
.pixel-strip-cell:nth-child(4)  { background: var(--joystick-lilac); }
.pixel-strip-cell:nth-child(5)  { background: var(--coin-gold); }
.pixel-strip-cell:nth-child(6)  { background: var(--plumber-blue); }
.pixel-strip-cell:nth-child(7)  { background: var(--berry-smash); }
.pixel-strip-cell:nth-child(8)  { background: var(--joystick-lilac); }

/* ============== Connector lines (revealed when hex focused) ============== */
.board.show-path::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        repeating-linear-gradient(
            45deg,
            transparent 0 6px,
            var(--joystick-lilac) 6px 9px,
            transparent 9px 18px
        );
    opacity: 0.18;
    mix-blend-mode: screen;
}

/* ============== Scrollbar styling for arcade feel ============== */
body::-webkit-scrollbar {
    height: 14px;
}

body::-webkit-scrollbar-track {
    background: var(--dither-plum);
    border-top: 2px solid var(--cabinet-plum);
}

body::-webkit-scrollbar-thumb {
    background: var(--coin-gold);
    border: 2px solid var(--cabinet-plum);
}

body::-webkit-scrollbar-thumb:hover {
    background: var(--berry-smash);
}

/* ============== Responsive: stack on small screens ============== */
@media (max-width: 720px) {
    :root {
        --hex-flat: clamp(110px, 22vw, 150px);
    }

    .board {
        grid-template-columns: repeat(4, var(--hex-flat));
        transform: rotateX(8deg) rotateY(-3deg);
    }

    /* Hide the columns 4-7 on small screens by collapsing them */
    .hex[style*="--col:4"],
    .hex[style*="--col:5"],
    .hex[style*="--col:6"],
    .hex[style*="--col:7"] {
        display: none;
    }

    .brand {
        font-size: 1.1rem;
    }

    .hud,
    .scroll-hint,
    .reading-hint {
        font-size: 0.55rem;
        padding: 8px 10px;
    }

    .hex-text {
        font-size: 0.65rem;
    }
}

/* ============== High-contrast / reduced motion fallback ============== */
@media (prefers-reduced-motion: reduce) {
    .hex,
    .board,
    .hud-coin,
    .brand-blink,
    .scroll-hint-arrow,
    .hint-arrow {
        animation: none !important;
        transition: none !important;
    }

    .hex {
        opacity: 1;
    }
}
