* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: #1a1a1a;
    color: #fff;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    position: fixed; /* iOS Safariのアドレスバー対策としてスクロールを完全に防ぐ */
    top: 0;
    left: 0;
}

/* 汎用非表示クラス */
.hidden {
    display: none !important;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: calc(100vh * 9 / 16); /* 画面の高さに応じて最大幅を動的計算（タブレット対応） */
    max-height: 100vh;
    aspect-ratio: 9 / 16;
    background-color: #ffe4b5; /* フォールバック */
    background-image: linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.05)), url('apple-orchard-background.webp');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    margin: 0 auto; /* 中央配置 */
}

@media (min-aspect-ratio: 9/16) {
    #game-container {
        height: 100%;
        width: auto;
    }
}

@media (max-aspect-ratio: 9/16) {
    #game-container {
        width: 100%;
        height: auto;
    }
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 10px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    z-index: 10;
}

.left-ui {
    display: flex;
    flex-direction: row; /* 横並びに変更して被りを軽減 */
    align-items: flex-start; /* 上揃えに戻す */
    gap: 8px;
    pointer-events: auto; /* ボタンをクリック可能にするため */
}

#score-board {
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.3); /* 枠線追加 */
    border-radius: 10px; /* 角丸統一 */
    padding: 6px 10px;
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    line-height: 1.3;
    display: flex;
    flex-direction: column; /* 2行に戻す */
    justify-content: center; /* 縦方向の中央揃え */
}

#next-box {
    background: rgba(0, 0, 0, 0.5); /* 背景色統一 */
    border: 2px solid rgba(255, 255, 255, 0.3); /* 枠線追加 */
    border-radius: 10px; /* 角丸統一 */
    padding: 4px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 14px;
    font-weight: bold;
    margin-top: -4px;
}



#next-preview {
    margin-top: 4px;
    width: 40px; /* リンゴのサイズを戻す */
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none; /* スマホのスワイプスクロール防止 */
}

/* スタート画面 */
#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 30;
    color: #fff;
    text-align: center;
}

#sound-toggle-btn {
    height: 29px; /* スコアボード(約58px)の半分に設定 */
    padding: 0 8px;
    border-radius: 6px; /* 角丸も少し小さく調整 */
    background-color: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.3);
    font-size: 14px; /* ネクスト・スコアに合わせて少し大きく */
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 10;
    transition: background-color 0.2s, transform 0.1s;
}

#sound-toggle-btn:active {
    transform: scale(0.9);
}

#sound-toggle-btn.muted {
    background-color: rgba(255, 50, 50, 0.5);
}

#start-screen h1 {
    font-size: 28px;
    margin-bottom: 10px;
    color: #ff9933;
    display: inline-block; /* ブロック自体の幅を中身に合わせる */
    text-align: left; /* 中身のテキストは左揃えにする */
}

#start-screen p {
    font-size: 16px;
    margin-bottom: 30px;
    color: #ccc;
}

/* モード選択UI */
.mode-selection {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 25px;
}

.mode-btn {
    padding: 10px 20px;
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    background-color: #555;
    border: 3px solid transparent;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Hiragino Maru Gothic ProN', 'M PLUS Rounded 1c', sans-serif;
}

.mode-btn:hover {
    background-color: #666;
}

/* 選択されたモード */
.mode-btn.selected {
    background-color: #ff3366; /* 少し目立つ色 */
    border: 3px solid #fff;
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(255, 51, 102, 0.4);
}

#btn-hard-mode.selected {
    background-color: #9900cc; /* HARD用にもう少しダークな色に */
    box-shadow: 0 4px 10px rgba(153, 0, 204, 0.4);
}

#start-button {
    padding: 15px 40px;
    font-size: 22px;
    font-weight: bold;
    color: #fff;
    background-color: #33ccff;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
}

#start-button:active:not(:disabled) {
    transform: scale(0.95);
}

#start-button:hover:not(:disabled) {
    background-color: #00bfff;
}

