/* === Reset & Base === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
    color: #e0e0e0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* === Start Page === */
#start-page {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a0a2e 0%, #16213e 50%, #0f3460 100%);
}

.start-container {
    text-align: center;
    padding: 20px;
    max-width: 500px;
}

.game-title {
    font-size: 2.5em;
    color: #e8c170;
    text-shadow: 0 0 20px rgba(232, 193, 112, 0.6), 0 2px 4px rgba(0,0,0,0.8);
    margin-bottom: 5px;
    letter-spacing: 8px;
}

.game-subtitle {
    font-size: 1.2em;
    color: #a0c4e8;
    margin-bottom: 40px;
    letter-spacing: 4px;
}

/* === Loading === */
.loading-area {
    margin: 20px 0 30px;
}

.progress-wrapper {
    width: 80%;
    margin: 0 auto;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.15);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #e8c170, #f0d090);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-text {
    margin-top: 12px;
    font-size: 0.85em;
    color: #a0a0a0;
}

.progress-percent {
    margin-top: 5px;
    font-size: 1.2em;
    color: #e8c170;
    font-weight: bold;
}

/* === Buttons === */
.start-btn, .retry-btn {
    display: inline-block;
    padding: 14px 50px;
    font-size: 1.2em;
    font-family: inherit;
    color: #1a0a2e;
    background: linear-gradient(135deg, #e8c170, #d4a850);
    border: none;
    border-radius: 30px;
    cursor: pointer;
    letter-spacing: 4px;
    box-shadow: 0 4px 15px rgba(232, 193, 112, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    margin: 5px;
}

.start-btn:active, .retry-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(232, 193, 112, 0.3);
}

.retry-btn {
    background: linear-gradient(135deg, #e07070, #c05050);
    color: #fff;
}

/* === Save Management === */
.save-management {
    margin-top: 20px;
}

.save-btn {
    padding: 10px 20px;
    margin: 5px;
    font-size: 0.9em;
    font-family: inherit;
    color: #e8c170;
    background: transparent;
    border: 1px solid #e8c170;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.save-btn:active {
    background: rgba(232, 193, 112, 0.2);
}

/* === Tips === */
.tips {
    margin-top: 30px;
    font-size: 0.75em;
    color: #707080;
    line-height: 1.8;
}

/* === Game Page === */
#game-page {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background: #000;
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* === Virtual Controls === */
.virtual-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 140px;
    pointer-events: none;
    z-index: 100;
    display: none;
}

#game-page:not([style*="display: none"]) .virtual-controls {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 20px 10px;
    background: transparent;
}

@media screen and (max-width: 1024px) {
    .virtual-controls {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        padding: 0 20px 10px;
    }

    @media (orientation: portrait) {
        .virtual-controls {
            height: 120px;
        }
        .dpad {
            width: 100px;
            height: 100px;
        }
        .dpad-btn {
            width: 34px;
            height: 34px;
            font-size: 14px;
        }
        .action-btn {
            width: 50px;
            height: 50px;
            font-size: 11px;
        }
    }
}

.dpad {
    position: relative;
    width: 120px;
    height: 120px;
    pointer-events: auto;
}

.dpad-btn {
    position: absolute;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: rgba(255, 255, 255, 0.7);
    pointer-events: auto;
}

.dpad-btn:active, .dpad-btn.pressed {
    background: rgba(255, 255, 255, 0.45);
    border-color: rgba(255, 255, 255, 0.6);
}

.dpad-up    { top: 0; left: 50%; transform: translateX(-50%); }
.dpad-down  { bottom: 0; left: 50%; transform: translateX(-50%); }
.dpad-left  { top: 50%; left: 0; transform: translateY(-50%); }
.dpad-right { top: 50%; right: 0; transform: translateY(-50%); }

.action-buttons {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    pointer-events: auto;
}

.action-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: rgba(255,255,255,0.8);
    pointer-events: auto;
    border: 2px solid rgba(255,255,255,0.3);
}

.action-btn:active, .action-btn.pressed {
    border-color: rgba(255,255,255,0.6);
}

.btn-a {
    background: rgba(100, 200, 100, 0.3);
}

.btn-a:active, .btn-a.pressed {
    background: rgba(100, 200, 100, 0.55);
}

.btn-b {
    background: rgba(200, 100, 100, 0.3);
    margin-bottom: 10px;
}

.btn-b:active, .btn-b.pressed {
    background: rgba(200, 100, 100, 0.55);
}

.btn-menu {
    background: rgba(100, 100, 200, 0.3);
    margin-bottom: 20px;
}

.btn-menu:active, .btn-menu.pressed {
    background: rgba(100, 100, 200, 0.55);
}

/* === Game Menu Button === */
.game-menu-btn {
    position: fixed;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    z-index: 101;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* === Game Settings Panel === */
.game-settings {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-content {
    background: linear-gradient(135deg, #1a0a2e 0%, #16213e 100%);
    padding: 30px;
    border-radius: 15px;
    border: 1px solid #e8c170;
    min-width: 300px;
}

.settings-content h3 {
    color: #e8c170;
    margin-bottom: 20px;
    text-align: center;
}

.setting-item {
    margin: 15px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.setting-item label {
    color: #a0c4e8;
    min-width: 80px;
}

.setting-item input[type="range"] {
    flex: 1;
}

.setting-buttons {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.setting-btn {
    padding: 10px 20px;
    background: rgba(232, 193, 112, 0.2);
    border: 1px solid #e8c170;
    border-radius: 20px;
    color: #e8c170;
    cursor: pointer;
}

.setting-btn:active {
    background: rgba(232, 193, 112, 0.4);
}

.close-btn {
    margin-top: 20px;
    width: 100%;
    padding: 12px;
    background: #e8c170;
    border: none;
    border-radius: 25px;
    color: #1a0a2e;
    font-weight: bold;
    cursor: pointer;
}

/* === Rotate Hint (iOS portrait) === */
.rotate-hint {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #ccc;
    font-size: 1.1em;
}

.rotate-hint.show {
    display: flex;
}

.rotate-icon {
    font-size: 3em;
    margin-bottom: 15px;
    animation: rotate-anim 1.5s ease-in-out infinite;
}

@keyframes rotate-anim {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

/* === Update Toast === */
.update-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #e8c170, #d4a850);
    color: #1a0a2e;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 14px;
    z-index: 1000;
    display: none;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.update-toast.show {
    display: flex;
}

.update-toast button {
    padding: 6px 15px;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    font-weight: bold;
}

#update-btn {
    background: #1a0a2e;
    color: #e8c170;
}

#dismiss-update-btn {
    background: transparent;
    color: #1a0a2e;
    font-size: 18px;
    padding: 0 8px;
}

/* === Toast === */
.toast {
    position: fixed;
    bottom: 30%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

/* === Mobile Adjustments === */
@media (max-width: 640px) {
    .game-title { font-size: 1.8em; letter-spacing: 4px; }
    .game-subtitle { font-size: 1em; margin-bottom: 25px; }
    .start-btn, .retry-btn { padding: 12px 36px; font-size: 1em; }
    .tips { font-size: 0.65em; }
    .settings-content { padding: 20px; min-width: auto; width: 90%; }
}

/* === Landscape on mobile === */
@media screen and (max-width: 1024px) and (orientation: landscape) {
    #canvas { width: 100%; height: 100%; }
}

/* === Portrait on mobile === */
@media screen and (max-width: 1024px) and (orientation: portrait) {
    #canvas { width: 100%; height: 100%; }
}
