:root {
    --btn-scale: 1;
    --top-ui-height: 125px;
}
@media (max-width: 1300px), (max-height: 950px) {
    :root { --btn-scale: 0.85; --top-ui-height: 110px; }
}
@media (max-width: 1100px), (max-height: 800px) {
    :root { --btn-scale: 0.75; --top-ui-height: 100px; }
}
@media (max-height: 600px) {
    :root { --top-ui-height: 85px; }
}

html, body {
    margin: 0; background: #2c3e50; color: white; font-family: Arial, sans-serif;
    overscroll-behavior: none;
    overscroll-behavior-y: none;
    touch-action: manipulation;
}
body {
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
    min-height: 100vh; position: relative; overflow-x: hidden;
}
#ui {
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 600;
    transform: scale(var(--canvas-scale, 1));
    transform-origin: top right;
    background: rgba(0, 0, 0, 0.75);
    border: 2px solid rgba(127, 140, 141, 0.7);
    border-radius: 28px;
    padding: 6px 22px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    gap: 14px;
    color: #ffffff;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    user-select: none;
    white-space: nowrap;
    line-height: 1.35;
}
.ui-divider {
    color: rgba(255, 255, 255, 0.35);
    font-size: 20px;
    user-select: none;
}
#hp {
    color: #2ecc71;
    font-weight: bold;
}
#money {
    color: #f1c40f;
    font-weight: bold;
}

/* 當處於抽卡補給時間時，右上角 UI (金幣與生命值) 提升至遮罩之上顯示 */
body.buff-selecting-mode #ui {
    z-index: 1501;
}


#stage-info-container {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%) scale(var(--canvas-scale, 1));
    transform-origin: top center;
    z-index: 999;
    background: rgba(0, 0, 0, 0.75);
    border: 2px solid rgba(127, 140, 141, 0.7);
    border-radius: 24px;
    padding: 6px 24px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    user-select: none;
    white-space: nowrap;
    gap: 3px;
}
.stage-info-row-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
}
#waveText {
    font-size: 24px;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
}
#countdownText {
    font-size: 22px;
    font-weight: bold;
    color: #f1c40f;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
}
#countdownText:empty {
    display: none;
}
#message {
    color: #f1c40f;
    font-size: 20px;
    font-weight: bold;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
    line-height: 1.2;
    min-height: 24px;
    margin-left: 0;
}
#tower-description { 
    color: #2ecc71; 
    font-size: calc(1rem * var(--btn-scale, 1)); 
    margin-top: calc(5px * var(--btn-scale, 1)); 
    min-height: calc(24px * var(--btn-scale, 1)); 
    height: auto; 
    text-align: center; 
}
#tower-description .current-dmg-text,
.current-dmg-text {
    color: #3ed7b8;
}

