/* 追加: Safe Area 対応 */
:root {
    --vh: 1vh;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --actual-vh: 100vh;
}

/* 前回のCSSはそのまま維持 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Arial", sans-serif;
    background: linear-gradient(135deg, #fff5f5, #ffeaea);
    overflow: hidden;
    user-select: none;
    touch-action: manipulation;
    width: 100vw;
    height: 100vh; /* この行を修正 */
    height: calc(var(--actual-vh) * 100); /* 追加 */
}

#game-container {
    position: relative;
    width: 100%;
    height: 100vh; /* フォールバック */
    height: calc(var(--vh, 1vh) * 100);
    min-height: -webkit-fill-available; /* iOS Safari用 */
}

/* 重なり防止のためのクリアフィックス */
#game-container::after {
    content: "";
    display: table;
    clear: both;
}

/* 明太子の基本スタイル */
.mentaiko {
    position: absolute;
    cursor: pointer;
    transition:
        transform 0.2s,
        opacity 0.2s;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 通常明太子 */
.mentaiko.normal {
    width: 60px;
    height: 40px;
    border-radius: 50% 50% 30% 70% / 60% 40% 60% 40%;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
    border: 2px solid; /* 色を指定しない */
}

/* ボーダー色を背景色に合わせて調整 */
.mentaiko.normal[style*="background: #ff6b6b"],
.mentaiko.normal[style*="background:#ff6b6b"] {
    border-color: #e53935; /* デフォルト用の濃い赤 */
}

.mentaiko.normal[style*="background: #a8e6cf"],
.mentaiko.normal[style*="background:#a8e6cf"] {
    border-color: #7bc4a9; /* ミント用の濃い緑 */
}

.mentaiko.normal[style*="background: #d4a5e3"],
.mentaiko.normal[style*="background:#d4a5e3"] {
    border-color: #b57bc4; /* ラベンダー用の濃い紫 */
}

.mentaiko.normal[style*="background: #4cc9f0"],
.mentaiko.normal[style*="background:#4cc9f0"] {
    border-color: #1ea8d4; /* アクア用の濃い青 */
}

.mentaiko.normal[style*="background: #f6b483"],
.mentaiko.normal[style*="background:#faa667"] {
    border-color: #ff6b6b;
}

.mentaiko.normal[style*="background: #a3d9a5"],
.mentaiko.normal[style*="background:#a3d9a5"] {
    border-color: #7bc47f;
}

.mentaiko.normal[style*="background: #b19cd9"],
.mentaiko.normal[style*="background:#b19cd9"] {
    border-color: #8a6dcc;
}

.mentaiko.normal::after {
    content: "";
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 25%;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
}

/* ゴールデン明太子 */
.mentaiko.golden {
    width: 70px;
    height: 45px;
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    border-radius: 50% 50% 30% 70% / 60% 40% 60% 40%;
    box-shadow: 0 3px 12px rgba(255, 215, 0, 0.4);
    border: 2px solid #ffc400;
    animation: glow 1.5s ease-in-out infinite alternate;
}

.mentaiko.golden::after {
    content: "";
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 25%;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
}

@keyframes glow {
    from {
        filter: brightness(1) drop-shadow(0 0 5px rgba(255, 215, 0, 0.6));
    }
    to {
        filter: brightness(1.3) drop-shadow(0 0 10px rgba(255, 215, 0, 0.8));
    }
}

/* レインボー明太子 */
.mentaiko.rainbow {
    width: 65px;
    height: 42px;
    border-radius: 50% 50% 30% 70% / 60% 40% 60% 40%;
    box-shadow: 0 3px 12px rgba(255, 255, 255, 0.4);
    border: 2px solid white;
    animation: rainbow-glow 2s ease-in-out infinite;
}

@keyframes rainbow-glow {
    0% {
        background: #ff6b6b;
        filter: drop-shadow(0 0 8px rgba(255, 107, 107, 0.6));
    }
    20% {
        background: #ffd166;
        filter: drop-shadow(0 0 8px rgba(255, 209, 102, 0.6));
    }
    40% {
        background: #06d6a0;
        filter: drop-shadow(0 0 8px rgba(6, 214, 160, 0.6));
    }
    60% {
        background: #118ab2;
        filter: drop-shadow(0 0 8px rgba(17, 138, 178, 0.6));
    }
    80% {
        background: #9d4edd;
        filter: drop-shadow(0 0 8px rgba(157, 78, 221, 0.6));
    }
    100% {
        background: #ff6b6b;
        filter: drop-shadow(0 0 8px rgba(255, 107, 107, 0.6));
    }
}

.mentaiko.rainbow::after {
    content: "";
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 25%;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: rainbow-shine 2s ease-in-out infinite;
}

@keyframes rainbow-shine {
    0%,
    100% {
        opacity: 0.7;
        transform: scale(1);
    }
    50% {
        opacity: 0.9;
        transform: scale(1.1);
    }
}

/* シャドウ明太子 */
.mentaiko.shadow {
    width: 55px;
    height: 35px;
    border-radius: 50% 50% 30% 70% / 60% 40% 60% 40%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(0, 0, 0, 0.5);
    background: rgba(100, 100, 100, 0.6) !important;
    animation: shadow-fade 3s ease-in-out infinite;
    cursor: none;
}

@keyframes shadow-fade {
    0%,
    100% {
        opacity: 0.3;
        transform: scale(0.9);
    }
    50% {
        opacity: 0.7;
        transform: scale(1);
    }
}

.mentaiko.shadow::after {
    content: "";
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 25%;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    animation: shadow-pulse 2s ease-in-out infinite;
}

@keyframes shadow-pulse {
    0%,
    100% {
        opacity: 0.1;
    }
    50% {
        opacity: 0.3;
    }
}

/* シャドウ明太子用の特別なカーソル */
.mentaiko.shadow:hover {
    cursor: crosshair;
}

/* チェーンメンタイ - 改善版 */
.mentaiko.chain {
    width: 65px;
    height: 45px;
    border-radius: 50% 50% 30% 70% / 60% 40% 60% 40%;
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.4);
    border: 3px dashed #4a90e2;
    background: linear-gradient(135deg, #4a90e2, #7b68ee, #9370db) !important;
    animation: chain-pulse 1.2s ease-in-out infinite;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

@keyframes chain-pulse {
    0%,
    100% {
        transform: scale(1);
        box-shadow:
            0 0 0 0 rgba(74, 144, 226, 0.8),
            0 4px 12px rgba(74, 144, 226, 0.4);
    }
    50% {
        transform: scale(1.08);
        box-shadow:
            0 0 0 6px rgba(74, 144, 226, 0.3),
            0 6px 16px rgba(74, 144, 226, 0.5);
    }
}

.mentaiko.chain::before {
    content: "";
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
    animation: chain-shine 3s linear infinite;
    z-index: 1;
}

@keyframes chain-shine {
    0% {
        transform: translateX(-100%) rotate(45deg);
    }
    100% {
        transform: translateX(200%) rotate(45deg);
    }
}

.mentaiko.chain::after {
    content: "⛓️";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
    opacity: 0.9;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    z-index: 2;
}

/* アクティブ状態の改善 */
.mentaiko.chain.active {
    background: linear-gradient(135deg, #ff6b6b, #ff5252, #ff8e8e) !important;
    border: 3px solid #ff5252;
    animation: chain-active-pulse 0.6s ease-in-out infinite;
    box-shadow:
        0 0 0 0 rgba(255, 107, 107, 0.8),
        0 6px 18px rgba(255, 107, 107, 0.5);
}

@keyframes chain-active-pulse {
    0%,
    100% {
        transform: scale(1.1);
        box-shadow:
            0 0 0 0 rgba(255, 107, 107, 0.9),
            0 6px 18px rgba(255, 107, 107, 0.6);
    }
    50% {
        transform: scale(1.15);
        box-shadow:
            0 0 0 10px rgba(255, 107, 107, 0.4),
            0 8px 22px rgba(255, 107, 107, 0.7);
    }
}
/*
            @keyframes chain-active {
                0%,
                100% {
                    transform: scale(1.1);
                    box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.8);
                }
                50% {
                    transform: scale(1.15);
                    box-shadow: 0 0 0 8px rgba(255, 107, 107, 0);
                }
            }
*/
.mentaiko.chain.active::after {
    content: "🔥";
    font-size: 20px;
    animation: fire-flicker 0.3s ease-in-out infinite alternate;
}

@keyframes fire-flicker {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 0.8;
    }
}

/* チェーンカウンター表示 */
.chain-counter {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #4a90e2, #7b68ee);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    white-space: nowrap;
    z-index: 110;
    border: 2px solid white;
    min-width: 85px;
    text-align: center;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.mentaiko.chain.active .chain-counter {
    background: linear-gradient(135deg, #ff6b6b, #ff5252);
    border: 2px solid #ffeb3b;
}

/* チェーン専用のホバーエフェクト */
.mentaiko.chain:hover {
    transform: scale(1.05);
    transition: transform 0.2s ease;
}

/* チェーン可能状態のフィードバック */
.chain-available {
    filter: brightness(1.2) contrast(1.1);
}

.chain-available::before {
    content: "✨";
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 16px;
    animation: sparkle 1.5s ease-in-out infinite;
    z-index: 120;
}

@keyframes sparkle {
    0%,
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(0);
    }
    50% {
        opacity: 1;
        transform: translateX(-50%) translateY(-5px);
    }
}

/* ミラクル明太子 */
.mentaiko.miracle {
    width: 70px;
    height: 50px;
    border-radius: 50% 50% 30% 70% / 60% 40% 60% 40%;
    box-shadow:
        0 0 20px rgba(255, 255, 255, 0.8),
        0 0 40px rgba(255, 255, 255, 0.4),
        inset 0 0 20px rgba(255, 255, 255, 0.3);
    border: 3px solid rgba(255, 255, 255, 0.9);
    background: linear-gradient(135deg, #ffffff, #f0f8ff, #e6f7ff) !important;
    animation:
        miracle-float 4s ease-in-out infinite,
        miracle-glow 2s ease-in-out infinite alternate;
    cursor: pointer;
    position: relative;
    z-index: 150;
}

@keyframes miracle-float {
    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }
    25% {
        transform: translateY(-8px) rotate(1deg);
    }
    50% {
        transform: translateY(-4px) rotate(0deg);
    }
    75% {
        transform: translateY(-12px) rotate(-1deg);
    }
}

@keyframes miracle-glow {
    0% {
        filter: brightness(1) drop-shadow(0 0 10px rgba(255, 255, 255, 0.6));
    }
    100% {
        filter: brightness(1.2) drop-shadow(0 0 20px rgba(255, 255, 255, 0.8));
    }
}

/* 天使の輪エフェクト */
.mentaiko.miracle::before {
    content: "✨";
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 24px;
    animation: halo-rotate 6s linear infinite;
    z-index: 151;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
}

@keyframes halo-rotate {
    0% {
        transform: translateX(-50%) rotate(0deg);
    }
    100% {
        transform: translateX(-50%) rotate(360deg);
    }
}

/* 光彩エフェクト */
.mentaiko.miracle::after {
    content: "";
    position: absolute;
    top: -15px;
    left: -15px;
    right: -15px;
    bottom: -15px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0) 70%);
    border-radius: 50% 50% 30% 70% / 60% 40% 60% 40%;
    animation: miracle-shine 3s ease-in-out infinite;
    z-index: 149;
    pointer-events: none;
}

@keyframes miracle-shine {
    0%,
    100% {
        opacity: 0.6;
        transform: scale(1);
    }
    50% {
        opacity: 0.9;
        transform: scale(1.1);
    }
}

/* ミラクル効果UI */
.miracle-ui {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(240, 248, 255, 0.95));
    color: #2c3e50;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    z-index: 2000;
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.2),
        0 0 0 2px rgba(255, 255, 255, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    min-width: 200px;
}

