/* ===== 基礎重置與字體 ===== */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&family=Share+Tech+Mono&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

input {
    -webkit-user-select: text;
    user-select: text;
}

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.8);
    --primary: #00f2fe;
    --primary-glow: rgba(0, 242, 254, 0.3);
    --secondary: #7b2ff7;
    --accent: #ff6b6b;
    --text: #e2e8f0;
    --text-dim: #64748b;
    --text-bright: #ffffff;
    --border: rgba(255, 255, 255, 0.08);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --font-display: 'Outfit', sans-serif;
    --font-mono: 'Share Tech Mono', monospace;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text);
    font-family: var(--font-display);
    -webkit-font-smoothing: antialiased;
}

/* ===== 動態星空背景 ===== */
.bg-stars {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 0;
    background-image:
        radial-gradient(2px 2px at 20% 30%, rgba(0, 242, 254, 0.3), transparent),
        radial-gradient(2px 2px at 40% 70%, rgba(123, 47, 247, 0.2), transparent),
        radial-gradient(1px 1px at 60% 20%, rgba(255, 255, 255, 0.3), transparent),
        radial-gradient(1px 1px at 80% 50%, rgba(0, 242, 254, 0.2), transparent),
        radial-gradient(1px 1px at 10% 80%, rgba(255, 255, 255, 0.2), transparent),
        radial-gradient(1.5px 1.5px at 50% 10%, rgba(123, 47, 247, 0.3), transparent),
        radial-gradient(1px 1px at 90% 90%, rgba(0, 242, 254, 0.2), transparent),
        radial-gradient(1px 1px at 30% 50%, rgba(255, 255, 255, 0.15), transparent);
    animation: starsTwinkle 8s ease-in-out infinite alternate;
}

@keyframes starsTwinkle {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.7; }
}

.bg-glow {
    position: fixed;
    top: -30%; left: -30%;
    width: 160%; height: 160%;
    pointer-events: none;
    z-index: 0;
    background: radial-gradient(ellipse at 30% 20%, rgba(0, 242, 254, 0.06) 0%, transparent 50%),
                radial-gradient(ellipse at 70% 80%, rgba(123, 47, 247, 0.05) 0%, transparent 50%);
    animation: glowShift 15s ease-in-out infinite alternate;
}

@keyframes glowShift {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(3%, -3%) scale(1.05); }
}

/* ===== 主容器 ===== */
.app-container {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ===== 遊戲標題 ===== */
.game-header {
    width: 100%;
    max-width: 500px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    flex-shrink: 0;
}

.game-header .logo {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 2px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 18px;
}

.icon-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 12px var(--primary-glow);
}

/* ===== HUD 資訊列 ===== */
.hud {
    width: 100%;
    max-width: 500px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 16px;
    flex-shrink: 0;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.hud-label {
    font-family: var(--font-display);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
    letter-spacing: 1px;
}

.hud-value {
    font-family: var(--font-mono);
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary);
    text-shadow: 0 0 10px var(--primary-glow);
}

.hud-value.health {
    color: var(--accent);
    text-shadow: 0 0 10px rgba(255, 107, 107, 0.3);
}

/* 一格一格生命值條 */
.health-grid {
    display: flex;
    gap: 3px;
    align-items: center;
    margin-top: 4px;
    height: 16px;
}

.health-unit {
    width: 7px;
    height: 14px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 1.5px;
    transition: all 0.2s ease;
}

/* 經典彩虹漸層血條：1-3格紅色, 4-6格橘黃色, 7-10格綠色 */
.health-unit.active:nth-child(-n+3) {
    background: #ef4444;
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
}

.health-unit.active:nth-child(n+4):nth-child(-n+6) {
    background: #f59e0b;
    box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
}

.health-unit.active:nth-child(n+7) {
    background: #10b981;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

/* ===== Canvas 遊戲區域 ===== */
.game-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 500px;
    position: relative;
    min-height: 0;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-canvas {
    display: block;
    background: rgba(8, 12, 28, 0.9);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 0 30px rgba(0, 242, 254, 0.05), inset 0 0 20px rgba(0, 0, 0, 0.3);
    max-width: 100%;
    max-height: 100%;
}

/* ===== 覆蓋層 (開始 / 暫停 / 結束) ===== */
.overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10005;
    border-radius: 0;
    overflow-y: auto;
}

.overlay::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(10, 14, 26, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 32px 16px; /* 預設左右 padding 縮小，防範手機版容器被擠小 */
    max-width: 340px;
    width: 100%;
}

@media (max-width: 500px) {
    .overlay-content {
        padding: 24px 8px; /* 手機版進一步縮小左右 padding，確保可用寬度大於 320px */
    }
}