.btn {
    background-color: #34495e; color: white; border: 2px solid #ecf0f1;
    padding: 5px 10px; cursor: pointer; font-size: 16px; border-radius: 5px;
    transition: 0.2s; margin: 0 5px; margin-bottom: 5px;
    touch-action: manipulation;
}
.btn:hover { background-color: #ecf0f1; color: #2c3e50; }
.btn-danger { border-color: #e74c3c; color: #e74c3c; }
.btn-danger:hover { background-color: #e74c3c; color: white; }
.btn-skip { background-color: #8e44ad; border-color: #8e44ad; }
.btn-skip:hover { background-color: #9b59b6; color: white; }
.btn-money { background-color: #f1c40f; border-color: #f1c40f; color: black; }
.btn-money:hover { background-color: #f39c12; color: white; }
.btn-notes { background-color: #16a085; border-color: #16a085; }
.btn-notes:hover { background-color: #1abc9c; color: white; }

#tower-selection { 
    margin: calc(8px * var(--btn-scale, 1)) auto calc(5px * var(--btn-scale, 1)) auto; 
    display: flex; 
    gap: calc(8px * var(--btn-scale, 1)); 
    flex-wrap: nowrap; 
    justify-content: center; 
    align-items: center; 
    max-width: var(--canvas-width, 1900px);
    width: 100%;
    box-sizing: border-box;
}
.tower-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: calc(6px * var(--btn-scale, 1));
    padding: calc(4px * var(--btn-scale, 1)) calc(9px * var(--btn-scale, 1));
    cursor: pointer;
    border: calc(3px * var(--btn-scale, 1)) solid transparent;
    border-radius: calc(8px * var(--btn-scale, 1));
    color: #2c3e50;
    background-color: #bdc3c7;
    transition: 0.2s;
    touch-action: manipulation;
    min-height: calc(56px * var(--btn-scale, 1));
    box-sizing: border-box;
    white-space: nowrap;
    flex-shrink: 0;
}
.tower-btn-icon {
    width: calc(50px * var(--btn-scale, 1));
    height: calc(50px * var(--btn-scale, 1));
    object-fit: contain;
    flex-shrink: 0;
    pointer-events: none;
    /* image-rendering: pixelated; */
}
.tower-btn-emoji {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: calc(32px * var(--btn-scale, 1));
    line-height: 1;
}
.tower-btn-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.18;
    gap: calc(2px * var(--btn-scale, 1));
    pointer-events: none;
    text-align: center;
}
.tower-btn-name {
    font-size: calc(15px * var(--btn-scale, 1));
    font-weight: bold;
    white-space: nowrap;
    letter-spacing: 0.5px;
}
.tower-btn-cost {
    font-size: calc(12.5px * var(--btn-scale, 1));
    font-weight: bold;
    white-space: nowrap;
    opacity: 0.92;
    letter-spacing: 0.5px;
}
.tower-btn.selected { border-color: #e74c3c; box-shadow: 0 0 15px rgba(231, 76, 60, 0.9); }
#btn-blue { background-color: #3498db; color: white; }
#btn-yellow { background-color: #f1c40f; color: black; }
#btn-white { background-color: #ffffff; color: black; }
#btn-brown { background-color: #8b4513; color: white; }
#btn-chick { background-color: #e67e22; color: white; }
#btn-bobo { background-color: #9b59b6; color: white; }
.demolish-btn { background-color: #7f8c8d; color: white; }

#main-container { 
    display: flex; 
    flex-direction: row; 
    align-items: flex-start; 
    justify-content: center; 
    gap: 15px; 
    width: 100%; 
    max-width: 100vw;
    margin-top: 6px; 
    flex-wrap: wrap; 
    box-sizing: border-box;
}
#game-wrapper { 
    position: relative; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    /* 同時受螢幕寬度與可用高度限制，高度變小時自動依 1900/1080 等比縮小內容 */
    width: min(94vw, calc((100dvh - var(--top-ui-height, 125px)) * (1900 / 1080)), 1900px); 
    max-width: 1900px; 
    margin: 0 auto; 
    touch-action: none;
    box-sizing: border-box;
}
#game-wrapper:has(#transition-overlay[style*="display: flex"]) {
    z-index: 1500;
}
body:has(#transition-overlay[style*="display: flex"]) #combat-info-panel {
    display: none !important;
}

/* ==========================================
   左上角選單與更新按鈕區塊 (Top-Left UI Banner)
   ========================================== */
#top-left-ui {
    position: absolute;
    top: 8px;
    left: 10px;
    z-index: 600;
    background: rgba(0, 0, 0, 0.75);
    border: 2px solid rgba(127, 140, 141, 0.7);
    border-radius: 19px;
    padding: 9px 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    box-sizing: border-box;
    transform: scale(var(--canvas-scale, 1));
    transform-origin: top left;
}

/* 當處於抽卡補給時間時，左上角 UI 提升至遮罩之上，方便滑鼠或觸控點選設定 (ESC) 進入暫停 */
body.buff-selecting-mode #top-left-ui {
    z-index: 1501;
}

/* 當遊戲進入 ESC 暫停狀態時隱藏左上角 UI，避免與暫停戰場情報面板重疊 */
body.game-paused #top-left-ui {
    display: none !important;
}

.top-ui-btn {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    text-decoration: none;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    transition: transform 0.15s ease-out;
}

.top-ui-btn:hover {
    transform: translateY(-2px);
}

.top-ui-btn:active {
    transform: translateY(0) scale(0.95);
}

.top-ui-icon {
    width: 100%;
    height: auto;
    object-fit: contain;
    display: block;
    image-rendering: pixelated;
   /*  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6)); */
    transition: filter 0.2s ease-out;
}

.top-ui-btn:hover .top-ui-icon {
    filter: brightness(1.22) drop-shadow(0 0 7px rgba(255, 255, 255, 0.85)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

.top-ui-label {
    font-size: 1.1rem;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 1px 1px 2px #000, -1px -1px 2px #000, 1px -1px 2px #000, -1px 1px 2px #000, 0 0 6px rgba(0, 0, 0, 0.8);
    margin-top: 3px;
    line-height: 1.1;
    white-space: nowrap;
    opacity: 1;
    pointer-events: none;
    transition: color 0.15s ease-out, text-shadow 0.15s ease-out;
}

.top-ui-btn:hover .top-ui-label {
    color: #f1c40f;
    text-shadow: 0 0 6px rgba(241, 196, 15, 0.7), 1px 1px 2px #000;
}

canvas { 
    background: #34495e url('images/map_bg_grass.png') repeat; 
    border: 4px solid #ecf0f1; 
    box-shadow: 0 10px 20px rgba(0,0,0,0.3); 
    cursor: none; 
    width: 100%; 
    height: auto;
    aspect-ratio: 1900 / 1080; 
    max-width: 1900px; 
    max-height: calc(100dvh - var(--top-ui-height, 125px)); 
    box-sizing: border-box; 
    object-fit: fill; 
    touch-action: none;
}

#map-buttons-container { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; z-index: 500; pointer-events: auto; }
#map-buttons-container button {
    font-size: 22px;
    padding: 7px 16px;
    border-radius: 7px;
    border-width: 3px;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

#transition-overlay { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background-color: rgba(0, 0, 0, 0.7); 
    z-index: 1500; 
    display: none; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    pointer-events: auto; 
    opacity: 0; 
    padding: 10px; 
    box-sizing: border-box; 
}
#transition-overlay::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: inherit;
    z-index: -1;
    pointer-events: auto;
}
#overlay-text { font-weight: bold; text-align: center; text-shadow: 0 5px 15px rgba(0,0,0,0.8); color: #ffffff; font-size: clamp(24px, 5vmin, 56px); margin-bottom: clamp(4px, 1.5vh, 18px); }
#overlay-subtext { font-size: clamp(16px, 3vmin, 32px); color: white; font-weight: bold; margin-top: clamp(4px, 1.2vh, 15px); text-align: center; }

#active-buffs-container {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 3px;
    align-content: flex-start;
    min-height: 28px;
    max-height: 150px;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    padding: 2px 3px 2px 1px;
    scrollbar-width: thin;
    scrollbar-color: #7f8c8d rgba(0, 0, 0, 0.2);
}
#active-buffs-container::-webkit-scrollbar {
    width: 5px;
}
#active-buffs-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2.5px;
}
#active-buffs-container::-webkit-scrollbar-thumb {
    background: #7f8c8d;
    border-radius: 2.5px;
}
#active-buffs-container::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}
#active-buffs-container:empty::after {
    content: "目前無 Buff 圖標";
    color: #95a5a6;
    font-size: 13px;
    font-style: italic;
    line-height: 24px;
    grid-column: 1 / -1;
}
.combat-panel-hr {
    border: none;
    border-top: 1px solid rgba(127, 140, 141, 0.6);
    margin: 10px 0;
}

