/* ==========================================================================
   ANIMEGUESS - DESIGN SYSTEM & STYLESHEET
   Anime Cyberpunk / Manga Energy Theme
   ========================================================================== */

/* --- CSS Variables & Design Tokens --- */
:root {
    --bg-dark: #090a10;
    --bg-card: rgba(18, 20, 32, 0.88);
    --bg-card-border: rgba(168, 85, 247, 0.35);
    
    --primary: #a855f7;        /* Neon Purple */
    --primary-glow: #c084fc;   /* Bright Purple Glow */
    --secondary: #ff2a70;      /* Electric Magenta / Fire */
    --cyan: #00f5d4;           /* Energy Cyan */
    --accent-gold: #ffd166;    /* Super Saiyan Gold */
    --accent-blue: #3b82f6;
    --accent-red: #ef4444;
    
    --text-primary: #ffffff;
    --text-secondary: #e2e8f0;
    --text-muted: #94a3b8;
    
    --font-heading: 'Bangers', cursive, 'Outfit', sans-serif;
    --font-body: 'Outfit', sans-serif;
    --font-badge: 'Permanent Marker', cursive;

    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;

    --shadow-glow-purple: 0 0 25px rgba(168, 85, 247, 0.4);
    --shadow-glow-pink: 0 0 25px rgba(255, 42, 112, 0.4);
    --shadow-glow-cyan: 0 0 25px rgba(0, 245, 212, 0.4);
    --shadow-card: 0 20px 40px rgba(0, 0, 0, 0.6);
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
}

/* --- Animated Organic Background Shapes --- */
.shape {
    position: fixed;
    border-radius: 50%;
    filter: blur(90px);
    z-index: 0;
    pointer-events: none;
    opacity: 0.4;
    animation: floatGlow 12s infinite alternate ease-in-out;
}

.shape.top-left {
    top: -100px;
    left: -100px;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, var(--primary) 0%, transparent 70%);
}

.shape.top-right {
    top: -50px;
    right: -100px;
    width: 450px;
    height: 450px;
    background: radial-gradient(circle, var(--secondary) 0%, transparent 70%);
    animation-delay: -3s;
}

.shape.bottom-left {
    bottom: -100px;
    left: -50px;
    width: 380px;
    height: 380px;
    background: radial-gradient(circle, var(--cyan) 0%, transparent 70%);
    animation-delay: -6s;
}

.shape.bottom-right {
    bottom: -100px;
    right: -100px;
    width: 420px;
    height: 420px;
    background: radial-gradient(circle, var(--accent-gold) 0%, transparent 70%);
    animation-delay: -9s;
}

@keyframes floatGlow {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(30px, -20px) scale(1.1); }
    100% { transform: translate(-20px, 30px) scale(0.95); }
}

/* Watermark text */
.bg-text-26 {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-heading);
    font-size: 35vw;
    color: rgba(255, 255, 255, 0.018);
    pointer-events: none;
    user-select: none;
    z-index: 0;
    letter-spacing: 5px;
}

/* --- Container & Layout --- */
.container {
    width: 100%;
    max-width: 680px;
    padding: 20px;
    position: relative;
    z-index: 1;
}

/* Language Switcher (Segmented Pill Switch) */
.lang-switch-container {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 14px;
}

.lang-switch {
    display: inline-flex;
    align-items: center;
    background: rgba(20, 16, 35, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 30px;
    padding: 3px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35), inset 0 1px 1px rgba(255, 255, 255, 0.08);
    gap: 3px;
}

.lang-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-muted);
    padding: 6px 13px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    font-family: inherit;
}

.lang-btn .lang-flag {
    font-size: 1.05rem;
    line-height: 1;
}

.lang-btn .lang-text {
    font-size: 0.78rem;
    font-weight: 700;
}

@media (hover: hover) and (pointer: fine) {
    .lang-btn:hover:not(.active) {
        color: var(--text-primary);
        background: rgba(255, 255, 255, 0.08);
    }
}

.lang-btn.active {
    background: linear-gradient(135deg, var(--secondary) 0%, var(--primary) 100%);
    color: #ffffff;
    box-shadow: 0 2px 12px rgba(255, 42, 112, 0.45);
}

/* --- Global Header / Logo --- */
.game-logo-header {
    text-align: center;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.logo-emblem-wrapper {
    position: relative;
    width: 90px;
    height: 90px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.game-logo-emblem {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    border: 2.5px solid var(--cyan);
    box-shadow: 0 0 20px rgba(0, 245, 212, 0.45), 0 0 35px rgba(168, 85, 247, 0.5);
    animation: emblemPulse 4s infinite alternate ease-in-out;
    position: relative;
    z-index: 2;
    transition: transform 0.3s ease;
}

.game-logo-header:hover .game-logo-emblem {
    transform: scale(1.06) rotate(3deg);
}

.emblem-glow {
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 42, 112, 0.5) 0%, rgba(168, 85, 247, 0.4) 50%, transparent 70%);
    filter: blur(10px);
    z-index: 1;
    pointer-events: none;
    animation: glowFloat 5s infinite alternate ease-in-out;
}

