.muscle-tool-page {
  background:
    radial-gradient(circle at 28% 18%, rgba(103, 236, 255, 0.12), transparent 34%),
    radial-gradient(circle at 78% 12%, rgba(240, 185, 90, 0.1), transparent 30%),
    linear-gradient(180deg, #060809, #0a0f11 44%, #050708);
}

.tool-nav a {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 760;
  padding: 0 13px;
  text-decoration: none;
  white-space: nowrap;
}

.tool-nav a:hover {
  color: var(--ink);
}

.tool-nav a.is-active {
  background: linear-gradient(180deg, rgba(103, 236, 255, 0.2), rgba(103, 236, 255, 0.08));
  color: var(--cyan);
  box-shadow: inset 0 0 0 1px rgba(103, 236, 255, 0.48), 0 0 18px rgba(103, 236, 255, 0.16);
}

.muscle-shell {
  min-height: calc(100vh - 74px);
  padding: 18px;
}

.muscle-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 390px);
  gap: 14px;
  align-items: start;
  width: min(1480px, 100%);
  margin: 0 auto;
}

.viewer-panel,
.muscle-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    rgba(7, 11, 13, 0.86);
  box-shadow: var(--shadow);
}

.viewer-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: calc(100vh - 110px);
  overflow: hidden;
}

.viewer-topline,
.viewer-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
}

.viewer-topline {
  border-bottom: 1px solid var(--line);
}

.viewer-topline h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 2.7vw, 2.55rem);
}

.view-controls,
.zoom-control {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.tool-button,
.icon-button {
  min-height: 38px;
  border: 1px solid rgba(219, 231, 234, 0.18);
  border-radius: 8px;
  background: rgba(244, 247, 248, 0.08);
  color: var(--chrome);
  cursor: pointer;
  font-weight: 820;
  padding: 0 13px;
}

.tool-button:hover,
.icon-button:hover {
  border-color: rgba(103, 236, 255, 0.45);
  color: var(--ink);
}

.tool-button.is-active {
  border-color: rgba(103, 236, 255, 0.64);
  background: linear-gradient(180deg, rgba(103, 236, 255, 0.24), rgba(31, 208, 238, 0.12));
  color: var(--cyan);
  box-shadow: 0 0 24px rgba(103, 236, 255, 0.14);
}

.tool-button.subtle {
  color: var(--muted);
}

.icon-button {
  width: 38px;
  padding: 0;
}

.body-stage {
  position: relative;
  display: grid;
  height: clamp(465px, calc(100vh - 255px), 700px);
  min-height: 465px;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(103, 236, 255, 0.16), transparent 48%),
    rgba(4, 8, 10, 0.78);
  background-size: 64px 64px, 64px 64px, auto, auto;
  cursor: grab;
  perspective: 950px;
  touch-action: none;
}

.body-stage.is-dragging {
  cursor: grabbing;
}

.body-stage.is-dragging .body-model {
  transition: none;
}

.body-glow {
  position: absolute;
  width: min(56vw, 590px);
  aspect-ratio: 1;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(103, 236, 255, 0.17), transparent 64%);
  filter: blur(8px);
}

.body-model {
  --body-tilt: 0deg;
  --turn-light: 0;
  --turn-shade: 0;
  position: relative;
  z-index: 1;
  width: auto;
  height: min(calc(100% - 8px), 660px);
  max-width: min(76vw, 520px);
  min-width: 0;
  aspect-ratio: 2 / 3;
  transform: scale(var(--zoom)) rotateX(var(--body-tilt)) rotateY(var(--body-yaw));
  transform-origin: 50% 48%;
  transform-style: preserve-3d;
  transition: transform 640ms cubic-bezier(0.18, 0.84, 0.24, 1);
  will-change: transform;
}

.body-face {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  transform-style: preserve-3d;
}

.body-face-front {
  transform: translateZ(0.8px);
}

.body-face-back {
  pointer-events: none;
  transform: rotateY(180deg) translateZ(0.8px);
}

.body-face::before,
.body-face::after {
  position: absolute;
  z-index: 1;
  inset: 0;
  content: "";
  pointer-events: none;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
}

