:root {
  --bg: #fbf5f2;
  --bg2: #f4e7e2;
  --card: #ffffff;
  --ink: #3a2622;
  --ink2: #7a625c;
  --line: #ead9d3;
  --brand: #c9677f;
  --brand2: #8a3d52;
  --cocoa: #4a2c27;
  --blue: #5aa7e8;
  --blue2: #2f7fcf;
  --blue-soft: #e3f0fc;
  --ok: #3c9a6e;
  --warn: #c7863a;
  --radius: 18px;
  --shadow: 0 8px 30px rgba(74, 44, 39, 0.1);
  --head: 'Playfair Display', Georgia, serif;
  --body: 'Nunito', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1416; --bg2: #261b1e; --card: #2b1f22; --ink: #f6e9e5; --ink2: #c4aaa3; --line: #3d2c30;
    --brand: #e58aa2; --brand2: #f1b3c3; --cocoa: #f1d9d2; --blue-soft: #1d2d3d; --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font: 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--brand2); }
h1, h2, h3 { font-family: var(--head); font-weight: 700; line-height: 1.15; margin: 0 0 0.4em; }
h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }
.muted { color: var(--ink2); }
.small { font-size: 0.88rem; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo { font-family: var(--head); font-weight: 700; font-size: 1.15rem; letter-spacing: 0.01em; flex: 1; cursor: pointer; }
.logo b { color: var(--brand); }
.logo small { font-family: var(--body); font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink2); margin-left: 6px; }
.iconbtn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; cursor: pointer;
}
.iconbtn svg { width: 22px; height: 22px; }
main { max-width: 980px; margin: 0 auto; padding: 18px 16px 90px; }

.drawer-bg { position: fixed; inset: 0; background: rgba(30, 15, 15, 0.35); z-index: 40; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(320px, 86vw); background: var(--card); z-index: 41; transform: translateX(100%); transition: transform 0.25s ease; padding: 22px 16px; padding-top: max(22px, env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); }
body.menu-open .drawer { transform: none; }
body.menu-open .drawer-bg { opacity: 1; pointer-events: auto; }
.drawer a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; text-decoration: none; color: var(--ink); font-weight: 600; }
.drawer a:hover, .drawer a.active { background: var(--bg2); }
.drawer .who { padding: 4px 14px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }

/* ---------- common ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 20px;
  border-radius: 999px; border: 1px solid transparent; background: var(--brand); color: #fff; font-weight: 700;
  cursor: pointer; text-decoration: none; transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn.blue { background: var(--blue2); }
.btn.ghost { background: transparent; color: var(--brand2); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.55; pointer-events: none; }
label.field { display: grid; gap: 6px; font-weight: 600; font-size: 0.92rem; }
input.input, textarea.input, select.input {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); outline: none;
}
input.input:focus, textarea.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.err { color: #c0392b; font-weight: 600; min-height: 1.2em; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--bg2); font-size: 0.8rem; font-weight: 700; color: var(--ink2); }
.pill.blue { background: var(--blue-soft); color: var(--blue2); }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }

/* the comforting blue progress bar */
.progress { height: 14px; border-radius: 999px; background: var(--blue-soft); overflow: hidden; position: relative; }
.progress > i {
  position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, #8cc7f5, var(--blue) 55%, var(--blue2));
  box-shadow: 0 0 14px rgba(90, 167, 232, 0.55) inset; transition: width 0.6s ease;
}
.progress.thin { height: 8px; }

/* ---------- welcome ---------- */
.hero { display: grid; gap: 18px; padding: 26px 4px 8px; }
.hero p { font-size: 1.08rem; max-width: 560px; }
.hero .tag { font-size: 0.75rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--brand); font-weight: 800; }
.features { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-top: 8px; }
.features .card { padding: 14px; }
.tabs { display: flex; gap: 6px; background: var(--bg2); padding: 4px; border-radius: 999px; margin-bottom: 14px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 999px; font-weight: 700; cursor: pointer; color: var(--ink2); }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); }

