/*
 * The page of online games, play.html, on top of style.css: the views around the game (loading,
 * invitation of the host, invitation of the guest, a game that is no longer there), the presence
 * of the players, the connection, the aim of the opponent, the dialog of an opponent who left, and
 * the end of a round with its score and its rematch. From the screens 08 to 13, 16 and 20 of
 * docs/design/.
 */

/* What the script hides stays hidden, whatever the display of its class, such as a button. */
[hidden] {
  display: none !important;
}

/* The views of the page: one at a time, centered under the header. */
.online-screen {
  flex: 1;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 40px 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.online-intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.online-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.online-lead {
  max-width: 520px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text-secondary);
  text-wrap: balance;
}

.screen-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.screen-button {
  width: 100%;
  min-height: 52px;
}

.screen-note {
  font-size: 13px;
  color: var(--color-text-muted);
  text-align: center;
}

/* The presence of a player: a green dot while online, a grey one once away. */
.presence,
.player-presence {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-online);
}

.presence::before,
.player-presence::before {
  content: '';
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px color-mix(in srgb, currentColor 70%, transparent);
}

.presence.is-offline,
.is-offline .player-presence {
  color: var(--color-text-muted);
}

.presence.is-offline::before,
.is-offline .player-presence::before {
  box-shadow: none;
}

/* Three dots that blink in turn, while the page waits for a player. */
.waiting-dots {
  display: inline-flex;
  gap: 4px;
  vertical-align: middle;
}

.waiting-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: waiting-dot 1.2s ease-in-out infinite;
}

.waiting-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.waiting-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes waiting-dot {
  0%,
  80%,
  100% {
    opacity: 0.3;
  }

  40% {
    opacity: 1;
  }
}

/* Loading: the two tokens, and what the page waits for. */
.loading-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
}

.loading-tokens {
  display: flex;
  gap: 12px;
}

.loading-tokens .token {
  --token-size: 28px;
  animation: loading-token 1.2s ease-in-out infinite alternate;
}

.loading-tokens .token + .token {
  animation-delay: 0.6s;
}

@keyframes loading-token {
  from {
    transform: translateY(0);
  }

  to {
    transform: translateY(-10px);
  }
}

.loading-text {
  font-size: 16px;
  color: var(--color-text-secondary);
}

/* The invitation of the guest (screen 08). */
.join-screen {
  max-width: 480px;
  gap: 28px;
}

.invitation-tokens {
  position: relative;
  width: 120px;
  height: 80px;
}

.invitation-token {
  --token-size: 72px;
  --glow-ratio: 0.42;
  position: absolute;
  left: 4px;
  top: 4px;
}

.invitation-ring {
  position: absolute;
  left: 48px;
  top: 4px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px dashed color-mix(in srgb, var(--color-yellow) 75%, transparent);
  background: var(--color-bg);
}

.seat-chips {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.seat-chip {
  min-width: 0;
  padding: 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  align-items: center;
  gap: 10px;
}

.seat-chip.is-you {
  border-color: color-mix(in srgb, var(--player-color) 55%, transparent);
  background: var(--color-surface-raised);
}

.seat-chip-token {
  --token-size: 26px;
  --glow-ratio: 0;
}

.seat-chip-name {
  font-size: 14px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.seat-chip .presence,
.seat-chip-detail {
  margin-top: 2px;
  font-size: 12px;
}

.seat-chip-detail {
  color: var(--color-text-muted);
}

.join-form {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 20px;
}

.join-form .screen-actions {
  margin-top: auto;
}

.button-join {
  gap: 10px;
  min-height: 54px;
  border-radius: var(--radius-lg);
  background: var(--color-yellow);
  color: var(--color-bg);
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--color-yellow) 25%, transparent);
}

/* The invitation of the host (screen 09). */
.online-title-large {
  font-size: 32px;
}

.invite-card {
  padding: 24px;
  border-radius: var(--radius-2xl);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.invite-link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.invite-link {
  flex: 1 1 280px;
  min-width: 0;
  height: 56px;
  padding: 0 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-strong);
  background: var(--color-bg);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--color-text-muted);
}

