body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    /* Safari/iOS optimizations */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#game-header {
    position: fixed;
    top: 0.5vw;
    left: 0.5vw;
    z-index: 1000;
    pointer-events: none;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.8vw;
    /* Use viewport units for responsive scaling */
}

#game-title {
    font-size: clamp(7px, 0.88vw, 11px);
    font-weight: 600;
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 50%, #FF8C00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.08em;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    white-space: nowrap;
    display: none;
}

#game-clock {
    font-size: clamp(6px, 0.69vw, 9px);
    font-weight: 700;
    color: #FFD700;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    padding: 0.12vw 0.5vw;
    border-radius: 0.48vw;
    border: 1px solid rgba(255, 215, 0, 0.4);
    text-align: left;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
    display: none;
    white-space: nowrap;
    margin-left: -0.3vw; /* Shift left slightly */
}

#app-container {
    /* No margin needed - game fills full screen */
    /* Safari/iOS performance optimizations */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* UI Controls - Base styles for desktop */
#ui-controls {
    position: fixed;
    top: 0.5vw;
    right: 0.5vw;
    gap: 0.3vw;
    display: none;
    z-index: 9000;
    pointer-events: auto;
}

#ui-controls button {
    width: clamp(36px, 2.5vw, 50px);
    height: clamp(36px, 2.5vw, 50px);
    pointer-events: auto;
}

#ui-controls svg {
    width: clamp(20px, 1.5vw, 28px);
    height: clamp(20px, 1.5vw, 28px);
    pointer-events: none;
}

/* Portrait mobile devices */
@media (max-width: 768px) and (orientation: portrait) {
    #game-header {
        top: 1vh;
        left: 1vh;
        gap: 1.5vw;
        flex-direction: row;
        align-items: center;
    }

    #game-title {
        font-size: clamp(8px, 2.5vw, 12px);
        letter-spacing: 0.05em;
    }

    #game-clock {
        font-size: clamp(6px, 1.32vw, 7px) !important;
        padding: 0.2vh 0.4vh !important;
        border-radius: 0.6vh !important;
        border-width: 0.5px !important;
    }

    /* Make modals larger in portrait mode (not fullscreen to avoid iOS cut issues) */
    #paytable-modal > div,
    #game-rules-modal > div,
    #game-history-modal > div,
    #bet-menu-modal > div,
    #autoplay-menu-modal > div,
    #settings-info-modal > div,
    #cheat-menu-modal > div {
        max-width: 95vw !important;
        width: 95vw !important;
        max-height: 85vh !important;
    }

    /* Make bet menu buttons smaller in portrait */
    #bet-menu-content .bet-button,
    #bet-menu-content .line-button {
        padding: 8px 10px !important;
        font-size: 14px !important;
    }

    /* Reduce grid gap for bet menu in portrait */
    #bet-menu-content .grid {
        gap: 6px !important;
    }

    /* Smaller section titles in bet menu portrait */
    #bet-menu-content h3 {
        font-size: 16px !important;
    }

    /* Smaller UI control buttons in portrait */
    #ui-controls {
        top: 1vh !important;
        right: 1vh !important;
        gap: 6px !important;
    }

    #ui-controls button {
        width: 40px !important;
        height: 40px !important;
    }

    #ui-controls svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* Compact autoplay menu for portrait to avoid scrollbars */
    #autoplay-menu-content {
        font-size: 14px;
    }

    #autoplay-menu-content h3 {
        font-size: 18px !important;
        margin-bottom: 8px !important;
    }

    #autoplay-menu-content button {
        padding: 10px 14px !important;
        font-size: 14px !important;
    }

}

/* Removed auto-scaling - using collapsible advanced settings instead */

