:root {
  --bg: #000;
  --surface: #0e0e0e;
  --surface-2: #161616;
  --line: #242424;
  --line-2: #333;
  --text: #fff;
  --muted: #8d8d8d;
  --dim: #5c5c5c;
  --radius: 16px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: 'Poppins', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(var(--tabs-h) + var(--safe-b) + 24px);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
b, strong { font-weight: 600; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.sm { font-size: 13px; }
.xs { font-size: 11.5px; }
.upper { text-transform: uppercase; letter-spacing: .08em; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: rgba(0,0,0,.86);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-t);
}
.top-inner {
  max-width: 600px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { font-weight: 800; font-size: 17px; letter-spacing: -.02em; display: flex; align-items: center; gap: 2px; }
.brand span { font-weight: 400; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; margin-left: 8px; border: 1.5px solid var(--dim); display: inline-block; }
.sync-dot.online { background: #fff; border-color: #fff; }
.sync-dot.connecting { border-color: #fff; animation: pulse 1s infinite alternate; }
.sync-dot.error { border-color: #fff; border-style: dashed; }
@keyframes pulse { to { opacity: .3; } }

.switch { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.switch button { padding: 6px 13px; border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap; transition: .15s; }
.switch button.on { background: #fff; color: #000; font-weight: 600; }

/* ---------- Layout ---------- */
main { max-width: 600px; margin: 0 auto; padding: 20px 16px 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.page-head.back { justify-content: flex-start; }
.section { margin-top: 26px; }
.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin: 0 0 10px; }
.list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.gap-s { gap: 6px; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 14px; }
.mt-s { margin-top: 8px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px; width: 100%; text-align: left; display: block;
}
button.card { transition: border-color .15s, transform .1s; }
button.card:active { transform: scale(.985); border-color: var(--line-2); }
.card-title { font-weight: 600; font-size: 16px; line-height: 1.3; }
.card .row + .row { margin-top: 6px; }
.chev { color: var(--dim); font-size: 22px; line-height: 1; }
.sets-line { font-size: 13.5px; color: #d6d6d6; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.partner { font-size: 12px; color: var(--muted); margin-top: 4px; }

.back-btn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; flex: none; font-size: 20px; }

/* ---------- Buttons ---------- */
.btn {
  background: #fff; color: #000; font-weight: 600; border-radius: 12px;
  padding: 12px 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); opacity: .85; }
.btn.ghost { background: transparent; color: #fff; border: 1px solid var(--line-2); }
.btn.sm { padding: 7px 13px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.danger { background: transparent; color: #fff; border: 1px dashed #555; }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); display: grid; place-items: center; color: #ddd; flex: none; font-size: 15px; }
.icon-btn:active { background: var(--surface-2); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line-2); font-size: 13px; font-weight: 500; color: var(--muted); }
.chip.on { background: #fff; color: #000; border-color: #fff; font-weight: 600; }

/* ---------- Inputs ---------- */
.input, select.input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; outline: none; font-size: 16px;
}
.input:focus { border-color: #fff; }
select.input { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, #888 50%), linear-gradient(135deg, #888 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 38px; }
input[type="date"].input { color-scheme: dark; }
label.field { display: block; font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 6px; }

/* ---------- Set editor ---------- */
.sets { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.set-row { display: grid; grid-template-columns: 30px 52px 1fr 14px 1fr 34px; gap: 8px; align-items: center; }
.set-n { font-size: 13px; color: var(--muted); font-weight: 600; text-align: center; }
.set-row input {
  width: 100%; min-width: 0; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 10px; text-align: center; font-size: 17px; font-weight: 600; outline: none;
}
.set-row input:focus { border-color: #fff; }
.set-row input::placeholder { color: #4d4d4d; font-weight: 500; }
.set-x { color: var(--dim); text-align: center; font-size: 14px; }
.tag-btn { font-size: 11px; font-weight: 600; padding: 7px 0; border-radius: 9px; border: 1px solid var(--line-2); color: var(--muted); text-align: center; text-transform: uppercase; letter-spacing: .04em; }
.tag-btn.on { background: transparent; border-style: dashed; color: #fff; border-color: #888; }
.set-row.prep input { border-style: dashed; color: #bbb; }
.set-head { display: grid; grid-template-columns: 30px 52px 1fr 14px 1fr 34px; gap: 8px; font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.set-head span { text-align: center; }

.cmp { display: flex; gap: 10px; margin-top: 12px; }
.cmp > div { flex: 1; background: var(--surface-2); border-radius: 12px; padding: 11px 12px; }
.cmp .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }
.cmp .v { font-size: 17px; font-weight: 700; margin-top: 2px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stats.two { grid-template-columns: 1fr 1fr; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; letter-spacing: -.02em; }
.stat .s { font-size: 12px; color: var(--muted); }

.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.duo .card { padding: 14px; }
.duo .who { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.duo .card.me { border-color: #fff; }
.tally { display: flex; gap: 12px; margin-top: 6px; font-weight: 700; font-size: 20px; }
.tally span { display: flex; align-items: baseline; gap: 3px; }
.tally small { font-size: 12px; color: var(--muted); font-weight: 600; }

.trend { font-weight: 700; font-size: 13px; padding: 3px 9px; border-radius: 999px; white-space: nowrap; flex: none; }
.trend.up { background: #fff; color: #000; }
.trend.same { border: 1px solid var(--line-2); color: #ccc; }
.trend.down { border: 1px dashed #777; color: #aaa; }
.trend.new { border: 1px solid var(--line); color: var(--muted); font-weight: 600; }

.chart-box { position: relative; height: 240px; margin-top: 14px; }
.chart-box.sm { height: 170px; }
.empty { text-align: center; color: var(--muted); padding: 34px 16px; border: 1px dashed var(--line-2); border-radius: var(--radius); font-size: 14px; }

.hist-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.hist-item:first-child { border-top: 0; }
.hist-date { font-weight: 600; font-size: 13px; width: 64px; flex: none; }

.week-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.week-nav .lbl { font-weight: 600; text-align: center; }

.edit-row { display: flex; align-items: center; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.edit-row:first-child { border-top: 0; }
.edit-row .name { flex: 1; min-width: 0; font-weight: 500; font-size: 14.5px; }
.unit-pill { font-size: 11px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line-2); color: var(--muted); font-weight: 600; }

.banner { border: 1px dashed var(--line-2); border-radius: var(--radius); padding: 14px 16px; margin-top: 16px; }

/* ---------- Tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  background: rgba(0,0,0,.92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs button { flex: 1; max-width: 150px; height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--dim); font-size: 11px; font-weight: 500; }
.tabs svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: #fff; font-weight: 600; }

/* ---------- Toast / Modal ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 16px); transform: translate(-50%, 20px);
  background: #fff; color: #000; font-weight: 600; font-size: 14px; padding: 11px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 60; white-space: nowrap; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#modal { display: none; }
#modal.open { display: block; position: fixed; inset: 0; z-index: 50; }
.modal-bg { position: absolute; inset: 0; background: rgba(0,0,0,.7); }
.modal-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(420px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 20px; padding: 20px;
}
.modal-card h3 { margin-bottom: 6px; }
.modal-card p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.modal-card .input { margin-top: 8px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

@media (min-width: 640px) {
  main { padding-top: 28px; }
}
