* {
    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;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    background: white;
    border-radius: 20px;
    padding: 40px;
    max-width: 600px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 30px;
    font-size: 2em;
}

h2 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.2em;
}

.input-section {
    margin-bottom: 30px;
}

.input-section label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 600;
}

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

.input-section input:focus {
    outline: none;
    border-color: #667eea;
}

.mode-section {
    margin-bottom: 30px;
}

.mode-option {
    display: block;
    margin-bottom: 15px;
    cursor: pointer;
}

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

.mode-card {
    padding: 20px;
    border: 2px solid #ddd;
    border-radius: 12px;
    transition: all 0.3s;
}

.mode-option input[type="radio"]:checked + .mode-card {
    border-color: #667eea;
    background: #f0f4ff;
}

.mode-card h3 {
    color: #667eea;
    margin-bottom: 8px;
}

.mode-card p {
    color: #666;
    font-size: 14px;
}

.btn {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-bottom: 10px;
}

.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-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

/* ゲーム画面用 */
.game-container {
    text-align: center;
}

.game-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
}

.question-number {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.timer {
    font-size: 18px;
    font-weight: 600;
    color: #667eea;
}

.timer.warning {
    color: #e74c3c;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.numbers-area {
    margin-bottom: 30px;
}

.numbers-area h3,
.operators-area h3,
.formula-area h3 {
    white-space: nowrap;
    margin-bottom: 10px;
}

.number-card {
    display: inline-block;
    width: 70px;
    height: 70px;
    line-height: 70px;
    margin: 5px;
    background: #667eea;
    color: white;
    font-size: 32px;
    font-weight: bold;
    border-radius: 10px;
    cursor: move;
    user-select: none;
    transition: all 0.3s;
}

.number-card:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.number-card.dragging {
    opacity: 0.5;
}

.operators-area {
    margin-bottom: 30px;
}

.operator-card {
    display: inline-block;
    width: 60px;
    height: 60px;
    line-height: 60px;
    margin: 5px;
    background: #764ba2;
    color: white;
    font-size: 28px;
    font-weight: bold;
    border-radius: 10px;
    cursor: move;
    user-select: none;
    transition: all 0.3s;
}

.operator-card:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(118, 75, 162, 0.4);
}

.formula-area {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
    min-height: 100px;
}

.formula-area h3 {
    text-align: center;
    margin-bottom: 15px;
}

#formulaSlots {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
}

.formula-slot {
    display: inline-block;
    width: 60px;
    height: 60px;
    line-height: 60px;
    margin: 5px;
    border: 2px dashed #ccc;
    border-radius: 8px;
    font-size: 28px;
    font-weight: bold;
    background: white;
}

.formula-slot.filled {
    border: 2px solid #667eea;
    background: #f0f4ff;
}

.operator-slot {
    display: inline-block;
    width: 40px;
    height: 40px;
    line-height: 40px;
    margin: 5px;
    border: 2px dashed #ccc;
    border-radius: 50%;
    font-size: 24px;
    background: white;
}

.operator-slot.filled {
    border: 2px solid #764ba2;
    background: #f5f0ff;
}

.result-display {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 20px;
    color: #333;
}

.result-display.correct {
    color: #27ae60;
}

.game-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr 2fr;
    gap: 10px;
}

.game-buttons .btn {
    width: 100%;
}

/* 判定モード用 */
.judge-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

.judge-btn {
    padding: 20px;
    font-size: 20px;
}

#giveUpBtnJudge {
    padding: 12px;
    font-size: 16px;
}

/* フィードバック */
.feedback {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 80px;
    font-weight: bold;
    z-index: 1000;
    animation: fadeInOut 1s;
}

.feedback.correct {
    color: #27ae60;
}

.feedback.incorrect {
    color: #e74c3c;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* 結果画面用 */
.result-summary {
    margin-bottom: 30px;
}

.result-info {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.result-info p {
    margin: 8px 0;
    font-size: 16px;
    color: #333;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.stat-item {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    color: white;
}

.stat-label {
    font-size: 14px;
    margin-bottom: 8px;
    opacity: 0.9;
}

.stat-value {
    font-size: 28px;
    font-weight: bold;
}

.question-details {
    margin-bottom: 30px;
}

.question-details h2 {
    margin-bottom: 15px;
}

.question-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
}

.question-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.question-status {
    font-size: 24px;
    font-weight: bold;
    width: 30px;
}

.question-status.correct {
    color: #27ae60;
}

.question-status.incorrect {
    color: #e74c3c;
}

.question-number {
    font-weight: 600;
    color: #333;
}

.question-numbers {
    color: #667eea;
    font-weight: 600;
}

.question-time {
    margin-left: auto;
    color: #666;
}

.question-score {
    color: #764ba2;
    font-weight: 600;
}

.question-detail {
    font-size: 14px;
    color: #666;
    padding-left: 40px;
}

.result-buttons {
    display: flex;
    gap: 10px;
}

.result-buttons .btn {
    flex: 1;
}

/* 履歴画面用 */
.history-controls {
    margin-bottom: 20px;
}

.filter-section {
    margin-bottom: 15px;
}

.filter-section label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 600;
}

.filter-options {
    display: flex;
    gap: 15px;
}

.filter-options label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

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

.history-item {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 15px;
}

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

.history-date {
    font-size: 14px;
    color: #666;
}

.history-mode {
    background: #667eea;
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
}

.history-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.history-stat {
    text-align: center;
}

.history-stat-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.history-stat-value {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.history-actions {
    text-align: center;
}

.btn-small {
    padding: 8px 20px;
    font-size: 14px;
}

.empty-message {
    text-align: center;
    padding: 40px;
    color: #999;
}

/* レスポンシブ対応 */
@media (max-width: 600px) {
    .container {
        padding: 20px;
    }

    h1 {
        font-size: 1.5em;
    }

    .number-card {
        width: 50px;
        height: 50px;
        line-height: 50px;
        font-size: 24px;
        margin: 3px;
    }

    .operator-card {
        width: 45px;
        height: 45px;
        line-height: 45px;
        font-size: 20px;
        margin: 3px;
    }

    .formula-slot {
        width: 45px;
        height: 45px;
        line-height: 45px;
        font-size: 20px;
        margin: 2px;
    }

    .operator-slot {
        width: 30px;
        height: 30px;
        line-height: 30px;
        font-size: 18px;
        margin: 2px;
    }

    .formula-area {
        padding: 15px 5px;
    }

    .result-stats {
        grid-template-columns: 1fr;
    }

    .history-stats {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 400px) {
    .number-card {
        width: 45px;
        height: 45px;
        line-height: 45px;
        font-size: 20px;
        margin: 2px;
    }

    .operator-card {
        width: 40px;
        height: 40px;
        line-height: 40px;
        font-size: 18px;
        margin: 2px;
    }

    .formula-slot {
        width: 40px;
        height: 40px;
        line-height: 40px;
        font-size: 18px;
        margin: 1px;
    }

    .operator-slot {
        width: 25px;
        height: 25px;
        line-height: 25px;
        font-size: 16px;
        margin: 1px;
    }
}
