:root {
    --primary: #6366f1;
    /* Indigo */
    --primary-light: #818cf8;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-sub: #64748b;
    --border: #e2e8f0;

    /* Category Colors */
    --cat-health: #f43f5e;
    --cat-health-bg: #ffe4e6;
    --cat-study: #0ea5e9;
    --cat-study-bg: #e0f2fe;
    --cat-mind: #f59e0b;
    --cat-mind-bg: #fef3c7;
    --cat-sport: #10b981;
    --cat-sport-bg: #d1fae5;
    --cat-other: #64748b;
    --cat-other-bg: #f1f5f9;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

/* 横揺れ防止：全体設定 */
html,
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    padding-bottom: 90px;
    overflow-x: hidden;
    /* 横スクロールを禁止 */
    width: 100%;
    position: relative;
}

a {
    text-decoration: none;
    color: inherit;
}

.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.content-area {
    flex: 1;
    width: 100%;
    padding-bottom: 80px;
    /* スマホ用ナビの余白 */
    position: relative;
}

/* Header */
/* Header (スマホ版修正) */
.home-header {
    padding: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    /* 要素間の余白 */
}

.header-left {
    flex: 1;
    min-width: 0;
    /* フレックスボックス内で省略表示を効かせるために必須 */
    display: flex;
    align-items: center;
}

.user-greeting-wrapper {
    overflow: hidden;
    /* はみ出し防止 */
}

.greeting {
    font-size: 14px;
    color: var(--text-sub);
    margin-bottom: 4px;
}

.username-display {
    font-size: 24px;
    font-weight: 800;
    white-space: nowrap;
    /* 改行しない */
    overflow: hidden;
    /* はみ出しを隠す */
    text-overflow: ellipsis;
    /* 「...」を表示 */
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    /* 画面が狭くなってもアイコンを潰さない */
}

.profile-icon {
    width: 40px;
    height: 40px;
    background: #e2e8f0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: var(--text-sub);
    flex-shrink: 0;
}

.btn-icon-sub {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f1f5f9;
    flex-shrink: 0;
}

/* Stats Cards */
.stats-container {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 16px;
    padding: 0 24px 24px;
}

.stat-card {
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 140px;
}

.primary-card {
    background: var(--primary);
    color: white;
    box-shadow: 0 10px 20px -5px rgba(99, 102, 241, 0.4);
}

.secondary-card {
    background: var(--bg-card);
    color: var(--text-main);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.stat-icon {
    font-size: 24px;
    margin-bottom: 12px;
}

.stat-value {
    font-size: 32px;
    font-weight: 800;
    display: block;
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    opacity: 0.8;
}

/* Section Header */
.section-header {
    padding: 0 24px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
}

.section-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.badge {
    background: #e0e7ff;
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

/* Habit List */
.habit-list {
    padding: 0 24px;
    margin-bottom: 12px;
}

.habit-item {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    border: 1px solid transparent;
    transition: all 0.2s;
}

.habit-item.completed {
    border-color: var(--primary);
    background: #f5f7ff;
}

.habit-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    cursor: pointer;
}

.check-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.habit-item.completed .check-btn {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.habit-info h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.habit-meta {
    font-size: 12px;
    font-weight: 600;
}

/* Category Colors */
.cat-health {
    color: var(--cat-health);
}

.cat-study {
    color: var(--cat-study);
}

.cat-sport {
    color: var(--cat-sport);
}

.cat-mind {
    color: var(--cat-mind);
}

.cat-other {
    color: var(--cat-other);
}

.streak-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
}

/* Bottom Nav - 修正：優先度を高くして常に表示 */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 600px;
    height: 70px;
    background: var(--bg-card);
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid var(--border);
    z-index: 1000;
    /* 分析画面(z-index:200)より手前に */
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.03);
}

.nav-btn {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-sub);
    font-size: 10px;
    cursor: pointer;
}

.nav-btn.active {
    color: var(--primary);
}

.nav-btn .material-icons-round {
    font-size: 24px;
}

.nav-btn:active {
    transform: scale(0.95);
}

.nav-fab-wrapper {
    position: relative;
    top: -20px;
}

.nav-fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 16px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    transition: transform 0.2s;
}

