:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f7faf9;
  color: #184b4b;
  font-synthesis: none;
  --teal: #177e7e;
  --teal-dark: #184b4b;
  --teal-hover: #146f6f;
  --teal-soft: #e4f3f1;
  --lilac: #7a6197;
  --lilac-accent: #a78bc7;
  --lilac-soft: #f3eff8;
  --surface: #ffffff;
  --line: #dce8e6;
  --muted: #677673;
  --success: #34794d;
  --success-fill: #4d9a68;
  --warning: #b95549;
  --warning-hover: #a64b41;
  --shadow: 0 12px 32px rgba(24, 75, 75, 0.08);
  --shadow-soft: 0 6px 18px rgba(24, 75, 75, 0.055);
  --focus-ring: rgba(23, 126, 126, 0.34);
  --visual-viewport-height: 100dvh;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  max-width: 100%;
  min-height: 100%;
}

html {
  background: #f7faf9;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: #f7faf9;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, select, input { min-height: 3rem; }
button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

button:disabled { cursor: default; }

.app-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 48rem;
  margin: 0 auto;
  background: #f9fbfa;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  min-height: 4.5rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: max(0.75rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) 0.75rem max(1.25rem, env(safe-area-inset-left));
  background: rgba(249, 251, 250, 0.94);
  border-bottom: 1px solid rgba(220, 232, 230, 0.86);
  backdrop-filter: blur(14px);
}

.topbar > * { min-width: 0; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--teal-dark);
  font-size: 1.15rem;
  font-weight: 750;
  text-decoration: none;
}

.brand-mark {
  width: 1.85rem;
  height: 1.85rem;
  border: 0.42rem solid var(--teal);
  border-radius: 0.7rem 0.7rem 0.7rem 0.25rem;
  transform: rotate(-8deg);
}

.storage-state {
  color: var(--muted);
  font-size: 0.75rem;
  text-align: right;
}

.storage-state[data-ready="true"] { color: var(--teal-dark); }
.storage-state[data-ready="false"] { color: var(--warning); }

main {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 1.5rem max(1.25rem, env(safe-area-inset-right)) calc(7rem + env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
}

main > *,
.screen-header-row > *,
.routine-editor-toolbar > * {
  min-width: 0;
  max-width: 100%;
}

.screen-header { margin: 0 0 1.5rem; }

.screen-header-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--lilac);
  font-size: 0.8rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #184b4b;
  font-size: clamp(1.8rem, 8vw, 2.5rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
  overflow-wrap: anywhere;
}

h2, strong { overflow-wrap: anywhere; }

