:root {
    --hex-size: 70px;
    --hex-gap: 10px;
    --board-bg: #2c3e50;
    --hex-bg: #34495e;
    /* 己方棋格底色 */
    --hex-bg-enemy: #5c4033;
    /* 敵方棋格底色 */
    --hex-bg-occupied: #212f3c;
    --hex-hover-bg: #4a6572;
    /* 己方懸停顏色 */
    --hex-hover-bg-enemy: #7c5a43;
    /* 敵方懸停顏色 */
    --char-panel-bg: #ecf0f1;
    --selected-border-color: #3498db;
    --clear-button-bg: #0e89b8;
    --clear-button-hover-bg: #0d6d93;
    --hex-border-color: #0d1117;
    --elixir-color: #f39c12;
    --drag-over-border: #f1c40f;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #1c2833;
    color: #ecf0f1;
    /* display: flex; */
    flex-direction: column;
    align-items: center;
    padding: 16px;
    gap: 10px;
    margin: 0;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    /* 修改此處以將版本選擇器推到左邊 */
    align-items: center;
    width: 100%;
    padding: 0 10px;
    box-sizing: border-box;
}

.version-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
    color: #bdc3c7;
}

.version-selector select {
    background-color: var(--hex-bg);
    color: #ecf0f1;
    border: 1px solid var(--hex-border-color);
    border-radius: 5px;
    padding: 4px 8px;
    cursor: pointer;
}

.version-selector select:hover {
    background-color: var(--hex-hover-bg);
}

.version-info-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-left: 8px;
    background-color: var(--hex-bg);
    border: 1px solid var(--hex-border-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #bdc3c7;
    font-size: 12px;
}

.version-info-icon:hover {
    background-color: var(--hex-hover-bg);
    color: #ecf0f1;
    transform: scale(1.1);
}

.game-container {
    display: flex;
    gap: 16px;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    margin: 16px 0px;
}

.title-container {
    text-align: center;
    width: 100%;
    margin-bottom: 10px;
}

.title-container h1 {
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.title-container .text {
    margin-top: 8px;
    color: #bdc3c7;
    font-size: 0.9em;
}

.author-link {
    color: #bdc3c7;
    text-decoration: none;
    transition: color 0.2s, text-decoration 0.2s;
}

.author-link:hover {
    color: #ecf0f1;
    text-decoration: underline;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    /* 防止被壓縮 */
}

/* "問題回報" 按鈕 */
.report-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #95a5a6;
    text-decoration: none;
    border-radius: 8px;
    transition: color 0.2s;
    font-size: 0.8em;
    cursor: pointer;
    background: none;
    border: none;
    padding: 6px 10px;
}

.report-trigger:hover {
    color: #ecf0f1;
}

.version-info {
    font-size: 0.8em;
    color: #7f8c8d;
}

/* --- 羈絆統計面板 --- */
#traits-summary-panel {
    display: flex;
    flex-direction: column;
    padding: 8px;
    color: #ecf0f1;
    width: 100px;
    flex-shrink: 0;
    /* 防止面板在 flex 佈局中被壓縮 */
}

#traits-summary-panel h3 {
    text-align: center;
    margin: 0;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--hex-bg);
}

.summary-sections-wrapper {
    display: flex;
    flex-direction: column;
    /* 預設垂直排列 */
    gap: 15px;
    flex-grow: 1;
    /* 填滿父容器 #traits-summary-panel 的高度 */
    overflow: hidden;
}

.summary-section {
    display: flex;
    flex-direction: column;
}

.summary-section--player {
    flex-direction: column-reverse;
    margin-top: auto;
    /* 將此區塊推至 flex 容器底部 */
}

.summary-section .no-traits {
    text-align: center;
    color: #7f8c8d;
    font-style: italic;
}

.summary-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.summary-header h4 {
    margin: 8px 0;
    font-size: 1.1em;
}

.summary-header i {
    padding-top: 4px;
}

.clear-section-button {
    cursor: pointer;
    color: #95a5a6;
    transition: color 0.2s ease, transform 0.2s ease;
}

.clear-section-button:hover {
    color: #ecf0f1;
    transform: scale(1.2);
}

.trait-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.trait-summary-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0px 4px;
    transition: all 0.3s ease;
    cursor: help;
}

