/* Kettlebell — training app (dark, Figma "Training app") */

@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("fonts/space-grotesk-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/inter-latin.woff2") format("woff2");
}

:root {
  --bg: #090a0b;
  --ink: #f4f3ec;
  --muted: #9a9c9b;
  --line: #343738;
  --tile: rgba(244, 243, 236, .1);
  --sheet: #141516;
  --accent: #e4f65a;
  --on-ink: #090a0b;
  --danger: #ff7a62;
  --font: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --display: "Space Grotesk", var(--font);
  --text: Inter, var(--font);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);       /* entering, press feedback */
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);   /* things morphing on screen */
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; background: var(--bg); }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--text);
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
main:focus { outline: none; }

/* ---------- Pages (History, Programs, editor) */

.page {
  max-width: 560px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--sat) 0 calc(var(--sab) + 32px);
}
.p-body { padding: 12px 24px 0; }

.p-back {
  min-height: 44px;
  margin: -12px 0 4px -8px;
  padding: 0 8px;
  font-family: var(--text);
  font-size: 12px;
  color: var(--muted);
}

.p-label {
  display: block;
  font-family: var(--text);
  font-weight: 400;
  font-size: 10px;
  letter-spacing: 1.4px;
  color: var(--muted);
}
.p-sub { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.p-empty { font-size: 14px; color: var(--muted); padding: 16px 0; }

.p-sec { margin-top: 32px; }
.p-sec > .p-label { margin-bottom: 4px; }

/* Rows */
.p-rows { list-style: none; }
.p-row {
  width: 100%;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.p-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.p-row-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -.2px;
  overflow-wrap: anywhere;
}
.p-row-sub { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.p-row-meta {
  flex: none;
  font-family: var(--display);
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.p-row-meta.is-active, .p-row-meta.is-full { color: var(--accent); }

/* Tile (active program) */
.p-tile { background: var(--tile); padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.p-tile-link {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  min-height: 44px;
}
.p-tile-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 32px;
  letter-spacing: -1.5px;
  line-height: 1;
  overflow-wrap: anywhere;
}
.p-tile-sub { font-size: 12px; color: var(--muted); }
.p-weeks { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; }
.p-weeks i { height: 4px; background: var(--line); }
.p-weeks i.on { background: var(--ink); }
.p-weeks i.now { background: var(--accent); }

.p-note-box { margin-top: 12px; padding: 20px; border: 1px solid var(--accent); }
.p-note-box p { font-family: var(--display); font-weight: 700; font-size: 18px; line-height: 1.3; }

/* Buttons */
.p-actions { display: grid; gap: 8px; margin-top: 16px; }
.p-actions-row { grid-template-columns: 1fr 1fr; }
.p-btn {
  min-height: 56px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -.3px;
  text-align: left;
  background: var(--ink);
  color: var(--on-ink);
  border: 1px solid var(--ink);
  transition: opacity .12s ease, transform 160ms var(--ease-out);
}
.p-btn:active { transform: scale(.97); }
.p-btn.accent { background: var(--accent); border-color: var(--accent); }
.p-btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.p-btn.danger { color: var(--danger); border-color: var(--danger); }
.p-btn-small { min-height: 44px; font-size: 16px; }

/* Editor */
.p-editbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  padding: calc(var(--sat) + 6px) 24px 6px;
  margin-top: calc(-1 * var(--sat));
  border-bottom: 1px solid var(--line);
}
.p-editbar .p-back { margin: 0 0 0 -8px; font-size: 14px; }
.p-field { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; min-width: 0; }
.p-field > span { font-size: 10px; letter-spacing: 1.4px; color: var(--muted); }
.p-field-title { margin-top: 12px; }
.p-field-title input { font-family: var(--display); font-weight: 700; font-size: 24px; }
input {
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  min-height: 44px;
  padding: 0 2px;
  width: 100%;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}
input:focus { outline: none; border-bottom-color: var(--accent); }
input::placeholder { color: var(--muted); opacity: .6; }

.p-seg { display: grid; grid-template-columns: repeat(3, 1fr); margin: 16px 0 8px; border: 1px solid var(--line); }
.p-seg button {
  min-height: 48px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.p-seg button + button { border-left: 1px solid var(--line); }
.p-seg button.on { background: var(--ink); color: var(--on-ink); }
.p-seg small { font-family: var(--text); font-weight: 400; font-size: 11px; opacity: .7; }

.ed-blocks, .ed-items { list-style: none; }
.ed-block { padding: 12px 0 4px; border-bottom: 1px solid var(--line); }
.ed-head { display: flex; justify-content: space-between; align-items: center; }
.ed-tools { display: flex; }
.icon { width: 44px; height: 44px; font-size: 20px; display: inline-flex; align-items: center; justify-content: center; }
.icon:disabled { opacity: .25; cursor: default; }
.ed-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ed-grid-4 { grid-template-columns: repeat(4, 1fr); }
.ed-item { display: grid; grid-template-columns: 1fr 64px 52px 44px; gap: 8px; align-items: end; }
.ed-item .icon { margin-bottom: 12px; }

/* ---------- Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sab) + 128px);
  z-index: 10;
  max-width: calc(100% - 48px);
  transform: translate(-50%, 8px);
  padding: 12px 16px;
  background: var(--ink);
  color: var(--on-ink);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s var(--ease-out), transform .18s var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Dialog (bottom sheet) */
dialog {
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  margin: auto auto 0;
  padding: 20px 24px calc(20px + var(--sab));
  border: 0;
  border-top: 1px solid var(--line);
  background: var(--sheet);
  color: var(--ink);
  font-family: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog[open] { animation: sheet .2s var(--ease-out); }
@keyframes sheet { from { transform: translateY(16px); opacity: 0; } }
.dlg-title { font-family: var(--display); font-size: 24px; font-weight: 700; letter-spacing: -1px; line-height: 1.1; }
.dlg-text { color: var(--muted); margin-top: 8px; font-size: 14px; }
.dlg .p-field { margin-top: 16px; }
.dlg-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  margin-top: 20px;
}
.dlg-actions.grid { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
.dlg-actions.list { grid-auto-flow: row; grid-template-columns: 1fr; gap: 6px; margin-top: 12px; }
.dlg-group { font-size: 10px; letter-spacing: 1.4px; color: var(--muted); margin-top: 12px; min-height: 1px; }
.dlg-group:first-child { margin-top: 0; }
.btn {
  min-height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px solid var(--line);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  transition: opacity .12s ease;
}
.btn:active { opacity: .6; }
.dlg-actions.list .btn { justify-content: space-between; text-align: left; }
.btn small { font-size: 12px; font-weight: 500; opacity: .7; font-variant-numeric: tabular-nums; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-ink); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-primary.btn-danger { background: var(--danger); color: var(--on-ink); }

@media (min-width: 600px) {
  dialog { margin: auto; max-width: 420px; border: 1px solid var(--line); padding-bottom: 20px; }
}

/* ---------- Menu: workouts with the current one's sets grouped under it */
.m-label { margin-top: 16px; }
.m-groups { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.m-group { display: flex; flex-direction: column; gap: 4px; }
.m-group .btn { justify-content: space-between; text-align: left; }
.m-sub { display: flex; flex-direction: column; gap: 4px; margin-left: 16px; padding-left: 12px; border-left: 1px solid var(--line); }
.m-set { min-height: 44px; font-size: 14px; font-weight: 500; }
.m-set.on { border-color: var(--ink); }
.m-set.on small { color: var(--accent); opacity: 1; }
.m-set-no { display: inline-block; width: 18px; color: var(--muted); font-variant-numeric: tabular-nums; }
.m-links { margin-top: 20px; }

/* ---------- After a workout: same frame as the workout screen */
.done-tile {
  background: rgba(244, 243, 236, .2);
  padding: 20px 12px;
  flex-direction: column;
  container-type: inline-size;
}
.done-face { flex: 1; display: flex; flex-direction: column; justify-content: space-between; }
.done-face .f-rest-label { font-weight: 700; }
.done-face .f-rest-time { width: auto; margin: 0; padding: 0; font-weight: 700; }

/* ---------- Workout (focus layout) */
.focus-view {
  max-width: 560px;
  height: 100dvh; /* fixed, so the progress tile can give way to long exercise lists */
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: var(--sat) 0 var(--sab);
}

.f-mast {
  height: 54px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}
.f-mast h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 32px;
  letter-spacing: -2px;
  line-height: 1;
}
.f-menu { width: 44px; height: 44px; margin-right: -10px; display: flex; align-items: center; justify-content: center; }
.f-menu img { display: block; }

.f-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 24px 10px;
}
/* Exercise list at the top; Work/Rest tile and button sit together at the bottom with a fixed
   16 px between them, so the controls don't shift as the number of exercise lines changes. */
.f-ex { margin-bottom: 24px; }
.f-progress { margin-top: auto; }
.f-controls { margin-top: 16px; }

.f-ex { display: flex; flex-direction: column; gap: 8px; }
.f-meta { display: flex; justify-content: space-between; align-items: flex-start; color: var(--muted); height: 15px; }
.f-setno { font-family: var(--text); font-size: 10px; letter-spacing: 1.4px; }
.f-kg {
  min-height: 44px;
  margin: -15px -10px 0 0;
  padding: 0 10px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  text-decoration: underline;
  text-underline-offset: 2px;
  color: var(--muted);
}
.f-line {
  display: flex;
  gap: 10px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 18px;
  line-height: 1.28;
  color: var(--ink);
}
.f-line span:first-child { flex: 1; min-width: 0; }
.f-line span:last-child { white-space: nowrap; text-align: right; }

/* Progress: three phases, animated between (Figma "Animation v2").
   work  — big Work tile, thin vertical Rest strip
   rest  — thin vertical Work strip, big countdown
   done  — Work tile folds away, "Set completed" spans the row */
.f-body { --ease: var(--ease-in-out); --dur: .4s; --thin: 31px; --gap: 8px; }

/* 400 px when there is room; shrinks (down to 220 px) when a circuit lists many exercises. */
.f-progress { display: flex; flex: 0 1 400px; min-height: 220px; }

.f-round, .f-rest {
  position: relative;
  flex-grow: 0;
  flex-shrink: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  border: 1px solid transparent;
  transition:
    flex-basis var(--dur) var(--ease),
    margin var(--dur) var(--ease),
    padding var(--dur) var(--ease),
    border-width var(--dur) var(--ease),
    background-color .3s ease,
    border-color .3s ease,
    opacity .3s ease;
}
.f-round { flex-basis: calc(100% - var(--thin) - var(--gap)); background: rgba(244, 243, 236, .1); container-type: size; }
.f-rest {
  flex-basis: var(--thin);
  margin-left: var(--gap);
  border-color: var(--line);
  container-type: inline-size;
}

[data-phase="rest"] .f-round { flex-basis: var(--thin); background: transparent; border-color: var(--line); }
[data-phase="rest"] .f-rest { flex-basis: calc(100% - var(--thin) - var(--gap)); background: rgba(244, 243, 236, .2); border-color: transparent; }

[data-phase="done"] .f-round { flex-basis: 0; padding-left: 0; padding-right: 0; border-width: 0; opacity: 0; }
[data-phase="done"] .f-rest { flex-basis: 100%; margin-left: 0; background: rgba(244, 243, 236, .2); border-color: transparent; }

/* Big and thin faces cross-fade */
.f-big {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: opacity .25s var(--ease-out), filter .25s var(--ease-out);
}
.f-thin {
  position: absolute;
  inset: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0;
  opacity: 0;
  filter: blur(2px);
  visibility: hidden;
  transition: opacity .25s var(--ease-out), filter .25s var(--ease-out), visibility 0s linear .25s;
}
.f-vert {
  writing-mode: vertical-rl;
  font-family: var(--text);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  opacity: .5;
}
.f-vert-num { font-family: var(--display); }

[data-phase="work"] .f-rest .f-big,
[data-phase="rest"] .f-round .f-big { opacity: 0; filter: blur(2px); visibility: hidden; }
[data-phase="work"] .f-rest .f-thin,
[data-phase="rest"] .f-round .f-thin {
  opacity: 1;
  filter: none;
  visibility: visible;
  transition: opacity .25s var(--ease-out) .15s, filter .25s var(--ease-out) .15s, visibility 0s;
}

/* Work tile */
.f-round-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 15px;
  padding: 0 8px;
  font-family: var(--text);
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}
.f-undo {
  min-height: 44px;
  margin: -15px -16px -15px 0;
  padding: 0 16px;
  font-family: var(--text);
  font-weight: 400;
  font-size: 12px;
  color: var(--ink);
  opacity: .6;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.f-count { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.f-count span {
  font-family: var(--display);
  font-weight: 700;
  font-size: 139px;
  font-size: min(139px, 46cqh, 72cqw);
  line-height: .9;
  letter-spacing: -.036em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.f-rule { display: block; align-self: stretch; height: 1px; background: var(--ink); opacity: .1; }

/* Rest tile */
.f-rest-head { display: flex; justify-content: space-between; align-items: center; height: 15px; }
.f-rest-label {
  font-family: var(--text);
  font-weight: 700;
  font-size: 12px;
  line-height: 15px;
  white-space: nowrap;
}
.f-skip {
  min-height: 44px;
  margin: -15px -12px -15px 0;
  padding: 0 12px;
  font-family: var(--text);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 2px;
  opacity: .6;
}
.f-rest-time {
  width: calc(100% + 24px);
  margin: 0 -12px -20px;
  padding: 12px 12px 20px;
  text-align: left;
  font-family: var(--display);
  font-weight: 700;
  font-size: 80px;
  font-size: min(80px, 29cqw);
  letter-spacing: -2px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.f-rest[data-status="paused"] .f-rest-time { opacity: .4; }

/* Breathing pulse while resting (Figma "Rest" -> "Rest B"): 4 s in, 6 s out, about 6 breaths
   a minute. The fill brightens from 5 % to 50 % and the corners round from 0 to 30 px. It runs
   on a layer behind the content so only opacity (GPU) and one pseudo-element's radius change. */
.f-rest::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(244, 243, 236, .5);
  opacity: 0;
  pointer-events: none;
}
.f-rest > * { position: relative; }
.f-rest > .f-thin { position: absolute; }
[data-phase="rest"] .f-rest[data-status="running"],
[data-phase="rest"] .f-rest[data-status="paused"] { background: transparent; }
[data-phase="rest"] .f-rest[data-status="running"]::before,
[data-phase="rest"] .f-rest[data-status="paused"]::before { animation: breathe 10s ease-in-out infinite; }
[data-phase="rest"] .f-rest[data-status="paused"]::before { animation-play-state: paused; }
@keyframes breathe {
  0%, 100% { opacity: .1; border-radius: 0; }   /* 5 % fill */
  40% { opacity: 1; border-radius: 30px; }      /* 50 % fill */
}

/* Controls: one big button — Add round (dimmed while resting), Finish set once the set is done */
.f-controls { display: flex; flex-direction: column; }
.f-add {
  width: 100%;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--ink);
  color: #090a0b;
  transition: background-color .3s ease, opacity .3s ease, transform 160ms var(--ease-out);
}
.f-add img { display: block; flex: none; }
.f-lbl { white-space: nowrap; font-family: var(--display); font-weight: 700; font-size: 27px; letter-spacing: -.7px; }
[data-phase="rest"] .f-add, .f-add:disabled { opacity: .5; }
.f-add:disabled { cursor: default; }
.f-next { background: var(--accent); }
.f-add:not(:disabled):active { transform: scale(.97); }

/* Phase morph via View Transitions (Safari 18+, Chrome 111+): the browser snapshots both
   tiles and animates the snapshots on the GPU, so nothing is laid out per frame. Browsers
   without it fall back to the flex-basis transitions above (see animateFocus in app.js). */
.vt .f-round, .vt .f-rest { transition: background-color .3s ease, border-color .3s ease; }
.vt .f-big, .vt .f-thin { transition: none !important; } /* the snapshots cross-fade instead */
.f-round { view-transition-name: f-round; }
.f-rest { view-transition-name: f-rest; }
::view-transition-group(*) {
  animation-duration: .4s;
  animation-timing-function: var(--ease-in-out);
}
::view-transition-image-pair(f-round),
::view-transition-image-pair(f-rest) { overflow: clip; }
/* Don't stretch the snapshots — crop them as the tile changes width. */
::view-transition-old(f-round), ::view-transition-new(f-round),
::view-transition-old(f-rest), ::view-transition-new(f-rest) {
  width: 100%;
  height: 100%;
  object-fit: none;
  object-position: left top;
}
::view-transition-old(f-round), ::view-transition-old(f-rest) { animation-name: vt-out; }
::view-transition-new(f-round), ::view-transition-new(f-rest) { animation-name: vt-in; }
@keyframes vt-out { to { opacity: 0; filter: blur(2px); } }
@keyframes vt-in { from { opacity: 0; filter: blur(2px); } }

/* Reduced motion: drop movement and size changes, keep gentle fades and the breathing pulse. */
@media (prefers-reduced-motion: reduce) {
  .f-round, .f-rest { transition: background-color .3s ease, border-color .3s ease; }
  .f-big, .f-thin { filter: none !important; }
  .f-add:not(:disabled):active, .p-btn:active { transform: none; }
  .toast { transform: translate(-50%, 0); }
  dialog[open] { animation: fade .2s ease-out; }
  @keyframes fade { from { opacity: 0; } }
}
