* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.game-container {
    position: relative;
    max-width: 800px;
    width: 100%;
    height: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

header {
    margin-bottom: 10px;
    flex-shrink: 0;
}

h1 {
    color: #ffd700;
    font-size: 2rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin-bottom: 10px;
}

.stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
}

.stat {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 20px;
    border-radius: 10px;
    backdrop-filter: blur(5px);
}

.stat-label {
    display: block;
    color: #aaa;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    display: block;
    color: #fff;
    font-size: 1.5rem;
    font-weight: bold;
}

/* Multiplier-specific styles */
.multiplier-stat {
    position: relative;
}

.multiplier-bar {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    margin-top: 5px;
    overflow: hidden;
}

.multiplier-fill {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #ffd700, #ff6b6b);
    border-radius: 2px;
    transition: width 0.1s ease;
    width: 0%;
}

/* Multiplier tier colors */
.multiplier-good {
    color: #4caf50 !important;
}

.multiplier-epic {
    color: #9c27b0 !important;
    text-shadow: 0 0 10px rgba(156, 39, 176, 0.5);
}

.multiplier-legendary {
    color: #ffd700 !important;
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.7);
    animation: legendaryPulse 0.5s ease infinite alternate;
}

@keyframes legendaryPulse {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

/* Multiplier pop-up feedback */
.multiplier-pop {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    font-weight: bold;
    color: #4caf50;
    opacity: 0;
    pointer-events: none;
    z-index: 50;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
}

.multiplier-pop.show {
    opacity: 1;
    animation: popUp 0.8s ease forwards;
}

.multiplier-pop.negative {
    color: #ff6b6b;
}

@keyframes popUp {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    20% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }
    80% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -60%) scale(1);
        opacity: 0;
    }
}

.notification {
    height: 30px;
    line-height: 30px;
    color: #ffd700;
    font-size: 1rem;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.3s ease;
    flex-shrink: 0;
}

.notification.show {
    opacity: 1;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: min(12px, 2vw);
    padding: min(20px, 3vw);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    margin-bottom: 10px;
    width: 100%;
    max-width: min(100%, calc((100dvh - 280px) * 1.25));
    margin-left: auto;
    margin-right: auto;
    flex: 1;
    align-content: center;
    justify-items: center;
}