.active-buff-icon {
    font-size: 13.5px;
    width: 100%;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    border: 1.5px solid white;
    box-sizing: border-box;
    line-height: 1;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.active-buff-icon:hover {
    transform: scale(1.18);
    box-shadow: 0 0 8px rgba(241, 196, 15, 0.9);
    z-index: 5;
}

/* ==========================================
   戰場情報 Buff 獨立浮動說明框 (Floating Buff Tooltip)
   ========================================== */
#buff-floating-tooltip {
    position: fixed;
    z-index: 99999;
    display: none;
    opacity: 0;
    max-width: 275px;
    min-width: 160px;
    background: rgba(20, 28, 38, 0.96);
    backdrop-filter: blur(8px);
    border: 2px solid #f1c40f;
    border-radius: 8px;
    padding: 10px 14px;
    color: #ffffff;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.75), 0 0 12px rgba(241, 196, 15, 0.3);
    font-size: 13.5px;
    line-height: 1.55;
    pointer-events: none;
    box-sizing: border-box;
    transition: opacity 0.15s ease-out;
    word-break: break-word;
}
.buff-tooltip-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 6px;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(127, 140, 141, 0.5);
}
.buff-tooltip-icon {
    font-size: 20px;
    line-height: 1;
}
.buff-tooltip-title {
    font-size: 14px;
    font-weight: bold;
    color: #f1c40f;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.buff-tier-badge {
    font-size: 11px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 4px;
    color: #ffffff;
}
.buff-tier-badge.tier-gold {
    background-color: #d4af37;
    color: #1a1a1a;
}
.buff-tier-badge.tier-purple {
    background-color: #8e44ad;
}
.buff-tier-badge.tier-blue {
    background-color: #2980b9;
}
.buff-tooltip-content {
    font-size: 13px;
    color: #ecf0f1;
    line-height: 1.5;
}

#bottom-controls { margin-top: 15px; display: flex; gap: 15px; flex-wrap: wrap; justify-content: center; align-items: center; }
#version-info { margin: 0 0 20px 0; font-size: 0.8rem; color: #bdc3c7; font-weight: bold; padding:0 4%;}

#actionBtnContainer { 
    margin-top: clamp(10px, 2.5vh, 25px); 
    display: none; 
    flex-direction: column; 
    gap: clamp(8px, 1.5vh, 15px); 
    align-items: center; 
    max-width: 90vw;
    box-sizing: border-box;
}
#actionBtnContainer button { 
    background-color: #2ecc71; 
    border: 2px solid #27ae60; 
    font-size: clamp(13px, 1.8vmin, 22px); 
    padding: clamp(6px, 1.2vh, 12px) clamp(16px, 2.5vw, 32px); 
    cursor: pointer; 
    color: white; 
    border-radius: 8px; 
    pointer-events: auto; 
    width: clamp(160px, 25vmin, 280px); 
    white-space: nowrap;
    box-sizing: border-box;
    transition: transform 0.15s, background-color 0.2s, box-shadow 0.2s;
    touch-action: manipulation;
}
#actionBtnContainer button:hover { 
    background-color: #27ae60; 
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
#actionBtnContainer button:active { 
    transform: translateY(0);
}
#actionBtnContainer button#resumeBtn { background-color: #2980b9; border: 2px solid #3498db; }
#actionBtnContainer button#resumeBtn:hover { background-color: #3498db; }
#actionBtnContainer button#retryGameOverBtn { background-color: #e67e22; border: 2px solid #f39c12; }
#actionBtnContainer button#retryGameOverBtn:hover { background-color: #d35400; }
#actionBtnContainer button#mainMenuBtn { background-color: #2ecc71; border: 2px solid #27ae60; }
#actionBtnContainer button#mainMenuBtn:hover { background-color: #27ae60; }
#actionBtnContainer button#continueEndlessBtn,
.btn-endless-mode {
    background: linear-gradient(135deg, #f39c12, #e74c3c);
    border: 2px solid #f1c40f !important;
    color: #ffffff;
    font-weight: bold;
    box-shadow: 0 0 15px rgba(241, 196, 15, 0.6);
    animation: endlessBtnPulse 1.8s infinite alternate ease-in-out;
}
#actionBtnContainer button#continueEndlessBtn:hover,
.btn-endless-mode:hover {
    background: linear-gradient(135deg, #e67e22, #c0392b);
    box-shadow: 0 0 25px rgba(241, 196, 15, 0.9);
    transform: translateY(-2px) scale(1.04);
}
@keyframes endlessBtnPulse {
    0% { box-shadow: 0 0 10px rgba(241, 196, 15, 0.4); }
    100% { box-shadow: 0 0 22px rgba(241, 196, 15, 0.9); }
}

.checkbox-container { display: flex; align-items: center; gap: 5px; background-color: #34495e; padding: 5px 10px; border-radius: 5px; border: 2px solid #ecf0f1; cursor: pointer; }
.checkbox-container input { cursor: pointer; width: 18px; height: 18px; }

/* ==========================================
   完整更新筆記彈窗 (Changelog Modal)
   ========================================== */
#notes-modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    animation: notesBackdropFadeIn 0.3s ease-out;
}
@keyframes notesBackdropFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#notes-content {
    background-color: #2c3e50;
    border: 3px solid #7f8c8d;
    border-radius: 14px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.9);
    width: 90%;
    max-width: 860px;
    height: 94vh;
    max-height: 94vh;
    display: flex;
    flex-direction: column;
    position: relative;
    color: #ecf0f1;
    box-sizing: border-box;
    overflow: hidden;
    animation: notesPopIn 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes notesPopIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

.notes-close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    background: rgba(0, 0, 0, 0.35);
    border: 2px solid #7f8c8d;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    font-size: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: #ecf0f1;
    transition: transform 0.2s, background-color 0.2s, border-color 0.2s;
    z-index: 20;
}
.notes-close-btn:hover {
    background: rgba(231, 76, 60, 0.85);
    transform: scale(1.15);
    border-color: #e74c3c;
}

