/* --- デザインシステム & 変数定義 --- */
:root {
    --bg-dark: #0a0b10;
    --bg-card: rgba(255, 255, 255, 0.03);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.4);
    --success: #10b981;
    --error: #ef4444;
    
    /* 22種類の鮮やかで識別しやすいネオンカラーパレット */
    --color-1: linear-gradient(180deg, #ff4b4b, #b30000); /* 1: 赤 */
    --color-2: linear-gradient(180deg, #3b82f6, #1d4ed8); /* 2: 青 */
    --color-3: linear-gradient(180deg, #10b981, #047857); /* 3: 緑 */
    --color-4: linear-gradient(180deg, #f59e0b, #b45309); /* 4: オレンジ */
    --color-5: linear-gradient(180deg, #a855f7, #6b21a8); /* 5: 紫 */
    --color-6: linear-gradient(180deg, #ec4899, #be185d); /* 6: ピンク */
    --color-7: linear-gradient(180deg, #06b6d4, #0891b2); /* 7: シアン */
    --color-8: linear-gradient(180deg, #eab308, #a16207); /* 8: 黄色 */
    --color-9: linear-gradient(180deg, #84cc16, #4d7c0f); /* 9: ライム */
    --color-10: linear-gradient(180deg, #6366f1, #4338ca); /* 10: インディゴ */
    --color-11: linear-gradient(180deg, #14b8a6, #0f766e); /* 11: ティール */
    --color-12: linear-gradient(180deg, #f97316, #c2410c); /* 12: コーラル */
    --color-13: linear-gradient(180deg, #d946ef, #a21caf); /* 13: マゼンタ */
    --color-14: linear-gradient(180deg, #0284c7, #0369a1); /* 14: スカイブルー */
    --color-15: linear-gradient(180deg, #22c55e, #15803d); /* 15: エメラルド */
    --color-16: linear-gradient(180deg, #f43f5e, #be123c); /* 16: ローズ */
    --color-17: linear-gradient(180deg, #a1a1aa, #52525b); /* 17: グレー */
    --color-18: linear-gradient(180deg, #fdba74, #f97316); /* 18: ピーチ */
    --color-19: linear-gradient(180deg, #a3e635, #65a30d); /* 19: 黄緑 */
    --color-20: linear-gradient(180deg, #818cf8, #4f46e5); /* 20: ラベンダー */
    --color-21: linear-gradient(180deg, #2dd4bf, #0d9488); /* 21: ミント */
    --color-22: linear-gradient(180deg, #fb7185, #e11d48); /* 22: サーモン */
}

/* 液体カラーマッピング用クラス */
.color-val-1 { background: var(--color-1); box-shadow: 0 0 8px rgba(255, 75, 75, 0.4); }
.color-val-2 { background: var(--color-2); box-shadow: 0 0 8px rgba(59, 130, 246, 0.4); }
.color-val-3 { background: var(--color-3); box-shadow: 0 0 8px rgba(16, 185, 129, 0.4); }
.color-val-4 { background: var(--color-4); box-shadow: 0 0 8px rgba(245, 158, 11, 0.4); }
.color-val-5 { background: var(--color-5); box-shadow: 0 0 8px rgba(168, 85, 247, 0.4); }
.color-val-6 { background: var(--color-6); box-shadow: 0 0 8px rgba(236, 72, 153, 0.4); }
.color-val-7 { background: var(--color-7); box-shadow: 0 0 8px rgba(6, 182, 212, 0.4); }
.color-val-8 { background: var(--color-8); box-shadow: 0 0 8px rgba(234, 179, 8, 0.4); }
.color-val-9 { background: var(--color-9); box-shadow: 0 0 8px rgba(132, 204, 22, 0.4); }
.color-val-10 { background: var(--color-10); box-shadow: 0 0 8px rgba(99, 102, 241, 0.4); }
.color-val-11 { background: var(--color-11); box-shadow: 0 0 8px rgba(20, 184, 166, 0.4); }
.color-val-12 { background: var(--color-12); box-shadow: 0 0 8px rgba(249, 115, 22, 0.4); }
.color-val-13 { background: var(--color-13); box-shadow: 0 0 8px rgba(217, 70, 239, 0.4); }
.color-val-14 { background: var(--color-14); box-shadow: 0 0 8px rgba(2, 132, 199, 0.4); }
.color-val-15 { background: var(--color-15); box-shadow: 0 0 8px rgba(34, 197, 94, 0.4); }
.color-val-16 { background: var(--color-16); box-shadow: 0 0 8px rgba(244, 63, 94, 0.4); }
.color-val-17 { background: var(--color-17); box-shadow: 0 0 8px rgba(161, 161, 170, 0.4); }
.color-val-18 { background: var(--color-18); box-shadow: 0 0 8px rgba(253, 186, 116, 0.4); }
.color-val-19 { background: var(--color-19); box-shadow: 0 0 8px rgba(163, 230, 53, 0.4); }
.color-val-20 { background: var(--color-20); box-shadow: 0 0 8px rgba(129, 140, 248, 0.4); }
.color-val-21 { background: var(--color-21); box-shadow: 0 0 8px rgba(45, 212, 191, 0.4); }
.color-val-22 { background: var(--color-22); box-shadow: 0 0 8px rgba(251, 113, 133, 0.4); }

/* --- 基本のCSSリセット & 共通スタイル --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    height: 100%;
    max-height: 900px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 20px;
}

/* 背景の発光装飾（ネオン） */
.bg-glow {
    position: absolute;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    filter: blur(120px);
    z-index: -1;
    opacity: 0.15;
}
.bg-glow-1 {
    top: 10%;
    left: -10%;
    background-color: #6366f1;
}
.bg-glow-2 {
    bottom: 10%;
    right: -10%;
    background-color: #ec4899;
}

/* --- 画面管理 (スクリーン) --- */
.screen {
    display: none;
    flex-direction: column;
    height: 100%;
    width: 100%;
    opacity: 0;
    transition: opacity 0.4s ease;
}
.screen.active {
    display: flex;
    opacity: 1;
}

/* --- ボタン共通スタイル --- */
.btn {
    font-family: inherit;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    outline: none;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: white;
    padding: 14px 28px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    font-size: 1rem;
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}
.btn-primary:active {
    transform: translateY(1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 14px 28px;
    font-size: 1rem;
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-2px);
}
.btn-secondary:active {
    transform: translateY(1px);
}

.btn-icon {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 44px;
    height: 44px;
    border-radius: 50%;
}
.btn-icon:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}
.btn-icon:active:not(:disabled) {
    transform: scale(0.95);
}
.btn-icon:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}

#home-screen {
    overflow-y: auto;
    padding-bottom: 24px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
#home-screen::-webkit-scrollbar {
    width: 6px;
}
#home-screen::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.01);
}
#home-screen::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}
#home-screen::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.3);
}

/* --- 1. ホーム画面のスタイリング --- */
.hero-section {
    text-align: center;
    margin-top: 40px;
    margin-bottom: 40px;
}

.logo-text {
    font-size: 3.5rem;
    font-weight: 800;
    letter-spacing: 2px;
    background: linear-gradient(135deg, #a855f7, #6366f1, #06b6d4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 20px rgba(99, 102, 241, 0.2);
    margin-bottom: 8px;
    animation: pulseGlow 3s infinite alternate;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 300;
}

.menu-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 30px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    margin: 0 auto;
    width: 100%;
    max-width: 450px;
    flex-grow: 0;
}

.menu-title {
    font-size: 1.3rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.difficulty-options {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.btn-diff {
    position: relative;
    flex-direction: column;
    padding: 16px;
    text-align: left;
    align-items: flex-start;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    width: 100%;
}
.diff-name, .diff-desc {
    max-width: 70%;
}
.diff-best {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    color: var(--success);
    font-weight: 600;
}
.new-record-badge {
    background: linear-gradient(135deg, #f59e0b, #eab308);
    color: #000;
    font-weight: 800;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    margin: 12px auto 4px auto;
    width: fit-content;
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
    animation: pulseGlow 1.5s infinite alternate;
    letter-spacing: 1px;
}
.btn-diff:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--accent);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.2);
    transform: translateY(-2px);
}
.btn-diff:active {
    transform: translateY(0);
}

.diff-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 4px;
}
.diff-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.footer-info {
    text-align: center;
    margin-top: auto;
    padding-top: 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* --- 2. ゲーム画面のスタイリング --- */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 15px;
}

.game-stats {
    display: flex;
    align-items: center;
    gap: 12px;
}

.badge {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
    border: 1px solid rgba(99, 102, 241, 0.3);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.stat-item {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.game-controls {
    display: flex;
    gap: 8px;
}

/* ゲームボード領域 */
.game-board-wrapper {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
    padding: 10px 0;
    min-height: 0; /* flexの子要素スクロールバグ回避用 */
}

/* ボトルグリッドのレイアウト
   スマートフォン・PCに最適化し、15〜24本のボトルを複数行で綺麗に収める */
/* ボトルグリッドのレイアウト
   スマートフォン・PCに最適化し、15〜24本のボトルを複数行で綺麗に収める */
.bottle-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* デフォルトスマホ: 5列 */
    gap: 12px 6px; /* スマホでは間隔を狭めにして収まりを良くする */
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 650px;
    margin: 0 auto;
    padding: 10px;
}

@media (min-width: 400px) {
    .bottle-grid {
        grid-template-columns: repeat(6, 1fr); /* 6列 */
        gap: 14px 8px;
    }
}

@media (min-width: 600px) {
    .bottle-grid {
        grid-template-columns: repeat(7, 1fr); /* 7列 */
        gap: 16px 10px;
    }
}

@media (min-width: 768px) {
    .bottle-grid {
        grid-template-columns: repeat(8, 1fr); /* PC: 8列 */
        gap: 20px 12px;
    }
}

/* ボトルの外枠デザインとサイズ変数定義 */
.bottle-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    
    /* レスポンシブな基本寸法 (標準的なスマホ用) */
    --bottle-w: 32px;
    --bottle-h: 100px;
    --neck-w: 20px;
    --cork-w: 16px;
    --cork-h: 10px;
}

/* 画面幅に応じたサイズ調整 */
@media (min-width: 400px) {
    .bottle-container {
        --bottle-w: 36px;
        --bottle-h: 110px;
        --neck-w: 24px;
        --cork-w: 20px;
        --cork-h: 12px;
    }
}
@media (min-width: 600px) {
    .bottle-container {
        --bottle-w: 40px;
        --bottle-h: 125px;
        --neck-w: 26px;
        --cork-w: 22px;
        --cork-h: 13px;
    }
}
@media (min-width: 768px) {
    .bottle-container {
        --bottle-w: 44px;
        --bottle-h: 140px;
        --neck-w: 28px;
        --cork-w: 24px;
        --cork-h: 14px;
    }
}

/* 画面の高さが低い場合の縦見切れ対策 (最優先で高さを圧縮) */
@media (max-height: 720px) {
    .app-container {
        padding: 10px;
    }
    .hero-section {
        margin-top: 15px;
        margin-bottom: 15px;
    }
    .logo-text {
        font-size: 2.2rem;
    }
    .subtitle {
        font-size: 0.9rem;
    }
    .menu-container {
        padding: 20px;
        max-width: 380px;
    }
    .btn-diff {
        padding: 12px;
    }
    .bottle-container {
        --bottle-w: 30px;
        --bottle-h: 90px;
        --neck-w: 18px;
        --cork-w: 14px;
        --cork-h: 9px;
    }
}

@media (max-height: 600px) {
    .bottle-container {
        --bottle-w: 28px;
        --bottle-h: 80px;
        --neck-w: 16px;
        --cork-w: 12px;
        --cork-h: 8px;
    }
}

/* ボトル本体 */
.bottle {
    position: relative;
    width: var(--bottle-w);
    height: var(--bottle-h);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 0 0 16px 16px;
    background: rgba(255, 255, 255, 0.02);
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.05),
                0 4px 12px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column-reverse; /* 下から積み上げる */
    transition: all 0.25s ease;
}

/* ボトルのつや（ハイライト線） */
.bottle::after {
    content: '';
    position: absolute;
    top: 5%;
    left: 8%;
    width: 4px;
    height: 90%;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
    pointer-events: none;
    z-index: 5;
}

/* ボトルの口（上部のガラスのふち） */
.bottle-neck {
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: var(--neck-w);
    height: 6px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    background: rgba(255, 255, 255, 0.1);
    z-index: 2;
}

/* 選択されたボトルのアニメーション効果 */
.bottle-container.selected {
    transform: translateY(-16px);
}
.bottle-container.selected .bottle {
    border-color: var(--accent);
    box-shadow: inset 0 0 12px rgba(99, 102, 241, 0.2),
                0 0 20px var(--accent-glow);
}

/* 完成したボトル（栓が閉まる） */
.bottle-container.completed .bottle {
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: not-allowed;
}

/* 栓（コルク）のスタイリングと出現アニメーション */
.cork {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    width: var(--cork-w);
    height: var(--cork-h);
    background: linear-gradient(135deg, #a16207, #78350f);
    border-radius: 4px 4px 2px 2px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    z-index: 10;
    opacity: 0;
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
}

/* コルク栓が閉じた状態 */
.bottle-container.completed .cork {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* 液体ブロック */
.liquid-block {
    width: 100%;
    height: 25%; /* 4分割なので1ブロック25% */
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    box-sizing: border-box;
    transition: height 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    position: relative;
    overflow: hidden;
}

/* 液体表面のウェーブアニメーション（最上部のブロックにのみ波を表示） */
.liquid-block::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -50%;
    width: 200%;
    height: 8px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 40% 40% 0 0;
    animation: waveMotion 4s infinite linear;
    pointer-events: none;
}

/* 注ぎ中アニメーション用の傾きクラス */
.bottle-container.pouring-source {
    z-index: 100;
}

/* 操作指示エリア */
.game-instruction {
    text-align: center;
    padding-top: 10px;
    padding-bottom: 5px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 400;
    min-height: 35px;
}

/* --- 3. モーダル（ゲームオーバー / クリア） --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(5, 5, 8, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 20px;
}
.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: rgba(20, 21, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 28px;
    width: 100%;
    max-width: 420px;
    padding: 35px 30px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5),
                0 0 30px rgba(99, 102, 241, 0.1);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px auto;
}
.error-icon {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.2);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.15);
}
.success-icon {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.15);
}

.modal-title {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}
#gameover-modal .modal-title {
    color: #f87171;
}
#clear-modal .modal-title {
    color: #34d399;
}

.modal-message {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 28px;
    line-height: 1.5;
}

.clear-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
}

.clear-stat-box {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 12px 20px;
    border-radius: 16px;
    min-width: 110px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.clear-stat-box .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}
.clear-stat-box .value {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.modal-buttons .btn {
    width: 100%;
}

/* --- アニメーションの定義 --- */

@keyframes pulseGlow {
    from {
        text-shadow: 0 4px 20px rgba(99, 102, 241, 0.2);
    }
    to {
        text-shadow: 0 4px 30px rgba(99, 102, 241, 0.5), 0 0 10px rgba(168, 85, 247, 0.3);
    }
}

@keyframes waveMotion {
    0% { transform: translateX(0); }
    100% { transform: translateX(50%); }
}

/* グラスモーフィズム共通ルール */
.glassmorphism {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* タブレット・PCのサイズ調整は上記のCSS変数によるスケーリングに統合されました */