.nav-fab:active {
    transform: scale(0.95);
}

/* Overlays (Add/Detail) - 修正：横揺れ防止設定 */
.overlay-view {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-body);
    z-index: 200;
    overflow-y: auto;
    padding-bottom: 90px;
    /* ナビバーの分だけ余白を確保 */
    animation: slideUp 0.3s ease;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    /* 横スクロールを完全禁止 */
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.hidden {
    display: none !important;
}

.detail-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-main);
    cursor: pointer;
}

/* Form Styles */
.form-group {
    padding: 0 24px;
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 8px;
}

/* 一般的な入力フォーム */
.form-group input[type="text"] {
    width: 100%;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: var(--bg-card);
    font-size: 16px;
}

/* Auth Input Styles - 修正：ログイン画面の入力欄を大きく綺麗にする */
.input-group input {
    width: 100%;
    padding: 16px;
    padding-left: 48px !important;
    /* アイコン分のスペース */
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 16px;
    height: 52px;
    /* 高さを明示的に確保 */
    box-sizing: border-box;
    transition: all 0.2s;
}

.input-group input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.category-chips {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.category-chips input {
    display: none;
}

.chip {
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
}

.chip.health {
    background: var(--cat-health-bg);
    color: var(--cat-health);
}

.chip.study {
    background: var(--cat-study-bg);
    color: var(--cat-study);
}

.chip.sport {
    background: var(--cat-sport-bg);
    color: var(--cat-sport);
}

.chip.mind {
    background: var(--cat-mind-bg);
    color: var(--cat-mind);
}

.chip.other {
    background: var(--cat-other-bg);
    color: var(--cat-other);
}

input:checked+.chip {
    border-color: currentColor;
    box-shadow: 0 0 0 2px currentColor inset;
}

.hint-box {
    background: #fffbeb;
    padding: 16px;
    border-radius: 12px;
    display: flex;
    gap: 12px;
    margin-top: 12px;
    font-size: 13px;
    color: #b45309;
    line-height: 1.5;
}

.btn-primary-large {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: calc(100% - 48px);
    margin: 0 24px;
    padding: 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.habit-loop-card {
    margin: 24px;
    background: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
}

.loop-item {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.loop-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.loop-icon.trigger {
    background: #ede9fe;
    color: #8b5cf6;
}

.loop-icon.routine {
    background: #e0e7ff;
    color: #6366f1;
}

.loop-icon.reward {
    background: #fce7f3;
    color: #ec4899;
}

.loop-content label {
    font-size: 12px;
    color: var(--text-sub);
    display: block;
    margin-bottom: 4px;
}

.loop-content p {
    font-weight: 600;
}

.btn-danger-outline {
    display: block;
    width: calc(100% - 48px);
    margin: 40px 24px;
    padding: 14px;
    background: transparent;
    border: 1px solid #ef4444;
    color: #ef4444;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
}

/* Calendar Grid */
.calendar-container {
    padding: 0 24px;
    margin-bottom: 24px;
}

.calendar-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
}

.cal-cell {
    aspect-ratio: 1;
    border-radius: 50%;
    background: #e2e8f0;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-sub);
}

.cal-cell.done {
    background: var(--primary);
    color: white;
}

/* --- 追加機能のスタイル --- */

/* ログアウトボタン */
.btn-icon-sub {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f1f5f9;
    transition: background 0.2s;
}

.btn-icon-sub:hover {
    background: #e2e8f0;
}

/* タイプ選択スイッチャー */
.type-selector-group {
    margin-bottom: 20px !important;
}

.type-selector {
    display: flex;
    background: #e2e8f0;
    border-radius: 12px;
    padding: 4px;
}

.type-selector input {
    display: none;
}

.type-label {
    flex: 1;
    text-align: center;
    padding: 10px;
    border-radius: 10px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1.2;
    font-size: 14px;
}

.type-selector input:checked+.type-label.task-label {
    background: white;
    color: var(--primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.type-selector input:checked+.type-label.habit-label {
    background: white;
    color: var(--primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Auth Pages (Login/Register) */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f1f5f9;
}

.auth-container {
    display: flex;
    max-width: 900px;
    width: 100%;
    background: white;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    margin: 20px;
    flex-direction: column;
}

.auth-visual {
    background: linear-gradient(135deg, var(--primary) 0%, #4f46e5 100%);
    color: white;
    padding: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-logo-large {
    font-size: 24px;
    font-weight: 800;
    display: block;
    margin-bottom: 16px;
}

.auth-visual h1 {
    font-size: 28px;
    line-height: 1.3;
    margin-bottom: 16px;
}

.auth-form-wrapper {
    padding: 30px;
    flex: 1;
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-header h2 {
    font-size: 24px;
    color: var(--text-main);
}

.auth-header p {
    color: var(--text-sub);
    font-size: 14px;
}

.input-group {
    margin-bottom: 20px;
}

.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-icon .material-icons-round {
    position: absolute;
    left: 12px;
    color: var(--text-sub);
    font-size: 20px;
}

.btn-primary {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    background: var(--primary);
    color: white;
    font-weight: bold;
    cursor: pointer;
    font-size: 16px;
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 14px;
    color: var(--text-sub);
}

.sub-btn {
    color: var(--primary);
    font-weight: bold;
    margin-left: 5px;
}

/* Auth Responsive */
@media (min-width: 768px) {
    .auth-container {
        flex-direction: row;
    }

    .auth-visual {
        width: 45%;
        border-radius: 0;
    }

    .auth-form-wrapper {
        padding: 50px;
    }
}

/* 3つのタイプセレクター */
.type-selector-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: #e2e8f0;
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
}

.type-selector-3 input {
    display: none;
}

.type-label-3 {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
    gap: 4px;
    text-align: center;
    background: transparent;
    color: var(--text-sub);
}

.type-label-3 .material-icons-round {
    font-size: 20px;
}

.type-selector-3 input:checked+.type-label-3 {
    background: white;
    color: var(--primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* カテゴリ追加ボタン */
.btn-add-category {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-add-category:active {
    transform: scale(0.95);
}

.btn-add-category .material-icons-round {
    font-size: 18px;
}

/* モーダル */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.3s;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 700;
}

/* カラーチップ */
.color-chips {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.color-chips input {
    display: none;
}

.color-chip {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.2s;
}

.color-chip.health {
    background: var(--cat-health);
}

.color-chip.study {
    background: var(--cat-study);
}

.color-chip.sport {
    background: var(--cat-sport);
}

.color-chip.mind {
    background: var(--cat-mind);
}

.color-chip.other {
    background: var(--cat-other);
}

input:checked+.color-chip {
    border-color: var(--text-main);
    transform: scale(1.1);
}

/* カラーピッカー */
#input-category-color {
    width: 100%;
    height: 50px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
}

/* カテゴリチップに削除ボタン */
.chip-wrapper {
    position: relative;
    display: inline-block;
}

.chip-delete {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ef4444;
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s;
}

.chip-wrapper:hover .chip-delete {
    opacity: 1;
}

.date-indicator {
    font-size: 11px;
    color: var(--text-sub);
    margin-top: 2px;
}

/* ヘッダーロゴ */
.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: linear-gradient(135deg, var(--primary) 0%, #4f46e5 100%);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.logo-icon {
    font-size: 24px;
}

.logo-text {
    font-size: 18px;
    font-weight: 800;
    color: white;
    letter-spacing: 0.5px;
}

.user-info {
    display: flex;
    flex-direction: column;
}

/* カスタム日付ピッカー */
.date-picker-custom {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.date-quick-btn {
    padding: 8px 16px;
    background: #e0e7ff;
    color: var(--primary);
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.date-quick-btn:hover {
    background: var(--primary);
    color: white;
}

#input-date {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 14px;
}

/* 曜日セレクター */
.weekday-selector {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.weekday-selector input {
    display: none;
}

.weekday-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #f1f5f9;
    color: var(--text-sub);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.weekday-selector input:checked+.weekday-btn {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
}

/* 分析画面 - 修正：横揺れ対応 */
.analysis-container {
    padding: 0 24px 24px;
}

.analysis-card {
    background: white;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.analysis-card h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--text-main);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.stat-item {
    text-align: center;
    padding: 16px;
    background: #f8fafc;
    border-radius: 12px;
}

.stat-number {
    display: block;
    font-size: 28px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 4px;
}

.stat-text {
    font-size: 12px;
    color: var(--text-sub);
}

/* 空の状態 */
.empty-state {
    text-align: center;
    padding: 60px 24px;
}

.empty-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    color: var(--text-sub);
    font-size: 14px;
}

/* 設定リスト */
.settings-list {
    padding: 0 24px;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: white;
    border-radius: 12px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.setting-item:hover {
    background: #f8fafc;
}

.setting-item .material-icons-round {
    color: var(--primary);
}

/* レスポンシブ調整 */
@media (max-width: 480px) {
    .app-logo {
        padding: 6px 12px;
    }

    .logo-text {
        font-size: 14px;
    }

    .header-left {
        gap: 12px;
    }
}

/* 分析タブ */
.analysis-tabs {
    display: flex;
    gap: 8px;
    padding: 0 24px 16px;
    position: sticky;
    top: 0;
    background: var(--bg-body);
    z-index: 10;
}

.analysis-tab {
    flex: 1;
    padding: 10px;
    background: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.2s;
}

.analysis-tab.active {
    background: var(--primary);
    color: white;
}

/* 分析コンテンツ - 修正：横揺れ対応 */
.analysis-content {
    /* 左右のパディング調整で幅を安全に保つ */
    padding: 0 16px 100px;
    width: 100%;
    overflow-x: hidden;
}

/* ミニ統計カード */
.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.mini-stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 16px;
    padding: 16px;
    text-align: center;
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.mini-stat-card:nth-child(2) {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.mini-stat-card:nth-child(3) {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.mini-stat-label {
    font-size: 11px;
    opacity: 0.9;
    margin-bottom: 8px;
}

.mini-stat-value {
    font-size: 24px;
    font-weight: 800;
}

/* 棒グラフ - 修正：レスポンシブ幅 */
.chart-container {
    padding: 16px 0;
    width: 100%;
    overflow-x: auto;
}

.bar-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 200px;
    gap: 8px;
    width: 100%;
}

.bar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.bar {
    width: 100%;
    background: linear-gradient(to top, var(--primary), var(--primary-light));
    border-radius: 8px 8px 0 0;
    /* heightプロパティの変化をアニメーションさせる */
    transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 4px;
    /* 0%でも少し見えるように */
}

.bar-label {
    font-size: 12px;
    color: var(--text-sub);
    font-weight: 600;
}

.bar-value {
    font-size: 10px;
    color: var(--text-main);
    font-weight: 700;
}

/* 習慣パフォーマンス */
.performance-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: #f8fafc;
    border-radius: 12px;
    margin-bottom: 12px;
}

.performance-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.performance-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.performance-info h4 {
    font-size: 14px;
    margin-bottom: 4px;
}

.performance-info p {
    font-size: 12px;
    color: var(--text-sub);
}

.performance-rate {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
}

/* 達成バッジ */
.badge-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* スマホは2列 */
    gap: 12px;
}
.achievement-badge {
    aspect-ratio: 1;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    transition: all 0.3s;
}

.achievement-badge.unlocked {
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
    box-shadow: 0 4px 12px rgba(253, 203, 110, 0.4);
}

.achievement-badge.locked {
    background: #e2e8f0;
    opacity: 0.5;
}

.badge-icon {
    font-size: 32px;
}

.badge-name {
    font-size: 10px;
    font-weight: 600;
    text-align: center;
}

/* ヒートマップ - 修正：レスポンシブ幅 */
.heatmap-container {
    padding: 16px 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.heatmap-months {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    width: 100%;
}

.month-nav-btn {
    background: #f1f5f9;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-main);
    transition: all 0.2s;
}

.month-nav-btn:hover {
    background: var(--primary);
    color: white;
}

#heatmap-month-label {
    font-weight: 700;
    font-size: 14px;
}

.heatmap-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 16px;
    width: 100%;
    max-width: 350px;
    /* カレンダーが横に伸びすぎないようにする */
}

.heatmap-day {
    aspect-ratio: 1;
    border-radius: 4px;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-sub);
    transition: all 0.2s;
}

.heatmap-day.level-1 {
    background: #c7d2fe;
    color: var(--primary);
}

.heatmap-day.level-2 {
    background: #a5b4fc;
    color: white;
}

.heatmap-day.level-3 {
    background: var(--primary);
    color: white;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-sub);
}

.legend-box {
    width: 16px;
    height: 16px;
    border-radius: 3px;
}

.legend-box.level-0 {
    background: #e2e8f0;
}

.legend-box.level-1 {
    background: #c7d2fe;
}

.legend-box.level-2 {
    background: #a5b4fc;
}

.legend-box.level-3 {
    background: var(--primary);
}

/* アニメーション */
@keyframes barGrow {
    from {
        transform: scaleY(0);
    }

    to {
        transform: scaleY(1);
    }
}

.bar {
    animation: barGrow 0.5s ease-out;
    transform-origin: bottom;
}

/* --- PC/タブレット用レイアウト (サイドバー化) --- */
.desktop-only {
    display: none;
}

/* スマホでは隠す */

@media (min-width: 1024px) {

    /* スマホ用要素を非表示 */
    .mobile-only {
        display: none !important;
    }

    .mobile-only-flex {
        display: none !important;
    }

    .desktop-only {
        display: block;
    }

    /* 全体レイアウト：横並び */
    .app-layout {
        flex-direction: row;
    }

    /* サイドバーナビゲーション設定 */
    .main-nav {
        position: sticky;
        top: 0;
        left: 0;
        width: 260px;
        /* サイドバー幅 */
        height: 100vh;
        background: white;
        border-top: none;
        border-right: 1px solid var(--border);
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        padding: 0;
        box-shadow: none;
        transform: none;
        /* 中央寄せ解除 */
    }

    /* サイドバー内のロゴ */
    .sidebar-header {
        padding: 32px 24px;
        margin-bottom: 10px;
    }

    .app-logo-sidebar {
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .app-logo-sidebar .logo-icon {
        font-size: 24px;
    }

    .app-logo-sidebar .logo-text {
        font-size: 20px;
        font-weight: 800;
        color: var(--primary);
    }

    /* ナビゲーション項目（縦並び） */
    .nav-items {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        max-width: none;
        padding: 0 16px;
        gap: 8px;
        height: auto;
    }

    .nav-btn {
        flex-direction: row;
        width: 100%;
        padding: 12px 16px;
        gap: 16px;
        border-radius: 8px;
        font-size: 15px;
        transition: background 0.2s;
    }

    .nav-btn:hover {
        background: #f1f5f9;
    }

    .nav-btn.active {
        background: #e0e7ff;
        color: var(--primary);
    }

    .nav-label {
        font-size: 15px;
        font-weight: 500;
    }

    .nav-btn .material-icons-round {
        font-size: 22px;
    }

    /* サイドバーフッター (プロフィール) */
    .sidebar-footer {
        margin-top: auto;
        padding: 24px;
        border-top: 1px solid var(--border);
    }

    .sidebar-user {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 16px;
        background: #f8fafc;
        padding: 12px;
        border-radius: 12px;
    }

    .profile-icon-small {
        width: 32px;
        height: 32px;
        background: var(--primary);
        color: white;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: bold;
    }

    .sidebar-username {
        font-size: 14px;
        font-weight: 700;
    }

    .sidebar-logout {
        display: flex;
        align-items: center;
        gap: 8px;
        color: #ef4444;
        font-size: 14px;
        font-weight: 600;
        padding-left: 12px;
        cursor: pointer;
    }

    /* メインコンテンツ調整 */
    .content-area {
        padding-bottom: 0;
        background: #f8fafc;
        max-width: 1000px;
        margin: 0 auto;
        overflow-y: auto;
    }

    /* PC用ヘッダー */
    .desktop-header {
        padding: 32px 24px 20px;
    }

    .desktop-header h2 {
        font-size: 24px;
        font-weight: 800;
        color: var(--text-main);
    }

    /* オーバーレイ（モーダル）調整 */
    .overlay-view {
        position: relative;
        z-index: 1;
        padding-bottom: 40px;
        background: transparent;
        animation: none;
        max-width: 800px;
        margin: 0 auto;
    }

    .view.hidden {
        display: none !important;
    }

    /* グリッド調整 (PCでは列数を増やす) */
    .stats-container {
        grid-template-columns: repeat(2, 1fr);
    }

    .badge-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}