/* Duelexic — game styles (lobby + game page).
   Loaded after GameShack's shared style.css, which supplies --navy, --paper, --ink, --gold,
   --brick, --serif and --sans. Duelexic adds the Pine & Violet tile palette below.

   Tile colors (checked for WCAG AA letter contrast and for colour-blind separation):
     correct  pine   #235A49, white letters
     present  violet #6E4FA3, white letters
     absent   stone  #9A958D, navy letters
*/

:root {
  --tw-pine: #235A49;
  --tw-pine-dark: #1A4537;
  --tw-violet: #6E4FA3;
  --tw-violet-dark: #574085;
  --tw-stone: #9A958D;
  --tw-empty-border: #C9C3B6;
  --tw-filled-border: #8F877A;
  --tw-key: #E2DDD1;
  --tw-key-hover: #D6D0C2;
  --tw-panel: #FFFFFF;
  --tw-line: rgba(24, 43, 58, 0.14);
  --tw-error: #9B2C2C;
  --tw-radius: 4px;
  --tw-focus: 0 0 0 3px var(--paper, #F2EFE7), 0 0 0 5px var(--tw-violet);
}

/* ── Page frame ─────────────────────────────────────────────────────── */

.tw-main {
  max-width: 64rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.tw-hero {
  text-align: center;
  margin: 0 0 1.75rem;
}

.tw-hero__logo {
  display: block;
  width: 100%;
  max-width: 24rem;
  height: auto;
  margin: 0 auto 0.5rem;
}

.tw-hero h1 {
  margin: 0;
}

.tw-subtitle {
  margin: 0 0 0.35rem;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.3rem;
  color: var(--navy);
}

.tw-tagline {
  margin: 0 0 0.75rem;
  color: var(--brick);
  font-size: 1.05rem;
}

.tw-account {
  margin: 0;
  font-size: 0.95rem;
}

/* ── Lobby layout: one column (Today's Daily, then Games) ────────────── */

.tw-lobby {
  display: grid;
  gap: 1.25rem;
  max-width: 40rem;
  margin: 0 auto;
}

.tw-panel {
  background: var(--tw-panel);
  border: 1px solid var(--tw-line);
  border-radius: var(--tw-radius);
  padding: 1.25rem;
}

.tw-panel + .tw-panel {
  margin-top: 1.5rem;
}

.tw-panel h2,
.tw-section h2 {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin: 0 0 0.75rem;
}

.tw-section + .tw-section {
  margin-top: 2rem;
}

.tw-divider {
  border: 0;
  border-top: 1px solid var(--tw-line);
  margin: 1.25rem 0;
}

.tw-note {
  color: var(--brick);
  font-size: 0.92rem;
  margin: 0.5rem 0 0;
}

/* ── Forms and buttons ───────────────────────────────────────────────── */

.tw-field {
  display: block;
  margin: 0 0 0.75rem;
}

.tw-field label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--navy);
  margin: 0 0 0.3rem;
}

.tw-input {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--tw-filled-border);
  border-radius: var(--tw-radius);
  padding: 0.6rem 0.7rem;
}

.tw-input--code {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-transform: uppercase;
}

.tw-input:focus-visible,
.tw-btn:focus-visible,
.tw-link:focus-visible,
.tw-key:focus-visible,
.tw-row-link:focus-visible {
  outline: none;
  box-shadow: var(--tw-focus);
}

.tw-btn {
  display: inline-block;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  border-radius: var(--tw-radius);
  padding: 0.65rem 1.1rem;
  border: 2px solid var(--tw-pine);
  background: var(--tw-pine);
  color: #fff;
}

.tw-btn:hover {
  background: var(--tw-pine-dark);
  border-color: var(--tw-pine-dark);
  color: #fff;
}

.tw-btn--quiet {
  background: transparent;
  color: var(--navy);
  border-color: var(--tw-filled-border);
}

.tw-btn--quiet:hover {
  background: var(--tw-key);
  border-color: var(--tw-filled-border);
  color: var(--navy);
}

.tw-btn--violet {
  background: var(--tw-violet);
  border-color: var(--tw-violet);
}

.tw-btn--violet:hover {
  background: var(--tw-violet-dark);
  border-color: var(--tw-violet-dark);
}