.card {
    width: 100%;
    aspect-ratio: 1;
    background: linear-gradient(145deg, #2d3a4a, #1e2836);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1.8rem, 8vw, 3.5rem);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    user-select: none;
}

.card.empty {
    background: transparent;
    border: 2px dashed rgba(255, 255, 255, 0.1);
    cursor: default;
}

.card.empty:hover {
    transform: none;
    border-color: rgba(255, 255, 255, 0.1);
    background: transparent;
}

.card:hover:not(.matched):not(.selected) {
    transform: scale(1.05);
    border-color: rgba(255, 255, 255, 0.3);
    background: linear-gradient(145deg, #3d4a5a, #2e3846);
}

.card.selected {
    border-color: #ffd700;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
    transform: scale(1.08);
}

.card.matched {
    animation: matchFade 0.4s ease forwards;
}

@keyframes matchFade {
    0% {
        transform: scale(1.1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.5;
    }
    100% {
        transform: scale(0);
        opacity: 0;
        visibility: hidden;
    }
}

.card.invalid {
    animation: shake 0.3s ease;
    border-color: #ff4444;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 100;
}

.game-over-overlay.show {
    opacity: 1;
    visibility: visible;
}

.game-over-content {
    background: linear-gradient(145deg, #2d3a4a, #1e2836);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    border: 3px solid #ffd700;
}

.game-over-content h2 {
    color: #ff6b6b;
    font-size: 2.5rem;
    margin-bottom: 20px;
}

.game-over-content p {
    color: #fff;
    font-size: 1.3rem;
    margin-bottom: 10px;
}

#new-high-score {
    color: #ffd700;
    font-weight: bold;
    animation: pulse 0.5s ease infinite alternate;
}

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

.hidden {
    display: none !important;
}

#restart-btn {
    margin-top: 20px;
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: bold;
    color: #1a1a2e;
    background: linear-gradient(145deg, #ffd700, #ffaa00);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

#restart-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(255, 215, 0, 0.4);
}

footer {
    color: #888;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* Config button */
.config-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.config-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Settings overlay */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 200;
}

.settings-overlay.show {
    opacity: 1;
    visibility: visible;
}

.settings-content {
    background: linear-gradient(145deg, #2d3a4a, #1e2836);
    padding: 30px 40px;
    border-radius: 20px;
    text-align: center;
    border: 3px solid #ffd700;
    min-width: 280px;
}

.settings-content h2 {
    color: #ffd700;
    font-size: 1.8rem;
    margin-bottom: 25px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.setting-label {
    color: #fff;
    font-size: 1.1rem;
}

/* Toggle switch */
.toggle-btn {
    width: 56px;
    height: 30px;
    background: #444;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    position: relative;
    transition: background 0.3s ease;
}

.toggle-btn.active {
    background: #4caf50;
}

.toggle-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.toggle-btn.active .toggle-slider {
    transform: translateX(26px);
}

.reset-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: bold;
    color: #fff;
    background: #c0392b;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reset-btn:hover {
    background: #e74c3c;
    transform: scale(1.05);
}

.close-settings-btn {
    margin-top: 25px;
    padding: 12px 35px;
    font-size: 1.1rem;
    font-weight: bold;
    color: #1a1a2e;
    background: linear-gradient(145deg, #ffd700, #ffaa00);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.close-settings-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(255, 215, 0, 0.4);
}

/* Share link */
#share-link {
    color: #ffd700;
    text-decoration: none;
    margin-left: 10px;
}

#share-link:hover {
    text-decoration: underline;
}

/* Share overlay */
.share-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 200;
}

.share-overlay.show {
    opacity: 1;
    visibility: visible;
}

.share-content {
    background: linear-gradient(145deg, #2d3a4a, #1e2836);
    padding: 30px 40px;
    border-radius: 20px;
    text-align: center;
    border: 3px solid #ffd700;
}

.share-content h2 {
    color: #ffd700;
    font-size: 1.8rem;
    margin-bottom: 20px;
}

.share-content img {
    border-radius: 10px;
    background: #fff;
    padding: 10px;
}

.share-url {
    color: #aaa;
    font-size: 0.85rem;
    margin-top: 15px;
    word-break: break-all;
    max-width: 220px;
}

.close-share-btn {
    margin-top: 20px;
    padding: 12px 35px;
    font-size: 1.1rem;
    font-weight: bold;
    color: #1a1a2e;
    background: linear-gradient(145deg, #ffd700, #ffaa00);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.close-share-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(255, 215, 0, 0.4);
}

/* Responsive Design */
@media (max-width: 600px) {
    h1 {
        font-size: 1.5rem;
        margin-bottom: 8px;
    }

    .stats {
        gap: 10px;
    }

    .stat {
        padding: 6px 12px;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    .card {
        border-radius: 8px;
    }

    .config-btn {
        padding: 6px 12px;
        font-size: 1.2rem;
    }

    footer {
        font-size: 0.8rem;
    }
}

@media (max-width: 400px) {
    h1 {
        font-size: 1.3rem;
    }
}

/* Landscape orientation on phones - move info to left side */
@media (orientation: landscape) and (max-height: 500px) {
    body {
        padding: 5px;
        padding-left: max(5px, env(safe-area-inset-left));
        padding-right: max(5px, env(safe-area-inset-right));
    }

    .game-container {
        flex-direction: row;
        max-width: 100%;
        gap: 10px;
    }

    header {
        flex-direction: column;
        justify-content: center;
        margin-bottom: 0;
        min-width: 100px;
        max-width: 140px;
        flex-shrink: 0;
    }

    h1 {
        font-size: 1rem;
        margin-bottom: 10px;
        line-height: 1.2;
    }

    .stats {
        flex-direction: column;
        gap: 8px;
    }

    .stat {
        padding: 5px 10px;
    }

    .stat-label {
        font-size: 0.6rem;
    }

    .stat-value {
        font-size: 0.95rem;
    }

    .notification {
        position: absolute;
        top: 5px;
        left: 50%;
        transform: translateX(-50%);
        height: auto;
        padding: 3px 10px;
        font-size: 0.8rem;
        background: rgba(0, 0, 0, 0.7);
        border-radius: 5px;
        z-index: 10;
    }

    .card-grid {
        flex: 1;
        min-height: 0;
        max-width: none;
        max-height: 100%;
        height: 100%;
        margin: 0;
        padding: min(8px, 1.5vw);
        aspect-ratio: auto;
        grid-template-rows: repeat(4, 1fr);
        align-content: stretch;
        overflow: hidden;
    }

    .card {
        font-size: clamp(1.5rem, 12vh, 3rem);
        aspect-ratio: auto;
        width: 100%;
        height: 100%;
    }

    footer {
        display: none;
    }

    .config-btn {
        padding: 5px 10px;
        font-size: 1.1rem;
    }

    .multiplier-bar {
        height: 3px;
        margin-top: 3px;
    }

    .multiplier-pop {
        font-size: 1.5rem;
    }
}
