/* Custom training task builder.
   Tokens mirror the record-calendar v3 system: one purple hue, 4px rhythm,
   1px hairlines, no gradients/shadows on controls, 44px minimum targets. */

/* ---------- Global entry points (visible inside the exercise library / sport hub) ---------- */
.ct-entry{
  display:flex;align-items:center;gap:12px;box-sizing:border-box;width:100%;
  min-height:84px;margin:18px 0 10px;padding:15px 16px;
  border:1px solid #e4dcfa;border-radius:20px;background:#f5f1ff;
}
.ct-entry-copy{flex:1;min-width:0}
.ct-entry-copy h2{margin:0 0 5px;color:#4b35b8;font-size:15px;font-weight:750;line-height:1.3}
.ct-entry-copy p{margin:0;color:#6b7396;font-size:11px;line-height:1.5}
.ct-entry-btn{
  flex-shrink:0;min-height:44px;padding:0 14px;border:1px solid #d9c9ff;border-radius:13px;
  background:#fff;color:#5b3fd0;font:700 12px/1 inherit;white-space:nowrap;cursor:pointer;
}
.ct-entry-btn i{font-size:16px;vertical-align:-2px}
/* 入口按钮：和功能中心的运动/饮食磁贴（.fc-tile）同一套视觉语言——
   11px 圆角、浅紫渐变底、右上角低透明度装饰图标、左下角圆形箭头，
   这样它看起来是「运动」区块里的第 8 个磁贴，而不是一条外挂的灰条。 */
.ct-entry-inline{
  position:relative;display:block;box-sizing:border-box;width:100%;
  height:80px;margin:8px 0 0;padding:0;
  border:0;border-radius:11px;overflow:hidden;isolation:isolate;
  background:linear-gradient(118deg,#f4f0ff 0%,#e7deff 100%);
  color:#0b1030;font-family:inherit;text-align:left;cursor:pointer;
  touch-action:manipulation;-webkit-tap-highlight-color:transparent;
  transition:filter .12s ease;
}
.ct-entry-inline:hover{filter:brightness(.985)}
.ct-entry-inline:active{filter:brightness(.955)}
.ct-entry-inline:focus-visible{outline:3px solid #7354ef;outline-offset:2px}
.ct-entry-inline>i:first-child{
  position:absolute;right:13px;bottom:9px;z-index:0;
  font-size:36px;line-height:1;color:#9f89ea;opacity:.4;pointer-events:none;
}
/* 文案绝对定位在左上，和 .fc-tile .fc-copy 一致：不论标题行高多少，
   左下角的圆形箭头都不会压到副标题上。 */
.ct-entry-inline span{
  position:absolute;z-index:2;top:9px;left:12px;right:68px;min-width:0;
}
.ct-entry-inline strong{
  display:block;font-size:15px;font-weight:800;line-height:20px;
  color:#0b1030;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
.ct-entry-inline small{
  display:block;margin-top:3px;font-size:10.5px;line-height:16px;
  color:#535e86;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
/* 左下角圆形箭头，尺寸与 .fc-arrow 完全一致（17px 圆 + 白色箭头） */
.ct-entry-inline>i:last-child{
  position:absolute;left:12px;bottom:10px;z-index:2;
  display:grid;place-items:center;width:17px;height:17px;margin:0;
  border-radius:50%;background:#9e8dff;color:#fff;font-size:17px;
}
.ct-entry-mini{
  margin:12px 0 0;
  background:linear-gradient(118deg,#f6f3ff 0%,#ece4ff 100%);
}
@media(max-width:370px){
  .ct-entry-inline{height:76px}
  .ct-entry-inline span{left:9px;right:62px}
  .ct-entry-inline strong{font-size:14px;line-height:19px}
  .ct-entry-inline small{font-size:10px;line-height:15px}
  .ct-entry-inline>i:first-child{right:10px;font-size:32px}
  .ct-entry-inline>i:last-child{left:9px}
}

/* ---------- Exercise library selection (numbers only, no extra UI module) ----------
   The native search box stays untouched. Picked cards get a purple outline and the
   existing "+" button turns into a continuous sequence number; tapping again removes it. */
.action-library-item.is-ct-picked{
  border-color:#b9a3ff!important;background:#f7f3ff!important;
  box-shadow:inset 0 0 0 1px #e2d8ff,0 6px 17px rgba(90,73,240,.10);
}
.action-library-add.is-ct-picked{
  background:#5533c9!important;color:#fff!important;
  font-size:16px!important;font-weight:800!important;line-height:1!important;
  box-shadow:0 4px 12px rgba(85,51,201,.26)!important;
}
.action-library-add.is-ct-picked i{display:none}
#global-map-back[data-ct-count]:not([data-ct-count="0"])::after{
  content:attr(data-ct-count);position:absolute;top:1px;right:-3px;
  display:grid;place-items:center;min-width:19px;height:19px;padding:0 4px;
  border-radius:999px;background:#6d4de0;color:#fff;
  font:750 11px/1 Inter,"Microsoft YaHei",sans-serif;letter-spacing:0;
  pointer-events:none;
}
.action-library-list .global-empty [data-ct-create-custom]{
  margin-top:2px;border:1px solid #d9c9ff!important;background:#f3eeff!important;color:#5533c9!important;
  font-weight:700!important;
}

/* ---------- Toast (parent may be the library page, so keep it global) ---------- */
.ct-toast{
  position:fixed;z-index:200;left:50%;bottom:calc(112px + env(safe-area-inset-bottom));transform:translateX(-50%);
  max-width:min(88vw,360px);padding:11px 16px;border-radius:13px;
  background:#2c3358;color:#fff;font-size:12px;line-height:1.5;text-align:center;
  opacity:0;pointer-events:none;transition:opacity .18s ease;
}
.ct-toast.is-on{opacity:1}

/* ---------- Page shell ---------- */
#custom-task-module{
  --ct-brand:#6d4de0; --ct-brand-dark:#5533c9; --ct-brand-soft:#f0eaff;
  --ct-ink:#2c3358; --ct-muted:#6b7396; --ct-line:#ece8fa;
  --ct-canvas:#f6f6fd; --ct-surface:#fff; --ct-soft:#faf9ff;
  --ct-record:#dcd0ff; --ct-record-ink:#4a2eaa;
  box-sizing:border-box;display:none;width:min(100%,500px);margin:0 auto;
  min-height:100vh;padding:0 16px calc(126px + env(safe-area-inset-bottom));background:var(--ct-canvas);
  font-family:Inter,"Microsoft YaHei",-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  color:var(--ct-ink);
}
body.custom-task-active{background:var(--ct-canvas)!important}
body.custom-task-active #custom-task-module{display:block}
#custom-task-module *,#custom-task-module *::before,#custom-task-module *::after{box-sizing:border-box}
#custom-task-module button{font-family:inherit}
#custom-task-module button:focus-visible,
#custom-task-module input:focus-visible{outline:3px solid #b6a6ff;outline-offset:2px}

.ct-top{display:flex;align-items:center;gap:12px;padding:22px 0 18px}
.ct-back{
  flex-shrink:0;width:44px;height:44px;border:1px solid var(--ct-line);border-radius:14px;
  background:var(--ct-surface);color:var(--ct-brand);font-size:26px;line-height:1;cursor:pointer;
}
.ct-top h1{margin:0;font-size:23px;font-weight:800;letter-spacing:.01em;line-height:1.25}
.ct-top p{margin:4px 0 0;color:var(--ct-muted);font-size:11.5px;line-height:1.5}
.ct-main{display:grid;gap:14px}
[data-ct-success]:empty{display:none}
.ct-section{
  padding:16px;border:1px solid var(--ct-line);border-radius:20px;background:var(--ct-surface);
}
.ct-section-head{display:flex;align-items:baseline;justify-content:space-between;gap:10px;margin-bottom:12px}
.ct-section-head h2{margin:0;font-size:15px;font-weight:750;line-height:1.4}
.ct-section-head span{flex-shrink:0;color:var(--ct-muted);font-size:11px}
.ct-hint{margin:0 0 12px;color:var(--ct-muted);font-size:11.5px;line-height:1.7}
.ct-empty{margin:0;padding:14px 4px;color:var(--ct-muted);font-size:11.5px;text-align:center}

/* ---------- Training parts (same vocabulary as the 1/2/3/5 split table) ----------
   之前是四等分固定列 + white-space:nowrap：五分化里「胸部＋肱三头肌」「股四头肌＋小腿」
   这种两部位合称的标签比一列还宽，直接压到相邻块上，看起来像一串连在一起的文字。
   现在改成「按内容自适应」：普通标签约占四分之一行，带＋的合称标签占半行并可换行，
   ＋ 单独做成一个彩色标记，标签再长也不会溢出到隔壁。 */
.ct-parts{display:flex;flex-wrap:wrap;gap:8px}
.ct-part{
  box-sizing:border-box;
  display:inline-flex;align-items:center;justify-content:center;gap:4px;
  flex:1 1 calc(25% - 8px);min-width:0;min-height:44px;padding:6px 10px;
  border:1px solid var(--ct-line);border-radius:12px;
  background:var(--ct-soft);color:var(--ct-ink);font-size:12.5px;font-weight:650;
  line-height:1.25;white-space:nowrap;text-align:center;cursor:pointer;
  transition:background .15s ease,color .15s ease,border-color .15s ease;
}
.ct-part.is-wide{
  flex:1 1 calc(50% - 4px);white-space:normal;flex-wrap:wrap;
  row-gap:2px;padding:8px 10px;
}
.ct-part-token{display:inline-block}
.ct-part-plus{
  display:inline-grid;place-items:center;width:14px;height:14px;flex-shrink:0;
  border-radius:50%;background:rgba(112,72,239,.12);color:var(--ct-brand);
  font-size:10px;font-weight:700;font-style:normal;line-height:1;
}
.ct-part:hover{background:#f2ecff}
.ct-part.is-on{border-color:var(--ct-brand);background:var(--ct-brand);color:#fff;font-weight:750}
.ct-part.is-on .ct-part-plus{background:rgba(255,255,255,.24);color:#fff}
.ct-part:active{transform:scale(.97)}

/* ---------- Exercise cards ----------
   Left media / right copy rhythm matches .plan-workout-row in the training plan:
   4:3 cover, action name, timing, then the three parameter buttons below. */
.ct-exercise-list{display:grid;gap:10px;margin-bottom:12px}
.ct-exercise{padding:12px;border:1px solid var(--ct-line);border-radius:16px;background:var(--ct-soft)}
.ct-exercise-head{
  display:grid;grid-template-columns:88px minmax(0,1fr) 44px;
  align-items:center;gap:10px;margin-bottom:10px;
}
.ct-ex-media{
  position:relative;width:100%;aspect-ratio:4/3;overflow:hidden;
  border:1px solid #e6e0fa;border-radius:13px;background:#eeebfb;
}
.ct-ex-video{display:block;width:100%;height:100%;object-fit:cover;object-position:center}
.ct-ex-media-empty{
  display:grid;place-items:center;width:100%;height:100%;
  background:#eeebfb;color:#a99add;font-size:26px;
}
.ct-ex-index{
  position:absolute;z-index:2;top:4px;left:4px;
  display:grid;place-items:center;width:21px;height:21px;border-radius:7px;
  background:rgba(109,77,224,.94);color:#fff;font-size:10.5px;font-weight:800;
}
.ct-ex-play{
  position:absolute;z-index:1;inset:0;display:grid;place-items:center;
  width:100%;height:100%;padding:0;border:0;border-radius:13px;
  background:rgba(28,22,66,.10);color:#fff;cursor:pointer;
}
.ct-ex-play i{
  display:grid;place-items:center;width:27px;height:27px;border-radius:50%;
  background:rgba(255,255,255,.95);color:var(--ct-brand-dark);font-size:13px;
}
.ct-ex-play.is-playing{background:transparent}
.ct-ex-play.is-playing i{opacity:.86}
.ct-ex-play:focus-visible{outline:3px solid #b6a6ff;outline-offset:-3px}
.ct-ex-copy{min-width:0}
.ct-ex-name{display:block;font-size:14px;font-weight:750;line-height:1.4;overflow-wrap:anywhere}
.ct-ex-meta{display:block;margin-top:3px;color:var(--ct-muted);font-size:10.5px;line-height:1.5;overflow-wrap:anywhere}
.ct-ex-remove{
  width:44px;height:44px;border:0;border-radius:12px;background:transparent;
  color:#8b73d8;font-size:19px;cursor:pointer;
}
.ct-params{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}
.ct-param-btn{
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;
  min-height:54px;padding:7px 4px;border:1px solid var(--ct-line);border-radius:12px;
  background:var(--ct-surface);color:var(--ct-ink);text-align:center;cursor:pointer;
}
.ct-param-btn small{color:var(--ct-muted);font-size:10px;line-height:1.3}
.ct-param-btn strong{color:var(--ct-brand-dark);font-size:11.5px;font-weight:750;line-height:1.35;overflow-wrap:anywhere}
.ct-param-btn.is-primary{background:var(--ct-brand-soft);border-color:#e0d2ff}
.ct-param-btn:active{transform:scale(.98)}
.ct-add{
  display:flex;align-items:center;justify-content:center;gap:8px;width:100%;min-height:56px;
  border:1px dashed #d3c2ff;border-radius:14px;background:var(--ct-soft);color:var(--ct-brand-dark);
  font-size:13px;font-weight:750;cursor:pointer;
}
.ct-add i{font-size:20px}
.ct-add small{color:var(--ct-muted);font-size:10.5px;font-weight:400}
.ct-add:hover{background:#f2ecff}

/* ---------- Multi-select training dates ---------- */
.ct-calendar-toolbar{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:10px}
.ct-calendar-toolbar strong{font-size:15px;font-weight:750}
.ct-calendar-toolbar button{
  width:44px;height:44px;border:1px solid var(--ct-line);border-radius:12px;
  background:var(--ct-soft);color:var(--ct-brand);font-size:23px;line-height:1;cursor:pointer;
}
.ct-calendar{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:5px}
.ct-cal-week{display:grid;place-items:center;min-height:22px;color:var(--ct-muted);font-size:11px;font-weight:650}
.ct-day{
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;
  min-width:0;min-height:56px;padding:6px 2px;border:1px solid var(--ct-line);border-radius:12px;
  background:#f8f8fd;color:var(--ct-ink);text-align:center;cursor:pointer;
}
.ct-day time{font-size:13px;font-weight:650;line-height:1.2}
.ct-day small{min-height:11px;color:var(--ct-muted);font-size:9px;line-height:1.2}
.ct-day.is-today{border-color:var(--ct-brand);background:var(--ct-surface)}
.ct-day.is-plan{background:var(--ct-brand-soft);border-color:#e0d2ff;color:var(--ct-brand-dark)}
.ct-day.is-plan small{color:var(--ct-brand-dark)}
.ct-day.is-record{background:var(--ct-record);border-color:#cdbcff;color:var(--ct-record-ink)}
.ct-day.is-record small{color:var(--ct-record-ink)}
.ct-day:active{transform:scale(.97)}
.ct-legend{display:flex;flex-wrap:wrap;gap:14px;margin-top:12px;color:var(--ct-muted);font-size:10.5px}
.ct-legend span{display:flex;align-items:center;gap:5px}
.ct-legend i{display:inline-block;width:9px;height:9px;border-radius:3px}
.ct-legend .plan{background:var(--ct-brand-soft);border:1px solid #e0d2ff}
.ct-legend .record{background:var(--ct-record);border:1px solid #cdbcff}
.ct-legend .today{background:#fff;border:1px solid var(--ct-brand)}
.ct-date-actions{display:flex;gap:8px;margin-top:12px}
.ct-date-actions button{
  flex:1;min-height:44px;border:1px solid var(--ct-line);border-radius:12px;
  background:var(--ct-soft);color:var(--ct-brand-dark);font-size:11.5px;font-weight:650;cursor:pointer;
}

/* ---------- Saved custom tasks ---------- */
.ct-saved-list{display:grid;gap:8px}
.ct-saved-item{display:flex;align-items:center;gap:9px;padding:10px 12px;border:1px solid var(--ct-line);border-radius:12px;background:var(--ct-soft)}
.ct-saved-copy{flex:1;min-width:0}
.ct-saved-copy strong{display:block;font-size:12.5px;font-weight:700;line-height:1.4;overflow-wrap:anywhere}
.ct-saved-copy small{display:block;margin-top:2px;color:var(--ct-muted);font-size:10.5px;line-height:1.4}
.ct-saved-del{flex-shrink:0;width:44px;height:44px;border:0;border-radius:12px;background:transparent;color:#8b73d8;font-size:18px;cursor:pointer}
.ct-saved-del.is-locked{color:#a7a1b8;cursor:default}

/* ---------- Success state ---------- */
.ct-success{padding:16px;border:1px solid #ded3ff;border-radius:18px;background:var(--ct-brand-soft)}
.ct-success strong{display:block;color:var(--ct-brand-dark);font-size:14px;font-weight:750;line-height:1.5}
.ct-success .ct-success-parts{margin:6px 0 0;color:var(--ct-brand-dark);font-size:11.5px;font-weight:650;line-height:1.6}
.ct-success p{margin:6px 0 13px;color:#5a5483;font-size:11.5px;line-height:1.7}
.ct-success-actions{display:flex;gap:8px;flex-wrap:wrap}
.ct-success-actions button{
  flex:1;min-width:110px;min-height:44px;padding:8px 10px;border-radius:12px;
  border:1px solid #d9c9ff;background:#fff;color:var(--ct-brand-dark);font-size:11.5px;font-weight:700;cursor:pointer;
}
.ct-success-actions button.primary{border-color:var(--ct-brand);background:var(--ct-brand);color:#fff}

/* ---------- Sticky save bar ---------- */
.ct-savebar{
  position:fixed;z-index:60;left:50%;bottom:0;transform:translateX(-50%);
  width:min(100%,500px);padding:12px 16px calc(10px + env(safe-area-inset-bottom));
  border-top:1px solid var(--ct-line);border-radius:16px 16px 0 0;background:var(--ct-canvas);
}
.ct-save{
  width:100%;min-height:50px;border:0;border-radius:14px;background:var(--ct-brand);color:#fff;
  font-size:15px;font-weight:750;cursor:pointer;
  display:flex;align-items:center;justify-content:center;gap:8px;
  transition:transform .12s ease,opacity .18s ease;
}
.ct-save i{font-size:18px}
.ct-save:active{transform:scale(.98)}
.ct-save:focus-visible{outline:3px solid #b9a7ff;outline-offset:3px}
.ct-save:disabled{opacity:.5;cursor:default}
.ct-savebar p{margin:8px 0 0;color:var(--ct-muted);font-size:10.5px;text-align:center;line-height:1.5}

/* ---------- Option sheets ---------- */
.ct-sheet-backdrop{
  position:fixed;inset:0;z-index:150;display:flex;align-items:flex-end;justify-content:center;
  background:rgba(28,22,66,.32);
}
.ct-sheet{
  width:min(100%,500px);max-height:72vh;overflow:auto;padding:18px 18px max(20px,env(safe-area-inset-bottom));
  border-radius:24px 24px 0 0;background:var(--ct-surface);box-shadow:0 -12px 40px rgba(40,30,90,.16);
}
.ct-sheet-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:8px}
.ct-sheet-head h2{margin:0;font-size:16px;font-weight:750}
.ct-sheet-close{width:44px;height:44px;border:0;border-radius:12px;background:var(--ct-soft);color:var(--ct-brand);font-size:20px;cursor:pointer}
.ct-sheet-sub{margin:0 0 13px;color:var(--ct-muted);font-size:11.5px;line-height:1.6}
.ct-segment{display:flex;gap:8px;margin-bottom:14px}
.ct-segment button{
  flex:1;min-height:46px;border:1px solid var(--ct-line);border-radius:12px;
  background:var(--ct-soft);color:var(--ct-ink);font-size:12.5px;font-weight:650;cursor:pointer;
}
.ct-segment button.is-active{border-color:#d6c4ff;background:var(--ct-brand-soft);color:var(--ct-brand-dark);font-weight:750}
.ct-option-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:8px}
.ct-option{
  min-height:46px;border:1px solid var(--ct-line);border-radius:12px;background:var(--ct-surface);
  color:var(--ct-ink);font-size:12.5px;font-weight:650;cursor:pointer;
}
.ct-option.is-active{border-color:var(--ct-brand);background:var(--ct-brand);color:#fff}
.ct-sheet-note{margin:14px 0 0;color:var(--ct-muted);font-size:10.5px;line-height:1.6}

/* ---------- Responsive ---------- */
@media(max-width:420px){
  #custom-task-module{padding-left:12px;padding-right:12px}
  .ct-section{padding:14px;border-radius:18px}
  .ct-exercise-head{grid-template-columns:76px minmax(0,1fr) 40px;gap:8px}
  .ct-ex-remove{width:40px;height:40px}
  .ct-ex-name{font-size:13px}
  .ct-parts{gap:6px}
  .ct-part{font-size:11.5px;padding:5px 8px}
  .ct-part.is-wide{flex-basis:calc(50% - 3px)}
  .ct-params{gap:6px}
  .ct-param-btn{min-height:52px}
  .ct-param-btn strong{font-size:11px}
  .ct-calendar{gap:4px}
  .ct-day{min-height:52px;border-radius:11px}
  .ct-day time{font-size:12px}
  .ct-day small{font-size:8.5px}
  .ct-savebar{padding-left:12px;padding-right:12px}
}
@media(max-width:370px){
  #custom-task-module{padding-left:10px;padding-right:10px}
  .ct-top h1{font-size:21px}
  .ct-exercise-head{grid-template-columns:68px minmax(0,1fr) 36px;gap:7px}
  .ct-ex-remove{width:36px;height:36px}
  .ct-ex-name{font-size:12.5px}
  .ct-ex-meta{font-size:10px}
  .ct-calendar{gap:3px}
  .ct-day{min-height:48px;border-radius:10px;padding:5px 1px}
  .ct-day time{font-size:11px}
  .ct-day small{font-size:8px}
  .ct-params{gap:5px}
  .ct-param-btn strong{font-size:10.5px}
  .ct-param-btn small{font-size:9.5px}
  .ct-savebar{padding-left:10px;padding-right:10px}
}
@media(prefers-reduced-motion:reduce){
  .ct-toast,.ct-param-btn,.ct-day,.ct-part{transition:none!important}
  .ct-param-btn:active,.ct-day:active,.ct-part:active{transform:none}
}
@media(forced-colors:active){
  #custom-task-module .ct-section,#custom-task-module .ct-exercise,#custom-task-module .ct-ex-media,
  #custom-task-module .ct-day,#custom-task-module .ct-param-btn,#custom-task-module .ct-option,
  #custom-task-module .ct-part,#custom-task-module .ct-add{border:1px solid CanvasText}
  #custom-task-module .ct-day.is-plan,#custom-task-module .ct-day.is-record{forced-color-adjust:none}
  #custom-task-module .ct-part.is-on{background:Highlight;color:HighlightText}
}
