/* Google Fontsの読み込み (モダンな英数・日本語フォント) */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@600;700&family=Noto+Sans+JP:wght@500;700&display=swap');

/* --- Base & Variables --- */
/* --- ベース・変数定義 --- */
:root {
    --color-bg: #f4f0ea; /* 背景のクリーム色 */
    --color-white: #ffffff;
    --color-text-main: #333333;
    --color-terracotta: #d97a62; /* 赤茶色 */
    --color-sage: #839a84;       /* くすんだ緑 */
    --color-sand: #d1bba7;       /* サンドベージュ */
    --color-light-gray: #e0e0e0;
    --color-navy: #2b3a4a;
    --border-radius: 12px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
}

body {
    margin: 0;
    font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
    background-color: #e5e5e5; /* PC閲覧時用の背景 */
    color: var(--color-text-main);
    display: flex;
    justify-content: center;
    -webkit-tap-highlight-color: transparent; /* スマホ特有の青いタップハイライトを無効化 */
}

/* --- Loading Screen --- */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-bg); /* 背景と同じクリーム色 */
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}

.loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--color-sand);
    border-top: 4px solid var(--color-terracotta);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.loading-text {
    color: var(--color-navy);
    font-family: 'Montserrat', sans-serif;
    font-weight: bold;
    letter-spacing: 0.1em;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* スマホサイズのコンテナ */
#app-container {
    width: 100%;
    max-width: 414px; /* iPhone Pro Max幅相当 */
    background-color: var(--color-bg);
    height: 100vh;
    height: 100dvh; /* スマホのURLバーを考慮した全画面の高さ */
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden; /* 画面全体のスクロールを無効化 */
}

/* --- ヘッダー --- */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: var(--spacing-md);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    box-sizing: border-box;
    z-index: 100;
    pointer-events: none; /* スワイプ操作を背面の瓶に貫通させる */
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    color: var(--color-text-main);
    pointer-events: auto; /* ボタンはタッチ可能に */
    transition: opacity 0.2s ease;
}

.icon-btn:active {
    opacity: 0.4; /* タップ時にフワッと薄くなる優しい反応 */
}

.icon-btn.has-profile-img {
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-profile-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--color-light-gray);
}

/* --- メニュー --- */
.menu-container {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background-color: var(--color-white);
    border: 1px solid var(--color-light-gray);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    z-index: 100;
    min-width: 150px;
    pointer-events: auto; /* メニューはタッチ可能に */
}

.dropdown-menu ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.dropdown-menu li {
    padding: var(--spacing-sm) var(--spacing-md);
    cursor: pointer;
    color: var(--color-text-main);
    border-bottom: 1px solid var(--color-light-gray);
}

.dropdown-menu li:last-child {
    border-bottom: none;
}

.dropdown-menu li:hover,
.dropdown-menu li:active {
    background-color: var(--color-bg);
    color: var(--color-terracotta); /* タップ時にテーマカラーのテラコッタ色に変化 */
}

/* --- メインコンテンツ領域 --- */
main {
    display: flex;
    flex-direction: column;
    flex: 1; /* ヘッダーとティッカー以外の高さを埋める */
    overflow: hidden;
}

/* --- 瓶と進捗バー --- */
.bottle-section {
    padding: 0 var(--spacing-md) var(--spacing-md); /* 上部の余白をなくす */
    text-align: center;
    flex: 1; /* 残りの高さを占める（ヘッダーと合わせて約65%になる） */
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.bottle-carousel-container {
    width: 100%;
    flex: 1; /* 高さを自動調整 */
    position: relative;
    overflow: hidden;
    touch-action: pan-y; /* 縦スクロールは許可、横スワイプをJSで処理 */
    margin: 0 auto;
}

.bottle-name-overlay {
    position: absolute;
    bottom: 35px; /* プログレスバーが上に被さるため、被らないように上に配置 */
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85rem; /* 文字サイズを少し小さく */
    color: var(--color-navy);
    font-weight: bold;
    pointer-events: none;
    z-index: 30; /* progress-containerより手前 */
    background: rgba(255, 255, 255, 0.7);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Montserrat', 'Noto Sans JP', sans-serif;
    letter-spacing: 0.02em;
}

.progress-container {
    margin-top: -4vh; /* キャンバス領域にめり込ませて上に寄せる */
    padding: 0 var(--spacing-lg);
    flex-shrink: 0; /* プログレスバーが潰れないようにする */
    position: relative;
    z-index: 20; /* キャンバスより手前に表示 */
}

.progress-bar {
    width: 100%;
    height: 24px;
    background-color: var(--color-light-gray);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background-color: var(--color-terracotta);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: width 0.5s ease;
    min-width: 15%; /* パーセンテージ文字が見える最小幅 */
}

#progress-text {
    color: var(--color-white);
    font-size: 0.8rem;
    font-weight: bold;
    white-space: nowrap;
    font-family: 'Montserrat', sans-serif;
    letter-spacing: 0.05em;
}

