/* 全局样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --blue: #3b82f6;
    --blue-dark: #1d4ed8;
    --blue-light: #dbeafe;
    --red: #ef4444;
    --red-dark: #b91c1c;
    --red-light: #fee2e2;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #1f2937;
    --gray: #6b7280;
    --gray-light: #f3f4f6;
    --white: #ffffff;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-lg: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 12px 24px;
    color: var(--dark);
}

/* 游戏主容器 */
.game-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* ========== 头部样式 ========== */
.game-header {
    text-align: center;
    color: white;
    margin-bottom: 16px;
}

.game-header h1 {
    font-size: 2em;
    margin-bottom: 8px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.subtitle {
    font-size: 1em;
    opacity: 0.9;
}

/* ========== 游戏控制面板 ========== */
.control-panel {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 2px solid rgba(255,255,255,0.2);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 16px 32px;
    font-size: 1.1em;
    min-height: 56px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--success), #16a34a);
    color: white;
}

.btn-warning {
    background: linear-gradient(135deg, var(--warning), #d97706);
    color: white;
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), #dc2626);
    color: white;
}

.btn-secondary {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    color: white;
}

.btn-icon { font-size: 1.3em; }

/* ========== 计分板 ========== */
.score-board {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    border-radius: var(--radius-lg);
    padding: 16px 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-lg);
}

.team-score {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.team-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.team-score.red .team-info {
    align-items: flex-end;
}

.team-icon {
    font-size: 2.2em;
}

.team-name {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--gray);
}

.score-number {
    font-size: 2.2em;
    font-weight: 800;
    line-height: 1;
}

.timer-section {
    text-align: center;
    padding: 0 24px;
}

.timer-label {
    font-size: 0.75em;
    color: var(--gray);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.timer-display {
    font-size: 2em;
    font-weight: 700;
    color: var(--dark);
    font-family: 'SF Mono', 'Courier New', monospace;
    background: var(--gray-light);
    padding: 6px 16px;
    border-radius: 8px;
    min-width: 100px;
}

.timer-display.warning {
    color: var(--warning);
    animation: pulse 1s infinite;
}

.timer-display.danger {
    color: var(--danger);
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* ========== 拔河可视化区域 ========== */
.tug-war-section {
    background: white;
    border-radius: var(--radius-lg);
    padding: 16px 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-lg);
}

.tug-war-track {
    position: relative;
    height: 70px;
    background: linear-gradient(to bottom, #e5e7eb, #f3f4f6);
    border-radius: 40px;
    overflow: hidden;
    border: 3px solid #d1d5db;
}

/* 赛道标记 */
.track-markers {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 10%;
    pointer-events: none;
}

.marker {
    width: 2px;
    height: 100%;
    background: rgba(0,0,0,0.1);
}

.marker.center {
    background: rgba(0,0,0,0.2);
    width: 3px;
}

/* 终点线 */
.finish-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 10%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
}

.finish-line.left {
    left: 0;
    background: linear-gradient(to right, rgba(59,130,246,0.2), transparent);
    border-radius: 37px 0 0 37px;
}

.finish-line.right {
    right: 0;
    background: linear-gradient(to left, rgba(239,68,68,0.2), transparent);
    border-radius: 0 37px 37px 0;
}

/* 绳子 - 固定不动 */
.rope-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 20px;
}

