* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none; /* Prevent text selection on click */
    -webkit-user-select: none; /* Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE/Edge */
}

body {
    font-family: 'Sarabun', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    cursor: default; /* Default cursor instead of text cursor */
    touch-action: none; /* Prevent scrolling/zooming on mobile */
    -webkit-touch-callout: none; /* Prevent callout on iOS */
}

#game-container {
    position: relative;
    width: 800px;
    height: 600px;
    background: #000;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    overflow: hidden;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    transform-origin: center center;
    transition: none; /* Let anime.js handle the animation */
    opacity: 0; /* Start invisible for opening animation */
}

/* Start Screen */
#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.98) 0%, rgba(118, 75, 162, 0.98) 50%, rgba(237, 100, 166, 0.98) 100%);
    background-size: 200% 200%;
    animation: gradientShift 8s ease infinite;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    overflow: hidden;
}

/* Animated background gradient */
@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Particles Canvas */
#particles-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.start-content {
    text-align: center;
    color: white;
    animation: fadeInUp 1s ease;
    position: relative;
    z-index: 1;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.start-content h1 {
    position: relative;
    font-size: 72px;
    font-weight: 700;
    margin-bottom: 15px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.4),
                 0 0 20px rgba(255, 255, 255, 0.3);
    letter-spacing: 2px;
    animation: glow 2s ease-in-out infinite alternate;
}

/* Animated light orbs on title */
.start-content h1::before,
.start-content h1::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 1) 0%, rgba(255, 200, 220, 0.5) 50%, transparent 100%);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.8),
                0 0 40px rgba(255, 200, 220, 0.6);
    animation: orbit 4s ease-in-out infinite;
}

.start-content h1::before {
    left: -30px;
    top: 50%;
    animation-delay: 0s;
}

.start-content h1::after {
    right: -30px;
    top: 50%;
    animation-delay: 2s;
}

@keyframes orbit {
    0%, 100% { 
        transform: translate(0, -50%) scale(1);
        opacity: 0.6;
    }
    25% {
        transform: translate(-10px, -60%) scale(1.2);
        opacity: 1;
    }
    50% { 
        transform: translate(0, -70%) scale(0.8);
        opacity: 0.6;
    }
    75% {
        transform: translate(10px, -60%) scale(1.2);
        opacity: 1;
    }
}

/* Floating shapes (animated by anime.js) */
.float-shape {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0%, rgba(255, 180, 220, 0.4) 100%);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.6),
                0 0 20px rgba(255, 180, 220, 0.4);
    pointer-events: none;
    left: 50%;
    top: 50%;
}

@keyframes glow {
    from {
        text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.4),
                     0 0 20px rgba(255, 255, 255, 0.3);
    }
    to {
        text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.4),
                     0 0 30px rgba(255, 255, 255, 0.5),
                     0 0 40px rgba(255, 200, 220, 0.3);
    }
}

.start-content .subtitle {
    font-size: 22px;
    margin-bottom: 50px;
    opacity: 0.95;
    font-weight: 300;
    letter-spacing: 3px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    animation: fadeIn 1.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 0.95; }
}

#start-button {
    padding: 18px 50px;
    font-size: 20px;
    font-weight: 600;
    background: linear-gradient(135deg, #ffffff 0%, #f0f0ff 100%);
    color: #667eea;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2),
                0 0 20px rgba(255, 255, 255, 0.3);
    position: relative;
    overflow: hidden;
    letter-spacing: 1px;
    z-index: 10;
}

#start-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(102, 126, 234, 0.2), rgba(118, 75, 162, 0.1));
    transform: translate(-50%, -50%);
    transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
    z-index: -1;
}

#start-button:hover::before {
    width: 300px;
    height: 300px;
}

#start-button:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25),
                0 0 50px rgba(255, 255, 255, 0.4),
                0 0 80px rgba(102, 126, 234, 0.3);
}

#start-button:active {
    transform: translateY(-1px) scale(0.98);
    transition: all 0.1s ease;
}

