body {
    margin: 0;
    padding: 0;
    background: #000;
    color: #fff;
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    box-sizing: border-box;
}

#gameContainer {
    position: relative;
    text-align: center;
    width: 100%;
    max-width: 100%;
}

.game-stage {
    position: relative;
    display: inline-block;
    max-width: 100%;
    line-height: 0;
}

.float-toast-item {
    position: fixed;
    transform: translate(-50%, 12px);
    pointer-events: none;
    line-height: 1.2;
    font-size: clamp(22px, 5vw, 36px);
    font-weight: bold;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.85);
    opacity: 0;
    transition: opacity 0.25s ease, transform 2s ease-out;
    white-space: nowrap;
}

.float-toast-item.float-toast-visible {
    opacity: 1;
    transform: translate(-50%, -28px);
}

.float-toast-item.float-toast-hide {
    opacity: 0;
    transform: translate(-50%, -48px);
}

#gameCanvas {
    border: 2px solid #fff;
    background: linear-gradient(45deg, #001122, #003366);
    display: block;
    max-width: 100%;
    touch-action: none;
}

.mobile-controls {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 25;
}

.mobile-pause-btn {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    pointer-events: auto;
    min-width: 52px;
    min-height: 44px;
    padding: 8px 14px;
    font-size: 15px;
    font-weight: bold;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 8px;
    touch-action: manipulation;
}

#gameUI {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
    margin-top: 10px;
    font-size: 18px;
    font-weight: bold;
}

#revivePoints {
    font-size: 15px;
    color: #7fd4ff;
}

.revive-shop {
    margin: 16px 0;
    padding: 12px;
    border: 1px solid #335577;
    border-radius: 8px;
    text-align: left;
}

.revive-shop-panel {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin: 0;
    min-height: 100%;
    padding: 0;
    border: none;
    background: transparent;
}

.revive-shop-panel h3 {
    color: white;
    margin: 0 0 4px;
    font-size: 18px;
    width: 100%;
}

.menu-high-score {
    margin: 0 0 8px;
    font-size: 16px;
    color: #ccc;
}

.menu-high-score span {
    color: #7fd4ff;
    font-weight: bold;
}

.revive-shop-balance {
    margin: 0 0 4px;
    font-size: 18px;
    font-weight: bold;
    color: #fff;
}

.revive-shop-balance span {
    color: #7fd4ff;
    font-weight: bold;
}

.revive-buy-open {
    margin: 0 !important;
    padding: 10px 22px !important;
    font-size: 15px !important;
    text-transform: none;
}

.shop-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 1099;
}

.shop-dialog {
    display: block;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1100;
    background: linear-gradient(145deg, #14141e, #1a2438);
    color: #fff;
    padding: 24px 22px 20px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.65);
    max-width: 400px;
    width: 92%;
    border: 2px solid rgba(255, 255, 255, 0.12);
    text-align: center;
}

.shop-dialog h3 {
    margin: 0 0 10px;
    font-size: 22px;
    color: #fff;
}

.shop-balance-hint {
    margin: 0 0 18px;
    color: #aaa;
    font-size: 14px;
}

.shop-balance-hint span {
    color: #7fd4ff;
    font-weight: bold;
}

.shop-dialog-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 20px;
    line-height: 1;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
}

.revive-bundle-dialog {
    flex-direction: column;
}

.revive-bundle-dialog .secondary-btn {
    margin: 0;
    width: 100%;
    text-transform: none;
}

.revive-bundle-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}

.revive-bundle-row .secondary-btn {
    flex: 1 1 140px;
}

.revive-panel {
    cursor: default;
}

.revive-panel > .game-over-title {
    line-height: 1;
    margin: 0 0 0.5em;
}

.revive-score-summary {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: baseline;
    gap: 8px 28px;
    margin: 0 0 4px;
    color: #ddd;
    font-size: 16px;
    line-height: 1.5;
}

.revive-score-item span {
    color: #7fd4ff;
    font-weight: bold;
}

.revive-death-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
    width: 100%;
    max-width: 420px;
    margin: 12px auto 0;
}

.revive-death-actions .primary-btn,
.revive-death-actions .secondary-btn {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 12px 10px;
    font-size: 15px;
    text-transform: none;
}

.revive-death-actions button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.revive-balance {
    color: #7fd4ff;
}

#gameOver {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    padding: 30px;
    border: 2px solid #fff;
    border-radius: 10px;
    text-align: center;
}

