/* El valor que se anima en el anillo (sigue a --musi-value) */
@property --musi-notchprogress-v {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

.musi-notchprogress {
  /* Tokens: cambia estos valores para adaptar la barra */
  --musi-bg: #f4f1ea; /* fondo de la placa y pista del anillo */
  --musi-fg: #0d0d0d;
  --musi-accent: #ff4d1f; /* relleno y ficha */
  --musi-size: 1rem; /* todo el componente escala con este tamaño */
  --musi-width: 20em; /* ancho de la placa */
  --musi-ring: 6.5em; /* diámetro del anillo */
  --musi-thickness: 0.45em; /* grosor de la pista */
  --musi-chip: 0.55em; /* lado de la ficha */
  --musi-chip-radius: 0.2em; /* redondeo de la ficha: 0 = cuadrada */
  --musi-notch-gap: 0.2em; /* aire entre la ficha y la mordida */
  --musi-shadow: 0; /* intensidad de la sombra: 0 = sin sombra */
  --musi-duration: 0.7s;
  --musi-ease: cubic-bezier(0.65, 0, 0.35, 1);

  display: inline-block;
  color: inherit;
  /* Inter es opcional: si tu sitio no la carga, se usa la fuente del sistema */
  font: 300 var(--musi-size) / 1.3 "Inter", system-ui, sans-serif;
}

/* Fuera de la regla de los tokens, para que el build la deje como declaración */
.musi-notchprogress {
  --musi-notchprogress-v: var(--musi-value, 0);
  --musi-bite: calc(var(--musi-chip) + var(--musi-notch-gap));
  transition: --musi-notchprogress-v var(--musi-duration) var(--musi-ease);
}

/* ---------- En línea: la placa ---------- */
.musi-notchprogress__plate {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 0.7em 1em;
  box-sizing: border-box;
  width: min(100%, var(--musi-width));
  padding: calc(var(--musi-bite) + 0.55em) 1.1em 1em;
  color: var(--musi-fg);
}

.musi-notchprogress:not([data-musi-ready]) .musi-notchprogress__plate {
  border-radius: 0.85em;
  background: var(--musi-bg);
}

.musi-notchprogress__shape {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: var(--musi-bg);
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / calc(0.08 * var(--musi-shadow))))
    drop-shadow(0 8px 12px rgb(0 0 0 / calc(0.22 * var(--musi-shadow))));
}

/* Rótulo pequeño, en mayúsculas espaciadas */
.musi-notchprogress__label {
  font-size: 0.68em;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.65;
}

.musi-notchprogress__number {
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
}

.musi-notchprogress[data-musi-mode="indeterminate"] .musi-notchprogress__number {
  visibility: hidden;
}

/* La pista: el relleno lo estira el script hasta la ficha (--musi-fill) */
.musi-notchprogress__track {
  position: relative;
  grid-column: 1 / -1;
  height: var(--musi-thickness);
  overflow: hidden;
  border-radius: var(--musi-thickness);
  background: color-mix(in srgb, var(--musi-fg) 10%, transparent);
}

.musi-notchprogress__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--musi-fill, calc(var(--musi-notchprogress-v) * 100%));
  border-radius: inherit;
  background: var(--musi-accent);
}

.musi-notchprogress[data-musi-mode="indeterminate"] .musi-notchprogress__fill {
  opacity: 0.35;
}

/* La mordida con su ficha: la mueve el script (--musi-pos) */
.musi-notchprogress__slot {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0 var(--musi-notch-gap) var(--musi-notch-gap);
  translate: var(--musi-pos, 0px) 0;
  pointer-events: none;
}

.musi-notchprogress__chip {
  display: block;
  width: var(--musi-chip);
  height: var(--musi-chip);
  border-radius: var(--musi-chip-radius);
  background: var(--musi-accent);
}

.musi-notchprogress[data-musi-done] .musi-notchprogress__chip {
  animation: musi-notchprogress-pop 0.6s cubic-bezier(0.34, 1.6, 0.64, 1) var(--musi-duration);
}

@keyframes musi-notchprogress-pop {
  40% {
    scale: 1.5;
  }
}

/* ---------- Anillo ---------- */
.musi-notchprogress__ring {
  position: relative;
  display: none;
  place-items: center;
  width: var(--musi-ring);
  height: var(--musi-ring);
}

.musi-notchprogress[data-musi-shape="ring"] .musi-notchprogress__plate {
  display: none;
}

.musi-notchprogress[data-musi-shape="ring"] .musi-notchprogress__ring {
  display: grid;
}

.musi-notchprogress__ring > * {
  grid-area: 1 / 1;
}

.musi-notchprogress__ring svg {
  width: var(--musi-ring);
  height: var(--musi-ring);
  overflow: visible;
  rotate: -90deg;
}

/* El grosor no cambia con el tamaño del anillo */
.musi-notchprogress__ring circle {
  --musi-g: 0.035; /* el hueco a cada lado de la ficha, en fracción de vuelta */

  r: calc(50% - var(--musi-thickness) * 0.8);
  fill: none;
  stroke-width: calc(var(--musi-thickness) * 1.6);
  stroke-linecap: round;
}

/* La pista va desde después de la ficha hasta antes del comienzo */
.musi-notchprogress__rail {
  stroke: var(--musi-bg);
  stroke-dasharray: max(0, calc(1 - var(--musi-notchprogress-v) - var(--musi-g) * 2)) 1;
  stroke-dashoffset: calc((var(--musi-notchprogress-v) + var(--musi-g)) * -1);
}

.musi-notchprogress__arc {
  stroke: var(--musi-accent);
  stroke-dasharray: max(0, calc(var(--musi-notchprogress-v) - var(--musi-g))) 1;
}

/* La ficha da la vuelta con el valor, en la punta del arco */
.musi-notchprogress__orbit {
  width: var(--musi-ring);
  height: var(--musi-ring);
  rotate: calc(var(--musi-notchprogress-v) * 1turn);
}

.musi-notchprogress__dot {
  display: block;
  width: calc(var(--musi-thickness) * 1.9);
  height: calc(var(--musi-thickness) * 1.9);
  margin: calc(var(--musi-thickness) * 0.8 - var(--musi-thickness) * 0.95) auto 0;
  border-radius: var(--musi-chip-radius);
  background: var(--musi-accent);
  rotate: calc(var(--musi-notchprogress-v) * -1turn);
}

.musi-notchprogress__ring .musi-notchprogress__number {
  font-size: 1.15em;
  color: inherit;
}

/* Sin valor, el anillo gira con un arco fijo */
.musi-notchprogress[data-musi-mode="indeterminate"] .musi-notchprogress__ring svg,
.musi-notchprogress[data-musi-mode="indeterminate"] .musi-notchprogress__orbit {
  --musi-notchprogress-v: 0.3;
  animation: musi-notchprogress-spin calc(var(--musi-duration) * 2) linear infinite;
}

.musi-notchprogress[data-musi-mode="indeterminate"] .musi-notchprogress__ring svg {
  animation-name: musi-notchprogress-spin-svg;
}

@keyframes musi-notchprogress-spin {
  from {
    rotate: 0.3turn;
  }
  to {
    rotate: 1.3turn;
  }
}

@keyframes musi-notchprogress-spin-svg {
  from {
    rotate: -90deg;
  }
  to {
    rotate: 270deg;
  }
}

@media (prefers-reduced-motion: reduce) {
  .musi-notchprogress {
    transition: none;
  }
  .musi-notchprogress__chip,
  .musi-notchprogress__ring svg,
  .musi-notchprogress__orbit {
    animation-duration: 8s !important;
  }
}
