/* ============================================================
   THEME: MEMPHIS + POP ART + ART DECO + Y2K
   ENHANCED: 3D DEPTH + 4D TIME/SPACE EFFECTS
   ============================================================ */
:root {
    --ink: #0B0B0B;
    --hot: #FF2D8F;
    --cyan: #00D9FF;
    --yellow: #FFE81A;
    --purple: #7B2FF7;
    --orange: #FF7A00;
    --mint: #00E07A;
    --gold: #E8B84B;
    --cream: #FFF8EC;
    --white: #FFFFFF;
    --hard: 5px 5px 0 var(--ink);
    --hard-lg: 9px 9px 0 var(--ink);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Rubik', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html, body { height: 100%; }

body {
    min-height: 100vh;
    color: var(--ink);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 26px 18px;
    overflow-x: hidden;
    /* 4D: animated halftone background that shifts hue over time */
    background-color: #FFF1DC;
    background-image:
        radial-gradient(circle, rgba(255,45,143,.22) 1.6px, transparent 1.7px),
        radial-gradient(circle, rgba(0,217,255,.22) 1.6px, transparent 1.7px);
    background-size: 28px 28px, 28px 28px;
    background-position: 0 0, 14px 14px;
    animation: bgShift 30s linear infinite;
    /* 3D: perspective for the whole scene */
    perspective: 1600px;
    perspective-origin: 50% 50%;
}

/* 4D: slow ambient hue rotation of the dot pattern */
@keyframes bgShift {
    0%   { background-position: 0 0, 14px 14px; }
    50%  { background-position: 14px 14px, 0 0; }
    100% { background-position: 0 0, 14px 14px; }
}

/* ---------- 3D FLOATING MEMPHIS SHAPES (4D motion) ---------- */
.shapes {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
    perspective: 1200px;
    perspective-origin: 50% 50%;
}
.shape {
    position: absolute;
    border: 3px solid var(--ink);
    animation: drift3D 16s infinite ease-in-out;
    opacity: .9;
    will-change: transform, translate;
    transform-origin: 50% 50%;
}
.shape.circle   { border-radius: 50%; }
.shape.square   { border-radius: 4px; }
.shape.ring     { border-radius: 50%; background: transparent !important; }
.shape.triangle {
    border: none;
    clip-path: polygon(50% 4%, 96% 96%, 4% 96%);
}
.shape.star {
    border: none;
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

/* 4D drift: rotates through 3D axes over time */
@keyframes drift3D {
    0%, 100% { transform: translateY(0) rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
    25%      { transform: translateY(-20px) rotateX(18deg) rotateY(-12deg) rotateZ(6deg); }
    50%      { transform: translateY(-28px) rotateX(0deg) rotateY(22deg) rotateZ(0deg); }
    75%      { transform: translateY(-14px) rotateX(-12deg) rotateY(10deg) rotateZ(-6deg); }
}

/* ---------- APP SHELL: 3D + 4D GLOW PULSE + FLOAT ---------- */
#app {
    width: 100%;
    max-width: 940px;
    min-height: 82vh;
    background: var(--cream);
    border: 4px solid var(--ink);
    border-radius: 20px;
    box-shadow:
        12px 12px 0 var(--ink),
        0 25px 50px rgba(0,0,0,.18),
        0 8px 16px rgba(0,0,0,.1);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 10;
    transform-style: preserve-3d;
    will-change: transform;
    /* 4D: time-based color cycle + floating levitation */
    animation:
        glowPulse 10s ease-in-out infinite,
        floatApp 7s ease-in-out infinite;
}

/* 4D: glow cycles through the brand palette over 10 seconds */
@keyframes glowPulse {
    0%, 100% {
        box-shadow:
            12px 12px 0 var(--ink),
            0 25px 50px rgba(255,45,143,.30),
            0 8px 16px rgba(0,0,0,.10);
    }
    25% {
        box-shadow:
            12px 12px 0 var(--ink),
            0 25px 50px rgba(0,217,255,.30),
            0 8px 16px rgba(0,0,0,.10);
    }
    50% {
        box-shadow:
            12px 12px 0 var(--ink),
            0 25px 50px rgba(255,232,26,.35),
            0 8px 16px rgba(0,0,0,.10);
    }
    75% {
        box-shadow:
            12px 12px 0 var(--ink),
            0 25px 50px rgba(123,47,247,.30),
            0 8px 16px rgba(0,0,0,.10);
    }
}

/* 4D: slow vertical levitation (uses translate, separate from JS transform) */
@keyframes floatApp {
    0%, 100% { translate: 0 0; }
    50%      { translate: 0 -6px; }
}

/* Art Deco gold inner frame (3D: subtle inner bevel via inset shadow) */
#app::after {
    content: '';
    position: absolute;
    inset: 9px;
    border: 2px solid rgba(232,184,75,.85);
    border-radius: 13px;
    pointer-events: none;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.4);
}