.miracle-ui.time-extension {
    background: linear-gradient(135deg, rgba(173, 216, 230, 0.95), rgba(135, 206, 250, 0.95));
    color: #1e3a5f;
}

.miracle-ui.fever-time {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.95), rgba(255, 165, 0, 0.95));
    color: #8b4513;
}

.miracle-ui.golden-time {
    background: linear-gradient(135deg, rgba(255, 223, 0, 0.95), rgba(255, 195, 0, 0.95));
    color: #8b4513;
}

.miracle-ui.bomb-disable {
    background: linear-gradient(135deg, rgba(144, 238, 144, 0.95), rgba(50, 205, 50, 0.95));
    color: #1e453e;
}

/* 画面全体エフェクト */
.miracle-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1800;
    animation: overlay-fade 0.5s ease-out;
}

@keyframes overlay-fade {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.miracle-overlay.time-extension {
    background: radial-gradient(circle at center, rgba(173, 216, 230, 0.3) 0%, transparent 70%);
}

.miracle-overlay.fever-time {
    background: radial-gradient(circle at center, rgba(255, 215, 0, 0.4) 0%, transparent 70%);
    animation: fever-pulse 1s ease-in-out infinite alternate;
}

@keyframes fever-pulse {
    0% {
        opacity: 0.3;
    }
    100% {
        opacity: 0.6;
    }
}

.miracle-overlay.golden-time {
    background: radial-gradient(circle at center, rgba(255, 223, 0, 0.4) 0%, transparent 70%);
    animation: golden-shimmer 2s ease-in-out infinite;
}

@keyframes golden-shimmer {
    0%,
    100% {
        opacity: 0.3;
    }
    50% {
        opacity: 0.6;
    }
}

.miracle-overlay.bomb-disable {
    background: radial-gradient(circle at center, rgba(144, 238, 144, 0.3) 0%, transparent 70%);
}

/* ミラクル効果中の明太子変換 */
.mentaiko.golden-converted {
    background: linear-gradient(135deg, #ffd700, #ffed4e) !important;
    border: 2px solid #ffc400 !important;
    animation: converted-glow 1s ease-in-out infinite alternate;
}

@keyframes converted-glow {
    from {
        filter: brightness(1) drop-shadow(0 0 5px rgba(255, 215, 0, 0.6));
    }
    to {
        filter: brightness(1.3) drop-shadow(0 0 10px rgba(255, 215, 0, 0.8));
    }
}

/* ミラクル明太子のホバー効果 */
.mentaiko.miracle:hover {
    animation: miracle-hover 0.5s ease-in-out;
}

@keyframes miracle-hover {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* 爆弾明太子 */
.mentaiko.bomb {
    width: 65px;
    height: 42px;
    border-radius: 50% 50% 30% 70% / 60% 40% 60% 40%;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
    border: 2px solid;
}

.mentaiko.bomb::after {
    content: "";
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 25%;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
}

.mentaiko.bomb.danger {
    background: #666666 !important;
    border-color: #555555 !important;
    animation: danger-pulse 0.3s ease-in-out infinite;
}

.mentaiko.bomb.warning {
    background: #ff8800 !important;
    border-color: #e67e00 !important;
    animation: warning-pulse 0.8s ease-in-out infinite;
}

.mentaiko.bomb.safe {
    background: #ff4444 !important;
    border-color: #e53935 !important;
}

@keyframes danger-pulse {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

@keyframes warning-pulse {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* 爆弾タイマー */
.bomb-timer {
    position: absolute;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    background: rgba(0, 0, 0, 0.85);
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
    z-index: 110;
    border: 2px solid white;
    min-width: 60px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* 安全状態の爆弾用アニメーション */
@keyframes safe-glow {
    from {
        box-shadow: 0 0 5px rgba(76, 175, 80, 0.6);
    }
    to {
        box-shadow:
            0 0 15px rgba(76, 175, 80, 0.9),
            0 0 25px rgba(76, 175, 80, 0.4);
    }
}

@keyframes safe-pulse {
    0%,
    100% {
        opacity: 0.6;
        transform: scale(1);
    }
    50% {
        opacity: 0.9;
        transform: scale(1.1);
    }
}

@keyframes safe-bonus-pop {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -100px) scale(1.5);
    }
}

/* 安全状態の爆弾スタイル */
.mentaiko.bomb.safe {
    background: #4caf50 !important;
    border-color: #45a049 !important;
}

.mentaiko.bomb.safe.safe-active {
    animation: safe-glow 1.5s ease-in-out infinite alternate;
}

/* クリックエフェクト */
.mentaiko.popping {
    transform: scale(1.8);
    opacity: 0;
}

/* コンボエフェクト */
.combo-effect {
    position: absolute;
    color: #ff6b6b;
    font-size: 24px;
    font-weight: bold;
    animation: combo-pop 0.6s ease-out forwards;
    pointer-events: none;
    z-index: 150;
}

@keyframes combo-pop {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(-50px) scale(1.5);
        opacity: 0;
    }
}

/* コンボメッセージ用の固定位置スタイル */
.combo-message {
    position: fixed;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 28px;
    font-weight: bold;
    z-index: 200;
    text-align: center;
    pointer-events: none;
    animation: combo-message-pop 1s ease-out forwards;
}

@keyframes combo-message-pop {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    50% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
}

.combo-bonus {
    color: #ff6b6b;
    text-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
}

.combo-fail {
    color: #666666;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

/* 不足しているアニメーションを追加 */
@keyframes fadeInOut {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
    20%,
    80% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
}

/* 画面遷移 */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh; /* フォールバック */
    height: calc(var(--vh, 1vh) * 100);
    min-height: -webkit-fill-available; /* iOS Safari用 */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding-top: 20px;
    padding-bottom: 20px;
    overflow-y: auto;
    background: rgba(255, 245, 245, 0.98);
    z-index: 2000;
    padding: 20px;
    text-align: center;
}

.hidden {
    display: none !important;
}

h1 {
    color: #d32f2f;
    font-size: clamp(2em, 6vw, 3.5em); /* フォントサイズを少し小さく */
    margin-bottom: 20px;
    margin-top: 10px; /* 上部マージンを追加 */
    text-align: center;
    padding: 0 15px; /* 左右のパディングを追加 */
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    line-height: 1.2;
}

.subtitle {
    color: #666;
    font-size: clamp(1.1em, 4vw, 1.5em);
    margin-bottom: 25px;
    line-height: 1.5;
    max-width: 600px;
}

/* 基本ルール表示 */
.basic-rules {
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 15px;
    margin: 20px 0;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.3);
}

.basic-rules h3 {
    color: #d32f2f;
    margin-bottom: 15px;
    text-align: center;
    font-size: 1.2em;
}

.rule-item {
    margin: 10px 0;
    color: #666;
    font-size: 0.95em;
    line-height: 1.5;
    text-align: left;
    padding-left: 5px;
}

#full-rules-button {
    background: linear-gradient(135deg, #4caf50, #45a049);
    margin: 15px 0;
    max-width: 300px;
    width: 90%;
}

#full-rules-button:hover {
    background: linear-gradient(135deg, #45a049, #3d8b40);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

/* 全ルール画面 */
#rules-screen .settings-container {
    max-height: 85vh;
    overflow-y: auto;
}

#rules-screen .instruction-content {
    max-height: none;
    overflow-y: visible;
}

/* 折りたたみ式説明書のスタイル - スクロール対応 */
.game-instruction {
    background: rgba(255, 255, 255, 0.95);
    padding: 0;
    border-radius: 15px;
    margin: 20px 0;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.3);
    overflow: hidden;
    max-height: 80px; /* 閉じているときの高さ */
    transition: max-height 0.4s ease-in-out;
    display: flex;
    flex-direction: column;
}