/* ---------- quiz ---------- */
.quiz { max-width: 640px; margin: 0 auto; }
.quiz .q { font-family: var(--head); font-size: 1.6rem; margin: 18px 0 16px; }
.options { display: grid; gap: 10px; }
.opt {
  text-align: left; padding: 14px 16px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card);
  cursor: pointer; display: grid; gap: 2px; font-weight: 700;
}
.opt span { font-weight: 400; color: var(--ink2); font-size: 0.9rem; }
.opt.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--card)); }
.options.chips { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.trainers { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.trainer { padding: 14px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--card); cursor: pointer; text-align: left; display: grid; gap: 6px; }
.trainer.on { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.trainer .face { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-family: var(--head); font-size: 1.6rem; color: #fff; }
.quiz-nav { display: flex; justify-content: space-between; margin-top: 22px; gap: 10px; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.cal-head h2 { flex: 1; margin: 0; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .dow { text-align: center; font-size: 0.75rem; font-weight: 800; color: var(--ink2); text-transform: uppercase; letter-spacing: 0.08em; padding: 4px 0; }
.day {
  aspect-ratio: 1 / 1.08; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 6px;
  display: flex; flex-direction: column; gap: 2px; cursor: pointer; position: relative; overflow: hidden; text-align: left;
  transition: transform 0.08s;
}
.day:active { transform: scale(0.97); }
.day .n { font-weight: 800; font-size: 0.9rem; }
.day .t { font-size: 0.66rem; line-height: 1.15; color: var(--ink2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.day.empty { background: transparent; border-color: transparent; cursor: default; }
.day.off { opacity: 0.45; cursor: default; }
.day.workout { background: linear-gradient(160deg, var(--card), color-mix(in srgb, var(--brand) 9%, var(--card))); }
.day.workout::after { content: ''; position: absolute; right: 7px; top: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.day.done { background: linear-gradient(160deg, var(--blue-soft), color-mix(in srgb, var(--blue) 30%, var(--card))); border-color: color-mix(in srgb, var(--blue) 45%, var(--line)); }
.day.done::after { background: var(--blue2); content: '✓'; color: #fff; width: 16px; height: 16px; font-size: 10px; display: grid; place-items: center; top: 5px; right: 5px; }
.day.today { outline: 2.5px solid var(--brand); outline-offset: 1px; }
.day.moving { outline: 2.5px dashed var(--blue2); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 0.82rem; color: var(--ink2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }

.sheet-bg { position: fixed; inset: 0; background: rgba(30, 15, 15, 0.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: min(640px, 100%); max-height: 88vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 18px 16px; padding-bottom: max(18px, env(safe-area-inset-bottom)); animation: up 0.22s ease; }
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 22px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.loc-preview { height: 150px; border-radius: 14px; margin: 10px 0; position: relative; overflow: hidden; display: flex; align-items: flex-end; padding: 12px; color: #fff; font-weight: 800; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.4); }
.moves { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; }
.moves li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 12px; border-radius: 10px; background: var(--bg); font-size: 0.92rem; }
.moves li b { font-weight: 700; }

/* ---------- progress ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.stat b { display: block; font-family: var(--head); font-size: 1.8rem; color: var(--blue2); }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: calc(100dvh - 190px); min-height: 360px; }
.chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 8px 2px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 16px; background: var(--bg2); white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.trainer { align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 8px; padding-top: 10px; }
.chat-input input { flex: 1; }
.mic { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--blue2); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.mic.live { background: #d9455f; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(217, 69, 95, 0.15); } }
.mic svg { width: 22px; height: 22px; }

/* ---------- session player ---------- */
body.in-session { overflow: hidden; }
body.in-session .topbar { display: none; }
.player { position: fixed; inset: 0; z-index: 60; background: #111; color: #fff; overflow: hidden; }
.player canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud { position: absolute; inset: 0; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; padding: 12px; padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.hud > * { pointer-events: auto; }
.hud-top { display: grid; gap: 8px; }
.hud-row { display: flex; align-items: center; gap: 10px; }
.glass { background: rgba(20, 14, 16, 0.42); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 16px; }
.hud .progress { background: rgba(255, 255, 255, 0.2); }
.hud .iconbtn { background: rgba(20, 14, 16, 0.42); border-color: rgba(255, 255, 255, 0.18); color: #fff; backdrop-filter: blur(10px); }
.now { padding: 10px 14px; display: flex; align-items: center; gap: 14px; }
.now h2 { margin: 0; font-size: 1.35rem; }
.now .sub { font-size: 0.85rem; opacity: 0.85; }
.ring { width: 66px; height: 66px; flex: none; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.countdown { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; }
.countdown .big { font-family: var(--head); font-size: clamp(5rem, 22vw, 9rem); line-height: 1; text-shadow: 0 6px 30px rgba(0, 0, 0, 0.45); animation: beat 1s ease infinite; }
.countdown .lbl { font-size: 1.1rem; letter-spacing: 0.2em; text-transform: uppercase; opacity: 0.9; }
@keyframes beat { 0% { transform: scale(1.15); opacity: 0.4; } 30% { transform: scale(1); opacity: 1; } }
.cues { padding: 12px 14px; max-width: 460px; font-size: 0.92rem; display: grid; gap: 4px; }
.cues .k { font-size: 0.68rem; letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.7; font-weight: 800; }
.cues .say { font-size: 1.02rem; font-weight: 700; }
.hud-bottom { display: grid; gap: 10px; }
.controls { display: flex; justify-content: center; gap: 12px; align-items: center; }
.controls .iconbtn { width: 52px; height: 52px; border-radius: 50%; }
.controls .play { width: 66px; height: 66px; background: var(--brand); border: 0; }
.subtitle { text-align: center; font-weight: 700; font-size: 1.02rem; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); min-height: 1.5em; padding: 0 8px; }
.ask { display: flex; gap: 8px; padding: 6px; }
.ask input { flex: 1; min-height: 44px; border-radius: 999px; border: 0; padding: 0 16px; background: rgba(255, 255, 255, 0.14); color: #fff; outline: none; }
.ask input::placeholder { color: rgba(255, 255, 255, 0.7); }
.tech-toggle { font-size: 0.8rem; }
.cues.collapsed .more { display: none; }
@media (max-width: 640px) {
  .cues { max-width: none; }
  .now h2 { font-size: 1.12rem; }
}
.finish { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 14, 16, 0.55); backdrop-filter: blur(6px); z-index: 5; padding: 16px; }
.finish .card { color: var(--ink); max-width: 420px; text-align: center; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--cocoa); color: var(--bg); padding: 12px 18px; border-radius: 14px; z-index: 90; box-shadow: var(--shadow); font-weight: 600; max-width: 92vw; animation: up 0.2s ease; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--blue-soft); border-top-color: var(--blue2); animation: spin 0.9s linear infinite; margin: 10px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- admin ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tbl th, .tbl td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink2); }
.tbl-wrap { overflow-x: auto; }
