@media (prefers-reduced-motion: reduce) {
  :root {
    --slide: 0s;
  }
  .toast {
    transition: none;
  }
  .toast-bar {
    display: none;
  }
}

@media (max-width: 760px) {
  :root {
    --sidebar-w: min(310px, calc(100vw - 58px));
  }
  .sidebar {
    position: absolute;
    z-index: 25;
    height: 100%;
    box-shadow: 0 0 40px #000a;
  }
  body.sidebar-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 24;
    background: #05070b80;
  }
  .detail {
    width: 218px;
  }
  .map {
    --compass-h: 84px;
  }
}

@media (max-width: 760px) {
  /* on a phone play's strip is a bar at the foot of the screen, over the scale bar's band: one row
     of text, the line or a notice while one stands, and the buttons sharing one row beneath, so the
     bar keeps its height as the text changes and the pad above it stays put under a thumb */
  #play {
    left: 0;
    right: 0;
    bottom: 0;
    max-width: none;
    gap: 8px;
    border-radius: 12px 12px 0 0;
    padding: 8px 10px 10px;
  }
  #play .line {
    flex-basis: 100%;
    order: -2;
    color: var(--dim);
  }
  #play .status {
    order: -1;
    font-size: 12.5px;
  }
  #play:has(.status:not(:empty)) .line {
    display: none;
  }
  #play .controls {
    flex-basis: 100%;
    flex-wrap: nowrap;
  }
  #play .controls button {
    flex: 1 1 0;
    min-width: 0;
    padding: 3px 4px;
  }
  .hud {
    left: 54px;
    right: 12px;
    min-width: 0;
    transform: none;
  }
}

/* on a phone the palette and the panel are sheets at the foot of the map, one
   at a time, and the editor's strip stands above whichever is open */
@media (max-width: 760px) {
  .map {
    --sheet-h: 42vh;
  }
  body.editing .tools {
    left: 0;
    right: 0;
    bottom: 0;
    max-width: none;
    gap: 4px;
    border-radius: 12px 12px 0 0;
    padding: 6px 8px;
  }
  body.editing.sheet-open .tools {
    bottom: var(--sheet-h);
  }
  /* the status keeps its row while editing, so the line that arms a face moves no button
     under the second tap */
  body.editing #tools .status {
    display: block;
    min-height: 1lh;
  }
  body.editing .tools button,
  .palette .tabs button,
  .palette .kind,
  .palette .x,
  body.editing .detail .x,
  body.editing .detail .fold,
  body.editing .detail .press button,
  body.editing .detail .put button,
  body.editing .detail .form .faces button,
  body.editing .detail .form .swatches button,
  body.editing .detail .form .row button,
  body.editing .detail .form .circuit button,
  body.editing .detail .form select,
  body.editing .detail .form input[type="number"] {
    min-height: 44px;
    min-width: 44px;
  }
  .palette,
  body.editing .detail {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: auto;
    height: var(--sheet-h);
    max-height: none;
    border-radius: 12px 12px 0 0;
    z-index: 16;
  }
  .palette {
    padding-top: 6px;
  }
  .palette .grip {
    display: block;
  }
  .palette .x {
    display: grid;
  }
  .palette .tabs {
    padding-right: 48px;
  }
  body.editing .detail .fold {
    right: 52px;
  }
  body.editing .detail .fold + h3 {
    padding-right: 100px;
  }
  #course button,
  #play button {
    min-height: 44px;
    min-width: 44px;
  }
  body.editing #course {
    display: none;
  }
  /* the strips can span the width, so the corner's widgets and the panel stand above them */
  #corner {
    bottom: calc(
      var(--corner-foot) + var(--under-h, 0px) + var(--course-h, 0px) + var(--play-h, 0px)
    );
  }
  body.editing #corner {
    bottom: calc(var(--under-h, 0px) + var(--course-h, 0px) + var(--play-h, 0px));
  }
  /* while the ball is on the level the play bar covers the scale bar's band and the readout: the
     editor's strip stands on the bar and the planner's on that, or the bar on the editor's while
     editing, and the pad, the jump and the corner's widgets stand above them all */
  body.playing:not(.editing) #tools {
    bottom: var(--play-h, 0px);
  }
  body.playing #course {
    bottom: calc(var(--play-h, 0px) + var(--under-h, 0px));
  }
  body.playing.editing #play {
    bottom: var(--under-h, 0px);
    border-radius: 12px;
  }
  body.playing .readout {
    display: none;
  }
  .pad,
  .jump,
  body.playing #corner {
    bottom: calc(var(--under-h, 0px) + var(--course-h, 0px) + var(--play-h, 0px) + 4px);
  }
  /* and above the jump while the pad shows, the bar spanning the width still and the panel ending
     above the corner, the editor's sheet apart */
  body.padded #corner {
    right: 12px;
    bottom: calc(
      var(--under-h, 0px) + var(--course-h, 0px) + var(--play-h, 0px) + 4px + var(--jump-h) + 8px
    );
  }
  body.padded #play {
    max-width: none;
  }
  .detail {
    max-height: calc(
      100% - 20px - var(--corner-foot) - var(--corner-h) - var(--under-h, 0px) -
        var(--course-h, 0px) - var(--play-h, 0px)
    );
  }
  body.padded:not(.editing) .detail {
    max-height: calc(
      100% - 20px - var(--corner-foot) - var(--corner-h) - var(--under-h, 0px) -
        var(--course-h, 0px) - var(--play-h, 0px) - var(--jump-h) - 8px
    );
  }
}
