@keyframes game-market-games-view-rotation-animation {
  to {
    rotate: 360deg;
  }
}


#game-market-games-view {
  > [purpose="heading"] {
    translate: var(--logo-shift, 0px) 0;
    scale: var(--logo-scale, 1);
    transition: translate 200ms ease, scale 200ms ease;
    @media (prefers-reduced-motion: reduce) { transition: none; }
  }

  > header[purpose="toolbar"] {
    button[action="toggle-selection"] {
      &.start-selection {
        @media (max-width: 490px) {
          padding: 0;


          span {
            display: none;
          }
        }
      }


      &.stop-selection {
        color: var(--color-blue);

        @media (max-width: 610px) {
          padding: 0;


          span {
            display: none;
          }
        }
      }
    }


    button[action="select-all"],
    button[action="select-none"] {
      @media (max-width: 490px) {
        padding: 0;


        span {
          display: none;
        }
      }
    }


    button[action="add-game"] {
      &[aria-disabled="true"] { color: gray; background: transparent; }
      @media (max-width: 650px) {
        padding: 0;


        span {
          display: none;
        }
      }
    }



    button[action="delete-selection-from-cart"] {
      &:not(:disabled) {
        color: var(--color-red);
      }

      @media (max-width: 470px) {
        padding: 0;


        span {
          display: none;
        }
      }
    }


    button[action="pay"] {
      &:not(:disabled) {
        color: var(--color-blue);
      }
    }
  }


  > main {
    --cell-height: 5.2rem;
    --search-height: 5.2rem;
    --floatbar-block-size: calc(1.6rem + 0.8rem + 3.6rem + 0.8rem + 1.6rem);

    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: [list-start] 1fr [floatbar-start] auto [floatbar-end list-end];
    overflow: hidden;


    > * {
      grid-column: 1 / -1;
    }


    .list-search {
      position: sticky; top: 0; z-index: 2; background: var(--viewkit-light-background);
      display: flow-root;
      > .search { min-height: var(--search-height); border-top: 0.1rem solid var(--toolbar-border-color); }
    }


    .reload {
      position: absolute;
      grid-row: list;
      top: 0;
      left: 0;
      right: 0;
      height: var(--overscroll);
      display: grid;
      place-content: center;

      &[hidden] {
        display: none;
      }


      svg {
        --icon-size: 2.4rem;
        --fade-from: var(--icon-size);
        --fade-to: 10rem;

        aspect-ratio: 1 / 1;
        width: var(--icon-size);
        height: auto;
        opacity: clamp(
          0,
          calc((var(--overscroll, 0px) - var(--fade-from)) / (var(--fade-to) - var(--fade-from))),
          1
        );

        &:is([flags~="reloading"] *) {
          animation: game-market-games-view-rotation-animation 1.2s linear infinite;
        }
      }
    }


    > .list {
      --transaction-summary-height: calc(var(--cell-height) - 0.1rem);
      &:has(> .list-contents[data-has-games]) { --transaction-summary-height: var(--cell-height); }
      grid-row: list;
      margin-top: -1px;
      overflow-y: auto;
      overflow-anchor: none;
      scroll-padding-block-start: var(--list-search-height, var(--search-height));
      /* Keep WebKit scrollbars above the sticky search bar. */
      will-change: z-index;

      &:has(~ .floatbar:not([hidden])) {
        scroll-padding-block-end: var(--floatbar-block-size);
      }

      @media (width >= 680px) {
        scroll-padding-block-end: var(--floatbar-block-size);

        > .list-contents::after { min-height: var(--floatbar-block-size); }
      }

      &::before {
        content: "";
        width: 0;
        height: calc(100% + 1px);
        display: block;
        float: left;
      }


      > .list-contents {
        min-height: calc(100% - var(--list-search-height, var(--search-height)));
        &:is(.transaction-summary:not([hidden]) + *) {
          min-height: calc(100% - var(--list-search-height, var(--search-height)) - var(--transaction-summary-height));
        }
        display: flex;
        flex-direction: column;
        cursor: default;

        &::after {
          content: "";
          flex: 1 1;
          display: block;
          width: 100%;
          background: repeating-linear-gradient(
            var(--toolbar-border-color) 0,
            var(--toolbar-border-color) 1px,
            transparent 1px,
            transparent var(--cell-height)
          );
        }

        &:is(.list:has(~ .floatbar:not([hidden])) *) {
          &::after {
            min-height: var(--floatbar-block-size);
          }
        }

        &[inert] {
          opacity: 0.5;
        }


        > .game-rows {
          display: grid;
          grid-template-columns: minmax(0, 1fr);
          grid-auto-rows: var(--cell-height);
        }

        .game {
          border-top: 0.1rem solid var(--toolbar-border-color);
          &[aria-posinset="1"] { border-top-color: transparent; }
          padding-right: 1.2rem;
          padding-bottom: 0.2rem;
          display: grid;
          grid-template-columns: auto 1fr;
          grid-template-rows: auto auto;
          grid-template-areas:
            "left top"
            "left bottom";
          row-gap: 0.2rem;
          column-gap: 0.8rem;
          place-content: center;
          overflow: hidden;

          &[data-selected] {
            background-color: rgba(0, 0, 0, 0.1);
          }


          > div {
            min-width: 0;
            display: flex;
            align-items: center;


            &.left {
              grid-area: left;


              .select {
                --icon: 2.4rem;
                --inset: 1.2rem;

                margin-left: calc((var(--icon) + var(--inset)) * -1);
                margin-right: calc(var(--inset) + 0.4rem);
                display: grid;
                place-content: center;
                transition: margin 0.4s;
                transition-timing-function: ease;

                &:is([flags~="selection"] *) {
                  margin-left: var(--inset);
                  margin-right: 0;
                }


                svg {
                  aspect-ratio: 1 / 1;
                  width: var(--icon);
                  height: auto;

                  &:is(.game[data-selected] *) {
                    polyline,
                    circle {
                      stroke: var(--color-blue);
                    }
                  }

                  &:is(.game:not([data-selected]) *) {
                    circle {
                      stroke: rgba(0, 0, 0, 0.25);
                    }
                  }


                  polyline:is(.game:not([data-selected]) *) {
                    display: none;
                  }
                }
              }


              .language {
                border: 0.1rem solid gray;
                border-radius: 0.4rem;
                padding-block: 0.2rem;
                padding-inline: 0.4rem;
                display: none;
                font-size: 1.4rem;
              }
            }


            &.top {
              grid-area: top;
              gap: 0.8rem;


              .name {
                flex-shrink: 1;
                white-space: nowrap;
                text-overflow: ellipsis;
                overflow: hidden;
              }


              .prices {
                margin-left: auto;
                flex: 0 0 auto;
                font-size: 1.2rem;


                .price,
                .price-sunday {
                  --gray: oklch(from white calc(0.75 * l) c h);

                  font-variant-numeric: tabular-nums;

                  &[data-sold] {
                    font-weight: 600;
                  }

                  &:has(~ [data-sold]),
                  &:is([data-sold] ~ *) {
                    color: var(--gray);
                    text-decoration: line-through;
                    text-decoration-thickness: 2px;
                  }

                  &:is(.game:not([data-status="sold"]) *) {
                    &.price:is(#game-market-games-view[flags~="sunday-price"] *),
                    &.price-sunday:is(#game-market-games-view:not([flags~="sunday-price"]) *) {
                      color: var(--gray);
                    }
                  }
                }


                .divider {
                  color: gray;

                  &:is(.price:empty ~ *),
                  &:has(~ .price-sunday:empty) {
                    display: none;
                  }
                }
              }
            }


            &.bottom {
              grid-area: bottom;
              gap: 0.4rem;
              -webkit-user-select: none;
              user-select: none;


              .type {
                font-size: 1.2rem;
                text-box: trim-both cap alphabetic;
              }


              .labels {
                flex: 1 1;
                display: flex;
                align-items: center;
                gap: 0.4rem;
                overflow: hidden;


                .user,
                .condition,
                .complete {
                  --factor: 1.4;
                  flex-shrink: 1;
                  border: 0.1rem solid rgba(0, 0, 0, 0.1);
                  border-radius: 100vmax;
                  padding-block: 0.3rem;
                  padding-inline: 0.4rem;
                  font-size: 0.9rem;
                  line-height: 1;
                  text-box: trim-both cap alphabetic;
                  white-space: nowrap;
                  text-overflow: ellipsis;
                  overflow: hidden;

                  &:empty {
                    display: none;
                  }

                  &:is(.condition) {
                    &[data-value="new"] {
                      background: oklch(from rgba(245, 139, 1, 1) calc(var(--factor) * l) c h);
                    }

                    &[data-value="used"] {
                      background: oklch(from rgb(152 122 84) calc(var(--factor) * l) c h);
                    }

                    &[data-value="fresh"] {
                      background: oklch(from rgba(29, 195, 55, 1) calc(var(--factor) * l) c h);
                    }
                  }

                  &:is(.complete) {
                    &[data-value="true"] {
                      display: none;
                    }

                    &[data-value="false"] {
                      background: oklch(from rgba(255, 49, 38, 1) calc(var(--factor) * l) c h);
                    }
                  }
                }
              }


              .notes {
                &[data-value=""] {
                  display: none;
                }

                &:not([data-value=""]) {
                  display: contents;
                }


                svg {
                  width: auto;
                  height: 1.4rem;
                }
              }


              .status {
                font-size: 1.2rem;
                text-box: trim-both cap alphabetic;

                &:is(.game[data-status="donated"] *) {
                  color: rgb(225 112 144);
                }

                &:is(.game[data-status="sold"] *) {
                  color: var(--color-green);
                }

                &:is(.game[data-status="checkedout"] *) {
                  color: rgba(0, 112, 245, 1);
                }

                &:is(#game-market-games-view[flags~="games-in-cart"] *):is(.game:not([data-status]) *:not(:empty)) {
                  color: var(--color-red);
                }
              }
            }
          }
        }
      }
    }


    :is(.floatbar, .scroll-control) {
      box-shadow:
        0px 0px 0px 1px rgba(0, 0, 0, 0.06),
        0px 1px 2px -1px rgba(0, 0, 0, 0.06),
        0px 2px 4px 0px rgba(0, 0, 0, 0.04);
      border: 1px solid var(--toolbar-border-color);
      border-radius: 2.6rem;
      padding: 0.8rem;
      background: var(--toolbar-background-color);
    }

    > .scroll-control {
      display: none;
      grid-row: floatbar;
      justify-self: end;
      align-self: end;
      z-index: 1;
      margin-inline-end: 1.6rem;
      margin-block-end: 1.6rem;
      opacity: 0;
      visibility: hidden;
      transition: opacity 180ms ease, visibility 0s 180ms;

      &:not([inert]) {
        opacity: 1;
        visibility: visible;
        transition-delay: 0s;
      }

      @media (width >= 680px) {
        display: flex;
      }

      @media (prefers-reduced-motion: reduce) { transition: none; }
    }

    > .floatbar {
      grid-row: floatbar;
      justify-self: center;
      z-index: 1;
      margin-inline: 1.6rem;
      margin-bottom: 1.6rem;
      max-width: min(36rem, calc(100% - 1.6rem));
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 0.8rem;
      overflow: hidden;

      &[hidden] {
        display: none;
      }


      .preview {
        border: 1px solid var(--toolbar-border-color);
        border-radius: 1.6rem;
        aspect-ratio: 1 / 1;
        overflow: hidden;
        background: white;
        display: grid;
        grid-template-areas: "stack";
        place-items: center;

        &[hidden] {
          display: none;
        }


        > * {
          grid-area: stack;
        }


        svg {
          width: 9.6rem;
          height: auto;

          &[hidden] {
            display: none;
          }

          &:is(.success, .success-repeat) path {
            fill: var(--color-green);
          }

          &:is(.failure, .no-camera) path {
            fill: var(--color-red);
          }
        }


        video {
          aspect-ratio: 1 / 1;
          width: 100vmax;
          max-width: 100%;
          display: block;
          transition: 0.4s opacity;

          &[hidden] {
            opacity: 0;
          }
        }
      }


      nav {
        width: 100%;
        display: flex;
        gap: 0.8rem;
        justify-content: center;


        > button, .users {
          background: var(--button-background-color);
        }

        .inputs {
          min-width: 0;
          flex-shrink: 1;
          display: grid;
          grid-template-areas: "stack";


          > * {
            grid-area: stack;
          }


          .users {
            padding-right: 0.6rem;
          }

          :is(.users, .user-summary) {
            flex-shrink: 1;
            min-width: 0;
            gap: 0.6rem;
            align-items: center;

            &:not([hidden]) {
              display: flex;
            }

            > span {
              text-box: normal;
              line-height: 1.3;
            }

            .name {
              min-width: 0;
              flex: 1;
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }

            .count {
              border-radius: 100vmax;
              display: grid;
              place-items: center;
              height: 2.4rem;
              min-width: 2.4rem;
              padding-inline: 0.7rem;
              background: var(--viewkit-light-background);
              font-size: 1.3rem;
              font-variant-numeric: tabular-nums;
              white-space: nowrap;
            }
          }


          .cart {
            font-weight: 400;
          }
        }


        .cart {
          position: relative;
          border: none;
          border-radius: 100vmax;
          border: 1px solid var(--button-background-color);
          min-width: 0;
          display: flex;
          align-items: center;
          isolation: isolate;

          &[hidden] {
            display: none;
          }


          .counter {
            flex-shrink: 1;
            margin-left: 1.2rem;
            margin-right: 0.8rem;
            font-size: 1.4rem;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
          }


          button {
            min-width: calc(var(--viewkit-button-height) - 2px);
            height: calc(var(--viewkit-button-height) - 2px);
          }
        }


        .camera {
          &[marked] {
            color: var(--color-blue);
          }
        }
      }
    }
  }


  > .\@overlay {

  }

}

