:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --border: #e2e0da;
  --text: #1b1c1a;
  --muted: #6d6f6a;
  --accent: #b8452c;
  --accent-soft: #fbeae5;
  --good: #2f6b4f;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2a3038;
    --text: #e8e6e1;
    --muted: #9096a0;
    --accent: #e2694b;
    --accent-soft: #2a1b16;
    --good: #5aa681;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

/* Свойство display в правилах ниже перебивает атрибут hidden — возвращаем ему силу */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.muted { color: var(--muted); }

/* ------------------------------------------------------------- ворота входа */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.gate-card {
  max-width: 26rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.75rem; box-shadow: var(--shadow);
}
.gate-card h1 { margin-top: 0; font-size: 1.4rem; }

/* ------------------------------------------------------------------- шапка */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.top-inner { max-width: 56rem; margin: 0 auto; padding: .75rem 1rem; }
.brand { font-weight: 600; letter-spacing: -.01em; }
.brand span { color: var(--muted); font-weight: 400; }
.tabs { display: flex; gap: .35rem; margin-top: .6rem; overflow-x: auto; }
.tabs button {
  flex: 0 0 auto; border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: .4rem .8rem; border-radius: 999px; font: inherit; font-size: .92rem; cursor: pointer;
}
.tabs button.active { background: var(--surface); color: var(--text); border-color: var(--border); }

main { max-width: 56rem; margin: 0 auto; padding: 1rem 1rem 9rem; }
.section-hint { color: var(--muted); font-size: .93rem; }

/* --------------------------------------------------------- выбор дня недели */
.daybar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.daybar button {
  flex: 1; padding: .7rem .5rem; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: .9rem; text-align: center;
}
.daybar button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.daybar button small { display: block; font-size: .75rem; opacity: .7; }

.day-meta { color: var(--muted); font-size: .92rem; margin-bottom: 1rem; }

/* ---------------------------------------------------------------- карточки */
.exercise-list { display: flex; flex-direction: column; gap: .7rem; }

.ex {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.ex.warmup { background: var(--surface-2); }
.ex-head { display: flex; gap: .75rem; align-items: flex-start; padding: .85rem .9rem; }
.ex-no {
  font-variant-numeric: tabular-nums; color: var(--muted); font-size: .8rem;
  padding-top: .18rem; min-width: 1.4rem;
}
.ex-main { flex: 1; min-width: 0; }
.ex-name { font-weight: 600; }
.ex-name .swapped {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .04em;
  background: var(--accent-soft); color: var(--accent); padding: .1rem .4rem;
  border-radius: 4px; margin-left: .4rem; vertical-align: 1px;
}
.ex-scheme { color: var(--muted); font-size: .87rem; margin-top: .15rem; }
.ex-note { color: var(--muted); font-size: .84rem; margin-top: .4rem; font-style: italic; }
.ex-actions { display: flex; gap: .4rem; flex-wrap: wrap; padding: 0 .9rem .85rem; }

.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: .45rem .75rem; border-radius: 8px; font: inherit; font-size: .87rem; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: .3rem .55rem; font-size: .8rem; }
.btn.ghost { background: transparent; }
.btn.rest { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ запись весов */
.sets { border-top: 1px solid var(--border); padding: .7rem .9rem; background: var(--surface-2); }
.sets-row { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.sets-row input {
  width: 5rem; padding: .4rem .5rem; border-radius: 8px; font: inherit; font-size: .9rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.logged { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .55rem; }
.logged span {
  font-size: .82rem; font-variant-numeric: tabular-nums; padding: .2rem .5rem;
  border-radius: 6px; background: var(--surface); border: 1px solid var(--border); cursor: pointer;
}
.logged span:hover { border-color: var(--accent); color: var(--accent); }
.prev { font-size: .82rem; color: var(--muted); margin-top: .5rem; }

.callout {
  margin-top: 1.25rem; padding: .85rem 1rem; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: .9rem; color: var(--muted);
}

/* ------------------------------------------------------- база упражнений */
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: 1rem 0; }
.chips button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .4rem .75rem; border-radius: 999px; font: inherit; font-size: .87rem; cursor: pointer;
}
.chips button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.library-list { display: flex; flex-direction: column; gap: .6rem; }
.lib-item {
  display: flex; gap: .85rem; padding: .85rem .9rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.lib-rank {
  font-size: 1.1rem; font-weight: 600; color: var(--accent);
  font-variant-numeric: tabular-nums; min-width: 1.6rem;
}
.lib-name { font-weight: 600; }
.lib-tags { color: var(--muted); font-size: .82rem; margin-top: .1rem; }
.lib-note { color: var(--muted); font-size: .87rem; margin-top: .35rem; }

/* --------------------------------------------------------------- прогресс */
.body-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.body-form h2 { margin-top: 0; }
.body-inputs { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.body-inputs label { font-size: .85rem; color: var(--muted); display: flex; flex-direction: column; gap: .25rem; }
.body-inputs input {
  width: 7rem; padding: .45rem .5rem; border-radius: 8px; font: inherit;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
table.data th { color: var(--muted); font-weight: 500; font-size: .82rem; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 60px; margin-top: 1rem; }
.spark i { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; opacity: .75; min-height: 2px; }

/* ----------------------------------------------------------------- таймер */
.timer {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 1rem; z-index: 40;
  width: min(30rem, calc(100% - 2rem));
  display: flex; gap: .9rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: .7rem .9rem; box-shadow: var(--shadow);
}
.timer.done { border-color: var(--accent); background: var(--accent-soft); }
.timer-ring { position: relative; width: 58px; height: 58px; flex: 0 0 auto; }
.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--border); stroke-width: 8; }
.ring-fg {
  fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round;
  stroke-dasharray: 283; stroke-dashoffset: 0; transition: stroke-dashoffset .3s linear;
}
.timer-time {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: .82rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.timer-body { flex: 1; min-width: 0; }
.timer-label {
  font-size: .87rem; font-weight: 500; margin-bottom: .4rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.timer-controls { display: flex; gap: .35rem; flex-wrap: wrap; }

/* ----------------------------------------------------------------- модалка */
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: end center;
  background: rgba(0,0,0,.45); padding: 0;
}
.modal-card {
  position: relative; width: min(34rem, 100%); max-height: 85dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px 16px 0 0; padding: 1.25rem 1.1rem 2rem;
}
@media (min-width: 640px) {
  .modal { place-items: center; padding: 1.5rem; }
  .modal-card { border-radius: 16px; }
}
.modal-close {
  position: absolute; top: .6rem; right: .8rem; border: 0; background: transparent;
  color: var(--muted); font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.alt {
  display: block; width: 100%; text-align: left; margin-bottom: .5rem;
  padding: .7rem .8rem; border-radius: 10px; cursor: pointer; font: inherit;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
}
.alt:hover { border-color: var(--accent); }
.alt b { display: block; }
.alt small { color: var(--muted); }

/* ------------------------------------------------------------------- тост */
.toast {
  position: fixed; bottom: 6.5rem; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: .55rem .9rem;
  border-radius: 999px; font-size: .87rem; box-shadow: var(--shadow);
}
