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

:root {
    --accent-primary: #02d659;
    --accent-secondary: #ff2e2e;
    --glass-bg: rgba(20, 20, 25, 0.75);
    --glass-border: rgba(255, 255, 255, 0.15);
    --text-main: #ffffff;
    --text-dim: rgba(255, 255, 255, 0.7);
}

body {
    font-family: 'Outfit', sans-serif;
    color: var(--text-main);
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    background-color: #000;
}

.hidden {
    display: none !important;
}

/* Background Layers */
#bg-image {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-image: url('1080x360.jpe');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: background-image 0.5s ease, filter 0.5s ease;
    z-index: -2;
    filter: blur(10px) brightness(0.5);
}

#bg-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle at center, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.85) 100%);
    z-index: -1;
}

/* Typography */
.retro-text {
    font-family: 'Press Start 2P', monospace;
}

/* Layout */
#game-ui {
    width: 100%;
    max-width: 1000px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

main {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.side-col {
    flex: 0 0 250px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.main-col {
    flex: 1;
}

/* Glass Panels */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.glass-panel.vertical {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Header */
header.header-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 2px;
    background: linear-gradient(90deg, #fff, var(--accent-primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#mode-display {
    color: var(--accent-primary);
    font-family: 'Press Start 2P', monospace;
    font-size: 0.8rem;
}

/* Stats */
.stat-box {
    text-align: center;
    background: rgba(0,0,0,0.3);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.05);
}

.stat-box h2 {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 8px;
    letter-spacing: 2px;
}

.stat-box div {
    font-size: 1.2rem;
    color: var(--text-main);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.combo-box div {
    color: #ffaa00;
    text-shadow: 0 0 15px #ffaa00;
    transition: transform 0.2s;
}

/* Lore Panel */
#lore-panel {
    background: rgba(10, 20, 50, 0.8);
    border-color: rgba(100, 150, 255, 0.4);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

#lore-panel h3 {
    font-size: 0.8rem;
    color: #6496ff;
    margin-bottom: 10px;
    line-height: 1.4;
}

#lore-text {
    font-size: 0.95rem;
    line-height: 1.5;
    color: #eee;
}

/* Puzzle Grid */
#puzzle-board {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 600px;
}

#card-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    width: 100%;
    max-width: 600px;
    perspective: 1000px; /* For 3D flips */
}

/* Cards */
.card {
    width: 100%;
    aspect-ratio: 1 / 1;
    position: relative;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.5s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.card:hover {
    transform: scale(1.05);
}

.card.flipped {
    transform: rotateY(180deg);
}

.card.matched {
    transform: rotateY(180deg) scale(0.95);
    opacity: 0.9;
    cursor: default;
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    border: 2px solid var(--glass-border);
    display: flex;
    justify-content: center;
    align-items: center;
}

.card-front {
    background: #000;
    border-color: rgba(2, 214, 89, 0.3);
}

.logo-mark {
    width: 60px;
    height: 60px;
    position: relative;
    transform: scale(0.8);
}

.logo-green {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--accent-primary);
    clip-path: polygon(0 0, 100% 0, 100% 30%, 30% 30%, 30% 100%, 0 100%);
}

.logo-red {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 35%;
    height: 35%;
    background-color: var(--accent-secondary);
}

.card-back {
    background-color: #000;
    transform: rotateY(180deg);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.card.matched .card-back {
    box-shadow: 0 0 20px var(--accent-primary);
    border-color: var(--accent-primary);
}

.card.error {
    animation: shake 0.4s;
    border-color: var(--accent-secondary) !important;
}

@keyframes shake {
    0%, 100% { transform: rotateY(180deg) translateX(0); }
    25% { transform: rotateY(180deg) translateX(-5px); }
    75% { transform: rotateY(180deg) translateX(5px); }
}

.screen-shake {
    animation: bigShake 0.3s;
}

@keyframes bigShake {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(5px, 5px) rotate(1deg); }
    50% { transform: translate(-5px, -5px) rotate(-1deg); }
    75% { transform: translate(-5px, 5px) rotate(1deg); }
}

/* Overlay Screens */
.overlay-screen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(15px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 100;
}

#end-screen {
    position: absolute;
    border-radius: 16px;
    z-index: 10;
}

.overlay-screen h1, .overlay-screen h2 {
    font-size: 3rem;
    color: var(--accent-primary);
    margin-bottom: 20px;
    letter-spacing: 2px;
    text-shadow: 0 0 20px rgba(2, 214, 89, 0.6);
}

.overlay-screen h2.failed {
    color: var(--accent-secondary);
    text-shadow: 0 0 20px rgba(255, 46, 46, 0.6);
}

.overlay-screen p {
    font-size: 1.2rem;
    color: var(--text-dim);
    margin-bottom: 40px;
}

/* Difficulty Buttons */
.difficulty-buttons {
    display: flex;
    gap: 20px;
    margin-bottom: 40px;
}

.diff-btn {
    background: rgba(255,255,255,0.05);
    border: 2px solid var(--glass-border);
    color: #fff;
    padding: 20px 30px;
    font-family: 'Press Start 2P', monospace;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 12px;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.diff-btn small {
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    color: var(--text-dim);
}

.diff-btn:hover {
    background: rgba(255,255,255,0.15);
    border-color: var(--accent-primary);
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(51,255,102,0.2);
}

/* High Scores */
#high-scores {
    min-width: 300px;
    text-align: left;
}

#high-scores h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: var(--accent-primary);
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 10px;
}

#high-scores p {
    margin-bottom: 10px;
    font-size: 1rem;
    color: #fff;
}

#high-scores span {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.9rem;
    color: var(--accent-primary);
    float: right;
}

.final-stats {
    font-size: 1.2rem;
    font-family: 'Press Start 2P', monospace;
    margin-bottom: 40px;
    color: #fff;
    line-height: 2;
}

#restart-btn {
    background: transparent;
    border: 2px solid var(--accent-primary);
    color: var(--accent-primary);
    padding: 15px 30px;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
}

#restart-btn:hover {
    background: var(--accent-primary);
    color: #000;
    box-shadow: 0 0 20px rgba(2, 214, 89, 0.6);
}

/* Responsive */
@media (max-width: 800px) {
    main { flex-direction: column; }
    .side-col { flex: none; flex-direction: row; flex-wrap: wrap; }
    .glass-panel.vertical { flex-direction: row; flex-wrap: wrap; width: 100%; justify-content: space-around; }
    .stat-box { flex: 1; min-width: 100px; }
    #card-grid { gap: 8px; }
    .difficulty-buttons { flex-direction: column; }
}