#start-button:disabled {
    background-color: #888;
    cursor: not-allowed;
    transform: none;
}

.line-share-btn {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: bold;
    color: #ccc;
    background-color: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    cursor: pointer;
    margin-top: 20px;
    margin-bottom: 10px;
    transition: all 0.2s ease;
    font-family: 'Hiragino Maru Gothic ProN', 'M PLUS Rounded 1c', sans-serif;
}

.line-share-btn:hover {
    background-color: rgba(0, 195, 0, 0.15);
    border-color: #00c300;
    color: #fff;
}

#start-screen.hidden {
    display: none;
}

/* ゲームオーバー画面 */
#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
    color: #fff;
}

#game-over-screen.hidden {
    display: none;
}

#game-over-screen h1 {
    font-size: 36px;
    margin-bottom: 20px;
    color: #ff4d4d;
}

#game-over-screen .best-score {
    font-size: 20px;
    margin-bottom: 5px;
}

#new-best-notice {
    color: #ffd700; /* ゴールド */
    font-size: 24px;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
    margin-bottom: 20px;
    animation: newBestPulse 1.5s infinite alternate;
}

@keyframes newBestPulse {
    from { transform: scale(1); opacity: 0.8; }
    to { transform: scale(1.1); opacity: 1; }
}

.final-score, .best-score {
    font-size: 24px;
    margin-bottom: 10px;
}

#retry-button {
    margin-top: 30px;
    padding: 12px 32px;
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    background-color: #ff8c00;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
}

#retry-button:active {
    transform: scale(0.95);
}

#retry-button:hover {
    background-color: #ffa500;
}

/* ランキングUI */
#ranking-container {
    width: 100%;
    margin-top: 20px;
    margin-bottom: 20px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 10px;
    padding: 15px;
    text-align: center;
}

#ranking-loading, #ranking-error {
    font-size: 14px;
    color: #ccc;
}

.highlight-text {
    color: #ffcc00;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 5px;
    animation: flash 1.5s infinite alternate;
}

@keyframes flash {
    0% { opacity: 1; text-shadow: 0 0 10px #ffcc00; }
    100% { opacity: 0.8; text-shadow: 0 0 5px #ffcc00; }
}

#ranking-input-section input {
    width: 80%;
    padding: 10px;
    margin-top: 10px;
    border: 2px solid #ccc;
    border-radius: 5px;
    font-size: 16px;
    text-align: center;
}

#submit-score-button {
    margin-top: 10px;
    padding: 10px 20px;
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    background-color: #32cd32;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
}

#submit-score-button:disabled {
    background-color: #777;
    cursor: not-allowed;
    transform: none;
}

#submit-score-button:active:not(:disabled) {
    transform: scale(0.95);
}

.ranking-tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

.ranking-tab {
    background-color: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: none;
    padding: 8px 24px;
    border-radius: 20px;
    font-size: 16px;
    font-weight: normal;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.ranking-tab:hover {
    background-color: rgba(255, 255, 255, 0.4);
}

.ranking-tab.active {
    background-color: #ffdf00;
    color: #333;
    font-weight: bold;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

#ranking-list {
    list-style: none;
    padding: 0;
    margin: 0;
    text-align: left;
    display: inline-block;
    width: 100%;
}

#ranking-list li {
    display: flex;
    justify-content: space-between;
    padding: 5px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 16px;
    font-family: monospace;
}

#ranking-list li:last-child {
    border-bottom: none;
}

#ranking-list li.current-player {
    background: rgba(255, 215, 0, 0.3);
    font-weight: bold;
    border-radius: 5px;
}

