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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #c41e3a 0%, #8b0000 50%, #ff6347 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: -webkit-fill-available; /* iOS viewport fix */
    padding: 10px;
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-user-select: none;
    user-select: none;
    /* Support for iPhone notch and Dynamic Island */
    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));
}

html {
    height: -webkit-fill-available;
}

.container {
    position: relative;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 20px;
    padding: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 4px solid #ffd700;
    max-width: 100%;
    width: 100%;
    max-width: 450px;
    box-sizing: border-box;
}

@media (max-width: 480px) {
    .container {
        border-radius: 10px;
        padding: 8px;
        border: 2px solid #ffd700;
        margin-top: 5px;
    }

    body {
        padding: 5px;
        padding-top: max(5px, env(safe-area-inset-top));
        align-items: flex-start;
        padding-top: calc(max(5px, env(safe-area-inset-top)) + 10px);
    }
}

.header {
    text-align: center;
    margin-bottom: 15px;
    padding: 10px;
    background: linear-gradient(90deg, #c41e3a, #ff6347);
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.canvas-container {
    position: relative;
    display: block;
    width: 100%;
}

.countdown {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
    border-radius: 10px;
}

.countdown-number {
    font-size: 8em;
    font-weight: bold;
    color: #ffd700;
    text-shadow:
        0 0 20px #ff6347,
        0 0 40px #ff6347,
        0 0 60px #ff6347,
        4px 4px 8px rgba(0, 0, 0, 0.8);
    animation: countdownPulse 1s ease-in-out;
}

@keyframes countdownPulse {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.countdown-number.go {
    font-size: 6em;
    color: #00ff00;
    text-shadow:
        0 0 20px #00ff00,
        0 0 40px #00ff00,
        0 0 60px #00ff00,
        4px 4px 8px rgba(0, 0, 0, 0.8);
}

/* Oops message on crash - positioned at collision point */
.oops-message {
    position: absolute;
    z-index: 998;
    pointer-events: none;
    transform-origin: center center;
}

.oops-text {
    font-size: 4em;
    font-weight: bold;
    color: #ff4444;
    text-shadow:
        0 0 10px #ff0000,
        0 0 20px #ff0000,
        0 0 30px #ff0000,
        2px 2px 4px rgba(0, 0, 0, 0.8);
    animation: oopsExplode 0.5s ease-out;
    white-space: nowrap;
}

/* Starburst effect */
.starburst {
    position: absolute;
    width: 200px;
    height: 200px;
    z-index: 997;
    pointer-events: none;
}

.starburst::before,
.starburst::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.8) 0%, rgba(255, 99, 71, 0.6) 30%, transparent 70%);
    transform: translate(-50%, -50%);
    animation: starburstExpand 0.6s ease-out;
}

.starburst::after {
    animation-delay: 0.1s;
    background: radial-gradient(circle, rgba(255, 99, 71, 0.6) 0%, rgba(255, 0, 0, 0.4) 30%, transparent 70%);
}

/* Star rays */
.starburst-rays {
    position: absolute;
    width: 100%;
    height: 100%;
    animation: starburstRotate 0.6s ease-out;
}

