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

body {
    overflow: hidden;
    background: #0a0e1a;
    font-family: 'Segoe UI', 'Arial', sans-serif;
    cursor: none;
    user-select: none;
    -webkit-user-select: none;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for mobile */
    width: 100vw;
    position: fixed;
    top: 0;
    left: 0;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

body.show-cursor {
    cursor: default;
}

#gameContainer {
    position: relative;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: #0a0e1a;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

#celebrationCanvas {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 12;
    pointer-events: none;
}

#celebrationCanvas.show {
    display: block;
}

/* ============ ROTATE PROMPT ============ */
#rotatePrompt {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 40;
    background: rgba(10, 14, 26, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 20px;
    text-align: center;
    animation: fadeIn 0.5s ease;
}

#rotatePrompt.show {
    display: flex;
}

.rotate-icon {
    font-size: min(15vw, 72px);
    margin-bottom: 10px;
    animation: rotatePhone 3s ease-in-out infinite;
}

@keyframes rotatePhone {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-90deg);
    }

    75% {
        transform: rotate(-90deg);
    }
}

.rotate-text {
    color: rgba(255, 255, 255, 0.5);
    font-size: clamp(12px, 2.5vw, 16px);
    letter-spacing: 2px;
    margin-bottom: 5px;
}

.rotate-text-large {
    color: #ffffff;
    font-size: clamp(20px, 5vw, 32px);
    font-weight: 800;
    letter-spacing: 4px;
    margin-bottom: 8px;
}

.rotate-arrow {
    font-size: clamp(30px, 8vw, 48px);
    color: #fbbf24;
    margin: 8px 0;
    animation: arrowBounce 2s ease-in-out infinite;
}

@keyframes arrowBounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(10px);
    }
}

.rotate-subtext {
    color: rgba(255, 255, 255, 0.3);
    font-size: clamp(11px, 2vw, 14px);
    letter-spacing: 1px;
    margin-bottom: 20px;
}

#rotateDismissBtn {
    padding: 12px 30px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.6);
    font-size: clamp(14px, 2.5vw, 16px);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Segoe UI', 'Arial', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

#rotateDismissBtn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
    border-color: rgba(255, 255, 255, 0.25);
}

#rotateDismissBtn:active {
    transform: scale(0.95);
}

/* ============ SIDE SCORE DISPLAYS ============ */
#playerScoreDisplay {
    position: absolute;
    right: clamp(10px, 3vw, 30px);
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#playerScoreDisplay:hover {
    opacity: 0.8;
}

#aiScoreDisplay {
    position: absolute;
    left: clamp(10px, 3vw, 30px);
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#aiScoreDisplay:hover {
    opacity: 0.8;
}

.score-label-side {
    font-size: clamp(7px, 1.5vw, 10px);
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 600;
}

.player-label {
    color: rgba(96, 165, 250, 0.4);
}

.ai-label {
    color: rgba(248, 113, 113, 0.4);
}

.score-number {
    font-size: clamp(24px, 6vw, 48px);
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 0 40px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
}

.player-score {
    color: #3b82f6;
}

.ai-score {
    color: #ef4444;
}

.score-number.pop-side {
    animation: scorePopSide 0.4s ease;
}

@keyframes scorePopSide {
    0% {
        transform: scale(1);
    }

    40% {
        transform: scale(1.4);
        color: #fbbf24;
    }

    70% {
        transform: scale(0.9);
    }

    100% {
        transform: scale(1);
    }
}

/* ============ CENTER SCOREBOARD ============ */
#scoreboard {
    position: absolute;
    top: clamp(10px, 2vh, 20px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: clamp(10px, 3vw, 25px);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: clamp(4px, 1vh, 8px) clamp(12px, 3vw, 25px);
    border-radius: clamp(10px, 2vw, 16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

#scoreDivider {
    color: rgba(255, 255, 255, 0.2);
    font-size: clamp(10px, 2vw, 14px);
    font-weight: 700;
    letter-spacing: 3px;
}

/* ============ SETTINGS OVERLAY ============ */
#settingsOverlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
    padding: 16px;
}

#settingsOverlay.show {
    display: flex;
}