.body-face::before {
  background: linear-gradient(105deg, transparent 18%, rgba(255, 248, 225, 0.52) 44%, transparent 67%);
  mix-blend-mode: screen;
  opacity: var(--turn-light);
}

.body-face::after {
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0.1) 42%, rgba(0, 0, 0, 0.46));
  mix-blend-mode: multiply;
  opacity: var(--turn-shade);
}

.body-face-front::before,
.body-face-front::after {
  -webkit-mask-image: url("assets/muscle-explorer/anatomy-front.png");
  mask-image: url("assets/muscle-explorer/anatomy-front.png");
}

.body-face-back::before,
.body-face-back::after {
  -webkit-mask-image: url("assets/muscle-explorer/anatomy-back.png");
  mask-image: url("assets/muscle-explorer/anatomy-back.png");
}

.muscle-shell[data-facing="back"] .body-face-front {
  pointer-events: none;
}

.muscle-shell[data-facing="back"] .body-face-back {
  pointer-events: auto;
}

.body-asset {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter:
    drop-shadow(0 26px 34px rgba(0, 0, 0, 0.46))
    drop-shadow(0 0 20px rgba(103, 236, 255, 0.12));
  pointer-events: none;
  user-select: none;
}

.hotspot-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  backface-visibility: hidden;
  opacity: 1;
  transform: translateZ(0.3px);
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-mode: alpha;
  mask-mode: alpha;
}

.body-face-front .hotspot-layer {
  -webkit-mask-image: url("assets/muscle-explorer/anatomy-front.png");
  mask-image: url("assets/muscle-explorer/anatomy-front.png");
}

.body-face-back .hotspot-layer {
  -webkit-mask-image: url("assets/muscle-explorer/anatomy-back.png");
  mask-image: url("assets/muscle-explorer/anatomy-back.png");
}

.muscle-shell[data-facing="back"] .body-face-front .hotspot-layer,
.muscle-shell[data-facing="front"] .body-face-back .hotspot-layer {
  opacity: 0;
}

.muscle-target {
  position: absolute;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  padding: 0;
  transform-origin: center;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease,
    opacity 160ms ease;
}

.muscle-target:hover,
.muscle-target:focus {
  border-color: rgba(188, 255, 214, 0.9);
  background: rgba(38, 226, 118, 0.18);
  box-shadow: 0 0 18px rgba(38, 226, 118, 0.34);
  outline: none;
}

.muscle-target.is-active {
  border-color: rgba(188, 255, 214, 0.98);
  background: rgba(38, 226, 118, 0.42);
  box-shadow:
    inset 0 0 22px rgba(215, 255, 228, 0.24),
    0 0 22px rgba(38, 226, 118, 0.58);
}

