:root {
  --gp-ink: #4f321d;
  --gp-honey: #d89b39;
  --gp-focus: #166f9b;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: #291d17;
}

body {
  overflow: hidden;
}

#activity-root {
  min-height: 100dvh;
}

.gp-game {
  --gp-guest-width: clamp(98px, 23.5vw, 130px);
  --gp-guest-height: clamp(98px, 23.5vw, 130px);
  --gp-side-width: 60px;
  --gp-side-height: 60px;
  --gp-mat-size: 40px;
  --gp-cell: 56px;
  --gp-cell-gap: 2px;
  --gp-back-y: 20%;
  --gp-side-y: 42%;

  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  color: var(--gp-ink);
}

.gp-game img {
  max-width: none;
  max-height: none;
}

.gp-workspace {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 2px;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
}

.gp-table {
  position: relative;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  container-type: size;
}

.gp-table-visual,
.gp-guests {
  --gp-art-height: min(
    100cqh,
    65.08cqw,
    calc((100cqh - var(--gp-guest-height)) * 1.25)
  );
  --gp-art-width: calc(var(--gp-art-height) * 1.536492958);
  --gp-headroom: max(
    0px,
    calc(var(--gp-guest-height) - var(--gp-art-height) * 0.2),
    calc(var(--gp-side-height) - var(--gp-art-height) * 0.42)
  );
}

.gp-table-visual {
  position: absolute;
  z-index: 0;
  top: max(var(--gp-headroom), calc(100cqh - var(--gp-art-height) - 12px));
  left: 50%;
  display: block;
  width: var(--gp-art-width);
  height: var(--gp-art-height);
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
  transform: translateX(-50%);
  filter:
    drop-shadow(0 7px 5px rgba(74, 44, 18, 0.18))
    drop-shadow(0 2px 2px rgba(74, 44, 18, 0.14));
}

.gp-guests {
  position: absolute;
  z-index: 3;
  top: max(var(--gp-headroom), calc(100cqh - var(--gp-art-height) - 12px));
  left: 50%;
  width: var(--gp-art-width);
  height: var(--gp-art-height);
  aspect-ratio: 1200 / 781;
  pointer-events: none;
  transform: translateX(-50%);
}

.gp-guest-place {
  position: absolute;
  top: calc(var(--gp-seat-y, var(--gp-back-y)) - var(--gp-guest-height));
  display: grid;
  grid-template-rows: var(--gp-guest-height) var(--gp-mat-size);
  place-items: end center;
  width: var(--gp-guest-width);
  min-width: 56px;
  min-height: calc(var(--gp-guest-height) + var(--gp-mat-size));
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  transform: translateX(-50%);
  transition: transform 180ms ease, filter 180ms ease;
}

.gp-guest-place[data-guest]:nth-child(4),
.gp-guest-place[data-guest]:nth-child(5) {
  top: calc(var(--gp-side-y) - var(--gp-side-height));
  width: var(--gp-side-width);
  grid-template-rows: var(--gp-side-height) var(--gp-mat-size);
  min-height: calc(var(--gp-side-height) + var(--gp-mat-size));
}

.gp-guest-portrait {
  display: block;
  width: 100%;
  height: var(--gp-guest-height);
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
  filter:
    drop-shadow(0 5px 3px rgba(61, 38, 18, 0.2))
    drop-shadow(0 1px 1px rgba(61, 38, 18, 0.16));
}

.gp-guest-place:nth-child(4) .gp-guest-portrait,
.gp-guest-place:nth-child(5) .gp-guest-portrait {
  height: var(--gp-side-height);
}

.gp-setting {
  position: relative;
  display: grid;
  width: var(--gp-mat-size);
  height: var(--gp-mat-size);
  place-items: center;
  pointer-events: none;
  filter: drop-shadow(0 3px 2px rgba(72, 43, 17, 0.22));
}

.gp-placemat,
.gp-setting .gp-plate {
  grid-area: 1 / 1;
}