#gameOver h2 {
    color: #ff4444;
    margin-top: 0;
}

/* Game Over Menu Styles */
.game-over-title {
    color: #ff4444 !important;
    text-shadow: 2px 2px 4px rgba(255, 68, 68, 0.5);
}

.final-score {
    color: white;
    font-size: 24px;
    margin: 20px 0;
    font-weight: bold;
}

.payout-info {
    color: #ffd700;
    font-size: 18px;
    margin: 15px 0;
    font-weight: bold;
}

.payout-info span {
    color: #ffed4a;
}


#restartBtn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 15px;
}

#restartBtn:hover {
    background: #45a049;
}

.hidden {
    display: none !important;
}

.payment-content {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    background: linear-gradient(45deg, #001122, #003366);
    color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.7);
    max-width: 420px;
    width: 92%;
    border: 2px solid #fff;
    font-weight: bold;
}

.payment-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    z-index: 999;
}

/* Close button matches game's accent (white, minimal) */
#hide-payment {
    position: absolute;
    top: 10px;
    right: 12px;
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 20px;
    line-height: 1;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease;
}

#hide-payment:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.35);
}

/* Card uses subtle darker panel within the gradient */
.card {
    background: rgba(0, 0, 0, 0.25);
    padding: 14px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

/* Rows and small text */
.row {
    margin-bottom: 12px;
}

.small {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.65);
}

/* Inputs styled for dark theme */
input[type="password"],
input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.03);
    color: #fff;
    outline: none;
    box-sizing: border-box;
}

input[type="password"]::placeholder,
input[type="text"]::placeholder,
input[type="number"]::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

input[type="password"]:focus,
input[type="text"]:focus,
input[type="number"]:focus {
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.08);
}

/* Price display fits the game's UI */
.price-display {
    background: rgba(255, 255, 255, 0.03);
    padding: 10px;
    border-radius: 6px;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 16px;
    text-align: center;
}

/* Action buttons follow game's style: bold, bordered, hover accent */
.actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
}

.actions button {
    background: transparent;
    color: #fff;
    padding: 10px 18px;
    border: 2px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: background .12s ease, border-color .12s ease, transform .06s ease;
}

.actions button:hover {
    background: rgba(0, 102, 204, 0.12);
    border-color: rgba(0, 102, 204, 0.9);
    transform: translateY(-1px);
}

.actions button.primary {
    background: rgba(0, 102, 204, 0.18);
    border-color: rgba(0, 102, 204, 0.9);
}

/* Checkbox label styling */
label.checkbox {
    color: rgba(255, 255, 255, 0.9);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* small responsive tweaks */
@media (max-width: 420px) {
    .payment-content {
        padding: 14px;
    }

    .actions button {
        padding: 9px 14px;
        font-size: 14px;
    }
}

/* Menu System Styles */
.menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.menu-panel {
    background: rgba(20, 20, 30, 0.95);
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    padding: 40px;
    text-align: center;
    max-width: 600px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#startMenu .menu-panel {
    max-width: 720px;
    padding: 28px 32px 24px;
}

#startMenu .menu-panel > h1 {
    line-height: 1;
    margin-block: 1em;
    margin-inline: 0;
}

.menu-panel h1 {
    color: white;
    font-size: 48px;
    font-weight: bold;
    margin: 0 0 20px 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.subtitle {
    color: #cccccc;
    font-size: 16px;
    margin-bottom: 30px;
}

.menu-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px 28px;
    margin-bottom: 20px;
    align-items: stretch;
    text-align: left;
}

.menu-content > * {
    min-width: 0;
}

#gameStage:has(#startMenu:not(.hidden)) #gameUI {
    visibility: hidden;
    pointer-events: none;
}

.start-game-btn {
    margin-top: 4px;
}

/* Player Preview */
.player-preview {
    flex: 1;
    text-align: left;
}

.player-preview h3 {
    color: white;
    margin-bottom: 15px;
    font-size: 18px;
}

.preview-box {
    width: 200px;
    height: 180px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.preview-box:hover {
    background: rgba(255, 255, 255, 0.05);
}

.player-sprite {
    width: 30px;
    height: 30px;
    background: #00ff00;
    position: relative;
    transition: all 0.3s ease;
}

.customization-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.customize-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.3s ease;
}

.customize-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.hint {
    color: #aaaaaa;
    font-size: 12px;
    margin: 0;
}