.invite-link-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text);
  user-select: all;
}

.copy-button {
  flex: 1 0 auto;
  min-height: 56px;
  padding: 0 20px;
  font-size: 15px;
}

.icon-button {
  width: 56px;
  min-height: 56px;
  padding: 0;
  border-radius: var(--radius-lg);
}

.invite-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.invite-divider::before,
.invite-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.code-tiles {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.code-tile {
  flex: 0 1 56px;
  aspect-ratio: 56 / 68;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-strong);
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
}

.invite-seats {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.invite-seat {
  min-width: 0;
  padding: 16px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  align-items: center;
  gap: 12px;
}

.invite-seat-waiting {
  border-style: dashed;
  border-color: var(--color-border-strong);
  background: none;
}

.invite-seat-token {
  --token-size: 36px;
  --glow-ratio: 0.5;
}

.invite-seat-ring {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px dashed color-mix(in srgb, var(--color-yellow) 70%, transparent);
}

.invite-seat-name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.invite-seat-name .player-you {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.invite-seat .presence,
.invite-seat-detail {
  margin-top: 4px;
  font-size: 13px;
}

.invite-seat-detail {
  color: var(--color-text-muted);
}

/* A game that is no longer there (screen 20): two dashed rings, broken. */
.unavailable-screen {
  max-width: 480px;
  justify-content: space-between;
}

.unavailable-screen .online-intro {
  flex: 1;
  justify-content: center;
}

.broken-link {
  position: relative;
  width: 140px;
  height: 96px;
  margin-bottom: 12px;
}

.broken-ring {
  position: absolute;
  top: 12px;
  left: 0;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px dashed var(--color-handle);
}

.broken-ring + .broken-ring {
  left: auto;
  right: 0;
}

.broken-icon {
  position: absolute;
  top: 27px;
  left: 49px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface-control);
  color: var(--color-text-secondary);
  display: grid;
  place-items: center;
}

/* The connection: a pill in the header of the game, a chip under the board on a narrow screen. */
.connection-pill,
.connection-chip {
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.connection-dot {
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--color-online);
  box-shadow: 0 0 8px color-mix(in srgb, var(--color-online) 70%, transparent);
}

.connection-pill.is-warning,
.connection-chip.is-warning {
  color: var(--color-warning);
}

.is-warning .connection-dot {
  background: var(--color-warning);
  box-shadow: 0 0 8px color-mix(in srgb, var(--color-warning) 70%, transparent);
}

[data-view="game"] .connection-chip {
  display: flex;
}

.online-game .connection-chip {
  grid-area: replay;
  align-self: end;
  justify-self: center;
  margin-top: 24px;
}

/* The game: the nickname with « (toi) » on a chip, and the aim of the opponent. */
.player-name-line {
  min-width: 0;
  overflow-wrap: anywhere;
}

.player-name-line .player-you {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.player-presence {
  display: none;
  margin-top: 10px;
}

.aim-pill {
  margin-top: 4px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--player-color) 10%, transparent);
  color: var(--player-color);
  font-size: 13px;
  font-weight: 600;
}

.online-game .play-hint-touch:empty {
  display: none;
}

/* The dialog of an opponent who left (screen 13), over the game blurred. */
.online-dialog {
  width: calc(100% - 40px);
  max-width: 460px;
  padding: 32px;
  border-radius: var(--radius-3xl);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface-dialog);
  box-shadow: var(--shadow-dialog);
  color: var(--color-text);
  text-align: center;
}

.online-dialog[open] {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.online-dialog::backdrop {
  background: var(--color-scrim);
  backdrop-filter: blur(6px);
}

.dialog-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--color-warning) 40%, transparent);
  background: color-mix(in srgb, var(--color-warning) 12%, transparent);
  color: var(--color-warning);
  display: grid;
  place-items: center;
}

.dialog-icon .icon {
  width: 28px;
  height: 28px;
}