.empty-card {
  min-height: 12rem;
  display: grid;
  place-items: center;
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: 1.35rem;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.empty-card p {
  max-width: 28rem;
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.primary-button,
.secondary-button,
.danger-button {
  max-width: 100%;
  min-height: 3rem;
  padding: 0.75rem 1.1rem;
  border-radius: 0.9rem;
  border: 1px solid transparent;
  font-weight: 750;
  overflow-wrap: anywhere;
  white-space: normal;
}

.primary-button,
.start-training-button {
  box-shadow: 0 10px 24px rgba(24, 75, 75, 0.16);
}

.primary-button {
  color: #fff;
  background: var(--teal);
}

.primary-button:active { background: var(--teal-dark); }

.secondary-button:active,
.icon-button:active,
.group-scroller button:active,
.finish-training-button:active,
.bottom-nav a:active {
  color: var(--teal-dark);
  background: var(--teal-soft);
}

.text-button:active,
.back-button:active,
.history-back:active,
.history-link-button:active { color: var(--teal); }

@media (hover: hover) {
  .primary-button:not(:disabled):hover { background: var(--teal-hover); }
  .danger-button:not(:disabled):hover { background: var(--warning-hover); }
  .secondary-button:not(:disabled):hover,
  .icon-button:not(:disabled):hover,
  .group-scroller button:not([aria-selected="true"]):hover,
  .bottom-nav a:not([aria-current="page"]):hover {
    color: var(--teal-dark);
    background: var(--teal-soft);
  }
  .secondary-button:not(:disabled):hover { border-color: #a9d6d1; }
  .text-button:not(:disabled):hover,
  .back-button:hover,
  .history-back:hover,
  .history-link-button:hover { color: var(--teal); }
}

.primary-button.compact,
.secondary-button.compact {
  min-height: 3rem;
  flex: 0 0 auto;
  font-size: 0.88rem;
}

.secondary-button {
  color: var(--teal-dark);
  background: #fff;
  border-color: var(--line);
}

.button-with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.action-icon {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.danger-button {
  color: #fff;
  background: var(--warning);
}

.danger-button:active { background: var(--warning-hover); }

.icon-button {
  width: 3rem;
  min-width: 3rem;
  min-height: 3rem;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
}

.icon-button svg {
  width: 1.5rem;
  height: 1.5rem;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.library-loading {
  padding: 2rem 0;
  color: var(--muted);
}

.group-scroller {
  display: flex;
  gap: 0.6rem;
  margin: 0 -1.25rem 1.25rem;
  padding: 0.1rem 1.25rem 0.65rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.group-scroller::-webkit-scrollbar { display: none; }

.group-scroller button {
  min-height: 3.1rem;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  color: var(--muted);
  background: #fff;
  font-size: 0.86rem;
  font-weight: 700;
}

.group-scroller button[aria-selected="true"] {
  color: var(--teal-dark);
  background: var(--teal-soft);
  border-color: #a9d6d1;
}

.muscle-icon {
  width: 1.55rem;
  height: 1.55rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.library-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.library-toolbar label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.library-toolbar select,
.exercise-form select,
.exercise-form input {
  width: 100%;
  padding: 0.68rem 2.2rem 0.68rem 0.8rem;
  border: 1px solid #c4d9d6;
  border-radius: 0.8rem;
  color: #184b4b;
  background: #fff;
}

.library-toolbar > span {
  padding-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.83rem;
  white-space: nowrap;
}

.exercise-list {
  display: grid;
  gap: 0.75rem;
}

.exercise-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.8rem;
  padding: 1rem 0.8rem 1rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.exercise-card-icon {
  width: 2.6rem;
  height: 2.6rem;
  display: grid;
  place-items: center;
  border-radius: 0.85rem;
  color: var(--teal-dark);
  background: var(--teal-soft);
}

.exercise-card-copy { min-width: 0; }

.exercise-name-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.exercise-card h2 {
  margin: 0;
  color: #184b4b;
  font-size: 1rem;
  line-height: 1.35;
}

.exercise-card p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.own-label {
  padding: 0.18rem 0.42rem;
  border-radius: 999px;
  color: var(--lilac);
  background: var(--lilac-soft);
  font-size: 0.7rem;
  font-weight: 750;
}

.favorite-button.is-favorite { color: var(--lilac); }

.card-actions {
  display: flex;
  gap: 0.9rem;
  margin-top: 0.55rem;
}

.text-button {
  min-height: 2.75rem;
  padding: 0;
  border: 0;
  color: var(--teal-dark);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 750;
}

.text-button.danger { color: var(--warning); }

.empty-inline {
  padding: 2rem 1.25rem;
  border: 1px dashed #c4d8d5;
  border-radius: 1rem;
  color: var(--muted);
  background: #fff;
  text-align: center;
}

.empty-inline p { margin: 0; }
.empty-inline.error { color: var(--warning); }

.exercise-dialog {
  width: min(calc(100% - 2rem), 30rem);
  padding: 1.25rem;
  border: 0;
  border-radius: 1.35rem;
  color: #184b4b;
  box-shadow: 0 24px 70px rgba(24, 75, 75, 0.24);
}

.exercise-dialog::backdrop {
  background: rgba(24, 75, 75, 0.42);
  backdrop-filter: blur(3px);
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.15rem;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 1.4rem;
}

.close-dialog {
  color: var(--muted);
  font-size: 1.7rem;
  line-height: 1;
}

.exercise-form label {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.9rem;
  color: #526663;
  font-size: 0.88rem;
  font-weight: 700;
}

.exercise-form input { padding-right: 0.8rem; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1.35rem;
}

.form-error {
  min-height: 1.2rem;
  margin: 0.65rem 0 0;
  color: var(--warning);
  font-size: 0.82rem;
}

.confirm-dialog > p {
  margin: 0.5rem 0;
  line-height: 1.5;
}

.confirm-dialog .dialog-note {
  color: var(--muted);
  font-size: 0.88rem;
}

.routine-list,
.routine-exercise-list {
  display: grid;
  gap: 0.8rem;
}

.routine-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.routine-open {
  min-width: 0;
  min-height: 3.5rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.35rem;
  border: 0;
  color: #184b4b;
  background: transparent;
  text-align: left;
}

.routine-open > span:last-child {
  min-width: 0;
  display: grid;
  gap: 0.22rem;
}

.routine-open strong {
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.routine-open small {
  color: var(--muted);
  font-size: 0.8rem;
}

.routine-mark {
  width: 2.65rem;
  height: 2.65rem;
  display: grid;
  flex: 0 0 auto;
  align-content: center;
  gap: 0.28rem;
  padding: 0.65rem;
  border-radius: 0.85rem;
  background: var(--teal-soft);
}

.routine-mark span {
  display: block;
  height: 0.14rem;
  border-radius: 999px;
  background: var(--teal-dark);
}

.compact-action {
  min-height: 3rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.78rem;
}

.compact-empty { min-height: 10rem; }

.back-button {
  min-height: 3rem;
  margin: -0.4rem 0 1rem;
  padding: 0;
  border: 0;
  color: var(--teal-dark);
  background: transparent;
  font-weight: 750;
}

.routine-name-label {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.routine-name-label input {
  width: 100%;
  min-height: 3.2rem;
  padding: 0.7rem 0;
  border: 0;
  border-bottom: 2px solid #b5cfcc;
  border-radius: 0;
  color: #184b4b;
  background: transparent;
  font-size: 1.35rem;
  font-weight: 750;
}

.routine-name-label input:focus {
  border-color: var(--teal);
  outline: none;
}

.editor-status {
  margin: 0.55rem 0 0;
  color: var(--lilac);
  font-size: 0.8rem;
  font-weight: 700;
}

.routine-editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1.35rem 0 0.9rem;
}

.routine-editor-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.routine-exercise-card {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.65rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  background: #fff;
  box-shadow: var(--shadow-soft);
  transition: opacity 120ms ease, transform 120ms ease;
}

.routine-exercise-card.is-dragging {
  z-index: 2;
  opacity: 0.65;
  border-color: var(--teal);
  box-shadow: 0 14px 34px rgba(24, 75, 75, 0.16);
  transform: scale(1.015);
}

.drag-handle {
  width: 3rem;
  min-width: 3rem;
  min-height: 3rem;
  display: grid;
  align-content: center;
  gap: 0.3rem;
  padding: 0.6rem 0.7rem;
  border: 0;
  border-radius: 0.8rem;
  color: var(--muted);
  background: #edf5f4;
  cursor: grab;
  touch-action: none;
}

.drag-handle:active { cursor: grabbing; }

.drag-handle span {
  height: 0.12rem;
  border-radius: 999px;
  background: currentColor;
}

.routine-exercise-main { min-width: 0; }

.routine-exercise-heading {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.routine-exercise-heading .exercise-card-icon {
  width: 2.3rem;
  height: 2.3rem;
}

.routine-exercise-heading h2 {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.35;
}

.routine-exercise-heading p {
  margin: 0.18rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.routine-settings {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.9rem;
}

.routine-settings label {
  min-width: 0;
  display: grid;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.routine-settings input {
  width: 100%;
  min-width: 0;
  padding: 0.5rem;
  border: 1px solid #c4d9d6;
  border-radius: 0.7rem;
  color: #184b4b;
  background: #fff;
  text-align: center;
  font-weight: 700;
}

.routine-card-actions {
  flex-wrap: wrap;
  gap: 0.3rem 0.9rem;
  margin-top: 0.65rem;
}

.routine-card-actions .text-button:disabled {
  color: #9eaeab;
  cursor: default;
}

.routine-picker-dialog {
  max-height: min(86dvh, 48rem);
  overflow: hidden;
}

.routine-picker-dialog #routine-picker {
  max-height: calc(86dvh - 12rem);
  overflow-y: auto;
}

.picker-groups {
  margin-inline: -1.25rem;
  padding-inline: 1.25rem;
}

.picker-exercise-list {
  display: grid;
  gap: 0.55rem;
}

.picker-exercise {
  display: block;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: #fff;
}

.picker-exercise > input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.picker-exercise > span {
  min-height: 3.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.8rem;
  border-radius: inherit;
}

.picker-exercise > input:checked + span {
  color: var(--teal-dark);
  background: var(--teal-soft);
  box-shadow: inset 0 0 0 2px var(--teal);
}

.picker-exercise > input:focus-visible + span {
  outline: 3px solid rgba(23, 126, 126, 0.3);
  outline-offset: 2px;
}

.picker-exercise > span > span {
  min-width: 0;
  display: grid;
  gap: 0.15rem;
}

.picker-exercise strong {
  font-size: 0.9rem;
  line-height: 1.3;
}

.picker-exercise small {
  color: var(--muted);
  font-size: 0.75rem;
}

.picker-exercise.is-added { opacity: 0.55; }

.routine-picker-dialog #confirm-add-exercises:disabled {
  color: #e7efed;
  background: #829b98;
  cursor: default;
}

.home-header { margin-bottom: 1.35rem; }

.start-training-button {
  width: 100%;
  min-height: 5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border: 0;
  border-radius: 1.35rem;
  color: #fff;
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  box-shadow: 0 16px 34px rgba(24, 75, 75, 0.2);
  font-size: 1.15rem;
  font-weight: 780;
}

.start-training-button span:last-child { font-size: 1.6rem; }

.start-training-button:disabled {
  color: #e7efed;
  background: #758f8c;
  box-shadow: none;
  cursor: default;
}

.home-section { margin-top: 1.75rem; }

.home-section > h2 {
  margin: 0 0 0.8rem;
  font-size: 1.05rem;
}

.home-routine-list,
.schema-choice-list {
  display: grid;
  gap: 0.7rem;
}

.home-routine-card {
  width: 100%;
  min-height: 4.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1.05rem;
  color: #184b4b;
  background: #fff;
  box-shadow: var(--shadow-soft);
  text-align: left;
}

.home-routine-card > span:first-child {
  min-width: 0;
  display: grid;
  gap: 0.22rem;
}

.home-routine-card strong {
  overflow: hidden;
  font-size: 0.98rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-routine-card small {
  color: var(--muted);
  font-size: 0.78rem;
}

.home-routine-card:disabled { opacity: 0.58; cursor: default; }

.routine-start-label {
  flex: 0 0 auto;
  color: var(--teal-dark);
  font-size: 0.82rem;
  font-weight: 750;
}

.schema-choice-dialog { max-height: 82dvh; overflow-y: auto; }

.training-header { margin-bottom: 1.25rem; }

.training-header > p:last-child {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.advice-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 1rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid #c1dcd8;
  border-radius: 0.9rem;
  color: #184b4b;
  background: #eff8f6;
  font-size: 0.82rem;
}

.progress-advice { font-weight: 780; }
.progress-advice.increase { color: var(--success); }
.progress-advice.maintain { color: var(--lilac); }
.progress-advice.decrease { color: var(--warning); }
.progress-advice.none { color: var(--muted); }

.training-exercise-list {
  display: grid;
  gap: 0.65rem;
}

.training-exercise {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.training-exercise-summary,
.training-exercise.compact > button {
  width: 100%;
  min-height: 5.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border: 0;
  color: #184b4b;
  background: transparent;
  text-align: left;
}

.training-exercise-summary > span:first-child,
.training-exercise.compact > button > span:last-child {
  min-width: 0;
  display: grid;
  gap: 0.18rem;
}

.training-exercise-summary strong,
.training-exercise.compact strong {
  font-size: 0.98rem;
  line-height: 1.35;
}

.training-exercise-summary small,
.training-exercise.compact small {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.training-exercise-summary > span:last-child {
  color: var(--teal-dark);
  font-size: 1.6rem;
}

.training-exercise.is-open {
  padding: 1rem;
  border-color: #a9d6d1;
  box-shadow: 0 14px 32px rgba(24, 75, 75, 0.1);
}

.training-exercise-header h2 {
  margin: 0;
  font-size: 1.12rem;
}

.training-exercise-header p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.79rem;
  line-height: 1.4;
}

.training-sets {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}

.training-set {
  display: grid;
  grid-template-columns: 3.4rem minmax(0, 1fr) minmax(0, 1fr);
  align-items: end;
  gap: 0.5rem;
  padding: 0.8rem;
  border-radius: 0.9rem;
  background: #f3f7f6;
}

.training-set.is-skipped { opacity: 0.62; }

.set-label {
  align-self: center;
  color: #526663;
  font-size: 0.8rem;
  font-weight: 750;
}

.training-set > label:not(.skip-set) {
  min-width: 0;
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.training-set input[type="text"],
.training-set input[type="number"] {
  width: 100%;
  min-width: 0;
  min-height: 3.35rem;
  padding: 0.55rem;
  border: 1px solid #c4d9d6;
  border-radius: 0.68rem;
  color: #184b4b;
  background: #fff;
  text-align: center;
  font-size: 1.12rem;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
}

.training-set input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(23, 126, 126, 0.12);
}

.skip-set {
  grid-column: 2 / -1;
  min-height: 3rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.skip-set input { width: 1.1rem; height: 1.1rem; min-height: 0; accent-color: var(--teal); }

.training-input-error {
  min-height: 1rem;
  margin: 0.45rem 0 0;
  color: var(--warning);
  font-size: 0.78rem;
}

.training-exercise-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.6rem;
}

.training-exercise-actions .primary-button { grid-column: 1 / -1; }

.training-exercise-actions button {
  min-width: 0;
  padding-inline: 0.65rem;
  font-size: 0.85rem;
}

.training-exercise.compact { border-color: #c4d8d5; box-shadow: none; }
.training-exercise.compact.completed { background: #edf7f1; }
.training-exercise.compact.skipped { background: #f3f5f4; }

.training-exercise.compact > button {
  min-height: 3.8rem;
  justify-content: flex-start;
}

.status-icon {
  width: 2rem;
  height: 2rem;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--success-fill);
}

.status-icon svg,
.end-check svg {
  width: 1.3rem;
  height: 1.3rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-icon.skip-line {
  position: relative;
  background: #82918e;
}

.status-icon.skip-line::after {
  width: 0.9rem;
  height: 0.14rem;
  border-radius: 999px;
  background: #fff;
  content: "";
}

.finish-training-button {
  width: 100%;
  min-height: 3.7rem;
  margin-top: 1.25rem;
  padding: 0.8rem 1rem;
  border: 2px solid var(--teal);
  border-radius: 1rem;
  color: var(--teal-dark);
  background: #fff;
  font-weight: 780;
}

.training-end {
  min-height: calc(100dvh - 11rem);
  display: grid;
  place-items: center;
}

.end-card {
  width: 100%;
  padding: 2rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: 1.35rem;
  background: #fff;
  box-shadow: var(--shadow);
  text-align: center;
}

.end-check {
  width: 3.5rem;
  height: 3.5rem;
  display: grid;
  place-items: center;
  margin: 0 auto 1rem;
  border-radius: 50%;
  color: #fff;
  background: var(--success-fill);
}

.end-check svg { width: 2rem; height: 2rem; }

.end-card dl {
  display: grid;
  gap: 0.7rem;
  margin: 1.5rem 0;
  text-align: left;
}

.end-card dl div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--line);
}

.end-card dt { color: var(--muted); }
.end-card dd { margin: 0; font-weight: 720; text-align: right; }
.end-done { width: 100%; }

.history-training-list,
.history-exercise-list,
.exercise-history-list {
  display: grid;
  gap: 0.8rem;
}

.history-training-card {
  width: 100%;
  min-height: 4.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  color: #184b4b;
  background: #fff;
  box-shadow: var(--shadow-soft);
  text-align: left;
}

.history-training-card > span:first-child {
  min-width: 0;
  display: grid;
  gap: 0.25rem;
}

.history-training-card strong { font-size: 1rem; }

.history-training-card small {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.history-training-card > span:last-child {
  color: var(--teal-dark);
  font-size: 1.6rem;
}

.history-back {
  min-height: 3rem;
  margin: -0.45rem 0 0.4rem;
  padding: 0.35rem 0;
  border: 0;
  color: var(--teal-dark);
  background: transparent;
  font-weight: 750;
}

.history-detail-header { margin-bottom: 1rem; }

.history-exercise,
.exercise-history-entry {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.history-exercise > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.95rem 1rem 0.8rem;
}

.history-exercise h2 {
  margin: 0;
  font-size: 1rem;
}

.history-exercise header p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.history-status {
  flex: 0 0 auto;
  padding: 0.28rem 0.5rem;
  border-radius: 999px;
  color: var(--teal-dark);
  background: var(--teal-soft);
  font-size: 0.72rem;
  font-weight: 750;
}

.history-set-table { border-top: 1px solid var(--line); }

.history-set-head,
.history-set-row {
  display: grid;
  grid-template-columns: minmax(3rem, 0.65fr) minmax(5rem, 1fr) minmax(5rem, 1fr);
  gap: 0.55rem;
  padding: 0.62rem 1rem;
  text-align: right;
}

.history-set-head {
  color: var(--muted);
  background: #f3f7f6;
  font-size: 0.72rem;
  font-weight: 750;
}

.history-set-row {
  border-top: 1px solid #e7efed;
  color: #184b4b;
  font-size: 0.84rem;
}

.history-set-head span:first-child,
.history-set-row span:first-child { text-align: left; }
.history-set-row.is-skipped { color: var(--muted); }
.history-skipped-value { font-style: italic; }

.history-no-sets,
.history-snapshot-name {
  margin: 0;
  padding: 0.75rem 1rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.history-link-button {
  width: 100%;
  min-height: 3rem;
  padding: 0.65rem 1rem;
  border: 0;
  border-top: 1px solid var(--line);
  color: var(--teal-dark);
  background: #fff;
  text-align: left;
  font-weight: 750;
}

.exercise-history-entry > header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  color: #184b4b;
  background: #f3f7f6;
  font-size: 0.78rem;
}

.exercise-history-entry > header time { font-weight: 750; }
.exercise-history-entry > header span { color: var(--muted); text-align: right; }
.exercise-history-entry .history-exercise { border: 0; border-radius: 0; box-shadow: none; }

.export-dialog { width: min(92vw, 34rem); }

.export-help {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.export-text {
  width: 100%;
  min-height: min(48dvh, 22rem);
  padding: 0.85rem;
  resize: vertical;
  border: 1px solid #c4d9d6;
  border-radius: 0.85rem;
  color: #184b4b;
  background: #f7faf9;
  font: 0.82rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.export-status {
  min-height: 1.3rem;
  margin: 0.5rem 0 0;
  color: var(--teal-dark);
  font-size: 0.82rem;
  font-weight: 750;
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: 100%;
  max-width: 48rem;
  margin: 0 auto;
  padding: 0.55rem max(0.45rem, env(safe-area-inset-right)) max(0.55rem, env(safe-area-inset-bottom)) max(0.45rem, env(safe-area-inset-left));
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 28px rgba(24, 75, 75, 0.07);
  backdrop-filter: blur(14px);
  transition: opacity 120ms ease, transform 120ms ease;
}

body.keyboard-open .bottom-nav {
  opacity: 0;
  pointer-events: none;
  transform: translateY(100%);
}

.keyboard-panel-active {
  position: fixed !important;
  z-index: 80 !important;
  margin: 0 !important;
  max-width: calc(100% - 1.5rem) !important;
  background-color: var(--surface);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body.keyboard-open {
  overflow: hidden;
  overscroll-behavior: none;
}

.keyboard-panel-active .dialog-heading,
.keyboard-panel-active .training-exercise-header,
.keyboard-panel-active .routine-exercise-heading {
  position: sticky;
  z-index: 2;
  top: 0;
  background-color: var(--surface);
}

.keyboard-panel-active .dialog-actions,
.keyboard-panel-active .training-exercise-actions,
.keyboard-panel-active .routine-card-actions {
  position: sticky;
  z-index: 2;
  bottom: 0;
  padding-block: 0.5rem;
  background-color: var(--surface);
}

.bottom-nav a {
  min-width: 0;
  min-height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.25rem;
  border-radius: 0.9rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav a span {
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: center;
}

.bottom-nav a[aria-current="page"] {
  color: var(--teal-dark);
  background: var(--teal-soft);
}

.bottom-nav svg {
  width: 1.45rem;
  height: 1.45rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (min-width: 48rem) {
  .app-shell { box-shadow: 0 0 0 1px var(--line); }
  main { padding-inline: 2rem; }
  .topbar { padding-inline: 2rem; }
  .group-scroller { margin-inline: -2rem; padding-inline: 2rem; }
}

@media (max-width: 26rem) {
  .screen-header-row { align-items: flex-start; flex-direction: column; }
  .primary-button.compact,
  .secondary-button.compact { width: 100%; }
  .library-toolbar { align-items: stretch; flex-direction: column; }
  .library-toolbar > span { padding-bottom: 0; }
  .routine-card { grid-template-columns: 1fr; }
  .compact-action { width: 100%; }
  .routine-editor-toolbar { align-items: stretch; flex-direction: column; }
  .training-exercise.is-open { padding: 0.75rem; }
  .training-set {
    grid-template-columns: 3rem minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.4rem;
    padding: 0.65rem;
  }
}

@media (max-width: 36rem) {
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    font-size: 1rem;
  }

  .exercise-dialog {
    width: 100%;
    max-width: none;
    max-height: calc(var(--visual-viewport-height) - env(safe-area-inset-top));
    overflow-y: auto;
    margin: auto 0 0;
    padding: 1.25rem max(1.25rem, env(safe-area-inset-right)) max(1.25rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
    border-radius: 1.4rem 1.4rem 0 0;
  }

  .dialog-actions > button { flex: 1 1 0; }
}

@media (prefers-reduced-motion: no-preference) {
  main { animation: enter 180ms ease-out; }
  @keyframes enter { from { opacity: 0; transform: translateY(4px); } }
}
