/* ================================================================
   HabitX — Anime Rank SSS Design System (Dark Theme)
   ================================================================ */

/* ─── Reset ─── */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
html { -webkit-text-size-adjust:100%; -webkit-tap-highlight-color:transparent; }

/* ─── Dark Palette ─── */
:root {
    --bg:            #0d0f14;
    --bg-card:       #161922;
    --bg-surface:    #1c1f2b;
    --bg-elevated:   #242837;
    --text:          #f0f0f5;
    --text-sec:      #9a9bb2;
    --text-muted:    #5c5e72;
    --accent:        #7c5cfc;
    --accent-glow:   rgba(124,92,252,.35);
    --orange:        #f97316;
    --green:         #22c55e;
    --red:           #ef4444;
    --border:        rgba(255,255,255,.06);
    --border-active: rgba(255,255,255,.15);
    --radius-sm:     8px;
    --radius-md:     14px;
    --radius-lg:     20px;
    --radius-xl:     28px;
    --ease:          cubic-bezier(.4,0,.2,1);
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ================================================================
   TIER TOKENS — C / B / A / S / SS / SSS
   ================================================================ */
[data-tier="C"]   { --t-bg: linear-gradient(135deg,#2a2d3a,#1e2028); --t-border:#3e4155; --t-glow:rgba(120,120,140,.12); --t-glow-size:0 0 8px 1px; --t-badge-bg:#3e4155; --t-badge-fg:#b0b1c0; --t-rune:#6b6d82; --t-rune-empty:#2e3040; }
[data-tier="B"]   { --t-bg: linear-gradient(135deg,#152e24,#0f1f1a); --t-border:#28c76f; --t-glow:rgba(40,199,111,.15); --t-glow-size:0 0 12px 2px; --t-badge-bg:#1a4a34; --t-badge-fg:#5cf5a0; --t-rune:#28c76f; --t-rune-empty:#1a2e24; }
[data-tier="A"]   { --t-bg: linear-gradient(135deg,#121d36,#0d1528); --t-border:#3b82f6; --t-glow:rgba(59,130,246,.2); --t-glow-size:0 0 16px 3px; --t-badge-bg:#1a3060; --t-badge-fg:#7cb8ff; --t-rune:#3b82f6; --t-rune-empty:#162040; }
[data-tier="S"]   { --t-bg: linear-gradient(135deg,#231640,#170e2e); --t-border:#a855f7; --t-glow:rgba(168,85,247,.25); --t-glow-size:0 0 22px 4px; --t-badge-bg:#2e1860; --t-badge-fg:#d4a5ff; --t-rune:#a855f7; --t-rune-empty:#201438; }
[data-tier="SS"]  { --t-bg: linear-gradient(135deg,#302410,#231a08); --t-border:#f5a623; --t-glow:rgba(245,166,35,.3); --t-glow-size:0 0 28px 5px; --t-badge-bg:linear-gradient(135deg,#f5a623,#e8d44d); --t-badge-fg:#1a1200; --t-rune:#f5a623; --t-rune-empty:#2e2210; }
[data-tier="SSS"] { --t-bg: linear-gradient(135deg,#1a0a2e,#0a1e3d 25%,#0d2a2a 50%,#2a1a0a 75%,#1a0a2e); --t-border:transparent; --t-glow:rgba(200,160,255,.35); --t-glow-size:0 0 36px 8px; --t-badge-bg:linear-gradient(135deg,#f0c,#0ff,#f90,#f0c); --t-badge-fg:#fff; --t-rune:#e0aaff; --t-rune-empty:#1e1430; }

/* ================================================================
   APP LAYOUT
   ================================================================ */
#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    padding-bottom: calc(80px + var(--sab));
}
.page { padding: 16px; }
.loading { text-align:center; padding:60px; font-size:1.5rem; }

/* ── Header ── */
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-top: var(--sat);
}
.header h2 { font-size: 1.6rem; font-weight: 800; }
.header .date { font-size: 0.85rem; color: var(--text-sec); margin-top: 2px; }
.header-stats { display:flex; align-items:center; gap:8px; }
.level { font-size:0.85rem; color:var(--text-sec); font-weight:600; }

/* ── Rank Badge (header) ── */
.rank-badge {
    display: inline-flex; align-items:center; justify-content:center;
    min-width: 36px; height: 28px; padding: 0 10px;
    border-radius: 8px; font-weight: 800; font-size: 0.75rem;
    letter-spacing: 0.05em; text-transform: uppercase; user-select: none;
    background: var(--accent); color: #fff;
}
.rank-E { background:#3e4155; color:#b0b1c0; }
.rank-D { background:#3e4155; color:#b0b1c0; }
.rank-C { background:#3e4155; color:#b0b1c0; }
.rank-B { background:#1a4a34; color:#5cf5a0; border:1px solid #28c76f; }
.rank-A { background:#1a3060; color:#7cb8ff; border:1px solid #3b82f6; }
.rank-S { background:#2e1860; color:#d4a5ff; border:1px solid #a855f7; box-shadow:0 0 12px rgba(168,85,247,.3); }
.rank-SS { background:linear-gradient(135deg,#f5a623,#e8d44d); color:#1a1200; border:1px solid #f5a623; box-shadow:0 0 16px rgba(245,166,35,.3); }
.rank-SSS { background:linear-gradient(135deg,#f0c,#0ff,#f90,#f0c); background-size:300% 300%; animation:sss-shift 3s linear infinite; color:#fff; box-shadow:0 0 20px rgba(200,160,255,.4); }
@keyframes sss-shift { 0%{background-position:0% 50%} 50%{background-position:100% 50%} 100%{background-position:0% 50%} }

/* ── Progress Card ── */
.progress-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 24px;
}
.progress-row {
    display: flex; justify-content: space-between;
    font-size: 0.85rem; color: var(--text-sec); margin-bottom: 8px;
}
.progress-bar {
    height: 8px; background: var(--bg-surface);
    border-radius: 4px; overflow: hidden; margin-bottom: 16px;
}
.progress-fill {
    height: 100%; border-radius: 4px;
    background: linear-gradient(90deg, var(--accent), #a855f7);
    transition: width 0.5s var(--ease);
}
.stats-row {
    display: flex; justify-content: space-around; text-align: center;
}
.stat-item { display:flex; flex-direction:column; align-items:center; gap:2px; }
.stat-value { font-size:1.2rem; font-weight:700; color:var(--accent); }
.stat-label { font-size:0.7rem; color:var(--text-muted); text-transform:uppercase; }

/* ── Section Header ── */
.section-header {
    display:flex; justify-content:space-between; align-items:center;
    margin-bottom:16px;
}
.section-header h3 { font-size:1.1rem; font-weight:700; }
.btn-add {
    padding:8px 16px; background:var(--accent); color:#fff;
    border:none; border-radius:var(--radius-sm); font-weight:600;
    font-size:0.85rem; cursor:pointer;
    transition: transform .2s, box-shadow .2s;
}
.btn-add:hover { transform:translateY(-1px); box-shadow:0 0 16px var(--accent-glow); }

/* ================================================================
   HABIT CARD — AURA FRAME (ANIME RANK)
   ================================================================ */
.aura-frame {
    background: var(--t-bg, var(--bg-card));
    border: 1px solid var(--t-border, var(--border));
    border-radius: var(--radius-lg);
    box-shadow: var(--t-glow-size, 0 0 0 0) var(--t-glow, transparent);
    padding: 16px;
    margin-bottom: 12px;
    position: relative;
    transition: box-shadow .25s var(--ease), border-color .25s var(--ease), transform .15s var(--ease);
}
.aura-frame:active { transform: scale(0.98); }
.aura-frame.completed { opacity: 0.6; }
.aura-frame.completed .habit-name { text-decoration: line-through; text-decoration-color: var(--text-muted); }

.habit-card-top {
    display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
}
.habit-check {
    width: 42px; height: 42px; border-radius: 12px;
    border: 2px solid var(--t-border, var(--border-active));
    background: transparent; cursor: pointer;
    display:flex; align-items:center; justify-content:center;
    font-size: 1.3rem; color: var(--t-badge-fg, var(--text));
    transition: all .15s var(--ease); flex-shrink: 0;
}
.habit-check.done {
    background: var(--t-border, var(--accent));
    box-shadow: 0 0 14px 3px var(--t-glow, var(--accent-glow));
    color: #fff;
}
.habit-check:hover { box-shadow: 0 0 10px 2px var(--t-glow, var(--accent-glow)); }

.habit-info { flex:1; min-width:0; }
.habit-name { font-weight:700; font-size:1rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.habit-meta { font-size:0.8rem; color:var(--text-sec); margin-top:3px; }

/* ── Tier Badge (in card) ── */
.tier-badge {
    display: inline-flex; align-items:center; justify-content:center;
    min-width: 38px; height: 30px; padding: 0 10px;
    border-radius: 8px; font-weight: 900; font-size: 0.8rem;
    letter-spacing: 0.08em; text-transform: uppercase;
    background: var(--t-badge-bg, #3e4155);
    color: var(--t-badge-fg, #b0b1c0);
    border: 1px solid var(--t-border, #3e4155);
    box-shadow: var(--t-glow-size, 0 0 0 0) var(--t-glow, transparent);
    user-select: none;
}

.habit-card-bottom {
    display:flex; align-items:center; justify-content:space-between; gap:8px;
}
.habit-xp {
    font-size:0.75rem; font-weight:700;
    color: var(--t-rune, var(--accent));
    white-space:nowrap;
}

/* ── Progress Runes ── */
.progress-runes { display:flex; gap:4px; flex:1; }
.progress-runes__slot {
    flex:1; height:8px; border-radius:4px;
    background: var(--t-rune-empty, #2e3040);
    border: 1px solid rgba(255,255,255,.03);
    transition: background .15s var(--ease), box-shadow .15s var(--ease);
}
.progress-runes__slot.filled {
    background: var(--t-rune, var(--accent));
    box-shadow: 0 0 6px 1px var(--t-glow, var(--accent-glow));
}

/* ── Card Actions ── */
.habit-card-actions {
    position:absolute; top:12px; right:10px;
    opacity:0; transition:opacity .15s var(--ease);
}
.aura-frame:hover .habit-card-actions { opacity:1; }
@media (max-width:480px) { .habit-card-actions { opacity:0.5; } }
.btn-icon {
    background:none; border:none; cursor:pointer;
    font-size:1rem; padding:4px 8px; border-radius:6px;
}
.btn-icon:hover { background:var(--bg-surface); }

/* ── SSS Iridescent Border ── */
@keyframes sss-border { 0%{border-color:#f0c} 25%{border-color:#0ff} 50%{border-color:#f90} 75%{border-color:#0ff} 100%{border-color:#f0c} }
[data-tier="SSS"].aura-frame { animation:sss-border 4s linear infinite; border-width:2px; }

/* ── Upgrade Animation ── */
@keyframes upgrade-burst {
    0%   { transform:scale(1); box-shadow:var(--t-glow-size) var(--t-glow); }
    40%  { transform:scale(1.05); box-shadow:0 0 40px 10px var(--t-glow); }
    100% { transform:scale(1); box-shadow:var(--t-glow-size) var(--t-glow); }
}
.upgrade-animate { animation: upgrade-burst 700ms var(--ease) forwards; }

/* ================================================================
   EMPTY STATE
   ================================================================ */
.empty-state {
    text-align:center; padding:60px 20px; color:var(--text-sec);
}
.empty-state .icon { font-size:3rem; margin-bottom:12px; }

/* ================================================================
   AUTH PAGES
   ================================================================ */
.auth-page {
    display:flex; flex-direction:column; align-items:center;
    justify-content:center; min-height:80vh; padding:20px;
}
.auth-logo {
    width:72px; height:72px; border-radius:18px;
    background:linear-gradient(135deg,var(--accent),#a855f7);
    display:flex; align-items:center; justify-content:center;
    font-size:28px; font-weight:800; color:#fff;
    margin-bottom:16px; box-shadow:0 0 30px var(--accent-glow);
}
.auth-page h1 {
    font-size:1.8rem; font-weight:800; margin-bottom:6px;
    background:linear-gradient(135deg,var(--accent),#a855f7,#f5a623);
    -webkit-background-clip:text; -webkit-text-fill-color:transparent;
}
.auth-subtitle { color:var(--text-sec); margin-bottom:28px; font-size:0.95rem; }
.auth-page form { width:100%; max-width:340px; }
.input-group { margin-bottom:14px; }
.input-group label { display:block; font-size:0.8rem; color:var(--text-sec); margin-bottom:5px; }
.input-group input, .input-group select, .input-group textarea {
    width:100%; padding:12px 14px;
    background:var(--bg-surface); border:1px solid var(--border);
    border-radius:var(--radius-sm); color:var(--text);
    font-size:1rem; outline:none;
    transition:border-color .15s var(--ease);
}
.input-group input:focus, .input-group select:focus, .input-group textarea:focus {
    border-color:var(--accent);
}
.btn-primary {
    width:100%; padding:14px; margin-top:8px;
    background:var(--accent); color:#fff; border:none;
    border-radius:var(--radius-md); font-size:1rem; font-weight:600;
    cursor:pointer; transition:transform .2s, box-shadow .2s;
}
.btn-primary:hover { transform:translateY(-2px); box-shadow:0 0 20px var(--accent-glow); }
.btn-primary:disabled { opacity:.5; cursor:not-allowed; transform:none; }
.auth-link { text-align:center; margin-top:18px; color:var(--text-sec); font-size:0.9rem; }
.auth-link a { color:var(--accent); text-decoration:none; }

/* ================================================================
   BOTTOM NAV
   ================================================================ */
.bottom-nav {
    position:fixed; bottom:0; left:0; right:0;
    display:flex; justify-content:space-around; align-items:center;
    height:calc(64px + var(--sab)); padding-bottom:var(--sab);
    background:var(--bg-elevated); border-top:1px solid var(--border);
    z-index:100; max-width:480px; margin:0 auto;
}
.nav-item {
    display:flex; flex-direction:column; align-items:center; gap:2px;
    text-decoration:none; color:var(--text-muted);
    font-size:0.65rem; font-weight:600; padding:6px 12px;
    transition:color .15s var(--ease);
}
.nav-item.active { color:var(--accent); }
.nav-item .nav-icon { font-size:1.4rem; }

/* ================================================================
   STATS PAGE
   ================================================================ */
.rank-card {
    background:var(--bg-card); border:1px solid var(--border);
    border-radius:var(--radius-lg); padding:24px; text-align:center;
    margin-bottom:16px;
}
.rank-big { font-size:3rem; font-weight:900; color:var(--accent); }
.rank-big { background:none !important; border:none !important; box-shadow:none !important; -webkit-text-fill-color:var(--accent) !important; }
.rank-info { margin-top:8px; }
.rank-big { background:none !important; border:none !important; box-shadow:none !important; -webkit-text-fill-color:var(--accent) !important; }
.rank-title { font-size:1rem; color:var(--text-sec); }
.rank-big { background:none !important; border:none !important; box-shadow:none !important; -webkit-text-fill-color:var(--accent) !important; }
.rank-level { font-size:0.85rem; color:var(--text-muted); }
.rank-big { background:none !important; border:none !important; box-shadow:none !important; -webkit-text-fill-color:var(--accent) !important; }
.xp-card {
    background:var(--bg-card); border:1px solid var(--border);
    border-radius:var(--radius-lg); padding:16px; margin-bottom:16px;
}
.rank-big { background:none !important; border:none !important; box-shadow:none !important; -webkit-text-fill-color:var(--accent) !important; }
.stats-grid {
    display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:16px;
}
.stat-card {
    background:var(--bg-card); border:1px solid var(--border);
    border-radius:var(--radius-md); padding:16px; text-align:center;
}
.stat-big { font-size:1.8rem; font-weight:800; color:var(--accent); }

/* ================================================================
   ACHIEVEMENTS PAGE
   ================================================================ */
.achievement-card {
    background:var(--bg-card); border:1px solid var(--border);
    border-radius:var(--radius-md); padding:14px;
    display:flex; align-items:center; gap:12px; margin-bottom:10px;
}
.achievement-card.unlocked { border-color:var(--accent); box-shadow:0 0 12px var(--accent-glow); }
.ach-icon { font-size:2rem; }
.ach-info { flex:1; }
.ach-name { font-weight:700; font-size:0.95rem; }
.ach-desc { font-size:0.8rem; color:var(--text-sec); }
.ach-badge {
    padding:4px 10px; border-radius:20px; font-size:0.7rem; font-weight:700;
}
.ach-badge.locked { background:var(--bg-surface); color:var(--text-muted); }
.ach-badge.done { background:var(--accent); color:#fff; }

/* ================================================================
   ADD HABIT PAGE
   ================================================================ */
.page-header {
    display:flex; align-items:center; gap:12px; margin-bottom:20px;
}
.btn-back {
    background:var(--bg-surface); border:1px solid var(--border);
    color:var(--text); padding:8px 12px; border-radius:var(--radius-sm);
    cursor:pointer; font-size:1rem;
}
.icon-picker { display:flex; flex-wrap:wrap; gap:6px; }
.icon-btn {
    width:40px; height:40px; border-radius:10px;
    background:var(--bg-surface); border:1px solid var(--border);
    font-size:1.2rem; cursor:pointer;
    transition:border-color .15s, background .15s;
}
.icon-btn:hover, .icon-btn.selected {
    border-color:var(--accent); background:var(--bg-elevated);
}

/* ================================================================
   PROFILE PAGE
   ================================================================ */
.profile-card {
    background:var(--bg-card); border:1px solid var(--border);
    border-radius:var(--radius-lg); padding:24px; text-align:center;
    margin-bottom:20px;
}
.profile-avatar {
    width:64px; height:64px; border-radius:50%;
    background:linear-gradient(135deg,var(--accent),#a855f7);
    display:flex; align-items:center; justify-content:center;
    font-size:1.5rem; font-weight:700; color:#fff;
    margin:0 auto 12px; box-shadow:0 0 20px var(--accent-glow);
}
.profile-name { font-size:1.2rem; font-weight:700; }
.profile-email { font-size:0.85rem; color:var(--text-sec); margin-top:4px; }
.btn-logout {
    width:100%; padding:14px; background:transparent;
    border:1px solid var(--red); color:var(--red);
    border-radius:var(--radius-md); font-size:1rem;
    cursor:pointer; transition:background .2s;
}
.btn-logout:hover { background:rgba(239,68,68,.1); }
.app-version { text-align:center; color:var(--text-muted); font-size:0.8rem; margin-top:20px; }

/* ================================================================
   TOAST
   ================================================================ */


/* ── Responsive ── */
@media (min-width:481px) {
    #app { border-left:1px solid var(--border); border-right:1px solid var(--border); }
    .bottom-nav { left:50%; transform:translateX(-50%); }
}

/* ═══ Bottom Nav Fix ═══ */
.bottom-nav {
    left: 0 !important;
    right: 0 !important;
    transform: none !important;
    max-width: 100% !important;
}
@media (min-width: 481px) {
    .bottom-nav {
        max-width: 480px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
    }
}

/* ═══ Bottom Nav — Dark Seamless ═══ */
.bottom-nav,
.bottom-nav * {
    background-color: var(--bg-elevated) !important;
    border: none !important;
    box-shadow: none !important;
}
.bottom-nav {
    border-top: 1px solid var(--border) !important;
    gap: 0;
}
.nav-item {
    background: transparent !important;
    border-radius: 0 !important;
    flex: 1;
    padding: 8px 0 !important;
}
.nav-item.active {
    background: transparent !important;
    color: var(--accent) !important;
}

/* ═══ Completed card — less aggressive ═══ */
.aura-frame.completed {
    opacity: 0.8;
}

/* ═══ Bottom Nav — TRUE CENTER ═══ */
.bottom-nav {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: 100%;
    max-width: 480px !important;
}

/* ================================================================
   POLISH PASS — All Screens Enhancement
   ================================================================ */

/* ── Главная: habit check glow ── */
.habit-check {
    color: var(--text-muted) !important;
    font-size: 1.1rem !important;
}
.habit-check.done {
    color: #fff !important;
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    box-shadow: 0 0 16px 4px var(--accent-glow) !important;
}

/* ── Главная: карточка чуть ярче, aura видна ── */
.aura-frame {
    box-shadow: var(--t-glow-size, 0 0 8px 1px) var(--t-glow, rgba(124,92,252,.08)) !important;
}
.aura-frame:hover {
    box-shadow: var(--t-glow-size, 0 0 16px 3px) var(--t-glow, rgba(124,92,252,.15)) !important;
}

/* ── Статистика: ранг-карточка ── */
.rank-card {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-elevated)) !important;
    border: 1px solid var(--accent) !important;
    box-shadow: 0 0 20px 4px var(--accent-glow) !important;
    overflow: hidden;
    position: relative;
}
.rank-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--accent), #a855f7, #f5a623, var(--accent));
    background-size: 300% 100%;
    animation: rank-line 3s linear infinite;
}
@keyframes rank-line {
    0% { background-position: 0% 0; }
    100% { background-position: 300% 0; }
}
.rank-big {
    font-size: 3.5rem !important;
    font-weight: 900 !important;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
}
.rank-big { background:none !important; border:none !important; box-shadow:none !important; -webkit-text-fill-color:var(--accent) !important; }
.rank-title {
    font-weight: 600 !important;
    color: var(--text) !important;
    margin-top: 4px;
}
.rank-level {
    color: var(--text-muted) !important;
}

/* ── Статистика: XP bar ── */
.xp-card .progress-fill,
.xp-fill {
    background: linear-gradient(90deg, var(--accent), #a855f7, #f5a623) !important;
    background-size: 200% 100%;
    animation: xp-glow 2s ease infinite;
}
@keyframes xp-glow {
    0% { background-position: 0% 0; }
    50% { background-position: 100% 0; }
    100% { background-position: 0% 0; }
}

/* ── Статистика: stat cards ── */
.stat-card {
    transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 12px var(--accent-glow);
}
.stat-big {
    background: linear-gradient(135deg, var(--accent), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* ── Награды: achievement cards ── */
.achievement-card {
    transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s var(--ease);
}
.achievement-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.achievement-card.locked {
    opacity: 0.6;
}
.achievement-card.unlocked {
    border-color: var(--accent) !important;
    box-shadow: 0 0 16px 3px var(--accent-glow) !important;
    opacity: 1;
}
.ach-icon {
    font-size: 2.2rem !important;
    filter: grayscale(0);
}
.achievement-card.locked .ach-icon {
    filter: grayscale(1) brightness(.5);
}
.ach-xp {
    color: var(--accent);
    font-weight: 700;
    font-size: 0.85rem;
}

/* ── Добавить: icon picker glow ── */
.icon-btn:hover, .icon-btn.selected {
    border-color: var(--accent) !important;
    box-shadow: 0 0 10px var(--accent-glow);
    background: var(--bg-elevated) !important;
}
.btn-back:hover {
    border-color: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
}

/* ── Профиль: rank info under avatar ── */
.profile-avatar {
    box-shadow: 0 0 24px 6px var(--accent-glow) !important;
    border: 2px solid var(--accent);
}
.profile-card {
    position: relative;
    overflow: hidden;
}
.profile-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), #a855f7);
}

/* ── Кнопка выхода — мягче ── */
.btn-logout {
    border-color: var(--text-muted) !important;
    color: var(--text-muted) !important;
}
.btn-logout:hover {
    border-color: var(--red) !important;
    color: var(--red) !important;
    background: rgba(239,68,68,.08) !important;
}

/* ── Общее: анимация появления страниц ── */
.page {
    animation: page-in 300ms var(--ease) both;
}
@keyframes page-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Общее: скролл ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 4px; }

/* ── Nav active — underline accent ── */
.nav-item.active {
    position: relative;
}
.nav-item.active::after {
    content: '';
    position: absolute; bottom: 6px; left: 50%;
    transform: translateX(-50%);
    width: 20px; height: 3px;
    background: var(--accent);
    border-radius: 3px;
    box-shadow: 0 0 8px var(--accent-glow);
}

/* ═══ Stat Cards — Better Icons ═══ */
.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 100px;
}
.stat-big {
    font-size: 2rem !important;
    font-weight: 900 !important;
    display: flex;
    align-items: center;
    gap: 6px;
}
.stat-big .emoji, .stat-big span {
    font-size: 1.4rem;
}
.stat-label {
    font-size: 0.7rem !important;
    color: var(--text-muted) !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* ═══ Stat grid — accent borders on hover ═══ */
.stats-grid .stat-card:nth-child(1) { --card-accent: #f97316; }
.stats-grid .stat-card:nth-child(2) { --card-accent: #f5a623; }
.stats-grid .stat-card:nth-child(3) { --card-accent: var(--accent); }
.stats-grid .stat-card:nth-child(4) { --card-accent: #a855f7; }

.stats-grid .stat-card:hover {
    border-color: var(--card-accent) !important;
    box-shadow: 0 0 14px 2px color-mix(in srgb, var(--card-accent) 25%, transparent) !important;
}

/* ═══ Stat Icons — Large & Clear ═══ */
.stat-icon {
    font-size: 2.2rem;
    line-height: 1;
    margin-bottom: 4px;
    filter: none;
    text-shadow: none;
}
.stat-card {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 2px !important;
    padding: 20px 16px !important;
}
.stat-big {
    font-size: 2rem !important;
    font-weight: 900 !important;
    line-height: 1.2;
}

/* ================================================================
   ANIMATIONS — Complete, Check, Stagger
   ================================================================ */

/* ── Stagger appearance ── */
.habits-list .aura-frame {
    animation: card-appear 400ms var(--ease) both;
}
.habits-list .aura-frame:nth-child(1) { animation-delay: 0ms; }
.habits-list .aura-frame:nth-child(2) { animation-delay: 60ms; }
.habits-list .aura-frame:nth-child(3) { animation-delay: 120ms; }
.habits-list .aura-frame:nth-child(4) { animation-delay: 180ms; }
.habits-list .aura-frame:nth-child(5) { animation-delay: 240ms; }
.habits-list .aura-frame:nth-child(6) { animation-delay: 300ms; }
.habits-list .aura-frame:nth-child(7) { animation-delay: 360ms; }
.habits-list .aura-frame:nth-child(8) { animation-delay: 420ms; }

@keyframes card-appear {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Check pulse on complete ── */
@keyframes check-pulse {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.25); }
    60%  { transform: scale(0.95); }
    100% { transform: scale(1); }
}
.habit-check.done {
    animation: check-pulse 400ms var(--ease);
}

/* ── Card flash on complete ── */
@keyframes card-flash {
    0%   { box-shadow: var(--t-glow-size) var(--t-glow); }
    50%  { box-shadow: 0 0 30px 8px var(--t-glow, var(--accent-glow)); }
    100% { box-shadow: var(--t-glow-size) var(--t-glow); }
}
.aura-frame.just-completed {
    animation: card-flash 600ms var(--ease);
}

/* ── Completed state — softer ── */
.aura-frame.completed {
    opacity: 0.85 !important;
}
.aura-frame.completed .habit-name {
    text-decoration: line-through !important;
    text-decoration-color: var(--text-muted) !important;
    text-decoration-thickness: 1.5px;
}

/* ── Progress runes filled — pulse for last one ── */
@keyframes rune-glow {
    0%, 100% { box-shadow: 0 0 4px 1px var(--t-glow); }
    50%      { box-shadow: 0 0 10px 3px var(--t-glow); }
}
.progress-runes__slot.filled:last-of-type {
    animation: rune-glow 2s ease infinite;
}

/* ═══ STRONGER Flash Animation ═══ */
@keyframes card-flash-strong {
    0%   { box-shadow: 0 0 0 0 transparent; transform: scale(1); }
    20%  { box-shadow: 0 0 40px 12px var(--accent-glow); transform: scale(1.03); border-color: var(--accent); }
    50%  { box-shadow: 0 0 60px 20px var(--accent-glow); transform: scale(1.02); }
    100% { box-shadow: var(--t-glow-size) var(--t-glow); transform: scale(1); }
}
.aura-frame.just-completed {
    animation: card-flash-strong 800ms var(--ease) !important;
    z-index: 10;
}

/* ── Check mark — bigger pulse ── */
@keyframes check-boom {
    0%   { transform: scale(1); box-shadow: none; }
    30%  { transform: scale(1.35); box-shadow: 0 0 24px 8px var(--accent-glow); }
    60%  { transform: scale(0.9); }
    100% { transform: scale(1); box-shadow: 0 0 16px 4px var(--accent-glow); }
}
.habit-check.done {
    animation: check-boom 500ms var(--ease) !important;
}

/* ── Success ripple behind card ── */
@keyframes ripple-out {
    0%   { opacity: 0.6; transform: scale(0.95); }
    100% { opacity: 0; transform: scale(1.15); }
}
.aura-frame.just-completed::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: var(--radius-lg);
    border: 2px solid var(--accent);
    animation: ripple-out 800ms var(--ease) forwards;
    pointer-events: none;
}

/* ═══ Delete Button — Visible & Styled ═══ */
.habit-card-actions {
    opacity: 0 !important;
    transition: opacity .2s var(--ease) !important;
}
.aura-frame:hover .habit-card-actions {
    opacity: 1 !important;
}
.habit-card-actions .btn-icon {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--border-active) !important;
    border-radius: 8px !important;
    padding: 6px 10px !important;
    font-size: 0.9rem !important;
    transition: all .15s var(--ease) !important;
}
.habit-card-actions .btn-icon:hover {
    background: rgba(239,68,68,.15) !important;
    border-color: var(--red) !important;
    box-shadow: 0 0 10px rgba(239,68,68,.2) !important;
}

/* Mobile — always slightly visible */
@media (max-width: 480px) {
    .habit-card-actions {
        opacity: 0.4 !important;
    }
}

/* ═══ Card Menu — Mobile Friendly ═══ */
.card-menu-btn {
    position: absolute;
    top: 12px; right: 12px;
    background: none !important;
    border: none !important;
    color: var(--text-muted);
    font-size: 1.4rem;
    font-weight: 900;
    letter-spacing: 2px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: color .15s, background .15s;
    line-height: 1;
    z-index: 2;
}
.card-menu-btn:hover, .card-menu-btn:active {
    color: var(--text);
    background: var(--bg-surface) !important;
}

.card-menu {
    display: none;
    position: absolute;
    top: 44px; right: 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-active);
    border-radius: var(--radius-sm);
    overflow: hidden;
    z-index: 20;
    box-shadow: 0 8px 30px rgba(0,0,0,.5);
    min-width: 140px;
}
.card-menu.open {
    display: block;
    animation: menu-in 150ms var(--ease);
}
@keyframes menu-in {
    from { opacity: 0; transform: translateY(-6px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.card-menu-item {
    display: block;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--text);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    transition: background .1s;
}
.card-menu-item:hover, .card-menu-item:active {
    background: var(--bg-surface);
}
.card-menu-item.delete {
    color: var(--red);
}
.card-menu-item.delete:hover {
    background: rgba(239,68,68,.1);
}

/* ═══ Fix: Menu btn + Tier badge separation ═══ */
.habit-card-top {
    padding-right: 36px !important;  /* space for menu btn */
}
.card-menu-btn {
    top: 8px !important;
    right: 8px !important;
    padding: 2px 6px !important;
    font-size: 1.2rem !important;
}
.tier-badge {
    position: static !important;
    flex-shrink: 0;
    margin-left: auto;
    margin-right: 28px;
}

/* Alternative: move tier badge to bottom row */
.habit-card-bottom {
    position: relative;
}

/* Fix: hide nav on auth pages */
.bottom-nav.hidden { display: none !important; }

/* ══════ DESKTOP LAYOUT ══════ */
@media (min-width: 768px) {
    #app {
        max-width: 420px !important;
        padding: 24px 32px calc(80px + var(--sab));
    }

    .page {
        padding: 24px;
    }

    /* Habits grid — 2 columns on desktop */
    .habits-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    /* Stats grid — 4 columns */
    .stats-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    /* Auth page — wider form */
    .auth-page form {
        max-width: 400px;
    }

    /* Header wider */
    .header {
        padding: 16px 0;
    }

    /* Progress card full width */
    .progress-card {
        max-width: 480px;
    }

    /* Bottom nav — wider */
    .bottom-nav {
        max-width: 420px !important;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 16px 16px 0 0;
    }

    /* Add page — wider form */
    .add-page .input-group {
        max-width: 600px;
    }

    /* Achievements — 2 columns */
    .achievements-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    /* Profile centered wider */
    .profile-page {
        max-width: 600px;
        margin: 0 auto;
    }

    /* Toast wider */
    .toast {
        max-width: 420px !important;
    }
}

/* Extra wide screens */
@media (min-width: 1200px) {
    #app {
        max-width: 1100px !important;
    }

    .habits-list {
        grid-template-columns: repeat(3, 1fr);
    }

    .bottom-nav {
        max-width: 1100px !important;
    }

    .achievements-list {
        grid-template-columns: repeat(3, 1fr);
    }
}


.btn-install:hover {
    background: rgba(168, 85, 247, 0.1);
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.2);
}




.btn-install:hover {
    opacity: 1;
    background: rgba(168, 85, 247, 0.08);
}


.btn-install:hover {
    background: rgba(168, 85, 247, 0.2);
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.3);
    transform: translateY(-1px);
}
@keyframes installGlow {
    from { box-shadow: 0 0 5px rgba(168, 85, 247, 0.1); }
    to   { box-shadow: 0 0 15px rgba(168, 85, 247, 0.25); }
}



/* === Install Button === */
.auth-page .btn-install {
    width: 100% !important;
    max-width: 100% !important;
    padding: 14px;
    margin-top: 10px;
    background: rgba(168, 85, 247, 0.12);
    border: 1.5px solid #a855f7;
    color: #a855f7;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    box-sizing: border-box;
    transition: all 0.3s ease;
    animation: installGlow 2s ease-in-out infinite alternate;
}
.auth-page .btn-install:hover {
    background: rgba(168, 85, 247, 0.2);
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.3);
    transform: translateY(-1px);
}
@keyframes installGlow {
    from { box-shadow: 0 0 5px rgba(168, 85, 247, 0.1); }
    to   { box-shadow: 0 0 15px rgba(168, 85, 247, 0.25); }
}

/* Force install button to match form width */
.auth-page .btn-install {
    max-width: 340px !important;
    margin-left: auto !important;
    margin-right: auto !important;
    display: block !important;
}

/* ═══════════════════════════════════════════


/* ── Auth page desktop: #app full width transparent, form centered ── */
@media (min-width: 768px) {
    body.auth-active #app {
        max-width: 100% !important;
        margin: 0 !important;
        background: transparent !important;
    }
    body.auth-active .auth-page {
        max-width: 480px;
        margin: 0 auto;
    }
}
@media (min-width: 1200px) {
    body.auth-active #app {
        max-width: 100% !important;
        margin: 0 !important;
        background: transparent !important;
    }
}

/* ══════ DESKTOP SIDEBAR ══════ */
.desktop-sidebar {
    display: none;
}

@media (min-width: 768px) {
    .desktop-sidebar.visible {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        width: 220px;
        height: 100vh;
        background: var(--card);
        border-right: 1px solid var(--border);
        padding: 24px 12px;
        z-index: 100;
        overflow-y: auto;
    }

    .sidebar-logo {
        display: flex;
        align-items: center;
        gap: 12px;
        text-decoration: none;
        padding: 8px 12px;
        margin-bottom: 24px;
    }

    .sidebar-logo-icon {
        width: 40px;
        height: 40px;
        background: var(--primary);
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        font-size: 1.2rem;
        color: #fff;
    }

    .sidebar-logo-text {
        font-size: 1.3rem;
        font-weight: 700;
        color: var(--primary);
    }

    .sidebar-nav {
        display: flex;
        flex-direction: column;
        gap: 4px;
        flex: 1;
    }

    .sidebar-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        border: none;
        background: transparent;
        color: var(--text-secondary);
        font-size: 0.95rem;
        border-radius: 12px;
        cursor: pointer;
        transition: all 0.2s;
        text-align: left;
        width: 100%;
    }

    .sidebar-item:hover {
        background: rgba(168, 85, 247, 0.1);
        color: var(--text);
    }

    .sidebar-item.active {
        background: rgba(168, 85, 247, 0.15);
        color: var(--primary);
        font-weight: 600;
    }

    .sidebar-icon {
        font-size: 1.2rem;
        width: 24px;
        text-align: center;
    }

    .sidebar-footer {
        margin-top: auto;
        padding-top: 16px;
        border-top: 1px solid var(--border);
    }

    /* When sidebar is active, hide bottom nav */
    .desktop-sidebar.visible ~ #app .bottom-nav {
        display: none !important;
    }
}

@media (min-width: 1200px) {
    .desktop-sidebar.visible {
        width: 260px;
    }
}

/* ── Desktop with sidebar: hide bottom nav, expand content ── */
@media (min-width: 768px) {
    /* Hide bottom nav when sidebar exists */
    body:has(.desktop-sidebar.visible) .bottom-nav {
        display: none !important;
    }

    /* Content area takes full remaining width */
    body:has(.desktop-sidebar.visible) #app {
        max-width: 100% !important;
        margin-left: 220px !important;
        margin-right: 0 !important;
        padding-bottom: 24px !important;
    }
}

@media (min-width: 1200px) {
    body:has(.desktop-sidebar.visible) #app {
        margin-left: 260px !important;
    }
}

/* ── Desktop content improvements ── */
@media (min-width: 768px) {
    /* Content area padding and max-width */
    body:has(.desktop-sidebar.visible) #app {
        padding: 32px 48px !important;
        max-width: calc(100% - 220px) !important;
    }

    /* Limit content width for readability */
    body:has(.desktop-sidebar.visible) .page {
        max-width: 900px;
    }

    /* Progress card full width */
    body:has(.desktop-sidebar.visible) .progress-card {
        max-width: 100%;
    }

    /* Header row — keep items closer */
    body:has(.desktop-sidebar.visible) .header {
        max-width: 900px;
    }

    /* Habits section */
    body:has(.desktop-sidebar.visible) .habits-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
        max-width: 900px;
    }

    /* Section headers (Привычки + Добавить) */
    body:has(.desktop-sidebar.visible) .section-header {
        max-width: 900px;
    }
}

@media (min-width: 1200px) {
    body:has(.desktop-sidebar.visible) #app {
        max-width: calc(100% - 260px) !important;
        padding: 32px 64px !important;
    }

    body:has(.desktop-sidebar.visible) .page,
    body:has(.desktop-sidebar.visible) .header,
    body:has(.desktop-sidebar.visible) .section-header {
        max-width: 1100px;
    }

    body:has(.desktop-sidebar.visible) .habits-list {
        grid-template-columns: repeat(3, 1fr);
        max-width: 1100px;
    }
}

/* ── Fill all space right of sidebar ── */
@media (min-width: 768px) {
    body:has(.desktop-sidebar.visible) #app {
        padding-left: 32px !important;
        padding-right: 32px !important;
    }

    body:has(.desktop-sidebar.visible) .page,
    body:has(.desktop-sidebar.visible) .header,
    body:has(.desktop-sidebar.visible) .section-header,
    body:has(.desktop-sidebar.visible) .progress-card,
    body:has(.desktop-sidebar.visible) .habits-list,
    body:has(.desktop-sidebar.visible) .stats-grid,
    body:has(.desktop-sidebar.visible) .achievements-list {
        max-width: 100% !important;
        width: 100% !important;
    }
}

/* ── Sidebar logo link — no default blue ── */
.sidebar-logo {
    text-decoration: none !important;
    color: inherit !important;
}

/* ── Empty state centered on desktop ── */
@media (min-width: 768px) {
    body:has(.desktop-sidebar.visible) .empty-state {
        text-align: center !important;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 60px 20px;
        width: 100%;
    }
}

/* ── Empty state: centered everywhere ── */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    width: 100%;
    grid-column: 1 / -1;
}
.empty-state p {
    margin: 4px 0;
    color: var(--text-secondary);
}

/* ── Sidebar: ALWAYS hidden below 768px ── */
@media (max-width: 767px) {
    .desktop-sidebar,
    .desktop-sidebar.visible {
        display: none !important;
        width: 0 !important;
        overflow: hidden !important;
    }

    #app {
        margin-left: 0 !important;
    }
}

/* ── Force no margin on mobile (beats inline style) ── */
@media (max-width: 767px) {
    #app[style] {
        margin-left: 0 !important;
    }
}

/* ── Add habit form: limit width on desktop ── */
@media (min-width: 768px) {
    body:has(.desktop-sidebar.visible) .add-page form,
    body:has(.desktop-sidebar.visible) .add-page .input-group,
    body:has(.desktop-sidebar.visible) .add-page .btn-primary,
    body:has(.desktop-sidebar.visible) .add-page select,
    body:has(.desktop-sidebar.visible) .add-page textarea,
    body:has(.desktop-sidebar.visible) .add-page input {
        max-width: 600px !important;
    }
}

/* ── Profile page: centered, limited width on desktop ── */
@media (min-width: 768px) {
    body:has(.desktop-sidebar.visible) .profile-page {
        max-width: 600px !important;
        margin: 0 auto !important;
    }
}

/* ── Profile edit section ── */
.profile-edit-section {
    margin-top: 16px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.profile-edit-section .input-group { margin-bottom: 12px; }
.profile-edit-section .input-group label {
    display: block; font-size: 0.85rem; color: var(--text-sec);
    margin-bottom: 6px;
}
.profile-edit-section .input-group input {
    width: 100%; padding: 12px 14px; background: var(--bg-surface);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    color: var(--text); font-size: 1rem;
}
.profile-edit-section .btn-primary {
    width: 100%; padding: 14px; margin-top: 4px;
}



/* ── Toast (single source of truth) ── */
.toast {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(-120px);
    background: #1c1f2b;
    border: 1px solid rgba(255,255,255,0.1);
    color: #f0f0f5;
    padding: 14px 28px;
    border-radius: 14px;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 10000;
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    white-space: nowrap;
    max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    pointer-events: none;
    opacity: 0;
    width: auto;
    height: auto;
    display: block;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.toast-success { border-color: #28c76f; background: linear-gradient(135deg, #1a2e1f, #1c1f2b); }
.toast-error { border-color: #ea5455; background: linear-gradient(135deg, #2e1a1a, #1c1f2b); }
.toast-info { border-color: #7c5cfc; background: linear-gradient(135deg, #1e1a3a, #1c1f2b); }

/* ── Input hint ── */
.input-hint {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 4px;
}
input[type="time"] {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 1rem;
    -webkit-appearance: none;
}
input[type="time"]:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Input hint ── */
.input-hint {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 4px;
}
input[type="time"] {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 1rem;
    -webkit-appearance: none;
}
input[type="time"]:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ═══ TOAST — единый стиль ═══ */
.toast {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(-80px);
    background: #1c1f2b;
    border: 1px solid rgba(255,255,255,0.1);
    color: #f0f0f5;
    padding: 12px 24px;
    border-radius: 14px;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 10000;
    white-space: nowrap;
    max-width: 360px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    pointer-events: none;
    opacity: 0;
    transition: transform .3s cubic-bezier(.4,0,.2,1), opacity .3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.toast-success { border-color: rgba(40,199,111,0.4); }
.toast-error { border-color: rgba(239,68,68,0.4); }
.toast-info { border-color: rgba(124,92,252,0.4); }
.toast-rankup {
    border-color: rgba(124,92,252,0.5);
    box-shadow: 0 0 20px rgba(124,92,252,0.2), 0 8px 32px rgba(0,0,0,0.5);
}

/* ═══ HABIT TEMPLATES ═══ */
.templates-section {
    margin-bottom: 20px;
}
.templates-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-sec);
    margin-bottom: 12px;
}
.templates-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.template-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all .2s ease;
    text-align: center;
}
.template-card:hover {
    border-color: var(--accent);
    background: var(--bg-elevated);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(124,92,252,.15);
}
.template-icon {
    font-size: 1.5rem;
}
.template-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
}
.template-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
@media (min-width: 768px) {
    .templates-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* ═══ TEMPLATES — redesign horizontal scroll ═══ */
.templates-section {
    margin-bottom: 24px !important;
}
.templates-title {
    font-size: 0.9rem !important;
    font-weight: 600 !important;
    color: var(--text-muted) !important;
    margin-bottom: 10px !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.templates-grid {
    display: flex !important;
    overflow-x: auto;
    gap: 10px !important;
    padding-bottom: 8px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.templates-grid::-webkit-scrollbar { display: none; }
.template-card {
    min-width: 130px !important;
    max-width: 130px !important;
    padding: 12px 10px !important;
    scroll-snap-align: start;
    border-radius: 12px !important;
    flex-shrink: 0;
}
.template-icon {
    font-size: 1.3rem !important;
}
.template-name {
    font-size: 0.8rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.template-desc {
    font-size: 0.7rem !important;
    -webkit-line-clamp: 1 !important;
}
@media (min-width: 768px) {
    .templates-grid {
        grid-template-columns: none !important;
        flex-wrap: wrap !important;
        overflow-x: visible !important;
    }
    .template-card {
        min-width: 140px !important;
        max-width: 160px !important;
    }
}

/* ═══ ADD PAGE — two-column layout ═══ */
.add-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.add-form-col {
    flex: 1;
    min-width: 0;
}
.templates-section {
    order: -1 !important;
}
.templates-grid {
    flex-wrap: wrap !important;
    overflow-x: visible !important;
}
.template-card {
    min-width: 110px !important;
    max-width: 130px !important;
    padding: 10px 8px !important;
}

@media (min-width: 768px) {
    .add-layout {
        flex-direction: row-reverse !important;
        align-items: flex-start;
    }
    .add-form-col {
        flex: 1;
    }
    .templates-section {
        width: 320px !important;
        flex-shrink: 0;
        position: sticky;
        top: 24px;
        order: 0 !important;
    }
    .templates-grid {
        grid-template-columns: 1fr 1fr !important;
        display: grid !important;
    }
    .template-card {
        min-width: auto !important;
        max-width: none !important;
    }
}

/* ═══ TEMPLATES — mobile chips fix ═══ */
@media (max-width: 767px) {
    .add-layout {
        flex-direction: column !important;
    }
    .templates-section {
        width: 100% !important;
        order: -1 !important;
        margin-bottom: 16px !important;
    }
    .templates-title {
        font-size: 0.8rem !important;
        margin-bottom: 8px !important;
    }
    .templates-grid {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        gap: 8px !important;
        padding-bottom: 6px;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }
    .templates-grid::-webkit-scrollbar { display: none; }
    .template-card {
        min-width: 100px !important;
        max-width: 100px !important;
        padding: 8px 6px !important;
        flex-shrink: 0 !important;
        scroll-snap-align: start;
    }
    .template-icon { font-size: 1.1rem !important; }
    .template-name { font-size: 0.7rem !important; }
    .template-desc { display: none !important; }
    .add-form-col { width: 100% !important; }
}

/* ═══ TEMPLATES V2 ═══ */

/* --- Trigger button (mobile) --- */
.templates-trigger {
    width: 100%;
    padding: 14px;
    background: var(--bg-surface);
    border: 1.5px dashed var(--accent);
    border-radius: var(--radius-md);
    color: var(--accent);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all .2s;
    margin-bottom: 4px;
}
.templates-trigger:hover {
    background: rgba(124,92,252,.1);
}

/* --- Desktop panel (hidden on mobile) --- */
.templates-panel { display: none; }

/* --- Bottom sheet (mobile) --- */
.templates-sheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 999;
}
.templates-sheet-overlay.active { display: block; }

.templates-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border-radius: 20px 20px 0 0;
    padding: 12px 20px 32px;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    max-height: 70vh;
    overflow-y: auto;
}
.templates-sheet.active { transform: translateY(0); }

.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 4px;
    margin: 0 auto 12px;
}
.sheet-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--text);
}
.sheet-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.sheet-list .template-card,
.templates-list .template-card {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all .2s;
    text-align: left;
    width: 100%;
    min-width: auto !important;
    max-width: none !important;
}
.sheet-list .template-card:hover,
.templates-list .template-card:hover {
    border-color: var(--accent);
    background: rgba(124,92,252,.08);
    transform: translateX(4px);
}
.template-icon {
    font-size: 1.4rem !important;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(124,92,252,.1);
    border-radius: 10px;
}
.template-info {
    flex: 1;
    min-width: 0;
}
.template-name {
    font-size: 0.9rem !important;
    font-weight: 700;
    color: var(--text);
    display: block;
    white-space: normal !important;
}
.template-desc {
    font-size: 0.75rem !important;
    color: var(--text-muted);
    display: block !important;
    -webkit-line-clamp: none !important;
}
.template-arrow {
    color: var(--accent);
    font-size: 1rem;
    font-weight: 700;
    flex-shrink: 0;
    opacity: .5;
    transition: opacity .2s;
}
.template-card:hover .template-arrow { opacity: 1; }

/* --- Desktop: show panel, hide trigger + sheet --- */
@media (min-width: 768px) {
    .templates-trigger { display: none !important; }
    .templates-sheet, .templates-sheet-overlay { display: none !important; }
    .templates-panel {
        display: block !important;
        background: var(--bg-surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        padding: 20px;
    }
    .templates-panel-header {
        margin-bottom: 14px;
    }
    .templates-panel-title {
        display: block;
        font-size: 0.95rem;
        font-weight: 700;
        color: var(--text);
    }
    .templates-panel-hint {
        display: block;
        font-size: 0.75rem;
        color: var(--text-muted);
        margin-top: 2px;
    }
    .templates-list {
        display: flex;
        flex-direction: column;
        gap: 6px;
    }
}

/* === Rank Up Popup === */
.rankup-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    z-index: 9999;
    opacity: 0;
    transition: opacity .3s;
}
.rankup-overlay.active { opacity: 1; }
.rankup-modal {
    position: relative;
    background: var(--bg-elevated, #1e1e3a);
    border-radius: 20px;
    padding: 40px 32px 32px;
    text-align: center;
    max-width: 340px;
    width: 90%;
    overflow: hidden;
    transform: scale(.8);
    transition: transform .3s;
}
.rankup-overlay.active .rankup-modal { transform: scale(1); }
.rankup-glow {
    position: absolute;
    top: -40px; left: 50%;
    transform: translateX(-50%);
    width: 200px; height: 200px;
    border-radius: 50%;
    opacity: .15;
    filter: blur(60px);
    pointer-events: none;
}
.rankup-icon { font-size: 3rem; margin-bottom: 8px; }
.rankup-title {
    font-size: 1.4rem;
    font-weight: 800;
    color: #fff;
    margin: 0 0 16px;
}
.rankup-ranks {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 8px;
}
.rankup-old, .rankup-new {
    font-size: 1.6rem;
    font-weight: 900;
    padding: 8px 18px;
    border-radius: 12px;
    background: rgba(255,255,255,.06);
}
.rankup-old { opacity: .5; }
.rankup-new { color: #7c5cfc; border: 2px solid #7c5cfc; }
.rankup-new[data-tier="B"] { color: #22c55e; border-color: #22c55e; }
.rankup-new[data-tier="A"] { color: #7c5cfc; border-color: #7c5cfc; }
.rankup-new[data-tier="S"] { color: #f59e0b; border-color: #f59e0b; }
.rankup-new[data-tier="SS"] { color: #ef4444; border-color: #ef4444; }
.rankup-new[data-tier="SSS"] { color: #ff6b6b; border-color: #ff6b6b; text-shadow: 0 0 20px #ff6b6b; }
.rankup-arrow { font-size: 1.5rem; color: var(--text-muted, #888); }
.rankup-name {
    font-size: .85rem;
    color: var(--text-muted, #aaa);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 8px;
}
.rankup-xp {
    font-size: .95rem;
    color: #7c5cfc;
    font-weight: 600;
    margin-bottom: 6px;
}
.rankup-habit {
    font-size: .85rem;
    color: var(--text-muted, #aaa);
    margin: 0 0 20px;
}
.rankup-btn {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    border-radius: 12px;
}

/* Rank Up Target Selection */
.rankup-target { margin-top: 16px; }
.rankup-target-label { font-size: .95rem; font-weight: 700; color: #fff; margin: 0 0 4px; }
.rankup-target-current { font-size: .8rem; color: var(--text-muted, #888); margin: 0 0 12px; }
.rankup-target-buttons { display: flex; flex-direction: column; gap: 8px; }
.rankup-btn-skip {
    width: 100%; padding: 12px; font-size: .9rem; border-radius: 12px;
    background: transparent; border: 1px solid var(--border, #333);
    color: var(--text-muted, #aaa); cursor: pointer; font-weight: 600;
}
.rankup-btn-skip:hover { background: rgba(255,255,255,.05); }

/* Rank card border by rank */
.rank-border-C { border-color: #8b8fa3 !important; box-shadow: 0 0 15px rgba(139,143,163,.3) !important; }
.rank-border-B { border-color: #28c76f !important; box-shadow: 0 0 15px rgba(40,199,111,.3) !important; }
.rank-border-A { border-color: #3b82f6 !important; box-shadow: 0 0 15px rgba(59,130,246,.3) !important; }
.rank-border-S { border-color: #a855f7 !important; box-shadow: 0 0 15px rgba(168,85,247,.3) !important; }
.rank-border-SS { border-color: #f5a623 !important; box-shadow: 0 0 15px rgba(245,166,35,.3) !important; }
.rank-border-SSS { border-color: #ff66cc !important; box-shadow: 0 0 20px rgba(255,102,204,.4) !important; }

/* Level Card */
.level-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 16px;
}
.level-top {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}
.level-circle {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    flex-shrink: 0;
}
.level-number {
    font-size: 1.8rem; font-weight: 900; color: #fff; line-height: 1;
}
.level-label {
    font-size: 0.6rem; font-weight: 700; color: rgba(255,255,255,.7); letter-spacing: 0.1em;
}
.level-title {
    font-size: 1.3rem; font-weight: 700; color: var(--text);
}
.level-xp-text {
    font-size: 0.9rem; color: var(--text-muted); margin-top: 4px;
}
.level-progress {
    margin-top: 8px;
}
.level-fill {
    background: linear-gradient(90deg, var(--accent), #a855f7) !important;
}

/* Header Level Badge */
.header-level {
    display: inline-flex;
    align-items: center;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 6px 14px;
    border-radius: 20px;
    letter-spacing: 0.03em;
}

/* === Achievement Popup === */
.achievement-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.4s ease;
    backdrop-filter: blur(4px);
}
.achievement-overlay.show {
    opacity: 1;
}
.achievement-popup {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 2px solid #f59e0b;
    border-radius: 20px;
    padding: 32px 28px;
    text-align: center;
    max-width: 320px;
    width: 90%;
    position: relative;
    overflow: hidden;
    animation: achievementBounce 0.5s ease;
    box-shadow: 0 0 40px rgba(245, 158, 11, 0.3);
}
.achievement-popup-glow {
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: radial-gradient(circle, rgba(245,158,11,0.15) 0%, transparent 60%);
    animation: achievementGlow 2s ease infinite;
}
.achievement-popup-icon {
    font-size: 56px;
    margin-bottom: 12px;
    position: relative;
    animation: achievementPop 0.6s ease 0.2s both;
}
.achievement-popup-title {
    color: #f59e0b;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 8px;
    position: relative;
}
.achievement-popup-name {
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
    position: relative;
}
.achievement-popup-xp {
    color: #f59e0b;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    position: relative;
}
.achievement-popup-btn {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 12px 32px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s;
}
.achievement-popup-btn:active {
    transform: scale(0.95);
}
.toast-achievement {
    border-left: 3px solid #f59e0b;
}
@keyframes achievementBounce {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes achievementPop {
    0% { transform: scale(0) rotate(-20deg); }
    60% { transform: scale(1.3) rotate(5deg); }
    100% { transform: scale(1) rotate(0deg); }
}
@keyframes achievementGlow {
    0%, 100% { opacity: 0.5; transform: rotate(0deg); }
    50% { opacity: 1; transform: rotate(180deg); }
}

/* === Achievements Page Improved === */
.ach-overview {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    margin-bottom: 20px;
    border: 1px solid rgba(255,255,255,0.06);
}
.ach-overview-count {
    font-size: 32px;
    font-weight: 700;
    color: #f59e0b;
    margin-bottom: 10px;
}
.ach-overview-pct {
    color: rgba(255,255,255,0.5);
    font-size: 13px;
    margin-top: 8px;
}
.ach-section {
    margin-bottom: 20px;
}
.ach-section-title {
    font-size: 15px;
    font-weight: 600;
    color: rgba(255,255,255,0.7);
    margin-bottom: 12px;
    padding-left: 4px;
}
.achievement-card.unlocked {
    border-color: rgba(245, 158, 11, 0.3);
    background: linear-gradient(135deg, rgba(245,158,11,0.08), transparent);
}
.achievement-progress-text {
    font-size: 12px;
    color: rgba(255,255,255,0.4);
    margin-top: 4px;
}
.achievement-card.unlocked .achievement-progress-text {
    color: #f59e0b;
}
.achievement-xp.earned {
    color: #f59e0b;
    font-weight: 700;
}
.progress-fill.complete {
    background: linear-gradient(90deg, #f59e0b, #d97706);
}

/* === Category Filter === */
.category-filter {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0 12px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.category-filter::-webkit-scrollbar { display: none; }
.cat-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.04);
    color: rgba(255,255,255,0.6);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.cat-btn.active {
    background: linear-gradient(135deg, #7c5cfc, #6d4fe3);
    color: #fff;
    border-color: #7c5cfc;
}
.cat-btn:hover:not(.active) {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

/* === Achievements Page Improved === */
.ach-overview {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    margin-bottom: 20px;
    border: 1px solid rgba(255,255,255,0.06);
}
.ach-overview-count {
    font-size: 32px;
    font-weight: 700;
    color: #f59e0b;
    margin-bottom: 10px;
}
.ach-overview-pct {
    color: rgba(255,255,255,0.5);
    font-size: 13px;
    margin-top: 8px;
}
.ach-section {
    margin-bottom: 20px;
}
.ach-section-title {
    font-size: 15px;
    font-weight: 600;
    color: rgba(255,255,255,0.7);
    margin-bottom: 12px;
    padding-left: 4px;
}
.achievement-card.unlocked {
    border-color: rgba(245, 158, 11, 0.3);
    background: linear-gradient(135deg, rgba(245,158,11,0.08), transparent);
}
.achievement-progress-text {
    font-size: 12px;
    color: rgba(255,255,255,0.4);
    margin-top: 4px;
}
.achievement-card.unlocked .achievement-progress-text {
    color: #f59e0b;
}
.achievement-xp.earned {
    color: #f59e0b;
    font-weight: 700;
}
.progress-fill.complete {
    background: linear-gradient(90deg, #f59e0b, #d97706);
}

/* === Category Filter === */
.category-filter {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0 12px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.category-filter::-webkit-scrollbar { display: none; }
.cat-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.04);
    color: rgba(255,255,255,0.6);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.cat-btn.active {
    background: linear-gradient(135deg, #7c5cfc, #6d4fe3);
    color: #fff;
    border-color: #7c5cfc;
}
.cat-btn:hover:not(.active) {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

/* === Profile Improved === */
.profile-avatar-big {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c5cfc, #6d4fe3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: #fff;
    margin: 0 auto 12px;
    box-shadow: 0 0 20px rgba(124, 92, 252, 0.3);
}
.profile-badge {
    margin-top: 8px;
    font-size: 14px;
    color: #f59e0b;
    font-weight: 600;
}
.profile-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 20px 0;
}
.profile-stat {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 14px;
    padding: 16px;
    text-align: center;
}
.profile-stat-num {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 4px;
}
.profile-stat-label {
    font-size: 12px;
    color: rgba(255,255,255,0.5);
}

/* === Profile v2 === */
.profile-section {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 12px;
}
.profile-section-title {
    font-size: 13px;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}
.profile-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.profile-row:last-child { border-bottom: none; }
.profile-row-label {
    color: rgba(255,255,255,0.6);
    font-size: 14px;
}
.profile-row-value {
    color: #fff;
    font-size: 14px;
    font-weight: 500;
}
.profile-edit-row {
    display: flex;
    gap: 10px;
    align-items: center;
}
.profile-input {
    flex: 1;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.05);
    color: #fff;
    font-size: 14px;
}
.btn-primary-sm {
    padding: 10px 20px;
    border-radius: 10px;
    background: linear-gradient(135deg, #7c5cfc, #6d4fe3);
    color: #fff;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

/* === Password Change === */
.profile-section .input-group {
    margin-bottom: 8px;
}
.profile-section .btn-primary-sm {
    width: 100%;
    margin-top: 4px;
}

/* === Profile Desktop Layout === */
@media (min-width: 768px) {
    .profile-page {
        max-width: 1100px;
        margin: 0 auto;
    }
    .profile-page .profile-card {
        padding: 32px;
        flex-direction: row;
        display: flex;
        align-items: center;
        gap: 24px;
        text-align: left;
    }
    .profile-page .profile-card .profile-avatar-big {
        margin: 0;
        width: 80px;
        height: 80px;
        font-size: 32px;
        flex-shrink: 0;
    }
    .profile-page .profile-card .profile-name {
        font-size: 24px;
    }
    .profile-page .profile-card .profile-badge {
        margin-top: 4px;
    }
    .profile-sections-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    .profile-section {
        margin-bottom: 0;
    }
    .profile-page .btn-logout {
        max-width: 300px;
        margin: 20px auto 0;
    }
}

/* === Profile sections stretch === */
@media (min-width: 768px) {
    .profile-sections-grid {
        align-items: stretch;
    }
    .profile-section {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        min-height: 160px;
    }
    .profile-section .btn-primary-sm {
        margin-top: auto;
    }
    .profile-page .profile-card {
        padding: 28px 32px;
    }
    .profile-row-label {
        white-space: nowrap;
        margin-right: 16px;
    }
}

/* === Profile: override ALL width limits on desktop === */
@media (min-width: 768px) {
    body:has(.desktop-sidebar.visible) .profile-page {
        max-width: 100% !important;
        width: 100% !important;
        padding: 24px 40px !important;
    }
    body:has(.desktop-sidebar.visible) #app:has(.profile-page) {
        max-width: 100% !important;
    }
    .profile-page .profile-card {
        max-width: 100%;
    }
    .profile-sections-grid {
        max-width: 100%;
    }
    .profile-page .btn-logout {
        max-width: 100% !important;
        margin: 24px 0 0 !important;
    }
}

/* === Fix: Изменить имя — кнопка не вылазит === */
@media (max-width: 767px) {
    .profile-edit-row {
        flex-direction: column !important;
    }
    .profile-edit-row .profile-input {
        width: 100% !important;
    }
    .profile-edit-row .btn-primary-sm {
        width: 100% !important;
        padding: 12px !important;
    }
}

/* === Bottom Nav Redesign (Mobile) === */
.bottom-nav {
    background: rgba(13, 13, 22, 0.92) !important;
    backdrop-filter: blur(16px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(16px) saturate(180%) !important;
    border-top: 1px solid rgba(124, 92, 252, 0.15) !important;
    height: calc(68px + var(--sab)) !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}
.nav-item {
    position: relative;
    font-size: 0.7rem !important;
    gap: 4px !important;
    padding: 8px 14px !important;
    border-radius: 12px;
    transition: all 0.2s ease !important;
    color: rgba(255,255,255,0.4) !important;
}
.nav-item .nav-icon {
    font-size: 1.3rem !important;
    transition: transform 0.2s ease;
}
.nav-item.active {
    color: #fff !important;
    background: rgba(124, 92, 252, 0.15);
}
.nav-item.active .nav-icon {
    transform: scale(1.15);
}
.nav-item.active::after {
    content: '';
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: linear-gradient(90deg, #7c5cfc, #a78bfa);
    border-radius: 0 0 4px 4px;
}

/* Центральная кнопка + выделяется */
.nav-item[data-page="add"] .nav-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #7c5cfc, #6d4fe3);
    border-radius: 14px;
    font-size: 1.2rem !important;
    box-shadow: 0 4px 12px rgba(124, 92, 252, 0.35);
    color: #fff;
}
.nav-item[data-page="add"].active {
    background: none;
}
.nav-item[data-page="add"].active::after {
    display: none;
}

/* === Bottom Nav COMPLETE OVERRIDE === */
.bottom-nav {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    transform: none !important;
    max-width: 100% !important;
    display: flex !important;
    justify-content: space-around !important;
    align-items: center !important;
    height: calc(60px + var(--sab)) !important;
    padding-bottom: var(--sab) !important;
    background: rgba(10, 10, 18, 0.95) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-top: 1px solid rgba(124, 92, 252, 0.2) !important;
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.4) !important;
    z-index: 100 !important;
    margin: 0 !important;
}
@media (min-width: 481px) {
    .bottom-nav {
        max-width: 480px !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
    }
}
.nav-item {
    all: unset !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 3px !important;
    flex: 1 !important;
    padding: 8px 0 !important;
    font-size: 0.65rem !important;
    font-weight: 600 !important;
    color: rgba(255, 255, 255, 0.35) !important;
    cursor: pointer !important;
    transition: color 0.2s ease !important;
    text-align: center !important;
    -webkit-tap-highlight-color: transparent !important;
}
.nav-item span {
    display: block !important;
    font-size: 0.65rem !important;
    line-height: 1 !important;
}
.nav-item.active {
    color: #7c5cfc !important;
}

/* === Nav Icons & Labels: bigger, brighter === */
.nav-item {
    font-size: 1.4rem !important;
    color: rgba(255, 255, 255, 0.5) !important;
}
.nav-item span {
    font-size: 0.72rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.02em !important;
    color: inherit !important;
    margin-top: 2px !important;
}
.nav-item.active {
    color: #a78bfa !important;
}

/* === Nav: clean text, no highlight === */
.nav-item {
    background: none !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    -webkit-tap-highlight-color: transparent !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}
.nav-item span {
    background: none !important;
    -webkit-text-fill-color: inherit !important;
    text-shadow: none !important;
    box-shadow: none !important;
    border: none !important;
    outline: none !important;
    padding: 0 !important;
    margin-top: 2px !important;
}

/* === Icon Picker Preview === */
.icon-picker-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.icon-picker-preview:hover { border-color: #7c5cfc; background: rgba(124,92,252,0.06); }
.icon-preview-img { width: 40px; height: 40px; border-radius: 10px; }
.icon-picker-preview span { color: rgba(255,255,255,0.5); font-size: 14px; }
.icon-picker-modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7); z-index: 9999;
    display: flex; align-items: flex-end; justify-content: center;
    opacity: 0; transition: opacity 0.3s; backdrop-filter: blur(4px);
}
.icon-picker-modal.show { opacity: 1; }
.icon-picker-sheet {
    background: #1a1a2e; border-radius: 20px 20px 0 0;
    width: 100%; max-width: 480px; max-height: 75vh;
    overflow-y: auto; padding: 0 16px 24px;
    transform: translateY(100%); transition: transform 0.3s ease;
}
.icon-picker-modal.show .icon-picker-sheet { transform: translateY(0); }
.icon-picker-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 0; position: sticky; top: 0; background: #1a1a2e; z-index: 2;
}
.icon-picker-header h3 { font-size: 18px; font-weight: 700; color: #fff; }
.icon-picker-close {
    background: rgba(255,255,255,0.1); border: none; color: #fff;
    width: 32px; height: 32px; border-radius: 50%; font-size: 16px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.icon-picker-cat { margin-bottom: 16px; }
.icon-picker-cat-title {
    font-size: 12px; color: rgba(255,255,255,0.4);
    text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; padding-left: 2px;
}
.icon-picker-items { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-pick-btn {
    width: 52px; height: 52px; border-radius: 12px; border: 2px solid transparent;
    background: rgba(255,255,255,0.05); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s; padding: 0;
}
.icon-pick-btn:hover { background: rgba(255,255,255,0.1); transform: scale(1.08); }
.icon-pick-btn.selected {
    border-color: #7c5cfc; background: rgba(124,92,252,0.15);
    box-shadow: 0 0 12px rgba(124,92,252,0.3);
}
.icon-pick-btn.emoji-pick { font-size: 24px; }
.icon-pick-btn.svg-pick img { border-radius: 8px; }
@media (min-width: 768px) {
    .icon-picker-sheet { border-radius: 20px; max-height: 60vh; margin-bottom: 10vh; }
    .icon-picker-modal { align-items: center; }
    .icon-pick-btn { width: 56px; height: 56px; }
}

/* === Achievement Tabs === */
.ach-tabs { display: flex; gap: 4px; margin-bottom: 16px; background: rgba(255,255,255,0.05); border-radius: 12px; padding: 4px; }
.ach-tab { flex: 1; padding: 10px; border: none; background: transparent; color: rgba(255,255,255,0.5); font-size: 14px; font-weight: 600; border-radius: 10px; cursor: pointer; transition: all 0.2s; }
.ach-tab.active { background: rgba(124,92,252,0.2); color: #fff; }

/* === Achievement Rewards === */
.achievement-rewards { display: flex; gap: 8px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.ach-earned { color: #22c55e; font-size: 12px; font-weight: 600; }
.ach-progress-text { color: rgba(255,255,255,0.4); font-size: 12px; }
.ach-reward { font-size: 11px; color: rgba(255,255,255,0.5); background: rgba(255,255,255,0.06); padding: 2px 8px; border-radius: 6px; }
.ach-reward.crystal { color: #7c5cfc; background: rgba(124,92,252,0.1); }

/* === Shop === */
.shop-balance { display: flex; gap: 12px; margin-bottom: 20px; }
.balance-item { flex: 1; background: rgba(255,255,255,0.05); border-radius: 14px; padding: 16px; text-align: center; display: flex; flex-direction: column; gap: 4px; }
.balance-icon { font-size: 28px; }
.balance-value { font-size: 24px; font-weight: 800; color: #fff; }
.balance-label { font-size: 12px; color: rgba(255,255,255,0.4); }

.shop-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.shop-card { background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.08); border-radius: 16px; padding: 20px; text-align: center; transition: all 0.2s; }
.shop-card:hover { border-color: rgba(124,92,252,0.3); }
.shop-card.disabled { opacity: 0.5; }
.shop-icon { font-size: 40px; margin-bottom: 8px; }
.shop-name { font-size: 16px; font-weight: 700; color: #fff; margin-bottom: 4px; }
.shop-desc { font-size: 13px; color: rgba(255,255,255,0.4); margin-bottom: 12px; }
.shop-buy-btn { padding: 10px 24px; border: none; border-radius: 10px; font-size: 14px; font-weight: 700; cursor: pointer; background: linear-gradient(135deg, #7c5cfc, #a855f7); color: #fff; transition: all 0.2s; }
.shop-buy-btn:hover { transform: scale(1.05); box-shadow: 0 4px 15px rgba(124,92,252,0.4); }
.shop-buy-btn.locked { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.3); cursor: not-allowed; }

/* === Medals on Home === */
.home-medals { display: flex; gap: 6px; margin-top: 8px; }
.home-medal { font-size: 20px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3)); }
.home-crystals { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #7c5cfc; font-weight: 700; }

@media (min-width: 768px) {
    .shop-grid { grid-template-columns: repeat(3, 1fr); }
}


/* === Penalty Modal === */
.penalty-modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999; opacity: 0; transition: opacity .3s ease;
}
.penalty-modal.show { opacity: 1; }
.penalty-modal.show .penalty-sheet { transform: scale(1); opacity: 1; }
.penalty-sheet {
    background: var(--card-bg, #1a1a2e); border-radius: 20px;
    padding: 28px 24px; max-width: 340px; width: 90%; text-align: center;
    transform: scale(0.85); opacity: 0; transition: all .3s cubic-bezier(.34,1.56,.64,1);
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.penalty-icon { font-size: 48px; margin-bottom: 12px; }
.penalty-title {
    font-size: 20px; font-weight: 700; color: #fff; margin-bottom: 8px;
}
.penalty-desc {
    font-size: 14px; color: rgba(255,255,255,0.5); margin-bottom: 16px;
}
.penalty-list { text-align: left; margin-bottom: 24px; }
.penalty-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; margin-bottom: 6px;
    background: rgba(255,60,60,0.08); border-radius: 12px;
    font-size: 14px; color: rgba(255,255,255,0.8);
}
.penalty-item span { font-size: 18px; }
.penalty-item strong { color: #ff4d4d; margin-left: auto; }
.penalty-buttons { display: flex; gap: 10px; }
.penalty-btn {
    flex: 1; padding: 14px; border: none; border-radius: 14px;
    font-size: 15px; font-weight: 600; cursor: pointer; transition: all .2s;
}
.penalty-btn.cancel {
    background: rgba(255,255,255,0.08); color: #fff;
}
.penalty-btn.cancel:hover { background: rgba(255,255,255,0.15); }
.penalty-btn.confirm {
    background: linear-gradient(135deg, #ff4d4d, #cc0000); color: #fff;
}
.penalty-btn.confirm:hover { transform: scale(1.03); }


/* === Category Filter Pills === */
.cat-filters {
    display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px;
    scrollbar-width: none; -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}
.cat-filters::-webkit-scrollbar { display: none; }
.cat-filter-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 14px; border: none; border-radius: 20px;
    background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.6);
    font-size: 13px; font-weight: 500; white-space: nowrap;
    cursor: pointer; transition: all 0.25s ease;
    backdrop-filter: blur(8px);
}
.cat-filter-btn:hover {
    background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.8);
}
.cat-filter-btn.active {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    color: #fff; box-shadow: 0 4px 15px rgba(124,58,237,0.3);
}
.cat-count {
    background: rgba(255,255,255,0.15); padding: 1px 7px;
    border-radius: 10px; font-size: 11px; font-weight: 600;
}
.cat-filter-btn.active .cat-count {
    background: rgba(255,255,255,0.25);
}
.cat-empty-msg {
    text-align: center; padding: 40px 20px; color: rgba(255,255,255,0.3);
    font-size: 14px;
}
.cat-empty-msg p:first-child { font-size: 36px; margin-bottom: 8px; }
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}


/* === Icon Picker SVG Fix === */
.icon-cat-label {
    width: 100%;
    text-align: left;
    font-size: 13px;
    color: rgba(255,255,255,0.5);
    padding: 10px 0 6px;
}
.icon-cat-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.icon-option {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.15s;
}
.icon-option:hover {
    background: rgba(255,255,255,0.1);
}
.icon-option.selected {
    background: rgba(255,255,255,0.08);
    box-shadow: 0 0 0 2px #7c5cfc;
}
.icon-option img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}
