/* ═══════════════════════════════════════════════════════════════
   ClapClap 2.0 本地模拟对战 样式
   对齐 v1 local.css，扩展多人布局 + 结算进度 + 决策区 + 速度层条
   ═══════════════════════════════════════════════════════════════ */

:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 3px 10px rgba(0, 0, 0, 0.06);
    --blue: #2563eb;
    --blue-bg: #dbeafe;
    --danger: #ef4444;
    --danger-dark: #991b1b;
    --status-bg: #eef2ff;
    --orange: #e67e22;
}

* { box-sizing: border-box; }

body {
    font-family: Arial, "Microsoft YaHei", sans-serif;
    margin: 0;
    padding: 10px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

.container { max-width: 1040px; margin: 0 auto; }

/* ── 顶部栏 ─────────────────────────────────── */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.title-box h1 { margin: 0 0 2px 0; font-size: 23px; line-height: 1.2; }
.title-box .sub { color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── 卡片 ───────────────────────────────────── */
.card {
    background: var(--card);
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 8px 0; font-size: 17px; }
.status-card { padding-top: 8px; padding-bottom: 8px; }

/* ── 按钮 ───────────────────────────────────── */
button.action-btn, a.action-btn {
    border: none; border-radius: 10px; padding: 9px 12px;
    cursor: pointer; font-size: 13px; font-weight: bold;
    background: #e5e7eb; color: #111827;
    text-decoration: none; display: inline-block;
}
button.action-btn.primary, a.action-btn.primary { background: #2563eb; color: white; }
button.action-btn.danger, a.action-btn.danger { background: #ef4444; color: white; }
button.action-btn.secondary, a.action-btn.secondary { background: #6b7280; color: white; }
button.action-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.version-switch-btn {
    font-size: 11px; padding: 3px 10px;
    background: #fef3c7; border: 1px solid #f59e0b; color: #92400e;
    border-radius: 10px;
}

/* ── 消息 ───────────────────────────────────── */
.message-box { margin-top: 8px; color: #374151; min-height: 18px; font-size: 13px; }

/* ═══════════════════════════════════════════════
   准备阶段
   ═══════════════════════════════════════════════ */
.setup-card { text-align: center; }
.setup-card h2 { font-size: 20px; margin-bottom: 16px; }

.setup-controls {
    display: flex; flex-direction: column;
    align-items: center; gap: 20px;
}

.setup-count-row {
    display: flex; align-items: center; gap: 12px;
    background: #f8fafc; border-radius: 14px;
    padding: 10px 18px; border: 1px solid var(--border);
}
.setup-label { font-size: 14px; color: #4b5563; font-weight: bold; }
.setup-stepper-btn {
    width: 36px; height: 36px; padding: 0 !important;
    font-size: 20px !important; line-height: 1;
    border-radius: 10px !important;
    display: flex; align-items: center; justify-content: center;
    background: white !important; border: 1px solid #d1d5db !important;
    color: #374151 !important; transition: all 0.15s;
}
.setup-stepper-btn:hover {
    background: #eff6ff !important; border-color: #93c5fd !important;
    color: #2563eb !important;
}
.setup-count {
    font-size: 28px; font-weight: bold; min-width: 36px; text-align: center;
    color: #2563eb; font-variant-numeric: tabular-nums;
}

/* ── 玩家卡片网格 ──────────────────────────── */
.setup-players-grid {
    display: grid;
    gap: 12px;
    width: 100%; max-width: 680px;
}

/* 2人: 2列, 3人: 3列, 4人: 2x2, 5~6人: 3x2 */
.setup-player-card {
    background: #fafbfc;
    border: 2px solid #e5e7eb;
    border-radius: 14px;
    padding: 14px 12px 12px;
    display: flex; flex-direction: column;
    align-items: center; gap: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.setup-player-card:hover {
    border-color: #93c5fd;
    box-shadow: 0 3px 12px rgba(37,99,235,0.08);
}

.setup-player-avatar {
    width: 48px; height: 48px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: bold; color: #fff;
    box-shadow: 0 3px 10px rgba(0,0,0,0.12);
}
.setup-player-number {
    font-size: 12px; color: var(--muted); font-weight: bold;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.setup-player-card input {
    width: 100%; padding: 7px 10px;
    border: 1px solid #d1d5db;
    border-radius: 8px; font-size: 14px; text-align: center;
    background: white; transition: border-color 0.15s;
}
.setup-player-card input:focus {
    outline: none; border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* ── 开始按钮行 ────────────────────────────── */
.setup-start-row { margin-top: 4px; }
.setup-start-btn {
    padding: 13px 40px !important; font-size: 17px !important;
    border-radius: 14px !important;
    transition: transform 0.15s, box-shadow 0.15s !important;
}
.setup-start-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(37,99,235,0.2) !important;
}

.setup-hint {
    font-size: 12px; color: #9ca3af; line-height: 1.6;
    max-width: 480px;
}

/* ═══════════════════════════════════════════════
   状态栏（与 v1 一致）
   ═══════════════════════════════════════════════ */
.status-line { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.status-badge, .winner-badge, .turn-badge {
    display: inline-block; padding: 4px 9px; border-radius: 999px;
    font-weight: bold; font-size: 12px;
}
.status-badge { background: var(--status-bg); color: #3730a3; }
.winner-badge { background: #fee2e2; color: var(--danger-dark); }
.turn-badge {
    background: linear-gradient(180deg, #ecfdf5 0%, #d1fae5 100%);
    color: #166534; box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.12);
}

/* ═══════════════════════════════════════════════
   多列布局（替代 v1 的 .two-col，动态列数由 JS 设置）
   ═══════════════════════════════════════════════ */
.players-grid {
    display: grid;
    gap: 10px;
    margin-bottom: 10px;
}

/* ── 玩家资源卡片（与 v1 一致） ──────────────── */
.player-panel {
    border-radius: 10px;
    padding: 8px;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, #f9fafb 0%, #fafbfc 100%);
    cursor: pointer;
    transition: box-shadow 0.15s;
}
.player-panel:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.player-panel.focused { box-shadow: 0 0 0 2px var(--blue); }
.player-panel.dead { opacity: 0.45; pointer-events: none; }
.player-panel .player-name {
    font-weight: bold; font-size: 14px; margin-bottom: 4px;
    display: flex; align-items: center; gap: 6px;
}
.player-panel .player-status { font-size: 11px; color: var(--muted); margin-bottom: 6px; }

/* ── 资源网格（与 v1 完全一致） ──────────────── */
.resource-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
}
.resource-item {
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    min-height: 62px;
}
.resource-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.resource-value { font-size: 18px; font-weight: bold; line-height: 1.1; }

/* 资源颜色主题 — 与 v1 一致 */
.resource-item.theme-hp     { background: linear-gradient(180deg, #fff1f2 0%, #ffffff 100%); border-color: #fecdd3; }
.resource-item.theme-qi     { background: linear-gradient(180deg, #eff6ff 0%, #ffffff 100%); border-color: #bfdbfe; }
.resource-item.theme-shield { background: linear-gradient(180deg, #eef2ff 0%, #ffffff 100%); border-color: #c7d2fe; }
.resource-item.theme-spark  { background: linear-gradient(180deg, #fff7ed 0%, #ffffff 100%); border-color: #fdba74; }
.resource-item.theme-battery{ background: linear-gradient(180deg, #ecfeff 0%, #ffffff 100%); border-color: #a5f3fc; }
.resource-item.theme-pickaxe{ background: linear-gradient(180deg, #f3f4f6 0%, #ffffff 100%); border-color: #d1d5db; }
.resource-item.theme-flash  { background: linear-gradient(180deg, #faf5ff 0%, #ffffff 100%); border-color: #d8b4fe; }

/* ═══════════════════════════════════════════════
   动作选择区（与 v1 一致，多人时扩展列数）
   ═══════════════════════════════════════════════ */
.selection-layout {
    display: grid;
    gap: 10px;
    margin-bottom: 10px;
}
.move-side {
    border-radius: 12px;
    padding: 10px;
    border: 1px solid #edf2ff;
    background: linear-gradient(180deg, #f7fbff 0%, #ffffff 100%);
}
.move-side.focused { border-color: var(--blue); background: linear-gradient(180deg, #eff6ff 0%, #ffffff 100%); }
.move-side h3 {
    margin: 0 0 8px 0; font-size: 16px;
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.move-side .selector-selected {
    font-size: 11px; text-align: center; margin-bottom: 6px; min-height: 16px;
}
.active-turn-tip { font-size: 11px; color: var(--muted); font-weight: normal; }

.move-group-title {
    margin: 9px 0 5px 0; font-size: 12px;
    color: #4b5563; font-weight: bold;
}
.move-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 7px;
}
.move-btn-wrap { position: relative; }
.move-btn {
    width: 100%;
    border: 1px solid #d1d5db;
    background: white;
    border-radius: 11px;
    padding: 8px 6px;
    cursor: pointer;
    text-align: center;
    transition: 0.15s ease;
    font-size: 12px;
    min-height: 58px;
    position: relative;
    overflow: hidden;
}
.move-btn::after {
    content: "";
    position: absolute; inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.4), rgba(255,255,255,0));
    pointer-events: none;
}
.move-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,0.08); }
.move-btn.disabled { opacity: 0.38; cursor: not-allowed; background: #f3f4f6; }
.move-label { font-size: 14px; font-weight: bold; margin-bottom: 2px; line-height: 1.2; }
.move-name { font-size: 10px; color: var(--muted); line-height: 1.2; }
.move-hotkey {
    position: absolute; top: 5px; right: 6px;
    font-size: 10px; color: rgba(31,41,55,0.45);
    font-weight: bold; z-index: 2; pointer-events: none;
}

/* 选中状态 — 动态着色由 JS inline style 设置 */
.move-btn.selected {
    border-width: 2px; font-weight: bold;
    box-shadow: 0 4px 10px rgba(0,0,0,0.10);
}

/* ── 提交行 ─────────────────────────────────── */
.submit-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.auto-resolve-label {
    font-size: 12px; color: var(--muted); display: flex;
    align-items: center; gap: 4px; cursor: pointer; user-select: none;
}
.focused-label { font-size: 0.8em; color: #2563eb; margin-left: 8px; font-weight: bold; }

/* ── 选择信息行（与 v1 一致） ─────────────── */
.selection-info-row {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}
.selection-box {
    background: #f8fafc; border: 1px solid #e5e7eb;
    border-radius: 10px; padding: 8px 10px; font-size: 13px;
}

/* ═══════════════════════════════════════════════
   底部布局 — 与 v1 一致
   ═══════════════════════════════════════════════ */
.bottom-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.round-box {
    background: #f9fafb; border-radius: 10px; padding: 10px;
    line-height: 1.7; font-size: 13px; border: 1px solid #edf2f7;
}
.history-list {
    display: flex; flex-direction: column; gap: 8px;
    max-height: 300px; overflow-y: auto;
}
.history-item {
    background: #f9fafb; border-radius: 10px; padding: 10px;
    border: 1px solid var(--border); font-size: 13px; line-height: 1.7;
    cursor: default;
}
.history-item .hr-header { font-weight: bold; margin-bottom: 2px; }
.history-item .hr-detail { color: var(--muted); font-size: 11px; }

/* ═══════════════════════════════════════════════
   结算进度卡片（v2 新增，内联卡片）
   ═══════════════════════════════════════════════ */
#settlement-phase-label { font-size: 0.85em; color: var(--orange); margin-left: 8px; }
.phase-indicator { font-weight: bold; color: var(--blue); margin-bottom: 4px; font-size: 13px; }

/* 自动决策原因日志 */
.auto-decision-log {
    margin: 8px 0; max-height: 160px; overflow-y: auto;
    font-size: 12px; border: 1px solid #e5e7eb; border-radius: 8px;
    background: #fafbfc;
}
.auto-decision-log .ad-item {
    padding: 4px 10px; border-bottom: 1px solid #f0f0f0;
    color: #6b7280; line-height: 1.5;
}
.auto-decision-log .ad-item:last-child { border-bottom: none; }

/* 速度层进度条 */
.speed-layer-bar { display: flex; gap: 3px; margin: 8px 0; flex-wrap: wrap; }
.speed-layer-dot {
    width: 26px; height: 26px; border-radius: 5px; background: #e5e7eb;
    font-size: 10px; display: flex; align-items: center; justify-content: center;
    cursor: default; position: relative; font-weight: bold; color: #6b7280;
}
.speed-layer-dot.done { background: #86efac; color: #166534; }
.speed-layer-dot.current {
    background: var(--blue); color: #fff; font-weight: bold;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.2);
}
.speed-layer-tooltip {
    display: none; position: absolute; bottom: 32px; left: 50%;
    transform: translateX(-50%); background: #333; color: #fff;
    padding: 3px 8px; border-radius: 4px; font-size: 11px;
    white-space: nowrap; z-index: 10; pointer-events: none;
}
.speed-layer-dot:hover .speed-layer-tooltip { display: block; }

/* 事件流 */
.event-feed { max-height: 180px; overflow-y: auto; font-size: 12px; margin-top: 6px; }
.event-item { padding: 3px 6px; border-bottom: 1px solid #f0f0f0; line-height: 1.5; }
.event-item .ev-layer { color: var(--muted); margin-right: 4px; }
.event-item .ev-auto { color: #e67e22; font-size: 10px; margin-left: 4px; }

/* ═══════════════════════════════════════════════
   内联决策区（v2 新增）
   ═══════════════════════════════════════════════ */
.decision-heading {
    font-weight: bold; color: var(--orange); font-size: 16px;
    padding: 10px 12px; margin-top: 12px; margin-bottom: 8px;
    border-top: 2px solid #f59e0b;
    background: #fff8e1; border-radius: 6px;
}
.decision-prompt {
    font-size: 13px; margin-bottom: 8px; padding: 8px 12px;
    background: #fff3cd; border-radius: 6px; line-height: 1.5;
}
.decision-options { display: flex; flex-direction: column; gap: 4px; }
.decision-option {
    padding: 6px 10px; border: 2px solid var(--border);
    border-radius: 8px; cursor: pointer; font-size: 13px;
    transition: border-color 0.1s, background 0.1s;
}
.decision-option:hover { border-color: var(--blue); background: #f0f4ff; }
.decision-option.selected { border-color: var(--blue); background: var(--blue-bg); }
.decision-option.invalid { opacity: 0.4; cursor: not-allowed; }
.decision-option .option-label { font-weight: bold; }
.decision-option .option-reason { font-size: 11px; color: var(--muted); }
.decision-segment {
    margin-bottom: 8px; padding: 6px;
    border: 1px solid var(--border); border-radius: 8px; background: #fafbfc;
}
.decision-segment .seg-title { font-weight: bold; font-size: 12px; margin-bottom: 4px; color: var(--blue); }

/* ═══════════════════════════════════════════════
   回合总结卡片（v2 新增，内联显示）与对局结束
   ═══════════════════════════════════════════════ */
.summary-section { margin-bottom: 10px; }
.summary-section h3 {
    font-size: 14px; margin: 0 0 6px 0;
    border-bottom: 1px solid var(--border); padding-bottom: 4px;
}
.summary-moves { display: flex; gap: 6px; flex-wrap: wrap; }
.summary-move-tag {
    padding: 2px 8px; border-radius: 4px;
    background: #eef2ff; font-size: 12px;
}
.summary-death {
    padding: 4px 8px; background: #fee2e2;
    border-radius: 4px; font-size: 12px; margin: 2px 0;
}
.summary-change { font-size: 12px; padding: 2px 0; }
.summary-change .chg-pos { color: #16a34a; }
.summary-change .chg-neg { color: #dc2626; }

/* 对局结束内联卡片 */
.end-inline-content { text-align: center; padding: 16px 0; }
.end-inline-content .big-result { font-size: 28px; font-weight: bold; margin: 6px 0; }
.end-inline-content .rank-list { font-size: 14px; color: var(--muted); margin-top: 8px; line-height: 1.8; }

/* ═══════════════════════════════════════════════
   通用
   ═══════════════════════════════════════════════ */
.muted { color: var(--muted); }
.danger-text { color: #b91c1c; font-weight: bold; }
.good-text { color: #15803d; font-weight: bold; }

/* ═══════════════════════════════════════════════
   弹窗（与 v1 完全一致）
   ═══════════════════════════════════════════════ */
.modal-mask {
    position: fixed; inset: 0; background: rgba(0,0,0,0.35);
    display: none; align-items: center; justify-content: center;
    padding: 16px; z-index: 1000;
}
.modal-mask.show { display: flex; }
.modal {
    width: min(720px, 100%); max-height: 85vh; overflow-y: auto;
    background: white; border-radius: 14px; padding: 18px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.18);
}
.modal h2 { margin-top: 0; }
.modal-section { margin-bottom: 16px; line-height: 1.8; }
.modal-close-row { display: flex; justify-content: flex-end; margin-bottom: 8px; }

.modal-card {
    background: #fff; border-radius: 14px; padding: 24px 28px;
    max-width: 420px; width: 90%; box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
.modal-title { font-size: 16px; font-weight: bold; margin-bottom: 10px; }
.modal-body { font-size: 14px; line-height: 1.6; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

input[type="checkbox"] { transform: scale(1.12); }

/* ═══════════════════════════════════════════════
   响应式
   ═══════════════════════════════════════════════ */
@media (max-width: 900px) {
    .players-grid,
    .selection-layout,
    .bottom-layout,
    .selection-info-row {
        grid-template-columns: 1fr;
    }
    .speed-layer-dot { width: 22px; height: 22px; font-size: 9px; }
}
/* Step8: 结算日志折叠 */
.collapse-toggle-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 6px 10px;
    margin: 8px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--blue);
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}
.collapse-toggle-btn:hover { background: #dbeafe; }

.event-feed.collapsed {
    display: none;
}

/* v2_local 内联数据字段样式 */
.v2-setting-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

@media (max-width: 720px) {
    .resource-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .move-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .history-list { max-height: none; }
    .resource-value { font-size: 16px; }
}
@media (max-width: 520px) {
    .move-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