/* 未啟動羈絆的樣式 */
.trait-summary-item.inactive-trait {
    filter: grayscale(100%);
    opacity: 0.6;
}

.trait-summary-item .trait-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.trait-summary-item span {
    font-size: 0.9em;
    white-space: nowrap;
    /* 防止文字換行 */
}


/* --- 棋盤容器 --- */
#board-container {
    display: flex;
    flex-direction: row;
    /* 改為橫向排列 */
    align-items: stretch;
    gap: 16px;
    padding: 20px;
    background-color: var(--board-bg);
    border-radius: 15px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.board-main-content {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hex-grid-wrapper {
    margin: 42px 0;
}

.hex-row {
    display: flex;
    position: relative;
}

.hex-row:not(:first-child) {
    margin-top: calc(var(--hex-size) * -0.25 + var(--hex-gap) * -0.5 + 6px);
}

/* 將奇數行向右推移半個六邊形的寬度 */
.hex-row--odd {
    margin-left: calc(var(--hex-size) * 0.5 + var(--hex-gap) * 0.5);
}

/* --- 六邊形格子樣式 --- */
.hexagon {
    width: var(--hex-size);
    height: calc(var(--hex-size) * 0.866);
    background-color: var(--hex-bg);
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    margin: calc(var(--hex-gap) / 2);
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, transform 0.2s ease, background 0.2s;
    background-position: center;
    background-repeat: no-repeat;
    image-rendering: -webkit-optimize-contrast;
    box-sizing: border-box;
    /* 確保邊框不影響佈局 */
    position: relative;
}

/* 拖曳時的樣式 */
.hexagon.dragging {
    opacity: 0.5;
    transform: scale(1.05);
}

/* 拖曳經過時的放大效果 */
.hexagon.drag-over {
    transform: scale(1.05);
}

/* 拖曳經過時的背景色 tint 效果 (修改後) */
.hexagon.drag-over::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* 必須重複 clip-path 才能讓偽元素也是六邊形 */
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    /* 使用半透明的背景色作為 tint 疊加在原背景之上 */
    background-color: var(--drag-over-border);
    opacity: 0.4;
    z-index: 2;
    /* 確保在角色圖片之上 */
    pointer-events: none;
    /* 避免偽元素干擾滑鼠事件 */
    transition: opacity 0.2s ease;
}

/* 己方棋格懸停效果 */
.hexagon:not([draggable="true"]):hover {
    background-color: var(--hex-hover-bg);
    transform: scale(1.05);
    z-index: 1;
}

.hexagon[draggable="true"] {
    cursor: grab;
}

.hexagon[draggable="true"]:active {
    cursor: grabbing;
}

/* 敵方棋格樣式 */
.hexagon.enemy-territory {
    background-color: var(--hex-bg-enemy);
}

/* 敵方棋格懸停效果 */
.hexagon.enemy-territory:not([draggable="true"]):hover {
    background-color: var(--hex-hover-bg-enemy);
}

/* 棋盤上角色懸停效果 */
.hexagon[draggable="true"]::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 1;
    pointer-events: none;
    /* 允許點擊穿透 */
}

.hexagon[draggable="true"]:hover::before {
    opacity: 1;
}

.hexagon-traits {
    position: absolute;
    bottom: 5px;
    /* 定位在底部 */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    z-index: 2;
    /* 在遮罩之上 */
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    /* 避免圖示干擾滑鼠事件 */
}

.hexagon[draggable="true"]:hover .hexagon-traits {
    opacity: 1;
}

.hexagon-trait-icon {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.hex-bg-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    z-index: 0;
}

/* --- 角色選擇面板 --- */
#characters-panel {
    display: flex;
    flex-direction: column;
    max-width: 500px;
    gap: 12px;
    padding: 20px;
    background-color: var(--char-panel-bg);
    border-radius: 15px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    align-content: start;
    flex-grow: 1;
    /* 允許其在 flex 容器中增長 */
}

#characters-panel h3 {
    text-align: center;
    margin: 0;
    color: #2c3e50;
}

#characters-panel .divider-text {
    display: flex;
    align-items: center;
    color: #6b7280;
    font-size: 0.875rem;
}
#characters-panel .divider-text::before,
#characters-panel .divider-text::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #d1d5db;
}
#characters-panel .divider-text::before {
    margin-right: 1rem;
}
#characters-panel .divider-text::after {
    margin-left: 1rem;
}

