/* === Reset & Variables === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #C9A96E;
    --primary-dark: #B08D4F;
    --primary-light: #F5EDD8;
    --primary-gradient: linear-gradient(135deg, #D4B074 0%, #B99355 100%);
    --accent: #A68B5B;
    --accent-light: #F0E6D2;
    --danger: #C0392B;
    --warning: #D4A853;
    --purple: #8B7355;
    --purple-light: #F0EBE3;
    --pink: #C49A6C;
    --pink-light: #FAF3EA;
    --orange: #B8860B;
    --orange-light: #FDF6E8;
    --indigo: #7C6B52;
    --indigo-light: #EDE8E0;
    --teal: #8B7D6B;
    --teal-light: #F2EDE5;
    --brown: #6B5B3E;
    --brown-light: #F5EDD8;
    --bg: #FBF8F3;
    --bg-card: #FFFFFF;
    --text: #1A1714;
    --text-secondary: #6B6560;
    --text-tertiary: #9C958D;
    --border: #E8E0D4;
    --border-light: #F3EEE6;
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
    --radius: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --radius-full: 9999px;
    --nav-height: 72px;
    --header-height: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.01em;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* === Screens === */
.screen { display: none; height: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* === Auth === */
#auth-screen {
    background: linear-gradient(160deg, #FBF8F3 0%, #F5EDD8 30%, #FBF8F3 70%);
}

.auth-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 32px 24px;
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.auth-logo {
    text-align: center;
    margin-bottom: 40px;
}

.auth-logo svg {
    filter: drop-shadow(0 4px 12px rgba(201, 169, 110, 0.3));
}

.auth-logo h1 {
    font-size: 32px;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-top: 16px;
    letter-spacing: -0.03em;
}

.auth-logo p {
    color: var(--text-secondary);
    font-size: 15px;
    margin-top: 6px;
    font-weight: 500;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-switch {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
}

/* === Forms === */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.form-group small {
    font-size: 12px;
    color: var(--text-tertiary);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 16px;
    font-family: inherit;
    background: var(--bg-card);
    color: var(--text);
    transition: all 0.2s ease;
    -webkit-appearance: none;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(201, 169, 110, 0.2);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    letter-spacing: -0.01em;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 2px 8px rgba(201, 169, 110, 0.3);
}
.btn-primary:active {
    transform: scale(0.97);
    box-shadow: 0 1px 4px rgba(201, 169, 110, 0.2);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}
.btn-outline:active { background: var(--primary-light); }

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:active { opacity: 0.85; }

.btn-block { width: 100%; }
.btn-large { padding: 16px 24px; font-size: 16px; border-radius: var(--radius); }
.btn-small { padding: 8px 16px; font-size: 13px; }
.btn-upload { position: relative; }

.icon-btn {
    background: none;
    border: none;
    padding: 10px;
    cursor: pointer;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    transition: all 0.2s ease;
}
.icon-btn:active { background: var(--border-light); transform: scale(0.92); }

/* === Header === */
#app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    padding-top: calc(10px + var(--safe-top));
    height: calc(var(--header-height) + var(--safe-top));
    background: rgba(251, 248, 243, 0.88);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(232, 224, 212, 0.6);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 4px;
}

.header-left h2 {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.header-right .icon-btn {
    background: var(--border-light);
    width: 40px;
    height: 40px;
}

/* === Main Content === */
#main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 20px;
}

.page {
    display: none;
    padding: 20px;
    padding-bottom: 32px;
    min-height: 100%;
    animation: pageIn 0.25s ease;
    overflow-x: hidden;
    max-width: 100%;
}
.page.active { display: block; }

@keyframes pageIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}


/* === Home === */
.home-hero {
    background: var(--primary-gradient);
    border-radius: var(--radius);
    padding: 24px;
    color: white;
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(201, 169, 110, 0.25);
}

.home-hero::before {
    content: '';
    position: absolute;
    top: -30px;
    right: -30px;
    width: 120px;
    height: 120px;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
}

.home-hero::after {
    content: '';
    position: absolute;
    bottom: -40px;
    right: 30px;
    width: 80px;
    height: 80px;
    background: rgba(255,255,255,0.08);
    border-radius: 50%;
}