#start-button:disabled {
    cursor: default;
    pointer-events: none;
    opacity: 0.7;
    background: linear-gradient(135deg, #d0d0d0 0%, #e0e0e0 100%);
}

/* Button content */
#start-button .button-text {
    display: inline-block;
}

/* Loading spinner */
#start-button .spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 10px;
    border: 3px solid rgba(102, 126, 234, 0.3);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* White flash transition overlay */
.transition-flash {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, 
        rgba(255, 255, 255, 1) 0%,
        rgba(255, 220, 240, 0.95) 30%,
        rgba(200, 180, 255, 0.9) 60%,
        rgba(102, 126, 234, 0.8) 100%
    );
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
}

/* Opening animation overlay */
#opening-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 9999;
    pointer-events: none;
}

/* Fade out animation for start screen */
#start-screen.fade-out {
    animation: fadeOut 0.8s ease forwards;
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.95);
    }
}

/* Dialogue Box */
#dialogue-box {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 700px;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.92) 0%, rgba(20, 20, 40, 0.92) 100%);
    border: 3px solid rgba(102, 126, 234, 0.6);
    border-radius: 15px;
    padding: 25px 30px;
    color: white;
    z-index: 50;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5),
                0 0 20px rgba(102, 126, 234, 0.2);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

#dialogue-box * {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

#dialogue-box:hover {
    border-color: #667eea;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6),
                0 0 30px rgba(102, 126, 234, 0.4);
    transform: translateX(-50%) translateY(-2px);
}

.dialogue-content {
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.dialogue-counter {
    position: absolute;
    top: -10px;
    right: 0;
    font-size: 12px;
    color: #888;
}

#dialogue-text {
    font-size: 19px;
    line-height: 1.7;
    margin-bottom: 12px;
    min-height: 60px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.3px;
}

.dialogue-prompt {
    text-align: right;
    font-size: 14px;
    color: #b8b8ff;
    font-style: italic;
    animation: blink 1.5s infinite;
    text-shadow: 0 0 8px rgba(102, 126, 234, 0.5);
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Choice Menu */
#choice-menu {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    border: 3px solid #fff;
    border-radius: 15px;
    padding: 30px;
    color: white;
    min-width: 400px;
    z-index: 60;
}

.choice-content h3 {
    text-align: center;
    margin-bottom: 20px;
    font-size: 24px;
}

#choice-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.choice-option {
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    font-size: 16px;
}

.choice-option:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: white;
    transform: translateX(5px);
}

.choice-option.selected {
    background: rgba(102, 126, 234, 0.5);
    border-color: #667eea;
}