.character-grid {
    display: grid;
    /* RWD 核心：使用 auto-fit 自動調整欄位數 */
    /* 固定欄寬，並讓網格本身置中對齊 */
    grid-template-columns: repeat(auto-fill, 60px);
    justify-content: center;
    gap: 12px;
    padding-top: 10px;
}

.character-wrapper {
    position: relative;
    width: 60px;
    height: 75px;
    /* 調整高度以匹配圖片比例 */
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 4px solid transparent;
    box-sizing: border-box;
    overflow: visible;
    /* 顯示突出的水滴 */
}

.character-wrapper:hover {
    transform: scale(1.1);
}

.character-wrapper.selected {
    border-color: var(--selected-border-color);
    box-shadow: 0 0 15px var(--selected-border-color);
    transform: scale(1.1);
}

.character-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 6px;
}

.character-traits {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2px 0;
    gap: 3px;
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
}

.trait-icon {
    height: 18px;
    width: 18px;
}

/* --- Elixir 水滴樣式 --- */
.character-elixir {
    position: absolute;
    top: -10px;
    left: -10px;
    z-index: 10;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.character-elixir svg {
    width: 24px;
    height: 24px;
    filter: drop-shadow(0px 1px 3px rgba(0, 0, 0, 0.6));
    position: absolute;
    /* 讓 SVG 和數字重疊 */
    top: 0;
    left: 0;
}

.character-elixir svg path {
    fill: var(--elixir-color);
}

.character-elixir span {
    position: relative;
    z-index: 1;
    font-size: 13px;
    color: #fff;
    font-weight: bold;
    text-shadow: 1px 1px 1px #000;
}

/* --- 屬性篩選器樣式 --- */
.trait-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    align-items: center;
}

.trait-filter-button {
    background-color: #fff;
    border: 2px solid #bdc3c7;
    border-radius: 50%;
    padding: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    box-sizing: border-box;
}

.trait-filter-button:hover {
    border-color: var(--selected-border-color);
    background-color: #b4d4e9;
    /* transform: scale(1.1); */
}

.trait-filter-button.active {
    border-color: var(--selected-border-color);
    box-shadow: 0 0 10px var(--selected-border-color);
    background-color: #71b5e2;
}

.trait-filter-button img {
    width: 20px;
    height: 20px;
}

.clear-filter-button {
    position: relative;
    margin-right: 12px;
}

.clear-filter-button::after {
    content: '';
    position: absolute;
    top: 15%;
    bottom: 15%;
    right: -12px;
    width: 1px;
    background-color: #bdc3c7;
}

.clear-filter-button i {
    font-size: 18px;
    color: #888;
}

.clear-filter-button:hover i {
    color: var(--clear-button-hover-bg);
}

/* --- Tooltip 樣式 --- */
.tooltip {
    position: absolute;
    background-color: rgba(20, 30, 40, 0.9);
    color: #ecf0f1;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--hex-hover-bg);
    pointer-events: none;
    /* 避免 tooltip 自身觸發滑鼠事件 */
    z-index: 999;
    font-size: 14px;
    line-height: 1.6;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    transition: opacity 0.2s ease;
}

/* 針對不同類型 Tooltip 的寬度設定 */
.tooltip-character-width {
    width: 220px;
}

.tooltip-trait-width {
    width: 260px;
}

.tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--hex-bg);
}

.tooltip-header h4 {
    margin: 0;
    font-size: 18px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tooltip-header img {
    width: 24px;
    height: 24px;
}

.tooltip-elixir {
    display: flex;
    align-items: center;
    font-weight: bold;
    font-size: 18px;
    color: var(--elixir-color);
}

.tooltip-elixir .fa-droplet {
    margin-right: 4px;
}

.tooltip-traits {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}

.tooltip-trait {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--hex-bg);
    padding: 4px 8px;
    border-radius: 12px;
}

.tooltip-trait img {
    width: 20px;
    height: 20px;
}

.tooltip-trait span {
    font-size: 13px;
}

.tooltip-describe {
    color: #e0e5e8;
    margin-top: 10px;
    margin-bottom: 10px;
}

.tooltip-effects {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin: 10px 0;
    padding-left: 10px;
    border-left: 2px solid var(--hex-bg);
}

