body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    background-color: #f5f6f8;
}

.dental-game-container {
    width: 100%;
    max-width: 100%;
    margin: 0.5rem auto;
    padding: 0 0.25rem;
    box-sizing: border-box;
    position: relative;
}

.game-aspect-ratio {
    width: 100%;
    padding-bottom: 66.67%;
    position: relative;
    background: linear-gradient(135deg, #ffffff 0%, #f5f6f8 100%);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

#game-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Ensure zoom controls don't cause scrolling */
}

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
    object-fit: contain;
    background: linear-gradient(135deg, #ffffff 0%, #fff1e6 20%, #f5f6f8 60%, #e1e5ed 100%);
    border: none;
    margin: 0;
    padding: 0;
}

.game-dialog {
    position: fixed;
    padding: 12px 16px;
    background: white;
    border: 2px solid #ff6b35;
    border-radius: 8px;
    max-width: 90vw;
    min-width: auto;
    box-sizing: border-box;
    margin: 0;
    opacity: 0;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transform: translateX(-50%) translateY(5px);
    transition: all 0.2s ease-out;
    display: none;
    font-size: 16px;
    line-height: 1.5;
    font-family: Arial, sans-serif;
    color: #333333;
    padding: 20px 25px;
    background: #ffffff;
    border: 3px solid #ff6b35;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    will-change: opacity, transform;
}

.game-dialog:hover {
    transform: translateX(-50%) translateY(0);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.game-dialog.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    display: block;
}

/* Modal-specific dialog styles */
.game-dialog.modal-dialog {
    position: absolute;
    z-index: 10;
}

.dialog-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: #ff6b35;
    opacity: 0.6;
    transition: width linear;
}

.game-dialog::after {
    content: '';
    position: absolute;
    bottom: -12px;
    width: 0;
    height: 0;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 12px solid #ff6b35;
}

.game-dialog.arrow-left::after {
    left: 20%;
}

.game-dialog.arrow-center::after {
    left: 50%;
    transform: translateX(-50%);
}

.game-dialog.arrow-right::after {
    right: 20%;
}

.game-dialog strong {
    color: #ff6b35;
    font-weight: bold;
}

.game-dialog br {
    margin-bottom: 8px;
    content: "";
    display: block;
}

/* Media Queries */
@media (max-width: 768px) {
    .dental-game-container {
        margin: 0;
        padding: 0;
    }
    
    /* Adjust aspect ratio for mobile portrait */
    .game-aspect-ratio {
        padding-bottom: 100%;
        border-radius: 0;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .game-aspect-ratio {
        padding-bottom: 56.25%;
    }
    
    .dental-game-container {
        max-height: 100vh;
        margin: 0;
        padding: 0;
    }
}

/* Loading spinner styles */
#game-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    display: none; /* Hidden by default */
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 10px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #ff6b35;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.scene-transition {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    visibility: hidden;
    overflow: hidden;
}

.scene-transition-overlay {
    position: absolute;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    transform: translateX(-100%) skewX(45deg);
    transform-origin: 0 0;
}

.scene-transition-overlay::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, 
        rgba(255, 107, 53, 0.98) 0%,
        rgba(255, 134, 89, 0.98) 50%,
        rgba(255, 107, 53, 0.98) 100%
    );
    box-shadow: 0 0 50px rgba(255, 107, 53, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.scene-transition-overlay::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.1),
        rgba(255, 255, 255, 0.1) 2px,
        transparent 2px,
        transparent 4px
    );
    mix-blend-mode: overlay;
    animation: moveStripes 20s linear infinite;
}

.scene-transition.active {
    visibility: visible;
}

.scene-transition.wipe-out .scene-transition-overlay {
    animation: wipeOut 0.3s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

.scene-transition.wipe-in .scene-transition-overlay {
    transform: translateX(10%) skewX(45deg);
    animation: wipeIn 0.3s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

@keyframes wipeOut {
    0% {
        transform: translateX(-100%) skewX(45deg);
        filter: brightness(1) saturate(1);
    }
    100% {
        transform: translateX(10%) skewX(45deg);
        filter: brightness(1.2) saturate(1.1);
    }
}

@keyframes wipeIn {
    0% {
        transform: translateX(10%) skewX(45deg);
        filter: brightness(1.2) saturate(1.1);
    }
    100% {
        transform: translateX(200%) skewX(45deg);
        filter: brightness(1) saturate(1);
    }
}

@keyframes moveStripes {
    0% {
        background-position: 0 0;
    }
    100% {
        background-position: 50px 50px;
    }
}

/* Add a subtle pulse animation to the overlay */
.scene-transition.active .scene-transition-overlay::before {
    animation: pulseOverlay 2s ease-in-out infinite;
}

@keyframes pulseOverlay {
    0%, 100% {
        opacity: 0.98;
    }
    50% {
        opacity: 0.95;
    }
}

/* Start Game Overlay */
.start-game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, 
        rgba(200, 224, 200, 0.85) 0%,    /* Light sage, more transparent */
        rgba(168, 192, 168, 0.85) 50%,    /* Darker sage, more transparent */
        rgba(216, 232, 216, 0.85) 100%    /* Lighter sage, more transparent */
    );
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.5s ease-out;
    cursor: pointer;
}