@keyframes emblemPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 20px rgba(0, 245, 212, 0.45), 0 0 30px rgba(168, 85, 247, 0.4);
    }
    100% {
        transform: scale(1.03);
        box-shadow: 0 0 30px rgba(255, 42, 112, 0.7), 0 0 50px rgba(168, 85, 247, 0.7);
    }
}

@keyframes glowFloat {
    0% {
        opacity: 0.7;
        transform: scale(0.95);
    }
    100% {
        opacity: 1;
        transform: scale(1.1);
    }
}

.logo-text-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-logo-title {
    font-family: var(--font-heading);
    font-size: 2.8rem;
    letter-spacing: 2px;
    color: var(--text-primary);
    text-shadow: 0 0 20px rgba(168, 85, 247, 0.6);
    line-height: 1.1;
}

.game-logo-title span {
    color: var(--secondary);
    text-shadow: 0 0 20px rgba(255, 42, 112, 0.8);
}

.game-logo-subtitle {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(255, 209, 102, 0.5);
    margin-top: 4px;
}

/* --- Main Card Layout --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    padding: 30px;
    box-shadow: var(--shadow-card), var(--shadow-glow-purple);
    display: none;
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.card.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- Start Screen --- */
.start-screen-layout {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.profile-header {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

.user-badge {
    background: rgba(168, 85, 247, 0.15);
    border: 1px solid rgba(168, 85, 247, 0.4);
    padding: 8px 18px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.2);
}

.user-icon {
    font-size: 1.2rem;
}

.user-name {
    font-weight: 700;
    color: var(--cyan);
    letter-spacing: 0.5px;
}

.game-instructions {
    text-align: center;
    font-size: 1.05rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.stats-overview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.stat-box {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
    transition: transform 0.3s ease;
}

.stat-box:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--accent-gold);
}

.stat-subvalue {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-muted);
    display: block;
    margin-top: 2px;
}

/* --- Buttons --- */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn {
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 1.05rem;
    padding: 16px 24px;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    outline: none;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.btn-large {
    font-size: 1.15rem;
    padding: 18px 28px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: #ffffff;
    box-shadow: 0 8px 25px rgba(255, 42, 112, 0.35);
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 30px rgba(255, 42, 112, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: var(--cyan);
    color: var(--cyan);
    box-shadow: 0 0 15px rgba(0, 245, 212, 0.3);
}

/* --- Game Screen HUD & Card --- */
.game-screen-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.game-hud-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.game-player-badge {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.streak-container, .timer-text-container {
    display: flex;
    flex-direction: column;
}

.streak-container .label, .timer-text-container .label {
    font-size: 0.75rem;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.streak-container .value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--secondary);
}

.timer-text-container .value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--cyan);
}

.timer-text-container .value.highlight {
    color: var(--secondary);
    animation: pulse 0.5s infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.15); }
}

/* Visual Timer Bar */
.timer-bar-container {
    width: 100%;
    height: 10px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.timer-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--cyan) 0%, var(--primary) 100%);
    border-radius: 10px;
    transition: width 0.05s linear;
    position: relative;
}

.timer-ball {
    position: absolute;
    right: -6px;
    top: -6px;
    font-size: 14px;
    line-height: 1;
}

/* Main Player Card / Trading Card Frame */
.player-card {
    position: relative;
    width: 100%;
    max-width: min(340px, 85vw);
    aspect-ratio: 4 / 5;
    margin: 0 auto 24px auto;
    background: #090a10;
    border: 2px solid var(--primary);
    border-radius: var(--radius-md);
    padding: 6px;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(168, 85, 247, 0.35);
    display: flex;
    justify-content: center;
    align-items: center;
}

.player-image-backdrop {
    position: absolute;
    inset: -30px;
    background-size: cover;
    background-position: center;
    filter: blur(25px) brightness(0.4) saturate(1.4);
    transform: scale(1.25);
    z-index: 0;
    pointer-events: none;
    transition: background-image 0.4s ease;
}

.player-image-wrapper {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    border-radius: calc(var(--radius-md) - 6px);
    overflow: hidden;
    background-color: #0b091c;
    display: flex;
    justify-content: center;
    align-items: center;
}

.player-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    transition: transform 0.4s ease;
    filter: drop-shadow(0 6px 15px rgba(0, 0, 0, 0.6));
}

/* Loading Spinner */
.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid var(--cyan);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    position: absolute;
    z-index: 2;
}

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

/* Feedback Overlay */
.feedback-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: rgba(9, 10, 16, 0.88);
    backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.feedback-overlay.show {
    opacity: 1;
}

.feedback-overlay span {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    letter-spacing: 2px;
}

