:root {
  --bg: #07070f;
  --bg2: #0c0c1a;
  --card: rgba(255, 255, 255, 0.035);
  --card-border: rgba(255, 255, 255, 0.07);
  --text: #eef0ff;
  --muted: #8b90b3;
  --blue: #3b82f6;
  --violet: #a855f7;
  --cyan: #22d3ee;
  --pink: #ec4899;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --grad: linear-gradient(135deg, #3b82f6, #a855f7);
  --grad-soft: linear-gradient(135deg, rgba(59, 130, 246, 0.25), rgba(168, 85, 247, 0.25));
  --radius: 20px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
body { min-height: 100dvh; overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.err { color: var(--red); min-height: 1.2em; font-size: 0.9rem; margin-top: 8px; }

/* Fond animé */
#bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; background: radial-gradient(1200px 600px at 50% -10%, #141433 0%, var(--bg) 60%); }
.orb { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.45; animation: float 18s ease-in-out infinite alternate; }
.o1 { width: 420px; height: 420px; background: #3b82f6; top: -120px; left: -120px; }
.o2 { width: 380px; height: 380px; background: #a855f7; bottom: -140px; right: -100px; animation-delay: -6s; }
.o3 { width: 260px; height: 260px; background: #22d3ee; top: 40%; left: 60%; opacity: 0.18; animation-delay: -12s; }
@keyframes float { from { transform: translate(0, 0) scale(1); } to { transform: translate(40px, 60px) scale(1.15); } }

/* Logo */
.logo { width: 34px; height: 34px; border-radius: 10px; overflow: hidden; box-shadow: 0 6px 20px rgba(120, 90, 255, 0.35); flex: none; }
.logo svg { width: 100%; height: 100%; display: block; }
.logo.big { width: 84px; height: 84px; border-radius: 22px; margin: 0 auto 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; letter-spacing: -0.02em; }

/* Écrans plein */
.screen { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(7, 7, 15, 0.92); backdrop-filter: blur(14px); }
.login-card { width: 100%; max-width: 360px; text-align: center; padding: 32px 26px; border-radius: 28px; background: var(--card); border: 1px solid var(--card-border); box-shadow: var(--shadow); }
.login-card h1 { font-size: 1.8rem; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-card form { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }

.scold-card { width: 100%; max-width: 520px; text-align: center; padding: 34px 26px; border-radius: 28px; background: linear-gradient(160deg, rgba(239, 68, 68, 0.12), rgba(168, 85, 247, 0.1)); border: 1px solid rgba(239, 68, 68, 0.35); box-shadow: 0 0 80px rgba(239, 68, 68, 0.15), var(--shadow); animation: shake 0.6s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); } }
.scold-badge { display: inline-block; padding: 6px 14px; border-radius: 999px; background: var(--red); color: #fff; font-weight: 800; font-size: 0.8rem; letter-spacing: 0.12em; }
.scold-card blockquote { margin: 22px 0 10px; font-size: 1.45rem; line-height: 1.35; font-weight: 600; }
.scold-card .btn { margin-top: 20px; }

/* Layout */
#app { position: relative; z-index: 1; display: flex; min-height: 100dvh; }
#side { display: none; }
#main { flex: 1; min-width: 0; padding: calc(12px + var(--safe-t)) 16px calc(90px + var(--safe-b)); max-width: 760px; margin: 0 auto; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px 14px; }
.top-streak { font-weight: 700; display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--card-border); font-size: 0.9rem; }
.page { display: flex; flex-direction: column; gap: 14px; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

#tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around; padding: 8px 8px calc(8px + var(--safe-b)); background: rgba(9, 9, 20, 0.85); backdrop-filter: blur(16px); border-top: 1px solid var(--card-border); }
#tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.68rem; color: var(--muted); padding: 6px 12px; border-radius: 14px; min-width: 64px; transition: 0.2s; }
#tabbar a .ic { font-size: 1.25rem; line-height: 1; }
#tabbar a.active { color: #fff; background: var(--grad-soft); }

@media (min-width: 900px) {
  #side { display: flex; flex-direction: column; gap: 24px; width: 240px; padding: 28px 18px; border-right: 1px solid var(--card-border); position: sticky; top: 0; height: 100dvh; background: rgba(9, 9, 20, 0.55); backdrop-filter: blur(10px); }
  #side nav { display: flex; flex-direction: column; gap: 4px; }
  #side nav a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; color: var(--muted); font-weight: 600; transition: 0.2s; }
  #side nav a .ic { font-size: 1.15rem; width: 22px; text-align: center; }
  #side nav a:hover { color: #fff; background: var(--card); }
  #side nav a.active { color: #fff; background: var(--grad-soft); border: 1px solid rgba(168, 85, 247, 0.3); }
  .side-rank { margin-top: auto; padding: 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--card-border); font-size: 0.85rem; }
  #tabbar { display: none; }
  .brand.mobile { visibility: hidden; }
  #main { padding: 28px 36px 60px; max-width: 1000px; }
}

/* Cards */
.card { background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }

/* Rank card */
.rank-card { position: relative; overflow: hidden; background: linear-gradient(140deg, rgba(59, 130, 246, 0.16), rgba(168, 85, 247, 0.14) 60%, rgba(236, 72, 153, 0.08)); border-color: rgba(168, 85, 247, 0.3); }
.rank-card::after { content: ""; position: absolute; width: 300px; height: 300px; right: -120px; top: -140px; background: radial-gradient(circle, rgba(168, 85, 247, 0.35), transparent 65%); pointer-events: none; }
.rank-top { display: flex; align-items: center; gap: 16px; }
.rank-badge { width: 74px; height: 82px; flex: none; position: relative; display: grid; place-items: center; filter: drop-shadow(0 8px 22px rgba(0, 0, 0, 0.5)); }
.rank-badge svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.rank-badge b { position: relative; font-size: 1.05rem; font-weight: 800; color: #fff; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6); }
.rank-info { flex: 1; min-width: 0; }
.rank-name { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.rank-sub { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.xp-bar { margin-top: 14px; height: 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; position: relative; }
.xp-bar i { display: block; height: 100%; width: 0; background: var(--grad); border-radius: 999px; transition: width 1.2s cubic-bezier(.2,.8,.2,1); box-shadow: 0 0 18px rgba(168, 85, 247, 0.7); position: relative; }
.xp-bar i::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent); animation: shine 2.4s linear infinite; }
@keyframes shine { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.xp-meta { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.rank-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.rank-stats div { background: rgba(0, 0, 0, 0.25); border-radius: 14px; padding: 10px 12px; text-align: center; }
.rank-stats b { display: block; font-size: 1.3rem; }
.rank-stats span { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* Editor */
.editor { display: flex; flex-direction: column; gap: 10px; }
.exo { border-radius: 16px; padding: 12px 14px; background: rgba(0, 0, 0, 0.22); border: 1px solid var(--card-border); }
.exo-head { display: flex; align-items: center; gap: 10px; }
.exo-ic { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; font-size: 1.1rem; flex: none; background: var(--grad-soft); }
.exo-name { font-weight: 700; flex: 1; }
.exo-total { font-weight: 800; font-size: 1.15rem; }
.exo-total small { color: var(--muted); font-weight: 500; font-size: 0.75rem; margin-left: 3px; }
.sets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px 5px 11px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); font-weight: 600; font-size: 0.9rem; }
.chip button { border: 0; background: rgba(255, 255, 255, 0.12); color: #fff; width: 20px; height: 20px; border-radius: 50%; cursor: pointer; font-size: 0.75rem; line-height: 1; padding: 0; }
.chip button:hover { background: var(--red); }
.add-set { display: flex; gap: 6px; align-items: center; }
.add-set input { width: 66px; padding: 7px 9px; border-radius: 10px; border: 1px solid var(--card-border); background: rgba(0, 0, 0, 0.35); color: #fff; font: inherit; font-weight: 600; text-align: center; }
.add-set button { border: 0; border-radius: 10px; padding: 7px 12px; white-space: nowrap; background: var(--grad); color: #fff; font-weight: 700; cursor: pointer; font: inherit; }
.quick { display: flex; gap: 4px; }
.quick button { border: 1px solid var(--card-border); background: transparent; color: var(--muted); border-radius: 8px; padding: 5px 7px; font-size: 0.75rem; cursor: pointer; font-family: inherit; }
.quick button:hover { color: #fff; border-color: var(--violet); }
.save-state { font-size: 0.75rem; color: var(--muted); text-align: right; margin-top: 8px; min-height: 1em; }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.9rem; user-select: none; }
.switch input { display: none; }
.switch span { width: 44px; height: 26px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); position: relative; transition: 0.2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: 0.2s; }
.switch input:checked + span { background: var(--grad); }
.switch input:checked + span::after { left: 21px; }
.switch em { font-style: normal; font-weight: 600; }

/* Buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 14px; padding: 11px 18px; font: inherit; font-weight: 700; cursor: pointer; color: #fff; background: rgba(255, 255, 255, 0.07); transition: 0.2s; }
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--grad); box-shadow: 0 8px 24px rgba(120, 90, 255, 0.35); }
.btn.ghost { background: transparent; border-color: var(--card-border); color: var(--text); }
.btn.danger { background: var(--red); box-shadow: 0 8px 24px rgba(239, 68, 68, 0.35); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-btn { border: 1px solid var(--card-border); background: var(--card); color: #fff; width: 36px; height: 36px; border-radius: 12px; cursor: pointer; font-size: 1.2rem; display: grid; place-items: center; }
input[type=password], input[type=text], input[type=number], input[type=date] { width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--card-border); background: rgba(0, 0, 0, 0.35); color: #fff; font: inherit; font-size: 1rem; outline: none; }
input:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.2); }
input[type=date] { color-scheme: dark; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.form-row label { display: flex; flex-direction: column; gap: 6px; font-size: 0.8rem; color: var(--muted); }
.form-row .btn { grid-column: 1 / -1; }
@media (min-width: 600px) { .form-row { grid-template-columns: 1fr 1fr auto; } .form-row .btn { grid-column: auto; } }

/* Banner */
.banner { border-radius: 16px; padding: 12px 16px; background: linear-gradient(90deg, rgba(245, 158, 11, 0.18), rgba(236, 72, 153, 0.12)); border: 1px solid rgba(245, 158, 11, 0.4); display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 600; font-size: 0.9rem; }
.banner a { color: var(--amber); text-decoration: underline; white-space: nowrap; }

/* Quote */
.quote-card { border-left: 3px solid var(--violet); }
.quote-card blockquote { margin: 0; font-size: 1.05rem; line-height: 1.4; font-weight: 500; }
.quote-card .who { color: var(--muted); font-size: 0.75rem; margin-top: 8px; text-transform: uppercase; letter-spacing: 0.1em; }

/* Achievements */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.ach { border-radius: 14px; padding: 10px 12px; background: rgba(0, 0, 0, 0.25); border: 1px solid var(--card-border); font-size: 0.8rem; min-height: 68px; }
.ach b { display: block; font-size: 0.9rem; margin-bottom: 3px; }
.ach.locked { opacity: 0.45; filter: grayscale(1); }
.ach.unlocked { border-color: rgba(168, 85, 247, 0.5); background: var(--grad-soft); }
.ach.unlocked b::before { content: "★ "; color: var(--amber); }
.ach .muted { font-size: 0.75rem; }

/* Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head h2 { text-transform: capitalize; }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; color: var(--muted); font-size: 0.75rem; font-weight: 700; margin-bottom: 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.day { aspect-ratio: 1; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem; background: rgba(255, 255, 255, 0.03); border: 1px solid transparent; cursor: pointer; transition: 0.15s; position: relative; }
.day:hover { border-color: var(--violet); }
.day.empty { visibility: hidden; }
.day.future { opacity: 0.25; cursor: default; }
.day.done { background: var(--grad); box-shadow: 0 4px 16px rgba(120, 90, 255, 0.35); }
.day.off { background: rgba(239, 68, 68, 0.16); border-color: rgba(239, 68, 68, 0.35); color: #fca5a5; }
.day.today { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.3); }
.day small { font-size: 0.6rem; font-weight: 600; opacity: 0.85; }
.legend { display: flex; gap: 14px; margin-top: 12px; font-size: 0.75rem; color: var(--muted); flex-wrap: wrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.dot.done { background: var(--grad); } .dot.off { background: rgba(239, 68, 68, 0.5); } .dot.today { border: 2px solid var(--cyan); }

/* Stats */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--card-border); border-radius: 16px; padding: 14px; }
.tile b { display: block; font-size: 1.6rem; font-weight: 800; line-height: 1.1; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tile span { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.chart { position: relative; height: 240px; }
.seg { display: inline-flex; background: rgba(0, 0, 0, 0.3); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 5px 10px; border-radius: 8px; font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--grad); color: #fff; }
.records { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 700px) { .records { grid-template-columns: repeat(4, 1fr); } }
.rec { background: rgba(0, 0, 0, 0.25); border-radius: 14px; padding: 12px; text-align: center; }
.rec b { display: block; font-size: 1.4rem; }
.rec span { font-size: 0.75rem; color: var(--muted); }

/* Weight list */
.wlist { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow: auto; }
.wrow { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 10px; background: rgba(0, 0, 0, 0.2); font-size: 0.9rem; }
.wrow .delta { font-size: 0.8rem; margin-left: 8px; }
.wrow .delta.down { color: var(--green); } .wrow .delta.up { color: var(--red); }
.wrow button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 1rem; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(6px); display: flex; align-items: flex-end; justify-content: center; }
.modal-card { width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--bg2); border: 1px solid var(--card-border); border-radius: 24px 24px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); display: flex; flex-direction: column; gap: 12px; animation: up 0.25s ease; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .modal { align-items: center; } .modal-card { border-radius: 24px; } }

/* Toasts */
#toasts { position: fixed; top: calc(12px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 14px; background: rgba(14, 14, 30, 0.95); border: 1px solid var(--card-border); box-shadow: var(--shadow); font-weight: 600; font-size: 0.9rem; animation: fade 0.25s ease; }
.toast.ach { border-color: var(--amber); background: linear-gradient(90deg, rgba(245, 158, 11, 0.25), rgba(14, 14, 30, 0.95)); }
.toast.rank { border-color: var(--violet); background: var(--grad); font-size: 1rem; }
.toast.err { border-color: var(--red); }

/* Rank-up overlay */
.rankup { position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; background: rgba(7, 7, 15, 0.85); backdrop-filter: blur(10px); animation: fade 0.3s; }
.rankup .inner { text-align: center; animation: pop 0.6s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }
.rankup .rank-badge { width: 140px; height: 156px; margin: 0 auto 16px; }
.rankup .rank-badge b { font-size: 2rem; }
.rankup h1 { font-size: 2rem; }
.rankup p { color: var(--muted); }
