:root {
    --bg-color: #0d1117;
    --panel-bg: rgba(22, 27, 34, 0.7);
    --border-color: #30363d;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --accent-blue: #58a6ff;
    --accent-green: #2ea043;
    --accent-red: #da3633;
}

body {
    margin: 0;
    padding: 20px;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, sans-serif;
    min-height: 100vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

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

h1 { margin: 0; font-size: 24px; }
h2 { margin-top: 0; font-size: 18px; color: #fff; }
.subtitle { color: var(--text-secondary); font-size: 13px; margin-bottom: 20px; }

.metrics { display: flex; gap: 20px; }

.metric-box {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.metric-box .label { font-size: 12px; color: var(--text-secondary); }
.metric-box .value { font-size: 24px; font-weight: 800; font-family: 'JetBrains Mono', monospace; }
.metric-box .highlight { color: var(--accent-red); transition: color 0.3s; }

.main-container {
    display: flex;
    gap: 20px;
    flex: 1;
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.left-panel { flex: 1.2; overflow: hidden; }
.right-panel { flex: 0.8; }

/* 表格样式 */
.table-container {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

th {
    position: sticky;
    top: 0;
    background: #161b22;
    padding: 10px;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
}

td {
    padding: 8px 10px;
    border-bottom: 1px solid #21262d;
    color: var(--text-primary);
}

.td-name { color: var(--accent-blue); font-weight: bold; cursor: pointer; }
.td-name:hover { text-decoration: underline; }
.td-grad { color: var(--accent-red); }
.td-shape { color: var(--accent-green); }

/* 展开的矩阵表格 */
.expanded-row td { padding: 0; border: none; background: #000; }
.matrix-container {
    max-height: 250px;
    overflow: auto;
    padding: 10px;
    background: #0a0e12;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}
.matrix-table {
    width: auto;
    border-collapse: collapse;
    margin: 0 auto;
}
.matrix-table td {
    padding: 3px 6px;
    font-size: 10px;
    border: 1px solid #21262d;
    text-align: right;
    color: #8b949e;
}
.matrix-table td.pos { color: #58a6ff; }
.matrix-table td.neg { color: #da3633; }

.trace-matrix-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

/* 输入框 */
.target-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px 0 40px 0;
}

.custom-input {
    background: #000;
    border: 2px solid var(--border-color);
    color: #fff;
    font-family: 'JetBrains Mono', monospace;
    font-size: 36px;
    font-weight: 800;
    padding: 10px 20px;
    border-radius: 8px;
    text-align: center;
    width: 300px;
    outline: none;
    transition: border-color 0.3s;
}

.custom-input:focus { border-color: var(--accent-blue); }

.completion-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 36px;
    font-weight: 800;
    color: var(--accent-green);
    margin-left: 10px;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

/* 柱状图双列 */
.charts-wrapper { display: flex; gap: 20px; flex: 1; }
.chart-col { flex: 1; display: flex; flex-direction: column; }
.col-title { font-size: 14px; color: var(--text-secondary); text-align: center; margin-bottom: 10px; font-weight: normal; }
.chart-container { flex: 1; display: flex; flex-direction: column; gap: 6px; }

.prob-row { display: flex; align-items: center; gap: 10px; }

.prob-label {
    width: 35px; text-align: center; font-family: 'JetBrains Mono', monospace;
    font-weight: bold; background: #30363d; border-radius: 4px; padding: 2px 0; font-size: 12px;
}

.prob-bar-container { flex: 1; height: 18px; background: #000; border-radius: 4px; overflow: hidden; }
.prob-bar { height: 100%; background: var(--text-secondary); width: 0%; transition: width 0.3s ease; }
.prob-value { width: 45px; font-family: 'JetBrains Mono', monospace; font-size: 12px; text-align: right; }

/* 控件 */
.controls { display: flex; gap: 15px; }
.top-controls { margin: 0; padding: 0; border: none; align-items: center; }
.spacer { flex: 1; }
.btn { padding: 10px 20px; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; transition: 0.2s; }
.btn:active { transform: scale(0.96); }
.btn:hover { filter: brightness(1.2); }
.btn-primary { background: #1f6feb; color: white; }
.btn-success { background: #238636; color: white; }
.btn-danger { background: transparent; border: 1px solid #da3633; color: #da3633; }
.btn-warning { background: #d29922; color: white; }

/* ── 窄屏适配 ────────────────────────────────────────────────────────────────
   原样式是纯桌面两栏 flex，没有任何媒体查询：在手机上 .main-container 不换行，
   左栏被压成一条几十像素宽的竖条，文字逐字竖排完全不可读。
   这里让两栏在 ≤900px 时改为上下堆叠，并把宽表格交给横向滚动而不是压缩列宽。
   ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    body { padding: 14px; }

    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
        margin-bottom: 16px;
        padding-bottom: 16px;
    }
    h1 { font-size: 19px; line-height: 1.3; }

    /* 按钮排成可换行的一行，触摸目标不缩小 */
    .controls { flex-wrap: wrap; gap: 10px; }
    .btn { padding: 10px 14px; font-size: 13px; }
    .spacer { display: none; }          /* 竖排下撑开间距会把按钮推出屏幕 */

    .metrics { flex-wrap: wrap; gap: 10px; }
    .metric-box { flex: 1 1 130px; padding: 8px 12px; }
    .metric-box .value { font-size: 20px; }

    /* 核心修复：两栏改上下堆叠，不再互相挤压 */
    .main-container { flex-direction: column; gap: 14px; }
    /* min-width:0 必需：flex 子项默认 min-width:auto，会被内部宽表格顶出容器 */
    .left-panel, .right-panel { flex: none; width: auto; min-width: 0; }
    .panel { padding: 14px; min-width: 0; }

    /* 参数表有 6 列，窄屏靠横向滚动看全，不靠压缩 */
    .left-panel { overflow: visible; }
    .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; max-height: 60vh; }
    /* 只给参数表撑最小宽度。写成裸 table 会连右栏 Project Overview 的配置表
       一起套上，而那张表外面没有滚动容器，会直接撑破面板。 */
    .table-container > table { min-width: 460px; }
    /* 右栏正文里的表格反过来要能缩，长值允许断行 */
    .right-panel table { width: 100%; table-layout: fixed; }
    .right-panel td, .right-panel th { word-break: break-word; }

    /* 推理行：输入框原本写死 300px + 36px 字号 + 两个按钮挤在不换行的 flex 里，
       会整体冲出面板。改成可换行，输入框占满一行。 */
    .target-container { flex-wrap: wrap; gap: 8px; margin: 16px 0 24px 0; }
    .custom-input { width: 100%; box-sizing: border-box; font-size: 30px; padding: 8px 12px; }
    .completion-text { font-size: 30px; margin-left: 0; }
    /* 这两个按钮的 margin-left 写在 HTML 行内样式里，只能用 !important 覆盖 */
    #btn-trace, #btn-3d { margin-left: 0 !important; }

    /* 两列概率条并排在窄屏还读得动，收窄间距即可 */
    .charts-wrapper { gap: 10px; }
    .prob-row { gap: 6px; }
}
