/* Train v2 — один файл стилей, без фреймворков и веб-шрифтов. Мобильная версия по умолчанию, десктоп от 900px. */
:root {
  --bg: #f4f6f5; --card: #ffffff; --ink: #14201d; --muted: #5f6f6a; --line: #dfe5e3;
  --brand: #0f766e; --brand-ink: #ffffff; --up: #15803d; --down: #b91c1c; --zero: #64748b;
  --tag: #e6f2f0; --media-bg: #ffffff; --radius: 14px; --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 16px rgba(16, 24, 22, .05);
  --tabbar-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513; --card: #16201d; --ink: #e7efec; --muted: #93a49e; --line: #263330;
    --brand: #2dd4bf; --brand-ink: #062a26; --up: #4ade80; --down: #f87171; --zero: #94a3b8;
    --tag: #1d2c28; --media-bg: #e9eeec; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  overflow-x: hidden;
}
a { color: var(--brand); }
h1, .h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
.h1 { font-size: 1.2rem; margin: 20px 0 10px; }
h2 { font-size: 1rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 0; }
h3 a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; }
[hidden] { display: none !important; }

/* шапка */
.top {
  position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.1rem; }
.top .side { display: none; }
.menu { margin-left: auto; position: relative; }
.menu summary, .export summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 6px; color: var(--muted); }
.menu summary::-webkit-details-marker, .export summary::-webkit-details-marker { display: none; }
.menu summary svg { width: 24px; height: 24px; fill: currentColor; }
.menu .who { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 7; min-width: 220px; display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.menu-pop a, .menu-pop .link { display: block; padding: 10px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; text-align: left; width: 100%; }
.menu-pop a:hover, .menu-pop a.on { background: var(--tag); }
.export { position: relative; }

/* нижняя панель вкладок (телефон) */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 5; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .68rem; min-width: 0; }
.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar a.on { color: var(--brand); }
.tabbar svg, .side svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar a.fab svg { background: var(--brand); color: var(--brand-ink); border-radius: 50%; padding: 4px; width: 34px; height: 34px; }
.foot { max-width: 1180px; margin: 8px auto 0; padding: 0 16px 16px; }

@media (min-width: 900px) {
  body { padding-bottom: 32px; }
  .tabbar { display: none; }
  .top .side { display: flex; gap: 4px; }
  .side a { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px; color: var(--muted); text-decoration: none; }
  .side a.on, .side a:hover { background: var(--tag); color: var(--ink); }
  .side svg { width: 18px; height: 18px; }
  .wrap { padding: 24px; }
  h1 { font-size: 1.75rem; }
}

/* общие элементы */
.head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 18px;
  border: 0; border-radius: 12px; background: var(--brand); color: var(--brand-ink); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; text-align: center;
}
.btn.ghost { background: var(--tag); color: var(--ink); }
.btn.danger { background: transparent; color: var(--down); border: 1px solid currentColor; }
.link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; text-decoration: underline; padding: 8px; }
.icon {
  min-width: 44px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--muted);
  font: inherit; font-size: 1rem; cursor: pointer; line-height: 1;
}
.icon:disabled { opacity: .35; cursor: default; }
.icon.danger { color: var(--down); }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--brand); border-radius: 999px; padding: 4px 14px; font: inherit; font-size: .85rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; min-height: 44px; white-space: nowrap; }
a.tag { display: inline-flex; align-items: center; min-height: 32px; padding: 4px 10px; }
.flash { background: var(--tag); border-left: 4px solid var(--brand); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
.err { color: var(--down); margin: 8px 0 0; }
.tag { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--tag); color: var(--muted); white-space: nowrap; text-decoration: none; }
.tag.up { color: var(--up); }
input, select {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  min-height: 44px; padding: 8px 10px; width: 100%; min-width: 0;
}
input[type=checkbox] { width: 22px; min-height: 22px; accent-color: var(--brand); }
input[type=file] { padding: 8px; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .875rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; min-height: 44px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.row > label { flex: 1 1 110px; }
.row .grow, .grow { flex: 1 1 220px; }
.inline { display: inline; }
.actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.stackform { display: flex; flex-direction: column; gap: 12px; }
ul.plain { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 8px; }
.empty-state { text-align: center; }
.chipline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tools { display: inline-flex; gap: 4px; align-items: center; flex: none; }

/* вход */
.auth { max-width: 380px; margin: 10vh auto 0; text-align: center; }
.auth h1 { margin-top: 8px; }
.auth form, .auth .card { text-align: left; margin-top: 20px; display: flex; flex-direction: column; gap: 12px; }
.auth pre { white-space: pre-wrap; background: var(--bg); padding: 10px; border-radius: 8px; }

/* сетки */
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; margin-bottom: 12px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 640px) and (max-width: 1099px) { .grid > .span-md:nth-child(odd):last-child { grid-column: 1 / -1; } }
@media (min-width: 1100px) { .grid > .wide:nth-child(3n+1):last-child { grid-column: 1 / -1; } }
.split { display: grid; gap: 12px; grid-template-columns: 1fr; margin-bottom: 12px; }
@media (min-width: 900px) { .split { grid-template-columns: minmax(0, 400px) 1fr; } }

