:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #657084;
  --line: #d8dee8;
  --paper: #f7f8fb;
  --white: #ffffff;
  --green: #2f9d55;
  --blue: #176fb9;
  --red: #d84444;
  --shadow: 0 18px 46px rgba(24, 32, 51, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.app {
  display: grid;
  grid-template-columns: minmax(320px, 520px) minmax(360px, 1fr);
  gap: 20px;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0;
}

.timer-panel,
.routine-panel {
  min-width: 0;
}

.timer-panel {
  position: sticky;
  top: 18px;
  align-self: start;
  display: grid;
  gap: 18px;
  min-height: calc(100vh - 36px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.topbar,
.settings,
.badge-row,
.controls,
.secondary-controls,
.field {
  display: flex;
  align-items: center;
}

.topbar,
.settings,
.badge-row {
  justify-content: space-between;
  gap: 12px;
}

.kicker,
.settings p,
.step-meta,
.exercise-cue,
.step-cue {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  margin-top: 4px;
  font-size: clamp(1.7rem, 4vw, 2.6rem);
  line-height: 1.04;
}

.exercise-cue {
  max-width: 42rem;
  margin-top: 8px;
  font-size: 0.95rem;
  line-height: 1.35;
}

h2 {
  font-size: 1rem;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 800;
}

.visual-wrap {
  display: grid;
  gap: 10px;
}

.exercise-visual {
  position: relative;
  overflow: hidden;
  min-height: 320px;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-image: var(--routine-image, url("./assets/rutina-20-min.jpg"));
  background-repeat: no-repeat;
  background-size: var(--zoom, 330%);
  background-position: var(--pos-x, 50%) var(--pos-y, 50%);
  box-shadow: inset 0 0 0 999px rgba(255, 255, 255, 0.02);
}

.exercise-visual.change-visual {
  border-color: #176fb9;
  box-shadow:
    inset 0 0 0 999px rgba(23, 111, 185, 0.18),
    0 0 0 4px rgba(23, 111, 185, 0.18),
    0 18px 38px rgba(37, 99, 235, 0.24);
}

.exercise-visual.change-visual::after {
  content: "CANVI EXERCICI";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(255, 255, 255, 0.36);
  color: rgba(23, 32, 51, 0.62);
  font-size: clamp(2.1rem, 8vw, 4.8rem);
  font-weight: 900;
  line-height: 0.95;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0;
  text-shadow: 0 2px 14px rgba(255, 255, 255, 0.78);
}

.exercise-visual.round-rest-visual {
  border-color: #f97316;
  background-image: url("./assets/rest-between-rounds.svg");
  background-size: cover;
  background-position: center;
  box-shadow:
    inset 0 0 0 999px rgba(255, 255, 255, 0),
    0 0 0 4px rgba(249, 115, 22, 0.18),
    0 18px 38px rgba(15, 23, 42, 0.22);
}

.video-visual {
  display: block;
  background: #0f172a;
}

.video-visual iframe {
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
  border: 0;
}

.badge-row span {
  padding: 7px 10px;
  border-radius: 999px;
  background: #eef3f8;
  color: #354056;
  font-size: 0.86rem;
  font-weight: 700;
}

.time-readout {
  font-variant-numeric: tabular-nums;
  font-size: clamp(4.4rem, 15vw, 8rem);
  line-height: 0.9;
  text-align: center;
  font-weight: 850;
}

.timer-panel.warning .time-readout {
  color: var(--red);
}

.timer-panel.transitioning .time-readout {
  color: var(--blue);
}

.progress-track {
  overflow: hidden;
  height: 12px;
  border-radius: 999px;
  background: #e7ebf1;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 160ms linear, background-color 180ms ease;
}

.timer-panel.warning .progress-fill {
  background: var(--red);
}

.timer-panel.transitioning .progress-fill {
  background: var(--blue);
}

.controls {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  gap: 10px;
}

.controls button,
.secondary-controls button,
.settings button {
  min-height: 46px;
  border-radius: 8px;
  font-weight: 750;
}

.controls button {
  font-size: 1.05rem;
}

.controls .primary {
  border-color: var(--blue);
  background: var(--blue);
  color: var(--white);
  font-size: 1.12rem;
}

.secondary-controls {
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
}

.secondary-controls button,
.settings button {
  padding: 0 14px;
}

.field,
.duration-field {
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
}

input {
  width: 66px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  color: var(--ink);
}

select {
  height: 38px;
  min-width: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  color: var(--ink);
  background: var(--white);
}

.routine-panel {
  display: grid;
  gap: 16px;
}

.routine-picker {
  display: grid;
  grid-column: 1 / -1;
  gap: 10px;
}

.video-picker {
  margin-top: -6px;
}

.routine-menu {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.routine-card {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  min-width: 0;
  padding: 8px;
  border-radius: 8px;
  text-align: left;
}

.routine-card.active {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(23, 111, 185, 0.2);
}

.routine-card-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border-radius: 6px;
  background: #eef3f8;
}

.routine-card-title,
.routine-card-summary {
  display: block;
  min-width: 0;
}

.routine-card-title {
  font-weight: 850;
}

.routine-card-summary {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

.poster-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.poster-card img {
  display: block;
  width: 100%;
  height: auto;
}

.settings {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.block-controls {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.block-list {
  display: grid;
  gap: 8px;
}

.block-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px 84px;
  gap: 10px;
  align-items: center;
}

.block-item > span {
  min-width: 0;
}

.block-title,
.block-meta {
  display: block;
  min-width: 0;
}

.block-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.block-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.84rem;
}

.mini-field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.block-repeat-input,
.block-rest-input {
  width: 100%;
  text-align: center;
}

.step-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.step-group {
  margin-top: 8px;
}

.step-group-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 8px;
  text-align: left;
}

.step-group.expanded .step-group-button {
  border-color: var(--blue);
  background: #eef6ff;
}

.step-group-main,
.step-group-title,
.step-group-meta {
  display: block;
  min-width: 0;
}

.step-group-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 850;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.step-group-meta,
.step-group-state {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.step-group-state::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
}

.step-group.expanded .step-group-state::before {
  transform: rotate(90deg);
}

.step-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 8px;
  align-items: stretch;
}

.step-select {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 8px;
  text-align: left;
}

.step-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.step-cue {
  display: block;
  margin-top: 2px;
  line-height: 1.28;
}

.step-item.active .step-select {
  border-color: var(--blue);
  box-shadow: inset 4px 0 0 var(--blue);
}

.step-item.done .step-select {
  color: var(--muted);
  background: #f1f5f4;
}

.duration-field {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.duration-field input {
  width: 54px;
  border: 0;
  text-align: right;
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    width: min(100% - 20px, 620px);
    padding: 10px 0 18px;
  }

  .timer-panel {
    position: static;
    min-height: auto;
    padding: 16px;
  }

  .exercise-visual {
    min-height: 250px;
  }

  .poster-card {
    order: 3;
  }

  .routine-menu {
    grid-template-columns: 1fr;
  }

  .routine-card {
    grid-template-columns: 92px 1fr;
    grid-template-rows: auto;
    align-items: center;
  }
}

@media (max-width: 420px) {
  .controls {
    grid-template-columns: 54px 1fr 54px;
  }

  .step-item {
    grid-template-columns: 1fr 78px;
  }

  .step-title {
    white-space: normal;
  }

  .block-item {
    grid-template-columns: minmax(0, 1fr) 58px 66px;
    gap: 6px;
  }

  .mini-field {
    font-size: 0.7rem;
  }
}