.tw-btn--wide {
  width: 100%;
}

.tw-btn[aria-busy="true"] {
  opacity: 0.7;
  cursor: progress;
}

/* Text-style button (e.g. "How to play", "Sign in") */
.tw-link {
  font: inherit;
  background: none;
  border: none;
  padding: 0;
  color: var(--navy);
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
  border-radius: 2px;
}

.tw-link:hover {
  color: var(--tw-violet);
}

.tw-form-row {
  display: flex;
  gap: 0.5rem;
}

.tw-form-row .tw-input {
  flex: 1;
  min-width: 0;
}

.tw-error {
  color: var(--tw-error);
  font-size: 0.92rem;
  margin: 0.5rem 0 0;
  min-height: 1.2em;
}

.tw-error:empty {
  min-height: 0;
  margin: 0;
}

/* ── Game lists (bordered rows, not cards) ───────────────────────────── */

.tw-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--tw-line);
}

.tw-row {
  border-bottom: 1px solid var(--tw-line);
}

.tw-row-link,
.tw-row-static {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 0.25rem;
  color: var(--ink);
  text-decoration: none;
}

.tw-row-link:hover {
  background: rgba(110, 79, 163, 0.06);
  color: var(--ink);
}

.tw-row__main {
  min-width: 0;
}

.tw-row__title {
  display: block;
  font-weight: 600;
  color: var(--navy);
}

.tw-row__detail {
  display: block;
  font-size: 0.9rem;
  color: var(--brick);
}

.tw-row__action {
  flex-shrink: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--tw-pine);
}

.tw-row__action--yours {
  color: #fff;
  background: var(--tw-pine);
  border-radius: var(--tw-radius);
  padding: 0.3rem 0.6rem;
}

.tw-empty {
  color: var(--brick);
  margin: 0;
  padding: 0.75rem 0.25rem;
  border-bottom: 1px solid var(--tw-line);
}

/* Rivalry record: "You 3, Ann 1, draws 2" */
.tw-record {
  display: block;
  font-size: 0.9rem;
  color: var(--brick);
}

.tw-record strong {
  color: var(--navy);
  font-size: 1rem;
}

/* Invite code display */
.tw-code {
  display: inline-block;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--navy);
  background: var(--paper);
  border: 1px dashed var(--tw-filled-border);
  border-radius: var(--tw-radius);
  padding: 0.25rem 0.6rem;
}

.tw-share {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin: 0.5rem 0 0;
}

/* ── Tiles (shared by the rules example and the game board) ─────────── */

.tw-tiles {
  display: flex;
  gap: 0.3rem;
}

.tw-tile {
  width: 2.6rem;
  height: 2.6rem;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 1.45rem;
  line-height: 1;
  text-transform: uppercase;
  border-radius: var(--tw-radius);
  border: 2px solid var(--tw-empty-border);
  color: var(--ink);
  background: transparent;
}

.tw-tile--filled {
  border-color: var(--tw-filled-border);
}

.tw-tile--correct {
  background: var(--tw-pine);
  border-color: var(--tw-pine);
  color: #fff;
}

.tw-tile--present {
  background: var(--tw-violet);
  border-color: var(--tw-violet);
  color: #fff;
}

.tw-tile--absent {
  background: var(--tw-stone);
  border-color: var(--tw-stone);
  color: var(--navy);
}

/* Small colour-only tiles (opponent's board, rivalry lists) */
.tw-tiles--mini {
  gap: 0.15rem;
}

.tw-tiles--mini .tw-tile,
.tw-board .tw-tiles--mini .tw-tile {
  width: 0.85rem;
  height: 0.85rem;
  border-width: 1px;
  border-radius: 2px;
  font-size: 0;
}

/* ── Rules dialog ────────────────────────────────────────────────────── */

.tw-dialog {
  width: min(36rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  border: 1px solid var(--tw-line);
  border-radius: var(--tw-radius);
  padding: 0;
  color: var(--ink);
  background: var(--paper);
}

.tw-dialog::backdrop {
  background: rgba(24, 43, 58, 0.55);
}

.tw-dialog__body {
  padding: 1.25rem 1.5rem 1.5rem;
}

.tw-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 0.5rem;
}

.tw-dialog__head h2 {
  font-family: var(--serif);
  margin: 0;
}

