/* 首页操作简化 + 布局自适应 + 结果区行数控制。

   权重说明：styles.css 里存在 `body.layout-grid .container`（权重 0,2,1）
   和 `@media` 内的 `.container` 规则，会覆盖本页布局。
   布局下拉已移除，body 不再有 layout-* class，但 styles.css 的规则仍在，
   所以这里统一用 `body .container` 压过它，确保新布局生效。 */

body .container {
    display: grid;
    /* 左右两栏等宽（原来 5:7 左窄右宽，按需求改为一致） */
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "play result";
    gap: 20px;
    height: auto;
    max-width: 1600px;
    /* stretch：两栏拉伸到同一行高 → 左右框体等高。
       （原来 start 会让两栏各自随内容，左栏比右栏矮一大截） */
    align-items: stretch;
}

.play-panel {
    grid-area: play;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 0;
}

.result-panel {
    grid-area: result;
    min-width: 0;
}

/* ★ 关键修正：styles.css 里残留的旧布局规则
     `#result-area { grid-column: 2; grid-row: 2; }`
   权重是 ID（1,0,0），会压过上面 `.result-panel` 的 `grid-area: result`（0,1,0）。
   结果：桌面端结果区被丢进「隐式第 2 行」，于是整体下移、与左侧交互区错位。
   这里用同为 ID 选择器但权重更高的 `body #result-area`（1,0,1）压回去，
   让它按 `grid-template-areas: "play result"` 自动定位（同一行的第 2 列）。
   注意：必须放在所有 @media 之外，且不写死行列，手机/平板端才能继续用各自的 areas 布局。 */
body #result-area {
    grid-area: result;
}

/* 平板及以下：两区改为上下 */
@media (max-width: 992px) {
    body .container {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto;
        grid-template-areas:
            "play"
            "result";
        gap: 15px;
    }
}

/* 手机版上下结构，两区等宽 */
@media (max-width: 768px) {
    body .container,
    body.layout-grid .container,
    body.layout-vertical .container {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "play"
            "result";
        gap: 15px;
        height: auto;
    }

    /* 手机端结果区占满整宽，不再受旧 grid-row 约束 */
    #result-area,
    body.layout-grid #result-area {
        grid-column: 1;
        grid-row: auto;
        min-height: 0;
    }
}

/* ---------- 玩法标签 ---------- */
.game-tabs {
    display: flex;
    gap: 8px;
    background: #fff;
    border-radius: 14px;
    padding: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .05);
}

.game-tab {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 10px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #666;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background .18s ease, color .18s ease, box-shadow .18s ease;
}

.game-tab:hover {
    background: #f2f5f9;
    color: #333;
}

.game-tab.active {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: #fff;
    box-shadow: 0 3px 10px rgba(231, 76, 60, .28);
}

.game-tab:focus-visible {
    outline: 2px solid #e74c3c;
    outline-offset: 2px;
}

/* 隐藏非当前玩法区。结果区在 .result-panel 里，不受影响。 */
.game-panel {
    display: none;
}

.game-panel.is-active {
    display: block;
    /* 左栏被拉伸到与结果区等高后，让当前玩法卡填满剩余高度，
       这样「左框体」的可视卡片边界也跟右框体一样高。 */
    flex: 1 1 auto;
}

/* ---------- 操作条 ---------- */
.mode-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.mode-row:first-of-type {
    margin-top: 0;
}

.mode-row .stepper {
    flex: 0 0 auto;
}

/* 单式行：随机按钮占满剩余空间 */
.btn-grow {
    flex: 1 1 auto;
    min-width: 110px;
}

/* 复式行：下拉均分剩余空间 */
.mode-row .complex-select {
    flex: 1 1 0;
    min-width: 92px;
}

/* 计算器按钮：放大成独立大号方形按钮，与生成按钮区分层次 */
.btn-icon-only {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    min-width: 52px;
    padding: 0;
    font-size: 22px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
}

.btn-icon-only i {
    font-size: 24px;
    line-height: 1;
}

/* ---------- 连买行 ---------- */
.subscribe-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
    padding: 8px 12px;
    background: #f7f9fc;
    border-radius: 10px;
}

.subscribe-row .checkbox-inline {
    margin: 0;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
}

.subscribe-row .complex-select-small {
    flex: 0 0 auto;
    min-width: 90px;
    width: auto;
    margin: 0;
}