.gp-placemat {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gp-game .gp-seat-plate {
  width: calc(100% - 2px);
  height: calc(100% - 2px);
  object-fit: contain;
}

.gp-guest-place.has-plate .gp-setting {
  filter:
    drop-shadow(0 4px 3px rgba(72, 43, 17, 0.25))
    drop-shadow(0 0 4px rgba(250, 224, 153, 0.18));
}

.gp-guest-place.is-selected .gp-setting,
.gp-guest-place.is-over .gp-setting {
  outline: 4px solid var(--gp-focus);
  outline-offset: 2px;
  border-radius: 50%;
}

.gp-guest-place.is-wrong .gp-setting {
  outline: 3px solid #b26845;
  outline-offset: 2px;
  border-radius: 50%;
}

.gp-guest-place.is-over {
  filter: brightness(1.06);
  transform: translateX(-50%) translateY(-3px);
}

.gp-guest-place:focus-visible {
  outline: 3px solid var(--gp-focus);
  outline-offset: 1px;
  border-radius: 22px;
}

.gp-guest-place.just-placed .gp-setting {
  animation: gp-plate-settle 480ms cubic-bezier(0.2, 0.9, 0.25, 1.25);
}

.gp-game.is-correct .gp-setting {
  animation: gp-warm-nod 620ms ease-in-out;
}

.gp-game[data-count="2"] .gp-guest-place:nth-child(1) { left: 30%; }
.gp-game[data-count="2"] .gp-guest-place:nth-child(2) { left: 70%; }

.gp-game[data-count="4"] .gp-guest-place:nth-child(1),
.gp-game[data-count="5"] .gp-guest-place:nth-child(1) { left: 20%; }

.gp-game[data-count="4"] .gp-guest-place:nth-child(2),
.gp-game[data-count="5"] .gp-guest-place:nth-child(2) { left: 50%; }

.gp-game[data-count="4"] .gp-guest-place:nth-child(3),
.gp-game[data-count="5"] .gp-guest-place:nth-child(3) { left: 80%; }

.gp-game[data-count="3"] .gp-guest-place:nth-child(1) { left: 18%; }
.gp-game[data-count="3"] .gp-guest-place:nth-child(2) { left: 50%; }
.gp-game[data-count="3"] .gp-guest-place:nth-child(3) { left: 82%; }

.gp-game[data-count="4"] {
  --gp-guest-width: 60px;
  --gp-guest-height: 60px;
}

.gp-game[data-count="4"] .gp-guest-place {
  top: calc(var(--gp-back-y) - var(--gp-guest-height));
  width: var(--gp-guest-width);
  grid-template-rows: var(--gp-guest-height) var(--gp-mat-size);
  min-height: calc(var(--gp-guest-height) + var(--gp-mat-size));
}

.gp-game[data-count="4"] .gp-guest-portrait {
  height: var(--gp-guest-height);
}

.gp-game[data-count="4"] .gp-guest-place:nth-child(1) { left: 12.5%; }
.gp-game[data-count="4"] .gp-guest-place:nth-child(2) { left: 37.5%; }
.gp-game[data-count="4"] .gp-guest-place:nth-child(3) { left: 62.5%; }
.gp-game[data-count="4"] .gp-guest-place:nth-child(4) { left: 87.5%; }

.gp-game[data-count="5"] {
  --gp-guest-width: 60px;
  --gp-guest-height: 60px;
  --gp-side-width: 60px;
  --gp-side-height: 60px;
}

.gp-game[data-count="5"] .gp-guest-place:nth-child(1) { left: 27%; }
.gp-game[data-count="5"] .gp-guest-place:nth-child(2) { left: 50%; }
.gp-game[data-count="5"] .gp-guest-place:nth-child(3) { left: 73%; }
.gp-game[data-count="5"] .gp-guest-place:nth-child(4) { left: 12%; }
.gp-game[data-count="5"] .gp-guest-place:nth-child(5) { left: 88%; }

.gp-game[data-count="5"] .gp-guest-place:nth-child(4),
.gp-game[data-count="5"] .gp-guest-place:nth-child(5) {
  top: calc(60% - var(--gp-mat-size) + 15px);
  grid-template-rows: var(--gp-mat-size) var(--gp-side-height);
}

.gp-game[data-count="5"] .gp-guest-place:nth-child(4) .gp-setting,
.gp-game[data-count="5"] .gp-guest-place:nth-child(5) .gp-setting {
  grid-row: 1;
}

.gp-game[data-count="5"] .gp-guest-place:nth-child(4) .gp-guest-portrait,
.gp-game[data-count="5"] .gp-guest-place:nth-child(5) .gp-guest-portrait {
  grid-row: 2;
}

.gp-table-target {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 56px;
  min-height: 56px;
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: transparent;
  cursor: pointer;
  pointer-events: none;
}

.gp-table-target:focus-visible {
  outline: 3px solid var(--gp-focus);
  outline-offset: -4px;
}

.gp-table-target.is-over {
  background: rgba(255, 249, 218, 0.24);
  box-shadow: inset 0 0 0 4px var(--gp-focus);
}

.gp-supply-zone {
  position: relative;
  z-index: 4;
  display: grid;
  grid-row: 2;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: max-content max-content;
  grid-auto-rows: max-content;
  align-content: flex-start;
  justify-content: center;
  column-gap: var(--gp-cell-gap);
  row-gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: var(--gp-cell);
  margin: 0 auto;
  padding: 0 4px;
  box-sizing: border-box;
  isolation: isolate;
}

.gp-table-plates {
  --gp-table-rows: 1;

  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--gp-table-columns, 1), var(--gp-cell));
  grid-auto-rows: var(--gp-cell);
  grid-column: 1 / -1;
  grid-row: 2 / span var(--gp-table-rows);
  justify-self: center;
  gap: var(--gp-cell-gap);
  width: max-content;
  min-width: 56px;
  min-height: 56px;
}

