.freeplay-active #arena { touch-action: none; }
#freeplay-controls { position: absolute; inset: 0; z-index: 8; pointer-events: none; }
#freeplay-controls[hidden], #freeplay-controls [hidden] { display: none !important; }
#freeplay-controls button, #move-drawer { pointer-events: auto; }
#freeplay-controls button { min-height: 48px; min-width: 48px; font: inherit; }
.freeplay-toolbar { position: absolute; z-index: 1; left: 12px; bottom: 42px; right: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.freeplay-hint { position: absolute; top: 80px; left: 12px; max-width: min(80%, 430px); padding: 8px 12px; border-radius: 12px; background: #101936e8; color: white; }
#move-drawer { position: absolute; right: 8px; top: 132px; bottom: 114px; width: min(390px, calc(100% - 16px)); overflow-y: auto; overscroll-behavior: contain; padding: 16px; border-radius: 18px; background: #183c36fa; border: 3px solid #c1ae85; box-sizing: border-box; color: #fff; }
#move-drawer h2, #move-drawer h3 { margin: 0 0 12px; }
.freeplay-moves { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.freeplay-moves button { min-height: 76px; padding: 8px; display: flex; flex-direction: column; justify-content: center; gap: 5px; }
.freeplay-moves button span { font-size: 14px; }
.routine-editor { margin: 18px 0; padding-top: 12px; border-top: 2px dashed #ffffff70; }
.routine-steps { padding-left: 0; list-style: none; }
.routine-steps button { width: 100%; text-align: left; margin-bottom: 6px; }
.routine-actions { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-height: 500px) { #move-drawer { top: 112px; bottom: 104px; } .freeplay-hint { top: 58px; font-size: 13px; max-width: 40%; } }

.freeplay-toolbar button { min-height: 56px; padding: 10px 14px; }
@media (max-width: 500px) { .freeplay-toolbar { gap: 6px; } .freeplay-toolbar button { font-size: 13px; padding: 8px; } #bug { font-size: 10px; } #bug span { padding: 8px 5px; } }
/* Leave space for the shared Shop balance on narrow screens. */
@media (max-width: 500px) {
  .freeplay-hint { top: 62px; max-width: calc(100% - 166px); font-size: 13px; }
}

/* A small creation desk beside the live gymnast. No dragging is required. */
.routine-open { --routine-width: min(470px, 52%); }
.routine-open canvas#arena { width: calc(100% - var(--routine-width)); }
.routine-open .freeplay-toolbar, .routine-open #hud, .routine-open #call { display: none; }
.routine-open .freeplay-hint { top: 8px; max-width: calc(100% - var(--routine-width) - 24px); }
.editing-gym-routine .arcade-shop-link, .editing-gym-routine .arcade-reward-badge { display: none; }
#routine-editor { position: absolute; inset: 0 0 0 auto; width: var(--routine-width); margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; pointer-events: auto; background: #f6f4ff; color: #21183f; box-shadow: -8px 0 28px #0005; }
#routine-editor button { color: #251844; background: #fff; border: 2px solid #d6cee9; box-shadow: none; font-size: 14px; font-weight: 800; }
#routine-editor button:disabled { opacity: .45; cursor: default; }
#routine-editor button:focus-visible { outline: 4px solid #6840bd; outline-offset: -4px; }
#routine-editor .editor-header { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 8px; border-bottom: 2px solid #ddd3f2; }
#routine-editor .editor-header button { min-height: 56px; padding: 6px 8px; }
.editor-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 12px; min-height: 0; }
.editor-heading { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
#routine-editor h2 { font-size: 28px; }
#routine-editor h3 { font-size: 17px; margin: 8px 0; }
.routine-save { font-size: 11px; max-width: 130px; text-align: right; }
.editor-feedback { position: sticky; top: -12px; z-index: 2; background: #f6f4ff; margin: 0; padding: 10px 0; font-size: 14px; min-height: 40px; font-weight: 750; }
.routine-timeline { position: relative; display: flex; align-items: center; overflow-x: auto; padding: 8px 0 14px; min-height: 132px; border-radius: 14px; background: #e8e2f5; }
#routine-editor .routine-steps { display: flex; align-items: center; gap: 0; margin: 0; padding: 0; }
.routine-steps li { display: flex; align-items: center; flex-shrink: 0; }
#routine-editor .routine-insert { width: 48px; min-width: 48px; height: 64px; padding: 0; margin: 0; border: 0; background: transparent; font-size: 28px; }
#routine-editor .routine-step { position: relative; width: 132px; min-width: 132px; min-height: 116px; margin: 0; padding: 4px 6px 8px; border-radius: 16px; line-height: 1.1; text-align: center; }
.routine-step b { position: absolute; left: 7px; top: 6px; font-size: 18px; }
.routine-step canvas { width: 104px; height: 70px; display: block; margin: 0 auto; pointer-events: none; }
.routine-step span { display: block; }
#routine-editor .routine-step[aria-pressed="true"] { border: 4px solid #7953bc; background: #eee4ff; padding: 2px 4px 6px; }
#routine-editor [aria-current="step"] .routine-step { border: 4px solid #976b00; background: #fff0aa; }
#routine-editor .routine-add-end { flex-shrink: 0; width: 104px; min-height: 104px; margin: 0 12px; background: #fff9dc; border-style: dashed; font-size: 30px; }
.routine-add-end span { display: block; font-size: 14px; }
.step-actions { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; margin: 10px 0; }
#routine-editor .step-actions button { min-width: 0; min-height: 64px; padding: 4px 1px; font-size: 23px; }
.step-actions span { display: block; font-size: 11px; }
.picker-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0; }
#routine-editor .picker-heading button { padding: 4px 8px; min-height: 48px; }
.routine-catalog { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
#routine-editor .routine-catalog button { min-width: 0; min-height: 116px; padding: 4px; font-size: 13px; }
.routine-catalog canvas { display: block; width: 100%; max-width: 128px; height: 76px; object-fit: contain; margin: auto; pointer-events: none; }
#routine-editor [data-editor="more"] { width: 100%; margin-top: 8px; }
#routine-editor .routine-note { font-size: 12px; }
#routine-editor .editor-footer { display: flex; flex-shrink: 0; gap: 8px; padding: 8px 12px max(12px, env(safe-area-inset-bottom)); background: #e8e2f5; text-align: left; }
#routine-editor .editor-footer button { min-height: 64px; }
#routine-editor .editor-footer button:first-child, #routine-editor [data-editor="stop"] { flex: 1; background: #7541bd; color: #fff; font-size: 18px; }
.saved-routines { display: grid; gap: 8px; }
#routine-editor .saved-routines button, #routine-editor [data-editor="new"] { min-height: 64px; width: 100%; margin-bottom: 8px; font-size: 18px; }
@media (max-width: 700px) and (min-height: 501px) {
  .routine-open canvas#arena { width: 100%; height: 36%; }
  #routine-editor { top: 36%; width: 100%; }
  .routine-open .freeplay-hint { top: 4px; max-width: calc(100% - 24px); font-size: 13px; }
  #routine-editor h2 { font-size: 23px; }
  #routine-editor .editor-header button { font-size: 13px; }
}
@media (max-height: 500px) { .routine-open { --routine-width: 55%; } .editor-heading { display: none; } }
#routine-editor .saved-routines button { display: flex; align-items: center; gap: 12px; text-align: left; }
.routine-cover { display: flex; width: 126px; flex-shrink: 0; }
.routine-cover canvas { width: 42px; height: 48px; object-fit: contain; }
@media (max-height: 500px) {
  #routine-editor .editor-header { padding: 4px 8px; }
  #routine-editor .editor-header button { min-height: 44px; }
  .editor-body { padding: 8px 12px; }
  .editor-feedback { top: -8px; min-height: 32px; padding: 6px 0; }
  .routine-timeline { min-height: 112px; padding: 4px 0 8px; }
  #routine-editor .routine-step { min-height: 100px; }
  .routine-step canvas { height: 56px; width: 90px; }
  .step-actions { margin: 6px 0; }
}

.freeplay-apparatus { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; overflow-x: auto; pointer-events: auto; }
.freeplay-apparatus button { flex: 0 0 auto; min-height: 64px !important; padding: 10px 18px; border: 3px solid #c1ae85; }
.freeplay-apparatus button[aria-pressed="true"] { background: #f9e29a; color: #261744; outline: 3px solid #fff; outline-offset: -6px; }
.routine-open .freeplay-apparatus { display: none; }
@media (max-height: 500px), (max-width: 500px) { .freeplay-hint { top: 76px; } }
/* The apparatus tabs and move hint replace the competition broadcast labels. */
.freeplay-active #bug, .freeplay-active #call { display: none; }


/* Difficulty is readable in words and stars, in ascending order. */
.difficulty-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
#routine-editor .difficulty-choices button { min-width: 0; min-height: 96px; padding: 10px; }
.difficulty-choices strong, .difficulty-choices small { display: block; }
.difficulty-choices small { margin-top: 8px; font-weight: normal; }
.routine-rating { font-weight: 800; }

#routine-editor [data-editor="challenge"] { background: #7541bd; color: white; flex: 1; }
#routine-editor .editor-header { flex-wrap: wrap; }