/* 展開時のスタイル - 高さ制限を緩和 */
.game-instruction[open] {
    max-height: 85vh !important; /* 画面の85%まで使用可能 */
    height: auto;
}

.game-instruction summary {
    padding: 20px;
    font-size: 1.1em;
    font-weight: bold;
    color: #d32f2f;
    cursor: pointer;
    list-style: none;
    background: linear-gradient(135deg, rgba(255, 107, 107, 0.1), rgba(255, 245, 245, 0.8));
    border-bottom: 1px solid rgba(255, 107, 107, 0.2);
    transition: all 0.3s ease;
    position: relative;
    height: 60px; /* 固定高さ */
    display: flex;
    align-items: center;
}

.game-instruction summary:hover {
    background: linear-gradient(135deg, rgba(255, 107, 107, 0.15), rgba(255, 245, 245, 0.9));
}

/* detailsマーカーを非表示 */
.game-instruction summary::-webkit-details-marker {
    display: none;
}

/* カスタム矢印アイコン */
.game-instruction summary::after {
    content: "▼";
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8em;
    transition: transform 0.3s ease;
    color: #d32f2f;
}

.game-instruction[open] summary::after {
    transform: translateY(-50%) rotate(180deg);
}

/* スクロール可能なコンテンツエリアを修正 */
.instruction-content {
    padding: 20px;
    max-height: calc(85vh - 80px); /* 親要素の高さからヘッダー分を引く */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    flex: 1;
    min-height: 150px;
}

