:root {
  color-scheme: dark;
  --bg: #111410;
  --surface: #1a1e18;
  --surface2: #22271f;
  --text: #f1f4eb;
  --muted: #a7afa0;
  --line: #333a2e;
  --accent: #c3f56a;
  --accent-text: #17210d;
  --done: #202c17;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5ef;
  --surface: #fff;
  --surface2: #e9ede3;
  --text: #20261b;
  --muted: #5b6553;
  --line: #d7dfcd;
  --accent: #a9de45;
  --done: #edf7dd;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 16px; line-height: 1.5; }
button { font: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.shell { max-width: 1060px; margin: auto; padding: 0 40px; }
.header { display: flex; align-items: center; justify-content: space-between; padding: 28px 0; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.theme { background: var(--surface); color: var(--muted); border: 1px solid var(--line); padding: 8px 16px; min-height: 44px; border-radius: 24px; font-size: 14px; }
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 24px; }
.tabs button { display: flex; gap: 16px; align-items: center; text-align: left; min-height: 82px; padding: 16px 20px; border: 1px solid var(--line); border-radius: 14px; color: var(--muted); background: var(--surface); transition: background .18s, border-color .18s; }
.tabs strong { font-size: 30px; line-height: 1; color: var(--text); }
.tabs span { font-size: 14px; line-height: 1.3; }
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tabs button[aria-selected="true"] strong { color: var(--accent-text); }
.workout-summary { margin: 22px 0; }
.summary-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
h2 { font-size: 26px; letter-spacing: -.035em; margin: 0; }
.progress-label { display: flex; justify-content: space-between; margin-top: 16px; font-size: 14px; color: var(--muted); }
.progress-label strong { color: var(--text); }
progress { display: block; width: 100%; height: 6px; border: 0; border-radius: 9px; overflow: hidden; background: var(--surface2); margin-top: 10px; }
progress::-webkit-progress-bar { background: var(--surface2); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 9px; transition: width .2s; }
progress::-moz-progress-bar { background: var(--accent); }
#complete-message { color: var(--accent); font-size: 14px; margin-bottom: 0; }
:root[data-theme="light"] #complete-message { color: #476d19; }
.muscle-section { margin-bottom: 22px; }
.group-heading { display: flex; align-items: center; gap: 12px; margin: 0 0 10px; font-size: 16px; font-weight: 700; letter-spacing: .1em; }
.group-heading::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.group-heading small { font-weight: 400; font-size: 14px; letter-spacing: 0; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card { position: relative; display: grid; grid-template-columns: minmax(0, 36fr) minmax(0, 64fr); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; min-width: 0; overflow: hidden; transition: background .2s, border-color .2s; }
.card.done { background: var(--done); border-color: #6f9641; }
.exercise-figure { margin: 0; min-width: 0; display: flex; align-items: center; background: #e1e2e3; }
.exercise-image { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: contain; object-position: center; background: #e1e2e3; }
.exercise-content { min-width: 0; padding: 15px 14px; }
.card-title { text-align: left; padding: 0 38px 0 0; min-height: 38px; display: flex; align-items: center; }
.card h4 { font-size: 20px; line-height: 1.3; letter-spacing: -.02em; margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.muscles { text-align: left; color: var(--muted); font-size: 13px; line-height: 1.4; margin: 8px 0 0; }
.muscles b { font-weight: 500; color: var(--text); }
.exercise-toggle { position: absolute; top: 8px; right: 8px; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: 0 2px 10px #0003; color: var(--text); }
.exercise-toggle .check-mark { width: 25px; height: 25px; opacity: .35; transition: opacity .18s ease; pointer-events: none; }
.exercise-toggle[aria-pressed="true"] .check-mark { opacity: 1; }
.exercise-toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
footer { display: flex; justify-content: space-between; border-top: 1px solid var(--line); padding: 24px 0; margin-top: 20px; font-size: 12px; letter-spacing: .14em; color: var(--muted); }
#storage-warning { font-size: 14px; color: var(--muted); }

@media (max-width: 700px) {
  .shell { padding: 0 14px; }
  .header { padding: 14px 0; }
  .brand { font-size: 20px; }
  .tabs { gap: 7px; margin-top: 16px; }
  .tabs button { padding: 10px; flex-direction: column; align-items: flex-start; gap: 5px; min-height: 86px; }
  .tabs strong { font-size: 28px; }
  .tabs span { font-size: 12px; }
  .workout-summary { margin: 18px 0 22px; }
  .cards { grid-template-columns: 1fr; gap: 10px; }
  .exercise-content { padding: 12px; }
  .card h4 { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

.sticky-top { position: sticky; top: 0; z-index: 20; background: var(--bg); padding-top: env(safe-area-inset-top); border-bottom: 1px solid var(--line); }
.sticky-top .header { padding: 12px 0; }
.sticky-top .tabs { margin-top: 12px; }
.sticky-top .tabs button { min-height: 64px; padding: 12px 16px; }
.sticky-top .workout-summary { margin: 14px 0 16px; }
.sticky-top .progress-label { margin-top: 10px; }
#workout { padding-top: 22px; }
.timer-controls { display: flex; align-items: center; gap: 8px; }
#timer { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 68px; }
.timer-button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 9px; font-size: 14px; }
#timer-start:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.timer-button:disabled { opacity: .4; cursor: default; }
@media (max-width: 700px) {
  .sticky-top .tabs button { min-height: 70px; padding: 9px 10px; }
  .sticky-top .tabs strong { font-size: 23px; }
  .sticky-top .workout-summary { margin: 12px 0; }
  .summary-row { gap: 8px; }
  h2 { font-size: 23px; }
  .timer-controls { gap: 6px; }
  #timer { font-size: 19px; min-width: 61px; }
  .timer-button { padding: 8px 10px; }
}
@media (max-width: 340px) {
  .summary-row { flex-wrap: wrap; }
}

.group-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 10px 0; margin-bottom: 10px; cursor: pointer; list-style: none; touch-action: manipulation; border-bottom: 1px solid var(--line); }
.group-toggle::-webkit-details-marker { display: none; }
.group-toggle::marker { content: ''; }
.group-toggle:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.group-toggle .group-heading { margin: 0; flex-wrap: wrap; gap: 6px 12px; }
.group-toggle .group-heading::after { display: none; }
.group-action { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); flex-shrink: 0; }
.group-chevron { width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .18s; }
.muscle-section[open] .group-chevron { transform: rotate(225deg); }
.muscle-section:not([open]) .group-toggle { margin-bottom: 0; }

.summary-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 20px; }

.progress-block { min-width: 0; }
.sticky-top .progress-label { margin-top: 0; gap: 8px; }
.timer-controls { flex-wrap: nowrap; }
@media (max-width: 700px) {
  .summary-row { grid-template-columns: minmax(0, 1fr) auto; gap: 12px; }
  .progress-label { font-size: 12px; gap: 5px; }
  #timer { font-size: 17px; min-width: 52px; }
  .timer-controls { gap: 4px; }
  .timer-button { padding: 8px; font-size: 13px; }
}

.group-toggle {
  position: sticky;
  top: var(--header-height, 220px);
  z-index: 10;
  background: var(--bg);
  box-shadow: 0 5px 10px var(--bg);
}

.header-actions { display: flex; align-items: center; gap: 10px; }
.mode-switch { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); }
.mode-switch button { min-height: 38px; padding: 7px 12px; border: 0; border-radius: 20px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 700; }
.mode-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.tabs[data-mode="AB"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tabs button[hidden] { display: none; }
@media (max-width: 380px) {
  .header-actions { gap: 6px; }
  .mode-switch button { padding: 7px 10px; }
  .theme { padding: 8px 12px; }
}

html { scroll-padding-top: calc(var(--header-height, 220px) + 72px); }
.card { scroll-margin-top: calc(var(--header-height, 220px) + 72px); }
.muscle-section { scroll-margin-top: calc(var(--header-height, 220px) + 12px); }
.group-toggle { top: calc(var(--header-height, 220px) + 1px); margin-top: 0; }
.muscle-section[open] .cards { padding-top: 12px; }
.exercise-guide { padding: 0; text-align: left; }
.exercise-guide p { margin: 8px 0 0; font-size: 14px; line-height: 1.45; color: var(--text); }
.exercise-guide a { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; color: var(--accent); font-size: 13px; font-weight: 600; text-underline-offset: 4px; }
:root[data-theme="light"] .exercise-guide a { color: #476d19; }
a:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.character-select { font: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); color: var(--text); padding: 8px 6px; min-height: 44px; max-width: 90px; }
@media (max-width: 700px) {
  .header-actions { gap: 6px; }
  .mode-switch button { padding: 7px 8px; font-size: 13px; }
  .character-select { max-width: 80px; font-size: 13px; }
  .theme { padding: 8px 10px; font-size: 13px; }
  .exercise-guide { padding: 0; }
}
@media (max-width: 350px) {
  .header { gap: 8px; flex-wrap: wrap; }
  .header-actions { margin-left: auto; }
}

.muscle-section:not([open]) .group-toggle { position: relative; top: auto; }
.sticky-top { display: flow-root; }

.video-links { display: flex; flex-wrap: wrap; justify-content: flex-start; column-gap: 12px; }

.icon-toggle { position: relative; display: flex; align-items: center; gap: 2px; flex-shrink: 0; width: 76px; height: 44px; padding: 4px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); color: var(--muted); }
.icon-toggle::before { content: ''; position: absolute; top: 5px; left: 4px; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); transition: transform .18s ease; }
.icon-toggle[data-position="second"]::before { transform: translateX(34px); }
.icon-toggle > span { position: relative; display: grid; place-items: center; width: 32px; height: 32px; flex-shrink: 0; }
.icon-toggle svg { width: 22px; height: 22px; }
.character-toggle img { width: 28px; height: 28px; object-fit: cover; border-radius: 50%; opacity: .55; transition: opacity .18s ease; }
.character-toggle[data-position="first"] > span:first-child img, .character-toggle[data-position="second"] > span:last-child img { opacity: 1; }
.icon-toggle[data-position="first"] > span:first-child, .icon-toggle[data-position="second"] > span:last-child { color: var(--accent-text); }
.card { display: flex; align-items: flex-end; min-height: 330px; aspect-ratio: 1.25; }
.exercise-figure { position: absolute; inset: 0; align-items: flex-start; }
.exercise-image { height: 100%; aspect-ratio: auto; object-fit: contain; object-position: center top; }
.exercise-content { position: relative; width: 100%; padding: 64px 16px 14px; color: #fff; background: linear-gradient(180deg, transparent 0%, #111410c9 28%, #111410f5 100%); }
.card-title { padding: 0; min-height: 0; }
.card h4 { font-size: 18px; line-height: 1.25; }
.exercise-guide p { margin-top: 6px; font-size: 12.5px; line-height: 1.4; color: #f1f4eb; }
.exercise-guide a, :root[data-theme="light"] .exercise-guide a { min-height: 40px; color: #c3f56a; font-size: 12px; }
.muscles { margin-top: 2px; font-size: 11.5px; line-height: 1.35; color: #d4d9cf; }
.muscles b { color: #f1f4eb; }
.card.done .exercise-content { background: linear-gradient(180deg, transparent 0%, #202c17cc 28%, #202c17fa 100%); }
@media (max-width: 700px) {
  .card { min-height: 330px; aspect-ratio: 1.08; }
  .header-actions { gap: 5px; }
}

.timer-controls { gap: 4px; padding: 4px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.timer-controls #timer { margin-right: 4px; min-width: 56px; text-align: center; }
.timer-button { display: grid; place-items: center; flex-shrink: 0; width: 44px; height: 44px; padding: 0; }
.timer-button svg { width: 18px; height: 18px; pointer-events: none; }
.timer-controls[data-state="paused"] #timer { color: var(--accent); }
:root[data-theme="light"] .timer-controls[data-state="paused"] #timer { color: #476d19; }
.progress-block { display: flex; flex-direction: column; justify-content: center; min-height: 54px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.progress-label { flex-wrap: wrap; }
.sticky-top .tabs button { min-height: 54px; padding: 9px 12px; flex-direction: row; align-items: center; gap: 10px; }
.sticky-top .tabs strong { font-size: 25px; }
.sticky-top .tabs span { font-size: 13px; }
@media (max-width: 700px) {
  .sticky-top .tabs button { min-height: 52px; padding: 8px; gap: 7px; }
  .sticky-top .tabs strong { font-size: 23px; }
  .sticky-top .tabs span { font-size: 10.5px; line-height: 1.2; }
  .summary-row { gap: 10px; }
  .progress-block { padding: 8px; }
  .timer-controls { gap: 2px; padding: 4px; }
  .timer-controls #timer { min-width: 48px; margin-right: 3px; font-size: 16px; }
  .timer-button { width: 42px; padding: 0; }
}