.front-trapezius { left: 39%; top: 12%; width: 22%; height: 7%; }
.front-deltoid-left { left: 26.6%; top: 16.8%; width: 10.8%; height: 8.4%; transform: rotate(-18deg); clip-path: polygon(14% 46%, 28% 16%, 60% 0, 92% 20%, 100% 58%, 72% 92%, 30% 100%, 0 76%); }
.front-deltoid-right { right: 26.6%; top: 16.8%; width: 10.8%; height: 8.4%; transform: rotate(18deg); clip-path: polygon(8% 20%, 40% 0, 72% 16%, 86% 46%, 100% 76%, 70% 100%, 28% 92%, 0 58%); }
.front-pec-left { left: 32%; top: 18%; width: 18%; height: 11%; transform: rotate(7deg); }
.front-pec-right { right: 32%; top: 18%; width: 18%; height: 11%; transform: rotate(-7deg); }
.front-biceps-left { left: 23.2%; top: 24.9%; width: 8%; height: 11.2%; transform: rotate(27deg); clip-path: polygon(42% 0, 74% 8%, 92% 34%, 82% 82%, 55% 100%, 26% 90%, 8% 56%, 20% 18%); }
.front-biceps-right { right: 23.2%; top: 24.9%; width: 8%; height: 11.2%; transform: rotate(-27deg); clip-path: polygon(26% 8%, 58% 0, 80% 18%, 92% 56%, 74% 90%, 45% 100%, 18% 82%, 8% 34%); }
.front-forearm-left { left: 12.5%; top: 33.1%; width: 10.3%; height: 13.3%; transform: rotate(37deg); clip-path: polygon(30% 0, 68% 5%, 90% 32%, 70% 93%, 36% 100%, 8% 54%); }
.front-forearm-right { right: 12.5%; top: 33.1%; width: 10.3%; height: 13.3%; transform: rotate(-37deg); clip-path: polygon(32% 5%, 70% 0, 92% 54%, 64% 100%, 30% 93%, 10% 32%); }
.front-abs { left: 44.8%; top: 31.5%; width: 10.4%; height: 15.7%; clip-path: polygon(26% 0, 74% 0, 90% 24%, 86% 86%, 62% 100%, 38% 100%, 14% 86%, 10% 24%); }
.front-oblique-left { left: 36.4%; top: 33%; width: 4.9%; height: 12.6%; transform: rotate(-9deg); clip-path: polygon(42% 0, 94% 12%, 78% 100%, 18% 88%, 0 34%); }
.front-oblique-right { right: 36.4%; top: 33%; width: 4.9%; height: 12.6%; transform: rotate(9deg); clip-path: polygon(6% 12%, 58% 0, 100% 34%, 82% 88%, 22% 100%); }
.front-quad-left { left: 33.8%; top: 48.4%; width: 14%; height: 14.7%; transform: rotate(4deg); clip-path: polygon(22% 0, 78% 0, 100% 38%, 82% 100%, 24% 100%, 0 38%); }
.front-quad-right { right: 33.8%; top: 48.4%; width: 14%; height: 14.7%; transform: rotate(-4deg); clip-path: polygon(22% 0, 78% 0, 100% 38%, 76% 100%, 18% 100%, 0 38%); }
.front-tibialis-left { left: 37%; top: 74%; width: 10%; height: 15%; transform: rotate(4deg); }
.front-tibialis-right { right: 37%; top: 74%; width: 10%; height: 15%; transform: rotate(-4deg); }

.back-trapezius { left: 33%; top: 6%; width: 34%; height: 19%; }
.back-deltoid-left { left: 22%; top: 14.5%; width: 14%; height: 9.8%; transform: rotate(-14deg); }
.back-deltoid-right { right: 22%; top: 14.5%; width: 14%; height: 9.8%; transform: rotate(14deg); }
.back-lat-left { left: 34%; top: 25.2%; width: 8.7%; height: 15.2%; transform: rotate(-6deg); clip-path: polygon(8% 10%, 82% 0, 100% 26%, 78% 76%, 42% 100%, 8% 70%, 0 34%); }
.back-lat-right { right: 34%; top: 25.2%; width: 8.7%; height: 15.2%; transform: rotate(6deg); clip-path: polygon(18% 0, 92% 10%, 100% 34%, 92% 70%, 58% 100%, 22% 76%, 0 26%); }
.back-erector { left: 44%; top: 10%; width: 12%; height: 38%; }
.back-triceps-left { left: 22.5%; top: 22.8%; width: 8%; height: 11.5%; transform: rotate(17deg); clip-path: polygon(38% 0, 74% 10%, 100% 42%, 82% 88%, 48% 100%, 10% 76%, 0 30%); }
.back-triceps-right { right: 22.5%; top: 22.8%; width: 8%; height: 11.5%; transform: rotate(-17deg); clip-path: polygon(26% 10%, 62% 0, 100% 30%, 90% 76%, 52% 100%, 18% 88%, 0 42%); }
.back-forearm-left { left: 12.5%; top: 36.8%; width: 12.3%; height: 14%; transform: rotate(30deg); clip-path: polygon(30% 0, 70% 6%, 92% 38%, 70% 96%, 34% 100%, 8% 48%); }
.back-forearm-right { right: 12.5%; top: 36.8%; width: 12.3%; height: 14%; transform: rotate(-30deg); clip-path: polygon(30% 6%, 70% 0, 92% 48%, 66% 100%, 30% 96%, 8% 38%); }
.back-glute-left { left: 32%; top: 39.4%; width: 17.4%; height: 12.4%; transform: rotate(-4deg); clip-path: polygon(18% 18%, 58% 0, 100% 30%, 88% 78%, 54% 100%, 12% 88%, 0 48%); }
.back-glute-right { right: 32%; top: 39.4%; width: 17.4%; height: 12.4%; transform: rotate(4deg); clip-path: polygon(42% 0, 82% 18%, 100% 48%, 88% 88%, 46% 100%, 12% 78%, 0 30%); }
.back-ham-left { left: 34.4%; top: 54.6%; width: 12.5%; height: 17%; transform: rotate(2deg); clip-path: polygon(18% 0, 78% 0, 100% 38%, 82% 100%, 22% 100%, 0 38%); }
.back-ham-right { right: 34.4%; top: 54.6%; width: 12.5%; height: 17%; transform: rotate(-2deg); clip-path: polygon(22% 0, 82% 0, 100% 38%, 78% 100%, 18% 100%, 0 38%); }
.back-calf-left { left: 37.7%; top: 70%; width: 7.6%; height: 11.9%; transform: rotate(2deg); clip-path: polygon(34% 0, 70% 4%, 100% 40%, 78% 100%, 28% 94%, 0 38%); }
.back-calf-right { right: 37.7%; top: 70%; width: 7.6%; height: 11.9%; transform: rotate(-2deg); clip-path: polygon(30% 4%, 66% 0, 100% 38%, 72% 94%, 22% 100%, 0 40%); }

