* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-main: #0b0f19;
    --card-bg: #1e293b;
    --card-border: #334155;
    --card-glow: #38bdf8;
    --accent: #38bdf8;
    --accent-gradient: linear-gradient(135deg, #0ea5e9, #6366f1);
    --gold: #fbbf24;
    --text: #f8fafc;
    --text-muted: #94a3b8;
}

body {
    background: radial-gradient(circle at 50% 20%, #172554, var(--bg-main) 70%);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
    overflow-y: auto;
    padding-bottom: 70px; /* Space for bottom ad */
}

/* Header & HUD */
header {
    width: 100%;
    max-width: 500px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: sticky;
    top: 0;
    z-index: 50;
}

.title-group h1 {
    font-size: 1.25rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 6px;
}

.hud-stats {
    display: flex;
    gap: 8px;
}

.stat-chip {
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 4px 10px;
    text-align: center;
    min-width: 60px;
}

.stat-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.stat-value {
    font-size: 0.95rem;
    font-weight: 800;
    color: #38bdf8;
    font-variant-numeric: tabular-nums;
}

/* Game Controls & Filter Bars */
.toolbar {
    width: 100%;
    max-width: 500px;
    padding: 10px 14px 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bar-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.pill-btn {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pill-btn:hover {
    color: #fff;
    background: rgba(56, 189, 248, 0.2);
    border-color: #38bdf8;
}

.pill-btn.active {
    background: var(--accent-gradient);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 0 12px rgba(14, 165, 233, 0.4);
}

/* Combo Banner */
#combo-banner {
    height: 24px;
    margin-top: 4px;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--gold);
    text-shadow: 0 0 10px rgba(251, 191, 36, 0.6);
    display: none;
}

.pop-anim {
    animation: popBounce 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popBounce {
    0% { transform: scale(0.5); opacity: 0; }
    70% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

/* Card Board Grid */
.board-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    width: 100%;
    max-width: 500px;
}

#board {
    display: grid;
    justify-content: center;
    align-content: center;
    perspective: 1000px;
    margin: 0 auto;
}

/* Individual 3D Card */
.card {
    background: transparent;
    perspective: 800px;
    cursor: pointer;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 12px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

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

.card.matched .card-inner {
    transform: rotateY(180deg) scale(0.96);
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.6), inset 0 0 12px rgba(56, 189, 248, 0.3);
    border: 2px solid #38bdf8;
}

.card.shake .card-inner {
    animation: shakeCard 0.4s ease;
}

@keyframes shakeCard {
    0%, 100% { transform: rotateY(180deg) translateX(0); }
    20%, 60% { transform: rotateY(180deg) translateX(-6px); }
    40%, 80% { transform: rotateY(180deg) translateX(6px); }
}

.card-front, .card-back {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.card-front {
    background: linear-gradient(145deg, #1e293b, #0f172a);
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.05);
}

.card-front::after {
    content: '?';
    font-size: 1.4rem;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.25);
    transition: transform 0.2s ease, color 0.2s ease;
}

.card:hover .card-front::after {
    color: #38bdf8;
    transform: scale(1.15);
}

.card-back {
    background: linear-gradient(145deg, #0f172a, #1e293b);
    border: 2px solid rgba(56, 189, 248, 0.4);
    transform: rotateY(180deg);
}

.card-back span {
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-box {
    background: linear-gradient(145deg, #1e293b, #0f172a);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 28px 24px;
    text-align: center;
    max-width: 360px;
    width: 100%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

.modal-box h2 {
    font-size: 1.8rem;
    margin-bottom: 8px;
}

.win-title {
    color: var(--gold);
    text-shadow: 0 0 15px rgba(251, 191, 36, 0.5);
}

.lose-title {
    color: #f87171;
}

.stars-row {
    font-size: 2rem;
    margin: 12px 0 16px;
    letter-spacing: 4px;
}

.results-grid {
    background: rgba(15, 23, 42, 0.6);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.res-item span {
    display: block;
}

.res-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.res-val {
    font-size: 1.1rem;
    font-weight: 800;
    color: #38bdf8;
}

.action-btn {
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(14, 165, 233, 0.4);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    width: 100%;
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(14, 165, 233, 0.6);
}

.action-btn:active {
    transform: translateY(1px);
}
