/* Wordtris shares the site's tokens and the duel rules in duels.css, so it reads as a sibling of Tug of Word. */
@layer components  {
  /* Match page */
  .wt  {
    display: block;
    max-width: var(--game-max);
    margin: 0 auto;
    padding: var(--s4) var(--s5) var(--s6);
  }
  .wt-boards  {
    display: grid;
    grid-template-areas: "opponent" "you";
    gap: var(--s3);
  }
  .wt-side[data-side="you"]  {
    grid-area: you;
    display: grid;
    justify-items: center;
    gap: var(--s2);
  }
  /* On a phone the opponent's small live board sits at the right of their name. */
  .wt-side[data-side="opponent"]  {
    grid-area: opponent;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto 1fr;
    column-gap: var(--s4);
    align-items: start;
  }
  .wt-side[data-side="opponent"] .wt-mini-wrap  {
    grid-column: 2;
    grid-row: 1 / span 2;
  }
  .wt .player-line  {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--s2) var(--s4);
    margin: 0;
    font-size: var(--text-sm);
  }
  .wt .player-rating, .wt .player-words, .wt .player-word  {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
  }
  .wt .player-away  {
    flex-basis: 100%;
    color: var(--progress);
    font-weight: var(--weight-bold);
  }
  .wt-play  {
    display: grid;
    grid-template-columns: auto auto;
    align-items: start;
    gap: var(--s3);
  }
  .wt .board-wrap  {
    position: relative;
  }
  /* On a phone the board leaves room beside it for the pieces, and below it for the strip and the buttons. */
  .wt-board  {
    display: grid;
    grid-template-columns: repeat(var(--wt-columns), 1fr);
    grid-template-rows: repeat(var(--wt-rows), 1fr);
    width: max(160px, min(calc(100vw - 2 * var(--s5) - 72px - var(--s3)), calc((100dvh - 19rem) / 2), 360px));
    aspect-ratio: 1 / 2;
    container-type: inline-size;
    border: var(--stroke) solid var(--line);
    border-radius: var(--radius-card);
    background: var(--surface);
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
  .wt-board:focus-visible  {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
  }
  .wt-cell  {
    display: grid;
    place-items: center;
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px var(--surface);
    /* Half a cell's width, so the letters grow with the board. */
    font: 700 clamp(0.625rem, 100cqi / 16, 1.25rem) var(--font-mono);
    color: var(--ink);
  }
  .wt-cell[data-look="empty"]  {
    box-shadow: inset 0 0 0 0.5px var(--line);
  }
  .wt-cell[data-look="letter"]  {
    background: var(--surface-2);
  }
  .wt-cell[data-look="piece"]  {
    background: var(--word);
    color: var(--on-accent);
  }
  .wt-cell[data-look="ghost"]  {
    box-shadow: inset 0 0 0 2px var(--word);
    color: transparent;
  }
  .wt-cell[data-look="lit"]  {
    background: var(--correct);
    color: var(--on-accent);
    animation: wt-flash 400ms ease-in-out;
  }
  .wt-cell[data-look="junk"], .wt-cell[data-look="broken"]  {
    background: repeating-linear-gradient(45deg, var(--muted) 0 3px, var(--line) 3px 6px);
  }
  .wt-cell[data-look="broken"]  {
    opacity: 0.4;
  }
  .wt-cell[data-look="wild"]  {
    background: var(--surface-2);
    color: var(--accent);
  }
  .wt-cell[data-look="bomb"]  {
    background: var(--surface-2);
  }
  /* The tiles a lock at the ghost would clear. A ghost square shows its letter, so the player can read the word. */
  .wt-cell[data-preview="true"]  {
    box-shadow: inset 0 0 0 2px var(--correct);
  }
  .wt-cell[data-look="ghost"][data-preview="true"]  {
    background: color-mix(in srgb, var(--correct) 15%, transparent);
    color: var(--correct);
  }
  .wt-board[data-mini="true"]  {
    width: 72px;
    border-radius: 6px;
  }
  .wt-board[data-mini="true"] .wt-cell  {
    font-size: 0;
    border-radius: 1px;
  }
  .wt-pieces  {
    display: grid;
    gap: var(--s3);
  }
  .wt-preview  {
    margin: 0;
    font-size: var(--text-xs);
    color: var(--muted);
  }
  .wt-preview-box  {
    display: grid;
    grid-template-columns: repeat(4, 18px);
    grid-auto-rows: 18px;
    margin-top: var(--s1);
  }
  /* As wide as the piece boxes above it, so a long word wraps rather than push the board aside. */
  .wt-clears-words  {
    width: 72px;
    min-height: 1.25rem;
    margin: var(--s1) 0 0;
    overflow-wrap: anywhere;
    color: var(--correct);
    font: 700 var(--text-xs) var(--font-mono);
  }
  .wt-preview-box .wt-cell  {
    font-size: 0.625rem;
  }
  .wt-preview-box .wt-cell[data-look="empty"]  {
    box-shadow: none;
  }
  .wt-warning  {
    display: flex;
    align-items: center;
    gap: var(--s2);
    min-height: 1.25rem;
    font-size: var(--text-xs);
    color: var(--progress);
  }
  .wt-warning-rows  {
    flex: none;
    width: calc(var(--wt-junk) * 6px);
    height: 10px;
    border-radius: 2px;
    background: repeating-linear-gradient(90deg, var(--progress) 0 4px, transparent 4px 6px);
  }
  /* One line only: a second line would push the power-ups off a phone's screen. The help gives way before the word. */
  .wt-warning-text, .wt-warning-help  {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .wt-warning-help  {
    flex-shrink: 1000;
    color: var(--muted);
  }
  .wt-controls  {
    display: grid;
    grid-template-columns: repeat(6, minmax(var(--tap), 1fr));
    gap: var(--s2);
    width: min(100%, 420px);
  }
  .wt-controls .button  {
    min-width: 0;
    padding-inline: 0;
    touch-action: manipulation;
  }
  .wt-powers  {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s2);
    width: min(100%, 420px);
  }
  .wt-powers .power-button  {
    min-width: 0;
    touch-action: manipulation;
  }
  .wt-powers .power-button[data-armed="true"]  {
    box-shadow: inset 0 0 0 2px var(--accent);
    color: var(--accent);
  }
  .wt-powers .power-slot  {
    display: grid;
    place-items: center;
    min-height: var(--tap);
    border: 1px dashed var(--line);
    border-radius: var(--radius-card);
    color: var(--muted);
    font-size: var(--text-sm);
  }
  .wt-mini-wrap  {
    position: relative;
  }
  .wt .freeze-sign  {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--accent);
    font: 700 var(--text-sm) var(--font-mono);
    pointer-events: none;
  }
  .wt .freeze-sign[data-side="opponent"]  {
    top: 2px;
    right: 2px;
    padding: 0 4px;
    font-size: var(--text-xs);
  }
  .wt .float-word  {
    position: absolute;
    top: 35%;
    left: 50%;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--correct);
    font: 700 var(--text-lg) var(--font-mono);
    white-space: nowrap;
    pointer-events: none;
    animation: wt-float 1500ms ease-out forwards;
  }
  .wt .countdown  {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font: 700 5rem var(--font-display);
    color: var(--accent);
    background: color-mix(in srgb, var(--surface) 70%, transparent);
    pointer-events: none;
  }
  .how-picture .tile.piece  {
    background: var(--word);
    color: var(--on-accent);
  }
  .how-picture .tile.junk  {
    background: repeating-linear-gradient(45deg, var(--muted) 0 3px, var(--line) 3px 6px);
  }
  .how-picture[data-picture="piece"]  {
    display: grid;
    grid-template-columns: repeat(3, 36px);
  }
  @media (min-width: 960px)  {
    .wt-boards  {
      grid-template-areas: "you opponent";
      grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
      align-items: start;
      gap: var(--s7);
    }
    .wt-side[data-side="opponent"]  {
      grid-template-columns: minmax(0, 1fr);
      justify-items: center;
      gap: var(--s2);
    }
    .wt-side[data-side="opponent"] .wt-mini-wrap  {
      grid-column: auto;
      grid-row: auto;
    }
    .wt-board, .wt-board[data-mini="true"]  {
      width: clamp(200px, calc((100dvh - 16rem) / 2), 360px);
      border-radius: var(--radius-card);
    }
    .wt-board[data-mini="true"] .wt-cell  {
      font: 700 clamp(0.625rem, 100cqi / 16, 1.25rem) var(--font-mono);
      border-radius: 4px;
    }
  }
  @keyframes wt-float  {
    0%  {
      opacity: 0;
      transform: translate(-50%, 8px);
    }
    15%  {
      opacity: 1;
      transform: translate(-50%, 0);
    }
    100%  {
      opacity: 0;
      transform: translate(-50%, -64px);
    }
  }
  @keyframes wt-flash  {
    from  {
      box-shadow: inset 0 0 0 1px var(--surface);
    }
    to  {
      box-shadow: inset 0 0 0 3px var(--progress);
    }
  }
  @media (prefers-reduced-motion: reduce)  {
    .wt *, .wt *::before, .wt *::after  {
      animation: none;
      transition: none;
      scroll-behavior: auto;
    }
    .wt .float-word  {
      opacity: 1;
      transform: translate(-50%, 0);
    }
  }
}
