:root {
  --bg: #0d0d0f; --panel: #16161a; --panel-2: #1e1e24; --line: #2c2c35;
  --text: #ece9e1; --muted: #9b978c; --gold: #d4af37; --gold-2: #f1d67a; --gold-dim: #8a7426;
  --ok: #4fbf7f; --warn: #e5a23a; --bad: #e0605a;
  --radius: 12px; --shadow: 0 6px 24px rgba(0,0,0,.35);
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; font-size: 15px; line-height: 1.45; }
a { color: var(--gold); }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; letter-spacing: .02em; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; color: var(--gold-2); } h3 { font-size: 1.05rem; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .gold { color: var(--gold); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

/* layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.brand img { width: 38px; height: 38px; }
.brand b { font-family: Georgia, serif; color: var(--gold); letter-spacing: .12em; font-size: .95rem; display: block; }
.brand span { font-size: .75rem; color: var(--muted); letter-spacing: .2em; }
.nav a { display: flex; justify-content: space-between; padding: 10px 12px; border-radius: 8px; color: var(--text); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--panel-2); }
.nav a.active { background: linear-gradient(90deg, rgba(212,175,55,.18), transparent); color: var(--gold-2); border-left: 3px solid var(--gold); }
.side .who { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; font-size: .85rem; }
.main { padding: 28px clamp(16px, 4vw, 40px) 80px; max-width: 1200px; width: 100%; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; gap: 6px; }
  .brand { margin: 0 8px 0 0; } .nav { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; }
  .nav a { padding: 7px 10px; font-size: .85rem; } .side .who { margin: 0; border: 0; padding: 0; width: 100%; }
}

/* cards & controls */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.click { cursor: pointer; transition: border-color .15s, transform .15s; }
.card.click:hover { border-color: var(--gold-dim); transform: translateY(-1px); }
.stat { font-size: 1.7rem; font-weight: 700; color: var(--gold-2); }
.stat small { font-size: .9rem; color: var(--muted); font-weight: 400; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; border: 1px solid var(--line); color: var(--muted); }
.pill.gold { border-color: var(--gold-dim); color: var(--gold); }
.pill.ok { border-color: #2f6b4a; color: var(--ok); } .pill.warn { border-color: #7a5a22; color: var(--warn); }
.badge { background: var(--gold); color: #111; border-radius: 99px; padding: 0 7px; font-size: .75rem; font-weight: 700; }
button, .btn { font: inherit; border: 1px solid var(--gold-dim); background: linear-gradient(180deg, #e0bd4b, #b9952a); color: #141210; font-weight: 600; padding: 9px 16px; border-radius: 8px; cursor: pointer; }
button.ghost { background: transparent; color: var(--gold); }
button.danger { background: transparent; color: var(--bad); border-color: #6b2f2c; }
button.sm { padding: 5px 10px; font-size: .85rem; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; }
input[type=checkbox] { width: auto; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 16px 0 20px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--gold-2); border-color: var(--gold); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin: 6px 0 2px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-dim), var(--gold-2)); }
.bar.over > i { background: linear-gradient(90deg, #8a3b37, var(--bad)); }
.section { margin-bottom: 24px; }
.banner { border: 1px dashed var(--gold-dim); background: rgba(212,175,55,.07); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; color: var(--gold-2); }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(ellipse at top, rgba(212,175,55,.12), transparent 60%), var(--bg); }
.login { width: min(420px, 100%); }
.login .brand { justify-content: center; flex-direction: column; text-align: center; }
.login .brand img { width: 72px; height: 72px; }
.login .brand b { font-size: 1.4rem; }
.demo { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.demo button { margin: 4px 4px 0 0; }

/* messages */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; padding: 6px; }
.msg { max-width: 75%; padding: 9px 13px; border-radius: 14px; background: var(--panel-2); white-space: pre-wrap; word-wrap: break-word; }
.msg.mine { align-self: flex-end; background: linear-gradient(180deg, #3a3217, #2a2410); border: 1px solid var(--gold-dim); }
.msg .meta { font-size: .72rem; color: var(--muted); margin-top: 3px; }
.composer { display: flex; gap: 8px; margin-top: 10px; } .composer textarea { min-height: 46px; }

/* program */
.day { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; background: var(--panel-2); }
.day h3 { display: flex; gap: 8px; align-items: center; }
.type-lift { color: var(--gold); } .type-cardio { color: #6fb3e0; } .type-rest { color: var(--muted); }
.ex-edit td input { padding: 5px 7px; font-size: .85rem; }

/* photos */
.photos { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.photos img { width: 110px; height: 140px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); display: grid; place-items: center; z-index: 50; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }
.scale { display: flex; gap: 4px; } .scale button { flex: 1; padding: 6px 0; background: var(--panel-2); color: var(--text); border-color: var(--line); }
.scale button.on { background: var(--gold); color: #111; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--gold-dim); padding: 10px 18px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow); }
.toast.err { border-color: var(--bad); color: #ffb3ae; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 55; padding: 16px; }
.modal { width: min(640px, 100%); max-height: 90vh; overflow-y: auto; }
canvas { max-width: 100%; }

/* ===== v2: sign-up, habits, workout logger ===== */
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.g3m { display: grid; gap: 0 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.join { width: min(520px, 100%); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 44px; min-height: 46px; background: var(--panel-2); color: var(--text); border-color: var(--line); font-weight: 500; }
.seg button.on { background: var(--gold); color: #111; border-color: var(--gold); font-weight: 700; }
.err-box { margin-top: 12px; padding: 10px 12px; border: 1px solid #6b2f2c; border-radius: 8px; color: #ffb3ae; background: rgba(224,96,90,.08); font-size: .9rem; }
button.big, .btn.big { min-height: 52px; font-size: 1.05rem; display: block; }
.btn { display: inline-block; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips .on { background: var(--gold); color: #111; }
.grow { flex: 1; }

.habits { display: grid; gap: 8px; }
.habit { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; text-align: left; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; font-weight: 500; transition: background .15s, border-color .15s; }
.habit .tick { width: 32px; height: 32px; flex: none; border-radius: 50%; border: 2px solid var(--gold-dim); display: grid; place-items: center; font-weight: 800; color: #111; }
.habit.done { border-color: var(--gold-dim); background: linear-gradient(90deg, rgba(212,175,55,.16), var(--panel-2)); }
.habit.done .tick { background: var(--gold); border-color: var(--gold); }
.habit .hname { flex: 1; display: flex; flex-direction: column; }
.habit small { color: var(--muted); font-weight: 400; font-size: .78rem; }
.habit .streak { text-align: right; display: flex; flex-direction: column; font-size: .9rem; color: var(--gold-2); }
.dots { display: flex; gap: 3px; } .dots i { width: 10px; height: 10px; border-radius: 3px; background: var(--panel-2); border: 1px solid var(--line); }
.dots i.on { background: var(--gold); border-color: var(--gold); } .dots i.na { opacity: .25; }

.wrow { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; }
.wrow:hover b { color: var(--gold-2); }
.start-card { background: linear-gradient(160deg, rgba(212,175,55,.12), var(--panel) 60%); }
.wk-head { position: sticky; top: 0; z-index: 20; background: rgba(13,13,15,.96); backdrop-filter: blur(6px); padding: 10px 0 8px; margin: -10px 0 12px; border-bottom: 1px solid var(--line); }
.wname { font-size: 1.15rem; font-weight: 700; background: transparent; border-color: transparent; padding: 6px 4px; }
.wname:focus { border-color: var(--gold); }
.finish { min-height: 46px; padding: 0 20px; }
.mini { width: auto; padding: 4px 6px; font-size: .85rem; }
.wx { margin-bottom: 12px; padding: 14px; }
.wx .last { color: var(--muted); margin: 4px 0 8px; }
.exlink { color: var(--gold-2); text-decoration: none; }
.set { display: grid; grid-template-columns: 34px minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1fr) 52px; gap: 6px; align-items: center; padding: 4px 0; border-radius: 8px; }
.set.head { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 0; }
.set .sn { text-align: center; font-weight: 700; color: var(--gold); }
.set .prev { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.set input { min-height: 44px; text-align: center; font-size: 1.05rem; padding: 6px 4px; }
.set .chk { min-height: 44px; padding: 0; font-size: 1.2rem; background: var(--panel-2); color: var(--muted); border-color: var(--line); }
.set.done { background: rgba(79,191,127,.10); }
.set.done .chk { background: var(--ok); color: #0d0d0f; border-color: var(--ok); }
.set.done input { border-color: #2f6b4a; }
.restbar { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 45; background: var(--panel-2);
  border: 1px solid var(--gold-dim); border-radius: 14px; padding: 10px 14px; overflow: hidden; box-shadow: var(--shadow); max-width: 560px; margin: 0 auto; }
.restfill { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(212,175,55,.16); transition: width .5s linear; }
.restt { font-size: 1.6rem; color: var(--gold-2); font-variant-numeric: tabular-nums; }
.restbar button { min-height: 44px; min-width: 56px; }
.exres { display: grid; gap: 6px; max-height: 55vh; overflow-y: auto; margin-top: 10px; }
.exitem { display: flex; justify-content: space-between; align-items: center; text-align: left; min-height: 50px; background: var(--panel-2); color: var(--text); border-color: var(--line); font-weight: 500; }
.exitem small { color: var(--muted); font-weight: 400; } .exitem.custom { border-style: dashed; color: var(--gold); }
.summary-hero { text-align: center; margin: 8px 0 18px; } .summary-hero .trophy { font-size: 3rem; }
.pr-card { border-color: var(--gold-dim); background: linear-gradient(160deg, rgba(212,175,55,.14), var(--panel) 70%); }

/* mobile-first client chrome */
@media (max-width: 820px) {
  .side { position: static; padding: 8px 10px; }
  .nav { flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; min-height: 40px; align-items: center; gap: 6px; }
  .side .who { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .side .who .row { margin-top: 0 !important; }
  .side .who > div:nth-child(2) { display: none; }
  .main { padding: 16px 12px 110px; }
  .hide-sm { display: none; }
  .wk-head { top: 0; }
  .modal { max-height: 92vh; }
  .modal-bg { align-items: end; padding: 0; } .modal-bg .modal { border-radius: 16px 16px 0 0; width: 100%; }
}
.shell > * { min-width: 0; }
.seg { flex-wrap: nowrap; }
.seg button { flex: 1 1 0; min-width: 0; padding: 0 4px; font-size: .92rem; }
.g2m { display: grid; gap: 0 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  html, body { overflow-x: hidden; }
}
@media (max-width: 820px) {
  .card table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