.tw-dialog h3 {
  font-family: var(--serif);
  font-size: 1.1rem;
  margin: 1.25rem 0 0.4rem;
}

.tw-dialog p,
.tw-dialog li {
  max-width: 34rem;
  line-height: 1.55;
}

.tw-example {
  margin: 0.75rem 0;
}

.tw-example figcaption {
  font-size: 0.92rem;
  color: var(--brick);
  margin: 0.4rem 0 0;
}

.tw-legend {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
}

.tw-legend li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.35rem 0;
}

.tw-legend .tw-tile {
  width: 1.9rem;
  height: 1.9rem;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.tw-credits {
  font-size: 0.82rem;
  color: var(--brick);
  border-top: 1px solid var(--tw-line);
  margin-top: 1.25rem;
  padding-top: 0.75rem;
}

/* ── Game page ───────────────────────────────────────────────────────── */

.tw-game {
  max-width: 34rem;
  margin: 0 auto;
}

.tw-game__logo-link {
  display: block;
  width: fit-content;
  margin: 0 auto 0.75rem;
  border-radius: var(--tw-radius);
}

.tw-game__logo-link:focus-visible {
  outline: none;
  box-shadow: var(--tw-focus);
}

.tw-game__logo {
  display: block;
  width: 9rem;
  height: auto;
}

.tw-game__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 1rem;
}

.tw-game__title {
  font-family: var(--serif);
  font-size: 1.35rem;
  margin: 0;
}

.tw-game__sub {
  display: block;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--brick);
}

.tw-game__home {
  flex-shrink: 0;
  font-size: 0.95rem;
}

/* "Ends at midnight (Eastern). 3 h 10 m left." */
.tw-deadline {
  margin: -0.5rem 0 1rem;
  font-size: 0.92rem;
  color: var(--brick);
}

.tw-deadline--soon {
  color: var(--tw-error);
  font-weight: 600;
}

/* One line under the boards for "Not in the word list", "Waiting for Ann…", etc. */
.tw-message {
  min-height: 1.6em;
  margin: 0.6rem 0;
  text-align: center;
  font-weight: 600;
  color: var(--navy);
}

.tw-message--error {
  color: var(--tw-error);
}

.tw-stage-note {
  text-align: center;
  color: var(--brick);
  margin: 0.5rem 0 1rem;
}

.tw-center {
  text-align: center;
}

/* Waiting for a friend to join */
.tw-waiting {
  text-align: center;
  padding: 1.5rem 1rem;
}

.tw-waiting .tw-code {
  font-size: 2rem;
  margin: 0.5rem 0;
}

.tw-waiting .tw-share {
  justify-content: center;
}

/* ── Boards ──────────────────────────────────────────────────────────── */

.tw-board {
  display: grid;
  gap: 0.35rem;
  justify-content: center;
}

.tw-board .tw-tile {
  width: 3.35rem;
  height: 3.35rem;
  font-size: 1.9rem;
}

@media (max-width: 22rem) {
  .tw-board .tw-tile {
    width: 2.9rem;
    height: 2.9rem;
    font-size: 1.6rem;
  }
}

/* Opponent's colors-only board: compact, above yours on phones, beside it on wider screens */
.tw-boards {
  display: grid;
  gap: 1rem;
  justify-items: center;
}

.tw-opponent {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--tw-line);
  border-radius: var(--tw-radius);
  background: var(--tw-panel);
}

.tw-opponent__label {
  font-size: 0.9rem;
  line-height: 1.3;
}

.tw-opponent__label strong {
  display: block;
  color: var(--navy);
}

.tw-opponent__label span {
  color: var(--brick);
}

.tw-opponent .tw-board {
  gap: 0.15rem;
}

/* Floating window ("Repeated letters" on the game page): not modal, no dimmed page behind it,
   placed and dragged by play.js using left/top. */
.tw-floating {
  position: fixed;
  inset: auto;
  margin: 0;
  z-index: 60;
  width: min(30rem, calc(100vw - 1rem));
  max-height: calc(100vh - 1rem);
  max-height: calc(100dvh - 1rem);
  overflow-y: auto;
  box-shadow: 0 6px 24px rgba(24, 43, 58, 0.35);
}