/* ---------- HEADER ---------- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    border-bottom: 4px solid var(--ink);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    position: relative;
}

/* 3D pop-up title with layered drop-shadows */
h1 {
    font-family: 'Bungee', cursive;
    font-size: 1.85rem;
    line-height: 1.1;
    letter-spacing: .5px;
    background: linear-gradient(180deg, #ffffff 0%, #FFE81A 32%, #FF2D8F 68%, #7B2FF7 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-stroke: 2px var(--ink);
    filter:
        drop-shadow(3px 3px 0 rgba(11,11,11,.9))
        drop-shadow(6px 6px 10px rgba(0,0,0,.35));
}

/* 3D chrome score badge with inset bevel */
.score-badge {
    font-family: 'Bungee', cursive;
    font-size: .85rem;
    letter-spacing: .5px;
    white-space: nowrap;
    padding: .55rem 1.15rem;
    border: 3px solid var(--ink);
    border-radius: 999px;
    color: var(--ink);
    background: linear-gradient(180deg,
        #ffffff 0%, #e9eff4 35%, #a9b7c4 48%,
        #ffffff 56%, #dfe7ee 75%, #ffffff 100%);
    box-shadow:
        4px 4px 0 var(--ink),
        inset 0 2px 0 rgba(255,255,255,1),
        inset 0 -3px 4px rgba(0,0,0,.18);
}

/* ---------- SCREENS ---------- */
.screen { display: none; flex: 1; }
.screen.active {
    display: flex;
    flex-direction: column;
    animation: fadeIn .35s ease-out;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- TYPOGRAPHY ---------- */
h2 {
    font-family: 'Bungee', cursive;
    font-size: 1.3rem;
    letter-spacing: .5px;
    color: var(--ink);
    text-shadow:
        2px 2px 0 var(--yellow),
        4px 4px 0 rgba(11,11,11,.15);
    margin-bottom: 1.1rem;
}

/* ---------- NAV BAR: 3D raised panel ---------- */
.nav-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    background: var(--white);
    border: 3px solid var(--ink);
    border-radius: 14px;
    box-shadow:
        4px 4px 0 var(--ink),
        0 8px 16px rgba(0,0,0,.12),
        inset 0 2px 0 rgba(255,255,255,1);
    padding: .5rem .7rem;
    margin-bottom: 1.4rem;
}
.nav-btn {
    background: transparent;
    border: 3px solid transparent;
    border-radius: 999px;
    padding: .45rem .95rem;
    font-weight: 800;
    font-size: .95rem;
    color: var(--ink);
    cursor: pointer;
    transition: background .15s, transform .12s, border-color .15s, box-shadow .15s;
}
.nav-btn:hover:not(:disabled) {
    background: var(--cyan);
    border-color: var(--ink);
    transform: translate(-2px, -2px);
    box-shadow: 3px 3px 0 var(--ink), 0 6px 12px rgba(0,0,0,.15);
}
.nav-btn:active:not(:disabled) {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0 var(--ink);
}
.nav-btn:disabled {
    opacity: .35;
    cursor: not-allowed;
}

/* ---------- GRID: 3D perspective stage ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.4rem;
    margin-top: .5rem;
    perspective: 1000px;
    perspective-origin: 50% 50%;
}

/* ---------- CARDS: 3D POP + shine + depth ---------- */
.card {
    position: relative;
    overflow: hidden;
    border: 3px solid var(--ink);
    border-radius: 16px;
    padding: 2rem 1.2rem 1.4rem;
    text-align: center;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transform-style: preserve-3d;
    transform-origin: 50% 50%;
    background:
        radial-gradient(ellipse at 25% 15%, rgba(255,255,255,.85) 0%, transparent 55%),
        linear-gradient(135deg, rgba(255,255,255,.5) 0%, transparent 60%),
        var(--white);
    box-shadow:
        6px 6px 0 var(--ink),
        0 10px 20px rgba(0,0,0,.12);
    transition:
        transform .25s cubic-bezier(.34,1.56,.64,1),
        box-shadow .25s ease,
        background .2s ease;
}
/* Memphis colour strip on top of every card */
.card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 9px;
    background: var(--hot);
    border-bottom: 3px solid var(--ink);
    box-shadow: 0 2px 0 rgba(0,0,0,.1);
    z-index: 2;
}
.card:nth-child(6n+2)::before { background: var(--cyan); }
.card:nth-child(6n+3)::before { background: var(--yellow); }
.card:nth-child(6n+4)::before { background: var(--purple); }
.card:nth-child(6n+5)::before { background: var(--orange); }
.card:nth-child(6n)::before   { background: var(--mint); }

/* Ben-Day dot corner */
.card::after {
    content: '';
    position: absolute;
    right: -14px; bottom: -14px;
    width: 84px; height: 84px;
    background-image: radial-gradient(var(--ink) 1.6px, transparent 1.7px);
    background-size: 9px 9px;
    opacity: .16;
    pointer-events: none;
}

/* 3D hover: card pops out of the screen and tilts */
.card:hover {
    transform: translateZ(30px) rotateX(-5deg) rotateY(5deg) translate(-3px, -3px);
    background:
        radial-gradient(ellipse at 25% 15%, rgba(255,255,255,1) 0%, transparent 55%),
        linear-gradient(135deg, rgba(255,255,255,.65) 0%, transparent 60%),
        var(--white);
    box-shadow:
        12px 12px 0 var(--ink),
        0 30px 50px rgba(0,0,0,.28);
}
.card:active {
    transform: translateZ(5px) translate(2px, 2px);
    box-shadow:
        3px 3px 0 var(--ink),
        0 5px 10px rgba(0,0,0,.15);
}

/* 3D icon drop-shadow */
.card-icon {
    font-size: 2.5rem;
    line-height: 1;
    margin-bottom: .6rem;
    filter:
        drop-shadow(2px 2px 0 rgba(11,11,11,.25))
        drop-shadow(4px 4px 6px rgba(0,0,0,.15));
}
.card h3 {
    font-family: 'Rubik', sans-serif;
    font-weight: 900;
    font-size: 1.05rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink);
    margin-bottom: .25rem;
}
.card p {
    font-size: .85rem;
    font-weight: 500;
    color: #5a5a5a;
}