/* スコアポップアップアニメーション */
.score-popup {
    position: absolute;
    /* 日本語対応の丸ゴシック系フォントを指定 */
    font-family: 'Hiragino Maru Gothic ProN', 'ヒラギノ丸ゴ ProN W4', 'M PLUS Rounded 1c', 'YuRounded', 'Arial Rounded MT Bold', sans-serif;
    font-weight: 900;
    
    /* 黄金のグラデーション */
    background: linear-gradient(180deg, #ffffff 0%, #ffea00 40%, #ff8c00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    
    /* グラデーションテキスト用の影（text-shadowではなくdrop-shadowを使用） */
    filter: drop-shadow(0px 4px 2px rgba(0,0,0,0.5)) drop-shadow(0px 0px 4px rgba(255,100,0,0.8));
    
    pointer-events: none;
    z-index: 50;
    transform-origin: center center;
    
    /* 跳ねるようなイージング関数 */
    animation: popupAnim 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popupAnim {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-15deg); }
    15% { opacity: 1; transform: translate(-50%, -50%) scale(1.5) rotate(5deg); }
    35% { opacity: 1; transform: translate(-50%, calc(-50% - 30px)) scale(1.1) rotate(0deg); }
    70% { opacity: 1; transform: translate(-50%, calc(-50% - 20px)) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, calc(-50% - 80px)) scale(1.5); }
}

/* コンボ用スコア表示のベース */
.score-popup.combo-text {
    /* コンテナ自体は色を持たず、子要素のFlexレイアウトを担当 */
    background: none;
    -webkit-background-clip: unset;
    -webkit-text-fill-color: unset;
    filter: drop-shadow(0px 4px 2px rgba(80,40,20,0.8));
    z-index: 60; /* 通常スコアより手前 */
    animation: comboPopupAnim 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

/* 点数部分（上段） */
.score-popup.combo-text .score-val {
    /* 通常のスコアと同じような明るい黄金のグラデーション */
    background: linear-gradient(180deg, #ffffff 0%, #ffea00 40%, #ff8c00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 1.1em;
}

/* コンボテキスト部分（下段） */
.score-popup.combo-text .combo-val {
    /* 少し控えめでリッチなゴールドに変更 */
    background: linear-gradient(180deg, #ffffff 0%, #ffeaa7 40%, #f39c12 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 0.6em; /* コンボ文字は小さくして邪魔にならないように */
    white-space: nowrap;
}

@keyframes comboPopupAnim {
    /* 回転をなくし、拡縮も少しマイルドにして「うるささ」を軽減 */
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1.4); }
    40% { opacity: 1; transform: translate(-50%, calc(-50% - 20px)) scale(1.2); }
    70% { opacity: 1; transform: translate(-50%, calc(-50% - 10px)) scale(1.25); }
    100% { opacity: 0; transform: translate(-50%, calc(-50% - 60px)) scale(1.4); }
}

/* 大収穫ポップアップ */
.daisyukaku-popup {
    position: absolute;
    font-family: 'M PLUS Rounded 1c', 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', sans-serif;
    font-size: clamp(50px, 18vw, 90px); /* さらに大きく目立つように調整 */
    font-weight: 800; /* ExtraBold */
    color: #E84A3A;
    white-space: nowrap;
    pointer-events: none;
    z-index: 100;
    transform-origin: center center;
    
    /* 二重フチと薄い影をtext-shadowで表現 */
    text-shadow: 
        /* 内側の白フチ (#FFFDF8) */
        -2px -2px 0 #FFFDF8,  2px -2px 0 #FFFDF8,
        -2px  2px 0 #FFFDF8,  2px  2px 0 #FFFDF8,
         0px -2px 0 #FFFDF8,  0px  2px 0 #FFFDF8,
        -2px  0px 0 #FFFDF8,  2px  0px 0 #FFFDF8,
        
        /* 外側の赤茶フチ (#9E3B2E) - 白の2px分よりさらに外側に3px分追加 (計5px) */
        -5px -5px 0 #9E3B2E,  5px -5px 0 #9E3B2E,
        -5px  5px 0 #9E3B2E,  5px  5px 0 #9E3B2E,
         0px -5px 0 #9E3B2E,  0px  5px 0 #9E3B2E,
        -5px  0px 0 #9E3B2E,  5px  0px 0 #9E3B2E,
        -4px -5px 0 #9E3B2E,  4px -5px 0 #9E3B2E,
        -5px -4px 0 #9E3B2E,  5px -4px 0 #9E3B2E,
        -4px  5px 0 #9E3B2E,  4px  5px 0 #9E3B2E,
        -5px  4px 0 #9E3B2E,  5px  4px 0 #9E3B2E,
        
        /* 薄いドロップシャドウ（下方向、ぼかし弱め） */
         0px  8px 3px rgba(80, 40, 20, 0.22);
    
    /* アニメーションのカーブを少し柔らかく弾むように設定 */
    animation: daisyukakuAnim 0.9s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes daisyukakuAnim {
    0% {
        /* X軸方向は -50% (真ん中) ではなく -46% にして少し右へ光学調整 */
        transform: translate(-46%, -50%) scale(0.6);
        opacity: 0;
    }
    15% {
        transform: translate(-46%, -50%) scale(1.15);
        opacity: 1;
    }
    30% {
        transform: translate(-46%, -50%) scale(1.0);
        opacity: 1;
    }
    80% {
        transform: translate(-46%, -50%) scale(1.0);
        opacity: 1;
    }
    100% {
        transform: translate(-46%, -50%) scale(1.0);
        opacity: 0;
    }
}

/* 横画面（ランドスケープ）対応 */
@media (orientation: landscape) and (max-aspect-ratio: 16/9) {
    /* ゲームコンテナからはみ出すUIの表示を許可 */
    #game-container {
        overflow: visible;
    }
    
    /* 横画面ではUIを左右の余白（黒帯部分）に逃がす */
    .left-ui {
        position: absolute;
        left: -130px;
        top: 20px;
        flex-direction: column; /* 外に逃がした場合は縦並びの方が見やすい */
    }
    
    #next-box {
        position: absolute;
        right: -80px;
        top: 20px;
    }
}