/* Landscape mobile devices */
@media (max-height: 600px) and (orientation: landscape) {
    #game-header {
        top: 1vh;
        left: 1vh;
        gap: 1vw;
        flex-direction: row;
        align-items: center;
    }

    #game-title {
        font-size: clamp(8px, 2vh, 12px);
        letter-spacing: 0.05em;
    }

    #game-clock {
        font-size: clamp(4px, 1.08vh, 7px) !important;
        padding: 0.2vh 0.4vh !important;
        border-radius: 0.6vh !important;
        border-width: 0.5px !important;
    }

    /* Scale down orientation suggestion by 20% in landscape mode */
    #orientation-suggestion > div {
        transform: scale(0.8);
    }

    /* Paytable scaling for landscape small screens */
    .paytable-symbol-img {
        max-width: 100px !important;
    }

    .paytable-card {
        padding: 8px !important;
        gap: 6px !important;
    }

    .paytable-payout-row {
        font-size: 12px !important;
    }

    .paytable-section-title {
        font-size: 18px !important;
    }

    #paytable-content h2 {
        font-size: 20px !important;
    }

    .paytable-grid {
        gap: 12px !important;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    #game-header {
        top: 0.5vh;
        left: 0.5vh;
        gap: 0.3vh;
    }

    #game-title {
        font-size: clamp(7px, 2vw, 10px);
        letter-spacing: 0.03em;
    }

    #game-clock {
        font-size: clamp(6px, 1.8vw, 9px);
        padding: 0.4vh 1vh;
        border-radius: 1vh;
    }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-container {
    background: linear-gradient(145deg, #1a1a1a 0%, #2d2d2d 100%);
    border-radius: 20px;
    border: 2px solid rgba(255, 215, 0, 0.3);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8),
                0 0 30px rgba(255, 215, 0, 0.1);
    max-width: 900px;
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes popupIn {
    from {
        transform: scale(0.9) translateY(20px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

/* Popup animation class for modal containers */
.modal-popup {
    animation: popupIn 0.25s ease-out forwards;
}

/* Overlay fade animation */
.modal-fade {
    animation: fadeIn 0.2s ease-out forwards;
}

.modal-header {
    padding: 24px 30px;
    border-bottom: 2px solid rgba(255, 215, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-title {
    margin: 0;
    font-size: clamp(20px, 3vw, 28px);
    font-weight: 700;
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 50%, #FF8C00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.1em;
    text-shadow: 0 2px 8px rgba(255, 215, 0, 0.3);
}

.modal-close {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 215, 0, 0.3);
    color: #FFD700;
    font-size: 32px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.modal-close:hover {
    background: rgba(255, 215, 0, 0.2);
    border-color: #FFD700;
    transform: scale(1.1);
}

.modal-content {
    padding: 30px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Custom scrollbar */
.modal-content::-webkit-scrollbar {
    width: 8px;
}

.modal-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    border-radius: 10px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #FFA500, #FFD700);
}

/* Rules content styling */
.rules-section {
    margin-bottom: 30px;
}

.rules-section-title {
    font-size: clamp(16px, 2.5vw, 20px);
    font-weight: 700;
    color: #FFD700;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.rules-section-content {
    font-size: clamp(13px, 2vw, 16px);
    color: #e0e0e0;
    line-height: 1.7;
    font-weight: 400;
}

.rules-section-content p {
    margin: 0 0 12px 0;
}

.rules-section-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.rules-section-content li {
    margin: 6px 0;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 10px;
    }

    .modal-container {
        max-height: 85vh;
        border-radius: 15px;
    }

    .modal-header {
        padding: 18px 20px;
    }

    .modal-title {
        font-size: clamp(16px, 5vw, 22px);
    }

    .modal-close {
        width: 38px;
        height: 38px;
        font-size: 28px;
    }

    .modal-content {
        padding: 20px;
    }

    .rules-section {
        margin-bottom: 24px;
    }

    .rules-section-title {
        font-size: clamp(14px, 4vw, 18px);
    }

    .rules-section-content {
        font-size: clamp(12px, 3.5vw, 15px);
    }
}

@media (max-width: 480px) {
    .modal-overlay {
        padding: 5px;
    }

    .modal-container {
        border-radius: 12px;
    }

    .modal-header {
        padding: 15px;
    }

    .modal-content {
        padding: 15px;
    }
}

/* Game History Table Styles */
.history-table-container {
    overflow-x: auto;
    margin-bottom: 20px;
    -webkit-overflow-scrolling: touch;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: clamp(12px, 1.8vw, 16px);
    color: #e0e0e0;
}

.history-table thead {
    background: rgba(255, 255, 255, 0.05);
    position: sticky;
    top: 0;
    z-index: 10;
}

.history-table th {
    padding: 15px 10px;
    text-align: center;
    font-weight: 400;
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    font-size: clamp(11px, 1.6vw, 14px);
}

.history-table tbody tr {
    transition: background-color 0.2s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    border-left: 4px solid #ef4444;
}

.history-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

.history-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.08);
}

.history-table td {
    padding: 12px 10px;
    text-align: center;
    font-size: clamp(11px, 1.6vw, 14px);
    font-weight: 400;
}

.history-table td:first-child {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.replay-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 400;
    font-size: clamp(10px, 1.4vw, 13px);
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.replay-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
}

.replay-btn:active {
    transform: scale(0.98);
}

/* Pagination Styles */
.history-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 15px 0;
    border-top: 2px solid rgba(255, 255, 255, 0.1);
}

.pagination-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.pagination-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pagination-info {
    font-size: clamp(12px, 1.8vw, 16px);
    color: #ffffff;
    font-weight: 400;
    letter-spacing: 0.05em;
    min-width: 120px;
    text-align: center;
}

/* Mobile optimizations for history table */
@media (max-width: 768px) {
    .history-table th,
    .history-table td {
        padding: 10px 6px;
        font-size: clamp(10px, 3vw, 13px);
    }

    .replay-btn {
        padding: 5px 12px;
        font-size: clamp(9px, 2.5vw, 12px);
    }

    .pagination-btn {
        width: 38px;
        height: 38px;
        font-size: 18px;
    }

    .pagination-info {
        font-size: clamp(11px, 3.5vw, 14px);
        min-width: 100px;
    }
}

@media (max-width: 480px) {
    .history-table th,
    .history-table td {
        padding: 8px 4px;
    }

    .history-pagination {
        gap: 12px;
    }
}

/* Paytable Card Grid Styles */
.paytable-container {
    width: 100%;
    padding: 0 20px;
}

.paytable-section {
    margin-bottom: 40px;
}

.paytable-section-title {
    font-size: 24px;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 20px;
    padding-left: 20px;
    border-left: 4px solid #ef4444;
    display: inline-block;
}

.paytable-grid {
    display: grid;
    /* grid-template-columns and gap are set by JavaScript inline styles */
    justify-items: center;
}

.paytable-card {
    background: linear-gradient(145deg, rgba(30, 30, 30, 0.9), rgba(20, 20, 20, 0.8));
    border: 2px solid rgba(100, 100, 100, 0.3);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    max-width: 200px;
    width: 100%;
}

.paytable-card:hover {
    border-color: rgba(150, 150, 150, 0.5);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.paytable-symbol-img {
    width: 100%;
    max-width: 180px;
    height: auto;
    aspect-ratio: 1;
    object-fit: contain;
}

.paytable-payouts {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.paytable-payout-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
}

.paytable-range {
    color: #cccccc;
    font-weight: 400;
}

.paytable-value {
    color: #ffffff;
    font-weight: 400;
}

/* Mobile optimizations for paytable */
@media (max-width: 768px) {
    /* DON'T override grid-template-columns or gap - they're set by JavaScript */

    .paytable-card {
        padding: 12px;
        gap: 10px;
    }

    .paytable-symbol-img {
        max-width: 100px;
    }

    .paytable-payout-row {
        font-size: 13px;
    }

    .paytable-section-title {
        font-size: 18px;
        margin-bottom: 12px;
    }

    .paytable-container {
        padding: 0 10px;
    }

    .paytable-section {
        margin-bottom: 25px;
    }
}

@media (max-width: 480px) {
    /* DON'T override grid-template-columns or gap - they're set by JavaScript */

    .paytable-card {
        padding: 10px;
        gap: 8px;
        max-width: 180px;
    }

    .paytable-symbol-img {
        max-width: 80px;
    }

    .paytable-payout-row {
        font-size: 11px;
    }

    .paytable-section-title {
        font-size: 16px;
    }

    .paytable-container {
        padding: 0 8px;
    }
}