.gp-table-plates[data-count="1"] { --gp-table-columns: 1; }
.gp-table-plates[data-count="2"] { --gp-table-columns: 2; }
.gp-table-plates[data-count="3"] { --gp-table-columns: 3; }
.gp-table-plates[data-count="4"] { --gp-table-columns: 4; }
.gp-table-plates[data-count="5"] { --gp-table-columns: 5; }
.gp-table-plates[data-count="6"] { --gp-table-columns: 6; }
.gp-table-plates[data-count="7"] { --gp-table-columns: 7; }

.gp-table-plates.is-drop-open,
.gp-table-plates.is-drop-open .gp-plate-button,
.gp-table-plates.is-drop-open .gp-plate {
  pointer-events: none;
}

.gp-table-plates.is-drop-open .gp-table-target {
  pointer-events: auto;
}

.gp-plate-button {
  position: relative;
  z-index: 1;
  display: grid;
  width: var(--gp-cell);
  height: var(--gp-cell);
  min-width: 56px;
  min-height: 56px;
  place-items: center;
  padding: 2px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: grab;
  touch-action: none;
  transition: transform 160ms ease, filter 160ms ease;
}

.gp-plate-button.is-dragging {
  cursor: grabbing;
  opacity: 0.42;
}

.gp-game .gp-plate {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 3px 3px rgba(66, 41, 20, 0.24));
}

.gp-plate-button.is-selected {
  outline: 3px solid var(--gp-focus);
  outline-offset: 0;
  transform: translateY(-2px);
}

.gp-cupboard {
  position: relative;
  z-index: 1;
  display: grid;
  grid-column: 1 / -1;
  grid-row: 1;
  grid-template-columns: repeat(var(--gp-shelf-cells), minmax(var(--gp-cell), 1fr));
  grid-auto-rows: var(--gp-cell);
  align-items: center;
  justify-content: center;
  justify-self: end;
  gap: var(--gp-cell-gap);
  width: max-content;
  min-width: 220px;
  min-height: 72px;
  border-radius: 10px;
  background-color: rgba(255, 248, 231, 0.08);
  background-image: url("./assets/shelf.webp");
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
}

.gp-cupboard-target {
  position: relative;
  z-index: 1;
  display: block;
  width: auto;
  height: var(--gp-cell);
  min-width: 56px;
  min-height: 56px;
  align-self: center;
  justify-self: stretch;
  padding: 2px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--gp-ink);
  font: inherit;
  cursor: pointer;
}

.gp-cupboard-target:focus-visible {
  outline: 3px solid var(--gp-focus);
  outline-offset: 1px;
}

.gp-cupboard-target.is-over,
.gp-cupboard.is-over {
  border-radius: 8px;
  background-color: rgba(255, 249, 224, 0.44);
  outline: 3px solid var(--gp-focus);
  outline-offset: 1px;
}

