/* Memory Game Styles */
:root {
    --primary: #a36105;
    --primary-hover: #659531;
    --accent: #ffc107;
    --accent-dark: #ff9800;
}

* { box-sizing: border-box; }

body {
    background-color: #f3f7f2;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    font-family: 'Comic Sans MS', 'Nunito Sans', cursive, sans-serif;
}

/* ── Top bar ── */
.game-topbar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(255,255,255,0.85);
    border-bottom: 2px solid rgba(163, 97, 5, 0.15);
    backdrop-filter: blur(4px);
    flex-shrink: 0;
}

.hint-btn {
    padding: 8px 18px;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 50px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: #fff;
    border: none;
    font-weight: bold;
    box-shadow: 0 3px 10px rgba(0,0,0,0.15);
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
}

.hint-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    filter: brightness(1.1);
}

.score-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    background: linear-gradient(135deg, #fff9f0, #fff3e0);
    padding: 6px 16px;
    border-radius: 50px;
    border: 2px solid var(--accent);
    font-size: 0.9rem;
}

.score-label { color: #888; }
.score-value { font-weight: bold; color: var(--primary); font-size: 1rem; }

.restart-top-btn {
    padding: 8px 18px;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 50px;
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    font-weight: bold;
    transition: all 0.25s ease;
    font-family: inherit;
}

.restart-top-btn:hover {
    background: var(--primary);
    color: #fff;
    transform: translateY(-2px);
}

/* ── Pre-render cache ── */
.pre-render-container {
    position: fixed;
    top: 0; left: 0;
    width: 1px; height: 1px;
    opacity: 0.01;
    pointer-events: none;
    z-index: -1;
}

/* ── Card grid — 5 colunas x 4 linhas (paisagem) ── */
.memory-game {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    flex: 1;
    width: 100%;
    max-width: 850px;
    max-height: calc(100vh - 54px);
    margin: auto;
    padding: 10px;
    perspective: 1000px;
    box-sizing: border-box;
}

/* Tela cheia: expande o grid para ocupar orientação paisagem */
:fullscreen .memory-game,
:-webkit-full-screen .memory-game {
    max-width: 100%;
}

.memory-card {
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.45s ease;
    cursor: pointer;
    will-change: transform;
    border-radius: 8px;
}

.memory-card:hover:not(.flip):not(.matched) {
    transform: scale(1.04);
    z-index: 1;
}

.memory-card.flip {
    transform: rotateY(180deg);
}

.memory-card.matched .front-face {
    box-shadow: 0 0 0 3px var(--primary-hover), 0 2px 8px rgba(0,0,0,0.2);
}

.front-face,
.back-face {
    width: 100%;
    height: 100%;
    position: absolute;
    border-radius: 8px;
    background: #fff;
    backface-visibility: hidden;
    object-fit: cover;
    box-shadow: 1px 1px 6px rgba(0,0,0,0.18);
    image-rendering: -webkit-optimize-contrast;
    transform: translateZ(0);
}

.front-face {
    transform: rotateY(180deg);
    object-fit: contain;
    padding: 6px;
    background: #fffdf5;
}

/* Hint: glow only, sem conflito com rotateY */
.memory-card.hint .back-face {
    box-shadow: 0 0 0 3px var(--accent), 0 0 16px rgba(255,193,7,0.7);
}

/* ── Reward Overlay ── */
#reward-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, rgba(163,97,5,0.92), rgba(101,149,49,0.92));
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: white;
    text-align: center;
    font-family: inherit;
}

#reward-overlay h2 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#reward-overlay p {
    font-size: 1.2rem;
    margin-bottom: 28px;
    opacity: 0.9;
}

.restart-btn {
    padding: 14px 40px;
    font-size: 1.1rem;
    background-color: #fff;
    color: var(--primary);
    border: none;
    border-radius: 30px;
    cursor: pointer;
    font-weight: bold;
    font-family: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.restart-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

/* ── Spinner ── */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinner-img {
    animation: spin 1s linear infinite;
}