.tw-floating__handle {
  cursor: move;
  touch-action: none;          /* dragging on a phone moves the window, not the page */
  user-select: none;
  -webkit-user-select: none;
}

.tw-floating__handle.is-dragging {
  cursor: grabbing;
}

.tw-floating__grip {
  color: var(--tw-filled-border);
  font-family: var(--sans);
  font-size: 1rem;
  letter-spacing: -0.15em;
  margin-right: 0.3rem;
  vertical-align: 0.15em;
}

.tw-floating h2:focus,
.tw-floating h2:focus-visible {
  outline: none;   /* focused only so Enter keeps going to the game; it isn't clickable */
}

/* The title bar stays put while the text scrolls, so there's always something to drag. */
.tw-floating .tw-floating__handle {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: -1.25rem -1.5rem 0.5rem;
  padding: 0.9rem 1.5rem 0.6rem;
  background: var(--paper, #F2EFE7);
  border-bottom: 1px solid var(--tw-line);
}

/* Phones: compact, at most about half the screen, scrolling inside. */
@media (max-width: 45.99rem) {
  .tw-floating {
    max-height: 50vh;
    max-height: 50dvh;
  }

  .tw-floating .tw-dialog__body {
    padding: 0.9rem 1rem 1rem;
  }

  .tw-floating .tw-floating__handle {
    margin: -0.9rem -1rem 0.5rem;
    padding: 0.55rem 1rem 0.45rem;
  }

  .tw-floating h2 {
    font-size: 1.15rem;
  }

  .tw-floating .tw-btn {
    padding: 0.35rem 0.75rem;
    font-size: 0.9rem;
  }

  .tw-floating p,
  .tw-floating figcaption {
    font-size: 0.9rem;
    line-height: 1.45;
    margin: 0.45rem 0;
  }

  .tw-floating .tw-example {
    margin: 0.4rem 0;
  }

  .tw-floating .tw-example .tw-tile {
    width: 2rem;
    height: 2rem;
    font-size: 1.05rem;
  }
}

/* Colour key under the opponent's box: three swatches with short descriptions. */
.tw-colorkey {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--brick);
}

.tw-colorkey__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tw-colorkey__list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.15rem 0;
}

.tw-key-swatch {
  display: inline-block;
  flex-shrink: 0;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 2px;
}

.tw-key-swatch.tw-tile--correct { background: var(--tw-pine); }
.tw-key-swatch.tw-tile--present { background: var(--tw-violet); }
.tw-key-swatch.tw-tile--absent  { background: var(--tw-stone); }

.tw-colorkey__more {
  margin-top: 0.2rem;
  font-size: 0.8rem;
}

/* Phones: the key sits beside the opponent's box in one row of three, to save height. */
@media (max-width: 45.99rem) {
  .tw-side {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .tw-colorkey {
    text-align: center;
  }

  .tw-colorkey__list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 0.8rem;
  }
}

/* "Your word" over the opponent's mini-board: one letter per column, lined up with the
   0.85rem mini tiles below (same width and gap), so their colours read against your letters. */
.tw-myword {
  margin-bottom: 0.15rem;
}

.tw-myword__label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--brick);
  white-space: nowrap;
  margin-bottom: 0.05rem;
}

.tw-myword__letters {
  display: flex;
  gap: 0.15rem;
}

.tw-myword__letter {
  width: 0.85rem;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--navy);
}

@media (min-width: 46rem) {
  .tw-game--wide {
    max-width: 46rem;
  }

  .tw-boards {
    grid-template-columns: auto auto;
    align-items: start;
    justify-content: center;
    gap: 2rem;
  }

  .tw-boards .tw-side {
    order: 2;
  }

  .tw-boards .tw-opponent {
    flex-direction: column;
    align-items: flex-start;
  }
}

/*
 * Revealing a new guess: each tile flips on its vertical axis, left to right. A tile keeps its
 * plain typed look (tw-flip-face) until it's edge-on halfway through, then turns the rest of the
 * way showing its color. Timings must match REVEAL_STEP / REVEAL_FLIP in js/board.js.
 * Skipped with reduced motion (see the prefers-reduced-motion block).
 */
.tw-tile--reveal {
  animation: tw-flip 500ms both, tw-flip-face 250ms step-end backwards;
}