.start-game-overlay::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.1),
        rgba(255, 255, 255, 0.1) 2px,
        transparent 2px,
        transparent 4px
    );
    mix-blend-mode: overlay;
    animation: moveStripes 20s linear infinite;
    pointer-events: none;
}

.start-game-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.start-game-content {
    text-align: center;
    color: #2c4a2c;  /* Dark sage for text */
    padding: 3rem;
    transform: translateY(0);
    transition: transform 0.3s ease-out;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 24px;
    box-shadow: 0 8px 32px rgba(44, 74, 44, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    max-width: 600px;
    width: 90%;
    position: relative;
}

.doctor-sprite {
    width: 160px;
    height: 160px;
    margin: -100px auto 1rem;
    position: relative;
    filter: drop-shadow(0 4px 8px rgba(44, 74, 44, 0.2));
    animation: floatDoctor 3s ease-in-out infinite;
    transform-origin: center bottom;
}

.doctor-sprite img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform: scale(1.4);  /* Make the doctor larger */
    image-rendering: pixelated;  /* Keep pixel art crisp */
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

@keyframes floatDoctor {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-8px);
    }
}

.start-game-overlay:hover .start-game-content {
    transform: translateY(-5px);
}

.start-game-content h1 {
    font-size: 2.2rem;
    margin-bottom: 1rem;
    font-family: Arial, sans-serif;
    text-shadow: 2px 2px 4px rgba(255, 255, 255, 0.5);
    color: #1a3a1a;  /* Darker sage for title */
    line-height: 1.2;
}

.start-game-content p {
    font-size: 1.1rem;
    margin-bottom: 2rem;
    opacity: 0.9;
    color: #2c4a2c;  /* Dark sage for description */
    line-height: 1.6;
    max-width: 90%;
    margin-left: auto;
    margin-right: auto;
}

.start-button {
    display: inline-block;
    padding: 1rem 2.5rem;
    font-size: 1.2rem;
    background: linear-gradient(135deg, #a8c0a8, #c8e0c8);  /* Sage gradient */
    color: #1a3a1a;  /* Dark sage text */
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(44, 74, 44, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-weight: 500;
    letter-spacing: 0.5px;
}

.start-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(44, 74, 44, 0.3);
    background: linear-gradient(135deg, #b8d0b8, #d8e8d8);  /* Lighter sage gradient on hover */
}

@media (max-width: 768px) {
    .start-game-content {
        padding: 1.5rem;
        width: 85%;
        margin: 0 auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        min-height: 0;
        position: relative;
    }

    .doctor-sprite {
        display: none;
    }

    .start-game-content h1 {
        font-size: 1.4rem;
        margin-bottom: 1.25rem;
        padding: 0 0.5rem;
    }
    
    .start-game-content p {
        display: none;
    }
    
    .start-button {
        padding: 0.7rem 1.8rem;
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }
}

/* Add specific adjustments for very small screens */
@media (max-width: 380px) {
    .start-game-content {
        padding: 1.25rem;
        width: 90%;
    }

    .doctor-sprite {
        width: 70px;
        height: 70px;
    }

    .start-game-content h1 {
        font-size: 1.3rem;
        margin-bottom: 1rem;
    }
}

/* Add adjustments for landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .start-game-content {
        padding: 1rem 2rem;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        gap: 1.5rem;
    }

    .doctor-sprite {
        margin: 0;
        width: 60px;
        height: 60px;
    }

    .start-game-content h1 {
        font-size: 1.3rem;
        margin-bottom: 1rem;
        text-align: left;
    }

    .right-content {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }
}

.zoom-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.8);
    padding: 10px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    pointer-events: auto;
    transition: opacity 0.3s ease;
}

.zoom-controls:hover {
    background: rgba(255, 255, 255, 0.95);
}

/* Mobile adjustments for zoom controls */
@media (max-width: 768px) {
    .zoom-controls {
        bottom: 10px;
        right: 10px;
        padding: 8px;
        gap: 8px;
    }

    .zoom-controls input[type="range"] {
        width: 80px;
    }

    .zoom-controls button {
        width: 24px;
        height: 24px;
        font-size: 16px;
    }
}

/* Landscape mode adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .zoom-controls {
        bottom: 15px;
        right: 15px;
    }
}