/* Pencil Tic-Tac-Toe — graph-paper theme with light and dark palettes. */

*,
*::before,
*::after {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}

:root {
  --paper: #f6f7f2;
  --grid: #dde5e9;
  --margin: #e9afa6;
  --ink: #2a2e35;
  --muted: #5f666e; /* 4.97:1 on --chip, 5.4:1 on --paper */
  --x: #2447a8;
  --o: #c0392b;
  --hi: #fff1a0;
  --chip: #eceee6;
  --chip-on: #2a2e35;
  --chip-on-ink: #f6f7f2;
  --star: #9a6700;
  --ok: #1f7a43;
  --display: 'Caveat', 'Segoe Print', 'Bradley Hand', cursive;
  --body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
/* Arabic: Atkinson and Caveat have no Arabic letters, so the device's own
   Arabic font writes those (nothing more to download); Latin text such as
   the title keeps the site's fonts */
:root:lang(ar) {
  --display: 'Caveat', system-ui, 'Geeza Pro', 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  --body:
    'Atkinson Hyperlegible', system-ui, 'Geeza Pro', 'Noto Sans Arabic', 'Segoe UI', Tahoma,
    sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --paper: #1c2420;
    --grid: #26312c;
    --margin: #5b3833;
    --ink: #e4e8e1;
    --muted: #99a49e;
    --x: #93b5ff;
    --o: #ff8b7b;
    --hi: #4a4526;
    --chip: #25302b;
    --chip-on: #e4e8e1;
    --chip-on-ink: #1c2420;
    --star: #f2c14e;
    --ok: #6fd08f;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --paper: #1c2420;
  --grid: #26312c;
  --margin: #5b3833;
  --ink: #e4e8e1;
  --muted: #99a49e;
  --x: #93b5ff;
  --o: #ff8b7b;
  --hi: #4a4526;
  --chip: #25302b;
  --chip-on: #e4e8e1;
  --chip-on-ink: #1c2420;
  --star: #f2c14e;
  --ok: #6fd08f;
}

html,
body {
  min-height: 100%;
}
body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(
      90deg,
      transparent 0 calc(16px + 1.5rem),
      var(--margin) calc(16px + 1.5rem) calc(16px + 1.5rem + 2px),
      transparent 0
    ),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size:
    100% 100%,
    24px 24px,
    24px 24px;
  color: var(--ink);
  font: 16px/1.5 var(--body);
  padding-inline: 16px;
  padding-block: 28px 40px;
}

.sheet {
  max-width: 400px;
  margin: 0 auto;
  display: grid;
  gap: 20px;
}
.game-cols,
.side,
.stage {
  display: grid;
  gap: 20px;
  align-content: start;
  min-width: 0;
}
/* Wide screens: the choices and the lobby beside the board */
@media (min-width: 1000px) {
  .sheet {
    max-width: 1080px;
  }
  .sheet > header,
  .auth,
  .sheet > .loading,
  .site-footer {
    width: 100%;
    max-width: 440px;
    justify-self: center;
  }
  .sheet > header {
    max-width: 1080px;
  }
  .game-cols {
    grid-template-columns: minmax(340px, 400px) minmax(0, 560px);
    justify-content: center;
    gap: 48px;
  }
  .stage {
    position: sticky;
    top: 16px;
  }
  /* The board fits the screen's height, with the buttons under it in view */
  .stage .board,
  .stage .uboard-wrap {
    max-width: min(100%, calc(100vh - 400px));
    min-width: 300px;
  }
}