.dialog-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.dialog-text {
  font-size: 15px;
  line-height: 1.55;
  color: var(--color-text-secondary);
}

.waiting-chip {
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.dialog-actions {
  width: 100%;
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.dialog-button {
  min-height: 48px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  font-size: 15px;
}

/* Narrow screens: the actions of a view at the bottom, and a smaller code. */
@media (max-width: 599px) {
  .online-screen {
    padding: 32px 24px 28px;
    gap: 24px;
  }

  .unavailable-screen .screen-actions,
  .join-form .screen-actions {
    margin-top: auto;
  }

  .code-tile {
    font-size: 22px;
  }

  .invite-seats {
    grid-template-columns: 1fr;
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }
}

/* Medium and wide screens: the connection in the header, larger titles. */
@media (min-width: 600px) {
  [data-view="game"] .connection-pill {
    display: flex;
  }

  [data-view="game"] .connection-chip {
    display: none;
  }

  .online-title {
    font-size: 36px;
  }

  .online-title-large {
    font-size: 48px;
    line-height: 1.05;
    letter-spacing: -0.03em;
  }

  .online-lead {
    font-size: 17px;
  }

  .code-tile {
    font-size: 30px;
  }

  .unavailable-screen {
    justify-content: center;
  }

  .unavailable-screen .online-intro {
    flex: 0 1 auto;
  }

  .unavailable-screen .screen-actions {
    flex-direction: row;
    justify-content: center;
  }

  .unavailable-screen .screen-button {
    width: auto;
    padding: 0 28px;
  }
}

/* Wide screens: the presence on the cards beside the board, without « (toi) ». */
@media (min-width: 960px) {
  .player-presence {
    display: flex;
  }

  .player-name-line .player-you {
    display: none;
  }
}

/*
 * The end of a round (screens 12 and 16): a trophy for the winner, the score, then « Retour à
 * l’accueil » and « Proposer une revanche », or the offer of the opponent. The actions take the
 * place of « Rejouer » in the grid of the game: at the bottom of a narrow screen, under the status
 * of a wider one.
 */
[data-state="won"] #leave-game,
[data-state="draw"] #leave-game {
  display: none;
}

.status-trophy {
  display: none;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--color-yellow);
}

[data-result="win"] .status-trophy {
  display: block;
}

[data-result="win"] .online-game .status-tokens,
[data-result="loss"] .online-game .status-tokens {
  display: none;
}

