/* --- 1. IMPORT FONTS --- */
@import url('https://fonts.googleapis.com/css2?family=Instrument+Sans:ital,wght@0,400..800;1,400..800&family=Instrument+Serif:ital@0;1&display=swap');

:root {
    --bg-color: #000000;
    --card-bg: #1c1c1e;
    --text-primary: #f5f5f7;
    --text-secondary: #86868b;
    --accent: #007AFF;
    --success: #30d158;
    --error: #ff453a;
}

* { box-sizing: border-box; -webkit-font-smoothing: antialiased; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0; padding: 10px;
    display: flex; justify-content: center; min-height: 100vh;
    align-items: flex-start; overflow-x: hidden;
}

.main-wrapper {
    display: flex; flex-direction: column; align-items: center;
    width: 100%; max-width: 900px; text-align: center;
    animation: fadeIn 0.6s ease-out;
    position: relative;
    padding-top: 20px;
}

/* --- TYPOGRAPHY --- */

.main-title { 
    font-family: 'Instrument Sans', sans-serif;
    font-size: 3.5rem; 
    font-weight: 600; 
    letter-spacing: -0.02em; 
    margin-bottom: 8px; 
    line-height: 1.1; 
}

.italic-text {
    font-family: 'Instrument Serif', serif;
    font-style: italic;
    font-weight: 400; 
    font-size: 1.1em; 
}

.typing-effect {
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    border-right: 3px solid var(--accent);
    width: 0;
    padding-bottom: 5px; 
    margin-bottom: -5px; 
    vertical-align: bottom; 
    animation: typing 1.5s steps(30, end) forwards, blink-caret 0.75s step-end infinite;
}

.typing-finished { border-right: none !important; } 

@keyframes typing { from { width: 0 } to { width: 100% } }
@keyframes blink-caret { from, to { border-color: transparent } 50% { border-color: var(--accent) } }

.subtitle { 
    font-size: 1.1rem; color: var(--text-secondary); 
    font-weight: 400; margin-bottom: 30px; 
}

/* --- GAME UI HEADERS --- */
.game-header-wrapper {
    margin-top: 10px; margin-bottom: 15px;
    display: flex; flex-direction: column; align-items: center;
}

