/* 共通スタイル */
html {
    height: 100%;
    /* ダブルタップ拡大を完全に防止 */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: pan-y pan-x;
}
body {
    background-color: #000;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    /* ★修正: Watchのクラウンでスクロールさせるため、body自体のスクロールを許可 */
    overflow-y: auto; 
    overflow-x: hidden;
    min-height: 100%;
    /* 拡大防止 */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: pan-y pan-x;
    /* ダブルタップ拡大防止 */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    /* ヘッダーがページ最上部に確実に表示されるように */
    position: relative;
}
.hidden { display: none !important; }

/* ダブルタップ拡大を完全防止 */
* {
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

/* コンテナ定義 */
.container {
    width: 100%;
    box-sizing: border-box;
    padding-top: 50px; /* ヘッダーの高さ分の余白を追加 */
    position: relative;
}

/* 各画面の設定 (スクロール設定を削除し、自然な表示に) */
#view-parts, #view-exercises, #view-settings {
    width: 100%;
    padding: 15px;
    padding-bottom: 30px; /* 下部に余白を追加 */
    box-sizing: border-box;
}

#view-history {
    width: 100%;
    padding: 15px;
    padding-bottom: 30px;
    box-sizing: border-box;
    /* タブがstickyで動くようにoverflow設定なし */
}