header {
  position: relative;
  display: grid;
  gap: 2px;
}
/* The theme switch and language menu, top right */
.top-tools {
  position: absolute;
  top: 0;
  inset-inline-end: 0;
  display: flex;
  gap: 6px;
  align-items: center;
}
.theme-btn {
  font: 700 1rem/1 var(--body);
  color: var(--ink);
  background: var(--chip);
  border: 2px solid transparent;
  border-radius: 999px;
  width: 34px;
  height: 30px;
  cursor: pointer;
}
.theme-btn:focus-visible {
  outline: none;
  border-color: var(--ink);
}
.lang-pick select {
  font: 700 0.8rem/1 var(--body);
  color: var(--ink);
  background: var(--chip);
  border: 2px solid transparent;
  border-radius: 999px;
  padding: 6px 8px;
}
.lang-pick select:focus-visible {
  outline: none;
  border-color: var(--ink);
}
h1 {
  font: 700 3.25rem/0.95 var(--display);
  margin: 0;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
h1 .x {
  color: var(--x);
}
h1 .o {
  color: var(--o);
}
.sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
}
.seg {
  display: inline-flex;
  background: var(--chip);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  font: 700 0.82rem/1 var(--body);
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}
.seg button[aria-pressed='true'],
.seg button[aria-selected='true'] {
  background: var(--chip-on);
  color: var(--chip-on-ink);
}
.seg button:focus-visible,
.actions button:focus-visible {
  outline: 2px dashed var(--ink);
  outline-offset: 2px;
}

.status {
  font: 700 2rem/1.1 var(--display);
  min-height: 2.2rem;
  margin: 0;
}
.status mark {
  background: linear-gradient(transparent 35%, var(--hi) 35% 88%, transparent 88%);
  color: inherit;
  padding: 0 4px;
}
.status .x {
  color: var(--x);
}
.status .o {
  color: var(--o);
}

/* Boards stay left to right in Arabic too: square 1 is top-left, the number
   keys match, and "row 2, column 3" means the same square */