.home-hero h2 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.home-hero p {
    font-size: 14px;
    opacity: 0.85;
    font-weight: 500;
}

.home-stats-row {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.home-stat-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(8px);
    padding: 10px 16px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease;
    border: none;
    color: white;
}

.home-stat-pill:active {
    background: rgba(255,255,255,0.3);
}

.home-stat-pill svg {
    width: 18px;
    height: 18px;
    opacity: 0.9;
}

.section-title {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 16px;
    color: var(--text);
    letter-spacing: -0.02em;
}

.section-subtitle {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-top: -12px;
    margin-bottom: 16px;
    font-weight: 500;
}

/* === Tools Grid - New Section Layout === */
.tools-section {
    margin-bottom: 24px;
}

.tools-section-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
    padding-left: 4px;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.tool-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 18px 8px 14px;
    background: var(--bg-card);
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    text-align: center;
    line-height: 1.3;
}

.tool-card:active {
    transform: scale(0.94);
    box-shadow: var(--shadow-md);
}

.tool-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.tool-card:active .tool-icon {
    transform: scale(1.08);
}

/* === Featured Scanner Banner === */
.scanner-banner {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 20px;
    background: linear-gradient(135deg, #EDE9FE 0%, #FCE7F3 100%);
    border: 1.5px solid rgba(139, 92, 246, 0.15);
    border-radius: var(--radius);
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    overflow: hidden;
    max-width: 100%;
}

.scanner-banner:active {
    transform: scale(0.98);
}

.scanner-banner-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.scanner-banner-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.scanner-banner-text h4 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scanner-banner-text p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scanner-banner-arrow {
    color: var(--text-tertiary);
    flex-shrink: 0;
}

/* === Habits === */
.habits-level-bar {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow);
    padding: 16px 18px 14px;
    margin-bottom: 14px;
}

.habits-level-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.habits-level-badge {
    font-size: 15px;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.habits-level-pts {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
}

.habits-progress-track {
    width: 100%;
    height: 8px;
    background: var(--border-light);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.habits-progress-fill {
    height: 100%;
    background: var(--primary-gradient);
    border-radius: var(--radius-full);
    transition: width 0.4s ease;
}

.habits-level-next {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 6px;
    font-weight: 500;
    text-align: right;
}

.habits-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
    overflow: hidden;
}

.habits-stat-item {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border-light);
    padding: 12px 6px;
    text-align: center;
    min-width: 0;
    overflow: hidden;
}

.habits-stat-value {
    font-size: 18px;
    font-weight: 800;
    color: var(--primary-dark);
    letter-spacing: -0.02em;
}

.habits-stat-label {
    font-size: 10px;
    color: var(--text-tertiary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 2px;
}

.habits-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.habit-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    transition: all 0.25s ease;
}

.habit-item.completed {
    background: var(--primary-light);
    border-color: rgba(201, 169, 110, 0.25);
}

.habit-check {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    border: 2.5px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s ease;
    flex-shrink: 0;
    background: none;
    font-size: 18px;
}

.habit-emoji {
    font-size: 18px;
    line-height: 1;
}

.habit-check.checked {
    background: var(--primary-gradient);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 2px 6px rgba(201, 169, 110, 0.3);
    animation: habitPop 0.3s ease;
}

@keyframes habitPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.habit-info { flex: 1; min-width: 0; overflow: hidden; }

.habit-name {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.01em;
}

.habit-streak {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 2px;
    font-weight: 500;
}

.habit-delete {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-full);
    transition: all 0.2s ease;
}
.habit-delete:active { background: #FEE2E2; color: var(--danger); }

/* Calendar */
.habits-calendar-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 80px;
}

.habits-month-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 14px;
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
}

.habits-month-nav .icon-btn {
    background: var(--border-light);
    width: 34px;
    height: 34px;
}

.calendar-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 6px;
}

.cal-day-name {
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    padding: 4px 0;
}

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

.cal-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--border-light);
    transition: all 0.2s ease;
}

.cal-cell.empty {
    background: transparent;
}

.cal-cell.done {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 3px rgba(201, 169, 110, 0.3);
}