/* 连买提示：说明随机/复式/手动都按连买处理 */
.subscribe-hint {
    font-size: 12px;
    color: #95a5a6;
    margin-left: auto;
}

/* 连买记录（期号待定）在结果区的标记 */
.sub-tag-pending {
    display: inline-block;
    background: linear-gradient(135deg, #95a5a6, #7f8c8d);
    color: #fff;
    padding: 2px 9px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    margin-left: 6px;
    letter-spacing: .5px;
    vertical-align: middle;
}

/* 待定期号的提示文案 */
.period-pending {
    color: #95a5a6;
    font-size: 12px;
    font-weight: 600;
    margin-left: 6px;
}

/* ---------- 组数步进器 ---------- */
.stepper {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: #f7f9fc;
    border: 1px solid #e3e8ef;
    border-radius: 10px;
    padding: 3px;
}

.stepper-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: #fff;
    color: #555;
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease, color .15s ease;
}

.stepper-btn:hover:not(:disabled) {
    background: #e74c3c;
    color: #fff;
}

.stepper-btn:disabled {
    opacity: .35;
    cursor: not-allowed;
}

.stepper-input {
    width: 44px;
    height: 32px;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    color: #333;
    -moz-appearance: textfield;
}

.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.stepper-input:focus {
    outline: none;
    color: #e74c3c;
}

.stepper-unit {
    font-size: 13px;
    color: #888;
    padding-right: 4px;
    font-weight: 700;
}

/* ---------- 手动选号面板 ---------- */
.manual-panel {
    margin-top: 14px;
    padding: 14px;
    background: #f8fafc;
    border: 1px solid #e3e8ef;
    border-radius: 12px;
}

.manual-panel[hidden] {
    display: none;
}