.rope {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 8px;
    background: linear-gradient(to right, #3b82f6 0%, #8b4513 30%, #a0522d 50%, #8b4513 70%, #ef4444 100%);
    border-radius: 4px;
}

.rope-knot {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3em;
    box-shadow: var(--shadow-lg);
    border: 3px solid white;
    z-index: 10;
    transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.rope-knot.blue-advantage {
    background: linear-gradient(135deg, var(--blue), var(--blue-dark));
    transform: translate(-50%, -50%) scale(1.1);
}

.rope-knot.red-advantage {
    background: linear-gradient(135deg, var(--red), var(--red-dark));
    transform: translate(-50%, -50%) scale(1.1);
}

/* 进度提示 */
.progress-hint {
    text-align: center;
    margin-top: 12px;
    padding: 10px 16px;
    background: var(--gray-light);
    border-radius: var(--radius);
    font-size: 1em;
    font-weight: 500;
    color: var(--gray);
    transition: all 0.3s ease;
}

.progress-hint.blue-leading {
    background: var(--blue-light);
    color: var(--blue-dark);
}

.progress-hint.red-leading {
    background: var(--red-light);
    color: var(--red-dark);
}

.progress-hint.blue-win {
    background: var(--blue);
    color: white;
}

.progress-hint.red-win {
    background: var(--red);
    color: white;
}

/* ========== 对战区域 ========== */
.battle-area {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 16px;
    margin-bottom: 12px;
    flex: 1;
}

/* VS 分隔 */
.vs-divider {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.vs-badge {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    font-weight: 800;
    color: white;
    box-shadow: var(--shadow-lg);
}

.vs-text {
    font-size: 0.75em;
    font-weight: 600;
    color: var(--gray);
    text-transform: uppercase;
}

/* 玩家区域 */
.player-zone {
    background: white;
    border-radius: var(--radius-lg);
    padding: 12px;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.player-zone.blue-zone {
    border: 3px solid transparent;
}

.player-zone.red-zone {
    border: 3px solid transparent;
}

.player-zone.blue-zone.active {
    border-color: var(--blue);
    box-shadow: 0 0 0 4px var(--blue-light), var(--shadow-xl);
}

.player-zone.red-zone.active {
    border-color: var(--red);
    box-shadow: 0 0 0 4px var(--red-light), var(--shadow-xl);
}

.zone-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--gray-light);
}

.zone-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1em;
    font-weight: 700;
}

.zone-title .icon {
    font-size: 1.3em;
}

.zone-title.blue { color: var(--blue); }
.zone-title.red { color: var(--red); }

.zone-status {
    font-size: 0.75em;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--gray-light);
    color: var(--gray);
    font-weight: 600;
}

.zone-status.playing {
    background: var(--success);
    color: white;
}

/* 题目卡片 */
.question-card {
    background: linear-gradient(135deg, #f9fafb, #f3f4f6);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
    text-align: center;
}

.question-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 1.8em;
    font-weight: 700;
}

.question-display .num {
    color: var(--dark);
    min-width: 50px;
}

.question-display .op {
    color: var(--success);
    font-weight: 800;
}

.question-display .eq {
    color: var(--gray);
}

.answer-box {
    min-width: 56px;
    height: 44px;
    background: white;
    border: 3px solid var(--gray-light);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dark);
    font-size: 1.1em;
    transition: all 0.2s ease;
}

.answer-box.filled {
    border-color: var(--blue);
    background: var(--blue);
    color: white;
}

.answer-box.correct {
    border-color: var(--success);
    background: var(--success);
    color: white;
    animation: correctPop 0.4s ease;
}

.answer-box.wrong {
    border-color: var(--danger);
    background: var(--danger);
    color: white;
    animation: shake 0.4s ease;
}