.amount-display {
    margin-top: var(--spacing-sm);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--color-text-main);
    font-family: 'Montserrat', sans-serif;
    letter-spacing: 0.02em;
}

/* --- つもりボタンセクション --- */
.buttons-section {
    padding: var(--spacing-md);
    background-color: var(--color-white);
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    height: 35vh; /* 高さ35%に拡大 (5%広げる) */
    flex-shrink: 0;
    overflow-y: auto; /* ボタンが多い場合はこのエリア内でスクロール */
}

.buttons-section h2 {
    font-size: 1.2rem;
    margin-top: 0;
    margin-bottom: var(--spacing-md);
    text-align: center;
    font-family: 'Montserrat', 'Noto Sans JP', sans-serif;
    letter-spacing: 0.05em;
}

/* 3列のグリッドレイアウト */
.button-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.tsumori-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1.15; /* 少し縦長にして余裕を持たせる */
    border-radius: 16px; /* 丸みを少し大きくして優しい印象に */
    border: 1px solid rgba(255, 255, 255, 0.4); /* うっすらとしたハイライト枠線 */
    cursor: pointer;
    color: var(--color-white);
    font-weight: bold;
    padding: var(--spacing-sm);
    
    /* カフェモダンなリッチな立体感（グラデーションと複数シャドウの組み合わせ） */
    background-image: linear-gradient(135deg, rgba(255,255,255,0.25) 0%, rgba(255,255,255,0) 50%, rgba(0,0,0,0.05) 100%);
    box-shadow: 
        0 6px 12px rgba(0,0,0,0.08), 
        inset 0 2px 4px rgba(255,255,255,0.5), 
        inset 0 -4px 6px rgba(0,0,0,0.05);
    text-shadow: 0 1px 2px rgba(0,0,0,0.15); /* 文字の視認性を高める影 */
    
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    
    position: relative;

    /* ドラッグ時のテキスト選択やメニュー表示を防止 */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.tsumori-btn:active {
    transform: translateY(4px); /* 押し込みを深くする */
    box-shadow: 
        0 2px 4px rgba(0,0,0,0.1), 
        inset 0 2px 4px rgba(255,255,255,0.3), 
        inset 0 -2px 4px rgba(0,0,0,0.05);
}

.tsumori-btn img.btn-icon {
    width: 56px;
    height: 56px;
    margin-bottom: 6px;
    object-fit: contain;
    filter: drop-shadow(0 4px 4px rgba(0,0,0,0.15)); /* アイコンにも影をつけて浮かせる */
    
    /* 長押しメニューや画像のドラッグを防ぐ */
    pointer-events: none;
    -webkit-user-drag: none;
}

.tsumori-btn span {
    font-size: 0.85rem;
    text-align: center;
    line-height: 1.2;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.tsumori-btn .btn-amount {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    margin-top: 2px;
    background-color: rgba(255, 255, 255, 0.95); /* 値札のような白いバッジ */
    color: var(--color-navy); /* 金額の文字色はネイビーで引き締める */
    padding: 3px 12px;
    border-radius: 20px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    text-shadow: none; /* バッジ内の文字には影をつけない */
}

/* --- つもりボタン 編集/削除バッジ --- */
.delete-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 24px;
    height: 24px;
    background-color: #e74c3c;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 10;
}

.edit-badge {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 24px;
    height: 24px;
    background-color: var(--color-sage);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 10;
}

/* --- 編集モード時のスタイル --- */
.tsumori-btn.edit-mode-active {
    background-color: #e0e0e0 !important;
    color: #888888 !important;
    border-color: #cccccc !important;
    box-shadow: none;
}

.tsumori-btn.edit-mode-active img.btn-icon {
    opacity: 0.4;
    filter: grayscale(100%);
}

/* 各ボタンの背景色（動的に付与） */
.bg-terracotta { background-color: var(--color-terracotta); }
.bg-sage { background-color: var(--color-sage); }
.bg-sand { background-color: var(--color-sand); }