#settingsTitle {
    font-size: clamp(28px, 6vw, 42px);
    font-weight: 900;
    color: #fbbf24;
    margin-bottom: clamp(15px, 3vh, 30px);
    letter-spacing: 4px;
    text-shadow: 0 0 40px rgba(251, 191, 36, 0.2);
}

#settingsContent {
    background: rgba(255, 255, 255, 0.05);
    border-radius: clamp(14px, 2vw, 20px);
    padding: clamp(16px, 3vw, 30px) clamp(16px, 4vw, 40px);
    max-width: 500px;
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.setting-group {
    margin-bottom: clamp(15px, 2vh, 25px);
}

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-label {
    color: rgba(255, 255, 255, 0.7);
    font-size: clamp(13px, 2vw, 16px);
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.difficulty-buttons,
.win-score-buttons {
    display: flex;
    gap: clamp(6px, 1vw, 10px);
    flex-wrap: wrap;
}

.diff-btn,
.score-btn {
    padding: clamp(6px, 1.5vh, 10px) clamp(12px, 2.5vw, 24px);
    background: rgba(255, 255, 255, 0.06);
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-radius: clamp(8px, 1.5vw, 10px);
    color: rgba(255, 255, 255, 0.5);
    font-size: clamp(12px, 2vw, 15px);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Segoe UI', 'Arial', sans-serif;
    flex: 1;
    min-width: 50px;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
}

.diff-btn:hover,
.score-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
}

.diff-btn.active,
.score-btn.active {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border-color: #3b82f6;
    color: white;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.3);
}

.diff-btn.active:hover,
.score-btn.active:hover {
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
}

.difficulty-desc {
    color: rgba(255, 255, 255, 0.3);
    font-size: clamp(11px, 1.5vw, 13px);
    margin-top: 6px;
    font-style: italic;
    letter-spacing: 0.5px;
}

#settingsCloseBtn {
    margin-top: clamp(12px, 2vh, 20px);
    padding: clamp(10px, 1.5vh, 12px) clamp(24px, 5vw, 40px);
    background: linear-gradient(135deg, #10b981, #059669);
    border: none;
    border-radius: clamp(10px, 1.5vw, 12px);
    color: white;
    font-size: clamp(14px, 2.5vw, 18px);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Segoe UI', 'Arial', sans-serif;
    box-shadow: 0 8px 32px rgba(16, 185, 129, 0.3);
    -webkit-tap-highlight-color: transparent;
}

#settingsCloseBtn:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 48px rgba(16, 185, 129, 0.5);
}

#settingsCloseBtn:active {
    transform: scale(0.95);
}

/* ============ BUTTONS ============ */
#settingsBtn,
#pauseBtn {
    position: absolute;
    top: clamp(10px, 2vh, 20px);
    z-index: 10;
    padding: clamp(4px, 1vh, 8px) clamp(10px, 2vw, 18px);
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: clamp(8px, 1.5vw, 10px);
    color: rgba(255, 255, 255, 0.6);
    font-size: clamp(10px, 1.8vw, 13px);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-family: 'Segoe UI', 'Arial', sans-serif;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

#settingsBtn {
    left: clamp(10px, 2vw, 20px);
}

#pauseBtn {
    right: clamp(10px, 2vw, 20px);
}

#settingsBtn:hover,
#pauseBtn:hover {
    background: rgba(0, 0, 0, 0.6);
    border-color: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
}

#settingsBtn:active,
#pauseBtn:active {
    transform: scale(0.95);
}

#restartBtn {
    display: none;
    position: absolute;
    bottom: clamp(20px, 4vh, 40px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    padding: clamp(12px, 2vh, 16px) clamp(20px, 5vw, 40px);
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border: none;
    border-radius: clamp(12px, 2vw, 16px);
    color: white;
    font-size: clamp(14px, 2.5vw, 20px);
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 40px rgba(59, 130, 246, 0.5);
    transition: all 0.3s ease;
    font-family: 'Segoe UI', 'Arial', sans-serif;
    animation: pulse 2s ease-in-out infinite;
    pointer-events: all;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

#restartBtn.show {
    display: block;
}

#restartBtn:hover {
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 12px 56px rgba(59, 130, 246, 0.7);
}

