/* Tug of Word shares the site's tokens and Slirdle's dialog, results and button rules, so the games read as siblings. */
@layer components  {
  /* Start screen */
  /* Match page */
  .tow  {
    display: block;
    max-width: var(--game-max);
    margin: 0 auto;
    padding: var(--s4) var(--s5) var(--s6);
    --tow-cell-ink: var(--ink);
  }
  .tow-boards  {
    display: grid;
    grid-template-areas: "opponent" "meter" "you";
    gap: var(--s3);
  }
  .tow-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. */
  .tow-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;
  }
  .tow-side[data-side="opponent"] .tow-board  {
    grid-column: 2;
    grid-row: 1 / span 2;
  }
  .tow .player-line  {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--s2) var(--s4);
    margin: 0;
    font-size: var(--text-sm);
  }
  .tow .player-rating, .tow .player-momentum  {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
  }
  .tow .player-away  {
    flex-basis: 100%;
    color: var(--progress);
    font-weight: var(--weight-bold);
  }
  .tug-meter  {
    grid-area: meter;
    display: grid;
    gap: var(--s2);
    justify-items: center;
    font-size: var(--text-xs);
    color: var(--muted);
  }
  .tug-meter .meter-track  {
    position: relative;
    width: min(100%, 320px);
    height: 8px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--progress-soft), var(--surface-2) 50%, var(--done-soft));
  }
  /* -8 is a knockout of this player, 8 a knockout of the opponent. */
  .tug-meter .meter-mark  {
    position: absolute;
    top: -4px;
    left: calc(50% + (var(--barrier) * 6.25%) - 3px);
    width: 6px;
    height: 16px;
    border-radius: 3px;
    background: var(--ink);
    transition: left 240ms ease;
  }
  .tow .board-wrap  {
    position: relative;
    width: 100%;
    display: grid;
    justify-items: center;
  }
  /* The board keeps 7 by 12 square cells. On a phone it grows to the full width for big tiles, but only as tall as
     leaves the traced letters, the board and Send on one screen, and never below tiles of 38px. The opponent and the
     meter scroll above it. */
  .tow-board  {
    position: relative;
    width: clamp(min(100%, calc(7 * 38px + 2 * var(--stroke))), calc((100dvh - 1.75rem - var(--tap) - 4 * var(--s2)) * 7 / 12), min(100%, 420px));
    aspect-ratio: 7 / 12;
    container-type: inline-size;
    border: var(--stroke) solid var(--line);
    border-radius: var(--radius-card);
    background-color: var(--surface);
    background-image: linear-gradient(var(--line) 1px, transparent 1px);
    background-size: 100% calc(100% / 12);
    /* The board fills most of a phone's screen, so its empty rows still scroll the page. Only a tile starts a trace. */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    overflow: visible;
  }
  .tow-board:focus-visible  {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
  }
  .tow-board .ceiling  {
    position: absolute;
    inset: 0 0 auto 0;
    height: calc((12 - var(--ceiling)) / 12 * 100%);
    border-bottom: 3px solid var(--progress);
    background: repeating-linear-gradient(135deg, transparent 0 6px, var(--progress-soft) 6px 10px);
    transition: height 240ms ease;
    pointer-events: none;
  }
  .tow-board .tile  {
    position: absolute;
    left: 0;
    bottom: 0;
    display: grid;
    place-items: center;
    width: calc(100% / 7);
    height: calc(100% / 12);
    transform: translate(calc(var(--c) * 100%), calc(var(--r) * -100%));
    transition: transform 180ms ease;
    border-radius: 6px;
    box-shadow: inset 0 0 0 2px var(--surface);
    background: var(--surface-2);
    color: var(--tow-cell-ink);
    /* Half the tile's width, so the letters grow with the tiles. */
    font: 700 clamp(0.75rem, 100cqi / 14, 1.75rem) var(--font-mono);
    cursor: pointer;
  }
  .tow-board .tile.frozen  {
    background: #cfe6fb;
    color: #0b3a66;
    box-shadow: inset 0 0 0 2px var(--surface), inset 0 0 0 4px #7fb7e8;
    cursor: not-allowed;
  }
  .tow-board .tile.frozen::after  {
    content: "❄";
    position: absolute;
    top: 1px;
    right: 3px;
    font-size: 0.5em;
  }
  .tow-board .tile.glitch  {
    background: repeating-linear-gradient(45deg, var(--ink) 0 4px, var(--muted) 4px 8px);
    cursor: not-allowed;
  }
  /* A squeezed tile flashes an outline on a layer of its own, so a frame changes only its opacity. The opponent's small
     board and a paused replay show the outline still. */
  .tow-board.squeezing:not(.mini) .tile[data-over]::before  {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: inset 0 0 0 4px var(--progress);
    pointer-events: none;
    animation: tow-flash 500ms ease-in-out infinite alternate;
  }
  .tow-replay[data-playing="false"] .tow-board .tile[data-over]::before  {
    animation: none;
  }
  .tow-board.squeezing.mini .tile[data-over]  {
    box-shadow: inset 0 0 0 1px var(--progress);
  }
  .tow-board.shake-odd  {
    animation: tow-shake-odd 320ms ease;
  }
  .tow-board.shake-even  {
    animation: tow-shake-even 320ms ease;
  }
  /* The opponent's live view: blocks only, too small for letters to matter. */
  .tow-board.mini  {
    width: 64px;
    border-radius: 6px;
    cursor: default;
  }
  .tow-board.mini .tile  {
    font-size: 0;
    border-radius: 2px;
    box-shadow: inset 0 0 0 1px var(--surface);
    cursor: default;
  }
  .tow-board.mini .tile.frozen::after  {
    content: none;
  }
  .tow-board.mini .ceiling  {
    border-bottom-width: 2px;
  }
  .tow .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: tow-float 1500ms ease-out forwards;
  }
  .tow .float-word .float-sweep  {
    display: block;
    color: var(--accent);
    font-size: var(--text-base);
    text-align: center;
  }
  .tow .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;
  }
  .tow .squeeze-warning  {
    margin: 0;
    color: var(--progress);
    font-weight: var(--weight-bold);
    font-size: var(--text-sm);
  }
  .warning-strip  {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s2) var(--s3);
    min-height: 24px;
    font-size: var(--text-xs);
    color: var(--muted);
  }
  .warning-strip ol  {
    display: flex;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .warning-strip .hazard-mark  {
    display: block;
    width: 18px;
    height: 18px;
    border-radius: 4px;
  }
  .warning-strip [data-hazard="frozen"] .hazard-mark  {
    background: #cfe6fb;
    box-shadow: inset 0 0 0 2px #7fb7e8;
  }
  .warning-strip [data-hazard="glitch"] .hazard-mark  {
    background: repeating-linear-gradient(45deg, var(--ink) 0 3px, var(--muted) 3px 6px);
  }
  .how-picture .tile.traced  {
    background: var(--correct);
    color: var(--on-correct);
  }
  .how-picture .tile.frozen  {
    background: #cfe6fb;
    color: #0b3a66;
    box-shadow: inset 0 0 0 2px #7fb7e8;
  }
  .how-picture .tile.glitch  {
    background: repeating-linear-gradient(45deg, var(--ink) 0 4px, var(--muted) 4px 8px);
  }
  .how-picture .how-ceiling  {
    position: absolute;
    inset: -6px -6px auto;
    border-top: 3px solid var(--progress);
  }
  /* From 960px the opponent's board is shown at full size beside the player's. */
  @media (min-width: 960px)  {
    .tow-boards  {
      grid-template-areas: "you meter opponent";
      grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
      align-items: start;
      gap: var(--s7);
    }
    .tow-side[data-side="opponent"]  {
      display: grid;
      grid-template-columns: minmax(0, 1fr);
      justify-items: center;
      gap: var(--s2);
    }
    .tow-side[data-side="opponent"] .player-line  {
      min-height: calc(1.75rem + var(--s2) + 1.25rem);
      align-content: start;
    }
    .tow-side[data-side="opponent"] .tow-board  {
      grid-column: auto;
      grid-row: auto;
    }
    .tow-board, .tow-board.mini  {
      width: clamp(min(100%, calc(7 * 38px + 2 * var(--stroke))), calc((100dvh - 260px - var(--tap) - var(--s2)) * 7 / 12), min(100%, 420px));
      border-radius: var(--radius-card);
    }
    .tow-board.mini .tile  {
      font: 700 clamp(0.75rem, 100cqi / 14, 1.75rem) var(--font-mono);
      border-radius: 6px;
      box-shadow: inset 0 0 0 2px var(--surface);
    }
    .tug-meter  {
      align-self: center;
      width: 120px;
    }
    .tug-meter .meter-track  {
      width: 100%;
    }
  }
  /* Motion */
  @keyframes tow-float  {
    0%  {
      opacity: 0;
      transform: translate(-50%, 8px);
    }
    15%  {
      opacity: 1;
      transform: translate(-50%, 0);
    }
    100%  {
      opacity: 0;
      transform: translate(-50%, -64px);
    }
  }
  @keyframes tow-flash  {
    from  {
      opacity: 0;
    }
    to  {
      opacity: 1;
    }
  }
  @keyframes tow-shake-odd  {
    25%, 75%  {
      translate: calc(-1 * var(--s2)) 0;
    }
    50%  {
      translate: var(--s2) 0;
    }
  }
  @keyframes tow-shake-even  {
    25%, 75%  {
      translate: calc(-1 * var(--s2)) 0;
    }
    50%  {
      translate: var(--s2) 0;
    }
  }
  @media (prefers-reduced-motion: reduce)  {
    .tow *, .tow *::before, .tow *::after  {
      animation: none;
      transition: none;
      scroll-behavior: auto;
    }
    .tow .float-word  {
      opacity: 1;
      transform: translate(-50%, 0);
    }
  }
}