/* スクロールバーのスタイリングを確実に適用 */
.instruction-content::-webkit-scrollbar {
    width: 8px;
    display: block !important;
}

.instruction-content::-webkit-scrollbar-track {
    background: rgba(255, 107, 107, 0.15);
    border-radius: 4px;
}

.instruction-content::-webkit-scrollbar-thumb {
    background: rgba(255, 107, 107, 0.4);
    border-radius: 4px;
}

.instruction-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 107, 107, 0.6);
}

/* Firefox用スクロールバー */
.instruction-content {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 107, 107, 0.4) rgba(255, 107, 107, 0.1);
}

.instruction-content > * {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* セクション間の余白調整 */
.instruction-section {
    margin: 20px 0;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    display: block !important; /* 強制表示 */
}

.instruction-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

/* 各要素の表示を確実にする */
.game-instruction[open] .instruction-section,
.game-instruction[open] .instruction-section h4,
.game-instruction[open] .instruction-item,
.game-instruction[open] .bomb-details,
.game-instruction[open] .bomb-details div {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.instruction-section h4 {
    color: #d32f2f;
    margin-bottom: 12px;
    font-size: 1em;
    display: flex !important; /* 追加: 確実に表示 */
    align-items: center;
    gap: 8px;
}

/* 爆弾詳細の表示を修正 */
.bomb-details {
    margin-left: 0;
    margin-top: 8px;
    padding-left: 25px;
    display: block !important;
}

.bomb-details div {
    margin: 6px 0;
    font-size: 0.9em;
    color: #666;
    padding: 4px 0;
    display: block !important;
}

/* インストラクションアイテムの表示を修正 */
.instruction-item {
    margin: 10px 0;
    color: #666;
    font-size: 0.95em;
    line-height: 1.5;
    text-align: left;
    padding-left: 5px;
    display: flex !important;
    align-items: flex-start;
    gap: 8px;
}

/* 上部ボタングルップ（ゲームスタート用） */
.button-group-top {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 25px 0;
    width: 100%;
    max-width: 300px;
}

/* スタート画面の設定・実績ボタン - ナビボタンと同じスタイル */
#title-settings-button,
#title-achievements-button {
    background: rgba(255, 255, 255, 0.9);
    color: #d32f2f;
    border: none;
    padding: 12px 24px;
    font-size: 1em;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    font-weight: bold;
    width: 100%;
}

#title-settings-button:hover,
#title-achievements-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: rgba(255, 255, 255, 1);
}