.tw-tile--reveal:nth-child(2) { animation-delay: 300ms; }
.tw-tile--reveal:nth-child(3) { animation-delay: 600ms; }
.tw-tile--reveal:nth-child(4) { animation-delay: 900ms; }
.tw-tile--reveal:nth-child(5) { animation-delay: 1200ms; }

@keyframes tw-flip {
  0%   { transform: rotateY(0deg);  animation-timing-function: ease-in; }
  50%  { transform: rotateY(90deg); animation-timing-function: ease-out; }
  100% { transform: rotateY(0deg); }
}

@keyframes tw-flip-face {
  0%, 100% {
    background: transparent;
    border-color: var(--tw-filled-border);
    color: var(--ink);
  }
}

/* "Not in the word list": the current row shakes */
.tw-tiles--shake {
  animation: tw-shake 360ms ease-in-out;
}

@keyframes tw-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ── On-screen keyboard ──────────────────────────────────────────────── */

.tw-keyboard {
  margin: 0.75rem auto 0;
  max-width: 32rem;
  user-select: none;
  -webkit-user-select: none;
}

.tw-keyrow {
  display: flex;
  justify-content: center;
  gap: 0.3rem;
  margin: 0 0 0.35rem;
}

.tw-key {
  flex: 1 1 0;
  min-width: 0;
  max-width: 2.9rem;
  height: 3.4rem;
  padding: 0;
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--tw-key);
  border: none;
  border-radius: var(--tw-radius);
  cursor: pointer;
  touch-action: manipulation;
}

.tw-key:hover {
  background: var(--tw-key-hover);
}

.tw-key--wide {
  flex-grow: 1.6;
  max-width: 4.6rem;
  font-size: 0.8rem;
}

/* Backspace: an SVG icon (board.js), about the height of the letters */
.tw-key--back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tw-key__icon {
  width: 1.6rem;
  height: 1.6rem;
  display: block;
}

.tw-key--correct { background: var(--tw-pine); color: #fff; }
.tw-key--present { background: var(--tw-violet); color: #fff; }
.tw-key--absent  { background: var(--tw-stone); color: var(--navy); }
.tw-key--correct:hover { background: var(--tw-pine-dark); }
.tw-key--present:hover { background: var(--tw-violet-dark); }
.tw-key--absent:hover  { background: #8D887F; }

.tw-key:disabled {
  opacity: 0.6;
  cursor: default;
}

.tw-spacer {
  flex: 0.5 1 0;
  max-width: 1.4rem;
}

/* Choosing your word */
.tw-pick-actions {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  margin: 0.75rem 0 0;
}

/* Word list for choosing your secret word: search box over a scrolling list */
.tw-picker {
  max-width: 24rem;
  margin: 1.25rem auto 0;
}

.tw-picker__label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--navy);
  margin: 0 0 0.3rem;
}

.tw-picker__filter {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.tw-picker__filter::placeholder {
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
}

.tw-picker__count {
  font-size: 0.88rem;
  color: var(--brick);
  margin: 0.4rem 0;
}

.tw-picklist {
  list-style: none;
  margin: 0;
  padding: 0.4rem;
  height: 15rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5.2rem, 1fr));
  align-content: start;
  gap: 0.3rem;
  background: var(--tw-panel);
  border: 1px solid var(--tw-line);
  border-radius: var(--tw-radius);
}

.tw-pickword {
  width: 100%;
  padding: 0.45rem 0;
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid transparent;
  border-radius: var(--tw-radius);
  cursor: pointer;
}

.tw-pickword:hover {
  background: var(--tw-key);
}

.tw-pickword[aria-pressed="true"] {
  background: var(--tw-pine);
  color: #fff;
}

.tw-pickword:focus-visible {
  outline: none;
  box-shadow: var(--tw-focus);
}

.tw-picklist__empty {
  grid-column: 1 / -1;
  padding: 0.75rem;
  color: var(--brick);
}

/* ── Chat (game page) ───────────────────────────────────────────────── */
/* Modeled on the Hearts/Spades chat: a Chat button with an unread badge in the game's top
   bar, and a panel. Phones: a sheet along the bottom of the screen. Tablets and laptops: a card
   in the bottom-right corner. Wide screens: docked to the right of the boards. */