#restartBtn:active {
    transform: translateX(-50%) scale(0.95);
}

/* ============ READY TEXT ============ */
#readyText {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 15;
    font-size: clamp(32px, 10vw, 72px);
    font-weight: 900;
    letter-spacing: clamp(4px, 1.5vw, 10px);
    color: #ffffff;
    text-shadow:
        0 0 60px rgba(59, 130, 246, 0.5),
        0 0 120px rgba(59, 130, 246, 0.3),
        0 0 200px rgba(59, 130, 246, 0.2);
    animation: readyPulse 0.8s ease-in-out infinite;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.6);
    padding: clamp(12px, 2vh, 20px) clamp(20px, 5vw, 50px);
    border-radius: clamp(14px, 2vw, 20px);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

#readyText.show {
    display: block;
}

/* ============ MATCH POINT NOTIFICATION ============ */
#matchPointOverlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
    padding: 20px;
}

#matchPointOverlay.show {
    display: flex;
}

#matchPointText {
    font-size: clamp(32px, 10vw, 72px);
    font-weight: 900;
    color: #fbbf24;
    text-shadow:
        0 0 60px rgba(251, 191, 36, 0.5),
        0 0 120px rgba(251, 191, 36, 0.3);
    animation: matchPointPulse 0.8s ease-in-out infinite;
    letter-spacing: clamp(4px, 1.5vw, 10px);
    background: rgba(0, 0, 0, 0.7);
    padding: clamp(12px, 2vh, 20px) clamp(20px, 5vw, 50px);
    border-radius: clamp(14px, 2vw, 20px);
    border: 2px solid rgba(251, 191, 36, 0.3);
    text-align: center;
}

#matchPointSubtext {
    font-size: clamp(14px, 3vw, 24px);
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 10px;
    animation: matchPointPulse 0.8s ease-in-out infinite 0.2s;
    letter-spacing: 2px;
    background: rgba(0, 0, 0, 0.5);
    padding: clamp(8px, 1.5vh, 12px) clamp(16px, 4vw, 30px);
    border-radius: clamp(8px, 1.5vw, 12px);
    text-align: center;
}

@keyframes matchPointPulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.9;
    }
}

/* ============ FINAL SCORE OVERLAY ============ */
#finalScoreOverlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 25;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    animation: fadeIn 0.6s ease;
    pointer-events: none;
    padding: 20px;
}

#finalScoreOverlay.show {
    display: flex;
    pointer-events: none;
}

#finalScoreText {
    font-size: clamp(28px, 8vw, 64px);
    font-weight: 900;
    color: #fbbf24;
    text-shadow: 0 0 60px rgba(251, 191, 36, 0.3);
    letter-spacing: clamp(4px, 1.5vw, 8px);
    margin-bottom: 8px;
    animation: finalTextPulse 2s ease-in-out infinite;
    text-align: center;
}

#finalScoreDisplay {
    font-size: clamp(24px, 6vw, 56px);
    font-weight: 800;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 6px;
    letter-spacing: 4px;
}

#finalScoreWinner {
    font-size: clamp(18px, 4vw, 36px);
    font-weight: 700;
    margin-bottom: 10px;
    text-align: center;
}

#finalScoreWinner.win {
    color: #60a5fa;
    text-shadow: 0 0 60px rgba(96, 165, 250, 0.3);
}

#finalScoreWinner.lose {
    color: #f87171;
    text-shadow: 0 0 60px rgba(248, 113, 113, 0.3);
}

#finalScoreWinner.draw {
    color: #fbbf24;
    text-shadow: 0 0 60px rgba(251, 191, 36, 0.3);
}

#finalScoreSubtext {
    font-size: clamp(11px, 2vw, 16px);
    color: rgba(255, 255, 255, 0.3);
    letter-spacing: 1px;
    text-align: center;
}

@keyframes finalTextPulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.03);
        opacity: 0.8;
    }
}

/* ============ PAUSE OVERLAY ============ */
#pauseOverlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 15;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
    pointer-events: none;
    padding: 20px;
}

#pauseOverlay.show {
    display: flex;
    pointer-events: all;
}

.pause-icon {
    font-size: clamp(36px, 8vw, 56px);
    margin-bottom: 12px;
    animation: pausePulse 2s ease-in-out infinite;
}

