/* Clean Sweep's board, after the prototype the owner approved. The board box is size + 1 cells wide: half a cell of
   ghost edge on each side. The nine word colours are WordColours.Palette by index. The dark theme uses the palette as
   it is. The light theme uses the same hues in deeper shades, with white as slate, so every outline shows on a light
   page and touching words stay as far apart (master plan open question 9). */
@layer base  {
  :root, [data-theme="light"]  {
    --cs-board: var(--surface-2);
    --cs-tile: var(--surface);
    --cs-c0: #dc2626;
    --cs-c1: #d97706;
    --cs-c2: #eab308;
    --cs-c3: #16a34a;
    --cs-c4: #06b6d4;
    --cs-c5: #2563eb;
    --cs-c6: #9333ea;
    --cs-c7: #f472b6;
    --cs-c8: #334155;
    --cs-hint: #b45309;
    --cs-trace: #a5b4fc;
    --cs-seat-0: var(--accent);
    --cs-seat-1: #cf6732;
    --cs-seat-2: #b0307a;
    --team-seat-0: var(--cs-seat-0);
    --team-seat-1: var(--cs-seat-1);
    --team-seat-2: var(--cs-seat-2);
  }
  [data-theme="dark"]  {
    --cs-board: var(--bg);
    --cs-tile: var(--surface-3);
    --cs-c0: #ef4444;
    --cs-c1: #f59e0b;
    --cs-c2: #fde047;
    --cs-c3: #22c55e;
    --cs-c4: #22d3ee;
    --cs-c5: #3b82f6;
    --cs-c6: #a855f7;
    --cs-c7: #f9a8d4;
    --cs-c8: #f8fafc;
    --cs-hint: #facc15;
    --cs-trace: #3b5bdb;
  }
  @media (prefers-color-scheme: dark)  {
    :root:not([data-theme])  {
      --cs-board: var(--bg);
      --cs-tile: var(--surface-3);
      --cs-c0: #ef4444;
      --cs-c1: #f59e0b;
      --cs-c2: #fde047;
      --cs-c3: #22c55e;
      --cs-c4: #22d3ee;
      --cs-c5: #3b82f6;
      --cs-c6: #a855f7;
      --cs-c7: #f9a8d4;
      --cs-c8: #f8fafc;
      --cs-hint: #facc15;
      --cs-trace: #3b5bdb;
    }
  }
}

