/* Phones turned sideways. The game fills the screen's height in the middle, with its touch
   controls beside it (left and right) instead of underneath; settings, rules and the
   rest come after it. Real-time games use <body class="ls-play">, turn-based games
   <body class="ls-turns"> (whose turn it is across the top, scores and buttons beside the
   board). arcade.js scrolls the game into view when the phone is turned.
   Linked last in each game page's <head>, after the page's own styles. */

@media (orientation: landscape) and (max-height: 520px) and (any-pointer: coarse) {
  body.ls-play,
  body.ls-turns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-auto-flow: row;
    align-items: center;
    justify-items: center;
    column-gap: 10px;
    row-gap: 10px;
    padding: 4px max(8px, env(safe-area-inset-right)) 32px max(8px, env(safe-area-inset-left));
  }

  body.ls-play > *,
  body.ls-turns > * {
    grid-column: 1 / -1;
  }

  /* The title is drawn in the game too; the back link stays at the top */
  body.ls-play > h1,
  body.ls-turns > h1 {
    display: none;
  }

  body.ls-play > .back-link,
  body.ls-turns > .back-link {
    grid-row: 1;
    justify-self: start;
    min-height: 36px;
  }

  /* The game: as tall as the screen allows, keeping its shape */
  body.ls-play .screen,
  body.ls-turns .screen,
  body.ls-play > .arena {
    width: auto !important;
    max-width: 100%;
    margin: 0;
  }

  body.ls-play .screen canvas,
  body.ls-play .screen #game,
  body.ls-play .arena #game {
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: calc(100vh - 12px) !important;
    max-height: calc(100dvh - 12px) !important;
  }

  body.ls-turns .screen canvas {
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: calc(100vh - 52px) !important;
    max-height: calc(100dvh - 52px) !important;
  }

  /* ---------- Real-time games: game in the middle, thumbs either side ---------- */

  body.ls-play > .screen,
  body.ls-play > .arena {
    grid-column: 2;
    grid-row: 2;
  }

  /* Woofstead: joystick on the left, BARK and RUN on the right */
  body.ls-play .woof-pad {
    display: contents !important;
  }
  body.ls-play .woof-pad .joystick {
    --size: min(100px, 27vh);
    grid-column: 1;
    grid-row: 2;
  }
  body.ls-play .woof-pad .woof-buttons {
    grid-column: 3;
    grid-row: 2;
    flex-direction: column;
  }

  /* Lodestone: your PULL button on the right (two players on one phone: Blue left, Red right) */
  body.ls-play .pull-pad {
    display: contents !important;
  }
  body.ls-play .pull-pad button {
    width: min(120px, 100%);
    height: min(110px, 30vh);
  }
  body.ls-play .pull-pad #pull-x {
    grid-column: 3;
    grid-row: 2;
  }
  body.ls-play.two-player .pull-pad #pull-x {
    grid-column: 1;
  }
  body.ls-play .pull-pad #pull-o {
    grid-column: 3;
    grid-row: 2;
  }

  /* Shardfall, Echo Maze: the button pad on the right */
  body.ls-play > .touch-pad {
    grid-column: 3;
    grid-row: 2;
    margin: 0;
  }
  body.ls-play > .blocks-pad {
    --pad: min(48px, 12.5vh);
    gap: 6px;
  }
  body.ls-play > .touch-pad:not(.blocks-pad) {
    max-width: 240px;
  }

  /* Elemyth: the move buttons in a column on the right, the quest on the left */
  body.ls-play > .move-pad {
    grid-column: 3;
    grid-row: 2;
    flex-direction: column;
    flex-wrap: nowrap;
    width: auto;
    margin: 0;
  }
  body.ls-play > .quest-line {
    grid-column: 1;
    grid-row: 2;
    margin: 0;
    text-align: left;
  }

  /* ---------- Turn-based games: whose turn on top, board in the middle ---------- */

  body.ls-turns > #status {
    grid-row: 2;
    margin: 0;
    font-size: 15px;
  }

  body.ls-turns > .screen,
  body.ls-turns .battle-layout > .screen {
    grid-column: 2;
    grid-row: 3;
  }

  body.ls-turns > .scores {
    grid-column: 1;
    grid-row: 3;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  body.ls-turns > .actions {
    grid-column: 3;
    grid-row: 3;
    flex-direction: column;
    align-items: stretch;
  }

  /* Frontline: the map joins the board row; its field shop goes below */
  body.ls-turns > .battle-layout {
    display: contents;
  }
  body.ls-turns .battle-layout > .field-shop {
    grid-column: 1 / -1;
  }
}