#title-settings-button:active,
#title-achievements-button:active {
    transform: translateY(0);
}

/* ゲームスタートボタンの特別スタイル */
#start-button {
    background: linear-gradient(135deg, #ff6b6b, #ff5252);
    color: white;
    border: none;
    padding: 18px 36px;
    font-size: 1.3em;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: bold;
    width: 100%;
}

#start-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

#start-button:active {
    transform: translateY(0);
}

/* ボタングループ */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 25px;
    width: 100%;
    max-width: 300px;
}

button {
    background: linear-gradient(135deg, #ff6b6b, #ff5252);
    color: white;
    border: none;
    padding: 16px 32px;
    font-size: 1.2em;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
    transition:
        transform 0.2s,
        box-shadow 0.2s;
    pointer-events: auto;
    font-weight: bold;
    width: 100%;
}

/* タイトルに戻るボタン */
#title-button {
    background: linear-gradient(135deg, #666666, #888888);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

#title-button:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

button:active {
    transform: translateY(0);
}

#final-score {
    font-size: 4em;
    color: #d32f2f;
    margin: 20px 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

/* Phase 2 追加スタイル */
/* 実績通知 */
.achievement-notification {
    position: fixed;
    /* topとleftはJavaScriptで設定するのでここでは削除 */
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    color: #8b4513;
    padding: 20px 30px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    z-index: 3000;
    text-align: center;
    animation: achievement-pop 0.6s ease-out;
    border: 3px solid #ffc400;
}

@keyframes achievement-pop {
    0% {
        transform: translateX(-50%) scale(0.8);
        opacity: 0;
    }
    70% {
        transform: translateX(-50%) scale(1.1);
        opacity: 1;
    }
    100% {
        transform: translateX(-50%) scale(1);
        opacity: 1;
    }
}

.achievement-title {
    font-size: 1.3em;
    font-weight: bold;
    margin-bottom: 5px;
}

.achievement-desc {
    font-size: 0.9em;
    opacity: 0.8;
}

/* 設定画面 */
.settings-container {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.settings-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-title {
    color: #d32f2f;
    font-size: 1.4em;
    margin-bottom: 15px;
    text-align: center;
}

.settings-item {
    margin: 15px 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* 上部揃え */
    gap: 15px;
}

.skin-option {
    width: 35px;
    height: 22px;
    border-radius: 4px;
    margin: 0 2px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    flex-shrink: 0;
}

.skin-option.selected {
    border-color: #ff6b6b;
    transform: scale(1.1);
}

/* スキンオプション - 修正版 */
.skin-default {
    background: #ff6b6b;
} /* デフォルト（赤系） */
.skin-mint {
    background: #a8e6cf;
} /* 爽やかミント */
.skin-lavender {
    background: #d4a5e3;
} /* 優しいラベンダー */
.skin-ocean {
    background: #4cc9f0;
} /* 鮮やかアクア */
.skin-sunset {
    background: #f6b483;
}
.skin-forest {
    background: #a3d9a5;
}
.skin-galaxy {
    background: #b19cd9;
}

/* 実績画面 */
.achievement-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.achievement-item {
    background: #f8f8f8;
    padding: 15px;
    border-radius: 10px;
    text-align: center;
    border: 2px solid #e0e0e0;
    transition: all 0.3s;
}

.achievement-item.unlocked {
    background: linear-gradient(135deg, #fff9c4, #ffeb3b);
    border-color: #ffc400;
}

.achievement-icon {
    font-size: 2em;
    margin-bottom: 10px;
}

.achievement-name {
    font-weight: bold;
    color: #333;
    margin-bottom: 5px;
}

.achievement-description {
    font-size: 0.8em;
    color: #666;
}

/* 設定・実績画面のボタン調整 */
.settings-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.settings-buttons button {
    width: 100%;
    margin: 0;
}

#back-to-game-button,
#back-to-game-button-achievements {
    background: linear-gradient(135deg, #4caf50, #45a049);
}

#back-to-game-button:hover,
#back-to-game-button-achievements:hover {
    background: linear-gradient(135deg, #45a049, #3d8b40);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

/* トグルスイッチ */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
    flex-shrink: 0; /* サイズ固定 */
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #4caf50;
}

input:checked + .slider:before {
    transform: translateX(26px);
}

/* BGM設定の説明テキスト */
.setting-description {
    font-size: 0.8em;
    color: #666;
    margin-top: 5px;
    text-align: left;
}

/* ポーズ中のオーバーレイ */
.pause-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1999;
    display: none;
}

.pause-overlay.active {
    display: block;
}

/* UI表示 - ゲーム中のみ表示 */
#ui-container {
    position: absolute;
    top: 10px; /* この行を修正 */
    top: max(10px, var(--safe-area-top)); /* 追加 */
    left: 10px; /* この行を修正 */
    left: max(10px, var(--safe-area-left)); /* 追加 */
    z-index: 1000;
    background: rgba(255, 255, 255, 0.98);
    padding: 10px 15px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(5px);
    pointer-events: none;
    border: 3px solid rgba(255, 107, 107, 0.5);
    max-width: min(280px, calc(100vw - 120px));
    font-size: 14px;
    font-weight: 600;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.ui-item {
    margin: 5px 0; /* マージンを減らす */
    font-size: 14px; /* フォントサイズを小さく */
    font-weight: bold;
    color: #d32f2f;
    display: flex;
    justify-content: space-between;
    min-width: 120px; /* 最小幅を調整 */
}

.ui-value {
    color: #ff6b6b;
    margin-left: 10px;
}

.ui-item,
.ui-value {
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1); /* 文字に影を追加 */
}

/* ナビゲーションボタン - ゲーム中のみ表示 */
.nav-buttons {
    position: absolute;
    top: 10px; /* この行を修正 */
    top: max(10px, var(--safe-area-top)); /* 追加 */
    right: 10px; /* この行を修正 */
    right: max(10px, var(--safe-area-right)); /* 追加 */
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: flex-end;
    max-width: min(150px, calc(100vw - 20px));
    min-width: fit-content;
}

.nav-button {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    padding: 6px 10px;
    border-radius: 18px;
    cursor: pointer;
    font-size: 0.7em;
    font-weight: bold;
    color: #d32f2f;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    width: 100%;
    text-align: center;
    max-width: 100px;
    /* 高さを統一 */
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 追加：ボタンのホバー効果 */
.nav-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 中断ボタンは目立つ色に */
#pause-game-button {
    background: rgba(255, 107, 107, 0.9);
    color: white;
}

/* 既存のCSSに追加 */
.skin-selection-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start; /* スキン一覧のみ左寄せ */
    max-width: 100%;
    margin-top: 0;
    flex: 1;
}

/* ゲーム中断メニュー */
.pause-menu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.3);
    z-index: 3000;
    text-align: center;
    min-width: 280px;
    border: 3px solid #ff6b6b;
}

