:root {
    --bg: #05070e; 
    --panel: rgba(15, 20, 35, 0.85); 
    --primary: #00f2fe; 
    --secondary: #ff007f;
    --text: #f8fafc; 
    --text-dim: #64748b; 
    --danger: #ef4444;
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    user-select: none; 
    -webkit-user-select: none; 
    font-family: 'Noto Sans HK', sans-serif; 
    touch-action: none; 
}

body { 
    background: var(--bg); 
    color: var(--text); 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    min-height: 100vh; 
    overflow: hidden; 
}

#app { 
    position: relative; 
    width: 100%; 
    max-width: 450px; 
    height: 100vh; 
    max-height: 850px; 
    overflow: hidden; 
    display: flex; 
    flex-direction: column; 
}

@media(min-width: 451px) { 
    #app { 
        height: 95vh; 
        border-radius: 20px; 
        box-shadow: 0 10px 40px rgba(0,0,0,0.8); 
        border: 1px solid rgba(255,255,255,0.1); 
    } 
}

/* --- 畫面切換 --- */
.screen { 
    position: absolute; top:0; left:0; width:100%; height:100%; 
    display:none; flex-direction: column; padding: 20px; 
    background: radial-gradient(circle at top, #111827, var(--bg)); z-index: 10; 
}
.screen.active { display: flex; animation: fadeIn 0.4s ease-out; }
@keyframes fadeIn { from{opacity:0; transform:scale(0.98);} to{opacity:1; transform:scale(1);} }

/* --- UI 共用組件 --- */
.btn { 
    width: 100%; padding: 18px; border-radius: 16px; font-size: 1.2rem; 
    font-weight: 900; border: none; cursor: pointer; transition: 0.1s; 
    display: flex; justify-content: center; align-items: center; gap: 8px; 
    box-shadow: 0 6px 0 rgba(0,0,0,0.5); 
}
.btn:active { transform: translateY(6px); box-shadow: 0 0 0 transparent; }
.btn-primary { background: linear-gradient(135deg, var(--primary), #0284c7); color: #fff; text-shadow: 0 2px 5px rgba(0,0,0,0.5); }
.btn-danger { background: linear-gradient(135deg, var(--danger), #991b1b); color: #fff; }

/* --- Screen 1: 首頁 --- */
.title-box { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.game-logo { font-family: 'Orbitron', sans-serif; font-size: 2.8rem; font-weight: 900; background: linear-gradient(135deg, #fff, var(--secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; filter: drop-shadow(0 0 15px rgba(255,0,127,0.4)); margin-bottom: 10px; }
.input-name { width: 100%; background: rgba(0,0,0,0.5); border: 2px solid var(--primary); color: #fff; padding: 15px; border-radius: 12px; font-size: 1.2rem; text-align: center; margin-bottom: 20px; outline: none; }

/* --- Screen 2: 假排行榜 --- */
.rank-list { flex: 1; overflow-y: auto; background: var(--panel); border-radius: 16px; padding: 15px; margin-bottom: 20px; border: 1px solid rgba(255,255,255,0.05); }
.rank-item { display: flex; justify-content: space-between; align-items: center; padding: 12px; border-bottom: 1px solid rgba(255,255,255,0.05); font-family: 'Orbitron', sans-serif; }
.rank-item.is-me { background: rgba(0, 242, 254, 0.15); border-radius: 8px; border: 1px solid var(--primary); }
.rank-medal { font-size: 1.3rem; width: 30px; text-align: center; }
.rank-name { flex: 1; padding-left: 10px; font-weight: bold; }
.rank-score { color: #ffd700; font-weight: 900; }

/* --- Screen 3: 遊戲主戰場 --- */
header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.hud-box { background: var(--panel); border-radius: 12px; padding: 8px 12px; text-align: center; border: 1px solid rgba(255,255,255,0.05); }
.hud-title { font-size: 0.65rem; color: var(--text-dim); }
.hud-val { font-family: 'Orbitron', sans-serif; font-size: 1.1rem; font-weight: 900; color: #ffd700; }

.marquee { background: rgba(255,0,127,0.15); border: 1px solid rgba(255,0,127,0.3); border-radius: 8px; padding: 8px; font-size: 0.8rem; margin-bottom: 15px; overflow: hidden; white-space: nowrap; color: var(--secondary); font-weight: bold; }

/* 陣盤 */
.board-wrapper { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; }
#board { width: 100%; max-width: 380px; aspect-ratio: 1; background: #0b0e17; border-radius: 16px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 8px; position: relative; border: 4px solid #1e293b; transition: 0.3s; }
#board.frenzy-glow { border-color: var(--danger); box-shadow: 0 0 30px rgba(239, 68, 68, 0.5); }
.slot { background: #151b2b; border-radius: 10px; border: 1px dashed rgba(255,255,255,0.05); }

/* 實體拖拉卡片 */
.tile { position: absolute; border-radius: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center; color: #fff; font-weight: 900; cursor: grab; z-index: 10; border: 1px solid rgba(255,255,255,0.2); transition: transform 0.05s, box-shadow 0.1s; text-shadow: 0 2px 4px rgba(0,0,0,0.8); }
.tile:active { cursor: grabbing; transform: scale(1.15); z-index: 100; box-shadow: 0 15px 30px rgba(0,0,0,0.6) !important; }
.tile .icon { font-size: min(5.5vw, 1.7rem); pointer-events: none; }
.tile .name { font-size: min(2.5vw, 0.65rem); pointer-events: none; }
.tile.anim-merge { animation: pop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes pop { 0%{transform:scale(1);} 50%{transform:scale(1.3); filter:brightness(1.5);} 100%{transform:scale(1);} }

/* 商店與操作區 */
.shop-row { display: flex; gap: 6px; margin-bottom: 10px; }
.tool-btn { flex: 1; background: var(--panel); border: 1px solid rgba(255,255,255,0.1); border-radius: 10px; padding: 10px 2px; font-size: 0.75rem; font-weight: bold; color: #fff; cursor: pointer; transition: 0.2s; box-shadow: 0 4px 0 #000; }
.tool-btn:active { transform: translateY(4px); box-shadow: 0 0 0 #000; }
.tool-btn.active { background: var(--danger); border-color: #fff; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.7; } }

.spawn-area { width: 100%; position: relative; }
.frenzy-tag { position: absolute; top: -15px; right: -5px; background: var(--danger); color: #fff; font-size: 0.7rem; padding: 3px 8px; border-radius: 10px; font-weight: 900; transform: rotate(10deg); display: none; z-index: 5; animation: pop 0.5s infinite; }

/* 通用彈窗遮罩 */
.overlay { display: none; position: absolute; top:0; left:0; width:100%; height:100%; background: rgba(5,7,14,0.85); z-index: 1000; flex-direction: column; justify-content: center; align-items: center; padding: 20px; text-align: center; backdrop-filter: blur(8px); }
.modal-box { background: linear-gradient(145deg, #161c2d, #090b12); border: 1px solid var(--primary); padding: 30px 20px; border-radius: 20px; box-shadow: 0 20px 50px rgba(0,0,0,0.8); width: 85%; max-width: 320px; animation: pop 0.3s ease-out; }