/* リセット & ベーススタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #10b981;
    --secondary-dark: #059669;
    --accent: #f59e0b;
    --danger: #ef4444;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text: #f1f5f9;
    --text-light: #94a3b8;
    --border: #334155;
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    padding-bottom: 70px;
    min-height: 100vh;
}

/* ヘッダー */
.header {
    background: var(--surface);
    padding: 20px 16px;
    box-shadow: 0 4px 16px var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
}

.user-stats {
    max-width: 600px;
    margin: 0 auto;
}

.level-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 20px;
    font-weight: bold;
    color: var(--primary-light);
}

.level-icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.xp-container {
    width: 100%;
}

.xp-bar {
    width: 100%;
    height: 8px;
    background: var(--surface-light);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.xp-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    transition: width 0.5s ease;
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

.xp-text {
    text-align: center;
    font-size: 13px;
    color: var(--text-light);
    font-weight: 500;
}

/* メインコンテンツ */
.main-content {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px 16px;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

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

.section-header h2 {
    font-size: 28px;
    color: var(--text);
    font-weight: 700;
}

/* ボタン */
.btn-add {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
    transition: all 0.3s ease;
}

.btn-add i {
    width: 24px;
    height: 24px;
}

.btn-add:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 100px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 2px solid var(--border);
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-secondary i {
    width: 20px;
    height: 20px;
}

.btn-secondary:hover {
    background: var(--surface-light);
    border-color: var(--primary);
}

.btn-secondary:active {
    transform: scale(0.98);
}

/* 習慣リスト */
.habit-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.habit-item {
    background: var(--surface);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 12px var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.habit-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.habit-item.completed {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(5, 150, 105, 0.15));
    border-color: var(--secondary);
}

.habit-checkbox {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 12px;
    border: 3px solid var(--primary);
    background: var(--surface-light);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.habit-checkbox i {
    width: 28px;
    height: 28px;
    color: transparent;
    transition: all 0.3s ease;
}

.habit-item.completed .habit-checkbox {
    background: var(--secondary);
    border-color: var(--secondary);
}

.habit-item.completed .habit-checkbox i {
    color: white;
}

.habit-info {
    flex: 1;
}

.habit-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.habit-icon {
    width: 24px;
    height: 24px;
    color: var(--primary-light);
}

.habit-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.habit-stats {
    display: flex;
    gap: 16px;
    font-size: 14px;
    color: var(--text-light);
}

.habit-stat {
    display: flex;
    align-items: center;
    gap: 6px;
}

.habit-stat i {
    width: 16px;
    height: 16px;
}

/* 空の状態 */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-light);
}

.empty-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    color: var(--primary);
    opacity: 0.5;
}

.empty-hint {
    font-size: 14px;
    margin-top: 12px;
}

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

.stat-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 20px 12px;
    text-align: center;
    box-shadow: 0 4px 12px var(--shadow);
    border: 2px solid var(--border);
    transition: all 0.3s ease;
}

.stat-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.stat-icon {
    width: 32px;
    height: 32px;
    margin: 0 auto 12px;
    color: var(--primary-light);
}

.stat-value {
    font-size: 28px;
    font-weight: bold;
    color: var(--primary-light);
    margin-bottom: 8px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-light);
    font-weight: 500;
}

/* バッジ */
.badges-section {
    margin-bottom: 32px;
}

.badges-section h3 {
    font-size: 20px;
    margin-bottom: 16px;
    color: var(--text);
}

.badges-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 12px;
}

.badge-item {
    background: var(--surface);
    border-radius: 16px;
    padding: 16px 12px;
    text-align: center;
    box-shadow: 0 4px 12px var(--shadow);
    border: 2px solid var(--border);
    transition: all 0.3s ease;
}

.badge-item.locked {
    opacity: 0.3;
}

.badge-item:not(.locked):hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.badge-icon {
    width: 40px;
    height: 40px;
    margin: 0 auto 8px;
    color: var(--accent);
}

.badge-name {
    font-size: 11px;
    color: var(--text-light);
    font-weight: 500;
}

/* カレンダー */
.calendar-section h3 {
    font-size: 20px;
    margin-bottom: 16px;
    color: var(--text);
}

.calendar {
    background: var(--surface);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 12px var(--shadow);
    border: 2px solid var(--border);
}

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

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 12px;
    background: var(--surface-light);
    color: var(--text-light);
    font-weight: 500;
    transition: all 0.3s ease;
}

.calendar-day.completed {
    background: var(--secondary);
    color: white;
    font-weight: bold;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.calendar-day.today {
    border: 2px solid var(--primary);
}

/* 設定 */
.settings-section {
    margin-bottom: 32px;
}

.settings-section h3 {
    font-size: 20px;
    margin-bottom: 16px;
    color: var(--text);
}

.habit-manage-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.habit-manage-item {
    background: var(--surface);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 4px 12px var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
    border: 2px solid var(--border);
}

.habit-manage-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.habit-manage-info i {
    width: 24px;
    height: 24px;
    color: var(--primary-light);
}

.btn-delete {
    background: var(--danger);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-delete:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

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

.app-info {
    color: var(--text-light);
    font-size: 14px;
    margin-bottom: 8px;
}

/* ボトムナビゲーション */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    box-shadow: 0 -4px 16px var(--shadow);
    z-index: 100;
    border-top: 1px solid var(--border);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--text-light);
    transition: all 0.3s ease;
}

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

.nav-icon {
    width: 24px;
    height: 24px;
}

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

/* モーダル */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 20px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px var(--shadow);
    border: 2px solid var(--border);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 22px;
    color: var(--text);
}

.btn-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-light);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.btn-close i {
    width: 24px;
    height: 24px;
}

.btn-close:hover {
    background: var(--surface-light);
}

.modal-body {
    padding: 24px;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 12px;
    font-weight: 600;
    color: var(--text);
    font-size: 15px;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 16px;
    transition: all 0.3s ease;
    background: var(--surface-light);
    color: var(--text);
}

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

.icon-picker {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.icon-btn {
    aspect-ratio: 1;
    background: var(--surface-light);
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn i {
    width: 24px;
    height: 24px;
    color: var(--text-light);
}

.icon-btn.selected {
    background: var(--primary);
    border-color: var(--primary);
}

.icon-btn.selected i {
    color: white;
}

.icon-btn:hover {
    border-color: var(--primary);
    transform: scale(1.05);
}

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

.modal-footer {
    display: flex;
    gap: 12px;
    padding: 24px;
    border-top: 1px solid var(--border);
}

.modal-footer .btn-secondary,
.modal-footer .btn-primary {
    flex: 1;
    margin: 0;
}

/* トースト通知 */
.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface);
    color: var(--text);
    padding: 16px 28px;
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--shadow);
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s ease;
    border: 2px solid var(--border);
    font-weight: 500;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* アニメーション */
@keyframes checkmark {
    0% {
        transform: scale(0) rotate(0deg);
    }
    50% {
        transform: scale(1.2) rotate(180deg);
    }
    100% {
        transform: scale(1) rotate(360deg);
    }
}

.habit-checkbox.animate {
    animation: checkmark 0.5s ease;
}

/* レスポンシブ対応 */
@media (min-width: 769px) {
    .stats-cards {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .badges-list {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
    
    .icon-picker {
        grid-template-columns: repeat(6, 1fr);
    }
}
