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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.screen {
    display: none;
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.screen.active {
    display: block;
}

h1 {
    text-align: center;
    color: #5a67d8;
    margin-bottom: 30px;
    font-size: 2.5em;
}

h2 {
    color: #5a67d8;
    margin-bottom: 20px;
}

h3 {
    color: #4a5568;
    margin-bottom: 15px;
    font-size: 1.2em;
}

.setup-section {
    margin-bottom: 30px;
    padding: 20px;
    background: #f7fafc;
    border-radius: 10px;
}

.initial-amount-input {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.initial-amount-input-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.initial-amount-input input {
    flex: 1;
    padding: 10px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 16px;
    min-width: 0; /* 防止flex item溢出 */
}

.unit-toggle {
    display: inline-flex;
    flex-shrink: 0; /* 防止压缩 */
}

.toggle-container {
    display: inline-flex;
    background: #f7fafc;
    border-radius: 25px;
    padding: 4px;
    border: 2px solid #e2e8f0;
}

.toggle-option {
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #718096;
    transition: all 0.3s ease;
    min-width: 60px;
}

.toggle-option:hover {
    color: #4a5568;
}

.toggle-option.active {
    background: #5a67d8;
    color: white;
    box-shadow: 0 2px 4px rgba(90, 103, 216, 0.3);
}

.primary-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s;
}

.primary-btn:hover {
    transform: translateY(-2px);
}

.add-player {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.add-player input {
    flex: 1;
    padding: 10px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 16px;
}

.add-player button {
    background: #48bb78;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
}

.players-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.player-item {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-name {
    font-weight: bold;
    color: #2d3748;
}

.remove-player {
    background: #f56565;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
}

.game-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.game-controls button {
    background: #4299e1;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

.game-controls button:hover {
    background: #3182ce;
}

.players-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.player-card {
    background: white;
    border: 3px solid #e2e8f0;
    border-radius: 15px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.player-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    border-color: #667eea;
}

.player-card.dragging {
    opacity: 0.5;
    transform: scale(1.05);
    border-color: #f56565;
}

.player-card.drag-over {
    border-color: #48bb78;
    background: #f0fff4;
}

.player-rank {
    position: absolute;
    top: -10px;
    left: -10px;
    background: #f6ad55;
    color: white;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
}

.player-card .player-name {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 10px;
    color: #2d3748;
}

.player-amount {
    font-size: 24px;
    font-weight: bold;
    color: #5a67d8;
    margin-bottom: 5px;
}

.player-amount.negative {
    color: #f56565;
}

.game-history-section {
    margin-top: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
    border: 1px solid #e2e8f0;
}

.game-history-section h3 {
    color: #4a5568;
    margin-bottom: 15px;
    font-size: 18px;
    font-weight: bold;
}

.real-time-history {
    max-height: 300px;
    overflow-y: auto;
}

.real-time-history .log-entry {
    padding: 10px;
    margin-bottom: 8px;
    background: white;
    border-radius: 8px;
    border-left: 3px solid #667eea;
    font-size: 14px;
}

.real-time-history .log-time {
    font-size: 12px;
    color: #718096;
    margin-bottom: 4px;
    font-weight: 500;
}

.real-time-history .log-action {
    color: #2d3748;
    margin-bottom: 6px;
    font-weight: 500;
}

.real-time-history .log-balances {
    font-size: 12px;
    color: #4a5568;
}

.real-time-history .balance-item {
    color: #5a67d8;
    font-weight: 500;
}

.floating-actions {
    position: fixed;
    bottom: 20px;
    right: 20px;
}

.floating-actions button {
    background: #805ad5;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 15px;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: white;
    border-radius: 15px;
    padding: 0;
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header h3 {
    margin: 0;
    color: #2d3748;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #718096;
}

.modal-content {
    padding: 20px;
}

.amount-input-group {
    margin-bottom: 20px;
}

.amount-input-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
    margin-bottom: 10px;
}

.operation-toggle {
    margin-top: 10px;
    display: inline-flex;
    background: #f1f5f9;
    border-radius: 8px;
    padding: 2px;
    border: 1px solid #e2e8f0;
}

.amount-input-group label {
    display: block;
    margin-bottom: 5px;
    color: #4a5568;
}

.amount-input-group input {
    flex: 1;
    padding: 10px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 16px;
    min-width: 0; /* 防止flex item溢出 */
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.modal-buttons button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.modal-buttons .confirm {
    background: #48bb78;
    color: white;
}

.modal-buttons .cancel {
    background: #e2e8f0;
    color: #4a5568;
}

.history-section {
    margin-bottom: 20px;
}

.history-section h4 {
    color: #4a5568;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: bold;
}

.history-list {
    max-height: 200px;
    overflow-y: auto;
}

.game-log {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
    background: #f8f9fa;
}

.log-entry {
    padding: 8px;
    margin-bottom: 8px;
    background: white;
    border-radius: 6px;
    border-left: 3px solid #667eea;
}

.log-time {
    font-size: 12px;
    color: #718096;
    margin-bottom: 4px;
}

.log-action {
    font-size: 14px;
    color: #2d3748;
    margin-bottom: 6px;
    font-weight: 500;
}

.log-balances {
    font-size: 12px;
    color: #4a5568;
}

.balance-item {
    color: #5a67d8;
    font-weight: 500;
}

.history-item {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    cursor: pointer;
}

.history-item:hover {
    background: #f7fafc;
}

.history-date {
    font-size: 12px;
    color: #718096;
}

.history-players {
    font-weight: bold;
    color: #2d3748;
}

@media (max-width: 768px) {
    #app {
        padding: 10px;
    }

    .screen {
        padding: 20px;
    }

    h1 {
        font-size: 2em;
    }

    .game-header {
        flex-direction: column;
        text-align: center;
    }

    .players-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 15px;
    }

    .player-card {
        padding: 15px;
    }

    .player-amount {
        font-size: 20px;
    }

    /* 移动端金额输入优化 */
    .initial-amount-input-row {
        flex-direction: column;
        gap: 10px;
    }

    .initial-amount-input input {
        width: 100%;
    }

    .unit-toggle {
        width: 100%;
        justify-content: center;
    }

    .toggle-container {
        max-width: 200px;
        width: 100%;
    }

    .toggle-option {
        flex: 1;
        text-align: center;
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* 超小屏幕优化 */
@media (max-width: 480px) {
    .initial-amount-input input {
        font-size: 16px; /* 防止iOS缩放 */
        padding: 8px;
    }

    .toggle-option {
        font-size: 11px;
        padding: 5px 8px;
        min-width: 50px;
    }

    .toggle-container {
        padding: 3px;
    }

    /* 模态框移动端优化 */
    .amount-input-row {
        flex-direction: column;
        gap: 8px;
    }

    .amount-input-group input {
        width: 100%;
        font-size: 16px; /* 防止iOS缩放 */
        padding: 8px;
    }

    .unit-toggle {
        width: 100%;
        justify-content: center;
    }

    .modal {
        margin: 20px;
        max-width: calc(100vw - 40px);
    }

    .toggle-container {
        max-width: 180px;
        width: 100%;
    }

    .operation-toggle .toggle-container {
        max-width: 200px;
        width: 100%;
    }

    .operation-toggle .toggle-option {
        flex: 1;
        text-align: center;
        font-size: 11px;
        padding: 5px 8px;
    }
}

/* 语言切换样式 */
.language-toggle-container {
    text-align: center;
    margin-bottom: 20px;
}

.language-toggle {
    display: inline-flex;
    background: #f7fafc;
    border-radius: 25px;
    padding: 4px;
    border: 2px solid #e2e8f0;
}

.lang-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #718096;
    transition: all 0.3s ease;
    min-width: 60px;
}

.lang-btn:hover {
    color: #4a5568;
}

.lang-btn.active {
    background: #5a67d8;
    color: white;
    box-shadow: 0 2px 4px rgba(90, 103, 216, 0.3);
}

.game-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

/* 游戏界面的语言切换样式 */
.game-controls .language-toggle-container {
    margin: 0; /* 游戏界面中不需要额外的margin */
}

.game-controls .language-toggle {
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid #e2e8f0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(4px);
    /* 保持与设置界面相同的圆角 */
    border-radius: 25px;
    padding: 4px;
}

.game-controls .lang-btn {
    /* 继承基础样式，只调整需要变化的属性 */
    font-size: 13px;
    padding: 8px 16px; /* 保持与设置界面相同的内边距 */
    min-width: 60px; /* 保持与设置界面相同的最小宽度 */
    font-weight: 500;
    /* 确保圆角与设置界面一致 */
    border-radius: 20px;
    /* 未激活状态保持透明背景和灰色文字 */
    background: transparent;
    color: #718096;
    border: none;
}

.game-controls .lang-btn.active {
    background: #5a67d8;
    color: white;
    box-shadow: 0 2px 4px rgba(90, 103, 216, 0.3);
}

.game-controls .lang-btn:hover {
    color: #4a5568;
    background: transparent; /* 保持透明背景 */
}

.game-controls .lang-btn.active:hover {
    background: #5a67d8;
    color: white;
}

@media (max-width: 768px) {
    .game-controls {
        justify-content: center;
    }

    .language-toggle {
        transform: scale(0.9);
    }
}