.anatomy {
  display: none;
}

.anatomy-back {
  transform: rotateY(180deg) translateZ(0.1px);
  pointer-events: none;
}

.muscle-shell[data-facing="back"] .anatomy-front {
  pointer-events: none;
}

.muscle-shell[data-facing="back"] .anatomy-back {
  pointer-events: auto;
}

.body-base,
.head-base {
  fill: rgba(129, 34, 30, 0.3);
  stroke: rgba(235, 209, 191, 0.28);
  stroke-width: 2;
}

.head-base {
  fill: rgba(219, 150, 112, 0.64);
}

.face-plane {
  fill: rgba(244, 197, 157, 0.72);
  stroke: rgba(255, 240, 220, 0.24);
  stroke-width: 1.2;
}

.hand-base {
  fill: rgba(230, 174, 128, 0.72);
  stroke: rgba(255, 241, 219, 0.38);
  stroke-width: 1.5;
}

.muscle-group {
  cursor: pointer;
  outline: none;
}

.muscle-surface {
  fill: rgba(176, 48, 38, 0.9);
  stroke: rgba(255, 217, 186, 0.28);
  stroke-width: 1.6;
  vector-effect: non-scaling-stroke;
  transition:
    fill 180ms ease,
    opacity 180ms ease,
    stroke 180ms ease,
    stroke-width 180ms ease,
    filter 180ms ease;
}

.anatomy-front .muscle-surface {
  fill: url("#front-muscle-red");
}

.anatomy-back .muscle-surface {
  fill: url("#back-muscle-red");
}

.region-shoulder .muscle-surface,
.region-chest .muscle-surface {
  filter: brightness(1.12) saturate(1.08);
}

.region-core .muscle-surface {
  filter: brightness(0.92) saturate(1.2);
}

.region-leg .muscle-surface {
  filter: brightness(1.06) saturate(1.08);
}

.muscle-fiber {
  fill: none;
  stroke: rgba(255, 198, 148, 0.52);
  stroke-linecap: round;
  stroke-width: 2.2;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  transition: stroke 180ms ease, opacity 180ms ease, stroke-width 180ms ease;
}

.fascia {
  fill: none;
  stroke: url("#front-fascia");
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 5.2;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  opacity: 0.9;
}

.anatomy-back .fascia {
  stroke: url("#back-fascia");
}

.muscle-group:hover .muscle-surface,
.muscle-group:focus .muscle-surface {
  stroke: rgba(244, 247, 248, 0.86);
  stroke-width: 2.5;
  filter: brightness(1.2) saturate(1.18);
}

.muscle-shell.is-selecting .muscle-group:not(.is-active) .muscle-surface {
  opacity: 0.68;
  filter: grayscale(0.08) brightness(0.88);
}

.muscle-shell.is-selecting .muscle-group:not(.is-active) .muscle-fiber {
  opacity: 0.42;
}

.muscle-group.is-active .muscle-surface {
  fill: rgba(38, 226, 118, 0.94);
  opacity: 1;
  stroke: rgba(255, 251, 224, 0.98);
  stroke-width: 3.2;
  filter: drop-shadow(0 0 14px rgba(38, 226, 118, 0.68)) brightness(1.13);
}