.notes-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 30px;
    box-sizing: border-box;
}

/* 右側卷軸樣式 */
.notes-body::-webkit-scrollbar {
    width: 10px;
}
.notes-body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 5px;
}
.notes-body::-webkit-scrollbar-thumb {
    background: #7f8c8d;
    border-radius: 5px;
}
.notes-body::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}

.notes-body h1 {
    text-align: center;
    color: #f1c40f;
    border-bottom: 2px solid #7f8c8d;
    padding-bottom: 15px;
    margin-bottom: 25px;
    margin-top: 5px;
    font-size: 26px;
}
.notes-body details {
    margin-bottom: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border-left: 4px solid #3498db;
    transition: 0.3s;
}
.notes-body details:hover {
    background: rgba(255, 255, 255, 0.1);
}
.notes-body summary {
    padding: 14px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    outline: none;
    color: #34db98;
}
.notes-body .content {
    padding: 0 15px 15px 30px;
    color: #bdc3c7;
    white-space: pre-wrap;
    font-size: 0.95em;
    line-height: 1.6;
}
.notes-body .highlight { color: #e74c3c; font-weight: bold; }
.notes-body .version-badge { color: #f1c40f; }
.notes-body .old-versions { border-left-color: #95a5a6; }
.notes-body .old-versions summary { color: #95a5a6; }

/* ==========================================
   補給時間動態與互動樣式 (Buff Selection System)
   ========================================== */
.buff-selection-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 1000px;
    padding: 0 10px;
    box-sizing: border-box;
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.buff-selection-wrapper.buff-fade-out {
    pointer-events: none !important;
}

/* 補給時間確認後：標題、倒數提示與確認按鈕快速淡出 */
@keyframes buffHeaderFadeOut {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-15px); }
}

.buff-selection-wrapper.buff-fade-out .buff-title,
.buff-selection-wrapper.buff-fade-out .buff-timer-hint,
.buff-selection-wrapper.buff-fade-out .buff-confirm-container,
.buff-selection-wrapper.buff-fade-out .buff-reroll-container {
    animation: buffHeaderFadeOut 0.22s ease-out forwards !important;
    pointer-events: none !important;
}

/* 補給時間確認後：未被選中的兩組卡片，快速向下消失（0.25s），不漸漸變大（縮小至 0.85），快速淡出變暗 */
@keyframes buffCardDismissDown {
    0% {
        opacity: 0.6;
        transform: translateY(0) scale(0.96);
        filter: brightness(0.9);
    }
    100% {
        opacity: 0;
        transform: translateY(70px) scale(0.85);
        filter: brightness(0.3) grayscale(80%);
    }
}

.buff-selection-wrapper.buff-fade-out .buff-card:not(.selected) {
    animation: buffCardDismissDown 0.25s cubic-bezier(0.4, 0, 1, 1) forwards !important;
    pointer-events: none !important;
}

/* 補給時間確認後：被取得高亮的卡片，金光高亮懸浮，與未選中卡片形成強烈反差，隨後淡出套用 */
@keyframes buffCardAcquiredHighlight {
    0% {
        opacity: 1;
        transform: translateY(-10px) scale(1.05);
        filter: brightness(1.25);
        box-shadow: 0 0 25px rgba(241, 196, 15, 0.9), 0 12px 28px rgba(0, 0, 0, 0.9);
    }
    55% {
        opacity: 1;
        transform: translateY(-14px) scale(1.08);
        filter: brightness(1.4);
        box-shadow: 0 0 45px rgba(241, 196, 15, 1), 0 16px 36px rgba(0, 0, 0, 0.95);
    }
    100% {
        opacity: 0;
        transform: translateY(-20px) scale(1.02);
        filter: brightness(1.1);
        box-shadow: 0 0 10px rgba(241, 196, 15, 0);
    }
}

.buff-selection-wrapper.buff-fade-out .buff-card.selected {
    animation: buffCardAcquiredHighlight 0.52s cubic-bezier(0.2, 0.8, 0.25, 1) forwards !important;
    pointer-events: none !important;
    z-index: 10;
}

.buff-title {
    color: #f1c40f;
    font-size: clamp(20px, 4vmin, 44px);
    font-weight: bold;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.9), 0 0 10px rgba(241, 196, 15, 0.4);
    margin-bottom: clamp(8px, 1.8vh, 22px);
    text-align: center;
    user-select: none;
    letter-spacing: 2px;
}

.buff-cards-container {
    display: flex;
    gap: clamp(8px, 2vw, 26px);
    justify-content: center;
    align-items: stretch;
    flex-wrap: nowrap;
    width: 100%;
    max-width: 1080px;
    user-select: none;
    box-sizing: border-box;
}

/* 卡片入場動畫：由上往下就定位至 100%，淡入 0.5 秒 */
@keyframes buffCardDropIn {
    0% {
        opacity: 0;
        transform: translateY(-70px) scale(0.85);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.buff-card-anim {
    animation: buffCardDropIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.buff-card { 
    border: 3px solid #7f8c8d; 
    border-radius: clamp(8px, 1.5vmin, 14px); 
    width: clamp(105px, 26vw, 240px); 
    flex: 1 1 0;
    max-width: 250px;
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: flex-start;
    padding: clamp(8px, 2vh, 22px) clamp(6px, 1.2vw, 16px); 
    transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s, filter 0.25s, opacity 0.25s; 
    box-sizing: border-box; 
    box-shadow: 0 5px 15px rgba(0,0,0,0.5); 
}

/* 未完成入場前不可點選 */
.buff-cards-container.not-interactive .buff-card {
    pointer-events: none !important;
    cursor: default !important;
}

/* 完成入場後啟用點選與 hover */
.buff-cards-container.interactive .buff-card {
    pointer-events: auto;
    cursor: pointer;
}

.buff-cards-container.interactive .buff-card:hover { 
    transform: translateY(-8px) scale(1.03); 
    box-shadow: 0 15px 30px rgba(0,0,0,0.85); 
    border-color: #f1c40f; 
    filter: brightness(1.2); 
}

/* 卡片選中高亮 (hit) */
.buff-card.selected {
    border-color: #f1c40f !important;
    box-shadow: 0 0 25px rgba(241, 196, 15, 0.9), 0 12px 28px rgba(0, 0, 0, 0.9) !important;
    transform: translateY(-10px) scale(1.05) !important;
    filter: brightness(1.25) !important;
}

.buff-cards-container.has-selection .buff-card:not(.selected) {
    opacity: 0.6;
    transform: scale(0.96);
}

.buff-icon { 
    font-size: clamp(34px, 7vmin, 90px); 
    line-height: 1.15; 
    margin-bottom: clamp(4px, 1vh, 12px); 
    text-shadow: 0 5px 10px rgba(0,0,0,0.5); 
}
.buff-icon img,
.buff-card-icon-img {
    width: clamp(38px, 8vmin, 90px);
    height: clamp(38px, 8vmin, 90px);
    object-fit: contain;
    vertical-align: middle;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
    pointer-events: none;
    display: inline-block;
}
.active-buff-icon img {
    width: 82%;
    height: 82%;
    object-fit: contain;
    vertical-align: middle;
    pointer-events: none;
}
.buff-tooltip-icon img {
    width: 22px;
    height: 22px;
    object-fit: contain;
    vertical-align: middle;
}
.buff-desc { 
    font-size: clamp(22px, 1.6vmin, 21px); 
    color: #ecf0f1; 
    text-align: center; 
    flex-grow: 1; 
    font-weight: bold; 
    text-shadow: 1px 1px 2px black; 
    line-height: 1.35;
    word-break: break-word;
}
.buff-preview {
    margin-top: clamp(6px, 1.2vh, 14px);
    font-size: clamp(11px, 1.35vmin, 16px);
    color: #ffffff;
    text-align: center;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
    line-height: 1.3;
    word-break: break-word;
    width: 100%;
}
.buff-preview-add {
    color: #32f623;
    font-weight: bold;
}
.buff-tier-gray { background-color: #7f8c8d; border-color: #bdc3c7; }
.buff-tier-green { background-color: #5b7a6a; border-color: #2ecc71; }
.buff-tier-blue { background-color: #4b6a88; border-color: #3498db; }
.buff-tier-purple { background-color: #6c5b7b; border-color: #9b59b6; }
.buff-tier-orange { background-color: #d35400; border-color: #f39c12; }
.buff-tier-gray-orange { background-color: #8c6751; border-color: #f39c12; }

/* 補給時間倒數隨機提示文字 */
.buff-timer-hint {
    font-size: 1rem;
    color: #2ecc71;
    text-align: center;
    margin-top: clamp(8px, 1.5vh, 16px);
    margin-bottom: clamp(2px, 0.8vh, 6px);
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
    user-select: none;
    letter-spacing: 1px;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.buff-timer-hint.timer-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.buff-timer-sec {
    color: #ffffff;
    font-weight: bold;
}

/* 確認按鈕容器與彈出動態 */
.buff-confirm-container {
    min-height: clamp(36px, 5.5vh, 65px);
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: clamp(8px, 1.5vh, 20px);
}

.buff-confirm-btn {
    background: linear-gradient(135deg, #f1c40f, #e67e22);
    color: #1a252f;
    font-size: clamp(13px, 1.8vmin, 22px);
    font-weight: bold;
    padding: clamp(6px, 1vh, 12px) clamp(22px, 4vw, 55px);
    border: 3px solid #ffffff;
    border-radius: clamp(8px, 1.2vmin, 12px);
    cursor: pointer;
    box-shadow: 0 5px 20px rgba(241, 196, 15, 0.6);
    transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
    animation: confirmPop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
    letter-spacing: 2px;
    touch-action: manipulation;
}

.buff-confirm-btn:hover {
    transform: scale(1.08);
    filter: brightness(1.15);
    box-shadow: 0 8px 30px rgba(241, 196, 15, 0.9);
}

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

@keyframes confirmPop {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.85);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 補給時間：重新 roll 卡片按鈕與次數說明 */
.buff-reroll-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: clamp(18px, 3.2vh, 36px);
    gap: clamp(4px, 0.8vh, 8px);
    user-select: none;
}

.buff-reroll-btn {
    background: none;
    border: none;
    padding: 2px 6px;
    font-size: clamp(16px, 2.2vmin, 28px);
    color: #ffffff;
    text-decoration: none;
    font-weight: bold;
    cursor: pointer;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.9), 0 2px 4px rgba(0, 0, 0, 0.8);
    transition: transform 0.15s ease, filter 0.15s ease;
    touch-action: manipulation;
}

.buff-reroll-dice {
    display: inline-block;
    text-decoration: none !important;
    vertical-align: middle;
    margin: 0 2px;
}

.buff-reroll-text {
    text-decoration: underline;
    text-underline-offset: 4px;
    margin: 0 2px;
}

.buff-reroll-btn:hover {
    filter: brightness(1.2) drop-shadow(0 0 6px rgba(255, 255, 255, 0.7));
    transform: scale(1.05);
}

.buff-reroll-btn:active {
    transform: scale(0.96);
}

.buff-reroll-hint {
    font-size: clamp(14px, 1.8vmin, 24px);
    color: #ffdb83;
    font-weight: bold;
    text-align: center;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.9), 0 2px 4px rgba(0, 0, 0, 0.8);
}

.buff-reroll-count {
    color: #ffffff;
    font-weight: bold;
}

/* ==========================================
   主選單與面板 (Main Menu & Panels)
   ========================================== */
#main-menu {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: #111; /* 黑底 */
    z-index: 2000;
    display: flex; justify-content: center; align-items: center;
}

#main-menu-bg {
    position: relative;
    width: 100%; height: 100%;
   /*  max-width: min(1920px, calc(100vh * (1920 / 1538))); */
    max-height: calc(100vw * (1538 / 1920));
    aspect-ratio: 1920 / 1538;
    background: url('images/mainmenu_bg.webp') no-repeat center center;
    background-size: contain;
    display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
    padding-bottom: clamp(8px, 3.5%, 34px);
    box-sizing: border-box;
}

.menu-content {
    display: flex; flex-direction: column;
    gap: clamp(6px, 1.4vh, 16px);
    align-items: center;
    width: 100%;
    max-width: 95%;
    background: transparent;
    border: none; box-shadow: none; padding: 0;
}

.menu-row {
    display: flex;
    gap: clamp(8px, 1.8vw, 18px);
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
}

.menu-disclaimer {
    color: #bdc3c7;
    font-size: clamp(9.5px, 1.3vmin, 13px);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.9);
    text-align: center;
    letter-spacing: 0.5px;
    user-select: none;
    pointer-events: none;
    margin-top: clamp(2px, 0.4vmin, 6px);
    width: 96%;
    max-width: 96%;
    line-height: 1.35;
    word-break: break-word;
    box-sizing: border-box;
}

.menu-disclaimer a {
    color: inherit;
    text-decoration: none;
    pointer-events: auto;
    cursor: pointer;
    transition: color 0.15s ease;
}

.menu-disclaimer a:hover {
    text-decoration: underline;
    color: #ffffff;
}

/* ==========================================
   戰場資訊面板 (Combat Info Panel)
   ========================================== */
#combat-info-panel {
    position: fixed; top: 60px; right: 20px;
    background: rgba(31, 32, 33, 90%); border: 2px solid #7f8c8d;
    border-radius: 10px; padding: 14px; color: #ecf0f1; 
    width: 290px;
    box-sizing: border-box;
    z-index: 1000; box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    user-select: none;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #7f8c8d rgba(0, 0, 0, 0.2);
}
#combat-info-panel::-webkit-scrollbar {
    width: 5px;
}
#combat-info-panel::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2.5px;
}
#combat-info-panel::-webkit-scrollbar-thumb {
    background: #7f8c8d;
    border-radius: 2.5px;
}
#combat-info-panel::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}
#combat-info-panel h3 { margin: 0 0 10px 0; font-size: 18px; color: #f1c40f; text-align: center; cursor: move; }
.buff-summary { font-size: 16px; font-weight: bold; color: #3498db; cursor: pointer; outline: none; margin-bottom: 5px; }
#buff-stats-list { font-size: 14px; line-height: 1.6; margin-top: 10px; }
.stat-item { display: flex; justify-content: space-between; align-items: center; }
.stat-positive { color: #2ecc71; font-weight: bold; }
.stat-icon { margin-right: 6px; display: inline-flex; align-items: center; justify-content: center; width: 18px; text-align: center; vertical-align: middle; font-size: 15px; }
.stat-icon img { width: 18px; height: 18px; object-fit: contain; vertical-align: middle; }

.game-title {
    color: #f1c40f; font-size: 48px; margin-bottom: 20px; margin-top: 0; text-shadow: 2px 2px 4px #000;
}

.menu-btn {
    padding: clamp(7px, 1.3vh, 13px) clamp(12px, 2vw, 28px);
    font-size: clamp(13px, 1.8vmin, 20px);
    font-weight: bold;
    color: white;
    background-color: #2980b9;
    border: clamp(1.5px, 0.25vmin, 2px) solid #3498db;
    border-radius: clamp(6px, 1vmin, 10px);
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s, box-shadow 0.2s;
    width: clamp(135px, 21vmin, 250px);
    min-width: 125px;
    max-width: 270px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    touch-action: manipulation;
    white-space: nowrap;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    position: relative;
    z-index: 2005;
    pointer-events: auto;
}
.menu-btn:hover { background-color: #3498db; transform: scale(1.05); }
.menu-btn.disabled-btn { background-color: #7f8c8d; border-color: #95a5a6; cursor: not-allowed; }
.menu-btn.disabled-btn:hover { transform: none; background-color: #7f8c8d; }
.menu-btn.small-btn { width: auto; padding: clamp(4px, 1vh, 8px) clamp(8px, 1.5vw, 16px); font-size: clamp(11px, 1.5vmin, 16px); }

/* 手機橫向 (矮螢幕) 特化優化：高度不超過 480px 時，進一步縮小間距與按鈕，確保不遮擋背景三隻鸚鵡與標題 */
@media (max-height: 480px) {
    #main-menu-bg {
        padding-bottom: 2%;
    }
    .menu-content {
        gap: 5px;
    }
    .menu-row {
        gap: 8px;
    }
    .menu-btn {
        padding: 5px 10px;
        font-size: 12px;
        width: clamp(115px, 18vw, 150px);
        min-width: 110px;
        border-radius: 6px;
    }
    .menu-disclaimer {
        font-size: 9px;
        margin-top: 1px;
    }

    /* ESC 選單按鈕（矮螢幕時水平雙排自適應，不垂直佔滿畫面，高度僅佔螢幕約 22%） */
    #esc-combat-info {
        display: none !important;
    }
    #overlay-text {
        font-size: 20px !important;
        margin-bottom: 4px;
    }
    #overlay-subtext {
        font-size: 13px !important;
        margin-top: 2px;
    }
    #actionBtnContainer {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        max-width: 440px;
        gap: 5px 8px;
        margin-top: 6px;
    }
    #actionBtnContainer button {
        width: clamp(120px, 22vw, 140px);
        font-size: 12px;
        padding: 4px 8px;
        border-radius: 6px;
        border-width: 1.5px;
    }

    /* 補給時間卡片與按鈕（矮螢幕特化縮小，總高度僅約 180px，留出 50%+ 寬廣視野） */
    .buff-title {
        font-size: 18px !important;
        margin-bottom: 5px;
    }
    .buff-cards-container {
        gap: 8px;
        max-width: 580px;
        flex-wrap: nowrap;
    }
    .buff-card {
        width: clamp(120px, 24vw, 160px);
        padding: 6px 8px;
        border-radius: 8px;
        border-width: 2px;
    }
    .buff-icon {
        font-size: 36px !important;
        margin-bottom: 2px;
    }
    .buff-icon img,
    .buff-card-icon-img {
        width: 36px !important;
        height: 36px !important;
    }
    .buff-desc {
        font-size: 11px !important;
        line-height: 1.25;
    }
    .buff-preview {
        font-size: 10px !important;
        margin-top: 3px !important;
        line-height: 1.2;
    }
    .buff-timer-hint {
        font-size: 0.85rem !important;
        margin-top: 4px !important;
        margin-bottom: 2px !important;
    }
    .buff-confirm-container {
        min-height: 32px;
        margin-top: 5px;
    }
    .buff-confirm-btn {
        font-size: 12.5px !important;
        padding: 4px 24px !important;
        border-radius: 6px;
        border-width: 2px;
    }
    .buff-reroll-container {
        margin-top: 10px !important;
        gap: 1px !important;
    }
    .buff-reroll-btn {
        font-size: 15px !important;
    }
    .buff-reroll-hint {
        font-size: 13px !important;
    }
}

@media (max-width: 650px) {
    #esc-combat-info {
        display: none !important;
    }
    #combat-info-panel {
        display: none;
    }
}