/* ---------- GAME UI ---------- */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
    font-weight: 900;
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    margin-bottom: .7rem;
}

/* 3D grooved progress track */
.progress-bar {
    width: 100%;
    height: 22px;
    background: var(--white);
    border: 3px solid var(--ink);
    border-radius: 999px;
    box-shadow:
        inset 0 3px 6px rgba(0,0,0,.18),
        3px 3px 0 var(--ink);
    overflow: hidden;
    margin-bottom: 1.4rem;
}
.progress-fill {
    height: 100%;
    width: 0%;
    background: repeating-linear-gradient(
        45deg,
        var(--hot) 0 11px,
        var(--yellow) 11px 22px
    );
    border-right: 3px solid var(--ink);
    transition: width .3s ease;
    box-shadow: inset 0 2px 0 rgba(255,255,255,.5);
}

/* 3D floating question panel with inner highlight */
.question-box {
    background: var(--white);
    border: 4px solid var(--ink);
    border-radius: 18px;
    box-shadow:
        5px 5px 0 var(--ink),
        0 15px 30px rgba(0,0,0,.12),
        inset 0 3px 0 rgba(255,255,255,1),
        inset 0 -3px 0 rgba(0,0,0,.05);
    padding: 1.8rem 1.5rem;
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.5;
    margin-bottom: 1.4rem;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    position: relative;
}

.options-container {
    display: flex;
    flex-direction: column;
    gap: .85rem;
}