.tw-game__links {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-shrink: 0;
}

.tw-chat-btn {
  position: relative;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--tw-violet);
  background: #fff;
  border: 1px solid var(--tw-violet);
  border-radius: 999px;
  padding: 0.25rem 0.85rem;
  cursor: pointer;
}

.tw-chat-btn:hover,
.tw-chat-btn[aria-expanded="true"] {
  background: var(--tw-violet);
  color: #fff;
}

.tw-chat-btn:focus-visible,
.tw-chat__close:focus-visible,
.tw-chat__send:focus-visible,
.tw-chat__input:focus-visible {
  outline: none;
  box-shadow: var(--tw-focus);
}

.tw-chat-badge {
  position: absolute;
  top: -0.45rem;
  right: -0.45rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.25rem;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--tw-error);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.1rem;
  text-align: center;
}

.tw-chat {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 60vh;
  height: 60dvh;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--paper, #F2EFE7);
  border-radius: 10px 10px 0 0;
  box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

@media (min-width: 40rem) {
  .tw-chat {
    left: auto;
    right: 1rem;
    bottom: 1rem;
    width: 22rem;
    height: 28rem;
    max-height: calc(100vh - 2rem);
    border-radius: 8px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
  }
}

/* Wide screens: room beside the boards, so the panel sits there instead of on top. */
@media (min-width: 84rem) {
  .tw-chat {
    top: 9rem;
    bottom: auto;
    right: 1.5rem;
    width: 17rem;
    height: calc(100vh - 11rem);
    max-height: 36rem;
  }
}

.tw-chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--navy);
  color: #fff;
  padding: 0.6rem 0.9rem;
}

.tw-chat__title {
  margin: 0;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tw-chat__close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 0.25rem;
  cursor: pointer;
  border-radius: var(--tw-radius);
}

.tw-chat__messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tw-chat__empty {
  margin: 0;
  padding: 0 0.75rem 0.75rem;
  color: var(--brick);
  font-size: 0.9rem;
  text-align: center;
}

.tw-chat__msg {
  max-width: 85%;
  padding: 0.4rem 0.65rem;
  border-radius: 10px;
  font-size: 0.92rem;
  line-height: 1.35;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.tw-chat__msg--mine {
  align-self: flex-end;
  background: rgba(110, 79, 163, 0.16);
  border-bottom-right-radius: 3px;
}

.tw-chat__msg--theirs {
  align-self: flex-start;
  background: rgba(24, 43, 58, 0.08);
  border-bottom-left-radius: 3px;
}

.tw-chat__sender {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0.1rem;
}

.tw-chat__text {
  display: block;
}

.tw-chat__time {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.7rem;
  color: var(--brick);
  text-align: right;
}

.tw-chat__form {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem 0.6rem 0.3rem;
  border-top: 1px solid var(--tw-line);
}

.tw-chat__input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1rem;           /* 16px: stops phones zooming in on focus */
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--tw-filled-border);
  border-radius: var(--tw-radius);
  padding: 0.45rem 0.6rem;
}

.tw-chat__send {
  flex-shrink: 0;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  background: var(--tw-violet);
  border: none;
  border-radius: var(--tw-radius);
  padding: 0.45rem 0.9rem;
  cursor: pointer;
}

.tw-chat__send:hover {
  background: var(--tw-violet-dark);
}

.tw-chat__send:disabled {
  opacity: 0.6;
  cursor: default;
}

.tw-chat__error {
  margin: 0;
  padding: 0 0.75rem;
  color: var(--tw-error);
  font-size: 0.85rem;
}

.tw-chat__error:empty {
  display: none;
}

.tw-chat__note {
  margin: 0;
  padding: 0.2rem 0.75rem 0.6rem;
  color: var(--brick);
  font-size: 0.78rem;
}

/* Lobby: "New message" next to a game. */
.tw-new-msg {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--tw-violet);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  vertical-align: 0.1em;
}

/* ── The Daily ───────────────────────────────────────────────────────── */

/* Lobby card: "Today's Daily", violet edge while it's still there to play. */
.tw-daily-card {
  background: var(--tw-panel);
  border: 1px solid var(--tw-line);
  border-left: 4px solid var(--tw-violet);
  border-radius: var(--tw-radius);
  padding: 1rem 1.25rem 1.25rem;
}

