/* ========================================
   基本スタイル
   ======================================== */

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', 'メイリオ', Meiryo, sans-serif;
}

body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ========================================
   画面管理
   ======================================== */

.screen {
    display: none;
    width: 100%;
    height: 100%;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.screen.active {
    display: flex;
}

.screen-content {
    max-width: 800px;
    width: 100%;
    text-align: center;
}

/* ========================================
   スタート画面
   ======================================== */

.game-title {
    font-size: 3em;
    margin-bottom: 10px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
    animation: titleGlow 2s ease-in-out infinite;
}

@keyframes titleGlow {
    0%, 100% { text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5); }
    50% { text-shadow: 0 0 20px rgba(255, 255, 255, 0.8), 3px 3px 6px rgba(0, 0, 0, 0.5); }
}

.game-subtitle {
    font-size: 1.2em;
    margin-bottom: 30px;
    opacity: 0.9;
}

.how-to-play {
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 30px;
    text-align: left;
}

.how-to-play h3 {
    margin-bottom: 15px;
    font-size: 1.3em;
}

.how-to-play ul {
    list-style: none;
    padding-left: 0;
}

.how-to-play li {
    padding: 8px 0;
    padding-left: 25px;
    position: relative;
}

.how-to-play li::before {
    content: '▶';
    position: absolute;
    left: 0;
    color: #ffd43b;
}

/* ========================================
   ボタン
   ======================================== */

.game-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: 3px solid rgba(255, 255, 255, 0.5);
    padding: 15px 40px;
    font-size: 1.2em;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    font-weight: bold;
}

.game-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    border-color: #ffd43b;
}

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

.game-btn-secondary {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.button-group {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ========================================
   ジャンル選択画面
   ======================================== */

.section-title {
    font-size: 2em;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    max-width: 900px;
    margin: 0 auto;
}

.category-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    padding: 30px 20px;
    font-size: 1.1em;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
}

.category-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: #ffd43b;
    transform: scale(1.05);
}

.category-btn:active {
    transform: scale(0.98);
}

/* ========================================
   ゲーム画面
   ======================================== */

#game-screen {
    padding: 10px;
}

.back-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    padding: 10px 20px;
    font-size: 0.9em;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 100;
}

.back-btn:hover {
    background: rgba(0, 0, 0, 0.5);
    border-color: #ffd43b;
    transform: translateX(-3px);
}

.game-hud {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 15px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hud-label {
    font-size: 0.9em;
    opacity: 0.8;
    margin-bottom: 5px;
}

.hud-value {
    font-size: 1.5em;
    font-weight: bold;
}

/* ========================================
   パネルグリッド
   ======================================== */

.panel-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    max-width: 600px;
    margin: 0 auto;
}

.panel {
    aspect-ratio: 1;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.1) 100%);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8em;
    padding: 5px;
    text-align: center;
    overflow: hidden;
    position: relative;
}

.panel:hover:not(.cleared) {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0.2) 100%);
    border-color: #ffd43b;
    transform: scale(1.05);
}

.panel.cleared {
    background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
    border-color: #4caf50;
    cursor: default;
    animation: panelClear 0.5s ease-out;
}

@keyframes panelClear {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

.panel.cleared::after {
    content: '✓';
    position: absolute;
    font-size: 2.5em;
    color: #fff;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

/* ========================================
   モーダル
   ======================================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    padding: 30px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

/* ========================================
   問題モーダル
   ======================================== */

.question-timer {
    text-align: center;
    font-size: 1.5em;
    margin-bottom: 20px;
    font-weight: bold;
}

.question-text {
    font-size: 1.3em;
    margin-bottom: 25px;
    line-height: 1.6;
}

.choices-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.choice-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    padding: 20px;
    font-size: 1.1em;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
}

.choice-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: #ffd43b;
    transform: translateX(5px);
}

.choice-btn:active {
    transform: translateX(0);
}

.choice-btn.correct {
    background: rgba(76, 175, 80, 0.5);
    border-color: #4caf50;
}

.choice-btn.incorrect {
    background: rgba(244, 67, 54, 0.5);
    border-color: #f44336;
}

/* ========================================
   結果モーダル
   ======================================== */

.result-content {
    text-align: center;
}

.result-icon {
    font-size: 4em;
    margin-bottom: 15px;
}

.result-title {
    font-size: 2em;
    margin-bottom: 10px;
}

.result-score {
    font-size: 1.3em;
    margin-bottom: 20px;
    color: #ffd43b;
}

.explanation-box {
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    text-align: left;
}

.explanation-box h4 {
    margin-bottom: 10px;
    font-size: 1.2em;
}

.explanation-box p {
    line-height: 1.6;
}

/* ========================================
   ゲームオーバー画面
   ======================================== */

#gameover-screen {
    overflow-y: auto;
    align-items: center;
    padding: 20px 0;
}

.final-score-box {
    background: rgba(0, 0, 0, 0.3);
    border: 3px solid #ffd43b;
    border-radius: 20px;
    padding: 30px;
    margin-bottom: 30px;
}

.final-score-label {
    font-size: 1.2em;
    margin-bottom: 10px;
    opacity: 0.9;
}

.final-score-value {
    font-size: 4em;
    font-weight: bold;
    color: #ffd43b;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
}

.game-summary {
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 30px;
}

.summary-title {
    font-size: 1.5em;
    margin-bottom: 20px;
}

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

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
}

.summary-label {
    font-size: 1em;
}

.summary-value {
    font-size: 1.3em;
    font-weight: bold;
    color: #ffd43b;
}

/* ========================================
   正解時の吹き出し演出
   ======================================== */

.celebration-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4em;
    font-weight: bold;
    color: #ffd43b;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
    z-index: 2000;
    pointer-events: none;
    opacity: 0;
}

.celebration-popup.show {
    animation: celebrationBounce 1s ease-out;
}

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

/* ========================================
   レスポンシブ
   ======================================== */

@media (max-width: 600px) {
    .game-title {
        font-size: 2em;
    }

    .panel-grid {
        gap: 5px;
    }

    .panel {
        font-size: 0.6em;
    }

    .final-score-value {
        font-size: 3em;
    }

    .category-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .celebration-popup {
        font-size: 3em;
    }

    .back-btn {
        font-size: 0.8em;
        padding: 8px 15px;
    }
}
