:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --muted: #646b78;
  --border: #dde1e7;
  --accent: #0a7cff;
  --accent-contrast: #ffffff;
  --good: #1f9d55;
  --danger: #d64545;
  --warn: #c77700;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #22262e;
    --text: #e9ebef;
    --muted: #9aa2b1;
    --border: #2c313b;
    --accent: #3d95ff;
    --good: #3cc47c;
    --danger: #f06363;
    --warn: #f0a33a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0 0 12px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

main { max-width: 860px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.tile .value { font-size: 1.5rem; font-weight: 700; }
.tile .label { color: var(--muted); font-size: .8rem; }

button, .btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
}
button:hover { filter: brightness(.97); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; }
button.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
button.block { width: 100%; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  width: 100%;
  min-height: 38px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field + .field { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* navigation */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .inner { max-width: 860px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 800; font-size: 1.1rem; color: var(--text); }
.brand span { color: var(--accent); }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; text-align: center; color: var(--muted); font-size: .72rem;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.active { color: var(--accent); }
.tabbar a.live { color: var(--good); }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list-link { display: flex; align-items: center; gap: 10px; color: var(--text); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 4px 12px; min-height: 30px; font-size: .85rem;
}
.chip.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.badge {
  display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.video { color: var(--accent); }
.badge.good { color: var(--good); }

.thumb {
  width: 56px; height: 56px; border-radius: 10px; flex: none; overflow: hidden;
  background: var(--surface-2); display: grid; place-items: center; color: var(--muted);
}
.thumb video, .thumb img { width: 100%; height: 100%; object-fit: cover; }

/* video */
.video-box {
  position: relative; width: 100%; background: #000; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16 / 9;
}
.video-box.portrait { aspect-ratio: 9 / 16; max-width: 340px; margin: 0 auto; }
.video-box video, .video-box iframe, .video-box img { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; object-fit: contain; }
.video-empty {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px; text-align: center; color: var(--muted);
}

/* workout */
.ex-card .ex-head { display: flex; gap: 10px; align-items: flex-start; }
.sets { width: 100%; border-collapse: collapse; margin-top: 10px; }
.sets th { font-size: .75rem; color: var(--muted); font-weight: 500; text-align: center; padding: 4px; }
.sets td { padding: 4px; text-align: center; }
.sets td.prev { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.sets input { text-align: center; padding: 6px 4px; min-height: 36px; }
.sets tr.done td { background: color-mix(in srgb, var(--good) 12%, transparent); }
.sets tr.done td:first-child { border-radius: 8px 0 0 8px; }
.sets tr.done td:last-child { border-radius: 0 8px 8px 0; }
.check {
  width: 38px; height: 36px; padding: 0; border-radius: 8px;
}
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
.suggest { font-size: .82rem; background: var(--surface-2); border-radius: 8px; padding: 6px 10px; margin-top: 8px; }

.rest-timer {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); border-radius: 999px; padding: 8px 10px 8px 18px;
  display: flex; gap: 10px; align-items: center; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.rest-timer .time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.2rem; min-width: 56px; }
.rest-timer button { background: transparent; color: inherit; border-color: color-mix(in srgb, var(--bg) 40%, transparent); min-height: 32px; padding: 4px 10px; }
.rest-timer.over { background: var(--good); color: #fff; }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 88vh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 16px;
}
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; }
}

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 17px; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 3; }
.chart .line2 { fill: none; stroke: var(--good); stroke-width: 3; stroke-dasharray: 6 4; }
.chart .dot { fill: var(--accent); }
.chart .bar { fill: var(--accent); }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 3px; vertical-align: middle; margin-right: 4px; }

.toast {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 10px; font-size: .9rem;
}
.toast.error { background: var(--danger); color: #fff; }

.auth { max-width: 380px; margin: 10vh auto; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

@media (max-width: 480px) {
  .grid2 { grid-template-columns: 1fr; }
  main { padding: 12px; }
}
