:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 68px;
}
* { -webkit-tap-highlight-color: transparent; box-sizing: border-box; }
html, body { font-family: 'Cairo', system-ui, sans-serif; overscroll-behavior-y: none; }
body { min-height: 100dvh; background: radial-gradient(1200px 600px at 50% -200px, #1e1b4b 0%, #020617 60%); }

.app-shell { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; position: relative; }
.app-header {
  position: sticky; top: 0; z-index: 30; display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + var(--safe-top)) 16px 10px; backdrop-filter: blur(14px);
  background: rgba(2, 6, 23, .7); border-bottom: 1px solid rgba(255,255,255,.06);
}
.logo-emoji { font-size: 26px; filter: drop-shadow(0 0 10px rgba(245,158,11,.5)); }
.streak-badge { background: linear-gradient(135deg,#f97316,#f59e0b); color:#0f172a; border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 700; }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; background: rgba(255,255,255,.08); display:flex;align-items:center;justify-content:center; }

.app-main { flex: 1; padding: 16px 16px calc(var(--nav-h) + 20px + var(--safe-bottom)); }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; margin: 0 auto; max-width: 520px; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  padding: 8px 6px calc(8px + var(--safe-bottom)); background: rgba(2,6,23,.92); backdrop-filter: blur(16px);
  border-top: 1px solid rgba(255,255,255,.07);
}
.nav-item { display:flex; flex-direction:column; align-items:center; gap:3px; color:#94a3b8; font-size: 11px; font-weight: 600; padding: 4px 0; transition: color .2s; }
.nav-item i { font-size: 19px; }
.nav-item.active { color: #fbbf24; }
.nav-mirror .mirror-circle { width: 52px; height: 52px; border-radius: 50%; margin-top: -26px; display:flex;align-items:center;justify-content:center;
  background: linear-gradient(135deg,#f59e0b,#ef4444); box-shadow: 0 8px 24px rgba(245,158,11,.45); color:#fff; border: 4px solid #020617; }
.nav-mirror .mirror-circle i { font-size: 20px; }

/* Cards */
.card { background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08); border-radius: 20px; padding: 16px; }
.card-glow { background: linear-gradient(135deg, rgba(245,158,11,.18), rgba(239,68,68,.08)); border-color: rgba(245,158,11,.35); }
.stat { text-align: center; padding: 10px 4px; border-radius: 14px; background: rgba(255,255,255,.04); }
.stat b { display:block; font-size: 22px; color:#fbbf24; }
.stat span { font-size: 11px; color:#94a3b8; }

/* Buttons */
.btn-primary { background: linear-gradient(135deg,#f59e0b,#f97316); color:#0f172a; font-weight: 800; padding: 14px 18px; border-radius: 16px; font-size: 16px; box-shadow: 0 8px 20px rgba(245,158,11,.3); transition: transform .1s; }
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .5; }
.btn-ghost { background: rgba(255,255,255,.07); color:#e2e8f0; font-weight: 700; padding: 12px 18px; border-radius: 16px; }
.btn-danger { background: rgba(239,68,68,.15); color:#fca5a5; border: 1px solid rgba(239,68,68,.35); font-weight: 700; padding: 12px 18px; border-radius: 16px; }
.chip { display:inline-flex; align-items:center; gap:6px; padding: 8px 14px; border-radius: 999px; background: rgba(255,255,255,.07); font-size: 13px; font-weight: 700; color:#e2e8f0; border: 1px solid transparent; }
.chip.active { background: rgba(245,158,11,.2); border-color: #f59e0b; color:#fbbf24; }

/* Big timer ring */
.ring-wrap { position: relative; width: 240px; height: 240px; margin: 0 auto; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-bg { stroke: rgba(255,255,255,.08); }
.ring-fg { stroke: url(#grad); stroke-linecap: round; transition: stroke-dashoffset .5s linear; }
.ring-center { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; }
.ring-time { font-size: 48px; font-weight: 800; letter-spacing: 1px; }
.ring-label { font-size: 13px; color:#94a3b8; }

/* Mirror */
.mirror-wrap { position: relative; width: 100%; aspect-ratio: 3/4; border-radius: 24px; overflow: hidden; background:#000; border: 2px solid rgba(255,255,255,.1); }
.mirror-wrap video, .mirror-wrap canvas { position:absolute; inset:0; width:100%; height:100%; object-fit: cover; transform: scaleX(-1); }
.mirror-wrap.smiling { border-color: #22c55e; box-shadow: 0 0 30px rgba(34,197,94,.4); }
.mirror-hud { position:absolute; top: 12px; left: 12px; right: 12px; display:flex; justify-content:space-between; z-index: 5; }
.hud-pill { background: rgba(0,0,0,.55); backdrop-filter: blur(6px); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 700; }
.smile-meter { position:absolute; bottom: 12px; left: 12px; right: 12px; z-index:5; height: 14px; border-radius: 999px; background: rgba(0,0,0,.55); overflow:hidden; }
.smile-meter > div { height:100%; width:0%; background: linear-gradient(90deg,#ef4444,#f59e0b,#22c55e); transition: width .15s; }
.mirror-overlay-msg { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; flex-direction: column; gap: 10px; background: rgba(2,6,23,.85); z-index: 10; text-align:center; padding: 20px; }

/* Exercise */
.exercise-item { display:flex; gap: 12px; align-items:flex-start; padding: 14px; border-radius: 16px; background: rgba(255,255,255,.04); border:1px solid rgba(255,255,255,.06); }
.exercise-item .ex-icon { width: 44px; height: 44px; border-radius: 14px; flex-shrink:0; display:flex;align-items:center;justify-content:center; font-size: 22px; background: rgba(245,158,11,.15); }

/* Program grid */
.program-grid { display:grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.day-cell { aspect-ratio: 1; border-radius: 12px; display:flex; align-items:center; justify-content:center; font-weight: 800; font-size: 14px; background: rgba(255,255,255,.05); color:#94a3b8; border: 1px solid rgba(255,255,255,.06); }
.day-cell.done { background: linear-gradient(135deg,#22c55e,#16a34a); color:#fff; border-color: transparent; }
.day-cell.today { border-color: #f59e0b; color:#fbbf24; box-shadow: 0 0 0 2px rgba(245,158,11,.3); }
.day-cell.locked { opacity: .35; }

/* Toast */
.toast { position: fixed; bottom: calc(var(--nav-h) + 16px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); z-index: 100;
  background: #fbbf24; color: #0f172a; font-weight: 800; padding: 12px 20px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 90%; text-align:center; animation: pop .25s ease; }
@keyframes pop { from { transform: translate(-50%, 10px); opacity: 0 } to { transform: translate(-50%, 0); opacity: 1 } }

/* Reminder overlay */
.reminder-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(2,6,23,.92); backdrop-filter: blur(10px); display:flex; align-items:center; justify-content:center; padding: 24px; }
.reminder-card { background: linear-gradient(160deg,#1e1b4b,#0f172a); border: 1px solid rgba(245,158,11,.4); border-radius: 28px; padding: 28px 22px; width: 100%; max-width: 380px; text-align: center; }

/* Mood */
.mood-row { display:flex; justify-content: space-between; gap: 6px; }
.mood-btn { flex:1; font-size: 28px; padding: 10px 0; border-radius: 14px; background: rgba(255,255,255,.05); transition: transform .1s; }
.mood-btn:active { transform: scale(.9); }

/* Range */
input[type=range] { width: 100%; accent-color: #f59e0b; }
select, input[type=number] { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); border-radius: 12px; padding: 10px 12px; color: #fff; width: 100%; font-family: inherit; }
.toggle { position: relative; width: 50px; height: 28px; border-radius: 999px; background: rgba(255,255,255,.15); transition: .2s; flex-shrink:0; }
.toggle::after { content:''; position:absolute; top:3px; right:3px; width: 22px; height: 22px; border-radius:50%; background:#fff; transition: .2s; }
.toggle.on { background: #f59e0b; }
.toggle.on::after { right: 25px; }

.fade-in { animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }
.pulse-soft { animation: pulseSoft 2s infinite; }
@keyframes pulseSoft { 0%,100% { box-shadow: 0 0 0 0 rgba(245,158,11,.4) } 50% { box-shadow: 0 0 0 14px rgba(245,158,11,0) } }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
.offline-badge { background: rgba(239,68,68,.2); color:#fca5a5; border: 1px solid rgba(239,68,68,.4); border-radius: 999px; padding: 4px 10px; font-size: 11px; font-weight: 700; }
.hidden { display: none !important; }

/* ===== v2 features ===== */
.sos-cta { width:100%; display:flex; align-items:center; gap:12px; padding:14px 16px; border-radius:18px; text-align:right;
  background: linear-gradient(135deg, rgba(59,130,246,.25), rgba(139,92,246,.2)); border:1px solid rgba(99,102,241,.45); color:#e0e7ff; }
.sos-cta-icon { font-size:30px; }
.sos-fab { position: fixed; z-index: 45; left: 14px; bottom: calc(var(--nav-h) + 14px + var(--safe-bottom)); width: 58px; height: 58px; border-radius: 50%;
  background: linear-gradient(135deg,#3b82f6,#8b5cf6); box-shadow: 0 8px 24px rgba(99,102,241,.5); display:flex; flex-direction:column; align-items:center; justify-content:center; font-size: 22px; line-height:1; color:#fff; border: 3px solid #020617; }
.sos-fab span { font-size: 9px; font-weight: 800; margin-top: 1px; }
.sos-wrap { padding-top: 6px; }
.sos-ring-wrap { display:flex; justify-content:center; align-items:center; height: 260px; }
.sos-ring { width: 170px; height: 170px; border-radius:50%; border: 6px solid #3b82f6; display:flex; align-items:center; justify-content:center;
  transition: transform 4s ease-in-out, border-color .6s, box-shadow .6s; box-shadow: 0 0 60px rgba(59,130,246,.4); background: radial-gradient(circle, rgba(255,255,255,.06), transparent 70%); }
.sos-ring-inner { text-align:center; }
.sos-phase { font-size: 22px; font-weight: 800; }
.sos-count { font-size: 40px; font-weight: 800; color:#fbbf24; line-height: 1; margin-top: 4px; }
.sos-dot { width: 10px; height: 10px; border-radius: 50%; background: rgba(255,255,255,.15); }
.sos-dot.on { background: #22c55e; }

.stat-link { border: 1px solid rgba(245,158,11,.35); cursor: pointer; }
.badge-grid { display:grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.badge-cell { background: rgba(255,255,255,.04); border:1px solid rgba(255,255,255,.07); border-radius: 16px; padding: 14px 10px; text-align:center; opacity:.45; filter: grayscale(1); }
.badge-cell.on { opacity:1; filter:none; border-color: rgba(245,158,11,.5); background: linear-gradient(160deg, rgba(245,158,11,.15), rgba(255,255,255,.03)); }
.badge-cell .badge-emoji { font-size: 34px; margin-bottom: 4px; }
.badge-cell b { display:block; font-size: 13px; }
.badge-cell span { font-size: 11px; color:#94a3b8; }
.badge-pop { position: fixed; top: calc(70px + var(--safe-top)); left: 50%; transform: translate(-50%, -30px); opacity: 0; z-index: 300; display:flex; gap: 12px; align-items:center;
  background: linear-gradient(135deg,#1e1b4b,#0f172a); border: 1px solid rgba(245,158,11,.6); border-radius: 20px; padding: 12px 18px; width: min(92%, 360px); box-shadow: 0 20px 40px rgba(0,0,0,.5); transition: .35s; }
.badge-pop.show { transform: translate(-50%, 0); opacity: 1; }
.badge-pop-emoji { font-size: 40px; }
.confetti { position: fixed; inset: 0; z-index: 290; pointer-events: none; }

.onb-overlay { position: fixed; inset: 0; z-index: 250; background: rgba(2,6,23,.96); display:flex; align-items:center; justify-content:center; padding: 20px; }
.onb-card { width: 100%; max-width: 400px; text-align: center; background: linear-gradient(160deg,#1e1b4b,#0f172a); border: 1px solid rgba(245,158,11,.35); border-radius: 28px; padding: 30px 22px; }
.onb-emoji { font-size: 72px; margin-bottom: 10px; filter: drop-shadow(0 0 20px rgba(245,158,11,.5)); }
.onb-dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.2); }
.onb-dot.on { background: #f59e0b; width: 22px; border-radius: 6px; }
.onb-card input { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); border-radius: 12px; padding: 12px; color:#fff; width:100%; font-family: inherit; text-align:center; }

.snaps-grid { display:grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.snap { position: relative; aspect-ratio: 3/4; border-radius: 12px; overflow:hidden; background:#000; }
.snap img { width:100%; height:100%; object-fit: cover; }
.snap span { position:absolute; bottom:0; left:0; right:0; background: rgba(0,0,0,.6); font-size: 10px; text-align:center; padding: 3px; font-weight:700; }
.snap-del { position:absolute; top:4px; left:4px; width: 22px; height: 22px; border-radius: 50%; background: rgba(239,68,68,.85); color:#fff; font-weight: 800; font-size: 14px; line-height: 1; }
.snap-view { position: fixed; inset:0; z-index: 400; background: rgba(0,0,0,.95); display:flex; align-items:center; justify-content:center; }
.snap-view img { max-width: 96%; max-height: 90%; border-radius: 16px; }

/* ===== v3 ===== */
.quick-grid { display:grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick { display:flex; flex-direction:column; align-items:center; gap:4px; padding: 10px 4px; border-radius: 14px; background: rgba(255,255,255,.05); border:1px solid rgba(255,255,255,.07); font-size: 11px; font-weight: 700; color:#e2e8f0; }
.quick span { font-size: 24px; }
.guided-card { width:100%; display:flex; align-items:center; gap:12px; padding:14px; border-radius:18px; text-align:right; background: rgba(255,255,255,.05); border:1px solid rgba(255,255,255,.08); color:#e2e8f0; }
.j-resp { padding: 12px 14px; border-radius: 14px; background: rgba(255,255,255,.05); border: 1px solid transparent; font-weight: 700; font-size: 14px; color:#e2e8f0; }
.j-resp.active { border-color: #f59e0b; background: rgba(245,158,11,.15); }
#j-note { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); border-radius: 12px; padding: 10px 12px; color:#fff; font-family: inherit; }

/* Themes */
:root[data-theme="sunrise"] body { background: radial-gradient(1200px 600px at 50% -200px, #7c2d12 0%, #1c0a05 60%); }
:root[data-theme="sunrise"] .app-header, :root[data-theme="sunrise"] .bottom-nav { background: rgba(28,10,5,.85); }
:root[data-theme="forest"] body { background: radial-gradient(1200px 600px at 50% -200px, #14532d 0%, #021a0d 60%); }
:root[data-theme="forest"] .app-header, :root[data-theme="forest"] .bottom-nav { background: rgba(2,26,13,.85); }
:root[data-theme="forest"] .btn-primary { background: linear-gradient(135deg,#22c55e,#16a34a); box-shadow: 0 8px 20px rgba(34,197,94,.3); }
:root[data-theme="forest"] .nav-item.active, :root[data-theme="forest"] .stat b { color:#86efac; }
:root[data-theme="light"] body { background: #f1f5f9; color:#0f172a; }
:root[data-theme="light"] .text-slate-100, :root[data-theme="light"] body { color:#0f172a; }
:root[data-theme="light"] .app-header, :root[data-theme="light"] .bottom-nav { background: rgba(255,255,255,.92); border-color: rgba(0,0,0,.08); }
:root[data-theme="light"] .card, :root[data-theme="light"] .stat, :root[data-theme="light"] .exercise-item, :root[data-theme="light"] .quick, :root[data-theme="light"] .guided-card, :root[data-theme="light"] .j-resp, :root[data-theme="light"] .day-cell, :root[data-theme="light"] .badge-cell, :root[data-theme="light"] .mood-btn, :root[data-theme="light"] .chip, :root[data-theme="light"] .btn-ghost, :root[data-theme="light"] .icon-btn { background: #fff; border-color: rgba(0,0,0,.08); color:#0f172a; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
:root[data-theme="light"] .card-glow { background: linear-gradient(135deg, #fff7ed, #fff); border-color: #fdba74; }
:root[data-theme="light"] .text-slate-300, :root[data-theme="light"] .text-slate-200, :root[data-theme="light"] .stat span, :root[data-theme="light"] .nav-item, :root[data-theme="light"] .ring-label, :root[data-theme="light"] .badge-cell span { color:#475569; }
:root[data-theme="light"] .text-slate-400, :root[data-theme="light"] .text-slate-500 { color:#64748b; }
:root[data-theme="light"] .stat b, :root[data-theme="light"] .nav-item.active, :root[data-theme="light"] .text-amber-300 { color:#d97706; }
:root[data-theme="light"] .btn-primary { color:#fff; }
:root[data-theme="light"] .reminder-card, :root[data-theme="light"] .onb-card, :root[data-theme="light"] .badge-pop { background: #fff; color:#0f172a; }
:root[data-theme="light"] .reminder-overlay, :root[data-theme="light"] .onb-overlay { background: rgba(241,245,249,.95); }
:root[data-theme="light"] select, :root[data-theme="light"] input[type=number], :root[data-theme="light"] #j-note, :root[data-theme="light"] .onb-card input { background:#fff; color:#0f172a; border-color: rgba(0,0,0,.15); }
:root[data-theme="light"] .ring-bg { stroke: rgba(0,0,0,.08); }
:root[data-theme="light"] .sos-cta { color:#1e1b4b; }
:root[data-theme="light"] .text-amber-200\/80 { color:#b45309; }
:root[data-theme="light"] .sos-fab { border-color:#fff; }