.gp-cupboard.is-drop-open {
  background-color: rgba(255, 249, 224, 0.16);
}

.gp-hand {
  position: fixed;
  z-index: 70;
  width: clamp(50px, 6.5vmin, 58px);
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 4px 4px rgba(42, 24, 10, 0.28));
  transform: translate(0, -50%) rotate(-11deg);
  transform-origin: 15% 50%;
}

.gp-hand.gp-hand-check {
  transform: translate(0, -50%) rotate(15deg);
}

.gp-drag-ghost {
  position: fixed;
  z-index: 69;
  width: 64px;
  height: 64px;
  max-width: none;
  max-height: none;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 10px 10px rgba(55, 32, 15, 0.28));
}

.gp-game.is-demo-locked .gp-guest-place,
.gp-game.is-demo-locked .gp-plate-button,
.gp-game.is-demo-locked .gp-table-target,
.gp-game.is-demo-locked .gp-cupboard-target {
  pointer-events: none;
}

.gp-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes gp-plate-settle {
  0% { transform: translateY(-8px) scale(1.05); }
  65% { transform: translateY(2px) scale(0.99); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes gp-warm-nod {
  0%, 100% { filter: drop-shadow(0 3px 2px rgba(72, 43, 17, 0.22)); }
  50% { filter: drop-shadow(0 0 10px rgba(241, 193, 74, 0.88)); }
}

@media (min-width: 600px) {
  .gp-game {
    --gp-guest-width: 130px;
    --gp-guest-height: 130px;
    --gp-side-width: 130px;
    --gp-side-height: 130px;
    --gp-mat-size: clamp(70px, 8vmin, 88px);
    --gp-cell: 64px;
  }

  .gp-cupboard {
    min-width: 260px;
    min-height: 80px;
  }

  .gp-game[data-count="5"] {
    --gp-guest-width: 100px;
    --gp-guest-height: 100px;
    --gp-side-width: 90px;
    --gp-side-height: 90px;
  }

  .gp-game[data-count="3"] {
    --gp-guest-width: 130px;
    --gp-guest-height: 130px;
  }

  .gp-game[data-count="4"] {
    --gp-guest-width: 110px;
    --gp-guest-height: 110px;
    --gp-side-width: 110px;
    --gp-side-height: 110px;
  }

  .gp-supply-zone {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
}

@media (max-width: 599px) {
  .gp-game[data-count="3"] {
    --gp-guest-width: clamp(84px, 20vw, 110px);
    --gp-guest-height: clamp(84px, 20vw, 110px);
  }

  .gp-cupboard {
    justify-self: end;
  }

  .gp-table-plates[data-count="5"],
  .gp-table-plates[data-count="6"],
  .gp-table-plates[data-count="7"] {
    --gp-table-columns: 4;
    --gp-table-rows: 2;
  }
}

@media (min-width: 900px) {
  .gp-game {
    --gp-cell: 72px;
  }

}

@media (max-height: 650px) and (orientation: landscape) {
  .gp-workspace {
    gap: 0;
  }

  .gp-game {
    --gp-guest-width: 70px;
    --gp-guest-height: 50px;
    --gp-side-width: 60px;
    --gp-side-height: 50px;
    --gp-mat-size: 40px;
    --gp-cell: 56px;
  }

  .gp-game[data-count="5"] {
    --gp-guest-width: 70px;
    --gp-guest-height: 50px;
    --gp-side-width: 60px;
    --gp-side-height: 50px;
  }

  .gp-game[data-count="3"] {
    --gp-guest-width: 70px;
    --gp-guest-height: 50px;
  }

  .gp-table-visual,
  .gp-guests {
    --gp-art-width: 100cqw;
  }

  .gp-game[data-count="4"] .gp-table-visual,
  .gp-game[data-count="4"] .gp-guests,
  .gp-game[data-count="5"] .gp-table-visual,
  .gp-game[data-count="5"] .gp-guests {
    top: 0;
    width: 100cqw;
    height: 100%;
  }

  .gp-game .gp-table-visual {
    object-fit: cover;
    object-position: 50% 50%;
  }

  .gp-game[data-count="4"] .gp-guest-place,
  .gp-game[data-count="5"] .gp-guest-place,
  .gp-game[data-count="4"] .gp-guest-place:nth-child(4),
  .gp-game[data-count="5"] .gp-guest-place:nth-child(4),
  .gp-game[data-count="5"] .gp-guest-place:nth-child(5) {
    top: 0;
    width: var(--gp-guest-width);
    grid-template-rows: var(--gp-guest-height) var(--gp-mat-size);
    min-height: calc(var(--gp-guest-height) + var(--gp-mat-size));
  }

  .gp-game[data-count="4"] .gp-guest-portrait,
  .gp-game[data-count="5"] .gp-guest-portrait {
    height: var(--gp-guest-height);
  }

  .gp-game[data-count="4"] .gp-guest-place:nth-child(1) { left: 10%; }
  .gp-game[data-count="4"] .gp-guest-place:nth-child(2) { left: 36.67%; }
  .gp-game[data-count="4"] .gp-guest-place:nth-child(3) { left: 63.33%; }
  .gp-game[data-count="4"] .gp-guest-place:nth-child(4) { left: 90%; }

  .gp-game[data-count="5"] .gp-guest-place:nth-child(1) { left: 10%; }
  .gp-game[data-count="5"] .gp-guest-place:nth-child(2) { left: 30%; }
  .gp-game[data-count="5"] .gp-guest-place:nth-child(3) { left: 50%; }
  .gp-game[data-count="5"] .gp-guest-place:nth-child(4) { left: 70%; }
  .gp-game[data-count="5"] .gp-guest-place:nth-child(5) { left: 90%; }

  .gp-game[data-count="4"] .gp-guest-place:nth-child(4),
  .gp-game[data-count="5"] .gp-guest-place:nth-child(4),
  .gp-game[data-count="5"] .gp-guest-place:nth-child(5) {
    --gp-side-width: var(--gp-guest-width);
    --gp-side-height: var(--gp-guest-height);
  }

  .gp-game[data-count="5"] .gp-guest-place:nth-child(4) .gp-setting,
  .gp-game[data-count="5"] .gp-guest-place:nth-child(5) .gp-setting {
    grid-row: 2;
  }

  .gp-game[data-count="5"] .gp-guest-place:nth-child(4) .gp-guest-portrait,
  .gp-game[data-count="5"] .gp-guest-place:nth-child(5) .gp-guest-portrait {
    grid-row: 1;
  }

  .gp-supply-zone {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 20px minmax(56px, auto);
    align-content: start;
    column-gap: var(--gp-cell-gap);
    row-gap: 0;
    padding: 0 2px;
  }

  .gp-table-plates,
  .gp-table-plates[data-count="5"],
  .gp-table-plates[data-count="6"],
  .gp-table-plates[data-count="7"] {
    --gp-table-rows: 1;

    grid-column: 1;
    grid-row: 2;
    align-self: start;
    justify-self: start;
    row-gap: 0;
  }

  .gp-cupboard {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: start;
    min-width: calc(3 * var(--gp-cell) + 2 * var(--gp-cell-gap));
    min-height: 72px;
  }

  .gp-supply-zone:has(.gp-table-plates[data-count="5"]),
  .gp-supply-zone:has(.gp-table-plates[data-count="6"]),
  .gp-supply-zone:has(.gp-table-plates[data-count="7"]) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 56px 56px;
    gap: 2px;
  }

  .gp-supply-zone:has(.gp-table-plates[data-count="5"]) .gp-cupboard,
  .gp-supply-zone:has(.gp-table-plates[data-count="6"]) .gp-cupboard,
  .gp-supply-zone:has(.gp-table-plates[data-count="7"]) .gp-cupboard {
    grid-column: 1;
    grid-row: 1;
    justify-self: end;
    min-height: 56px;
  }

  .gp-supply-zone:has(.gp-table-plates[data-count="5"]) .gp-table-plates,
  .gp-supply-zone:has(.gp-table-plates[data-count="6"]) .gp-table-plates,
  .gp-supply-zone:has(.gp-table-plates[data-count="7"]) .gp-table-plates {
    grid-column: 1;
    grid-row: 2;
    justify-self: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gp-plate-button,
  .gp-guest-place,
  .gp-guest-place.just-placed .gp-setting,
  .gp-game.is-correct .gp-setting {
    animation: none;
    transition: none;
  }
}
