/* ══════════════════════════════════════════════════════════════════════
   TubeShuffle — CACO timer
   Colour here codes ONE thing: the intensity of the step.
     coral = run (hi) · green = walk (lo) · violet = warm-up / cool-down
   Amber and blue already mean "queue" and "list" in this app, so neither
   is used for a step.
   ══════════════════════════════════════════════════════════════════════ */
:root {
  --caco-hi:   #ff5d4d;
  --caco-lo:   #33c98a;
  --caco-edge: #b48cff;
  --caco-done: #ffffff;
}
[data-kind="hi"]   { --caco-c: var(--caco-hi); }
[data-kind="lo"]   { --caco-c: var(--caco-lo); }
[data-kind="warm"],
[data-kind="cool"] { --caco-c: var(--caco-edge); }
[data-kind="done"] { --caco-c: var(--caco-done); }

/* ── Bottom bar ─────────────────────────────────────────────────────── */
/* Above the gesture layer (z 10000) so it shows while the screen is locked;
   in that mode it lets every touch fall through to the layer underneath. */
.caco-hud {
  position: fixed;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10001;
  width: min(940px, calc(100vw - 20px));
  box-sizing: border-box;
  padding: 0 14px 10px;
  border-radius: 16px;
  background: #0a0c11;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .12);
  border-top: 0;
  box-shadow: 0 18px 44px -18px rgba(0, 0, 0, .9);
  overflow: hidden;
  font-family: inherit;
}
.caco-hud[hidden] { display: none; }
.caco-hud *, .caco-hud *::before, .caco-hud *::after { box-sizing: border-box; }
.caco-hud :where(p, strong, span, div) { margin: 0; padding: 0; border: 0; hyphens: manual; }

/* Thick colour rail on top: readable from arm's length while moving */
.caco-hud::before {
  content: '';
  display: block;
  height: 6px;
  margin: 0 -14px;
  background: var(--caco-c);
  transition: background-color .25s;
}

/* The whole workout, every block at its real proportion */
.caco-map {
  position: relative;
  display: flex;
  gap: 2px;
  height: 8px;
  margin: 9px 0 8px;
}
.caco-blk {
  flex: 1 1 0;
  min-width: 2px;
  border-radius: 2px;
  background: var(--caco-c);
  opacity: .42;
}
.caco-blk.is-past { opacity: .14; }
.caco-blk.is-now  { opacity: 1; }
.caco-head {
  position: absolute;
  top: -3px; bottom: -3px;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(8, 10, 14, .9);
  pointer-events: none;
}