.starburst-ray {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4px;
    height: 80px;
    background: linear-gradient(to top, transparent, #ffd700, transparent);
    transform-origin: center bottom;
    opacity: 0.8;
}

.starburst-ray:nth-child(1) { transform: translate(-50%, -100%) rotate(0deg); }
.starburst-ray:nth-child(2) { transform: translate(-50%, -100%) rotate(45deg); }
.starburst-ray:nth-child(3) { transform: translate(-50%, -100%) rotate(90deg); }
.starburst-ray:nth-child(4) { transform: translate(-50%, -100%) rotate(135deg); }
.starburst-ray:nth-child(5) { transform: translate(-50%, -100%) rotate(180deg); }
.starburst-ray:nth-child(6) { transform: translate(-50%, -100%) rotate(225deg); }
.starburst-ray:nth-child(7) { transform: translate(-50%, -100%) rotate(270deg); }
.starburst-ray:nth-child(8) { transform: translate(-50%, -100%) rotate(315deg); }

@keyframes oopsExplode {
    0% {
        transform: scale(0.3) rotate(-15deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.3) rotate(5deg);
        opacity: 1;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

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

@keyframes starburstRotate {
    0% {
        transform: rotate(0deg) scale(0);
        opacity: 1;
    }
    100% {
        transform: rotate(90deg) scale(1.5);
        opacity: 0;
    }
}

@media (max-width: 480px) {
    .countdown-number {
        font-size: 5em;
    }

    .countdown-number.go {
        font-size: 4em;
    }

    .oops-text {
        font-size: 3em;
    }

    .starburst {
        width: 150px;
        height: 150px;
    }

    .starburst-ray {
        height: 60px;
        width: 3px;
    }
}

@media (max-height: 700px) {
    .countdown-number {
        font-size: 4em;
    }

    .countdown-number.go {
        font-size: 3em;
    }

    .oops-text {
        font-size: 2.5em;
    }

    .starburst {
        width: 120px;
        height: 120px;
    }

    .starburst-ray {
        height: 50px;
        width: 2px;
    }
}

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

.subtitle {
    color: #fff;
    font-size: 0.9em;
    font-style: italic;
}

@media (max-width: 480px) {
    .header {
        padding: 5px;
        margin-bottom: 6px;
        /* Ensure header is below notch/Dynamic Island */
        margin-top: max(0px, calc(env(safe-area-inset-top) - 60px));
    }

    .header h1 {
        font-size: 1.2em;
        margin-bottom: 2px;
    }

    .subtitle {
        font-size: 0.7em;
    }
}

.sound-toggle {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(255, 215, 0, 0.8);
    border: 2px solid #ffd700;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2em;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.sound-toggle:hover {
    background: rgba(255, 215, 0, 1);
    transform: scale(1.1);
}

.sound-toggle.muted {
    opacity: 0.5;
}

/* Mobile optimizations */
@media (max-width: 480px) {
    .sound-toggle {
        width: 35px;
        height: 35px;
        font-size: 1em;
        bottom: 8px;
        left: 8px;
    }

    .btn {
        padding: 12px 25px;
        font-size: 1em;
    }

}

/* iPhone with notch/Dynamic Island support */
@supports (padding: max(0px)) {
    @media (max-width: 480px) {
        body {
            padding-top: calc(env(safe-area-inset-top) + 5px);
        }

        .container {
            margin-top: 0;
        }

        .header {
            margin-top: 5px;
        }
    }
}

/* Compact mode for very small screens */
@media (max-height: 700px) {
    .header {
        padding: 5px;
        margin-bottom: 6px;
    }

    .header h1 {
        font-size: 1.2em;
        margin-bottom: 2px;
    }

    .subtitle {
        font-size: 0.7em;
    }

    .info-panel {
        margin-top: 6px;
        gap: 4px;
    }

}

#gameCanvas {
    display: block;
    background: linear-gradient(180deg, #87ceeb 0%, #e0f6ff 50%, #90ee90 100%);
    border: 3px solid #ffd700;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
    width: 100%;
    height: auto;
    max-width: 400px;
    touch-action: none;
}

@media (max-width: 480px) {
    #gameCanvas {
        border: 2px solid #ffd700;
        border-radius: 5px;
    }
}

/* Score overlay on top of game canvas */
.score-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.score-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.score-item {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(0, 0, 0, 0.6);
    padding: 5px 10px;
    border-radius: 20px;
    border: 2px solid rgba(255, 215, 0, 0.8);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.score-icon {
    font-size: 1.2em;
    filter: drop-shadow(0 0 3px #ffd700);
}

.score-value {
    color: #fff;
    font-weight: bold;
    font-size: 1.1em;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    min-width: 20px;
    text-align: center;
}

canvas[id^="miniIcon"] {
    display: block;
}

@media (max-width: 480px) {
    .score-overlay {
        top: 8px;
        left: 8px;
        right: 8px;
    }

    .score-item {
        padding: 4px 8px;
        gap: 4px;
    }

    .score-icon {
        font-size: 1em;
    }

    .score-value {
        font-size: 0.95em;
        min-width: 18px;
    }
}

@media (max-height: 700px) {
    .score-overlay {
        top: 6px;
        left: 6px;
        right: 6px;
    }

    .score-item {
        padding: 3px 6px;
        gap: 3px;
        border: 1px solid rgba(255, 215, 0, 0.8);
    }

    .score-icon {
        font-size: 0.9em;
    }

    .score-value {
        font-size: 0.85em;
        min-width: 16px;
    }
}

/* Old score-display styles removed - now using score-overlay */

.screen {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(26, 26, 46, 0.98);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    border: 3px solid #ffd700;
    max-width: 350px;
    width: 90%;
    max-width: min(350px, calc(100vw - 40px));
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
    max-height: 85vh;
    overflow-y: auto;
    z-index: 1000;
}

/* Safe area for iPhone notch on screens */
@supports (padding: max(0px)) {
    .screen {
        max-height: calc(90vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        top: calc(50% + (env(safe-area-inset-top) / 2));
    }
}

@media (max-width: 480px) {
    .screen {
        padding: 15px;
        border-radius: 10px;
        border: 2px solid #ffd700;
        font-size: 0.85em;
        max-height: 85vh;
    }

    .screen h2 {
        font-size: 1.4em;
        margin-bottom: 10px;
    }

    .screen p {
        font-size: 0.9em;
        margin-bottom: 8px;
    }

    .screen ul {
        margin: 10px 0;
    }

    .screen ul li {
        padding: 4px;
        font-size: 0.8em;
        margin-bottom: 4px;
    }
}

@media (max-height: 700px) {
    .screen {
        padding: 12px;
        font-size: 0.8em;
        max-height: 88vh;
    }

    .screen h2 {
        font-size: 1.3em;
        margin-bottom: 8px;
    }

    .screen p {
        font-size: 0.85em;
        margin-bottom: 6px;
    }

    .screen ul {
        margin: 8px 0;
    }

    .screen ul li {
        padding: 3px;
        font-size: 0.75em;
        margin-bottom: 3px;
    }

    .btn {
        padding: 10px 20px;
        font-size: 0.95em;
        margin-top: 10px;
    }
}

.screen h2 {
    color: #ffd700;
    margin-bottom: 15px;
    font-size: 1.8em;
}

.screen p {
    color: #fff;
    margin-bottom: 10px;
    line-height: 1.6;
}

.screen ul {
    list-style: none;
    margin: 15px 0;
    text-align: left;
}

.screen ul li {
    color: #fff;
    padding: 8px;
    background: rgba(196, 30, 58, 0.3);
    margin-bottom: 8px;
    border-radius: 5px;
    border-left: 3px solid #ffd700;
}

.btn {
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    color: #8b0000;
    border: none;
    padding: 12px 30px;
    font-size: 1.1em;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    margin-top: 15px;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.6);
}

.btn:active {
    transform: translateY(0);
}

.hidden {
    display: none !important;
}

.final-score {
    font-size: 1.3em;
    color: #ffd700;
    font-weight: bold;
    margin: 15px 0;
}

.collection-stats {
    font-size: 1.2em;
    margin: 15px 0;
    padding: 10px;
    background: rgba(196, 30, 58, 0.3);
    border-radius: 8px;
}

.fortune-message {
    color: #ffed4e;
    font-style: italic;
    font-size: 1.1em;
    margin: 15px 0;
    padding: 10px;
    background: rgba(255, 215, 0, 0.1);
    border-radius: 8px;
}

@media (max-height: 700px) {
    .final-score {
        font-size: 1.1em;
        margin: 10px 0;
    }

    .collection-stats {
        font-size: 1em;
        margin: 10px 0;
        padding: 8px;
    }

    .fortune-message {
        font-size: 0.95em;
        margin: 10px 0;
        padding: 8px;
    }
}

canvas[id^="icon"], canvas[id^="finalIcon"] {
    display: inline-block;
    vertical-align: middle;
    margin-right: 5px;
}

.lottery-section {
    margin: 15px 0;
    padding: 12px;
    background: rgba(196, 30, 58, 0.3);
    border-radius: 10px;
    border: 2px solid #ffd700;
}

@media (max-width: 480px) {
    .lottery-section {
        margin: 10px 0;
        padding: 10px;
    }
}

@media (max-height: 700px) {
    .lottery-section {
        margin: 8px 0;
        padding: 8px;
    }

    .lottery-title {
        font-size: 1em;
        margin-bottom: 10px;
    }

    .lottery-numbers {
        gap: 12px;
    }
}

.lottery-title {
    color: #ffd700;
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 15px;
    text-align: center;
}

.lottery-numbers {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* 4D Styling */
.lottery-item-4d {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lottery-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.lottery-label {
    color: #ffd700;
    font-weight: bold;
    font-size: 1.1em;
}

.lottery-sublabel {
    color: #ffed4e;
    font-size: 0.9em;
}

.lottery-4d-box {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 3px solid #ffd700;
    border-radius: 10px;
    padding: 15px;
    text-align: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.lottery-value-4d {
    color: #ffd700;
    font-size: 2.5em;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    letter-spacing: 8px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    transition: all 0.1s ease;
}

.lottery-value-4d.animating {
    animation: numberPulse 0.3s ease-in-out infinite;
}

@keyframes numberPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); opacity: 0.8; }
}

/* TOTO Styling */
.lottery-item-toto {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toto-numbers-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toto-main-numbers {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 3px solid #ffd700;
    border-radius: 10px;
    padding: 12px;
    text-align: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.lottery-value-toto {
    color: #fff;
    font-size: 1.5em;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    letter-spacing: 4px;
    transition: all 0.1s ease;
}

.lottery-value-toto.animating,
.lottery-value-toto-additional.animating {
    animation: numberPulse 0.3s ease-in-out infinite;
}

.toto-additional-container {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

.toto-additional-label {
    color: #ffed4e;
    font-size: 0.9em;
    font-weight: bold;
}

.toto-additional-box {
    background: linear-gradient(135deg, #c41e3a, #8b0000);
    border: 3px solid #ffd700;
    border-radius: 8px;
    padding: 8px 16px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.lottery-value-toto-additional {
    color: #ffd700;
    font-size: 1.5em;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    letter-spacing: 2px;
}

/* Mobile responsive lottery numbers */
@media (max-width: 480px) {
    .lottery-value-4d {
        font-size: 2em;
        letter-spacing: 6px;
    }

    .lottery-value-toto {
        font-size: 1.2em;
        letter-spacing: 2px;
    }

    .lottery-value-toto-additional {
        font-size: 1.2em;
    }

    .lottery-4d-box, .toto-main-numbers, .toto-additional-box {
        padding: 10px;
    }
}

@media (max-height: 700px) {
    .lottery-value-4d {
        font-size: 1.8em;
        letter-spacing: 5px;
    }

    .lottery-value-toto {
        font-size: 1.1em;
        letter-spacing: 2px;
    }

    .lottery-value-toto-additional {
        font-size: 1.1em;
    }

    .lottery-4d-box, .toto-main-numbers {
        padding: 8px;
    }

    .toto-additional-box {
        padding: 6px 12px;
    }

    .lottery-item-4d, .lottery-item-toto {
        gap: 6px;
    }
}

/* iPhone Pro Max and similar large notched phones */
@media (min-width: 400px) and (min-height: 800px) and (max-width: 480px) {
    body {
        padding-top: calc(env(safe-area-inset-top) + 10px);
    }

    .container {
        max-width: 420px;
    }

    .header {
        padding: 6px;
        margin-bottom: 8px;
    }

    .header h1 {
        font-size: 1.4em;
    }

    .subtitle {
        font-size: 0.8em;
    }

}

/* Footer styles */
footer {
    width: 100%;
    max-width: 450px;
    text-align: center;
    padding: 15px 20px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9em;
    margin-top: 10px;
    box-sizing: border-box;
}

footer a {
    color: #ffd700;
    text-decoration: none;
    transition: color 0.3s;
}

footer a:hover {
    color: #ffed4e;
    text-decoration: underline;
}

@media (max-width: 480px) {
    footer {
        font-size: 0.8em;
        padding: 10px 15px;
    }
}