/* Controls Info */
.controls-info {
    flex: 1;
    text-align: left;
}

.controls-info h3 {
    color: white;
    margin-bottom: 15px;
    font-size: 18px;
}

.control-list {
    color: #cccccc;
}

.control-item {
    margin-bottom: 8px;
    font-size: 13px;
    line-height: 1.5;
    padding: 2px 0;
    word-break: break-word;
}

/* Buttons */
.primary-btn {
    background: #71ff4d;
    color: #222222;
    border: 2px solid #094d00;
    padding: 15px 40px;
    font-size: 20px;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    margin: 10px;
    transition: all 0.3s ease;
    text-transform: uppercase;
}

.primary-btn:hover {
    background: #5ee63a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(113, 255, 77, 0.3);
}

.secondary-btn {
    background: #ffd54d;
    color: #222222;
    border: 2px solid #b8860b;
    padding: 12px 30px;
    font-size: 16px;
    border-radius: 6px;
    cursor: pointer;
    margin: 10px;
    transition: all 0.3s ease;
    text-transform: uppercase;
}

.secondary-btn:hover {
    background: #ffcd1a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 213, 77, 0.3);
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.footer-text {
    color: #aaaaaa;
    font-size: 12px;
    margin-top: 12px;
    line-height: 1.4;
}

/* Level Up Menu */
.level-up-title {
    color: gold !important;
}

.level-up-subtitle {
    color: white;
    font-size: 20px;
    margin-bottom: 30px;
}

.upgrade-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 30px;
    text-align: left;
}

.upgrade-option {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 20px;
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
}

.upgrade-option:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.1);
}

.upgrade-name {
    color: white;
    font-weight: bold;
    font-size: 18px;
    margin-bottom: 5px;
}

.upgrade-description {
    color: lightgray;
    font-size: 14px;
}

.upgrade-number {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: bold;
}

.level-up-hint {
    color: yellow;
    font-size: 16px;
}

/* Game UI */
#gameUI {
    position: absolute;
    top: 10px;
    left: 10px;
    color: white;
    font-family: Arial, sans-serif;
    z-index: 10;
}

#gameUI>div {
    margin-bottom: 5px;
    font-size: 16px;
}

.progress-container {
    margin-bottom: 10px;
}

.progress-bar {
    width: 200px;
    height: 10px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 5px;
}

.progress-fill {
    height: 100%;
    transition: width 0.3s ease;
    border-radius: 5px;
}

#waveProgressFill {
    background: linear-gradient(90deg, #ffd700, #ffed4e);
}

#expProgressFill {
    background: linear-gradient(90deg, #4169e1, #6495ed);
}

.progress-label {
    color: white;
    font-size: 12px;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Player shape styles for preview */
.triangle-shape {
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

.circle-shape {
    border-radius: 50%;
}

/* Player Preview Improvements */
.player-sprite {
    width: 30px;
    height: 30px;
    background: #00ff00;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.inner-shape {
    position: absolute;
    background: #ffffff;
}

/* Shape-specific styles for preview */
.inner-shape.triangle-shape {
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

.inner-shape.circle-shape {
    border-radius: 50%;
}

/* Improve preview box */
.preview-box {
    width: 200px;
    height: 180px;
    background: rgba(0, 0, 0, 0.3);
    /* Darker background to show ship better */
    border: 2px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.preview-box:hover {
    background: rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.2);
}

@media (max-width: 768px), (pointer: coarse) {
    .menu-panel {
        padding: 22px 18px;
        max-height: min(92dvh, 92vh);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    .menu-overlay {
        touch-action: pan-y;
    }

    .menu-panel h1 {
        font-size: 32px;
    }

    .menu-content {
        grid-template-columns: 1fr;
        gap: 16px;
        margin-bottom: 16px;
    }

    #startMenu .subtitle {
        margin-bottom: 16px;
    }

    .primary-btn,
    .secondary-btn,
    .customize-btn {
        min-height: 44px;
        font-size: 15px;
    }

    #gameUI {
        font-size: 11px;
        max-width: calc(100% - 72px);
    }

    #gameUI > div {
        font-size: 11px;
        margin-bottom: 2px;
    }

    .progress-bar {
        width: min(140px, 42vw);
        height: 8px;
    }

    .progress-label {
        font-size: 10px;
    }

    .revive-bundle-row .secondary-btn {
        flex: 1 1 100%;
    }
}