@keyframes correctPop {
    0% { transform: scale(0.8); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

/* 数字键盘 */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 0;
}

.numkey {
    height: 82px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6em;
    font-weight: 700;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.numkey:hover {
    background: var(--gray-light);
    border-color: var(--blue);
    transform: scale(1.05);
}

.numkey:active {
    transform: scale(0.95);
}

/* 底部一行：0、跳过、← 同样大小 */
.numkey.zero,
.numkey.func-skip,
.numkey.func-back {
    height: 82px;
    grid-column: span 1;
}

.numkey.func-skip {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    color: white;
    border-color: transparent;
    font-size: 0.85em;
}

.numkey.func-back {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: white;
    border-color: transparent;
}

/* 操作按钮 */
.zone-actions {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.action-btn {
    padding: 10px;
    font-size: 0.9em;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.action-btn.submit {
    background: linear-gradient(135deg, var(--success), #16a34a);
    color: white;
}

.action-btn.skip {
    background: var(--gray-light);
    color: var(--gray);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* 反馈区域 */
.feedback-area {
    min-height: 32px;
    padding: 6px 8px;
    margin-top: 8px;
    border-radius: var(--radius);
    text-align: center;
    font-weight: 600;
    font-size: 0.85em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.feedback-area.correct {
    background: #dcfce7;
    color: #166534;
}

.feedback-area.incorrect {
    background: #fee2e2;
    color: #991b1b;
}

/* ========== 游戏规则 ========== */
.game-rules {
    background: white;
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    box-shadow: var(--shadow-lg);
}

.game-rules h3 {
    margin-bottom: 8px;
    color: var(--dark);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1em;
}

.rules-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.rule-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px;
    background: var(--gray-light);
    border-radius: var(--radius);
}

.rule-item .icon {
    font-size: 1.3em;
    flex-shrink: 0;
}

.rule-item .content {
    flex: 1;
}

.rule-item .title {
    font-weight: 600;
    font-size: 0.85em;
    color: var(--dark);
    margin-bottom: 2px;
}

.rule-item .desc {
    font-size: 0.75em;
    color: var(--gray);
}

/* ========== 结果弹窗 ========== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.modal-overlay.show {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    margin-bottom: 20px;
}

.modal-header h2 {
    font-size: 1.8em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.final-result {
    font-size: 1.1em;
    margin-bottom: 20px;
    padding: 16px;
    border-radius: var(--radius);
    font-weight: 500;
}

.final-result.win {
    background: #dcfce7;
    color: #166534;
}

.final-result.lose {
    background: #fee2e2;
    color: #991b1b;
}

.final-result.draw {
    background: #fef3c7;
    color: #92400e;
}

.score-comparison {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    margin-bottom: 24px;
    padding: 16px;
    background: var(--gray-light);
    border-radius: var(--radius);
}

.final-team {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.final-team .icon {
    font-size: 2.5em;
}

.final-team .score {
    font-size: 2em;
    font-weight: 800;
}

.final-team.blue { color: var(--blue); }
.final-team.red { color: var(--red); }

.vs-divider-modal {
    font-size: 1em;
    font-weight: 700;
    color: var(--gray);
}

/* ========== 设置弹窗样式 ========== */
.settings-content {
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.setting-group {
    text-align: left;
}

.setting-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1em;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 12px;
}

.setting-icon {
    font-size: 1.2em;
}

.setting-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-card {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--gray-light);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.option-card:hover {
    background: #e5e7eb;
}

.option-card input[type="radio"] {
    display: none;
}

.option-card input[type="radio"]:checked + .option-content {
    color: var(--blue);
}

.option-card input[type="radio"]:checked ~ .option-content,
.option-card:has(input[type="radio"]:checked) {
    background: var(--blue-light);
    border-color: var(--blue);
}

.option-content {
    display: flex;
    flex-direction: column;
    margin-left: 8px;
    flex: 1;
}

.option-title {
    font-weight: 600;
    font-size: 0.95em;
}

.option-desc {
    font-size: 0.8em;
    color: var(--gray);
    margin-top: 2px;
}

/* 时间选择芯片 */
.time-options {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.time-chip {
    flex: 1;
    min-width: 70px;
}

.time-chip input[type="radio"] {
    display: none;
}

.time-chip span {
    display: block;
    padding: 10px 16px;
    background: var(--gray-light);
    border-radius: var(--radius);
    text-align: center;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.time-chip:hover span {
    background: #e5e7eb;
}

.time-chip input[type="radio"]:checked + span {
    background: var(--blue);
    color: white;
    border-color: var(--blue-dark);
}

/* ========== 响应式设计 ========== */
@media (max-width: 768px) {
    body {
        padding: 12px;
    }
    
    .game-header h1 {
        font-size: 1.5em;
    }
    
    .score-board {
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .timer-section {
        order: -1;
        width: 100%;
        padding: 0;
    }
    
    .timer-display {
        font-size: 1.6em;
        min-width: 80px;
    }
    
    .battle-area {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .vs-divider {
        display: none;
    }
    
    .question-display {
        font-size: 1.6em;
    }
    
    .rules-grid {
        grid-template-columns: 1fr;
    }
    
    .control-panel {
        flex-wrap: wrap;
    }
    
    .btn {
        padding: 8px 16px;
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    .game-header h1 {
        font-size: 1.3em;
    }
    
    .question-display {
        font-size: 1.4em;
        gap: 6px;
    }
    
    .answer-box {
        min-width: 50px;
        height: 40px;
    }
    
    .numkey {
        font-size: 1.1em;
    }
    
    .zone-actions {
        grid-template-columns: 1fr;
    }
    
    .tug-war-track {
        height: 60px;
    }
    
    .rope-knot {
        width: 36px;
        height: 36px;
        font-size: 1em;
    }
}
