/* Screen-size adjustments, loaded last: focus ring, landscape phones (start
   card in two columns), desktop and TV (header scaled, 3% overscan, sizes
   that follow the screen up to 3840x2160). */
html {
  font-size: clamp(16px, 2.4vmin, 64px);
}

:focus-visible,
html.tv :focus,
.sc-app button:focus-visible,
.sc-app input:focus-visible {
  outline: max(3px, 0.4dvh) solid #d08a2e;
  outline-offset: max(2px, 0.3dvh);
}

/* A board cell's ring stays inside the cell, above its neighbours. */
.sc-cell:focus-visible,
html.tv .sc-cell:focus {
  z-index: 3;
  outline-offset: -1px;
}

/* Phones: the start card is tighter so Start stays above the 40px margin
   when Resume shows. */
@media (max-height: 720px) {
  .sc-card {
    padding: 16px 16px;
  }

  .sc-logo {
    margin-bottom: 10px;
  }

  .sc-field {
    margin-bottom: 12px;
  }

  .sc-button-resume {
    margin-bottom: 8px;
  }
}

/* Landscape phones are ~360px tall. */
@media (orientation: landscape) and (max-height: 500px) {
  .game-nav {
    height: 52px;
  }

  .sc-start {
    padding-top: 4px;
  }

  /* Start card in two columns: logo, resume and start on the left, the
     settings on the right. */
  .sc-card {
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    grid-auto-flow: dense;
    align-content: center;
    align-items: center;
    column-gap: 16px;
    width: 100%;
    max-width: 680px;
    padding: 10px 14px;
  }

  .sc-card > * {
    grid-column: 1;
  }

  .sc-card > .sc-field {
    grid-column: 2;
    margin-bottom: 4px;
  }

  .sc-logo {
    margin-bottom: 10px;
  }

  .sc-label {
    margin-bottom: 2px;
  }

  .sc-option,
  .sc-input {
    min-height: 38px;
    padding-block: 4px;
  }

  .sc-tick {
    min-height: 30px;
  }

  .sc-record {
    margin-top: 2px;
  }

  .sc-button {
    min-height: 44px;
    padding: 8px 14px;
  }

  .sc-sheet {
    padding-top: 8px;
  }

  .sc-slider {
    --thumb: 24px;
  }

  .sc-input {
    min-height: 34px;
  }

  .sc-names {
    gap: 4px;
  }

  .sc-sheet-card {
    padding: 12px 16px 10px;
  }

  .sc-sheet-title {
    margin-bottom: 4px;
    font-size: 1.1rem;
  }

  .sc-sheet-note {
    margin-bottom: 8px;
  }

  .sc-swap-tiles {
    margin-bottom: 8px;
    padding-top: 4px;
  }

  .sc-sheet-card {
    width: min(100%, 560px);
  }

  .sc-bag-letters {
    gap: 4px 8px;
    margin-bottom: 8px;
  }

  .sc-bag-item .sc-tile {
    width: 26px;
    height: 26px;
  }

  .sc-sheet-card > .sc-button {
    min-height: 40px;
    padding: 6px 10px;
  }

  /* Sheet buttons side by side. */
  .sc-sheet-actions {
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    align-items: center;
    gap: 8px;
  }

  .sc-sheet-actions .sc-button {
    min-height: 40px;
    padding: 6px 10px;
    font-size: 0.95rem;
  }

  /* Play: the side column must fit in ~270px above the 40px margin. */
  .sc-stage {
    padding-top: 4px;
    row-gap: 4px;
  }

  .sc-top {
    flex-wrap: nowrap;
    gap: 4px;
  }

  .sc-player {
    flex-basis: 0;
    min-height: 36px;
    padding: 2px 8px;
  }

  .sc-player-score {
    font-size: 1.1rem;
  }

  .sc-top .sc-bag {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 2px 6px;
  }

  .sc-bag-text small {
    display: none;
  }

  .sc-info {
    min-height: 2.2em;
    font-size: 0.8rem;
  }

  .sc-rack {
    min-height: 0;
    padding: 3px;
    gap: 4px;
    grid-template-columns: repeat(var(--rack, 7), minmax(0, 36px));
  }

  .sc-slot {
    font-size: 16px;
  }

  .sc-actions {
    gap: 4px;
  }

  .sc-action,
  .sc-play {
    min-height: 38px;
  }

  .sc-action {
    flex-direction: row;
    gap: 4px;
  }

  .sc-action svg {
    width: 16px;
    height: 16px;
  }
}

/* Wide desktop and TV: the side column grows with the screen. */
@media (min-width: 960px) and (min-height: 500px) and (min-aspect-ratio: 6/5) {
  .sc-stage {
    grid-template-columns: minmax(0, 1fr) minmax(250px, 34vw);
    column-gap: 2vw;
  }
}

/* Desktop and TV, 960x540 up to 3840x2160. */
@media (min-width: 960px) and (min-height: 500px) {
  .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%;
  }

  .nav-title {
    font-size: 1.2rem;
  }

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

  .sc-card {
    width: min(100%, 30rem);
    padding: 1.2rem 1.2rem;
  }

  .sc-logo {
    font-size: 1.1rem;
  }

  .sc-logo .sc-tile {
    width: calc((100% - 28px) / 8);
  }

  .sc-chip,
  .sc-option,
  .sc-input,
  .sc-tick {
    min-height: 2.5em;
    font-size: 1rem;
  }

  .sc-slider {
    --thumb: 1.9rem;
    --track: 0.6rem;
  }

  .sc-button {
    min-height: max(52px, 6dvh);
    font-size: 1.1rem;
  }

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

  .sc-player,
  .sc-bag {
    min-height: max(48px, 6dvh);
  }

  .sc-player-name,
  .sc-info {
    font-size: 0.95rem;
  }

  .sc-player-score {
    font-size: 1.4rem;
  }

  .sc-bag svg {
    width: 1.3rem;
    height: 1.3rem;
  }

  .sc-bag-text small {
    font-size: 0.7rem;
  }

  .sc-rack {
    grid-template-columns: repeat(var(--rack, 7), minmax(0, 3.6rem));
    gap: 0.4rem;
    padding: 0.4rem;
  }

  .sc-slot {
    font-size: 1.5rem;
  }

  .sc-action,
  .sc-play {
    min-height: max(52px, 7dvh);
  }

  .sc-action {
    font-size: 0.75rem;
  }

  .sc-action svg {
    width: 1.3rem;
    height: 1.3rem;
  }

  .sc-play {
    font-size: 1.1rem;
  }

  .sc-play small {
    font-size: 0.85rem;
  }

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

  .sc-sheet-card {
    width: min(100%, 28rem);
  }

  .sc-pick {
    min-height: 2.6rem;
  }

  .sc-picks {
    grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr));
  }

  .sc-swap-tiles {
    grid-template-columns: repeat(var(--rack, 7), minmax(0, 3rem));
  }

  .sc-swap-tiles .sc-slot {
    font-size: 1.3rem;
  }

  .sc-ghost {
    width: 3.2rem;
    height: 3.2rem;
    margin: -1.6rem 0 0 -1.6rem;
    font-size: 1.4rem;
  }
}