.tooltip-effect-item {
    font-size: 13px;
    color: #aab8b9;
    /* 預設為暗色 */
    transition: all 0.2s ease;
}

.tooltip-effect-item .level {
    font-weight: bold;
    color: #bdc3c7;
    /* 數字使用稍亮的灰色 */
}

.tooltip-effect-item.active {
    color: #f1c40f;
    /* 啟動的效果使用亮金色 */
}

.tooltip-effect-item.active .level {
    color: #f1c40f;
    /* 啟動時數字也變色 */
}

.tooltip-characters {
    display: grid;
    grid-template-columns: repeat(auto-fill, 40px);
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
}

.tooltip-character-image {
    width: 40px;
    height: 50px;
    border-radius: 5px;
    object-fit: cover;
    transition: filter 0.3s ease;
}

.grayscale {
    filter: grayscale(100%);
    opacity: 0.7;
}

/* --- Modal (彈跳視窗) 樣式 --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--board-bg);
    padding: 25px 30px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
    color: #ecf0f1;
    text-align: center;
    position: relative;
    max-width: 90%;
    width: 400px;
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #fff;
}

.modal-content p {
    margin-bottom: 20px;
}

.modal-content a {
    color: var(--selected-border-color);
    text-decoration: none;
    font-weight: bold;
    background-color: var(--hex-bg);
    padding: 8px 15px;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.modal-content a:hover {
    background-color: var(--hex-hover-bg);
}

.modal-close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 28px;
    color: #95a5a6;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close-button:hover {
    color: #ecf0f1;
}

/* --- RWD 響應式設計 --- */
@media (max-width: 860px) {
    .title-container {
        margin-top: 10px;
        /* 在手機版上，讓標題與頂部操作列保持距離 */
    }

    .game-container {
        /* 將主容器的排列方向改為垂直 */
        flex-direction: column;
        align-items: center;
        /* 讓棋盤和角色面板在垂直方向上置中 */
    }

    #board-container {
        flex-direction: column;
        align-items: center;
    }

    #characters-panel {
        width: 90%;
        max-width: 600px;
    }

    /* 當棋盤與統計面板垂直排列時，讓敵我雙方統計左右並排 */
    .summary-sections-wrapper {
        flex-direction: row;
        justify-content: space-around;
        width: 100%;
        gap: 20px;
    }

    .summary-section {
        flex: 1;
        /* 讓兩區塊均分寬度 */
    }

    #traits-summary-panel {
        width: 100%;
        /* 在小螢幕上佔滿寬度 */
        padding: 15px;
        box-sizing: border-box;
    }

    /* 讓棋盤內容可以水平滾動 */
    .board-main-content {
        width: 100%;
        overflow-x: auto;
    }

    .hex-grid-wrapper {
        padding: 0 10px 10px 10px;
        /* 增加左右內距，並在底部增加空間給滾動條 */
        margin: 20px 0;
        /* 調整垂直邊距 */
        box-sizing: border-box;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
        /* 縮小頁面邊距 */
        font-size: 14px;
        /* 在最小的螢幕上縮小基本字體 */
    }

    .title-container h1 {
        font-size: 1.5em;
        /* 相對應地調整標題大小 */
    }

    :root {
        --hex-size: 60px;
        /* 稍微縮小六邊形 */
        --hex-gap: 8px;
    }

    #characters-panel {
        width: 100%;
        /* 在小螢幕上佔滿寬度 */
        padding: 15px;
        box-sizing: border-box;
    }
}

.tool-description {
    margin: 16px auto;
    width: 80%;
}

.tool-description summary {
    padding: 12px;
    cursor: pointer;
    font-size: 1em;
    font-weight: normal;
    outline: none;
    list-style: none;
    text-align: left;
    color: #7f8c8d;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool-description summary::-webkit-details-marker {
    display: none; /* For Chrome, Safari */
}


.tool-description[open] summary {
    border-bottom: none;
}

.description-content {
    padding: 0 20px 20px 20px;
    color: #bdc3c7;
    font-size: 0.9em;
    text-align: left;
}

.description-content p {
    margin-top: 0;
}

.description-content ul {
    padding-left: 20px; 
    margin: 0;
    list-style-type: disc;
}

.description-content li {
    margin-bottom: 8px;
}