@layer components  {
  .cs-board  {
    position: relative;
    width: min(100%, 420px);
    aspect-ratio: 1;
    margin-inline: auto;
    overflow: hidden;
    border-radius: 10px;
    background: var(--cs-board);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    container-type: inline-size;
  }
  /* No step joins the cells across a corner, so the corners of the ghost edge stay blank. The mask sits above the
     layer and does not slide, so a corner stays blank while the letters slide under it. */
  .cs-board::after  {
    --cs-corner: calc(50% / var(--n));
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background:
      linear-gradient(var(--cs-board), var(--cs-board)) left top / var(--cs-corner) var(--cs-corner) no-repeat,
      linear-gradient(var(--cs-board), var(--cs-board)) right top / var(--cs-corner) var(--cs-corner) no-repeat,
      linear-gradient(var(--cs-board), var(--cs-board)) left bottom / var(--cs-corner) var(--cs-corner) no-repeat,
      linear-gradient(var(--cs-board), var(--cs-board)) right bottom / var(--cs-corner) var(--cs-corner) no-repeat;
    pointer-events: none;
  }
  .cs-layer  {
    --cell: calc(100cqw / var(--n));
    --bw: max(3px, calc(var(--cell) * 0.08));
    position: absolute;
    inset: 0;
    will-change: transform;
  }
  .cs-row  {
    display: contents;
  }
  .cs-cell  {
    position: absolute;
    left: calc((var(--c) + 0.5) * 100% / var(--n));
    top: calc((var(--r) + 0.5) * 100% / var(--n));
    width: calc(100% / var(--n));
    height: calc(100% / var(--n));
    display: flex;
    align-items: center;
    justify-content: center;
    --cs-bg: var(--cs-tile) padding-box;
    --cs-line: transparent;
    --cs-ink: var(--ink);
    border: 2px solid var(--cs-line);
    border-radius: 8px;
    background: var(--cs-bg);
    color: var(--cs-ink);
    font: 750 calc(var(--cell) * 0.5) / 1 var(--font);
  }
  .cs-cell:focus-visible  {
    z-index: 1;
    outline: 3px solid var(--focus);
    outline-offset: -3px;
  }
  .cs-cell.ghost  {
    padding: 2px 4px;
    opacity: 0.38;
    font-size: calc(var(--cell) * 0.38);
  }
  .cs-cell.g-up  {
    align-items: flex-end;
  }
  .cs-cell.g-down  {
    align-items: flex-start;
  }
  .cs-cell.g-left  {
    justify-content: flex-end;
  }
  .cs-cell.g-right  {
    justify-content: flex-start;
  }
  [data-colour="0"]  { --wc: var(--cs-c0); }
  [data-colour="1"]  { --wc: var(--cs-c1); }
  [data-colour="2"]  { --wc: var(--cs-c2); }
  [data-colour="3"]  { --wc: var(--cs-c3); }
  [data-colour="4"]  { --wc: var(--cs-c4); }
  [data-colour="5"]  { --wc: var(--cs-c5); }
  [data-colour="6"]  { --wc: var(--cs-c6); }
  [data-colour="7"]  { --wc: var(--cs-c7); }
  [data-colour="8"]  { --wc: var(--cs-c8); }
  /* A shown word fills its cells edge to edge and borders only the sides where another word begins. */
  .cs-cell[data-colour]  {
    --cs-bg: color-mix(in srgb, var(--wc) 22%, transparent);
    --cs-line: var(--wc);
    border-width: 0;
    border-radius: 0;
  }
  .cs-cell.e-t  { border-top-width: var(--bw); }
  .cs-cell.e-r  { border-right-width: var(--bw); }
  .cs-cell.e-b  { border-bottom-width: var(--bw); }
  .cs-cell.e-l  { border-left-width: var(--bw); }
  .cs-patch  {
    position: absolute;
    width: var(--bw);
    height: var(--bw);
    background: var(--wc);
  }
  .cs-patch.tl  { top: 0; left: 0; }
  .cs-patch.tr  { top: 0; right: 0; }
  .cs-patch.bl  { bottom: 0; left: 0; }
  .cs-patch.br  { bottom: 0; right: 0; }
  /* In Versus the claimer's seat colour fills the word and the word's colour draws its outline. */
  .cs-cell[data-seat="1"]  {
    --cs-bg: color-mix(in srgb, var(--accent) 34%, transparent);
  }
  .cs-cell[data-seat="2"]  {
    --cs-bg: color-mix(in srgb, var(--progress) 34%, transparent);
  }
  /* A team's mark: a corner triangle for the first seat, a dot for the second and a square for the third, so colour is
     not the only sign. */
  .cs-mark  {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 9px;
    height: 9px;
  }
  .cs-mark[data-seat="0"]  {
    background: var(--cs-seat-0);
    clip-path: polygon(0 0, 100% 0, 0 100%);
  }
  .cs-mark[data-seat="1"]  {
    border-radius: 50%;
    background: var(--cs-seat-1);
  }
  .cs-mark[data-seat="2"]  {
    width: 7px;
    height: 7px;
    background: var(--cs-seat-2);
  }
  .cs-cell.hinted  {
    outline: 3px dashed var(--cs-hint);
    outline-offset: -3px;
  }
  .cs-cell.lit::after  {
    content: "";
    position: absolute;
    inset: 10%;
    border: 3px solid var(--accent);
    border-radius: 50%;
  }
  .cs-cell.traced  {
    --cs-bg: var(--accent) padding-box;
    --cs-ink: var(--on-accent);
  }
  .cs-cell.ghost.traced  {
    opacity: 0.55;
  }
  .cs-traced  {
    pointer-events: none;
  }
  /* The edge target under a resting finger. It fills over the dwell, and then the board slides (spec section 4.2).
     With reduced motion it shows full at once, and the dwell still runs. */
  .cs-dwell  {
    position: absolute;
    left: calc((var(--c) + 0.5) * 100% / var(--n));
    top: calc((var(--r) + 0.5) * 100% / var(--n));
    width: calc(100% / var(--n));
    height: calc(100% / var(--n));
    pointer-events: none;
  }
  .cs-dwell::before  {
    content: "";
    position: absolute;
    inset: 0;
    border: 2px solid var(--accent);
    border-radius: 6px;
    background: linear-gradient(color-mix(in srgb, var(--accent) 45%, transparent), color-mix(in srgb, var(--accent) 45%, transparent)) no-repeat;
    background-size: 100% 100%;
    animation: cs-dwell-across var(--dwell) linear;
  }
  .cs-dwell.g-down::before  { bottom: 50%; }
  .cs-dwell.g-up::before  { top: 50%; }
  .cs-dwell.g-right::before  { right: 50%; animation-name: cs-dwell-down; }
  .cs-dwell.g-left::before  { left: 50%; animation-name: cs-dwell-down; }
  @keyframes cs-dwell-across  {
    from  { background-size: 0 100%; }
  }
  @keyframes cs-dwell-down  {
    from  { background-size: 100% 0; }
  }
  @media (prefers-reduced-motion: reduce)  {
    .cs-dwell::before  {
      animation: none;
    }
  }
  .cs-trace  {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
  }
  .cs-trace polyline  {
    fill: none;
    stroke: var(--cs-trace);
    stroke-width: 0.16px;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.75;
  }
  /* The word list: Relaxed shows one box per letter, shortest word first, down two columns; a found word fills its
     boxes in its colour. --rows comes from the markup, so the first column holds the first half of the list. */
  .cs-words  {
    display: grid;
    gap: var(--s2);
    justify-items: center;
    margin-block: var(--s3);
  }
  .cs-word-list  {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(var(--rows), auto);
    justify-items: start;
    gap: var(--s3) var(--s6);
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .cs-word  {
    display: flex;
    gap: 3px;
  }
  .cs-word span  {
    display: grid;
    place-items: center;
    width: 1.25rem;
    height: 1.5rem;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    font: 700 var(--text-sm) var(--font-mono);
  }
  .cs-word[data-found] span  {
    border-color: var(--wc);
    background: color-mix(in srgb, var(--wc) 22%, transparent);
  }
  /* Challenging's longer words do not fit two to a row on a phone, so the full list on See board takes one column. */
  @media (width < 440px)  {
    .cs-word-list[data-reveal]  {
      grid-auto-flow: row;
      grid-template-rows: none;
    }
  }
  /* A word nobody found, shown on See board: its letters in dashed boxes, so it reads apart from the finds. */
  .cs-word[data-missed] span  {
    border-style: dashed;
    border-color: var(--wc);
    color: var(--muted);
  }
  .cs-word-count  {
    margin: 0;
    color: var(--muted);
  }
  .cs-example  {
    width: min(100%, 200px);
    margin: var(--s4) auto;
  }
  /* "See board" draws each word's path over its outline. */
  .cs-paths  {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
  }
  .cs-paths polyline  {
    fill: none;
    stroke: var(--wc);
    stroke-width: 0.1px;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.85;
  }
  /* The daily page. The board sits high, so a long wrapped drag has room below it on a phone (spec section 4.2). */
  .clean-sweep  {
    max-width: 720px;
  }
  .clean-sweep .game-intro  {
    margin-bottom: var(--s4);
  }
  .clean-sweep .scorebar  {
    max-width: var(--play-max);
    margin: var(--s4) auto;
    gap: var(--s5);
  }
  .clean-sweep .scorebar p  {
    margin: 0;
  }
  .clean-sweep .timer  {
    font-size: var(--text-lg);
    font-variant-numeric: tabular-nums;
  }
  .cs-bonus-time  {
    color: var(--accent);
  }
  .cs-bonus-time small  {
    font-size: var(--text-xs);
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  .cs-hint  {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s2);
    margin: 0 auto var(--s4);
  }
  .cs-hint button  {
    display: flex;
    align-items: center;
    gap: var(--s4);
    min-height: 44px;
  }
  .cs-hint button small  {
    white-space: nowrap;
  }
  .cs-board-frame  {
    max-width: var(--play-max);
    margin-inline: auto;
    text-align: center;
  }
  .cs-slide  {
    display: flex;
    gap: var(--s2);
  }
  .cs-slide .button  {
    width: var(--tap);
    padding: 0;
    font-size: 1.125rem;
  }
  .cs-board-frame .trace-letters  {
    margin-top: var(--s4);
  }
  .cs-pause-frame  {
    width: min(100%, 420px);
    aspect-ratio: 1;
    margin: var(--s6) auto;
  }
  .clean-sweep .play-actions  {
    display: flex;
    justify-content: center;
    gap: var(--s4);
    margin-block: var(--s6);
  }
  .clean-sweep .play-actions button  {
    min-height: 44px;
  }
  /* Each refused word switches between two identical animations, so the shake starts again. */
  .cs-board-frame.shake-odd .cs-board  {
    animation: cs-shake-odd 320ms ease;
  }
  .cs-board-frame.shake-even .cs-board  {
    animation: cs-shake-even 320ms ease;
  }
  @keyframes cs-shake-odd  {
    20%, 60%  { transform: translateX(-6px); }
    40%, 80%  { transform: translateX(6px); }
  }
  @keyframes cs-shake-even  {
    20%, 60%  { transform: translateX(-6px); }
    40%, 80%  { transform: translateX(6px); }
  }
  @media (prefers-reduced-motion: reduce)  {
    .cs-board-frame .cs-board  {
      animation: none;
    }
  }
  /* Versus. Seat One is the accent and seat Two the progress colour, as in every duel, with a triangle and a dot so
     colour is not the only sign. */
  .cs-versus  {
    display: grid;
    gap: var(--s3);
    max-width: var(--game-max);
    margin: 0 auto;
    padding: var(--s4) var(--s5) var(--s6);
  }
  .cs-scores  {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: stretch;
    gap: var(--s2);
    max-width: 420px;
    width: 100%;
    margin-inline: auto;
  }
  .cs-player  {
    position: relative;
    display: grid;
    align-content: center;
    gap: 2px;
    margin: 0;
    padding: var(--s2) var(--s3) var(--s2) var(--s6);
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    font-size: var(--text-sm);
    min-width: 0;
  }
  .cs-player:nth-of-type(2)  {
    order: 3;
  }
  .cs-player .player-name  {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .cs-player .player-rating  {
    color: var(--muted);
    font-size: var(--text-xs);
  }
  .cs-player .player-score  {
    font: 700 var(--text-lg) var(--font-mono);
  }
  .cs-player .player-score small  {
    color: var(--muted);
    font: 400 var(--text-xs) var(--font);
  }
  .cs-player[data-side="you"][data-seat="1"]  {
    background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  }
  .cs-player[data-side="you"][data-seat="2"]  {
    background: color-mix(in srgb, var(--progress) 10%, var(--surface));
  }
  .cs-seat-mark  {
    position: absolute;
    top: 50%;
    left: var(--s2);
    width: 11px;
    height: 11px;
    translate: 0 -50%;
  }
  [data-seat="1"] > .cs-seat-mark  {
    background: var(--accent);
    clip-path: polygon(0 0, 100% 0, 0 100%);
  }
  [data-seat="2"] > .cs-seat-mark  {
    border-radius: 50%;
    background: var(--progress);
  }
  .cs-player .player-away  {
    color: var(--muted);
    font-size: var(--text-xs);
  }
  .cs-match  {
    order: 2;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 2px;
    margin: 0;
    padding-inline: var(--s2);
    font-size: var(--text-xs);
    color: var(--muted);
  }
  .cs-match .timer  {
    color: var(--ink);
    font: 700 var(--text-lg) var(--font-mono);
    font-variant-numeric: tabular-nums;
  }
  /* A grid item with auto margins shrinks to its content, and the board's size comes from its container, not its
     content, so the frame takes the full width. */
  .cs-versus .cs-board-frame  {
    width: 100%;
  }
  .cs-versus-board, .cs-board-stage  {
    position: relative;
  }
  .cs-versus .float-word  {
    position: absolute;
    top: 40%;
    left: 50%;
    z-index: 2;
    translate: -50% 0;
    padding: var(--s1, 4px) var(--s3);
    border-radius: var(--radius-card);
    background: var(--accent);
    color: var(--on-accent);
    font: 700 var(--text-lg) var(--font-mono);
    pointer-events: none;
    animation: cs-float 1500ms ease-out forwards;
  }
  .cs-versus .float-word[data-seat="2"]  {
    background: var(--progress);
  }
  .cs-versus .countdown  {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: grid;
    place-items: center;
    max-width: 420px;
    margin-inline: auto;
    font: 700 4rem var(--font-mono);
    color: var(--accent);
    pointer-events: none;
  }
  .cs-versus .board-status  {
    min-height: 1.5rem;
    margin: 0;
    text-align: center;
  }
  .cs-claims, .cs-versus .replay-words-title  {
    max-width: 420px;
    width: 100%;
    margin-inline: auto;
  }
  .cs-claims li  {
    align-items: baseline;
    padding-left: var(--s3);
    border-left: 4px solid var(--wc);
  }
  .cs-claims li[data-seat="1"] .word-player  {
    color: var(--accent);
  }
  .cs-claims li[data-seat="2"] .word-player  {
    color: var(--progress);
  }
  /* The words nobody claimed, listed once a Versus match ends, apart from the claims. */
  .cs-missed li  {
    border-left-style: dashed;
    color: var(--muted);
  }
  .cs-claims .word-points  {
    margin-left: auto;
    font-family: var(--font-mono);
  }
  .cs-replay .cs-versus-board .cs-board  {
    pointer-events: none;
  }
  /* The Versus head has no glyph, so its text takes the whole row. */
  /* The daily leaderboards link ends Play solo, so Play a bot below it starts a new part of the page. */
  .cs-daily-leaders  {
    display: inline-block;
    margin-bottom: var(--s8);
  }
  @keyframes cs-float  {
    from  {
      opacity: 1;
      translate: -50% 0;
    }
    to  {
      opacity: 0;
      translate: -50% -2.5rem;
    }
  }
  @media (prefers-reduced-motion: reduce)  {
    .cs-versus .float-word  {
      animation: none;
    }
  }
}

@layer states  {
  /* The site gives every control with tabindex 0 a hover and pressed look. The focused cell keeps its own. */
  .cs-board .cs-cell[tabindex="0"]  {
    transition: none;
  }
  .cs-board .cs-cell[tabindex="0"]:is(:hover, :active)  {
    border-color: var(--cs-line);
    background: var(--cs-bg);
    color: var(--cs-ink);
    box-shadow: none;
    transform: none;
  }
  :root[data-contrast="true"] .cs-layer  {
    --bw: max(4px, calc(var(--cell) * 0.1));
  }
  :root[data-contrast="true"] .cs-cell.hinted  {
    outline-width: 4px;
  }
  @media (forced-colors: active)  {
    .cs-board::after  {
      --cs-board: Canvas;
      forced-color-adjust: none;
    }
    .cs-cell[data-colour]  {
      --cs-line: CanvasText;
    }
    .cs-patch  {
      background: CanvasText;
    }
    .cs-cell.traced  {
      --cs-bg: Highlight;
      --cs-ink: HighlightText;
      forced-color-adjust: none;
    }
    .cs-cell.hinted  {
      outline-color: Highlight;
    }
  }
}
