/*
 * 页面整体样式。
 *
 * 目标是做一个可长时间对弈的工具界面：棋盘清晰、评分表可扫读，
 * 底部说明不遮挡棋局。布局在桌面端左右排列，窄屏自动上下排列。
 */

* {
    box-sizing: border-box;
}

:root {
    /*
     * 棋盘尺寸只在这里定义。
     *
     * --board-frame-size 包含 canvas、padding 和边框宽度，
     * 右侧 AI 面板使用同一个高度，保证左右视觉等高。
     */
    --board-size: min(76vh, 840px);
    --board-frame-size: calc(var(--board-size) + 44px);
    --ink: #1f2428;
    --paper: #77736b;
    --wood: #d3a35e;
    --panel: #20242b;
    --panel-line: rgba(255, 255, 255, 0.08);
    --blue: #72c7ff;
    --gold: #ffd36b;
}

body {
    margin: 0;
    min-height: 100vh;
    color: #f3f3f3;
    background: var(--paper);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#app {
    width: min(1680px, calc(100vw - 40px));
    margin: 0 auto;
    padding: 28px 0 22px;
}

#topbar {
    /* 标题栏宽度跟棋盘本体一致，左右计数圆不会跟评分表宽度联动。 */
    width: var(--board-size);
    margin: 0 auto 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#topbar h1 {
    margin: 0;
    color: #2b2b2b;
    font-size: clamp(42px, 5vw, 72px);
    line-height: 1;
    letter-spacing: 0;
    text-shadow: 0 2px 3px rgba(255, 255, 255, 0.28), 0 4px 8px rgba(0, 0, 0, 0.35);
}

.score {
    width: clamp(62px, 7vw, 84px);
    height: clamp(62px, 7vw, 84px);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: clamp(24px, 3vw, 34px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35), inset 3px 3px 8px rgba(255, 255, 255, 0.18), inset -4px -4px 10px rgba(0, 0, 0, 0.42);
}

.score.black {
    color: #fff;
    background: #242424;
}

.score.white {
    color: #222;
    background: #f5f5f5;
}

.score-label {
    font-size: 12px;
    opacity: 0.72;
}

#game-layout {
    /* 桌面端左右布局；窄屏在 media query 中改为上下布局。 */
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 56px;
}

#ai-panel {
    /*
     * 评分表高度跟整个棋盘外框一致。
     * 宽度给足，配合 table-layout: fixed 避免出现横向滚动条。
     */
    width: min(760px, calc(100vw - 32px));
    height: var(--board-frame-size);
    padding: 16px;
    color: #e8eaef;
    background: var(--panel);
    border: 1px solid var(--panel-line);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
    overflow: hidden;
}

#ai-panel-title {
    font-size: 18px;
    font-weight: 800;
}

#ai-panel-subtitle {
    margin-top: 4px;
    color: #aeb5c2;
    font-size: 13px;
    line-height: 1.35;
}

#ai-table-wrap {
    /* 表体纵向滚动，表头 sticky；横向空间由固定列宽控制。 */
    margin-top: 14px;
    max-height: calc(var(--board-frame-size) - 148px);
    overflow: auto;
}

#ai-stats-table {
    /* 固定布局可以防止长分数或长 NPS 把表格撑出面板。 */
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    table-layout: fixed;
}

#ai-stats-table th,
#ai-stats-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--panel-line);
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#ai-stats-table th:nth-child(1),
#ai-stats-table td:nth-child(1) {
    /* # 序号列。 */
    width: 52px;
}

#ai-stats-table th:nth-child(2),
#ai-stats-table td:nth-child(2) {
    width: 44px;
}

#ai-stats-table th:nth-child(3),
#ai-stats-table td:nth-child(3) {
    width: 64px;
}

#ai-stats-table th:nth-child(4),
#ai-stats-table td:nth-child(4) {
    width: 66px;
}

#ai-stats-table th:nth-child(5),
#ai-stats-table td:nth-child(5) {
    width: 58px;
}

#ai-stats-table th:nth-child(6),
#ai-stats-table td:nth-child(6),
#ai-stats-table th:nth-child(7),
#ai-stats-table td:nth-child(7),
#ai-stats-table th:nth-child(8),
#ai-stats-table td:nth-child(8) {
    width: 92px;
}

#ai-stats-table th {
    position: sticky;
    top: 0;
    color: #b8bfcc;
    background: var(--panel);
    font-weight: 700;
}

#ai-stats-table tbody tr:nth-child(odd) {
    background: rgba(255, 255, 255, 0.03);
}

#ai-stats-empty td {
    color: #9aa2af;
    text-align: center;
}

#ai-current {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--panel-line);
    color: #d8deea;
    font-size: 13px;
    line-height: 1.45;
}

.score-positive {
    color: var(--blue);
}

.score-negative {
    color: var(--gold);
}

.score-neutral {
    color: #e8eaef;
}

.source-ai {
    color: var(--blue);
    font-weight: 800;
}

.source-book {
    color: #7ee08b;
    font-weight: 900;
}

.source-human {
    color: #f4d06f;
    font-weight: 800;
}

#controls {
    /* 终局信息和“再来一局”按钮位于棋盘下方，不遮挡复盘。 */
    width: min(100%, calc(var(--board-size) + 594px));
    margin: 18px auto 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
}

#controls .hidden {
    display: none;
}

#restart-btn {
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 6px;
    padding: 9px 16px;
    color: #222;
    background: #f2f2f2;
    font-size: 15px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.22);
}

#restart-btn:hover {
    background: #fff;
}

#status {
    min-width: 0;
    color: #fff;
    font-size: 16px;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

#engine-note {
    /* 技术说明放在最底部，避免和主要对局区域抢注意力。 */
    width: min(100%, calc(var(--board-size) + 594px));
    margin: 24px auto 0;
    color: #f4f4f4;
    font-size: 14px;
    line-height: 1.55;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

#engine-note p {
    margin: 0;
}

#engine-note .docs-entry {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

#engine-note .docs-entry a {
    color: #f7f7f7;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0;
    text-decoration: underline;
    text-underline-offset: 3px;
    text-shadow: none;
}

#engine-note .docs-entry a:hover {
    color: #ffffff;
}

#engine-note .docs-entry span {
    color: rgba(255, 255, 255, 0.68);
}

#engine-note .engine-tech {
    white-space: nowrap;
    font-size: 13px;
}

@media (max-width: 1180px) {
    /* 评分表无法和棋盘并排时，改为上下布局并限制表格高度。 */
    :root {
        --board-size: min(86vw, 720px);
        --board-frame-size: calc(var(--board-size) + 44px);
    }

    #game-layout {
        flex-direction: column;
        align-items: center;
    }

    #ai-panel {
        height: auto;
        max-height: none;
    }

    #ai-table-wrap {
        max-height: 280px;
    }

    #topbar {
        width: min(var(--board-size), calc(100vw - 32px));
    }
}

@media (max-width: 720px) {
    /* 手机端减少横向留白，说明文字允许换行。 */
    #app {
        width: calc(100vw - 20px);
        padding-top: 18px;
    }

    #controls {
        flex-direction: column;
    }

    #engine-note .engine-tech {
        white-space: normal;
    }
}
