/* ===== 斗地主记分器 - 移动端样式（移动优先） ===== */
:root {
    --orange: #ff6f00;
    --blue: #1565c0;
    --pink: #e91e63;
    --purple: #9c27b0;
    --green: #4caf50;
    --red: #f44336;
    --radius: 14px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', sans-serif;
    background: linear-gradient(160deg, #1b5e20 0%, #2e7d32 55%, #388e3c 100%);
    background-attachment: fixed;
    min-height: 100vh;
    color: #333;
    /* 为底部固定结算栏预留空间 */
    padding-bottom: calc(86px + var(--safe-bottom));
}

button {
    font-family: inherit;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    cursor: pointer;
}

/* 输入控件字号 >=16px，防止 iOS 聚焦自动缩放 */
select,
input {
    font-size: 16px;
    font-family: inherit;
}

/* ===== 顶部吸顶栏 ===== */
.m-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: calc(10px + var(--safe-top)) 14px 10px;
    background: rgba(20, 70, 25, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.m-header-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.m-title {
    font-size: 1.05rem;
    color: #fff;
    letter-spacing: 1px;
    white-space: nowrap;
}

.m-switch-link {
    color: rgba(255, 255, 255, 0.75);
    font-size: 12px;
    text-decoration: none;
    white-space: nowrap;
}

.m-switch-link:active {
    color: #fff;
}

.m-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.m-setting {
    display: flex;
    align-items: center;
    gap: 6px;
}

.m-setting label {
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.m-setting select {
    padding: 6px 8px;
    border: none;
    border-radius: 8px;
    background: #fff;
    font-size: 15px;
    font-weight: 600;
}

.m-round {
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.18);
    padding: 6px 10px;
    border-radius: 20px;
}

/* ===== 主容器 ===== */
.m-container {
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    padding: 12px;
}

/* ===== 当前倍数横幅 ===== */
.current-multiplier-display {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(135deg, #fff3e0, #ffe0b2);
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    border: 2px solid var(--orange);
    margin-bottom: 12px;
}

.multiplier-number {
    font-size: 18px;
    font-weight: 800;
    color: var(--orange);
}

.multiplier-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--orange);
}

/* ===== 玩家卡片（纵向堆叠，行内布局） ===== */
.players-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.player-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
    border-top: 4px solid var(--green);
}

.player-card.landlord {
    border-top-color: var(--orange);
}

.player-card.farmer {
    border-top-color: var(--blue);
}

.player-top {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-name {
    flex: 1;
    min-width: 0;
    font-size: 16px;
    font-weight: 600;
    padding: 8px;
    border-radius: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    user-select: none;
}

.player-name::before {
    content: '✏️ ';
    font-size: 11px;
    opacity: 0.5;
}

.player-name:active {
    background: #f5f5f5;
}

.player-name-editing {
    background: #e8f5e9 !important;
    outline: 2px solid var(--green);
}

.player-score {
    font-size: 1.9rem;
    font-weight: 800;
    min-width: 70px;
    text-align: right;
    transition: all 0.3s ease;
}

.score-positive { color: var(--green); }
.score-negative { color: var(--red); }
.score-zero { color: #666; }

.player-mid {
    margin: 4px 0 2px;
}

.player-role {
    display: inline-block;
    font-size: 13px;
    font-weight: 700;
    padding: 3px 12px;
    border-radius: 20px;
}

.role-landlord {
    background: #fff3e0;
    color: var(--orange);
}

.role-farmer {
    background: #e3f2fd;
    color: var(--blue);
}

.role-none {
    background: #f5f5f5;
    color: #999;
}

/* 角色/抢地主/加倍按钮：2x2 网格，大触控目标 */
.player-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 8px;
}

.btn-role,
.btn-extra {
    min-height: 44px;
    padding: 10px 8px;
    border: 2px solid #ddd;
    border-radius: 10px;
    background: #fff;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.btn-role:active,
.btn-extra:active {
    opacity: 0.8;
}

.btn-landlord.active {
    background: var(--orange);
    color: #fff;
    border-color: var(--orange);
}

.btn-farmer.active {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}

.btn-steal {
    border-color: var(--orange);
    color: var(--orange);
}

.btn-steal.active {
    background: var(--orange);
    color: #fff;
}

.btn-double {
    border-color: var(--pink);
    color: var(--pink);
}

.btn-double.active {
    background: var(--pink);
    color: #fff;
}

.btn-steal:disabled,
.btn-double:disabled {
    opacity: 0.4;
}

/* ===== 随机选地主 ===== */
.random-btn {
    text-align: center;
    margin-bottom: 12px;
}

.btn-random {
    width: 100%;
    min-height: 44px;
    padding: 10px;
    border: 2px dashed rgba(255, 255, 255, 0.8);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
}

.btn-random:active {
    background: rgba(255, 255, 255, 0.3);
}

/* ===== 操作面板 ===== */
.actions-panel {
    background: rgba(255, 255, 255, 0.97);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
}

.actions-panel label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 14px;
}

.bid-group,
.spring-group,
.bomb-group {
    margin-bottom: 14px;
}

.bomb-group {
    margin-bottom: 0;
}

.bid-buttons,
.spring-buttons {
    display: flex;
    gap: 8px;
}

.btn-bid {
    flex: 1;
    min-height: 48px;
    border: 2px solid var(--purple);
    border-radius: 10px;
    background: #fff;
    color: var(--purple);
    font-size: 17px;
    font-weight: 700;
    transition: background 0.15s, color 0.15s;
}

.btn-bid.active {
    background: var(--purple);
    color: #fff;
}

.btn-spring {
    flex: 1;
    min-height: 44px;
    padding: 8px 4px;
    border: 2px solid var(--green);
    border-radius: 10px;
    background: #fff;
    color: var(--green);
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

.btn-spring.active {
    background: var(--green);
    color: #fff;
}

.btn-spring[data-spring="landlord"].active {
    background: var(--orange);
    border-color: var(--orange);
}

.btn-spring[data-spring="farmer"].active {
    background: var(--blue);
    border-color: var(--blue);
}

/* 炸弹/明牌步进器 */
.bomb-controls-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}

.bomb-count-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px;
    background: #f7faf7;
    border: 1px solid #e3ece3;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
}