#pauseText {
    color: white;
    font-size: clamp(28px, 6vw, 44px);
    font-weight: 900;
    letter-spacing: clamp(6px, 1.5vw, 10px);
    margin-bottom: 8px;
    opacity: 0.9;
    text-align: center;
}

#pauseHint {
    color: rgba(255, 255, 255, 0.4);
    font-size: clamp(12px, 2vw, 14px);
    margin-bottom: 20px;
    letter-spacing: 1px;
    text-align: center;
}

#pauseHint kbd {
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 8px;
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    font-family: inherit;
    color: rgba(255, 255, 255, 0.5);
    font-size: clamp(10px, 1.5vw, 12px);
}

#resumeBtn {
    padding: clamp(10px, 1.5vh, 14px) clamp(24px, 5vw, 38px);
    background: linear-gradient(135deg, #10b981, #059669);
    border: none;
    border-radius: clamp(10px, 1.5vw, 12px);
    color: white;
    font-size: clamp(14px, 2.5vw, 18px);
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(16, 185, 129, 0.3);
    transition: all 0.3s ease;
    font-family: 'Segoe UI', 'Arial', sans-serif;
    pointer-events: all;
    -webkit-tap-highlight-color: transparent;
}

#resumeBtn:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 48px rgba(16, 185, 129, 0.5);
}

#resumeBtn:active {
    transform: scale(0.95);
}

/* ============ ANIMATIONS ============ */
@keyframes pulse {

    0%,
    100% {
        transform: translateX(-50%) scale(1);
    }

    50% {
        transform: translateX(-50%) scale(1.03);
    }
}

@keyframes readyPulse {

    0%,
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        opacity: 0.7;
        transform: translate(-50%, -50%) scale(1.02);
    }
}

@keyframes pausePulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ============ RESPONSIVE FINE-TUNING ============ */
/* iPhone SE / Small phones */
@media (max-width: 380px) {
    .score-number {
        font-size: clamp(18px, 5vw, 24px);
    }

    #scoreboard {
        padding: 4px 10px;
        gap: 8px;
    }

    #settingsBtn,
    #pauseBtn {
        font-size: 9px;
        padding: 4px 8px;
    }

    .diff-btn,
    .score-btn {
        font-size: 10px;
        padding: 4px 8px;
        min-width: 35px;
    }
}

/* iPhone 12/13/14 Pro Max - Large phones */
@media (min-width: 768px) and (max-width: 1024px) {
    .score-number {
        font-size: clamp(32px, 6vw, 48px);
    }

    #settingsBtn,
    #pauseBtn {
        font-size: 14px;
        padding: 8px 16px;
    }
}

/* iPad / Tablets */
@media (min-width: 1024px) {

    #settingsBtn,
    #pauseBtn {
        font-size: 15px;
        padding: 10px 20px;
    }

    .score-number {
        font-size: 56px;
    }
}

/* Landscape mode optimization */
@media (orientation: landscape) and (max-height: 500px) {
    #scoreboard {
        top: 8px;
        padding: 4px 12px;
        gap: 10px;
    }

    .score-number {
        font-size: clamp(20px, 5vw, 32px);
    }

    .score-label-side {
        font-size: 8px;
    }

    #settingsBtn,
    #pauseBtn {
        top: 8px;
        padding: 4px 10px;
        font-size: 10px;
    }

    #readyText {
        font-size: clamp(24px, 6vw, 40px);
        padding: 10px 20px;
    }

    #matchPointText {
        font-size: clamp(24px, 6vw, 40px);
        padding: 10px 20px;
    }

    #finalScoreText {
        font-size: clamp(24px, 6vw, 40px);
    }

    #finalScoreDisplay {
        font-size: clamp(20px, 5vw, 32px);
    }

    #finalScoreWinner {
        font-size: clamp(16px, 3vw, 24px);
    }
}

/* Prevent zoom on double tap for iOS */
button,
canvas {
    touch-action: manipulation;
}

/* Safe area insets for iPhone X and newer */
@supports (padding: max(0px)) {
    #gameContainer {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        padding-top: max(0px, env(safe-area-inset-top));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}