/* ---------- 3D BUTTONS with shine gradient ---------- */
.btn {
    font-family: 'Rubik', sans-serif;
    font-weight: 700;
    font-size: 1.02rem;
    color: var(--ink);
    border: 3px solid var(--ink);
    border-radius: 14px;
    padding: .9rem 1.15rem;
    cursor: pointer;
    position: relative;
    background:
        linear-gradient(180deg, rgba(255,255,255,.7) 0%, rgba(255,255,255,.15) 45%, transparent 65%),
        var(--white);
    box-shadow:
        4px 4px 0 var(--ink),
        0 6px 12px rgba(0,0,0,.12);
    transition:
        transform .12s ease,
        box-shadow .12s ease,
        background .18s ease;
}
.btn:hover:not(:disabled) {
    background:
        linear-gradient(180deg, rgba(255,255,255,.6) 0%, rgba(255,255,255,.1) 45%, transparent 65%),
        var(--yellow);
    transform: translate(-3px, -3px);
    box-shadow:
        7px 7px 0 var(--ink),
        0 12px 22px rgba(0,0,0,.22);
}
.btn:active:not(:disabled) {
    transform: translate(2px, 2px);
    box-shadow:
        2px 2px 0 var(--ink),
        0 3px 6px rgba(0,0,0,.15);
}
.btn:disabled { cursor: default; }

.btn.correct {
    background:
        linear-gradient(180deg, rgba(255,255,255,.5) 0%, transparent 55%),
        var(--mint) !important;
    color: var(--ink) !important;
    border-color: var(--ink) !important;
    box-shadow: 4px 4px 0 var(--ink) !important;
}
.btn.wrong {
    background:
        linear-gradient(180deg, rgba(255,255,255,.4) 0%, transparent 55%),
        #FF3B3B !important;
    color: var(--white) !important;
    border-color: var(--ink) !important;
    box-shadow: 4px 4px 0 var(--ink) !important;
}

/* ---------- 3D INSET INPUTS ---------- */
input[type="text"] {
    width: 100%;
    padding: 1rem;
    border: 4px solid var(--ink);
    border-radius: 14px;
    background: var(--white);
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    color: var(--ink);
    margin-bottom: 1rem;
    outline: none;
    box-shadow:
        4px 4px 0 var(--ink),
        inset 0 2px 4px rgba(0,0,0,.06);
    transition: box-shadow .15s ease;
}
input[type="text"]::placeholder {
    color: #b3b3b3;
    font-weight: 500;
}
input[type="text"]:focus {
    box-shadow:
        4px 4px 0 var(--hot),
        inset 0 2px 4px rgba(0,0,0,.06),
        0 0 0 4px rgba(255,45,143,.15);
}

/* ---------- FEEDBACK ---------- */
.feedback {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 900;
    letter-spacing: .02em;
    min-height: 2rem;
    margin: 1rem 0 .3rem;
}

/* ---------- MATCH GAME ---------- */
.match-container {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    max-height: 50vh;
    overflow-y: auto;
    padding: .35rem;
}
.match-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: .6rem;
}
.match-btn {
    padding: .75rem .85rem;
    font-size: .95rem;
    text-align: left;
    border-radius: 12px;
}
.match-btn.active {
    background:
        linear-gradient(180deg, rgba(255,255,255,.5) 0%, transparent 55%),
        var(--cyan) !important;
    transform: translate(-2px, -2px);
    box-shadow:
        6px 6px 0 var(--ink),
        0 8px 16px rgba(0,0,0,.18);
}

/* ---------- SORT GAME ---------- */
.sort-container {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: .5rem;
}
.sort-container .btn {
    min-width: 170px;
    border-radius: 999px;
    font-weight: 900;
}

/* ---------- RESULTS ---------- */
#screen-results .btn {
    width: 100%;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
    display: block;
}
#final-score {
    font-family: 'Bungee', cursive;
    color: var(--hot);
    -webkit-text-stroke: 1.5px var(--ink);
    filter: drop-shadow(2px 2px 0 var(--ink));
}

/* ---------- UTILITY ---------- */
.hidden { display: none !important; }
.mt-2 { margin-top: .9rem; }
.text-center { text-align: center; }

/* ---------- ACCESSIBILITY: REDUCED MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    body { animation: none; }
    #app { animation: none; }
    .shape { animation: none; }
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 640px) {
    #app {
        padding: 1.3rem;
        box-shadow:
            8px 8px 0 var(--ink),
            0 15px 30px rgba(0,0,0,.18);
    }
    h1 { font-size: 1.35rem; -webkit-text-stroke: 1.5px var(--ink); }
    header { flex-direction: column; align-items: flex-start; gap: .8rem; }
    .match-container { flex-direction: column; }
    .nav-bar { justify-content: center; }
    .question-box { padding: 1.3rem 1rem; font-size: 1.05rem; }
    .sort-container .btn { min-width: 130px; }
}