.cal-cell.partial {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.cal-cell.today {
    outline: 2.5px solid var(--primary);
    outline-offset: -1px;
}

.cal-cell.future {
    opacity: 0.35;
}

/* Confetti */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 400;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    top: -10px;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    animation: confettiFall 1s ease-out forwards;
}

@keyframes confettiFall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Emoji grid in modal */
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
}

.emoji-option {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.15s ease;
}

.emoji-option.selected {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(201, 169, 110, 0.25);
}

/* === Weight & Measures === */
.weight-summary {
    text-align: center;
    padding: 28px 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.weight-current {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
}

.weight-value {
    font-size: 52px;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.04em;
    line-height: 1;
}

.weight-unit {
    font-size: 20px;
    color: var(--text-tertiary);
    font-weight: 600;
}

.weight-change {
    font-size: 14px;
    margin-top: 8px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: var(--radius-full);
}

.weight-change.positive {
    color: var(--danger);
    background: #FEF2F2;
}
.weight-change.negative {
    color: #5D8A3C;
    background: #EDF5E5;
}

.chart-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    height: 220px;
}

.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    background: var(--border-light);
    border-radius: var(--radius-md);
    padding: 4px;
}

.tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.25s ease;
}

.tab.active {
    background: var(--bg-card);
    color: var(--primary);
    box-shadow: var(--shadow);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow-xs);
}

.history-date {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.history-value {
    font-size: 16px;
    font-weight: 800;
    color: var(--text);
}

/* === Scanner Hub === */
.scanner-hub {
    padding: 20px 0;
}

.scanner-hub-header {
    text-align: center;
    padding: 20px 20px 28px;
}

.scanner-hub-icon {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.scanner-hub-header h3 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

.scanner-hub-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.scanner-hub-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 16px;
}

.scanner-hub-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-card);
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius);
    padding: 20px;
    padding-right: 40px;
    cursor: pointer;
    text-align: left;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    font-family: inherit;
    width: 100%;
}

.scanner-hub-card:active {
    transform: scale(0.98);
}

.scanner-hub-card-icon {
    width: 56px;
    height: 56px;
    min-width: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scanner-hub-card h4 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text);
}

.scanner-hub-card p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
    margin: 0;
}

.scanner-hub-card-arrow {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
}

/* === Scanner === */
.scanner-intro {
    text-align: center;
    padding: 40px 20px 32px;
}

.scanner-icon {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.scanner-icon.purple { background: var(--purple-light); }
.scanner-icon.indigo { background: var(--indigo-light); }
.scanner-icon.orange { background: var(--orange-light); }

.scanner-intro h3 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.scanner-intro p {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.5;
    max-width: 300px;
    margin: 0 auto;
}

.scanner-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 20px;
    max-width: 340px;
    margin: 0 auto;
}

.scanner-preview {
    margin-top: 20px;
    text-align: center;
    padding: 0 20px;
}

.scanner-preview img {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    object-fit: contain;
    box-shadow: var(--shadow-md);
}

.scanner-result {
    margin: 20px;
    padding: 24px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow);
    line-height: 1.7;
    font-size: 14px;
    overflow-wrap: break-word;
    word-break: break-word;
    overflow-x: hidden;
}

.scanner-result h4 {
    color: var(--primary);
    margin-bottom: 8px;
    font-size: 16px;
}

.scanner-result .good { color: var(--primary); font-weight: 700; }
.scanner-result .okay { color: var(--warning); font-weight: 700; }
.scanner-result .bad { color: var(--danger); font-weight: 700; }

/* === Videos === */
.video-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.video-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
}
.video-card:active { transform: scale(0.96); }

.video-thumb {
    width: 100%;
    aspect-ratio: 3 / 4;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.video-thumb-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    z-index: 1;
}

.video-thumb-emoji {
    font-size: 32px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.video-thumb-num {
    font-size: 28px;
    font-weight: 900;
    color: rgba(255,255,255,0.9);
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.video-play-icon {
    position: absolute;
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.2);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1.5px solid rgba(255,255,255,0.3);
    top: 8px;
    right: 8px;
}

.video-play-icon svg {
    width: 16px;
    height: 16px;
}

/* === Profile === */
.profile-header {
    text-align: center;
    padding: 28px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-full);
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
    box-shadow: 0 4px 12px rgba(201, 169, 110, 0.15);
}