.board,
.uboard {
  direction: ltr;
}
.board {
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.board > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.board .gridlines path {
  stroke: var(--ink);
  stroke-width: 3.2;
  fill: none;
  stroke-linecap: round;
}
.board .winline path {
  stroke: var(--ink);
  stroke-width: 6;
  fill: none;
  stroke-linecap: round;
  opacity: 0.85;
}

.cell {
  position: relative;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  border-radius: 10px;
}
.cell:disabled {
  cursor: default;
}
.cell:focus-visible {
  outline: 2px dashed var(--muted);
  outline-offset: -8px;
}
.cell svg {
  position: absolute;
  inset: 8%;
  width: 84%;
  height: 84%;
  overflow: visible;
}
.cell path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.cell .mx path {
  stroke: var(--x);
  stroke-width: 8;
}
.cell .mo path {
  stroke: var(--o);
  stroke-width: 7;
}
.cell .ghost {
  opacity: 0;
  transition: opacity 0.15s;
}
.cell:not(:disabled):hover .ghost {
  opacity: 0.18;
}

.draw {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: ink 0.28s ease-out forwards;
}
.draw.d2 {
  animation-delay: 0.16s;
}
.winline .draw {
  animation-duration: 0.45s;
  animation-delay: 0.25s;
}
@keyframes ink {
  to {
    stroke-dashoffset: 0;
  }
}
.ghost path {
  stroke-dasharray: none;
  stroke-dashoffset: 0;
  animation: none;
}

/* 3-mark rules: the mark that vanishes on its owner's next move */
.cell.fading svg:not(.ghost) {
  opacity: 0.3;
  transition: opacity 0.3s;
}
/* A hint: the square to try */
.cell.hinted {
  background: var(--hi);
  border-radius: 12px;
  animation: hint-pulse 1s ease-in-out 2;
}
@keyframes hint-pulse {
  50% {
    transform: scale(0.94);
  }
}
@media (prefers-reduced-motion: reduce) {
  .cell.hinted {
    animation: none;
  }
}

.board.won .cell:not(.hit) svg:not(.ghost) {
  opacity: 0.35;
  transition: opacity 0.4s 0.3s;
}

/* A win: the winning marks give a little jump, and pencil stars pop out */
.board.won .cell.hit svg {
  animation: hop 0.45s ease-in-out 0.75s 2;
}
@keyframes hop {
  50% {
    transform: translateY(-6%) rotate(-4deg);
  }
}
.confetti path {
  fill: none;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform-box: fill-box;
  transform-origin: center;
  opacity: 0;
  animation: pop 1.1s ease-out forwards;
}
.confetti .c0 {
  stroke: var(--x);
}
.confetti .c1 {
  stroke: var(--o);
}
.confetti .c2 {
  stroke: #e0a800;
}
@keyframes pop {
  0% {
    opacity: 0;
    transform: scale(0.2) rotate(-30deg);
  }
  25% {
    opacity: 1;
    transform: scale(1.15) rotate(0);
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(0.9) translateY(-14px) rotate(12deg);
  }
}

.scores {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.score {
  display: grid;
  gap: 4px;
  align-content: start;
}
.score .who {
  font: 700 0.72rem/1 var(--body);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.score .tally {
  min-height: 30px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.score .tally svg {
  width: 32px;
  height: 28px;
  overflow: visible;
}
.score .tally path {
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
}
.score.sx path {
  stroke: var(--x);
}
.score.so path {
  stroke: var(--o);
}
.score.sd path {
  stroke: var(--muted);
}
.score .n {
  font: 700 1.5rem/1 var(--display);
  color: var(--muted);
}
.score .zero {
  font: 500 1.25rem/1 var(--display);
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.actions button,
.btn {
  font: 700 0.9rem/1 var(--body);
  border-radius: 8px;
  padding: 11px 16px;
  cursor: pointer;
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
}
.actions .primary,
.btn.primary {
  background: var(--ink);
  color: var(--paper);
}
.actions .ghostbtn,
.btn.ghostbtn {
  background: transparent;
  color: var(--ink);
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.actions button:disabled,
.btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.btn:focus-visible {
  outline: 2px dashed var(--ink);
  outline-offset: 2px;
}

/* Online panel: a note pinned above the board */
.online {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 2px dashed var(--muted);
  border-radius: 10px;
  background: var(--paper);
}
.lobby {
  display: grid;
  gap: 10px;
}
.lobby-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}
.panel-title {
  font: 700 1.6rem/1 var(--display);
  margin: 0;
}
.panel-title .count {
  color: var(--muted);
  font-size: 1.2rem;
}
.filter {
  font: 0.9rem/1.2 var(--body);
  color: var(--ink);
  background: var(--chip);
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 6px 8px;
  max-width: 100%;
  min-width: 0;
}
.filter:focus {
  outline: none;
  border-color: var(--ink);
}
.players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  max-height: 320px;
  overflow-y: auto;
}
.player {
  display: flex;
  align-items: center;
  gap: 4px 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--grid);
  min-width: 0;
}
.player:last-child {
  border-bottom: 0;
}
.player .where {
  color: var(--muted);
  font-size: 0.8rem;
  margin-inline-end: auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player .btn {
  padding: 7px 12px;
  flex-shrink: 0;
}
.who-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.tag {
  font: 700 0.72rem/1 var(--body);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  flex-shrink: 0;
}
.empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Quick match, and "invite again" after a match */
.quick,
.rematch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.quick-note {
  color: var(--muted);
  font-size: 0.85rem;
}
.quick.searching .quick-note {
  color: var(--ink);
  font-weight: 700;
}
.quick .timer {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.rematch {
  padding: 10px 12px;
  border: 2px dashed var(--grid);
  border-radius: 10px;
}
.rematch-text {
  margin-inline-end: auto;
  min-width: 0;
}
/* A pencil going round in circles while we search */
.scribble {
  width: 18px;
  height: 18px;
  border: 3px solid var(--ink);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  flex-shrink: 0;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Invitations: notes stuck above the board, in every mode */
.invites {
  display: grid;
  gap: 8px;
}
.invite {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 10px 12px;
  background: var(--hi);
  border-radius: 10px;
}
.invite.outgoing {
  background: var(--chip);
}
.invite-text {
  margin-inline-end: auto;
  min-width: 0;
}
.invite .timer {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.85rem;
}
.invite .btn {
  padding: 8px 12px;
}
.opponent {
  font: 700 1.3rem/1 var(--display);
}
.room {
  display: grid;
  gap: 8px;
}
.room-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.room-head .who {
  font: 700 0.72rem/1 var(--body);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.room-head .btn {
  margin-inline-start: auto;
  padding-inline: 4px;
}
.room-role {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.net-msg {
  margin: 0;
  font-size: 0.85rem;
  color: var(--o);
}
.net-msg:empty {
  display: none;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}
kbd {
  font:
    0.75rem/1 ui-monospace,
    SFMono-Regular,
    Menlo,
    monospace;
  border: 1px solid var(--grid);
  border-radius: 4px;
  padding: 2px 5px;
  background: var(--chip);
}

/* Accounts: log-in and sign-up forms, account bar, profile dialog */
.loading {
  color: var(--muted);
  margin: 0;
}
.auth,
.game {
  display: grid;
  gap: 20px;
}
.auth .seg {
  justify-self: start;
}
.form {
  display: grid;
  gap: 14px;
}
.form > .btn {
  justify-self: start;
}
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 12px;
}
@media (max-width: 360px) {
  .pair {
    grid-template-columns: 1fr;
  }
}
.field {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.field > span {
  font: 700 0.72rem/1.2 var(--body);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.field em {
  font-style: normal;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
.field input,
.field select {
  font: 1rem/1.2 var(--body);
  color: var(--ink);
  background: var(--chip);
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 0 10px;
  height: 42px;
  width: 100%;
  min-width: 0;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--ink);
}
.field input[aria-invalid='true'],
.field select[aria-invalid='true'] {
  border-color: var(--o);
}
.help,
.privacy {
  color: var(--muted);
  font-size: 0.8rem;
}
.privacy {
  margin: 0;
}
.err,
.form-msg {
  color: var(--o);
  font-size: 0.85rem;
}
.err:empty,
.form-msg:empty {
  display: none;
}
.form-msg {
  margin: 0;
}
[role='status'].form-msg {
  color: var(--ink);
}

.account-bar {
  display: flex;
  align-items: center;
  gap: 4px 8px;
  flex-wrap: wrap;
}
.account-bar .me {
  margin-inline-end: auto;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
  overflow-wrap: anywhere;
}
.account-bar .btn {
  padding: 8px 6px;
}
.account-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
}
.menu-btn {
  display: none;
}
/* Phones: the links fold behind a Menu button */
@media (max-width: 640px) {
  .account-bar {
    position: relative;
    flex-wrap: nowrap;
  }
  .account-bar .me strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .menu-btn {
    display: inline-block;
  }
  .account-links {
    display: none;
    position: absolute;
    inset-inline-end: 0;
    top: 100%;
    z-index: 20;
    flex-direction: column;
    align-items: stretch;
    min-width: 180px;
    padding: 8px;
    background: var(--paper);
    border: 2px solid var(--ink);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
  }
  .account-links.open {
    display: flex;
  }
  .account-links .btn {
    text-align: start;
    padding: 10px 12px;
  }
}

/* Avatars: the picker on the sign-up and profile forms, and the face next
   to every player's name */
.avatar {
  font-size: 1.15em;
  line-height: 1;
  flex-shrink: 0;
}
.account-bar .avatar {
  font-size: 1.6rem;
}
.avatar-field {
  border: 0;
  margin: 0;
  padding: 0;
}
.avatar-field > legend {
  padding: 0;
  margin-bottom: 4px;
  font: 700 0.72rem/1.2 var(--body);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 6px;
  padding: 4px;
  border: 2px solid transparent;
  border-radius: 10px;
}
.avatar-field[aria-invalid='true'] .avatar-grid {
  border-color: var(--o);
}
.avatar-option {
  position: relative;
  display: grid;
  place-items: center;
  height: 46px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: var(--chip);
  cursor: pointer;
  transition: transform 0.12s;
}
.avatar-face {
  font-size: 1.6rem;
  line-height: 1;
}
.avatar-option:hover {
  transform: rotate(-6deg) scale(1.08);
}
.avatar-option:has(input:checked) {
  border-color: var(--ink);
  background: var(--hi);
}
.avatar-option:has(input:focus-visible) {
  outline: 2px solid var(--x);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .avatar-option {
    transition: none;
  }
  .avatar-option:hover {
    transform: none;
  }
}

/* Guests: the way in without an account, and what Online looks like to them */
.guest-locked {
  display: grid;
  gap: 8px;
  justify-items: start;
  padding: 16px;
  border: 2px dashed var(--muted);
  border-radius: 12px;
}
.guest-locked p {
  margin: 0;
}
.guest-locked-title {
  font: 700 1.5rem/1.1 var(--display);
}
.account-bar .btn.icon {
  font-size: 1.1rem;
  line-height: 1;
  text-decoration: none;
}

.dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 18px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
}
.dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.dialog h2,
.dialog h3 {
  font: 700 1.9rem/1 var(--display);
  margin: 0;
}
.dialog h3 {
  font-size: 1.5rem;
  margin: 24px 0 12px;
}

/* Stats dialog: number tiles, facts, opponents table, recent games */
.dialog.stats {
  width: min(520px, calc(100vw - 32px));
}
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(54px, 1fr));
  gap: 6px;
}
.tile {
  display: grid;
  gap: 2px;
  padding: 10px 4px 8px;
  background: var(--chip);
  border-radius: 10px;
  text-align: center;
}
.tile-value {
  font: 700 1.7rem/1 var(--display);
  font-variant-numeric: tabular-nums;
}
.tile-label {
  font: 700 0.68rem/1.2 var(--body);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 14px 0 0;
  font-size: 0.9rem;
}
.facts dt {
  color: var(--muted);
}
.facts dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th,
.table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--grid);
  text-align: start;
  font-weight: 400;
}
.table thead th {
  font: 700 0.68rem/1.2 var(--body);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.table tbody th {
  max-width: 0; /* take the room that's left, and cut long names */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.table .num {
  text-align: end;
  font-variant-numeric: tabular-nums;
  width: 3.5em;
}
.note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.history {
  list-style: none;
  margin: 0;
  padding: 0;
}
.history-item {
  display: grid;
  grid-template-columns: 3.4em 1fr;
  gap: 0 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--grid);
}
.history-item .outcome {
  grid-row: span 2;
  font: 700 1.25rem/1.1 var(--display);
}
.game-meta {
  color: var(--muted);
  font-size: 0.8rem;
}
.stats .btn.ghostbtn#moreHistory {
  margin-top: 8px;
}

/* Ratings: a small chip next to a name, and the points a round moved */
.rating-chip {
  font: 700 0.75rem/1 var(--body);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--chip);
  border-radius: 999px;
  padding: 3px 7px;
  flex-shrink: 0;
}
.delta {
  font: 700 0.85em/1 var(--body);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.delta.up {
  color: #2e7d32;
}
.delta.down {
  color: var(--o);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .delta.up {
    color: #7fd18a;
  }
}
:root[data-theme='dark'] .delta.up {
  color: #7fd18a;
}

/* Leaderboard dialog */
#leaderboardDialog .filter {
  width: 100%;
}
.lb-me {
  margin: 12px 0;
  font-weight: 700;
}
.lb-me:empty {
  display: none;
}
.table .rank {
  text-align: start;
  width: 2.5em;
  color: var(--muted);
}
.table tr.me {
  background: var(--hi);
}
#lbMore {
  margin-top: 8px;
}

@media (prefers-reduced-motion: reduce) {
  .confetti {
    display: none;
  }
  .board.won .cell.hit svg {
    animation: none;
  }
  .scribble {
    animation-duration: 3s;
  }
  .draw {
    animation: none;
    stroke-dashoffset: 0;
  }
  .board.won .cell:not(.hit) svg:not(.ghost) {
    transition: none;
  }
}

/* Rules: classic or 3 marks */
.rules-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.rule-note {
  margin: 0;
  flex: 1 1 200px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Replays */
.board.mini {
  width: min(260px, 100%);
  margin: 4px auto;
}
.board.mini .cell {
  cursor: default;
}
.still .draw {
  animation: none;
  stroke-dashoffset: 0;
}
.replay-who {
  margin: 0;
  font-weight: 700;
}
.replay-step {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}
.replay-controls {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}
.replay-btn {
  grid-column: 2;
  justify-self: start;
  margin-top: 4px;
  padding: 4px 8px;
  font-size: 0.85rem;
}

/* Online: the move clock, and reactions */
.turn-clock {
  margin: -8px 0 0;
  font: 700 0.9rem/1 var(--body);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.turn-clock.low {
  color: var(--o);
}
/* A ring that empties as the time for the move runs out */
.clock-ring {
  --left: 1;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: conic-gradient(currentColor calc(var(--left) * 360deg), var(--chip) 0);
  mask: radial-gradient(circle, transparent 5px, #000 6px);
  transition: background 0.25s linear;
}
.turn-clock.low .clock-ring {
  animation: tick 1s ease-in-out infinite;
}
@keyframes tick {
  50% {
    transform: scale(1.15);
  }
}
.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}
.btn.react {
  font-size: 1.2rem;
  line-height: 1;
  padding: 6px;
  text-decoration: none;
}
.reaction-feed {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.bubble {
  position: absolute;
  bottom: 10%;
  font-size: 2.6rem;
  animation: float-up 2.4s ease-out forwards;
}
.bubble.mine {
  inset-inline-start: 8%;
}
.bubble.theirs {
  inset-inline-end: 8%;
}
@keyframes float-up {
  0% {
    transform: translateY(20px) scale(0.6);
    opacity: 0;
  }
  15% {
    transform: translateY(0) scale(1.1);
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    transform: translateY(-120px) scale(1);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .bubble {
    animation: none;
  }
}

/* Recovery codes, and the account's danger zone */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.recovery-code {
  margin: 0;
  text-align: center;
}
.recovery-code code {
  display: inline-block;
  font:
    700 1.1rem/1.4 ui-monospace,
    'SF Mono',
    Menlo,
    monospace;
  letter-spacing: 0.04em;
  padding: 8px 12px;
  border: 2px dashed var(--ink);
  border-radius: 8px;
  background: var(--chip);
  user-select: all;
  overflow-wrap: anywhere;
}
.btn.danger {
  background: var(--o);
  border-color: var(--o);
  color: var(--paper);
}
a.btn {
  display: inline-block;
  justify-self: start;
  text-decoration: none;
}

/* Email confirmation banner */
.email-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 12px;
  border: 2px dashed var(--ink);
  border-radius: 10px;
  background: var(--hi);
}
.email-notice-text {
  margin: 0;
  flex: 1 1 220px;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}
.email-notice .btn {
  padding: 8px 12px;
}

/* Friends */
.friends {
  display: grid;
  gap: 8px;
}
.btn.star {
  font-size: 1.15rem;
  line-height: 1;
  padding: 4px 6px;
  text-decoration: none;
  flex-shrink: 0;
}
.btn.star[aria-pressed='true'] {
  color: var(--star);
}
.friend.is-offline .who-line {
  opacity: 0.55;
}
.friend.is-online .where::before {
  content: '● ';
  color: var(--ok);
}
.add-friend {
  display: flex;
  gap: 8px;
}
.add-friend input {
  flex: 1;
  min-width: 0;
  font: 1rem/1.2 var(--body);
  color: var(--ink);
  background: var(--chip);
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 0 10px;
  height: 40px;
}
.add-friend input:focus {
  outline: none;
  border-color: var(--ink);
}

/* Daily puzzle */
.puzzle-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: -8px;
}
.puzzle-note {
  margin: 0;
  flex: 1 1 200px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Seasons, on the leaderboard */
.lb-season {
  margin: 0;
  font-weight: 700;
}
.lb-podium {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: center;
  font-size: 0.9rem;
}
.podium-title {
  color: var(--muted);
}

/* Achievements */
.badges {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}
.badge {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px;
  border-radius: 10px;
  background: var(--chip);
}
.badge-emoji {
  font-size: 1.6rem;
  line-height: 1;
}
.badge-text {
  display: grid;
  gap: 2px;
  font-size: 0.8rem;
  color: var(--muted);
}
.badge-text strong {
  color: var(--ink);
  font-size: 0.9rem;
}
.badge.locked .badge-emoji {
  filter: grayscale(1);
  opacity: 0.45;
}
.badge-progress {
  font-weight: 700;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--hi);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.2);
  z-index: 10;
}
.toast.show {
  animation: toast-in 0.35s ease-out;
}
@keyframes toast-in {
  from {
    transform: translate(-50%, 20px);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .toast.show {
    animation: none;
  }
}

/* Privacy policy and terms */
.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}
.site-footer a,
.privacy a {
  color: inherit;
}
.dialog.legal p,
.dialog.legal li {
  font-size: 0.9rem;
  line-height: 1.5;
}
.dialog.legal ul {
  padding-inline-start: 1.2em;
  margin: 0;
}

/* The player menu: block and report */
.btn.more {
  padding: 4px 8px;
  text-decoration: none;
  font-weight: 700;
  flex-shrink: 0;
}
.choice {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.95rem;
  padding: 2px 0;
}
.field textarea {
  font: 1rem/1.3 var(--body);
  color: var(--ink);
  background: var(--chip);
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  resize: vertical;
}
.field textarea:focus {
  outline: none;
  border-color: var(--ink);
}
fieldset.field {
  border: 0;
  margin: 0;
  padding: 0;
}

/* Game analysis: the move that went wrong */
.cell.mistake {
  outline: 3px solid var(--o);
  outline-offset: -6px;
  border-radius: 12px;
}
.replay-note {
  margin: 0;
  font-size: 0.9rem;
  text-align: center;
}
.replay-note:empty {
  display: none;
}
#replayWhy {
  justify-self: center;
}

/* Watching a game */
.spectators {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}
body.spectating .cell {
  cursor: default;
}

/* Where you're logged in */
.sessions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.session {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--grid);
}
.session-what {
  display: grid;
  flex: 1;
}
.session-what small {
  color: var(--muted);
}

