.kg-lib-open{width:100%;margin:0 0 9px;padding:10px 12px;min-height:53px;display:flex;align-items:center;justify-content:space-between;text-align:left;background:var(--kg-surface)}
.kg-lib-open small{font-size:12px;font-weight:550}
.kg-lib-open>span:last-child{font-size:24px;line-height:1}
.kg-lib-dialog{color:var(--kg-text);background:var(--kg-surface);border:1px solid var(--kg-edge);border-radius:18px;width:min(560px,calc(100% - 18px));max-height:calc(100dvh - 26px);padding:14px;overscroll-behavior:contain}
.kg-lib-dialog::backdrop{background:#121219BB}
.kg-lib-head{display:flex;align-items:center;justify-content:space-between;gap:7px;margin:0 0 5px}
.kg-lib-head h2{margin:0;font-size:clamp(20px,6vw,27px);line-height:1.04}
.kg-lib-head button{width:44px;height:44px;padding:0;font-size:25px;line-height:1}
.kg-lib-intro{font-size:13px;margin:0 0 8px}
.kg-lib-filters{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:5px 8px}
.kg-lib-filters label{margin:0;font-size:12px;font-weight:700}
.kg-lib-search{grid-column:1/-1}
.kg-lib-filters select,.kg-lib-filters input[type=search]{margin-top:2px;min-height:44px;padding:5px 7px;font-size:14px}
.kg-lib-check{align-self:end;min-height:44px;display:flex;align-items:center;gap:5px}
.kg-lib-check input,.kg-gear-set input{width:18px;height:18px;margin:0;accent-color:var(--kg-primary)}
.kg-lib-method,.kg-lib-count,.kg-lib-empty{font-size:13px;margin:8px 0}
.kg-lib-method p{margin:5px 0}
.kg-lib-card{border:1px solid var(--kg-edge);border-radius:11px;background:var(--kg-bg);margin:5px 0;padding:0 9px}
.kg-lib-card summary{min-height:52px;display:flex;align-items:center;justify-content:space-between;gap:5px;padding:6px 0;list-style:none}
.kg-lib-card summary::after{content:'+';color:var(--kg-muted);font-size:18px;margin-left:4px}
.kg-lib-card[open] summary::after{content:'−'}
.kg-lib-card summary>span:first-child{flex:1}
.kg-lib-card summary strong{font-size:14px;line-height:1.2}
.kg-lib-card summary small{font-size:11px;line-height:1.25}
.kg-lib-study{padding:3px 5px;border-radius:6px;background:var(--kg-accent-soft);color:var(--kg-accent-text);font-size:10px;white-space:nowrap}
.kg-lib-detail{border-top:1px solid var(--kg-edge);padding:7px 0 9px}
.kg-lib-detail p{font-size:13px;margin:0 0 5px}
.kg-lib-detail button{min-height:44px;margin:4px 0 0}
.kg-gear-set{border:1px solid var(--kg-edge);border-radius:10px;margin:12px 0 0;padding:5px 8px}
.kg-gear-set legend{font-size:13px;font-weight:750}
.kg-gear-set p{font-size:11px;margin:1px 0 4px}
.kg-gear-set label{display:flex;align-items:center;gap:8px;margin:0;min-height:30px}
.cop-demo.cop-text-guide{height:auto;min-height:130px;background:var(--kg-surface);border-color:var(--kg-edge)}
.cop-text-guide-inner{padding:53px 10px 8px}
.cop-text-guide-inner p{margin:0;color:var(--kg-text);font-size:14px;font-weight:680;max-width:45ch}
.cop-text-guide-inner small{font:740 10px var(--kg-mono);color:var(--kg-muted);letter-spacing:.07em;margin-bottom:3px}
[data-theme] .cop-demo-panel a{color:inherit;text-decoration:underline}
.kg-lib-picks{border:1px solid var(--kg-edge);border-radius:11px;background:var(--kg-bg);padding:7px 9px;margin:6px 0 9px;font-size:13px}
.kg-lib-picks>summary{min-height:31px;align-content:center}
.kg-lib-picks p{margin:3px 0 6px}
.kg-lib-picks>div{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:5px}
.kg-lib-picks button{text-align:left;padding:6px 7px;min-height:45px;border-radius:8px;font-size:12px}
.kg-lib-picks button small{font-size:10px;line-height:1.2}

/* The control buttons stay put; open content replaces the player's drawing
   instead of squeezing into a tiny independently scrolling tooltip. */
#copDemoStage[data-panel]:not([data-panel=""]){
  height:auto;min-height:145px;overflow:visible;
  background:var(--kg-surface);border-color:var(--kg-edge);
}
#copDemoStage[data-panel]:not([data-panel=""])>.cop-motion,
#copDemoStage[data-panel]:not([data-panel=""])>.cop-demo-play,
#copDemoStage[data-panel]:not([data-panel=""])>small,
#copDemoStage[data-panel]:not([data-panel=""])>.cop-text-guide-inner{display:none}
[data-theme] #copDemoPanel:not([hidden]){
  position:relative;inset:auto;max-height:none;overflow:visible;
  width:100%;padding:48px 9px 9px;background:transparent;
  color:var(--kg-text);border:0;box-shadow:none;
}
#copDemoPanel h2{color:var(--kg-text);font-size:15px;line-height:1.15;margin:0 0 4px}
[data-theme] #copDemoPanel .kg-demo-meta{font-size:11px;color:var(--kg-muted);margin:3px 0}
[data-theme] #copDemoPanel .kg-demo-cue{font-size:14px;color:var(--kg-text);font-weight:640;line-height:1.33;margin:4px 0}
[data-theme] #copDemoPanel a{color:var(--kg-accent-text)}
.kg-demo-study{display:inline-flex;align-items:center;min-height:37px;font-size:12px}
.cop-demo>.kg-demo-back{position:absolute;z-index:3;top:3px;left:4px;right:auto;bottom:auto;display:inline-flex;align-items:center;gap:3px;min-height:44px;width:auto;height:auto;padding:4px 8px;border:0;border-radius:4px;background:transparent;box-shadow:none;color:var(--kg-accent-text);font-size:12px;white-space:nowrap;line-height:1.13}
.cop-demo>.kg-demo-back:hover:not(:disabled){filter:none;text-decoration:underline}
.cop-demo>.kg-demo-back[hidden]{display:none}
.kg-demo-back svg{width:15px;height:15px;flex:none}
.kg-swap-recommend{border:1px solid var(--kg-edge);border-inline-start:3px solid var(--kg-accent-text);border-radius:11px;background:var(--kg-bg)}
.kg-swap-pick{background:transparent;color:var(--kg-text);width:100%;min-height:49px;padding:6px 8px 2px;display:grid;grid-template-columns:minmax(0,1fr) max-content;align-items:center;text-align:left;gap:6px;border-radius:8px}
.kg-swap-pick:hover:not(:disabled){filter:none;background:var(--kg-surface)}
.kg-swap-choice{min-width:0}
[data-theme] #copDemoPanel .kg-swap-pick strong{color:var(--kg-text);margin:3px 0 0;font-size:14px;line-height:1.15;overflow-wrap:anywhere}
[data-theme] #copDemoPanel .kg-swap-badge{display:inline-flex;align-items:center;gap:3px;padding:2px 6px;border-radius:999px;background:var(--kg-accent-soft);color:var(--kg-accent-text);margin:0;font:750 10px/1.1 system-ui,sans-serif}
.kg-swap-badge svg{width:11px;height:11px;flex:none}
.kg-swap-arrow{width:27px;height:27px;border-radius:50%;background:var(--kg-accent-soft);color:var(--kg-accent-text);display:grid;place-items:center}
.kg-swap-arrow svg{width:16px;height:16px}
.kg-swap-why{padding:2px 8px 6px;font-size:11px;line-height:1.26;color:var(--kg-muted)}
.kg-swap-why a{white-space:normal;display:inline-flex;align-items:center;min-height:28px;margin-block:-5px}
@media(max-width:350px){.cop-demo>.kg-demo-back{padding-inline:5px;font-size:11px}}
.kg-swap-options{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:4px;margin-top:5px}
.kg-swap-options .secondary{min-height:44px;font-size:11px;line-height:1.16;padding:4px 6px;text-align:left}
.kg-swap-options .secondary:only-child{grid-column:1/-1}
.kg-lib-preview:not([hidden]){margin-top:5px}
.kg-lib-preview .cop-demo{height:clamp(128px,25svh,164px)}
.kg-lib-detail .kg-lib-preview .cop-demo-play{width:44px;height:44px;margin:0;padding:4px}

