/* Chess on short phones, landscape phones, desktop and TV
   (docs/PLATFORM_RULES.md 6 and 7). Sizes elsewhere are in rem, so the root
   font size below scales the whole page with the screen height. */

/* Phones up to ~720px tall: the start card drops its pitch and tightens up so
   the play button stays above the bottom 40px. */
@media (max-height: 720px) {
  .ch-start-card {
    padding: 0.75rem 0.875rem;
  }

  .ch-logo {
    display: none;
  }

  .ch-title {
    margin: 0 0 0.375rem;
    font-size: 1.6rem;
  }

  .ch-pitch {
    display: none;
  }

  .ch-field {
    margin-bottom: 0.5rem;
  }

  .ch-option {
    min-height: 2.5rem;
    padding: 0.25rem 0.375rem;
  }

  .ch-button {
    min-height: 2.75rem;
    padding: 0.5rem 1rem;
  }

  .ch-button-resume {
    margin-bottom: 0.5rem;
  }

  .ch-slider {
    --thumb: 1.5rem;
  }

  .ch-tick {
    min-height: 1.75rem;
  }
}

/* Landscape phones (~360px tall): a shorter header, the start card in two
   columns (title + resume on the left, choices + play on the right). */
@media (orientation: landscape) and (max-height: 500px) {
  .game-nav {
    height: 48px;
  }

  .ch-start {
    padding-top: 8px;
  }

  .ch-start-card {
    display: grid;
    grid-template-columns: minmax(0, 0.7fr) minmax(0, 2fr);
    grid-template-areas: "head fields" "head play";
    align-items: center;
    column-gap: 1rem;
    width: min(100%, 46rem);
  }

  .ch-start-head {
    grid-area: head;
  }

  .ch-start-fields {
    grid-area: fields;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 0.75rem;
  }

  .ch-start-card > .ch-button {
    grid-area: play;
  }

  .ch-label {
    margin-bottom: 0.25rem;
    font-size: 0.7rem;
  }

  .ch-option {
    min-height: 2.25rem;
    font-size: 0.85rem;
  }

  .ch-level-record {
    display: none;
  }

  .ch-stage {
    padding-top: 6px;
  }

  .ch-bar {
    min-height: 2.75rem;
    padding: 0.25rem 0.5rem;
  }

  .ch-action {
    min-height: 2.5rem;
  }

  .ch-end-actions {
    margin-top: 0.5rem;
  }
}

/* Desktop and TV, 960x540 up to 3840x2160: everything grows with the screen
   height, stays 3% away from the edges (TV overscan), and the start card
   uses the two-column layout. */
@media (min-width: 960px) and (min-height: 500px) {
  html {
    font-size: max(16px, 2.3dvh);
  }

  .game-nav {
    height: auto;
    padding: 3dvh max(3vw, env(safe-area-inset-right, 0px)) 1dvh
      max(3vw, env(safe-area-inset-left, 0px));
  }

  .back-button,
  .options-button {
    width: max(36px, 6dvh);
    height: max(36px, 6dvh);
    font-size: max(1rem, 3dvh);
  }

  .back-button svg,
  .options-button svg {
    width: 50%;
    height: 50%;
  }

  .options-panel-sheet {
    max-width: min(92vw, 30rem);
  }

  .ch-start,
  .ch-stage {
    padding: 2dvh max(3vw, env(safe-area-inset-right, 0px)) max(40px, 4dvh)
      max(3vw, env(safe-area-inset-left, 0px));
  }

  .ch-start-card {
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 2fr);
    grid-template-areas: "head fields" "head play";
    align-items: center;
    column-gap: 1.5rem;
    width: min(100%, 52rem);
  }

  .ch-start-head {
    grid-area: head;
  }

  .ch-start-fields {
    grid-area: fields;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 1rem;
  }

  .ch-start-card > .ch-button {
    grid-area: play;
  }

  .ch-sq:focus-visible {
    outline-width: max(3px, 0.5dvh);
    outline-offset: calc(-1 * max(3px, 0.5dvh));
  }
}

/* TV remote: a thick, high-contrast ring on the focused control. */
html.tv :focus {
  outline: max(3px, 0.4dvh) solid #ffcc00 !important;
  outline-offset: max(2px, 0.3dvh);
}

html.tv .ch-sq:focus {
  outline-offset: calc(-1 * max(3px, 0.4dvh));
}