.overlay-content h2 {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.overlay-content .subtitle {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.overlay-content .gameover-title {
    font-size: 2.2rem;
    background: linear-gradient(135deg, var(--accent), #ff9a9e);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* 操作說明 */
.controls-guide {
    text-align: left;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
}

.controls-guide h3 {
    font-size: 0.85rem;
    color: var(--primary);
    margin-bottom: 10px;
    letter-spacing: 1px;
}

.controls-guide ul {
    list-style: none;
    padding: 0;
}

.controls-guide li {
    font-size: 0.8rem;
    color: var(--text-dim);
    padding: 4px 0;
}

.controls-guide kbd {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-bright);
    margin: 0 2px;
}

/* 主要按鈕 */
.primary-btn {
    display: inline-block;
    padding: 12px 36px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--bg-primary);
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--primary-glow);
}

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

/* 結算面板 */
.final-stats {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin: 20px 0;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--primary);
}

/* ===== 手機端虛擬按鍵 ===== */
.mobile-controls {
    display: none;
    width: 100%;
    max-width: 500px;
    padding: 10px 16px 20px;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .mobile-controls {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
}

.dpad-group {
    display: flex;
    gap: 10px;
}

.ctrl-btn {
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.round-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 24px;
}

.round-btn:active {
    background: rgba(0, 242, 254, 0.15);
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
}

.action-group {
    display: flex;
    gap: 10px;
}

.action-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 24px;
}

.action-btn:active {
    background: rgba(123, 47, 247, 0.15);
    border-color: var(--secondary);
    color: var(--secondary);
    box-shadow: 0 0 15px rgba(123, 47, 247, 0.3);
}

.btn-label {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 1px;
}

/* ===== 粒子特效提示 ===== */
.floor-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 800;
    color: var(--primary);
    text-shadow: 0 0 30px var(--primary-glow);
    pointer-events: none;
    animation: floorPop 1.2s ease-out forwards;
    z-index: 5;
}

@keyframes floorPop {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    30% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

/* ===== 新紀錄面板 ===== */
.new-record-panel {
    margin: 12px 0;
}

.new-record-panel.hidden {
    display: none;
}

.glow-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--warning);
    text-shadow: 0 0 10px rgba(245, 158, 11, 0.4);
    margin-bottom: 10px;
}

.new-record-panel input {
    width: 80%;
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-bright);
    font-family: var(--font-display);
    font-size: 0.9rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

.new-record-panel input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--primary-glow);
}

.primary-btn.compact {
    padding: 8px 24px;
    font-size: 0.85rem;
}

/* ===== 排行榜表格 ===== */
.gameover-leaderboard h3 {
    font-size: 0.9rem;
    color: var(--primary);
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.leaderboard-table th {
    padding: 6px 8px;
    color: var(--text-dim);
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
}

.leaderboard-table td {
    padding: 8px;
    color: var(--text);
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.leaderboard-table tr:first-child td {
    color: var(--warning);
}

/* ===== 暫停按鈕 (螢幕上) ===== */
#pause-fab {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 8;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(17, 24, 39, 0.7);
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
}

#pause-fab:hover {
    color: var(--primary);
    border-color: var(--primary);
}

/* ===== 響應式微調 ===== */
@media (max-width: 768px) {
    .game-header .logo {
        font-size: 1.1rem;
    }
    .hud-value {
        font-size: 1.1rem;
    }
    .overlay-content h2 {
        font-size: 1.4rem;
    }
    .overlay-content .gameover-title {
        font-size: 1.8rem;
    }
}

@media (max-width: 400px) {
    .round-btn, .action-btn {
        width: 48px;
        height: 48px;
    }
}

/* ===== 頂部天花板傷害閃爍 ===== */
@keyframes damageFlash {
    0% { box-shadow: 0 0 30px rgba(0, 242, 254, 0.05), inset 0 0 20px rgba(0, 0, 0, 0.3); }
    25% { box-shadow: 0 0 30px rgba(239, 68, 68, 0.4), inset 0 0 30px rgba(239, 68, 68, 0.15); }
    50% { box-shadow: 0 0 30px rgba(0, 242, 254, 0.05), inset 0 0 20px rgba(0, 0, 0, 0.3); }
    75% { box-shadow: 0 0 30px rgba(239, 68, 68, 0.3), inset 0 0 25px rgba(239, 68, 68, 0.1); }
    100% { box-shadow: 0 0 30px rgba(0, 242, 254, 0.05), inset 0 0 20px rgba(0, 0, 0, 0.3); }
}

#game-canvas.damage {
    animation: damageFlash 0.5s ease-out;
}

/* ===== 手機端觸控提示 ===== */
.touch-hint {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-align: center;
    margin-top: 4px;
    opacity: 0.6;
}

@media (min-width: 769px) {
    .touch-hint {
        display: none;
    }
}

/* ===== 遊戲結束 AdSense 廣告區塊 ===== */
.gameover-ad-slot {
    width: 100%;
    max-width: 320px;
    margin: 12px auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
}

.gameover-ad-slot:empty {
    margin: 0;
    background: transparent;
}

/* 當廣告載入後，進行細微的間隔微調 */
.gameover-ad-slot ins {
    margin: 0 auto;
}

/* ===== 遊戲 SEO 介紹區塊 (自然超出螢幕，供 Google 爬蟲讀取，不影響排版) ===== */
.seo-description {
    position: absolute;
    top: 200vh;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 600px;
    padding: 20px;
    color: var(--text-dim);
    font-size: 0.85rem;
    line-height: 1.6;
    text-align: justify;
}