.pause-menu h3 {
    color: #d32f2f;
    margin-bottom: 20px;
    font-size: 1.4em;
}

.pause-menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.pause-menu-button {
    background: linear-gradient(135deg, #ff6b6b, #ff5252);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1.1em;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: bold;
}

.pause-menu-button.resume {
    background: linear-gradient(135deg, #4caf50, #45a049);
}

.pause-menu-button.quit {
    background: linear-gradient(135deg, #666666, #888888);
}

.pause-menu-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* ミラクル明太子用追加アニメーション */
@keyframes hint-fade {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    20%,
    80% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
}

@keyframes miracle-ring {
    0% {
        width: 10px;
        height: 10px;
        opacity: 1;
        border-width: 3px;
    }
    100% {
        width: 200px;
        height: 200px;
        opacity: 0;
        border-width: 1px;
    }
}

@keyframes miracle-sparkle {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translate(${Math.random() * 100 - 50}px, ${Math.random() * 100 - 50}px) scale(0) rotate(360deg);
    }
}

@keyframes miracle-beam {
    0% {
        height: 0;
        opacity: 1;
    }
    100% {
        height: 300px;
        opacity: 0;
    }
}

/* ミラクルヒント用スタイル */
.miracle-hint {
    /* JavaScript内でインラインスタイルを設定 */
}

/* 時間延長エフェクト */
@keyframes time-extension-pop {
    0% {
        opacity: 0;
        transform: translateX(-50%) scale(0.5);
    }
    50% {
        opacity: 1;
        transform: translateX(-50%) scale(1.1);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) scale(1);
    }
}

.time-extension-effect {
    position: fixed;
    top: 120px !important; /* 上部に固定 */
    left: 50% !important;
    transform: translateX(-50%) !important;
    font-size: 32px !important;
    font-weight: bold;
    color: #1e90ff;
    text-shadow: 0 0 20px rgba(30, 144, 255, 0.8);
    z-index: 1900;
    animation: time-extension-pop 1.5s ease-out forwards;
    pointer-events: none;
    white-space: nowrap !important; /* 改行を防止 */
    text-align: center;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 25px;
    border: 3px solid #1e90ff;
    box-shadow: 0 4px 20px rgba(30, 144, 255, 0.4);
    min-width: auto;
    max-width: 90vw; /* 画面幅の90%まで */
    overflow: hidden;
    text-overflow: ellipsis;
}

/* フィーバータイム用パルス */
/*
@keyframes fever-pulse {
    0% {
        opacity: 0.2;
    }
    100% {
        opacity: 0.4;
    }
}*/

/* ゴールデンタイム用きらめき */
/*
@keyframes golden-shimmer {
    0%,
    100% {
        opacity: 0.2;
    }
    50% {
        opacity: 0.4;
    }
}*/

/* 効果終了メッセージ（上部中央用） */
@keyframes fade-in-out {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    30%,
    70% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
}

/* フィーバー/ゴールデンタイム用スクリーンエフェクト */
.fever-screen-effect,
.golden-screen-effect {
    /* JavaScriptでスタイル設定 */
}

/* BGMコントロール用スタイル */
.theme-select {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    font-size: 14px;
    min-width: 180px;
}

.volume-slider {
    width: 120px;
    margin: 0 10px;
}

.volume-value {
    font-size: 14px;
    color: #666;
    min-width: 40px;
    display: inline-block;
}

.small-button {
    padding: 6px 12px;
    font-size: 12px;
    margin: 0 5px;
    background: linear-gradient(135deg, #4caf50, #45a049);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
}

.small-button:hover {
    background: linear-gradient(135deg, #45a049, #4caf50);
}

/* BGM設定アイテムのレイアウト調整 */
.settings-section h3 {
    margin-bottom: 15px;
    color: #333;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 5px;
}