.muscle-group.is-active .muscle-fiber {
  opacity: 1;
  stroke: rgba(223, 255, 231, 0.9);
  stroke-width: 2.7;
}

.viewer-controls {
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
  min-height: 68px;
}

.zoom-control {
  min-width: min(360px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 8, 10, 0.5);
  padding: 8px;
}

.zoom-control label,
.viewport-status {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 760;
}

.zoom-control input {
  width: min(210px, 34vw);
  accent-color: var(--cyan);
}

.viewport-status {
  margin-left: auto;
}

.muscle-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 10px;
  align-content: start;
  max-height: calc(100vh - 110px);
  overflow: hidden;
  padding: 14px;
}

.selected-muscle,
.coach-card,
.exercise-card,
.muscle-directory {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 8, 10, 0.46);
  padding: 18px;
}

.selected-muscle h2 {
  margin-bottom: 12px;
  font-size: 2.15rem;
}

.selected-muscle p,
.coach-card p,
.exercise-card p {
  margin-bottom: 0;
}

.meta-row,
.exercise-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.meta-row span,
.exercise-chips span {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  border: 1px solid rgba(103, 236, 255, 0.25);
  border-radius: 999px;
  background: rgba(103, 236, 255, 0.08);
  color: var(--chrome);
  font-size: 0.86rem;
  font-weight: 760;
  padding: 0 11px;
}

.directory-heading {
  position: sticky;
  z-index: 1;
  top: -18px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin: -18px -18px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 8, 10, 0.96);
  padding: 18px 18px 8px;
}

.muscle-directory {
  min-height: 0;
  overflow: auto;
}

.directory-heading span {
  color: var(--subtle);
  font-size: 0.82rem;
  font-weight: 760;
}

.muscle-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.muscle-option {
  min-height: 46px;
  border: 1px solid rgba(219, 231, 234, 0.14);
  border-radius: 8px;
  background: rgba(244, 247, 248, 0.06);
  color: var(--muted);
  cursor: pointer;
  font-weight: 760;
  line-height: 1.2;
  overflow-wrap: anywhere;
  padding: 8px 10px;
  text-align: left;
  white-space: normal;
}

.muscle-option:hover {
  border-color: rgba(103, 236, 255, 0.34);
  color: var(--ink);
}

.muscle-option.is-active {
  border-color: rgba(38, 226, 118, 0.72);
  background: rgba(38, 226, 118, 0.14);
  color: var(--ink);
  box-shadow: 0 0 18px rgba(38, 226, 118, 0.12);
}

@media (max-width: 1120px) {
  .muscle-workbench {
    grid-template-columns: 1fr;
  }

  .viewer-panel {
    min-height: auto;
  }

  .body-model {
    max-width: min(62vw, 430px);
  }
}

@media (max-width: 680px) {
  .muscle-tool-page .prototype-bar {
    grid-template-columns: 1fr auto;
    gap: 10px;
  }

  .muscle-tool-page .profile-link {
    justify-self: end;
  }

  .muscle-tool-page .tool-nav {
    grid-column: 1 / -1;
    flex-direction: row;
  }

  .muscle-shell {
    padding: 12px;
  }

  .tool-nav a {
    flex: 1;
    justify-content: center;
  }

  .viewer-topline,
  .viewer-controls,
  .zoom-control {
    align-items: stretch;
    flex-direction: column;
  }

  .view-controls {
    width: 100%;
  }

  .view-controls .tool-button {
    flex: 1;
  }

  .view-controls,
  .zoom-control,
  .tool-button.subtle,
  .viewport-status {
    width: 100%;
  }

  .body-stage {
    height: 420px;
    min-height: 420px;
  }

  .body-model {
    max-width: min(76vw, 360px);
  }

  .zoom-control input {
    width: auto;
    min-width: 0;
    flex: 1;
  }

  .zoom-control {
    flex-direction: row;
    align-items: center;
  }

  .viewport-status {
    margin-left: 0;
  }

  .muscle-list {
    grid-template-columns: 1fr;
  }

  .muscle-panel {
    max-height: none;
    overflow: visible;
  }
}