.game-header-title {
    font-family: 'Instrument Sans', sans-serif;
    font-size: 1.8rem; 
    font-weight: 600; 
    margin: 0 0 10px 0; 
    color: var(--text-primary); 
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.game-header-title .italic-text {
    font-family: 'Instrument Serif', serif;
    font-style: italic;
    font-weight: 400;
}
.game-header-wrapper .subtitle { font-size: 0.85rem; margin-bottom: 8px; }

.game-footer {
    display: flex; flex-direction: row; align-items: center; justify-content: center; 
    gap: 8px; opacity: 0.5;
}
.game-footer img { width: 25px; opacity: 0.8; margin: 0; }
.game-footer span { font-size: 0.6rem; color: var(--text-secondary); }

.quit-btn {
    position: absolute; top: 0; right: 0;
    width: 40px; height: 40px;
    background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%; color: var(--text-secondary); font-size: 1.1rem;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; z-index: 100; transition: all 0.2s; backdrop-filter: blur(10px);
}
.quit-btn:hover { background: rgba(255, 69, 58, 0.2); color: var(--error); border-color: var(--error); transform: scale(1.1); }

/* --- INSTRUCTIONS --- */
.instructions-box {
    background: var(--card-bg); padding: 24px; border-radius: 20px; margin-bottom: 30px;
    text-align: left; max-width: 320px; width: 100%; border: 1px solid rgba(255,255,255,0.1); 
}
.instructions-header { 
    font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; margin-bottom: 15px; 
}
.instruction-step { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; font-size: 0.95rem; }
.instruction-icon { color: var(--accent); }

.tmdb-attribution { display: flex; flex-direction: column; align-items: center; margin-bottom: 20px; opacity: 0.8; }
.tmdb-attribution img { width: 60px; margin-bottom: 8px; }
.tmdb-attribution p { font-size: 0.65rem; color: var(--text-secondary); margin: 0; max-width: 220px; line-height: 1.3; }

.start-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 280px; }
.btn {
    font-family: inherit; font-weight: 600; font-size: 1.05rem;
    background-color: var(--accent); color: white; border: none;
    padding: 14px 30px; border-radius: 999px; cursor: pointer; transition: transform 0.1s;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { background-color: #333; color: #666; }
.btn-secondary { background-color: rgba(255,255,255,0.1); color: var(--accent); }
.btn-share { display: flex; align-items: center; justify-content: center; gap: 10px; background: linear-gradient(135deg, #222, #444); border: 1px solid rgba(255,255,255,0.2); margin-bottom: 20px; width: 100%; }
.btn-row { display: flex; gap: 12px; justify-content: center; margin-top: 20px; }

/* --- GAMEPLAY --- */
.timer-container { width: 100%; max-width: 600px; height: 4px; background: #333; border-radius: 2px; margin-bottom: 20px; overflow: hidden; }
.timer-bar { height: 100%; background: var(--accent); width: 100%; transform-origin: left; }
.animate-timer { animation: shrink 5s linear forwards; }
@keyframes shrink { to { width: 0%; } }

.game-container { display: flex; justify-content: center; align-items: stretch; gap: 15px; width: 100%; position: relative; margin-bottom: 20px; }

.card {
    background-color: var(--card-bg); width: 280px; min-height: 480px;
    border-radius: 18px; padding: 10px; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s;
    display: flex; flex-direction: column; align-items: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4); border: 2px solid transparent; 
}
.card:hover { transform: translateY(-4px); box-shadow: 0 12px 30px rgba(0,0,0,0.5); }
.img-container { width: 100%; height: 400px; border-radius: 12px; overflow: hidden; background-color: #111; position: relative; margin-bottom: 12px; }
.poster-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster-fallback { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: #222; color: #444; font-size: 3rem; }
.card h2 { font-size: 1rem; font-weight: 600; margin: 0 0 5px 0; line-height: 1.3; color: var(--text-primary); text-align: center; }
.date-reveal { font-size: 1.1rem; font-weight: 700; color: var(--accent); opacity: 0; transition: opacity 0.3s; }
.card.correct { border-color: var(--success); background-color: rgba(48, 209, 88, 0.1); }
.card.wrong { border-color: var(--error); background-color: rgba(255, 69, 58, 0.1); }
.vs-circle { font-size: 0.8rem; font-weight: 700; color: var(--text-secondary); background: var(--card-bg); padding: 8px 12px; border-radius: 12px; z-index: 10; border: 1px solid rgba(255,255,255,0.1); position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }

.status-bar { margin-top: 10px; font-size: 1.1rem; color: var(--text-secondary); }
#score { color: var(--text-primary); font-weight: 700; }
.message { height: 25px; margin-bottom: 5px; font-weight: 600; font-size: 1rem; }

/* --- MODALS --- */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); backdrop-filter: blur(20px); z-index: 2000; justify-content: center; align-items: center; animation: fadeIn 0.3s ease-out; }
.modal-content { background: var(--card-bg); width: 90%; max-width: 400px; padding: 30px; border-radius: 24px; text-align: center; border: 1px solid rgba(255,255,255,0.1); }
.modal h2 { margin-top: 0; font-weight: 700; }

.final-score { font-size: 3rem; font-weight: 700; margin: 20px 0 5px 0; line-height: 1; }
.personal-best { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 15px; font-weight: 600; }
.top-10-badge { background: rgba(255, 215, 0, 0.15); color: #FFD700; border: 1px solid rgba(255, 215, 0, 0.3); padding: 8px 16px; border-radius: 99px; font-size: 0.9rem; font-weight: 700; display: inline-block; margin-bottom: 20px; animation: pulse 2s infinite; }

@keyframes pulse { 0% { transform: scale(1); } 70% { transform: scale(1.05); } 100% { transform: scale(1); } }

.input-group { display: flex; flex-direction: column; gap: 12px; margin-bottom: 25px; margin-top: 10px; }
#player-name { padding: 14px; border-radius: 12px; border: 1px solid #333; background: rgba(0,0,0,0.3); color: white; text-align: center; font-size: 1.1rem; }

.leaderboard-list { list-style: none; padding: 0; height: 300px; overflow-y: auto; width: 100%; }
.leaderboard-header, .leaderboard-row { display: grid; grid-template-columns: 15% 55% 30%; align-items: center; padding: 12px 10px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.leaderboard-header { border-bottom: 1px solid #444; margin-bottom: 5px; }
.leaderboard-header span { font-weight: 600; color: var(--text-secondary); font-size: 0.75rem; text-transform: uppercase; }
.leaderboard-row .score-col { font-weight: 700; color: var(--accent); }

/* --- SHARE CARD (HIDDEN) --- */
#share-card { width: 600px; height: 600px; background: radial-gradient(circle at center, #1c1c1e 0%, #000000 100%); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; border: 4px solid #333; padding: 40px; font-family: 'Instrument Sans', sans-serif; color: #f5f5f7; position: relative; }
#share-card::before { content: ''; position: absolute; top: 20px; left: 20px; right: 20px; bottom: 20px; border: 2px solid rgba(255, 255, 255, 0.1); border-radius: 20px; }
.share-header { font-family: 'Instrument Sans', sans-serif; font-size: 3.5rem; font-weight: 700; line-height: 1.1; margin-bottom: 40px; color: #fff; text-shadow: 0 4px 10px rgba(0,0,0,0.5); }
.share-header .italic-text { font-family: 'Instrument Serif', serif; font-style: italic; font-weight: 400; color: var(--accent); }
.share-score-label { font-size: 1.8rem; color: #86868b; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 10px; }
.share-score-number { font-size: 8rem; font-weight: 800; color: #fff; line-height: 1; margin-bottom: 30px; text-shadow: 0 0 30px rgba(0, 122, 255, 0.4); }
.share-footer { font-size: 1.5rem; color: #f5f5f7; font-weight: 600; }
.share-url { margin-top: 20px; font-size: 1rem; color: #555; text-transform: uppercase; letter-spacing: 0.2em; }

@media (max-width: 600px) {
    .main-title { font-size: 2.8rem; }
    .game-container { gap: 10px; }
    .card { flex: 1; min-height: 340px; width: auto; padding: 6px; }
    .img-container { height: 260px; }
    .card h2 { font-size: 0.85rem; }
    .vs-circle { padding: 6px 10px; font-size: 0.7rem; }
    .quit-btn { top: 5px; right: 5px; }
}
@keyframes fadeIn { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }
