body {
    margin: 0;
    background-color: #f0f0f0; /* 背景色 */
    font-family: 'Arial', sans-serif; /* フォント */
    overflow: hidden;
}

#game-viewport {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-container {
    width: 800px; /* ゲームエリアの幅 (調整可能) */
    height: 600px; /* ゲームエリアの高さ (調整可能) */
    background-color: #87CEEB; /* 空色の背景 */
    border: 3px solid #333;
    position: relative; /* 子要素を絶対位置で配置するための基準 */
    flex: 0 0 auto;
    overflow: hidden; /* エリア外に出たアイテムを非表示 */
    box-shadow: 0 0 15px rgba(0,0,0,0.3);
    transform-origin: center center;
    /* transform は JS で scale(s) を設定 */
}

#aoi-chan {
    position: absolute;
    top: 30px; /* 葵ちゃんの上からの位置 (調整可能) */
    left: 40px; /* 葵ちゃんの左からの位置 (調整可能) */
    /* transition はJSで制御 */
}

#aoi-chan img {
    width: 120px; /* 葵ちゃんの表示幅 (調整可能) */
    height: auto;
}

#akane-chan {
    position: absolute;
    bottom: 0; /* 茜ちゃんの初期Y位置 (地面) */
    left: calc(50% - 40px); /* 茜ちゃんの初期X位置 (中央やや左) */
    width: 80px;  /* 茜ちゃんの幅 (当たり判定にも影響, 調整可能) */
    height: 80px; /* 茜ちゃんの高さ (当たり判定にも影響, 調整可能) */
}

#akane-chan img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* アスペクト比を保ちつつコンテナに収める */
}

/* 落ちてくるアイテムの共通スタイル */
.item {
    position: absolute;
    width: 50px;  /* アイテムの幅 (調整可能) */
    height: 50px; /* アイテムの高さ (調整可能) */
}

.item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* チョコミント弾と岩弾のスタイル (必要に応じて調整) */
.chocomint-bullet, .danmaku-dumbbell {
    position: absolute;
    width: 30px; /* 弾の幅 */
    height: 30px; /* 弾の高さ */
}
.chocomint-bullet img, .danmaku-dumbbell img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}


#info-area {
    color: white;
    font-size: 22px;
    background-color: rgba(0, 0, 0, 0.8);
    padding: 15px 20px;
    border-radius: 8px;
    text-shadow: 1px 1px 2px black;
    margin-bottom: 20px;
    display: flex;
    gap: 30px;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

#info-area div {
    font-weight: bold;
}

#message-area {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #fff5fa 0%, #ffe4f2 100%);
    padding: 24px 36px;
    border-radius: 18px;
    text-align: center;
    font-size: 22px;
    color: #3a2a3a;
    box-shadow: 0 8px 30px rgba(255, 105, 180, 0.35), 0 0 0 4px #ffb6d9 inset;
    border: 3px solid #ff69b4;
    z-index: 100;
    width: 560px;
    max-width: min(90vw, 560px);
    max-height: 92vh;
    overflow: auto;
    touch-action: manipulation;
}
#message-area button,
#message-area a {
    touch-action: manipulation;
}

/* 防御: タイトル内のすべての画像に上限キャップ。万一個別CSSが効かなくても崩壊しない */
#message-area img {
    max-width: 100px;
    max-height: 100px;
}

#title-image {
    display: block;
    width: auto;
    max-width: 100% !important;
    max-height: 200px !important;
    height: auto;
    margin: 0 auto 6px;
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(255, 105, 180, 0.35);
}

#message-area p {
    margin: 12px 0 18px;
    line-height: 1.6;
    font-size: 18px;
}

/* タイトル装飾 */
#title-decor {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 6px;
}

#title-center { flex: 0 1 auto; }

#game-title {
    margin: 0;
    font-size: 38px;
    font-weight: 900;
    color: #ff1493;
    text-shadow:
        2px 2px 0 #fff,
        4px 4px 0 #ffb6d9,
        6px 6px 0 rgba(255, 20, 147, 0.25);
    letter-spacing: 2px;
    font-family: 'Arial Black', 'MS Gothic', sans-serif;
}

.title-char {
    width: 90px;
    height: auto;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.25));
}
.title-aoi { animation: titleBob 1.8s ease-in-out infinite; }
.title-akane { animation: titleBob 1.8s ease-in-out infinite 0.6s; transform: scaleX(-1); }

@keyframes titleBob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-8px); }
}
.title-akane { animation-name: titleBobAkane; }
@keyframes titleBobAkane {
    0%, 100% { transform: scaleX(-1) translateY(0); }
    50%      { transform: scaleX(-1) translateY(-8px); }
}

#title-ebi-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 14px;
    margin-top: 6px;
}
#title-ebi-row img {
    width: 38px;
    height: 38px;
    animation: ebiSpin 2.4s linear infinite;
}
#title-ebi-row img:nth-child(2) {
    width: 52px; height: 52px;
    animation-duration: 1.6s;
    filter: drop-shadow(0 0 8px gold);
}
.title-ebi-slot {
    cursor: pointer;
    transition: transform 0.1s ease;
}
.title-ebi-slot:hover {
    filter: drop-shadow(0 0 12px #ff4060) !important;
}
.title-ebi-slot:active {
    transform: scale(0.85);
}
@keyframes ebiSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ボタン群 */
.title-buttons {
    display: flex;
    gap: 14px;
    justify-content: center;
    margin-bottom: 14px;
}

#start-button {
    padding: 14px 36px;
    font-size: 22px;
    font-weight: bold;
    cursor: pointer;
    background: linear-gradient(180deg, #ff8ac5 0%, #ff1493 100%);
    color: white;
    border: none;
    border-radius: 10px;
    transition: transform 0.1s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 0 #b30f6b, 0 6px 12px rgba(0,0,0,0.2);
}
#start-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #b30f6b, 0 10px 16px rgba(0,0,0,0.25);
}
#start-button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #b30f6b, 0 4px 8px rgba(0,0,0,0.2);
}

.secondary-button {
    padding: 14px 24px;
    font-size: 18px;
    cursor: pointer;
    background: white;
    color: #ff1493;
    border: 2px solid #ff1493;
    border-radius: 10px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    font-weight: bold;
    transition: background 0.2s ease, color 0.2s ease;
}
.secondary-button:hover {
    background: #ff1493;
    color: white;
}

/* GIF作者クレジット */
#gif-credit {
    margin-top: 12px;
    font-size: 13px;
    color: #666;
    text-align: center;
}
#gif-credit a {
    color: #1da1f2;
    text-decoration: none;
}
#gif-credit a:hover { text-decoration: underline; }

/* ゲームオーバー時は装飾非表示 */
#message-area.result-mode #title-decor,
#message-area.result-mode #title-image,
#message-area.result-mode #title-ebi-row,
#message-area.result-mode #rules-link,
#message-area.result-mode #gif-credit {
    display: none;
}
/* タイトルに戻るボタンは result-mode 時のみ表示 */
#title-return-button { display: none; cursor: pointer; font-family: inherit; }
#message-area.result-mode #title-return-button { display: inline-flex; }
#message-area.result-mode {
    min-width: 380px;
}
#message-area.result-mode p {
    font-size: 22px;
    margin-top: 8px;
}

/* ゲームオーバー演出 */
.gameover-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.gameover-akane {
    width: 140px !important;
    max-width: 140px !important;
    max-height: 180px !important;
    height: auto;
    animation: gameoverAkaneWobble 0.9s ease-in-out infinite;
}
.gameover-title {
    font-size: 44px;
    font-weight: 900;
    color: #ff1493;
    letter-spacing: 4px;
    text-shadow:
        2px 2px 0 #fff,
        4px 4px 0 #ffb6d9,
        6px 6px 0 rgba(255, 20, 147, 0.25);
    font-family: 'Arial Black', 'MS Gothic', sans-serif;
    animation: gameoverTitlePulse 0.8s ease-in-out infinite alternate;
}
@keyframes gameoverAkaneWobble {
    0%, 100% { transform: rotate(-6deg) translateY(0); }
    50%      { transform: rotate(6deg) translateY(-4px); }
}
@keyframes gameoverTitlePulse {
    from { transform: scale(1); }
    to   { transform: scale(1.08); }
}

/* スペルカード演出用スタイル */
#spellcard-image {
    position: absolute;
    width: 60vw; /* 画面幅の60%程度 */
    max-width: 450px; /* 最大幅 */
    height: auto;
    opacity: 0; /* 初期状態は透明 */
    /* 初期位置をアニメーション後の目標位置（左上寄り）に設定 */
    left: calc(25% - (min(60vw, 450px) / 2));
    top: calc(25% - ( (min(60vw, 450px) * (9/16) ) / 2) ); /* アスペクト比16:9と仮定 */
    transform: scale(1); /* 初期状態は通常サイズ */
    z-index: 50;
    pointer-events: none;
    /* transition はJSで動的に設定 */
}

#spellcard-name {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #fff;
    text-shadow: 2px 2px 3px #000, -2px -2px 3px #000, 2px -2px 3px #000, -2px 2px 3px #000;
    opacity: 0;
    transition: opacity 1s ease-in-out 0.5s;
    z-index: 51;
    background-color: rgba(0,0,0,0.5);
    padding: 10px 15px;
    border-radius: 5px;
}

/* =========================================================================
   スマホ専用UI（PCには一切適用しない）
   - pointer: coarse = タッチデバイス（指）。マウスPCでは未マッチ。
   - 縦画面前提で設計。横画面では rotate-overlay で「縦にしてね」を表示。
   ========================================================================= */

/* 既定はPC: タッチUIも回転オーバーレイも非表示 */
#touch-controls { display: none; }
#rotate-overlay { display: none; }

@media (pointer: coarse) {
    /* --- タッチ操作パネル（縦画面で表示） ---
       下端には広告バナーが居座ることが多いので、広告ゾーンを避けて高めに配置。
       z-index は最前面（広告の残骸より上）に置く。 */
    #touch-controls {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: calc(max(16px, env(safe-area-inset-bottom)) + 110px);
        padding: 0 20px;
        justify-content: space-between;
        align-items: flex-end;
        z-index: 2147483646; /* 広告iframeより上に出すための最大級 */
        pointer-events: none; /* 隙間はタップを通す */
    }
    .tc-group {
        display: flex;
        gap: 18px;
        pointer-events: none;
    }
    .tc-btn {
        pointer-events: auto;
        width: 84px;
        height: 84px;
        border-radius: 50%;
        background: rgba(255, 105, 180, 0.55);
        color: #fff;
        font-size: 32px;
        font-weight: bold;
        border: 3px solid rgba(255, 255, 255, 0.85);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
        -webkit-tap-highlight-color: transparent;
        font-family: inherit;
        padding: 0;
        line-height: 1;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .tc-btn:active {
        background: rgba(255, 105, 180, 0.9);
        transform: scale(0.94);
    }
    .tc-jump {
        background: rgba(70, 150, 255, 0.6);
        font-size: 22px;
        width: 96px;
        height: 96px;
    }
    .tc-jump:active {
        background: rgba(70, 150, 255, 0.95);
    }

    /* 横画面のときは「縦にしてね」オーバーレイを最前面に */
    @media (orientation: landscape) {
        #touch-controls { display: none; }
        #rotate-overlay {
            display: flex;
            position: fixed;
            inset: 0;
            background: #1a0a20;
            color: #ffd9ec;
            z-index: 9999;
            align-items: center;
            justify-content: center;
            text-align: center;
            padding: 24px;
            font-size: 22px;
            line-height: 1.7;
            font-family: 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
        }
        #rotate-overlay .ro-inner {
            border: 2px solid #ff69b4;
            border-radius: 14px;
            padding: 28px 32px;
            background: rgba(30, 15, 40, 0.8);
            box-shadow: 0 0 30px rgba(255, 105, 180, 0.4);
        }
        #rotate-overlay .ro-icon {
            font-size: 56px;
            margin-bottom: 12px;
            display: block;
            animation: roSpin 2s ease-in-out infinite;
        }
        @keyframes roSpin {
            0%, 100% { transform: rotate(-8deg); }
            50%      { transform: rotate(8deg); }
        }
    }
}

/* タップ遅延・ハイライト除去（タッチ環境のみ） */
@media (pointer: coarse) {
    body, button, a { -webkit-tap-highlight-color: transparent; }
    #start-button, .secondary-button, .title-ebi-slot {
        touch-action: manipulation;
    }
    /* タイトル/結果ウィンドウも下端広告にかからないよう少し上に。
       広告は画面下部に出るので、中央より上寄りで固定する。 */
    #message-area {
        top: 42%;
        z-index: 2147483645;
    }
    #rotate-overlay { z-index: 2147483647; }
}