.tw-daily-card--done {
  border-left-color: var(--tw-pine);
  padding: 0.7rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.75rem;
}

/* Finished: one line ("Daily - 10/14/2026: solved in 4 guesses, 1 m 26 s · See your result") */
.tw-daily-card--done h2,
.tw-daily-card--done .tw-daily-card__status:empty {
  display: none;
}

.tw-daily-card__link {
  font-weight: 600;
}

.tw-daily-card h2 {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin: 0 0 0.5rem;
}

.tw-daily-card__title {
  margin: 0;
  font-weight: 600;
  color: var(--navy);
}

.tw-daily-card__status {
  margin: 0.25rem 0 0;
}

/* Daily page: "Time 2:31", running while you play. */
.tw-daily-timer {
  margin: 0 0 1rem;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

/* ── Result ──────────────────────────────────────────────────────────── */

.tw-result {
  text-align: center;
  margin: 0 0 1.25rem;
}

.tw-result__headline {
  font-family: var(--serif);
  font-size: 1.6rem;
  color: var(--navy);
  margin: 0 0 0.25rem;
}

.tw-result__text {
  margin: 0;
  color: var(--ink);
}

.tw-final {
  display: grid;
  gap: 1.5rem;
  justify-content: center;
}

@media (min-width: 46rem) {
  .tw-final {
    grid-template-columns: auto auto;
    gap: 3rem;
  }
}

.tw-final h3 {
  font-family: var(--serif);
  font-size: 1.05rem;
  text-align: center;
  margin: 0 0 0.5rem;
}

.tw-final .tw-board .tw-tile {
  width: 2.6rem;
  height: 2.6rem;
  font-size: 1.4rem;
}

.tw-final__word {
  text-align: center;
  margin: 0.5rem 0 0;
  color: var(--brick);
  font-size: 0.92rem;
}

.tw-final__word strong {
  color: var(--navy);
  letter-spacing: 0.12em;
}

.tw-result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin: 1.5rem 0 0;
}

/* ── Lobby: the Games card ───────────────────────────────────────────── */

.tw-games__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.75rem;
}

.tw-games__head h2 {
  margin: 0;
}

.tw-games__actions {
  display: flex;
  gap: 0.5rem;
}

.tw-games__sub {
  display: block;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brick);
  margin: 1rem 0 0.4rem;
}

.tw-signin-note {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
}

.tw-codebox {
  margin-top: 1.25rem;
}

.tw-codebox__label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--navy);
  margin: 0 0 0.3rem;
}

.tw-codebox__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tw-codebox__row .tw-input--code {
  flex: 0 1 11rem;
  min-width: 8rem;
}

.tw-codebox__row #playerName {
  flex: 1 1 9rem;
  width: auto;
  min-width: 7rem;
}

.tw-codebox__help {
  margin-top: 0.35rem;
}

.tw-past {
  margin-top: 0.5rem;
}

/* ── Invite page (invite.php) ────────────────────────────────────────── */

.tw-invite {
  max-width: 36rem;
  margin: 0 auto;
}

.tw-invite__title {
  font-family: var(--serif);
  font-size: 1.6rem;
  line-height: 1.25;
  color: var(--navy);
  text-align: center;
  margin: 0 0 0.75rem;
}

.tw-invite__title:focus {
  outline: none;   /* focused so screen readers start here; it isn't clickable */
}

.tw-invite__lead {
  text-align: center;
  font-size: 1.05rem;
  line-height: 1.5;
  margin: 0 0 1.25rem;
}

.tw-invite > #stage > p {
  line-height: 1.5;
}

.tw-invite > #stage > .tw-note {
  text-align: center;
}

/* Two choices: stacked on phones, side by side on wider screens */
.tw-choices {
  display: grid;
  gap: 1rem;
  margin: 0 0 1rem;
}