.profile-header h3 {
    font-size: 20px;
    font-weight: 800;
}

.profile-header p {
    color: var(--text-tertiary);
    font-size: 14px;
    margin-top: 2px;
}

.profile-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 14px;
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow-xs);
}

.profile-section h4 {
    font-size: 14px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 14px;
    letter-spacing: -0.01em;
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 23, 20, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-card);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    padding-bottom: var(--safe-bottom);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* === Toast === */
.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 14px 28px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 600;
    z-index: 300;
    animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
    box-shadow: var(--shadow-xl);
    max-width: calc(100vw - 32px);
    overflow: hidden;
    text-overflow: ellipsis;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(12px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* === FAB === */
.fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 58px;
    height: 58px;
    border-radius: var(--radius-full);
    background: var(--primary-gradient);
    color: white;
    border: none;
    box-shadow: 0 6px 20px rgba(201, 169, 110, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 50;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.fab:active {
    transform: scale(0.88);
    box-shadow: 0 3px 10px rgba(201, 169, 110, 0.25);
}

/* === Loading === */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px;
}

.spinner {
    width: 42px;
    height: 42px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: var(--radius-full);
    animation: spin 0.7s linear infinite;
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 56px 32px;
    color: var(--text-tertiary);
}

.empty-state svg {
    opacity: 0.4;
}

.empty-state p {
    margin-top: 14px;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.5;
}

/* === Gamification === */

/* Level Card */
.gami-level-card {
    background: var(--primary-gradient);
    border-radius: var(--radius);
    padding: 18px 20px 14px;
    margin-bottom: 14px;
    color: white;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(201, 169, 110, 0.3);
}

.gami-level-card::after {
    content: '';
    position: absolute;
    top: -20px;
    right: -20px;
    width: 80px;
    height: 80px;
    background: rgba(255,255,255,0.08);
    border-radius: 50%;
}

.gami-level-top {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.gami-level-icon {
    font-size: 36px;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.gami-level-details {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.gami-level-name {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gami-xp-text {
    font-size: 12px;
    opacity: 0.8;
    font-weight: 600;
    margin-top: 2px;
}

.gami-streak-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255,255,255,0.2);
    padding: 8px 12px;
    border-radius: var(--radius-full);
    backdrop-filter: blur(4px);
}

.gami-streak-fire {
    font-size: 18px;
    animation: firePulse 1s ease infinite;
}

@keyframes firePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.gami-streak-num {
    font-size: 18px;
    font-weight: 800;
}

.gami-progress-track {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.2);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.gami-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #FFD700, #FFF176);
    border-radius: var(--radius-full);
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
}

/* Missions */
.gami-missions {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 14px;
}

.gami-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.01em;
}

.gami-missions-count {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
    background: var(--primary-light);
    padding: 3px 10px;
    border-radius: var(--radius-full);
}

.mission-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    background: var(--bg);
    transition: all 0.2s ease;
}

.mission-item:last-child { margin-bottom: 0; }

.mission-item.done {
    background: #EDF5E5;
    opacity: 0.7;
}

.mission-icon {
    font-size: 18px;
    width: 28px;
    text-align: center;
}

.mission-text {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mission-xp {
    font-size: 12px;
    font-weight: 800;
    color: var(--primary);
    background: var(--primary-light);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.mission-item.done .mission-xp {
    background: #D4EDDA;
    color: #28A745;
}

/* Badges */
.gami-badges {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 14px;
}

.gami-see-all {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}

.badge-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.badge-item {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    border-radius: var(--radius-md);
    font-size: 22px;
    box-shadow: var(--shadow-xs);
    animation: badgeIn 0.3s ease;
}

@keyframes badgeIn {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

/* Quick Stats */
.gami-quick-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 14px;
    overflow: hidden;
}

.gami-qs-item {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border-light);
    padding: 10px 4px;
    text-align: center;
    min-width: 0;
    overflow: hidden;
}

.gami-qs-val {
    font-size: 20px;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.gami-qs-label {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 2px;
}

/* XP Float */
.xp-float {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-weight: 900;
    color: #FFD700;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 500;
    pointer-events: none;
    animation: xpFloat 1.5s ease-out forwards;
}

@keyframes xpFloat {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(0.5); }
    30% { opacity: 1; transform: translate(-50%, -70%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -120%) scale(0.8); }
}

/* Level Up Modal */
.level-up-icon {
    font-size: 72px;
    animation: levelUpBounce 0.6s ease;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.2));
}