/* Swap is a focused view. Never let a long history or a tall set card
   add scroll behind the three choices. Sets return unchanged on close. */
@media(min-height:365px){
  html:has(#copDemoStage[data-panel="swap"]),body:has(#copDemoStage[data-panel="swap"]){overflow:hidden;overscroll-behavior:none}
  main:has(#copDemoStage[data-panel="swap"]){max-height:100dvh;padding-bottom:calc(68px + env(safe-area-inset-bottom))}
  .cop-ex:has(#copDemoStage[data-panel="swap"])>.cop-logs:not(.cop-guided-sets),.cop-ex:has(#copDemoStage[data-panel="swap"])>.cop-step-back{display:none}
}
@media(min-height:365px) and (max-height:659px){
  .cop-ex:has(#copDemoStage[data-panel="swap"])>.cop-ex-workbar,
  .cop-ex:has(#copDemoStage[data-panel="swap"])>.cop-guided-sets{display:none}
}

/* The ordinary exercise view uses the viewport height instead of leaving a
   strip of unused space above the fixed app navigation. Long content can reflow. */
main:has(.cop-ex-compact){
  --kg-ex-top:8px;
  --kg-ex-bottom:calc(75px + env(safe-area-inset-bottom));
  padding-top:var(--kg-ex-top);
  padding-bottom:var(--kg-ex-bottom);
}
.cop-ex-compact>h1{
  margin:12px 0 10px;
  font-size:clamp(23px,6.1vw,30px);
  line-height:1.08;
  overflow-wrap:anywhere;
}
.cop-ex-compact:has(>#copDemoStage[data-panel=""]):has(>.cop-guided-sets):not(:has(details[open])){
  display:flex;
  flex-direction:column;
  min-height:calc(100svh - var(--kg-ex-top) - var(--kg-ex-bottom));
  min-height:calc(100dvh - var(--kg-ex-top) - var(--kg-ex-bottom));
}
.cop-ex-compact:has(>#copDemoStage[data-panel=""]):has(>.cop-guided-sets):not(:has(details[open]))>*{
  flex:0 0 auto;
}
.cop-ex-compact:has(>#copDemoStage[data-panel=""]):has(>.cop-guided-sets):not(:has(details[open]))>#copDemoStage{
  flex:1 0 clamp(126px,23svh,200px);
  height:auto;
}
.cop-ex-compact:has(>#copDemoStage[data-panel=""]):has(>.cop-guided-sets):not(:has(details[open]))>#copDemoStage>.cop-motion{
  position:absolute;
  inset:0;
}
.cop-ex-compact>.cop-guided-sets{margin-bottom:0}
.cop-ex-compact .cop-guided-sets .cop-set-stage{
  border-color:transparent;
}
@media(max-height:550px){
  .cop-ex-compact>h1{margin-top:8px;margin-bottom:8px}
}

/* Units share the weight label's row rather than adding a second control row. */
.kg-weighted-fields .cop-field-caption{min-height:32px;display:flex;align-items:center}
.kg-set-load{min-width:0}
.kg-weighted-fields .kg-set-load-head{justify-content:space-between;gap:4px}
.kg-weighted-fields .kg-set-load-head label{margin:0;font-size:12px}
.kg-unit-switch{display:inline-flex;flex-shrink:0;gap:2px;align-items:center;padding:2px;background:var(--kg-raised);border:1px solid var(--kg-edge);border-radius:8px}
.kg-unit-switch .kg-unit-option{min-width:30px;min-height:26px;padding:2px 6px;border-radius:5px;background:transparent;color:var(--kg-muted);font-size:11px;font-weight:720;line-height:1}
.kg-unit-switch .kg-unit-option[aria-pressed=true]{background:var(--kg-primary);color:var(--kg-primary-ink)}
@media(max-width:335px){.kg-unit-switch .kg-unit-option{min-width:25px;padding-inline:3px}}

/* Workout overview: four exercise rows and the finish/options actions stay
   together above the fixed navigation, without truncating names or status. */
main:has(.cop-summary){
  padding-top:8px;
  padding-bottom:calc(74px + env(safe-area-inset-bottom));
}
main:has(.cop-summary)>header{
  margin-bottom:8px;
  padding-bottom:6px;
}
.cop-summary .cop-session{padding:10px 11px 9px;border-radius:17px}
.cop-summary .cop-session-identity{grid-template-columns:minmax(0,1fr) 59px;gap:6px}
.cop-summary .cop-kicker{font-size:9px;line-height:1.2;margin:0 0 3px}
.cop-summary .cop-session h1{font-size:clamp(23px,6.6vw,34px);line-height:1.07;margin:0 0 4px;overflow-wrap:anywhere}
.cop-summary .cop-session-meta{font-size:11px;gap:2px 8px}
.cop-summary .cop-ring{width:57px;padding:3px}
.cop-summary .cop-ring strong{font-size:19px}
.cop-summary .cop-session-progress{margin-top:7px}
.cop-summary .cop-progress-text{font-size:11px;line-height:1.2;margin-top:3px}
.cop-summary .cop-primary{margin-top:7px;min-height:44px;padding:5px 8px;font-size:14px}
.cop-summary .cop-list-head{margin:8px 0 5px}
.cop-summary .cop-list-head h2{font-size:17px;line-height:1.17;margin:0 0 1px}
.cop-summary .cop-list-head p{font-size:11px;line-height:1.24}
.cop-summary .cop-workout-list{gap:4px}
.cop-summary .cop-workout-row{min-height:46px;padding:4px 8px;grid-template-columns:26px minmax(0,1fr) auto;gap:6px;border-radius:10px}
.cop-summary .cop-workout-number{width:25px;height:25px;border-radius:7px}
.cop-summary .cop-workout-title{gap:1px}
.cop-summary .cop-workout-title strong{font-size:14px;line-height:1.13}
.cop-summary .cop-workout-title>span{font-size:11px;line-height:1.15}
.cop-summary .cop-workout-indicators{gap:3px}
.cop-summary .cop-workout-footer{display:flex;flex-wrap:wrap;gap:5px;margin:6px 0 0}
.cop-summary .cop-workout-footer>button{flex:1 1 43%;margin:0;min-height:44px;padding:5px 6px;font-size:12px;line-height:1.17}
.cop-summary .cop-workout-footer>.cop-retained,.cop-summary .cop-workout-footer>.cop-feedback{flex:0 0 100%;margin:0}
.cop-summary .cop-workout-footer>.cop-feedback:empty{display:none}
.cop-summary .cop-comfort{margin:6px 0;padding:5px 8px}
.cop-overview-dialog{width:min(390px,calc(100% - 24px));max-height:calc(100dvh - 26px);border:1px solid var(--kg-edge);border-radius:16px;background:var(--kg-surface);color:var(--kg-text);padding:13px}
.cop-overview-dialog::backdrop{background:#121219BB}
.cop-overview-dialog-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:6px;gap:7px}
.cop-overview-dialog-head h2{margin:0;font-size:20px}
.cop-overview-dialog-head button{width:44px;height:44px;padding:0;font-size:24px;line-height:1}
.cop-overview-dialog>p{margin:0 0 6px;font-size:14px}
@media(min-width:650px){.cop-summary .cop-session{padding:13px 15px 11px}}

/* Fill the visible viewport using content, not a trailing spacer. At the
   44px minimum tap size longer lists or enlarged text can reflow safely. */
main:has(.cop-summary){
  display:flex;
  flex-direction:column;
  min-height:100svh;
  min-height:100dvh;
}
main:has(.cop-summary)>header{flex:0 0 auto}
#screen:has(>.cop-summary){display:flex;flex-direction:column;flex:1 0 auto}
.cop-summary{
  --cop-session-space:1.75;
  --cop-list-space:var(--cop-exercise-rows,4);
  display:flex;
  flex-direction:column;
  flex:1 0 auto;
  width:100%;
}
.cop-summary[data-density="spacious"]{--cop-session-space:3.75;--cop-list-space:var(--cop-exercise-rows,2)}
.cop-summary[data-density="compact"]{--cop-session-space:1}
.cop-summary>.cop-session{
  flex:var(--cop-session-space) 0 auto;
  display:flex;
  flex-direction:column;
  justify-content:center;
}
.cop-summary>.cop-session .cop-primary{flex-shrink:0}
.cop-summary>.cop-workout-list{display:flex;flex-direction:column;flex:var(--cop-list-space) 0 auto}
.cop-summary>.cop-workout-list>li{flex:1 0 auto;display:flex}
.cop-summary>.cop-workout-list>li>.cop-workout-row{flex:1 0 100%}
.cop-summary>.cop-workout-footer{flex:0 0 auto}
.cop-summary[data-density="compact"] .cop-workout-row{min-height:44px}
@media(min-height:660px){
  .cop-summary[data-density="spacious"] .cop-session{padding-block:14px}
  .cop-summary[data-density="spacious"] .cop-session-progress{margin-top:11px}
  .cop-summary[data-density="spacious"] .cop-primary{margin-top:11px}
}