.feedback-overlay.correct span {
    color: var(--cyan);
    text-shadow: 0 0 20px rgba(0, 245, 212, 0.8);
}

.feedback-overlay.incorrect span {
    color: var(--secondary);
    text-shadow: 0 0 20px rgba(255, 42, 112, 0.8);
}

/* Options Grid */
.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.btn-option {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
    padding: 16px;
    font-size: 1rem;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn-option:focus,
.btn-option:focus-visible {
    outline: none;
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: none;
}

/* Hover only on pointer devices (desktop/mouse) to prevent sticky highlight on mobile/touch */
@media (hover: hover) and (pointer: fine) {
    .btn-option:hover:not(:disabled) {
        background: rgba(168, 85, 247, 0.2);
        border-color: var(--primary-glow);
        transform: translateY(-2px);
        box-shadow: 0 0 15px rgba(168, 85, 247, 0.3);
    }
}

/* Immediate touch feedback for mobile and iPad without sticky effect */
.btn-option:active:not(:disabled) {
    background: rgba(168, 85, 247, 0.3);
    border-color: var(--primary-glow);
    transform: scale(0.98);
}

.btn-option.correct-choice {
    background: rgba(0, 245, 212, 0.25) !important;
    border-color: var(--cyan) !important;
    color: var(--cyan) !important;
    box-shadow: 0 0 20px rgba(0, 245, 212, 0.5) !important;
}

.btn-option.incorrect-choice {
    background: rgba(255, 42, 112, 0.25) !important;
    border-color: var(--secondary) !important;
    color: var(--secondary) !important;
    box-shadow: 0 0 20px rgba(255, 42, 112, 0.5) !important;
}

/* Shake and Glow Effects */
.shake {
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-10px); }
    40% { transform: translateX(10px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}

.success-glow {
    box-shadow: 0 0 50px rgba(0, 245, 212, 0.5), var(--shadow-card);
}

/* --- End Screen (Game Over) --- */
.section-title {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    text-align: center;
    color: var(--secondary);
    text-shadow: 0 0 15px rgba(255, 42, 112, 0.5);
    margin-bottom: 8px;
}

.end-screen-layout {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.end-summary-panel {
    text-align: center;
}

.end-message {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.percentile-message {
    font-size: 0.95rem;
    color: var(--accent-gold);
    font-weight: 600;
}

.divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
    margin: 16px 0;
}

.final-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.final-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.1rem;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
}

.restart-home-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* --- Leaderboard Screen --- */
.leaderboard-table-container {
    max-height: 360px;
    overflow-y: auto;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.3);
    margin-bottom: 20px;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.leaderboard-table th, .leaderboard-table td {
    padding: 14px 18px;
}

.leaderboard-table th {
    background: rgba(168, 85, 247, 0.2);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--primary-glow);
    position: sticky;
    top: 0;
}

.leaderboard-table tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.leaderboard-table tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

.current-player-row {
    background: rgba(0, 245, 212, 0.15) !important;
    font-weight: 700;
}

.rank-badge {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-weight: 800;
    font-size: 0.85rem;
}

.rank-1 { background: #ffd166; color: #000; box-shadow: 0 0 10px #ffd166; }
.rank-2 { background: #e2e8f0; color: #000; box-shadow: 0 0 10px #e2e8f0; }
.rank-3 { background: #cd7f32; color: #fff; box-shadow: 0 0 10px #cd7f32; }

/* Responsive Adjustments */
@media (max-width: 600px) {
    .container {
        padding: 12px 8px;
    }
    .card {
        padding: 18px 14px;
    }
    .logo-emblem-wrapper {
        width: 76px;
        height: 76px;
    }
    .game-logo-title {
        font-size: 2.2rem;
    }
    .game-logo-subtitle {
        font-size: 0.9rem;
    }
    .player-card {
        aspect-ratio: 4 / 5;
        max-width: min(290px, 35vh);
        margin: 0 auto 20px auto;
        padding: 5px;
    }
    .btn-option {
        padding: 14px 10px;
        font-size: 0.95rem;
    }
    .options-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .restart-home-row {
        grid-template-columns: 1fr;
    }
}

/* Tablet / iPad Spacing */
@media (min-width: 601px) and (max-width: 1024px) {
    .player-card {
        aspect-ratio: 4 / 5;
        max-width: min(330px, 38vh);
        margin: 0 auto 24px auto;
    }
    .options-grid {
        gap: 14px;
    }
}

@media (max-width: 380px) {
    .logo-emblem-wrapper {
        width: 64px;
        height: 64px;
    }
    .game-logo-title {
        font-size: 1.8rem;
    }
    .player-card {
        aspect-ratio: 4 / 5;
        max-height: 250px;
        margin: 0 auto 16px auto;
    }
    .btn {
        padding: 12px 16px;
        font-size: 0.9rem;
    }
    .btn-option {
        padding: 12px 8px;
        font-size: 0.88rem;
    }
}
