/* Play stage. Portrait: the HUD (stats | next + best + pause) in a row on
   top, the well below. Landscape: the HUD in columns left and right.
   The whole stage is the touch surface (gesture.js): left of the well moves
   left, right of it moves right, below it soft drops. The
   page script measures .tr-play and sets --cell (px) on it, keeping
   --tr-zone-cells free on each side and room for the pads below the well. */
.tr-stage {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "left right"
    "play play";
  gap: 0.5em 0.6em;
  padding: 0.4em max(24px, env(safe-area-inset-right, 0px))
    max(40px, calc(env(safe-area-inset-bottom, 0px) + 24px))
    max(24px, env(safe-area-inset-left, 0px));
  touch-action: none;
  overscroll-behavior: none;
}

.tr-play {
  --cell: 16px;
  --tr-zone-cells: 0;
  position: relative;
  grid-area: play;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.5);
}

.tr-well {
  position: relative;
  flex: 0 0 auto;
  border-radius: 0.3em;
  box-shadow: 0 0 0 0.2em rgba(168, 186, 240, 0.3);
}

.tr-canvas {
  display: block;
}

/* HUD. Sized in rem, not cells, so it never feeds back into --cell. */
.tr-side {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.9em;
  font-size: 0.8rem;
}

.tr-side-left {
  grid-area: left;
}

.tr-side-right {
  grid-area: right;
  justify-content: flex-end;
}

.tr-box {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2em;
}

.tr-preview {
  width: 4.4em;
  height: 2.6em;
  border-radius: 0.4em;
  background: rgba(255, 255, 255, 0.04);
}

.tr-label {
  margin: 0;
  font-size: 0.85em;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8f9cc4;
}

.tr-value {
  display: block;
  font-size: 1.4em;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #eef2fb;
}

.tr-stat {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tr-pause {
  flex: 0 0 auto;
  width: 2.8em;
  height: 2.8em;
  border: none;
  border-radius: 0.6em;
  background: #2a3358;
  color: #c7d2f0;
  font: inherit;
  font-size: 1em;
  cursor: pointer;
  touch-action: manipulation;
}

/* Faint arrows on the touch zones (touch screens only). */
.tr-hint {
  display: none;
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: calc(var(--cell) * 0.9);
  color: rgba(200, 214, 240, 0.16);
  pointer-events: none;
}

.tr-hint[data-zone="left"] {
  left: calc(25% - var(--cell) * 2.5);
  top: calc(var(--cell) * 10);
}

.tr-hint[data-zone="right"] {
  left: calc(75% + var(--cell) * 2.5);
  top: calc(var(--cell) * 10);
}

/* Touch pads, centred in the room under the well (touch screens only). */
.tr-pads {
  display: none;
  position: absolute;
  left: 50%;
  top: calc(50% + var(--cell) * 10);
  transform: translate(-50%, -50%);
  align-items: center;
  gap: 0.7rem;
}

.tr-pad {
  display: grid;
  place-items: center;
  width: 3.2rem;
  height: 3.2rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(168, 186, 240, 0.16);
  color: #dbe4f0;
  font: inherit;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: none;
}

.tr-pad:active {
  background: rgba(168, 186, 240, 0.4);
}

.tr-pad-drop {
  width: 4.8rem;
  border-radius: 1.6rem;
}

.tr-bar {
  width: 2.4rem;
  height: 0.4rem;
  border-radius: 0.2rem;
  background: currentColor;
}

/* "Tetris!" style toast over the well. */
.tr-toast {
  position: absolute;
  left: 0;
  right: 0;
  top: 30%;
  margin: 0;
  padding: 0 0.3em;
  text-align: center;
  font-size: 1.5em;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 0.1em 0.4em rgba(0, 0, 0, 0.8);
  opacity: 0;
  pointer-events: none;
}

.tr-toast.show {
  animation: tr-toast 1.2s ease-out both;
}

@keyframes tr-toast {
  0% {
    opacity: 0;
    transform: translateY(0.6em);
  }
  15%,
  70% {
    opacity: 1;
    transform: none;
  }
  100% {
    opacity: 0;
    transform: translateY(-0.6em);
  }
}

/* Touch screens: room for the zones beside and the pads below; the well sits
   on top so all the room left goes to the "down" zone around the pads. */
@media (pointer: coarse) {
  .tr-play {
    --tr-zone-cells: 1.6;
    align-items: flex-start;
  }

  .tr-hint {
    display: block;
  }

  .tr-pads {
    display: flex;
  }
}

/* Landscape: HUD columns on both sides of the well. */
@media (orientation: landscape) {
  .tr-stage {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "left play right";
  }

  .tr-side {
    width: 6.5em;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.6em;
    font-size: 1rem;
  }

  .tr-pause {
    width: 100%;
  }
}

/* Desktop and TV: 3% from the edges; the side padding brings the HUD
   columns near the well (about 43dvh wide at this size). */
@media (min-width: 960px) and (min-height: 500px) {
  .tr-stage {
    padding: 3dvh max(3vw, calc((100vw - 48dvh) / 2 - 8rem)) max(40px, 4dvh);
  }
}