/* Notification */
#notification {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.95) 0%, rgba(118, 75, 162, 0.95) 100%);
    color: white;
    padding: 15px 35px;
    border-radius: 30px;
    font-size: 16px;
    font-weight: 600;
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.4),
                0 0 20px rgba(102, 126, 234, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
    z-index: 70;
    animation: slideDown 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes slideDown {
    from {
        transform: translate(-50%, -100px);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

/* Hidden utility class */
.hidden {
    display: none !important;
}

/* Mobile Controls */
#mobile-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 200px;
    pointer-events: none;
    z-index: 1000;
}

/* Show controls on landscape for touch devices */
@media (orientation: landscape) and (max-height: 900px) {
    #mobile-controls:not(.hidden) {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* Hide controls ONLY on start screen */
body:has(#start-screen:not([style*="display: none"])) #mobile-controls {
    display: none !important;
}

.mobile-dpad {
    position: absolute;
    bottom: 30px;
    left: 30px;
    display: flex;
    gap: 15px;
}

.mobile-action {
    position: absolute;
    bottom: 30px;
    right: 30px;
}

.mobile-btn {
    width: 70px;
    height: 70px;
    background: rgba(255, 255, 255, 0.3);
    border: 3px solid rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    color: white;
    font-size: 32px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.1s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.mobile-btn:active {
    background: rgba(255, 255, 255, 0.6);
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.mobile-btn-action {
    width: 80px;
    height: 80px;
    background: rgba(255, 107, 157, 0.8);
    border-color: rgba(255, 182, 217, 0.9);
    font-size: 36px;
}

.mobile-btn-action:active {
    background: rgba(255, 107, 157, 1);
}

/* Mobile/Tablet Responsive - LANDSCAPE OPTIMIZED */
@media only screen and (orientation: landscape) and (max-height: 900px) {
    body {
        align-items: center;
        justify-content: center;
        padding: 0;
        margin: 0;
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }

    #game-container {
        border-radius: 0 !important;
        /* Size controlled by JavaScript */
    }

    #gameCanvas {
        width: 100% !important;
        height: 100% !important;
        display: block !important;
    }

    /* Ensure start screen also fills */
    #start-screen {
        border-radius: 0 !important;
    }
}

/* Portrait mode - show rotation message */
@media only screen and (max-width: 850px) and (orientation: portrait) {
    body::after {
        content: 'กรุณาหมุนจอเป็นแนวนอน';
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: rgba(0, 0, 0, 0.9);
        color: white;
        padding: 30px 40px;
        border-radius: 15px;
        font-size: 24px;
        font-weight: 600;
        text-align: center;
        z-index: 99999;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
        pointer-events: none;
    }

    body::before {
        content: '📱 ↻';
        position: fixed;
        top: calc(50% - 80px);
        left: 50%;
        transform: translate(-50%, -50%);
        font-size: 60px;
        z-index: 99999;
        pointer-events: none;
        animation: rotateIcon 2s ease-in-out infinite;
    }

    @keyframes rotateIcon {
        0%, 100% { transform: translate(-50%, -50%) rotate(0deg); }
        50% { transform: translate(-50%, -50%) rotate(90deg); }
    }
}

/* Landscape mobile button adjustments */
@media only screen and (max-width: 500px) and (orientation: landscape) {
    .mobile-btn {
        width: 55px;
        height: 55px;
        font-size: 26px;
    }

    .mobile-btn-action {
        width: 65px;
        height: 65px;
        font-size: 30px;
    }

    .mobile-dpad {
        bottom: 15px;
        left: 15px;
        gap: 10px;
    }

    .mobile-action {
        bottom: 15px;
        right: 15px;
    }
}

/* Short landscape (phones in landscape) */
@media only screen and (max-height: 500px) and (orientation: landscape) {
    .mobile-btn {
        width: 50px;
        height: 50px;
        font-size: 24px;
    }

    .mobile-btn-action {
        width: 60px;
        height: 60px;
        font-size: 28px;
    }

    .mobile-dpad {
        bottom: 10px;
        left: 10px;
        gap: 8px;
    }

    .mobile-action {
        bottom: 10px;
        right: 10px;
    }

    #mobile-controls {
        height: 120px;
    }
}

/* Touch-friendly dialogue */
@media (hover: none) and (pointer: coarse) {
    #dialogue-box {
        cursor: pointer;
    }

    .choice-option {
        min-height: 50px;
        padding: 15px 20px;
    }

    #start-button {
        min-height: 60px;
        padding: 15px 40px;
    }
}

/* Start screen landscape adjustments */
@media only screen and (max-width: 850px) and (orientation: landscape) {
    .start-content h1 {
        font-size: 52px;
        margin-bottom: 10px;
    }

    .start-content .subtitle {
        font-size: 22px;
        margin-bottom: 25px;
    }

    #start-button {
        font-size: 24px;
        padding: 15px 50px;
    }
}

/* Small landscape screens (phones) */
@media only screen and (max-height: 500px) and (orientation: landscape) {
    .start-content h1 {
        font-size: 40px;
        margin-bottom: 8px;
    }

    .start-content .subtitle {
        font-size: 18px;
        margin-bottom: 15px;
    }

    #start-button {
        font-size: 20px;
        padding: 12px 40px;
    }

    /* Hide decorative orbs on small screens */
    .start-content h1::before,
    .start-content h1::after {
        display: none;
    }
}

