/* Screen-size adjustments: short phones, short landscape phones (start card
   in two columns), desktop and TV (header scaled, 3% overscan, sizes that
   follow the screen up to 3840x2160). Loaded after the other stylesheets. */
:focus-visible,
html.tv :focus {
  outline: max(3px, 0.4dvh) solid #ffd54a;
  outline-offset: max(2px, 0.3dvh);
}

.tp-counts {
  flex-wrap: nowrap;
}

/* Two names per row from 320px wide. */
.tp-names {
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
}

/* Phones: the pitch line gives way so the start button stays on screen. */
@media (max-height: 720px) {
  .tp-pitch {
    display: none;
  }

  .tp-logo {
    font-size: 1.8rem;
  }

  .tp-mode {
    min-height: 0;
    padding: 6px;
  }

  .tp-mode-info {
    font-size: 0.72rem;
  }

  /* With Resume on top, the mode lines give way to the start button. */
  .tp-card:has(.tp-resume:not([hidden])) .tp-mode-info {
    display: none;
  }

  .tp-resume {
    margin: 0 0 10px;
    padding: 10px;
  }

  .tp-card {
    padding: 12px;
  }

  .tp-card p,
  .tp-modes,
  .tp-counts {
    margin-bottom: 8px;
  }

  .tp-names {
    gap: 6px;
    margin-bottom: 10px;
  }

  .tp-name-input {
    min-height: 40px;
  }
}

/* A card taller than the screen scrolls from its top, never cut off. */
.tp-start {
  place-items: safe center;
}

/* Landscape phones are ~360px tall: settings right, title and buttons left. */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --tp-nav-h: 52px;
  }

  .tp-start {
    padding-top: 0;
  }

  .tp-card {
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    grid-auto-flow: row dense;
    align-content: center;
    align-items: center;
    column-gap: 14px;
    width: 100%;
    padding: 10px 12px;
  }

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

  .tp-card > .tp-label,
  .tp-card > .tp-modes,
  .tp-card > .tp-names {
    grid-column: 2;
  }

  /* The player count sits under the title, left; start ends the right
     column under the names. */
  .tp-card > .tp-label:has(+ .tp-counts),
  .tp-card > .tp-counts {
    grid-column: 1;
  }

  .tp-card > .tp-button {
    grid-column: 2;
    justify-self: center;
  }

  .tp-card > .tp-label:has(+ .tp-counts) {
    margin-top: 4px;
  }

  .tp-logo {
    font-size: 1.4rem;
  }

  .tp-card > .tp-button {
    min-height: 40px;
  }

  .game-nav {
    height: 52px;
  }

  /* Question card: tight text, the actions and language pots on one row. */
  .tp-overlay {
    padding-top: 4px;
  }

  .tp-qcard {
    width: min(100%, 44rem);
    padding: 6px 12px 8px;
    border-top-width: 6px;
  }

  .tp-qtext {
    margin: 4px 0 6px;
    font-size: 1rem;
  }

  .tp-qanswer {
    margin-bottom: 6px;
    padding: 4px 8px;
  }

  .tp-qanswer-text {
    font-size: 1rem;
  }

  .tp-qinfo {
    margin-top: 2px;
    font-size: 0.8rem;
  }

  .tp-qactions {
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
  }

  .tp-qactions .tp-button {
    min-height: 40px;
    padding: 6px 10px;
  }

  .tp-qlangs {
    flex: 0 1 auto;
  }
}

/* A card taller than its overlay scrolls from its top. */
.tp-overlay {
  place-items: safe center;
}

@media (orientation: landscape) and (max-height: 500px) {
  .tp-qtag {
    margin-top: 2px;
  }

  .tp-card p,
  .tp-modes,
  .tp-counts,
  .tp-names {
    margin-bottom: 6px;
  }

  .tp-mode-info {
    display: none;
  }

  .tp-card > .tp-label {
    margin-bottom: 2px;
    font-size: 0.85rem;
  }

  .tp-mode {
    padding: 4px;
    font-size: 0.85rem;
  }

  .tp-mode,
  .tp-chip,
  .tp-name-input {
    min-height: 40px;
  }

  .tp-name-input {
    padding: 4px 8px;
  }

  .tp-chip {
    min-width: 0;
    flex: 1 1 0;
    padding: 6px 4px;
  }

  .tp-names {
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: 6px;
  }

  .tp-resume {
    margin: 0 0 8px;
    padding: 8px;
  }
}

/* Desktop and TV, 960x540 up to 3840x2160. */
@media (min-width: 960px) and (min-height: 500px) {
  :root {
    --tp-nav-h: calc(4dvh + max(36px, 6dvh));
  }

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

  .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;
  }

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

  .tp-card {
    width: min(100%, 34rem);
    border-radius: 1.2rem;
  }

  .tp-chip,
  .tp-mode,
  .tp-name-input {
    min-height: 2.6em;
  }

  .tp-chip {
    min-width: 2.6em;
  }

  .tp-panel {
    width: clamp(210px, 30vw, 34rem);
  }

  .tp-die {
    width: 3em;
    height: 3em;
  }

  .tp-player-pawn svg {
    width: 1.5em;
    height: 1.5em;
  }

  .tp-qcard {
    width: min(100%, 40rem);
  }

  .tp-qclose,
  .tp-pot {
    width: 2em;
    height: 2em;
  }

  .tp-pot {
    font-size: 0.75rem;
  }
}