/* дашборд и легаси-карточки */
.ex header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.ex.empty { opacity: .6; }
.spark { width: 84px; height: 28px; flex: none; }
.spark polyline { fill: none; stroke: var(--brand); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.ex dl, .kvs { margin: 0; display: grid; gap: 6px; }
.ex dl div, .kvs div { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.ex dt, .kvs dt { color: var(--muted); font-size: .875rem; flex: none; }
.ex dd, .kvs dd { margin: 0; text-align: right; }
.ex .next { border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 2px; }
.ex .next dd { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; align-items: center; }
.pf dd { font-size: .875rem; color: var(--muted); }
.pf .kv { white-space: nowrap; }
.pct { font-weight: 600; font-variant-numeric: tabular-nums; margin-right: 4px; }
.pct.up { color: var(--up); } .pct.down { color: var(--down); } .pct.zero, .pct.none { color: var(--zero); }
.legacy { margin-top: 20px; }
.bars { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 6px; }
.bars li { display: grid; grid-template-columns: minmax(0, 1fr) 90px 5.5em; gap: 8px; align-items: center; font-size: .875rem; }
.bars .bl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .bv { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.bars meter { width: 100%; height: 10px; }

/* анимация упражнения: два кадра, кроссфейд CSS */
.anim { margin: 0; position: relative; }
.anim .frames { display: block; position: relative; aspect-ratio: 1; background: var(--media-bg); border-radius: 12px; overflow: hidden; }
.anim img { display: block; width: 100%; height: 100%; object-fit: contain; }
.anim .frames img { position: absolute; inset: 0; }
.anim.two .frames img.b { animation: exfade 2.4s ease-in-out infinite alternate; opacity: 0; }
@keyframes exfade { 0%, 30% { opacity: 0; } 70%, 100% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .anim.two .frames img.b { animation: none; opacity: 0; } }
.anim.none img { border-radius: 12px; }
.anim-sm { width: 88px; flex: none; }
.anim-lg { width: 100%; max-width: 360px; margin: 0 auto; }
.credit { font-size: .75rem; color: var(--muted); margin-top: 6px; text-align: center; }
.credit a { color: inherit; }

/* библиотека */
.filters { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; margin-bottom: 12px; }
.filters > label { flex: 1 1 150px; }
.filters > label.grow { flex: 1 1 100%; }
.filters > label.check { flex: 0 1 auto; }
@media (min-width: 900px) { .filters > label.grow { flex: 2 1 260px; } }
.cards { display: grid; gap: 10px; grid-template-columns: 1fr; margin-bottom: 12px; }
@media (min-width: 640px) { .cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .cards { grid-template-columns: repeat(3, 1fr); } }
.excard { display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--ink); padding: 10px; }
.excard:hover { border-color: color-mix(in srgb, var(--brand) 55%, var(--line)); }
.exmeta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.exmeta b { overflow-wrap: anywhere; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 12px 0; }
.cues { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.chart { width: 100%; height: auto; display: block; }
.chart polyline { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; }
.chart circle { fill: var(--brand); }
.chart circle.lg { fill: var(--muted); }
.chart line.ax { stroke: var(--line); }
.chart line.gr { stroke: var(--line); stroke-dasharray: 3 3; }
.chart text { font-size: 10px; fill: var(--muted); }

/* тренажёры */
.mgroup details { margin-bottom: 8px; }
.mlist { margin-top: 10px; }
.mlist li { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.mlist li > a:first-child { display: inline-flex; align-items: center; min-height: 44px; }
ul.plain > li > a, .ex h3 a, .blockhead h2 a { display: inline-flex; align-items: center; min-height: 44px; }
.brand { min-height: 44px; }
.photos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.photos figure { margin: 0; }
.photos img { width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; display: block; background: var(--bg); }
.gmform { display: inline-flex; gap: 4px; align-items: center; }
.gmform input { min-height: 44px; padding: 4px 8px; width: auto; }
.num-s { width: 64px !important; }

/* программы */
.day { margin-bottom: 12px; }
.dayhead { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.dayhead .row { flex-wrap: nowrap; align-items: center; gap: 8px; }
.dayname { font-weight: 700; }
.items { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 10px; }
.items > li { border-top: 1px solid var(--line); padding-top: 10px; }
.itemhead { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 6px; }
.itemform { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.itemform label { flex: 1 1 72px; }
.itemform label.grow { flex: 2 1 160px; }
.additem { border-top: 1px dashed var(--line); padding-top: 12px; margin-bottom: 12px; }

/* тренировка */
.block { margin-bottom: 12px; }
.blockhead { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 10px; }
.blockhead .grow { flex: 1 1 150px; min-width: 0; }
.blockhead .tools { margin-left: auto; }
.blockhead .anim-sm { width: 64px; }
.blockhead h2 { margin: 0; }
.blockhead h2 a { color: inherit; text-decoration: none; }
.blockhead p { margin: 2px 0 0; }
.sets { display: flex; flex-direction: column; gap: 6px; }
.sethead, .setrow { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 6px; align-items: center; }
.sethead span:nth-child(2) { display: none; }
.sethead span:nth-child(3) { grid-column: 2; }
.setrow { padding: 4px; border-radius: 12px; }
.setrow .kind { min-height: 44px; padding: 4px; font-size: .85rem; text-align: center; }
.setrow .prev { grid-column: 1 / -1; grid-row: 2; padding-left: 4px; }
.setrow .inputs { display: flex; gap: 6px; min-width: 0; }
.setrow .inputs input { text-align: center; min-height: 44px; padding: 6px 4px; -moz-appearance: textfield; }
.setrow .inputs input::-webkit-outer-spin-button, .setrow .inputs input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.setrow .btns { display: flex; gap: 14px; }   /* ✓ и × не рядом: × ещё и спрашивает подтверждение */
.setrow .ok { min-width: 48px; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--tag); color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.setrow.done { background: color-mix(in srgb, var(--up) 12%, transparent); }
.setrow.done .ok { background: var(--up); color: #fff; border-color: var(--up); }
.setrow.k-warmup .kind { color: var(--muted); }
.setrow.k-drop .kind, .setrow.k-failure .kind { color: var(--down); }
.setrow .pr { grid-column: 1 / -1; }
.setrow .pr:empty { display: none; }
.setrow.busy { opacity: .6; }
.setrow.unsaved { outline: 2px dashed var(--down); outline-offset: -2px; }
.setrow.need .inputs input { border-color: var(--down); }
.setrow .pr.needmsg { color: var(--down); font-size: .875rem; }
.prevmore { margin: 4px 0 0 4px; }
@media (min-width: 640px) {
  .sethead, .setrow { grid-template-columns: 80px minmax(110px, 1fr) minmax(0, 2fr) auto; }
  .sethead span:nth-child(2) { display: block; }
  .sethead span:nth-child(3) { grid-column: auto; }
  .setrow .prev { grid-column: auto; grid-row: auto; }
}
.addset { margin-top: 8px; }
.prs { margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.meta { margin-top: 12px; }
.rest {
  /* полоса во всю ширину над панелью вкладок; main получает такой же отступ снизу (body.resting) — поля не перекрываются */
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 8; height: 60px;
  display: flex; gap: 10px; align-items: center; justify-content: center; background: var(--ink); color: var(--bg); padding: 8px 16px;
}
.rest b { font-variant-numeric: tabular-nums; font-size: 1.2rem; min-width: 3.2em; text-align: center; }
.rest .chip { min-width: 64px; }
.rest.over b { color: var(--up); }
body.resting { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 76px); }
@media (min-width: 900px) {
  .rest { bottom: 0; }
  body.resting { padding-bottom: 92px; }
  .setrow .inputs input { max-width: 160px; }
}

/* история и таблицы */
.list { display: flex; flex-direction: column; gap: 10px; }
.week { margin: 10px 0 0; font-weight: 500; }
details summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; list-style: none; min-height: 44px; }
details summary::-webkit-details-marker { display: none; }
details .note { flex-basis: 100%; color: var(--muted); font-size: .875rem; }
table { width: 100%; border-collapse: collapse; margin-top: 12px; 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; }
.exlist .pos { width: 64px; }
.exlist td { min-width: 120px; }
.exlist td:first-child, .exlist td:last-child { min-width: 0; }
.users tr.off td { opacity: .6; }
.users .acts { white-space: nowrap; }
.users select { min-height: 44px; padding: 4px; width: auto; max-width: 100%; }
@media (max-width: 639px) {
  .users thead { display: none; }
  .users, .users tbody, .users tr { display: block; }
  .users tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .users td { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; border: 0; padding: 3px 0; }
  .users td[data-label]:not(:first-child)::before { content: attr(data-label); flex: 0 0 6.5em; color: var(--muted); font-size: .8rem; }
  .users td:first-child { display: block; }
  .users .acts { white-space: normal; }
  .users td:empty { display: none; }
}
.newex { border: 1px dashed var(--line); border-radius: 12px; margin: 12px 0; padding: 12px; }
.newex legend { font-weight: 600; padding: 0 4px; }
.once { border-color: var(--brand); margin-bottom: 12px; }
.prose h2 { margin-top: 18px; }
.prose li { margin: 6px 0; }