@media (orientation: landscape) and (max-height: 520px) and (any-pointer: coarse) {
  /* Woofstead's BARK and RUN, sized to fit beside the field */
  body.ls-play .woof-pad .woof-buttons button,
  body.ls-play .woof-pad .woof-buttons #run-btn {
    width: min(88px, 24vh);
    height: min(88px, 24vh);
  }
}

@media (orientation: landscape) and (max-height: 520px) and (any-pointer: coarse) {
  /* Shardfall's smaller sideways buttons: labels that fit */
  body.ls-play > .blocks-pad [data-action] {
    font-size: 8px;
  }
}

@media (orientation: landscape) and (max-height: 520px) and (any-pointer: coarse) {
  /* Echo Maze: a direction pad (PING in the middle, SNEAK in the corner) beside the maze */
  body.ls-play > .touch-pad:not(.blocks-pad) {
    display: grid !important;
    grid-template-columns: repeat(3, min(64px, 17vh));
    grid-template-rows: repeat(3, min(64px, 17vh));
    gap: 6px;
  }
  body.ls-play > .touch-pad:not(.blocks-pad) button {
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    padding: 0;
  }
  body.ls-play > .touch-pad [data-dir="up"] { grid-area: 1 / 2; }
  body.ls-play > .touch-pad [data-dir="left"] { grid-area: 2 / 1; }
  body.ls-play > .touch-pad [data-dir="right"] { grid-area: 2 / 3; }
  body.ls-play > .touch-pad [data-dir="down"] { grid-area: 3 / 2; }
  body.ls-play > .touch-pad .ping { grid-area: 2 / 2; min-width: 0; font-size: 11px; }
  body.ls-play > .touch-pad .sneak { grid-area: 3 / 3; font-size: 10px; }
}

@media (orientation: landscape) and (max-height: 520px) and (any-pointer: coarse) {
  /* Elemyth: two columns of move buttons that share the screen's height, in a column of their
     own on the right; the picture takes the rest of the width */
  body.ls-play:has(> .move-pad) {
    --pad-w: clamp(176px, 25vw, 240px);
    grid-template-columns: minmax(0, 1fr) auto var(--pad-w);
  }
  body.ls-play:has(> .move-pad) .screen #game {
    max-width: calc(100vw - var(--pad-w) - 44px) !important;
  }
  body.ls-play:has(> .move-pad) > .screen {
    align-self: start;
  }
  body.ls-play > .move-pad {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: minmax(0, 1fr);
    gap: 6px;
  }
  body.ls-play > .move-pad button {
    min-height: 0;
    font-size: clamp(12px, 1.75vw, 16px);
  }
  body.ls-play > .move-pad button.long-name {
    font-size: clamp(10.5px, 1.5vw, 15px);
  }
  body.ls-play > .move-pad button .key .ic {
    font-size: 17px;
    line-height: 1;
  }
}

@media (orientation: landscape) and (max-height: 520px) and (any-pointer: coarse) {
  /* ...using the whole column, and starting below the settings button in the corner */
  body.ls-play > .move-pad {
    justify-self: stretch;
    align-self: start;
    margin-top: 60px;
    height: calc(100vh - 68px);
    height: calc(100dvh - 68px);
  }
  body.ls-play > .move-pad button {
    width: 100%;
  }
}