/* 手機直向 (窄螢幕) 特化優化：寬度不超過 500px 時，單排容納 2 顆按鈕自適應居中，不垂直堆疊 */
@media (max-width: 500px) {
    .menu-content {
        gap: 6px;
    }
    .menu-row {
        gap: 8px;
    }
    .menu-btn {
        width: calc(50% - 6px);
        min-width: 120px;
        max-width: 160px;
        padding: 7px 6px;
        font-size: 12.5px;
        border-radius: 6px;
    }
    .menu-disclaimer {
        font-size: 8px;
        line-height: 1.25;
        white-space: normal;
        max-width: 96%;
    }

    /* ESC 選單按鈕（直向窄螢幕縮小，完美契合 Canvas 高度） */
    #overlay-text {
        font-size: 18px !important;
        margin-bottom: 4px !important;
    }
    #actionBtnContainer {
        gap: 5px !important;
        margin-top: 4px !important;
    }
    #actionBtnContainer button {
        width: clamp(130px, 46vw, 170px) !important;
        font-size: 11.5px !important;
        padding: 4px 10px !important;
        border-radius: 6px !important;
    }

    /* 補給時間卡片與按鈕（直向窄螢幕橫向 3 張並排不折行，完美契合 Canvas 高度） */
    .buff-title {
        font-size: 16px !important;
        margin-bottom: 5px !important;
    }
    .buff-cards-container {
        flex-wrap: nowrap !important;
        gap: 5px !important;
        width: 100% !important;
    }
    .buff-card {
        width: calc((100% - 10px) / 3) !important;
        max-width: none !important;
        padding: 5px 3px !important;
        border-radius: 6px !important;
        border-width: 1.5px !important;
    }
    .buff-icon {
        font-size: 26px !important;
        margin-bottom: 2px !important;
    }
    .buff-icon img,
    .buff-card-icon-img {
        width: 26px !important;
        height: 26px !important;
    }
    .buff-desc {
        font-size: 9.5px !important;
        line-height: 1.2 !important;
    }
    .buff-preview {
        font-size: 9px !important;
        margin-top: 3px !important;
        line-height: 1.2 !important;
    }
    .buff-timer-hint {
        font-size: 0.8rem !important;
        margin-top: 4px !important;
        margin-bottom: 2px !important;
    }
    .buff-confirm-container {
        min-height: 30px !important;
        margin-top: 6px !important;
    }
    .buff-confirm-btn {
        font-size: 12px !important;
        padding: 4px 20px !important;
        border-radius: 6px !important;
    }
    .buff-reroll-container {
        margin-top: 12px !important;
        gap: 1px !important;
    }
    .buff-reroll-btn {
        font-size: 14px !important;
    }
    .buff-reroll-hint {
        font-size: 12px !important;
    }
}