/* The score pill takes the place of the line of the winning cells, which screen readers keep. */
.online-game .status-detail {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.score-pill {
  margin-top: 4px;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.score-player {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
}

.score-name {
  max-width: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-dot {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--player-color);
}

.score-value {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.rematch-area {
  flex-direction: column;
  gap: 12px;
}

.end-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.end-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.end-button {
  min-height: 52px;
  padding: 0 22px;
  border-radius: var(--radius-lg);
  font-size: 16px;
  font-weight: 600;
}

.rematch-button {
  font-weight: 700;
}

/* The offer waits for the opponent: the button stays in the tab order, with its new label. */
.rematch-button[aria-disabled="true"] {
  background: var(--color-border-strong);
  color: var(--color-text-secondary);
  cursor: default;
  filter: none;
}

.text-button {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--color-text-secondary);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.text-button:hover {
  color: var(--color-text);
}

.rematch-note {
  font-size: 13px;
  color: var(--color-text-muted);
  text-align: center;
  text-wrap: balance;
}

.rematch-offer {
  padding: 16px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface-raised);
  box-shadow: var(--shadow-card-lift);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.rematch-offer-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rematch-offer-token {
  --token-size: 36px;
  --glow-ratio: 0;
}

.rematch-offer-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.rematch-offer-text {
  margin-top: 3px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.rematch-offer-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.rematch-offer-actions .button {
  min-height: 48px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  font-size: 15px;
}

.rematch-offer-actions .button-secondary {
  background: var(--color-surface);
  font-weight: 600;
}

/* A narrow screen keeps the bottom for the actions of the end, without the connection chip. */
@media (max-width: 599px) {
  [data-state="won"] .online-game .connection-chip,
  [data-state="draw"] .online-game .connection-chip {
    display: none;
  }
}

@media (min-width: 600px) {
  .status-trophy {
    width: 40px;
    height: 40px;
  }

  .score-pill {
    padding: 8px 18px;
    gap: 14px;
  }

  .score-player {
    gap: 8px;
    font-size: 15px;
  }

  .score-value {
    font-size: 22px;
  }

  .rematch-area {
    align-items: center;
    padding-top: 22px;
  }

  .end-actions {
    align-items: center;
  }

  .end-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 12px;
  }

  .end-button {
    min-height: 48px;
  }

  .rematch-button {
    padding: 0 24px;
  }

  .rematch-note {
    font-size: 14px;
  }

  .rematch-offer {
    width: min(100%, 440px);
  }
}

/*
 * Quitting a game (screens 17 and 18). « Quitter la partie » asks first, in a dialog that becomes
 * a bottom sheet on a narrow screen, whose « Quitter » takes the danger tone. The player whose
 * opponent quit reads it under an icon in their color, with « Nouvelle partie à distance » in
 * place of the rematch, and the board keeps its tokens bright: no line won.
 */
.button-danger {
  border-color: color-mix(in srgb, var(--color-danger) 50%, transparent);
  background: color-mix(in srgb, var(--color-danger) 10%, transparent);
  color: var(--color-danger-text);
  font-weight: 700;
}

.danger-icon {
  border-color: color-mix(in srgb, var(--color-danger) 45%, transparent);
  background: color-mix(in srgb, var(--color-danger) 12%, transparent);
  color: var(--color-danger);
}

.quit-dialog[open] {
  animation: quit-dialog-in var(--motion-dialog) ease-out;
}

.sheet-handle {
  display: none;
}

@keyframes quit-dialog-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
}

@keyframes quit-sheet-in {
  from {
    transform: translateY(100%);
  }
}

.forfeit-icon {
  display: none;
  width: 64px;
  height: 64px;
  margin-bottom: 4px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--player-color, var(--color-yellow)) 45%, transparent);
  background: color-mix(in srgb, var(--player-color, var(--color-yellow)) 12%, transparent);
  color: var(--player-color, var(--color-yellow));
  place-items: center;
}

.forfeit-icon .icon {
  width: 28px;
  height: 28px;
}

[data-end-reason="forfeit"] .forfeit-icon {
  display: grid;
}

[data-end-reason="forfeit"] .status-trophy,
[data-end-reason="forfeit"] .rematch-button,
[data-end-reason="forfeit"] .rematch-note {
  display: none;
}

/* The line under the status says that the player wins by forfeit, unlike a line that won. */
[data-end-reason="forfeit"] .online-game .status-detail {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  line-height: 1.5;
}

[data-end-reason="forfeit"] .cell:not(.winning-cell) .token {
  opacity: 1;
}

/* The opponent left for good: the connection no longer matters, and « Connexion interrompue »
 * would read as a fault of the network. */
[data-view="game"][data-end-reason="forfeit"] .connection-pill {
  display: none;
}

.new-online-game {
  display: none;
}

[data-end-reason="forfeit"] .new-online-game {
  display: inline-flex;
}

@media (max-width: 599px) {
  .quit-dialog {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    padding: 12px 24px 28px;
    border-width: 1px 0 0;
    border-radius: var(--radius-3xl) var(--radius-3xl) 0 0;
    box-shadow: var(--shadow-sheet);
  }

  .quit-dialog[open] {
    animation: quit-sheet-in var(--motion-sheet) ease-out;
  }

  .sheet-handle {
    display: block;
    width: 40px;
    height: 5px;
    margin-bottom: 8px;
    border-radius: 3px;
    background: var(--color-handle);
  }

  /* Screen 17 puts « Nouvelle partie à distance » first, above « Retour à l’accueil ». */
  [data-end-reason="forfeit"] .new-online-game {
    order: -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .quit-dialog[open] {
    animation: none;
  }
}