@keyframes levelUpBounce {
    0% { transform: scale(0) rotate(-10deg); }
    60% { transform: scale(1.3) rotate(5deg); }
    100% { transform: scale(1) rotate(0); }
}

.level-up-title {
    font-size: 28px;
    font-weight: 900;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-top: 12px;
    letter-spacing: -0.03em;
}

.level-up-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin-top: 4px;
}

/* Achievements List */
.achievements-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.achievement-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--bg);
    transition: all 0.2s ease;
}

.achievement-row.unlocked {
    background: var(--primary-light);
    border: 1.5px solid rgba(201, 169, 110, 0.2);
}

.achievement-row.locked {
    opacity: 0.5;
}

.achievement-icon {
    font-size: 28px;
    width: 40px;
    text-align: center;
}

.achievement-info {
    flex: 1;
}

.achievement-title {
    font-size: 14px;
    font-weight: 800;
    color: var(--text);
}

.achievement-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 1px;
}

.achievement-check {
    font-size: 18px;
}

/* Weight Gamification */
.weight-journey {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 14px;
}

.weight-journey-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.wj-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 600;
}

.wj-value {
    font-size: 18px;
    font-weight: 900;
}

.wj-value.positive {
    color: #5D8A3C;
}

.wj-value.negative {
    color: var(--danger);
}

.weight-milestones-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.weight-milestone {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 700;
    background: var(--bg);
    color: var(--text-tertiary);
    border: 1.5px solid var(--border-light);
}

.weight-milestone.reached {
    background: #EDF5E5;
    color: #5D8A3C;
    border-color: rgba(93, 138, 60, 0.2);
}

.wm-icon {
    font-size: 14px;
}

/* Video Progress */
.video-progress-bar {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1.5px solid var(--border-light);
    box-shadow: var(--shadow);
    padding: 14px 16px;
    margin-bottom: 14px;
}

.video-progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.video-progress-bar .gami-progress-track {
    background: var(--border-light);
}

.video-progress-bar .gami-progress-fill {
    background: var(--primary-gradient);
    box-shadow: none;
}

/* Scan Counter */
.scan-counter {
    text-align: center;
    padding: 12px;
    margin-top: 16px;
}

.scan-counter-num {
    font-size: 32px;
    font-weight: 900;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.scan-counter-label {
    display: block;
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 600;
    margin-top: 2px;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 28px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: var(--shadow-xs);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* === Utilities === */
.hidden { display: none !important; }

/* === Animations === */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Responsive === */
@media (min-width: 768px) {
    .tools-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    #main-content {
        max-width: 540px;
        margin: 0 auto;
    }

    .modal {
        border-radius: 20px;
        margin-bottom: 10vh;
    }

    .modal-overlay {
        align-items: center;
    }
}

@media (max-width: 374px) {
    .tools-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .home-hero h2 {
        font-size: 22px;
    }

    .habits-stats-grid,
    .gami-quick-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .scanner-banner {
        padding: 14px 16px;
        gap: 12px;
    }

    .gami-level-name {
        font-size: 14px;
    }

    .gami-streak-badge {
        padding: 6px 10px;
    }
}

/* === Collapsible Categories === */
.collapsible-category {
    margin-bottom: 12px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border-light);
    background: var(--bg-card);
    box-shadow: var(--shadow-xs);
}

.category-header {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 16px 18px;
    background: var(--bg-card);
    border: none;
    cursor: pointer;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.2s ease;
}

.category-header:active {
    background: var(--border-light);
}

.category-header-icon {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.category-header-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.category-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.category-subtitle {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.category-chevron {
    width: 32px;
    height: 32px;
    min-width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.collapsible-category.expanded .category-chevron {
    transform: rotate(180deg);
}

.category-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.collapsible-category.expanded .category-content {
    max-height: 3000px;
}

.category-items {
    padding: 0 12px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-items .scanner-banner {
    margin: 0;
}