#game-market-games-view .transaction-summary {
  height: var(--transaction-summary-height);
  padding-inline: 1.2rem;
  text-align: center;
  font-size: 1.4rem;
  &:not([hidden]) { display: grid; align-content: center; gap: 0.2rem; }
  &:has(+ .list-contents[data-has-games]) {
    border-bottom: 0.1rem solid var(--toolbar-border-color);
  }
  > span { font-size: 1.2rem; color: var(--color-gray); }
}

#game-market-games-view {
  .label-toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: 1.2rem;
    padding: 0.8rem; padding-left: 1.6rem;
    background: var(--toolbar-background-color);
    &.prominent:not([flags~="scanning"] *) { background: color-mix(in srgb, var(--color-blue) 8%, white); }
    .label-count { flex: 1; min-width: 0; font-size: 1.3rem; line-height: 1.3; font-variant-numeric: tabular-nums; container: label-counter / inline-size; }
    .selection-unit { display: none; }
    @container label-counter (min-width: 22ch) { .selection-unit { display: inline; } }
    button { flex-shrink: 0; }
    &[hidden] { display: none; }
  }
  .label-print-action {
    span { display: none; }
    border-radius: 100vmax;
    width: 3.6rem; padding: 0;
    &[hidden] { display: none; }
  }
}
#game-market-games-view .game[data-status="labeled"] .status { color: #9a65c4; }

#game-market-games-view .print-scope {
  margin: auto;
  padding: 2.4rem;
  width: min(40rem, calc(100% - 3.2rem));
  border: 1px solid var(--toolbar-border-color);
  border-radius: 2rem;
  background: var(--viewkit-light-background);
  color: inherit;
  &::backdrop { background: rgb(0 0 0 / 30%); }
  h2 { margin-bottom: 2rem; font-size: 2rem; text-align: center; }
  > div { display: grid; gap: 0.8rem; }
  button:has(.scope-count) { justify-content: space-between; gap: 1.2rem; padding-block: 0.6rem; padding-inline: 1.2rem 0.6rem; height: auto; min-height: var(--viewkit-button-height); }
  .scope-label { text-align: left; line-height: 1.3; flex-shrink: 1; }
  .scope-count {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2.4rem;
    min-height: 2.4rem;
    padding: 0.4rem 0.6rem;
    border-radius: 100vmax;
    background: var(--viewkit-light-background);
    font-size: 1.3rem;
    line-height: 1.2;
    text-box: normal;
    font-variant-numeric: tabular-nums;
  }
  [data-print-scope="cancel"] { margin-top: 1.2rem; }
}