/* The sign-up form's field for bots: out of sight, out of reach */
.trap {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Admin dialog: reports and players with their actions, usage numbers */
.dialog.admin {
  width: min(720px, calc(100vw - 32px));
}
.dialog.admin .seg {
  margin-bottom: 12px;
}
.admin-list,
.admin-log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.admin-item {
  padding: 10px 12px;
  background: var(--chip);
  border-radius: 10px;
}
.admin-head,
.admin-meta {
  margin: 0;
}
.admin-meta {
  color: var(--muted);
  font-size: 0.85rem;
}
.admin-details {
  margin: 6px 0;
  padding-inline-start: 10px;
  border-inline-start: 3px solid var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.admin-actions select {
  font: inherit;
}
.btn.danger {
  color: var(--danger, #b3261e);
}
/* Admin dashboard: one card per part of the site, green, amber or red */
.dash-status {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--chip);
  font-weight: 700;
}
.dash-status[data-status='ok'] {
  box-shadow: inset 4px 0 0 var(--ok);
}
.dash-status[data-status='warn'] {
  box-shadow: inset 4px 0 0 var(--star);
}
.dash-status[data-status='bad'] {
  box-shadow: inset 4px 0 0 var(--o);
}
.dash-status small {
  display: block;
  font-weight: 400;
  color: var(--muted);
}
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.dash-card {
  padding: 10px 12px;
  background: var(--chip);
  border-radius: 10px;
}
.dash-card h4 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 4px;
  font-size: 0.95rem;
}
.dash-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  background: var(--ok);
}
.dash-dot[data-status='warn'] {
  background: var(--star);
}
.dash-dot[data-status='bad'] {
  background: var(--o);
}
.dash-why {
  margin: 0 0 4px;
  font-size: 0.85rem;
  font-weight: 700;
}
.dash-facts {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1px 10px;
  margin: 0;
  font-size: 0.85rem;
}
.dash-facts dt {
  color: var(--muted);
}
.dash-facts dd {
  margin: 0;
  text-align: end;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.admin-search {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.admin-search input {
  flex: 1 1 160px;
}
.admin-log {
  gap: 6px;
  font-size: 0.9rem;
}
.table-wrap {
  overflow-x: auto;
}
.usage-table .bar-cell {
  background: linear-gradient(to right, var(--chip) var(--bar), transparent var(--bar));
}
/* How-to-play guides: a practice board and the steps */
.dialog.guide {
  width: min(440px, calc(100vw - 32px));
}
.guide-btn {
  justify-self: start;
}
.guide-step {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.guide-text {
  min-height: 3em;
}
.guide-board {
  width: min(240px, 70vw);
  margin: 0 auto;
}
.guide-board .cell {
  border-color: var(--ink);
  border-style: solid;
  border-width: 0;
  border-radius: 0;
}
.guide-board .cell:nth-child(-n + 6) {
  border-bottom-width: 3px;
}
.guide-board .cell:not(:nth-child(3n)) {
  border-right-width: 3px;
}
.guide-board .cell.won {
  background: var(--chip);
}
.guide-uboard {
  width: min(360px, 80vw);
  margin: 0 auto;
}
.guide-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
}

/* The weekly arena in the lobby */
.arena {
  display: grid;
  gap: 6px;
  padding: 12px;
  background: var(--chip);
  border-radius: 12px;
}
.arena p {
  margin: 0;
}
.arena-me:empty {
  display: none;
}
.arena-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* The welcome above the log-in form */
.welcome {
  display: grid;
  gap: 10px;
  padding: 16px;
  background: var(--chip);
  border-radius: 14px;
}
.welcome-lead {
  margin: 0;
  font-size: 1.05rem;
}
.welcome-points {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.92rem;
}
.welcome-play {
  justify-self: start;
}

/* Placeholders while a list loads */
.skeletons {
  display: grid;
  gap: 8px;
  margin: 8px 0;
}
.skeletons span {
  display: block;
  height: 18px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--chip) 25%, var(--grid) 50%, var(--chip) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
.skeletons span:nth-child(2n) {
  width: 80%;
}
.skeletons span:nth-child(3n) {
  width: 60%;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .skeletons span {
    animation: none;
  }
}

/* Empty lists: a friendly note rather than a bare line */
.empty {
  padding: 12px;
  border: 2px dashed var(--grid);
  border-radius: 10px;
  text-align: center;
}

/* Your move online: the board lights up */
body.my-turn .play-area .board,
body.my-turn .play-area .uboard-wrap {
  border-radius: 14px;
  box-shadow: 0 0 0 4px var(--hi);
  transition: box-shadow 0.3s;
}
body.my-turn .status {
  animation: nudge 0.5s ease-out;
}
@keyframes nudge {
  30% {
    transform: translateX(4px);
  }
  60% {
    transform: translateX(-3px);
  }
}
/* A round's points pop in */
.status .delta {
  display: inline-block;
  animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes pop {
  from {
    transform: scale(0.3);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .clock-ring,
  body.my-turn .status,
  .status .delta,
  .turn-clock.low .clock-ring {
    animation: none;
    transition: none;
  }
}

/* Invite links */
.invited {
  margin: 0;
  font-weight: 700;
}
.share-btn {
  justify-self: start;
}
