/* ========================================
   基本設定（必須）
   ======================================== */

/* html/bodyは必ず100%とoverflow:hiddenを指定 */
html {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    /* スマホでのダブルタップズーム防止 */
    touch-action: manipulation;
}

body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Noto Sans JP', sans-serif;
    background-color: #1a1a2e;
    /* スマホでのスクロール防止 */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   ゲームコンテナ
   ======================================== */

.game-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #a8e063 0%, #56ab2f 100%);
    position: relative;
}

/* ========================================
   キャンバス
   ======================================== */

#gameCanvas {
    display: block;
    width: 800px;
    height: 600px;
    background-color: #87ceeb;
    border: 3px solid #333;
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    cursor: pointer;
    /* スマホでのタッチ操作最適化 */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* ========================================
   UI オーバーレイ
   ======================================== */

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ヘッダー情報 */
#game-header {
    width: 800px;
    max-width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 0 0 10px 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#timer, #score {
    font-size: 24px;
    font-weight: bold;
    color: #333;
}

/* 吹き出し */
#speech-bubble {
    position: absolute;
    top: 130px;
    background: white;
    border: 3px solid #333;
    border-radius: 20px;
    padding: 15px 25px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    transition: opacity 0.3s ease, left 0.3s ease, right 0.3s ease;
}

#speech-bubble.hidden {
    opacity: 0;
    visibility: hidden;
}

/* 左配置（しっぽは右下） */
#speech-bubble.position-left {
    left: 20px;
}

#speech-bubble.position-left::after {
    content: '';
    position: absolute;
    bottom: -20px;
    right: 30px;
    width: 0;
    height: 0;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-top: 20px solid white;
}

#speech-bubble.position-left::before {
    content: '';
    position: absolute;
    bottom: -23px;
    right: 27px;
    width: 0;
    height: 0;
    border-left: 23px solid transparent;
    border-right: 23px solid transparent;
    border-top: 23px solid #333;
}

/* 右配置（しっぽは左下） */
#speech-bubble.position-right {
    right: 20px;
}

#speech-bubble.position-right::after {
    content: '';
    position: absolute;
    bottom: -20px;
    left: 30px;
    width: 0;
    height: 0;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-top: 20px solid white;
}

#speech-bubble.position-right::before {
    content: '';
    position: absolute;
    bottom: -23px;
    left: 27px;
    width: 0;
    height: 0;
    border-left: 23px solid transparent;
    border-right: 23px solid transparent;
    border-top: 23px solid #333;
}

#speech-text {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    white-space: nowrap;
    min-width: 200px;
    text-align: center;
}

/* ========================================
   レスポンシブ対応（タブレット）
   ======================================== */

@media (max-width: 1024px) {
    #gameCanvas {
        width: 700px;
        height: 525px;
    }

    #game-header {
        width: 700px;
    }

    #timer, #score {
        font-size: 20px;
    }

    #speech-text {
        font-size: 20px;
    }
}

/* ========================================
   レスポンシブ対応（スマホ縦向き）
   ======================================== */

@media (max-width: 768px) and (orientation: portrait) {
    .game-container {
        align-items: flex-start;
    }

    #gameCanvas {
        width: 100%;
        height: 100%;
        border: none;
        max-width: 100%;
        max-height: 100%;
    }

    #game-header {
        width: 100%;
        padding: 10px 15px;
        border-radius: 0;
        background: rgba(255, 255, 255, 0.95);
    }

    #timer, #score {
        font-size: 18px;
        font-weight: bold;
    }

    #speech-bubble {
        top: 80px;
        padding: 12px 20px;
        border-width: 4px;
    }

    #speech-text {
        font-size: 20px;
        font-weight: bold;
        min-width: 150px;
    }
}

/* ========================================
   レスポンシブ対応（スマホ横向き）
   ======================================== */

@media (max-width: 768px) and (orientation: landscape) {
    .game-container {
        align-items: center;
    }

    #gameCanvas {
        width: auto;
        height: 100%;
        border: none;
        max-width: 100%;
        max-height: 100%;
    }

    #game-header {
        width: 100%;
        padding: 8px 12px;
        border-radius: 0;
        background: rgba(255, 255, 255, 0.95);
    }

    #timer, #score {
        font-size: 16px;
        font-weight: bold;
    }

    #speech-bubble {
        top: 70px;
        padding: 8px 15px;
        border-width: 3px;
    }

    #speech-text {
        font-size: 18px;
        font-weight: bold;
        min-width: 120px;
    }
}

/* ========================================
   ユーティリティクラス
   ======================================== */

.hidden {
    display: none !important;
}

/* アニメーション: バウンス効果 */
@keyframes bounce {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

.bounce {
    animation: bounce 0.4s ease;
}

/* アニメーション: フラッシュ効果 */
@keyframes flash {
    0%, 100% {
        background-color: transparent;
    }
    50% {
        background-color: rgba(255, 0, 0, 0.3);
    }
}

.flash {
    animation: flash 0.3s ease;
}