.caco-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
}
.caco-now { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.caco-tag, .caco-meta, .caco-next-label {
  font-family: var(--ft-mono, ui-monospace, monospace);
  font-size: .66rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .62);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.caco-step {
  font-size: clamp(1.35rem, 4.4vw, 2rem);
  font-weight: 750;
  letter-spacing: -.02em;
  line-height: 1.05;
  font-style: normal;
  color: var(--caco-c);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.caco-clock {
  font-family: var(--ft-mono, ui-monospace, monospace);
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.3rem, 9vw, 3.6rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.03em;
  color: #fff;
  text-align: center;
}
.caco-clock.is-ending { color: var(--caco-c); animation: caco-tick 1s steps(1) infinite; }
@keyframes caco-tick { 50% { opacity: .45; } }

.caco-next { min-width: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.caco-next[hidden] { display: none; }
.caco-next-name {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .28rem .6rem;
  border-radius: 999px;
  border: 1px solid var(--caco-c);
  color: #fff;
  font-size: .92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: color-mix(in srgb, var(--caco-c) 16%, transparent);
}
.caco-next-name::before {
  content: '';
  flex: 0 0 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--caco-c);
}

.caco-ctl { display: flex; gap: 4px; }
.caco-hud .caco-ctl button {
  all: unset;
  box-sizing: border-box;
  width: 42px; height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .16);
  cursor: pointer;
}
.caco-hud .caco-ctl button:hover { background: rgba(255, 255, 255, .16); }
.caco-hud .caco-ctl button:focus-visible { outline: 2px solid var(--caco-c); outline-offset: 2px; }
.caco-hud .caco-ctl svg { width: 18px; height: 18px; }
.caco-hud .caco-ctl .caco-ctl-main { width: 48px; height: 48px; background: var(--caco-c); color: #0b0d12; border-color: transparent; }
/* Same specificity as the `all: unset` rule above or it would win */
.caco-hud .caco-ctl button[data-when="done"] { display: none; }
.caco-hud[data-state="done"] .caco-ctl button[data-when="run"] { display: none; }
.caco-hud[data-state="done"] .caco-ctl button[data-when="done"] { display: grid; }

.caco-bar {
  height: 4px;
  margin-top: 10px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
}
.caco-bar span {
  display: block;
  height: 100%;
  background: var(--caco-c);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform .2s linear;
}
.caco-meta { margin-top: 6px; display: flex; justify-content: space-between; gap: 1rem; }
.caco-paused { display: none; color: #fff; }
.caco-hud[data-state="paused"] .caco-paused { display: inline; }
.caco-hud[data-state="paused"] .caco-clock { opacity: .55; }

/* The change itself: the bar lights up in the new colour */
.caco-hud.is-change { animation: caco-change .9s ease-out; }
.caco-hud.is-change .caco-step { animation: caco-pop .5s cubic-bezier(.2, .9, .3, 1.3); }
@keyframes caco-change {
  0%   { background: color-mix(in srgb, var(--caco-c) 55%, #0a0c11); }
  100% { background: #0a0c11; }
}
@keyframes caco-pop { from { transform: scale(.82); opacity: .3; } to { transform: none; opacity: 1; } }

/* …and so does the edge of the whole screen, for whoever is not looking at
   the bar but at the video */
.caco-flash {
  position: fixed;
  inset: 0;
  z-index: 10002;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 0 14px var(--caco-c), inset 0 0 90px 10px var(--caco-c);
}
.caco-flash.is-on { animation: caco-flash 1.1s ease-out; }
@keyframes caco-flash { 0% { opacity: .95; } 35% { opacity: .7; } 100% { opacity: 0; } }

.caco-sr {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ── Living with the rest of the page ───────────────────────────────── */
body.caco-on { padding-bottom: calc(var(--caco-h, 140px) + 16px); }
body.caco-on .ts-app[data-layout="foco"] .ts-stage-col,
body.caco-on .ts-app[data-layout="foco"] .ts-decks { bottom: calc(var(--caco-h, 140px) + 12px); }
body.caco-on .ts-gesture-hint { bottom: calc(var(--caco-h, 140px) + 24px); }
/* Locked: a display, not a control panel — touches go to the gesture layer */
body.ts-gesture-on .caco-hud { pointer-events: none; }
body.ts-gesture-on .caco-ctl { display: none; }
body.ts-gesture-on .caco-row { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }

@media (max-width: 640px) {
  .caco-hud { width: 100vw; bottom: 0; border-radius: 16px 16px 0 0; border-left: 0; border-right: 0;
              padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .caco-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "now clock" "next next" "ctl ctl";
    gap: 8px 12px;
  }
  .caco-now   { grid-area: now; }
  .caco-clock { grid-area: clock; text-align: right; }
  .caco-next  { grid-area: next; flex-direction: row; align-items: center; justify-content: space-between; }
  .caco-ctl   { grid-area: ctl; justify-content: center; gap: 10px; }
  body.ts-gesture-on .caco-row { grid-template-columns: minmax(0, 1fr) auto; }
}

/* ── Header button ─────────────────────────────────────────────────── */
.ts-lockbtn#caco-btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--caco-hi) 18%, transparent);
  color: var(--caco-hi);
  box-shadow: inset 0 0 0 1px var(--caco-hi);
}

/* ── Setup dialog (reuses .ts-modal / .ts-modal-card) ──────────────── */
.caco-card { width: min(640px, 100%); max-height: 92vh; }
.caco-body { flex: 1 1 auto; overflow-y: auto; padding: .4rem .9rem 1rem; overscroll-behavior: contain; }
.caco-sec { padding: .8rem 0; border-top: 1px solid var(--ts-rule); }
.caco-sec:first-child { border-top: 0; }
.caco-sec-hd { display: flex; align-items: baseline; gap: .6rem; margin-bottom: .5rem; }
.caco-sec-hd .caco-hint { font-size: .74rem; color: var(--ts-dim); }
.caco-inline { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.caco-inline > .ts-label { min-width: 9.5rem; }

.caco-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.caco-chips + .caco-chips-hd { margin-top: .7rem; }
.caco-chips-hd { display: block; margin-bottom: .4rem; }
.caco-chip {
  display: inline-flex;
  align-items: stretch;
  border-radius: 999px;
  border: 1px solid var(--ts-rule);
  background: var(--ts-well);
  overflow: hidden;
}
.caco-chip:hover { border-color: var(--ts-ink); }
.ts-modal .caco-chip button {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  color: var(--ts-ink);
  font-size: .8rem;
  font-weight: 560;
}
.ts-modal .caco-chip .caco-chip-main { padding: .45rem .75rem; }
.ts-modal .caco-chip .caco-chip-x { padding: 0 .55rem 0 .2rem; color: var(--ts-dim); }
.ts-modal .caco-chip .caco-chip-x:hover { color: var(--danger); }
.caco-chip-x svg { width: 12px; height: 12px; }
.ts-modal .caco-chip :focus-visible { outline: 2px solid var(--ts-live); outline-offset: -2px; }
.caco-dots { display: inline-flex; gap: 3px; }
.caco-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--caco-c); }

.caco-time { display: inline-flex; align-items: center; gap: 3px; }
.ts-modal .caco-time .ts-input {
  width: 3.6rem;
  flex: 0 0 auto;
  text-align: center;
  font-family: var(--ft-mono);
  font-variant-numeric: tabular-nums;
  font-size: .95rem;
  padding: .45rem .3rem;
  margin: 0;
  -moz-appearance: textfield;
}
.caco-time .ts-input::-webkit-outer-spin-button,
.caco-time .ts-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.caco-time-sep { font-family: var(--ft-mono); color: var(--ts-dim); }
.caco-unit { font-size: .72rem; color: var(--ts-dim); }

.ts-modal ol.caco-steps { display: flex; flex-direction: column; gap: .4rem; margin: 0; padding: 0; list-style: none; }
.caco-steprow {
  display: grid;
  grid-template-columns: 1.4rem minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: .45rem;
  padding: .4rem .45rem .4rem .35rem;
  border-radius: 10px;
  border: 1px solid var(--ts-rule);
  border-left: 4px solid var(--caco-c);
  background: var(--ts-well);
}
.caco-stepnum { font-family: var(--ft-mono); font-size: .72rem; color: var(--ts-dim); text-align: center; }
.ts-modal .caco-stepname { width: 100%; margin: 0; font-size: .88rem; font-weight: 600; background: var(--ts-deck); }
.ts-modal .caco-kind {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .6rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 650;
  white-space: nowrap;
  color: var(--ts-ink);
  border: 1px solid var(--caco-c);
  background: color-mix(in srgb, var(--caco-c) 15%, transparent);
}
.ts-modal .caco-kind::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--caco-c); }
.ts-modal .caco-kind:focus-visible { outline: 2px solid var(--ts-live); outline-offset: 2px; }
.caco-steprow .ts-ico { width: 32px; height: 32px; }
.caco-steprow .ts-ico:disabled { opacity: .3; cursor: default; }
.caco-steprow .ts-ico svg { width: 15px; height: 15px; }
.caco-add { margin-top: .5rem; }

.caco-stepper { display: inline-flex; align-items: center; gap: 4px; }
.ts-modal .caco-stepper .ts-input { width: 4rem; text-align: center; font-family: var(--ft-mono); font-size: .95rem; margin: 0; }

.caco-opts { display: flex; flex-direction: column; gap: .55rem; }
.caco-check { display: flex; align-items: center; gap: .55rem; font-size: .84rem; color: var(--ts-ink); cursor: pointer; margin: 0; }
.caco-check[hidden] { display: none; }
.ts-modal .caco-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--caco-lo); flex: 0 0 auto; }
.caco-volume { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; font-size: .84rem; color: var(--ts-ink); }
.ts-modal .caco-volume input[type="range"] { flex: 1 1 140px; margin: 0; accent-color: var(--caco-lo); padding: 0; border: 0; background: none; }

.caco-summary { padding: .8rem 0 0; border-top: 1px solid var(--ts-rule); }
.caco-summary .caco-map { margin: 0 0 .5rem; height: 12px; }
.caco-summary .caco-blk { opacity: .9; }
.caco-total { font-size: .84rem; color: var(--ts-ink); font-weight: 560; }
.caco-warn { font-size: .76rem; color: var(--danger); margin-top: .3rem; }
.caco-warn[hidden] { display: none; }

.caco-ft {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: .7rem .9rem;
  border-top: 1px solid var(--ts-rule);
  background: var(--ts-well);
}
.caco-ft .ts-input { flex: 1 1 180px; margin: 0; }
.caco-ft .caco-go { margin-left: auto; background: var(--caco-hi); border-color: var(--caco-hi); color: #fff; font-weight: 700; padding-inline: 1.1rem; }
.caco-ft .caco-go:hover { color: #fff; filter: brightness(1.08); border-color: var(--caco-hi); }
.caco-note { flex: 1 0 100%; font-size: .76rem; color: var(--ts-dim); }
.caco-note[data-type="ok"]  { color: var(--success); }
.caco-note[data-type="err"] { color: var(--danger); }
.caco-note[hidden] { display: none; }

@media (max-width: 640px) {
  .caco-steprow {
    grid-template-columns: 1.4rem minmax(0, 1fr) auto;
    grid-template-areas: "num name del" "num kind time";
  }
  .caco-stepnum { grid-area: num; }
  .ts-modal .caco-stepname { grid-area: name; }
  .ts-modal .caco-kind { grid-area: kind; justify-self: start; }
  .caco-steprow .caco-time { grid-area: time; justify-self: end; }
  .caco-steprow .ts-ico { grid-area: del; justify-self: end; }
  .caco-inline > .ts-label { min-width: 0; flex: 1 0 100%; }
  .caco-ft .ts-input, .caco-ft .ts-btn { flex: 1 1 100%; margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .caco-hud.is-change, .caco-hud.is-change .caco-step, .caco-clock.is-ending { animation: none; }
  .caco-flash.is-on { animation: caco-flash 1.1s steps(2); }
  .caco-bar span { transition: none; }
}

/* matcha paints `button:hover` with the accent at (0,1,1), above .ts-btn —
   the label (also accent on hover) vanished into it */
#caco-setup .ts-btn:is(:hover, :focus, :active) { background: var(--ts-well); }
#caco-setup .ts-btn.caco-go:is(:hover, :focus, :active) { background: var(--caco-hi); color: #fff; }
#caco-setup .ts-ico:is(:hover, :focus, :active) { background: var(--ts-well); }

/* Finished: the whole workout lights up once more */
.caco-hud[data-state="done"] .caco-blk { opacity: .9; }