.manual-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.manual-title {
    font-size: 14px;
    font-weight: 800;
    color: #55606d;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 已选提示 */
.manual-picked {
    font-size: 12px;
    color: #8b95a1;
}

.manual-picked b {
    color: #2c3e50;
    font-weight: 800;
}

/* 复式提示 */
.manual-fushi {
    display: none;
    margin-top: 8px;
    padding: 7px 10px;
    background: #eaf7f0;
    border: 1px solid #a9dfc3;
    border-radius: 8px;
    color: #1e8449;
    font-size: 13px;
    font-weight: 700;
}

.manual-fushi.show {
    display: block;
}

/* 双区分组 */
.manual-zone {
    margin-bottom: 12px;
}

.manual-zone:last-child {
    margin-bottom: 0;
}

.manual-zone-label {
    font-size: 12px;
    font-weight: 700;
    color: #7f8c8d;
    margin-bottom: 7px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.manual-zone-count {
    color: #b0b8c1;
    font-weight: 600;
}

/* 号码网格：双色球 33 红 + 16 蓝 */
.manual-balls {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
    gap: 6px;
}

.mball {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    border: 2px solid transparent;
    background: #eef1f5;
    color: #7f8c8d;
    font-size: 13px;
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform .12s ease, background .15s ease, color .15s ease, box-shadow .15s ease;
}

.mball:hover {
    transform: scale(1.1);
}

/* 未点亮 */
.mball.red-ball.off,
.mball.blue-ball.off {
    background: #eef1f5;
    color: #95a5a6;
}

/* 点亮 */
.mball.red-ball.on {
    background: linear-gradient(145deg, #e74c3c, #c0392b);
    color: #fff;
    box-shadow: 0 3px 8px rgba(231, 76, 60, .35);
}

.mball.blue-ball.on {
    background: linear-gradient(145deg, #3498db, #2980b9);
    color: #fff;
    box-shadow: 0 3px 8px rgba(52, 152, 219, .35);
}

.mball.kl8-ball.on {
    background: linear-gradient(145deg, #f39c12, #e67e22);
    color: #fff;
    box-shadow: 0 3px 8px rgba(243, 156, 18, .35);
}

/* ---------- 快乐8：上方选 N 标签 ---------- */
.kl8-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.kl8-tag {
    min-width: 34px;
    height: 30px;
    padding: 0 10px;
    border: 1px solid #dfe5ec;
    border-radius: 999px;
    background: #fff;
    color: #7f8c8d;
    font-size: 12px;
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s ease;
}

.kl8-tag:hover {
    border-color: #f39c12;
    color: #e67e22;
}

.kl8-tag.active {
    background: linear-gradient(135deg, #f39c12, #e67e22);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 3px 8px rgba(243, 156, 18, .3);
}

/* ---------- 手动选号操作条 ---------- */
.manual-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed #dfe5ec;
}

.manual-btn {
    flex: 1 1 auto;
    min-width: 96px;
    padding: 11px 16px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: filter .15s ease, opacity .15s ease;
}

.manual-btn:hover {
    filter: brightness(1.05);
}

.manual-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
    filter: none;
}

.manual-btn-add {
    background: linear-gradient(135deg, #34495e, #2c3e50);
    color: #fff;
}

.manual-btn-clear {
    background: #fff;
    border: 1px solid #dfe5ec;
    color: #7f8c8d;
}

.manual-btn-toggle {
    background: #fff;
    border: 1px solid #dfe5ec;
    color: #55606d;
}

/* ---------- 玩法区的「手动选号」入口按钮 ---------- */
.manual-entry {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 11px;
    background: #fff;
    border: 1px dashed #cfd8e3;
    border-radius: 10px;
    color: #7f8c8d;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all .16s ease;
}

.manual-entry:hover {
    border-color: #e74c3c;
    color: #e74c3c;
    background: #fff8f7;
}

.manual-entry.active {
    border-style: solid;
    border-color: #e74c3c;
    color: #e74c3c;
    background: #fff8f7;
}

/* 保留原生 select 供 app.js 读取，但不在界面上显示 */
.visually-hidden-select {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- 组合提示 ---------- */
.combo-hint {
    color: #999;
    font-size: 12px;
    margin-top: 6px;
}

/* ---------- 空状态快捷入口 ---------- */
.empty-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 18px;
}

.empty-btn {
    padding: 9px 20px;
    border: 1px solid #e3e8ef;
    border-radius: 999px;
    background: #fff;
    color: #555;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all .16s ease;
}

.empty-btn:hover {
    border-color: #e74c3c;
    color: #e74c3c;
    transform: translateY(-1px);
}

/* ---------- 页脚 ---------- */
.site-footer {
    margin-top: 18px;
    padding: 14px;
    text-align: center;
    color: #999;
    font-size: 13px;
}

/* ---------- 结果区：行数控制 ----------
   要求：默认 5 行，超过自动加长，最多 20 行后滚动。
   原来 styles.css 的 .result-content 是 flex:1 + 高度被容器锁死，
   这里改为 flex:0 1 auto，让高度由内容驱动。 */

.result-panel .result-wrapper {
    min-height: 0;
}

.result-panel .result-content {
    flex: 0 1 auto;
    min-height: calc(var(--result-row-h, 92px) * 5);
    max-height: calc(var(--result-row-h, 92px) * 20);
    overflow-y: auto;
}

/* 窄屏单行可能换行，行高会变大 */
@media (max-width: 768px) {
    .result-panel .result-content {
        min-height: calc(var(--result-row-h, 108px) * 5);
        max-height: calc(var(--result-row-h, 108px) * 20);
    }

    /* 手机端结果区左侧竖条占空间，缩窄一点给内容腾地方 */
    .result-panel .result-left {
        width: 68px;
        min-width: 68px;
        padding: 10px 6px;
    }

    .result-panel .result-title-vertical {
        font-size: 15px;
        letter-spacing: 1px;
    }
}

/* 放大模式：结果区占满屏幕，取消行数限制 */
#result-area.fullscreen-mode .result-content {
    max-height: none;
}

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
    .game-tabs {
        gap: 4px;
        padding: 4px;
    }

    .game-tab {
        padding: 11px 4px;
        font-size: 13px;
        gap: 0;
    }

    .game-tab i {
        display: none;
    }

    .mode-row {
        gap: 8px;
    }

    .mode-row .complex-select {
        min-width: 80px;
    }

    .btn-grow {
        min-width: 0;
    }

    .stepper-input {
        width: 36px;
    }

    .stepper-btn {
        width: 30px;
        height: 30px;
    }

    .btn-icon-only {
        width: 46px;
        height: 46px;
        min-width: 46px;
        font-size: 20px;
    }

    .btn-icon-only i {
        font-size: 21px;
    }
}