.sub-panel {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85); z-index: 2010;
    display: none; justify-content: center; align-items: center;
    padding: 10px;
    box-sizing: border-box;
}

.panel-box {
    background: #2c3e50; 
    padding: clamp(16px, 3vh, 35px); 
    border-radius: 14px; 
    color: white;
    width: clamp(280px, 88vw, 480px); 
    max-width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
    box-sizing: border-box;
    text-align: center; 
    border: 2px solid #3498db; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.9);
}
.panel-box h2 { 
    color: #f1c40f; 
    margin-top: 0; 
    margin-bottom: clamp(12px, 2vh, 25px); 
    font-size: clamp(20px, 4vmin, 32px); 
    text-shadow: 1px 1px 2px #000; 
}

.setting-item { 
    margin-bottom: clamp(10px, 1.8vh, 18px); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    font-size: clamp(13px, 2vmin, 20px); 
}
.setting-item label { flex-shrink: 0; width: 120px; text-align: left; }
.setting-item .checkbox-container { width: auto; font-size: clamp(12px, 1.8vmin, 18px); }
.setting-item input[type="range"] { flex-grow: 1; margin-left: 12px; cursor: pointer; }

.instructions-text { 
    text-align: left; 
    font-size: clamp(13px, 1.8vmin, 18px); 
    margin-bottom: 20px; 
    line-height: 1.55; 
}
.instructions-text ul { list-style-type: none; padding-left: 0; }
.instructions-text li { margin-bottom: 10px; }
.instructions-text code { background: #34495e; padding: 4px 8px; border-radius: 4px; color: #f1c40f; font-weight: bold; }

/* 開發者選項按鈕網格 */
.dev-btn-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 15px;
}
.dev-btn-grid .menu-btn {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    padding: clamp(6px, 1.2vh, 10px) clamp(6px, 1vw, 12px) !important;
    font-size: clamp(12px, 1.6vmin, 15px) !important;
    box-sizing: border-box;
}
.dev-btn-money {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    padding: clamp(8px, 1.4vh, 12px) clamp(10px, 1.5vw, 16px) !important;
    font-size: clamp(14px, 1.8vmin, 17px) !important;
    background-color: #f1c40f !important;
    color: #1a1a1a !important;
    border-color: #f39c12 !important;
    box-sizing: border-box;
}
.dev-btn-money:hover {
    background-color: #f39c12 !important;
}