/* ★修正: グリッドレイアウト */
.grid {
    display: grid;
    /* 2列。minmax(0, 1fr)で強制的に枠内に収める */
    grid-template-columns: repeat(2, minmax(0, 1fr)); 
    gap: 15px; /* 標準の間隔 */
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

/* ★修正: 円形ボタン */
.circle-btn {
    /* 枠いっぱいだと重なるので少し小さくする */
    width: 85%; 
    aspect-ratio: 1 / 1; 
    border-radius: 50%; 
    border: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: white; font-weight: bold; font-size: 14px;
    cursor: pointer; 
    transition: all 0.01s ease; /* 0.05s → 0.01s 最高速 */
    position: relative; overflow: hidden; 
    padding: 0; 
    background-color: #333; 
    /* セルの中央に配置 */
    margin: 0 auto; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
    /* タップ感度向上 */
    -webkit-tap-highlight-color: rgba(0, 122, 255, 0.3);
    touch-action: manipulation; /* タップ遅延を完全排除 */
    -webkit-user-select: none;
    user-select: none;
}
.circle-btn:active { 
    transform: scale(0.82); 
    box-shadow: 0 2px 6px rgba(0,0,0,0.8);
    filter: brightness(1.6);
    background-color: #007aff !important;
    transition: none; /* 即座に反応 */
}
/* タップ時のフラッシュエフェクト */
.circle-btn.tapped {
    animation: tapFlash 0.2s ease; /* 0.4s → 0.2s 高速化 */
}
@keyframes tapFlash {
    0% { 
        filter: brightness(1); 
        transform: scale(1);
    }
    25% { 
        filter: brightness(1.8); 
        transform: scale(0.82);
        background-color: #007aff;
    }
    50% { 
        filter: brightness(1.6); 
        transform: scale(0.85);
    }
    100% { 
        filter: brightness(1); 
        transform: scale(1);
    }
}
.circle-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.circle-btn svg { width: 50%; height: 50%; margin-bottom: 5px; fill: currentColor; }

/* カラー定義 */
.bg-red { background: linear-gradient(135deg, #ff3b30, #ff6b6b); }
.bg-green { background: linear-gradient(135deg, #34c759, #5dd879); }
.bg-blue { background: linear-gradient(135deg, #007aff, #5fa3ff); }
.bg-purple { background: linear-gradient(135deg, #af52de, #c77dff); }
.bg-orange { background: linear-gradient(135deg, #ff9500, #ffcc00); }
.bg-yellow { background: linear-gradient(135deg, #ffcc00, #ffee00); color: #333; }
.bg-dark { background: #333; }

/* --- 入力画面 --- */
#view-input {
    width: 100%;
    position: relative;
}

#view-input:not(.hidden) {
    display: block;
}

/* スクロールエリア */
.scroll-content {
    padding: 10px 20px;
    /* フッターの高さ分だけ下に余白を確保（たっぷりと） */
    padding-bottom: 140px;
}

.input-card { background: transparent; }
.controls-wrapper { display: flex; justify-content: center; gap: 0; width: 100%; margin-bottom: 20px; border-bottom: 1px solid #333; padding-bottom: 20px; }
.control-group { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 50%; padding: 8px 0; } /* gap: 5px → 8px、padding: 5px → 8px */
.controls-wrapper .control-group:first-child { border-right: 1px solid rgba(255, 255, 255, 0.1); }
.step-btn { 
    width: 70px; /* 60px → 70px に拡大 */
    height: 44px; /* 36px → 44px に拡大 */
    border-radius: 22px; /* 18px → 22px */
    background: #333; 
    border: none; 
    color: white; 
    font-size: 28px; /* 24px → 28px */
    display: flex; 
    align-items: center; 
    justify-content: center; 
    cursor: pointer;
    transition: all 0.01s ease; /* 0.03s → 0.01s 最高速 */
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    -webkit-tap-highlight-color: rgba(0, 122, 255, 0.4);
    /* タップ領域を拡大（視覚サイズより大きく） */
    position: relative;
    /* タッチ感度を最大化 */
    touch-action: none;
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
        /* 長押しメニュー無効化 */
}
.step-btn::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    /* デバッグ用: background: rgba(255,0,0,0.1); */
}
.step-btn:active { 
    background: #007aff; 
    transform: scale(0.85); /* 0.82 → 0.85 少し大きく */
    box-shadow: 0 1px 4px rgba(0,0,0,0.6);
    filter: brightness(1.5);
    transition: none; /* トランジション無し＝即座に反応 */
}
/* touchstartで即座に反応させる */
.step-btn.btn-active {
    background: #007aff !important;
    transform: scale(0.85) !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.6) !important;
    filter: brightness(1.5) !important;
    transition: none !important; /* 即座に適用 */
}
.premium-display { 
    width: 95px; 
    height: 48px; 
    background-color: #000000; 
    border-radius: 10px; 
    border: 1px solid #333; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    cursor: pointer; 
    padding: 0 5px;
    transition: all 0.01s ease; /* 0.05s → 0.01s 最高速 */
    -webkit-tap-highlight-color: rgba(0, 122, 255, 0.3);
    touch-action: manipulation; /* タップ遅延を完全排除 */
    -webkit-user-select: none;
    user-select: none;
}
.premium-display:active {
    transform: scale(0.88);
    background-color: #007aff;
    border-color: #007aff;
    filter: brightness(1.4);
    box-shadow: 0 0 15px rgba(0, 122, 255, 0.6);
    transition: none; /* 即座に反応 */
}
input[type="number"] { 
    width: auto; 
    max-width: 60px; 
    background: none; 
    border: none; 
    color: #fff; 
    font-size: 28px; /* 16px以上で自動ズーム防止 */ 
    font-weight: bold; 
    outline: none; 
    pointer-events: none; 
    text-align: right; 
}
.unit-label { font-size: 12px; color: #888; font-weight: bold; margin-left: 3px; padding-top: 4px; }

/* 固定フッター（画面下に常に固定） */
.footer-area { 
    position: fixed !important; 
    bottom: 0 !important; 
    left: 0 !important; 
    right: 0 !important; 
    padding: 8px 15px 15px 15px; 
    background: rgba(0,0,0,0.98); 
    backdrop-filter: blur(10px); 
    border-top: 1px solid #333; 
    z-index: 9999 !important; /* 最優先で表示 */
    box-shadow: 0 -2px 10px rgba(0,0,0,0.5);
    pointer-events: auto !important; /* クリック可能 */
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* view-inputが非表示の時はfooter-areaも非表示にする */
#view-input.hidden ~ .footer-area,
#view-input.hidden .footer-area {
    display: none !important;
}

/* view-inputが表示されている時だけfooter-areaを表示 */
body:has(#view-input:not(.hidden)) .footer-area {
    display: block !important;
}

/* ピッカーが開いている時はfooter-areaを非表示 */
body:has(.picker-modal:not(.hidden)) .footer-area {
    opacity: 0 !important;
    transform: translateY(100%) !important;
    pointer-events: none !important;
}

.record-btn { 
    width: 100%; 
    padding: 10px; 
    background: #007aff; 
    border: none; 
    border-radius: 12px; 
    color: white; 
    font-size: 15px; 
    font-weight: bold; 
    box-shadow: 0 4px 15px rgba(0, 122, 255, 0.4); 
    cursor: pointer;
    transition: all 0.01s ease; /* 0.05s → 0.01s 最高速 */
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.3);
    touch-action: manipulation; /* タップ遅延を完全排除 */
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

.record-btn:active { 
    background: #0051a8;
    transform: scale(0.96);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.6);
    filter: brightness(1.3);
    transition: none; /* 即座に反応 */
}

/* 押下時のリップル効果 */
.record-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    transform: translate(-50%, -50%);
    transition: width 0.5s, height 0.5s;
}

.record-btn:active::before {
    width: 400px;
    height: 400px;
}

/* ヘッダー */
#header-bar { 
    position: absolute; /* sticky → absolute に変更 */
    top: 0; 
    left: 0; 
    right: 0; 
    height: 50px; 
    background: rgba(0,0,0,0.95); 
    backdrop-filter: blur(10px); 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    padding: 0 5px; 
    z-index: 1000; 
    border-bottom: 1px solid #333; 
}
#page-title { font-size: 16px; font-weight: bold; margin: 0; pointer-events: none; }
#header-date-nav { display: flex; align-items: center; justify-content: center; width: 100%; }
#display-date { 
    font-size: 14px; 
    font-weight: bold; 
    color: #fff; 
    background: #333; 
    border-radius: 12px; 
    padding: 4px 12px; 
    margin: 0 5px; 
    cursor: pointer;
    transition: all 0.05s ease; /* 0.15s → 0.05s 高速化 */
    -webkit-tap-highlight-color: rgba(0, 122, 255, 0.3);
}
#display-date:active {
    transform: scale(0.90);
    background: #1a1a1a;
    filter: brightness(1.3);
    transition: all 0.02s ease; /* active時はさらに高速 */
}

.header-side-btn { 
    position: absolute; 
    top: 0; 
    bottom: 0; 
    /* width: 50px; を削除して幅可変に */
    display: flex; 
    align-items: center; 
    justify-content: center; 
    z-index: 1001; 
}
.header-side-btn.left { 
    left: 0; 
    /* width: 50px; を削除 */
    padding-left: 5px; /* 左端に余白 */
    gap: 0; 
}
.header-side-btn.right { 
    right: 0; 
    padding-right: 5px; /* 右端に余白 */
    gap: 0; 
}

.header-btn { 
    background: none; 
    border: none; 
    color: #007aff; 
    cursor: pointer; 
    padding: 0; 
    width: 50px; 
    height: 50px; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    transition: all 0.01s ease; /* 0.05s → 0.01s 最高速 */
    text-decoration: none; /* リンクの下線を消す */
    -webkit-tap-highlight-color: rgba(0, 122, 255, 0.3);
    touch-action: manipulation; /* タップ遅延を完全排除 */
}
.header-btn:active {
    transform: scale(0.80);
    opacity: 0.5;
    filter: brightness(1.4);
    transition: none; /* 即座に反応 */
}
.header-btn svg { 
    width: 40px; 
    height: 40px; 
}

/* カレンダー */
.cal-day { 
    aspect-ratio: 1; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    border-radius: 50%; 
    font-size: 14px; 
    color: #fff; 
    box-sizing: border-box; 
    cursor: pointer;
    transition: all 0.01s ease; /* 0.05s → 0.01s 最高速 */
    -webkit-tap-highlight-color: rgba(0, 122, 255, 0.3);
    touch-action: manipulation; /* タップ遅延を完全排除 */
}
.cal-day:active {
    transform: scale(0.80);
    filter: brightness(1.6);
    background-color: rgba(0, 122, 255, 0.5) !important;
    transition: none; /* 即座に反応 */
}
.cal-day.today { background-color: #007aff; border: none; font-weight: bold; }
.cal-day.selected { 
    border: 2px solid #007aff; 
    color: #fff; 
    box-shadow: 0 0 10px rgba(0, 122, 255, 0.6);
}
.cal-day.today.selected { border: 2px solid #fff; }
.cal-day.has-data { 
    background-color: rgba(52, 199, 89, 0.3); 
    font-weight: bold; 
}

/* 履歴タブ */
.history-tabs {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding: 10px 0;
    margin-bottom: 15px;
    border-bottom: 1px solid #333;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    position: sticky;
    top: 50px;
    background: #000;
    z-index: 10;
}
.history-tabs::-webkit-scrollbar { display: none; }

.history-tab {
    flex-shrink: 0;
    padding: 8px 12px;
    background: #1c1c1e;
    border: 1px solid #333;
    border-radius: 20px;
    color: #888;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.05s ease; /* 0.2s → 0.05s 高速化 */
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
    -webkit-tap-highlight-color: rgba(0, 122, 255, 0.3);
}

.history-tab:active {
    transform: scale(0.92);
    filter: brightness(1.5);
    background: #2c2c2e;
    transition: all 0.02s ease; /* active時はさらに高速 */
}

.history-tab.active {
    background: linear-gradient(135deg, #007aff, #0051d5);
    border-color: #007aff;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.5);
}

.history-tab.active:active {
    background: linear-gradient(135deg, #0051a8, #003d8f);
    filter: brightness(1.3);
}

.history-tab.has-data::after {
    /* バッジで件数を表示するため、緑丸は不要に */
    content: none;
}

/* 履歴コンテナのスムーズな切り替え */
#history-items-container {
    transition: opacity 0.15s ease;
}

#history-items-container.updating {
    opacity: 0.5;
}

/* ピッカー（スクロール防止用クラスがある時だけ背景固定） */
body.no-scroll { overflow: hidden; }

.picker-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 2000; display: flex; flex-direction: column; justify-content: flex-end; }
.picker-content { 
    background: #1c1c1e; 
    border-top-left-radius: 20px; 
    border-top-right-radius: 20px; 
    padding: 10px 15px 15px 15px; 
    text-align: center; 
    max-height: 70vh; 
    height: 70vh;
    display: flex; 
    flex-direction: column; 
}
.picker-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 8px; 
    width: 100%; 
    flex-shrink: 0;
    min-height: 60px;
    height: 60px;
}
.picker-title { font-weight: bold; font-size: 16px; color: #fff; flex-grow: 1; }
.picker-close { 
    color: #007aff; 
    border: none; 
    background: none; 
    cursor: pointer; 
    padding: 0; 
    width: 60px; 
    height: 60px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    flex-shrink: 0;
    transition: all 0.05s ease; /* 0.15s → 0.05s 高速化 */
    -webkit-tap-highlight-color: rgba(0, 122, 255, 0.3);
}
.picker-close:active {
    transform: scale(0.85);
    opacity: 0.6;
    transition: all 0.02s ease; /* active時はさらに高速 */
}
.picker-close svg { width: 28px; height: 28px; fill: none; stroke: currentColor; }
.picker-close.cancel { color: #888; } 
.picker-wheel-container { 
    position: relative; 
    flex-grow: 1; 
    overflow: hidden; 
    min-height: 200px;
    mask-image: linear-gradient(to bottom, transparent, black 20%, black 80%, transparent); 
    -webkit-mask-image: linear-gradient(to bottom, transparent, black 20%, black 80%, transparent); 
}
.picker-highlight { 
    position: absolute; 
    top: 50%; 
    left: 0; 
    width: 100%; 
    height: 50px; 
    margin-top: -25px;
    border-top: 1px solid #555; 
    border-bottom: 1px solid #555; 
    background: rgba(255,255,255,0.08); 
    pointer-events: none; 
    z-index: 10; 
}
.picker-wheel { 
    position: relative; 
    height: 100%; 
    overflow-y: scroll; 
    scroll-snap-type: y mandatory; 
    padding: 0; 
    -webkit-overflow-scrolling: touch; 
    touch-action: pan-y; 
    overscroll-behavior: contain; 
}
.picker-wheel::-webkit-scrollbar { display: none; }
.picker-item {
    height: 50px;
    min-height: 50px;
    max-height: 50px;
    font-size: 36px;
    color: #666;
    scroll-snap-align: center;
    transition: color 0.1s, font-size 0.1s;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;

    /* ★ここを修正: パディングを高さに含めて、下から押し上げる */
    box-sizing: border-box;
    padding-bottom: 35px;
    /* この数値を増やすと数字がさらに上に上がります */
}

.picker-item.active { 
    color: #fff; 
    font-weight: bold; 
    font-size: 44px; 
}

/* ★重要: Apple Watchなどの極小画面（幅340px以下）用調整 */
@media (max-width: 340px) {
    #view-parts, #view-exercises, #view-settings, #view-history {
        /* 横の余白を減らす */
        padding: 10px 5px; 
    }
    
    .grid {
        /* 間隔を確保 */
        gap: 10px; 
    }
    
    .circle-btn {
        /* ボタンをさらに小さくして重なりを完全回避 */
        width: 80%; 
        /* 文字サイズも少し小さく */
        font-size: 12px;
    }
    
    .footer-area {
        padding: 5px 8px 8px 8px;
    }
    
    .record-btn {
        padding: 8px;
        font-size: 14px;
    }
    
    .scroll-content {
        padding: 8px 10px;
        padding-bottom: 80px; /* フッター分の余白 */
    }
    
    /* ピッカーの調整 */
    .picker-content {
        max-height: 80vh;
        height: 80vh;
        padding: 8px 10px 10px 10px;
    }
    
    .picker-header {
        min-height: 50px;
        height: 50px;
        margin-bottom: 5px;
    }
    
    .picker-close {
        width: 50px;
        height: 50px;
    }
    
    .picker-close svg {
        width: 24px;
        height: 24px;
    }
    
    .picker-title {
        font-size: 14px;
    }
    
    .picker-wheel-container {
        min-height: 180px;
    }
    
    /* +/-ボタンのサイズ調整（小画面でも押しやすく） */
    .step-btn {
        width: 65px; /* 70px → 65px */
        height: 40px; /* 44px → 40px */
        font-size: 26px; /* 28px → 26px */
    }
    
    .control-group {
        gap: 6px; /* 8px → 6px */
    }
}