.stepper {
    display: flex;
    align-items: center;
    gap: 14px;
}

.btn-bomb-decrease,
.btn-bomb-increase {
    width: 44px;
    height: 44px;
    border: 2px solid var(--green);
    border-radius: 10px;
    background: #fff;
    color: var(--green);
    font-size: 22px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}

.btn-bomb-decrease:active,
.btn-bomb-increase:active {
    background: var(--green);
    color: #fff;
}

.bomb-count {
    min-width: 32px;
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    color: var(--orange);
}

.btn-bomb {
    width: 100%;
    min-height: 44px;
    border: 2px solid var(--orange);
    border-radius: 10px;
    background: #fff;
    color: var(--orange);
    font-size: 15px;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

.btn-bomb.active {
    background: var(--orange);
    color: #fff;
}

/* ===== 历史记录 ===== */
.history-panel {
    background: rgba(255, 255, 255, 0.97);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.history-header h3 {
    font-size: 16px;
}

.btn-export {
    min-height: 36px;
    padding: 6px 14px;
    border: 2px solid var(--green);
    border-radius: 8px;
    background: #fff;
    color: var(--green);
    font-size: 13px;
    font-weight: 600;
}

.btn-export:active {
    background: var(--green);
    color: #fff;
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.history-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    padding: 10px 4px;
    border-bottom: 1px solid #eee;
}

.history-item:last-child {
    border-bottom: none;
}

.history-round {
    font-weight: 700;
    color: #666;
    min-width: 36px;
    font-size: 13px;
}

.history-detail {
    flex: 1 1 calc(100% - 44px);
    font-size: 12px;
    color: #333;
    line-height: 1.5;
    word-break: break-all;
}

.history-scores {
    flex: 1 1 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
}

.history-score-change {
    padding: 2px 8px;
    border-radius: 4px;
}

.change-positive {
    background: #e8f5e9;
    color: var(--green);
}

.change-negative {
    background: #ffebee;
    color: var(--red);
}

.change-zero {
    background: #f5f5f5;
    color: #999;
}

.history-empty {
    text-align: center;
    padding: 24px;
    color: #999;
    font-size: 14px;
}

/* ===== 辅助操作按钮 ===== */
.footer-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.footer-actions button {
    flex: 1;
    min-height: 44px;
    padding: 10px 4px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    transition: opacity 0.15s;
}

.footer-actions button:active {
    opacity: 0.85;
}

.btn-secondary {
    border: 2px solid rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.btn-danger {
    border: 2px solid var(--red);
    background: rgba(244, 67, 54, 0.25);
    color: #fff;
}

/* ===== 底部固定结算栏 ===== */
.result-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: flex;
    gap: 10px;
    max-width: 560px;
    margin: 0 auto;
    padding: 10px 14px calc(10px + var(--safe-bottom));
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.18);
}

.btn-result {
    flex: 1;
    min-height: 52px;
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    transition: opacity 0.15s, transform 0.15s;
}

.btn-result:active:not(:disabled) {
    transform: scale(0.97);
}

.btn-landlord-win {
    background: linear-gradient(135deg, #ff6f00, #ffa000);
}

.btn-farmer-win {
    background: linear-gradient(135deg, #1565c0, #42a5f5);
}

.btn-result:disabled {
    opacity: 0.45;
}

/* ===== 姓名编辑输入框 ===== */
.name-edit-input {
    display: block;
    flex: 1;
    width: 100%;
    padding: 8px;
    border: 2px solid var(--green);
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    box-sizing: border-box;
    outline: none;
}

.name-edit-input[hidden] {
    display: none;
}

/* ===== 积分变化动画 ===== */
@keyframes scoreChange {
    0% { transform: scale(1); }
    50% { transform: scale(1.25); }
    100% { transform: scale(1); }
}

.score-animate {
    animation: scoreChange 0.5s ease;
}

/* ===== 横屏 / 平板适配 ===== */
@media (min-width: 600px) {
    .players-section {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .player-top {
        flex-direction: column;
        gap: 4px;
    }

    .player-score {
        text-align: center;
        min-width: 0;
    }
}