#copyright {
    margin-top: 50px; /* スタートボタンから一定の距離を保つ */
    font-size: 14px;
    font-weight: bold; /* 文字を太く */
    color: rgba(255, 255, 255, 0.4);
    text-align: center;
    pointer-events: none;
}

/* ===== 台風イベント用スタイル ===== */
.typhoon-notice {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Hiragino Maru Gothic ProN', 'M PLUS Rounded 1c', sans-serif;
    font-size: clamp(30px, 8vw, 50px);
    font-weight: 900;
    color: #fff;
    text-shadow: 0 4px 10px rgba(0,0,0,0.8), 0 0 20px rgba(0,200,255,0.8);
    z-index: 100;
    pointer-events: none;
    white-space: nowrap;
    animation: noticeFade 2.5s ease-in-out forwards;
}

@keyframes noticeFade {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    10% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
    30% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.3); }
}

.typhoon-leaf {
    position: absolute;
    pointer-events: none;
    z-index: 90;
    will-change: transform;
}

/* 葉っぱよりゆっくり横切り、約3秒でもがきながら2回転する。 */
.typhoon-chicori {
    position: absolute;
    left: 0;
    height: auto;
    pointer-events: none;
    z-index: 91;
    will-change: transform;
    animation: chicoriFly 3s linear forwards;
}

@keyframes chicoriFly {
    0% { transform: translate(var(--chicori-start-x), 24px) rotate(var(--chicori-start-angle)); }
    50% { transform: translate(calc((var(--chicori-start-x) + var(--chicori-end-x)) / 2), -36px) rotate(var(--chicori-mid-angle)); }
    100% { transform: translate(var(--chicori-end-x), 40px) rotate(var(--chicori-end-angle)); }
}

@keyframes leafFlyRight {
    0% { transform: translate(-100px, 0) rotate(0deg); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translate(120vw, var(--dropY)) rotate(var(--rotEnd)); opacity: 0; }
}

@keyframes leafFlyLeft {
    0% { transform: translate(120vw, 0) rotate(0deg); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translate(-100px, var(--dropY)) rotate(var(--rotEnd)); opacity: 0; }
}

