/* ─── Variables (ACTotal Theme) ─── */
:root {
    --bg: #050506;
    --surface: #111827;
    --surface-light: #1f2937;
    --surface-hover: #374151;
    --accent: #00A7E1;
    --accent-glow: rgba(0, 167, 225, 0.35);
    --text: #ffffff;
    --text-dim: #9ca3af;
    --radius: 20px;
    --radius-sm: 12px;

    --success: #10b981;
}

/* ─── Base Reset ─── */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
    /* Prevent double tap zoom on mobile matching */
    touch-action: pan-x pan-y;
}

/* ─── Layout ─── */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    padding: 1.5rem;
    max-width: 500px;
    margin: 0 auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1.5rem;
    position: relative;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), #007bb5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.btn-icon,
.btn-icon-subtle {
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .2s;
}

.btn-icon {
    width: 42px;
    height: 42px;
    border: 1px solid rgba(255, 255, 255, .08);
    background: var(--surface);
    color: var(--text-dim);
    text-decoration: none;
    font-size: 1.2rem;
}

.btn-icon:hover {
    background: var(--surface-light);
    color: var(--text);
}

.btn-icon-subtle {
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    color: var(--text-dim);
}

.btn-icon-subtle:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

/* ─── Stats Bar ─── */
.stats-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    padding: 0.8rem 1rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.stat-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.stat-badge strong {
    font-size: 1.2rem;
    color: var(--accent);
}

/* ─── Memory Grid ─── */
.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 1fr;
    gap: 0.8rem;
    /* Aspect ratio hack for square grid items matching width */
    aspect-ratio: 1 / 1;
    perspective: 1000px;
}

/* ─── 3D Card ─── */
.card {
    position: relative;
    width: 100%;
    height: 100%;
    cursor: pointer;
    /* Necessary for 3D flip */
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Active Flip State */
.card.flipped {
    -webkit-transform: rotateY(180deg);
    transform: rotateY(180deg);
}

/* Success wiggle state */
.card.matched {
    -webkit-transform: rotateY(180deg) scale(0.95);
    transform: rotateY(180deg) scale(0.95);
    pointer-events: none;
    transition: all 0.4s;
}

.card.matched .card-front {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.15);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: var(--radius-sm);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    /* Ensures the click always registers on the parent .card */
}

/* Front is the Emoji side (starts rotated away) */
.card-front {
    background: var(--surface-light);
    border: 1px solid rgba(255, 255, 255, 0.1);
    -webkit-transform: rotateY(180deg);
    transform: rotateY(180deg);
}

/* Back is the ACTapps logo side */
.card-back {
    background: linear-gradient(135deg, var(--accent), #007bb5);
    position: relative;
    -webkit-transform: rotateY(0deg);
    transform: rotateY(0deg);
}

/* Subtle pattern for the back */
.card-back::after {
    content: '🧩';
    font-size: 1.5rem;
    opacity: 0.3;
}

/* ─── Modals ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-box {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 90%;
    width: 320px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: translateY(0);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.hidden .modal-box {
    transform: translateY(30px);
}

.modal-box h2 {
    font-size: 1.8rem;
    color: var(--success);
}

.final-score {
    background: var(--surface-light);
    border-radius: var(--radius-sm);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.final-score strong {
    font-size: 2.5rem;
    color: var(--accent);
}

.btn-primary {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    background: linear-gradient(135deg, var(--accent), #007bb5);
    color: #fff;
    box-shadow: 0 5px 20px var(--accent-glow);
    transition: transform 0.15s;
}

.btn-primary:active {
    transform: scale(0.96);
}

/* ─── Footer ─── */
.app-footer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: auto;
    padding-top: 2rem;
}