@media (min-width: 40rem) {
  .tw-choices {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

/* The grid's gap spaces the two cards; cancel the usual space between stacked panels. */
.tw-choices .tw-panel + .tw-panel {
  margin-top: 0;
}

.tw-choice h2 {
  font-family: var(--serif);
  font-size: 1.1rem;
  margin: 0 0 0.75rem;
}

.tw-choice .tw-note {
  margin-top: 0.6rem;
}

.tw-perks {
  margin: 0.9rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.92rem;
  line-height: 1.45;
}

.tw-perks li + li {
  margin-top: 0.3rem;
}

.tw-invite__link {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.tw-invite__url {
  font-size: 0.9rem;
  color: var(--brick);
  overflow-wrap: anywhere;
}

.tw-invite .tw-share {
  justify-content: center;
}

.tw-invite__back {
  text-align: center;
  margin: 1.5rem 0 0;
}

/* ── New game page (new.php) ─────────────────────────────────────────── */

.tw-newgame {
  max-width: 36rem;
  margin: 0 auto;
}

.tw-newgame__part h2 {
  font-family: var(--serif);
  font-size: 1.2rem;
  margin: 0 0 0.75rem;
}

.tw-newgame__part p {
  line-height: 1.5;
}

.tw-newgame__empty {
  border-bottom: none;
  padding: 0;
}

.tw-invite-made {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--tw-line);
}

.tw-invite-made__lead {
  margin: 0 0 0.5rem;
  font-weight: 600;
  color: var(--navy);
}

.tw-invite-made .tw-invite__link,
.tw-invite-made .tw-share {
  justify-content: flex-start;
}

.tw-email-invite {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--tw-line);
}

.tw-email-invite__done {
  color: var(--tw-pine);
  font-weight: 600;
}

.tw-code--small {
  font-size: 1rem;
  padding: 0.1rem 0.45rem;
}

/* Invite labels: "Who's this for?" note, and the note shown on each sent invite */
.tw-invite-note {
  margin-top: 0.75rem;
}

.tw-optional {
  font-weight: 400;
  color: var(--brick);
  margin-left: 0.35rem;
}

.tw-invite-label {
  margin-left: 0.6rem;
  font-weight: 400;
  font-style: italic;
  color: var(--navy);
  overflow-wrap: anywhere;
}

.tw-waiting-row {
  flex-wrap: wrap;
}

.tw-row__actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.tw-row__actions .tw-btn {
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
}

/* ── Utilities ───────────────────────────────────────────────────────── */

.tw-intro {
  margin: 0 0 0.75rem;
}

.tw-gap-top {
  margin-top: 1rem;
}

.tw-hidden {
  display: none !important;
}

.tw-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .tw-tile,
  .tw-tiles,
  .tw-btn {
    transition: none !important;
    animation: none !important;
  }
}

/* ── Daily: Today's results ─────────────────────────────────────────── */

.tw-result__note {
  margin-top: 0.5rem;
  color: var(--tw-pine);
  font-weight: 600;
}

.tw-solvers {
  max-width: 28rem;
  margin: 2rem auto 0;
  padding: 1rem 1.1rem 1.1rem;
  background: var(--tw-panel);
  border: 1px solid var(--tw-line);
  border-radius: var(--tw-radius);
}

.tw-solvers__title {
  font-family: var(--serif);
  font-size: 1.3rem;
  color: var(--navy);
  margin: 0 0 0.25rem;
}

.tw-solvers__note {
  margin: 0 0 0.75rem;
  color: var(--ink);
  font-size: 0.95rem;
}

.tw-solvers__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.98rem;
}

.tw-solvers__table th {
  text-align: left;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tw-filled-border);
  padding: 0 0.5rem 0.4rem;
  border-bottom: 1px solid var(--tw-line);
}

.tw-solvers__table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--tw-line);
  color: var(--ink);
}

.tw-solvers__table tr:last-child td {
  border-bottom: 0;
}

.tw-solvers__table .tw-solvers__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tw-solvers__rank {
  width: 2.2rem;
  color: var(--tw-filled-border);
  font-variant-numeric: tabular-nums;
}

.tw-solvers__name {
  overflow-wrap: anywhere;
}

.tw-solvers__me td {
  background: rgba(35, 90, 73, 0.1);
  font-weight: 600;
}

.tw-solvers__me .tw-solvers__rank {
  color: var(--tw-pine);
  box-shadow: inset 3px 0 0 var(--tw-pine);
}

.tw-solvers__you {
  font-weight: 400;
  color: var(--tw-pine);
}

.tw-solvers__signin {
  margin: 0.9rem 0 0;
  text-align: center;
}