/* 新規作成ボタン専用のスタイル */
.new-create-btn {
    background-color: #fdfaf6; /* よりカフェっぽいクリーム色 */
    background-image: none; /* グラデーションなし */
    border: 2px dashed var(--color-sand);
    color: var(--color-sand);
    box-shadow: none;
    text-shadow: none;
}

.new-create-btn .plus-icon {
    font-size: 28px;
    font-weight: normal;
    margin-bottom: 5px;
}

/* --- Sortable Drag Styles --- */
.sortable-ghost {
    opacity: 0.4;
}

.sortable-drag {
    cursor: grabbing !important;
    box-shadow: 0 8px 12px rgba(0,0,0,0.2) !important;
}

/* --- リアルタイム通知ティッカー --- */
.ticker-container {
    position: relative;
    width: 100%;
    height: 5vh; /* 残り5%の高さ */
    min-height: 30px;
    background-color: rgba(43, 58, 74, 1);
    overflow: hidden;
    flex-shrink: 0;
    pointer-events: auto; /* タップ可能にする */
    cursor: pointer;
}

.ticker-message {
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%) translateX(0);
    white-space: nowrap;
    color: var(--color-white);
    font-size: 0.85rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: ticker-slide-rtl 12s linear forwards;
}

.ticker-profile-img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    background-color: var(--color-white);
}

@keyframes ticker-slide-rtl {
    0% { left: 100%; transform: translateY(-50%) translateX(0); }
    100% { left: 0; transform: translateY(-50%) translateX(-100%); }
}

/* --- トースト通知 --- */
.toast-container {
    position: absolute;
    bottom: 8vh; /* ティッカーより少し上に配置 */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}

.toast-message {
    background-color: rgba(43, 58, 74, 0.95); /* --color-navy の透過 */
    color: var(--color-white);
    padding: 12px 20px;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: bold;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    text-align: center;
    opacity: 0;
    transform: translateY(20px);
    animation: toast-fade-in 0.3s forwards, toast-fade-out 0.3s 3s forwards;
}

@keyframes toast-fade-in {
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-fade-out {
    to { opacity: 0; transform: translateY(-10px); }
}

/* --- Congratulations Modern --- */
.congratulations-modern {
    position: fixed;
    top: 35%; /* 瓶の上部あたり */
    left: 50%;
    white-space: nowrap;
    font-size: clamp(1.1rem, 5.5vw, 1.8rem); /* 画面幅に合わせて文字サイズを自動調整 */
    font-weight: 500; /* 太すぎない上品な太さ */
    color: var(--color-navy);
    background-color: rgba(244, 240, 234, 0.85); /* アプリ背景色(クリーム色)の半透明 */
    padding: clamp(10px, 2.5vw, 15px) clamp(20px, 5vw, 40px); /* 余白も自動調整 */
    border-radius: 50px;
    border: 1px solid var(--color-sand);
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
    backdrop-filter: blur(4px); /* すりガラス効果 */
    z-index: 999999;
    pointer-events: none;
    animation: congrats-fade 6s cubic-bezier(0.25, 1, 0.5, 1) forwards; /* 4秒から1.5倍の6秒に変更 */
    font-family: 'Montserrat', sans-serif;
    letter-spacing: 0.1em; /* はみ出し防止のため文字間隔を少しだけ詰める */
    text-transform: uppercase;
}

@keyframes congrats-fade {
    0% { opacity: 0; transform: translate(-50%, -30%) scale(0.95); }
    10% { opacity: 1; transform: translate(-50%, -50%) scale(1); } /* 現れる速度はキープ */
    90% { opacity: 1; transform: translate(-50%, -50%) scale(1); } /* 長く表示してから消える */
    100% { opacity: 0; transform: translate(-50%, -70%) scale(0.95); }
}

/* --- 貯金時の光の粒子エフェクト --- */
.deposit-light-particle {
    position: fixed;
    top: 0;
    left: 0;
    width: 10px;
    height: 10px;
    /* JSから渡されたボタンの色を使用して発色させる */
    background: radial-gradient(circle, var(--particle-color, rgba(217, 122, 98, 1)) 0%, var(--particle-color-alpha, rgba(217, 122, 98, 0.6)) 50%, var(--particle-color-transparent, rgba(217, 122, 98, 0)) 100%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 10000;
    box-shadow: 0 0 10px var(--particle-color-alpha, rgba(217, 122, 98, 0.6));
}
