/* ===== 基本スタイル ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 0;
}

.container {
    max-width: 100%;
    margin: 0;
    background: white;
    border-radius: 0;
    padding: 16px;
    padding-bottom: 80px;
    min-height: 100vh;
}

/* ===== 画面管理 ===== */
.screen {
    display: none;
}

.screen.active {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

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

.hidden {
    display: none !important;
}

/* ===== タイトル ===== */
h1 {
    text-align: center;
    color: #333;
    margin-bottom: 24px;
    font-size: 28px;
    font-weight: 700;
}

h2 {
    color: #555;
    margin-bottom: 16px;
    font-size: 20px;
    font-weight: 700;
}

/* ===== セットアップ画面 ===== */
.setup-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    text-align: center;
}

.setup-section label {
    display: block;
    font-weight: 600;
    margin-bottom: 12px;
    color: #333;
    font-size: 16px;
}

.setup-section input {
    width: 100px;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #667eea;
    border-radius: 8px;
    text-align: center;
    margin-bottom: 16px;
}

#playerNamesSection {
    margin-top: 20px;
}

.player-name-input {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-direction: column;
}

.player-name-input input {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
}

.player-name-input label {
    width: 100%;
    padding: 12px;
    font-weight: 600;
    background: #e7f3ff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    font-size: 14px;
}

/* ===== ボタン ===== */
.btn {
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    margin-top: 12px;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

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

.btn-success {
    background: #48bb78;
    color: white;
}

.btn-success:hover {
    background: #38a169;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(72, 187, 120, 0.4);
}

.btn-danger {
    background: #f56565;
    color: white;
}

.btn-danger:hover {
    background: #e53e3e;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(245, 101, 101, 0.4);
}

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

/* ===== レート設定画面 ===== */
.rate-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
}

.rate-section label {
    display: block;
    font-weight: 600;
    margin-bottom: 12px;
    color: #333;
    font-size: 16px;
}

.rate-section input {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #667eea;
    border-radius: 8px;
    margin-bottom: 12px;
}

.info {
    background: #e7f3ff;
    padding: 12px;
    border-radius: 8px;
    color: #2c5282;
    font-size: 14px;
    margin-top: 12px;
}

/* ===== ゲーム画面 ===== */
.scores-display {
    background: #f0f7ff;
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 20px;
}

.scores-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.score-card {
    background: white;
    padding: 14px;
    border-radius: 10px;
    text-align: center;
    border: 2px solid #e2e8f0;
    transition: all 0.3s ease;
    cursor: pointer;
}

.score-card:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.score-card-name {
    font-weight: 600;
    color: #555;
    font-size: 14px;
    margin-bottom: 8px;
}

.score-card-value {
    font-size: 24px;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 4px;
}

.score-card-total {
    font-size: 12px;
    color: #999;
}

/* ===== 勝者選択 ===== */
.winner-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
}

.winner-buttons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.winner-btn {
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    background: #e7f3ff;
    color: #333;
    border: 2px solid #667eea;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.winner-btn:hover {
    background: #d0e8ff;
    transform: translateY(-2px);
}

.winner-btn.selected {
    background: #667eea;
    color: white;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

/* ===== スコア入力セクション ===== */
.input-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
}

.input-section > .info {
    margin-bottom: 16px;
    font-size: 13px;
}

.score-input-item {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
    background: white;
    padding: 14px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.score-input-item:last-of-type {
    margin-bottom: 12px;
}

.score-input-item label {
    width: 100%;
    font-weight: 700;
    color: #333;
    font-size: 14px;
}

.score-input-item input {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.score-input-item input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* ===== ゲーム操作 ===== */
.game-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.game-controls .btn {
    margin: 0;
}

#recordScoreBtn {
    margin-top: 12px;
}

/* ===== 結果画面 ===== */
.results-container {
    background: #f8f9fa;
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 20px;
}

.result-item {
    background: white;
    padding: 14px;
    border-radius: 8px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid #667eea;
}

.result-rank {
    font-size: 18px;
    margin-right: 10px;
    min-width: 32px;
    font-weight: 700;
}

.result-name {
    font-weight: 600;
    flex: 1;
    color: #333;
    font-size: 14px;
}

.result-score {
    text-align: right;
}

.result-total {
    font-size: 16px;
    font-weight: 700;
    color: #667eea;
}

.result-rate {
    font-size: 12px;
    color: #999;
}

/* ===== モーダル ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 15px;
    padding: 0;
    width: 95%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

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

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

.modal-header h2 {
    margin: 0;
    color: #333;
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 16px;
}

.modal-footer {
    padding: 16px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 12px;
}

.modal-footer .btn {
    margin: 0;
}

.game-history-list {
    list-style: none;
    padding: 0;
}

.game-history-item {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 4px solid #667eea;
}

.game-history-item-score {
    font-size: 20px;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 4px;
}

.game-history-item-detail {
    font-size: 12px;
    color: #999;
}

/* ===== レスポンシブデザイン ===== */
@media (min-width: 768px) {
    .container {
        max-width: 600px;
        margin: 16px auto;
        border-radius: 12px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
        padding: 24px;
        padding-bottom: 80px;
    }

    body {
        padding: 8px;
    }

    h1 {
        margin-bottom: 32px;
        font-size: 32px;
    }

    h2 {
        margin-bottom: 20px;
        font-size: 22px;
    }

    .player-name-input {
        flex-direction: row;
        gap: 12px;
        align-items: center;
    }

    .player-name-input input {
        width: auto;
        flex: 1;
    }

    .player-name-input label {
        width: auto;
        min-width: 100px;
    }

    .game-controls {
        flex-direction: row;
        gap: 12px;
    }

    .game-controls .btn {
        flex: 1;
    }

    .modal-content {
        width: 90%;
        max-width: 600px;
    }
}
