/* Wordrush's own colours (the felt, tiles and tray) stay the same in every theme. The chrome (panels, text, buttons,
   fields) takes the site-wide theme's tokens (platform/site.css, chosen in the site bar or Settings). */
:root {
  --felt: #1d3b3a;
  --felt-line: #25504e;
  --felt-dark: #142b2a;
  --tile: #f6ecd6;
  --tile-edge: #c9b48a;
  --select: #6cc4ff;
  --ink: var(--ph-ink);
  --accent: var(--ph-accent);
  --accent-dark: var(--ph-accent-strong);
  --good: #3f9b6a;
  --bad: #d9443a;
  --paper: var(--ph-surface);
  --muted: var(--ph-muted);
  /* Tiles are part of the board: dark letters on cream whatever the theme. */
  --tile-ink: #1f2420;
  --tile-bad: #f7c9bf;
  --on-felt: #f6ecd6;
  --side-text: #b9cfcc;
  --good-light: #8fe0b1;
  --bad-light: #ffb4a6;
  --pill: rgb(255 255 255 / .1);
  --tray: #3a2c22;
  --tray-edge: #2b2019;
  --tray-muted: #a8937d;
  --tray-text: #e8dcc8;
  --btn: var(--ph-surface-2);
  --row: var(--ph-surface-2);
  --field-bg: var(--ph-surface);
  --field-line: var(--ph-line);
  --on-accent: var(--ph-accent-ink);
  --cell-base: 40px;
  --cell: var(--cell-base);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--felt-dark); overscroll-behavior: none; }
[hidden] { display: none !important; }

button {
  font: inherit; border: 0; border-radius: var(--radius); padding: 10px 16px;
  background: var(--btn); color: var(--ink); cursor: pointer; font-weight: 600;
}
button:hover { filter: brightness(1.05); }
button:disabled { opacity: .45; cursor: default; filter: none; }
button.primary { background: var(--accent); color: var(--on-accent); }
button.primary:hover:not(:disabled) { background: var(--accent-dark); }
button.link { background: none; color: var(--accent-dark); padding: 4px; text-decoration: underline; }
input {
  font: inherit; padding: 10px 12px; border: 2px solid var(--field-line); border-radius: var(--radius);
  background: var(--field-bg); color: var(--ink); width: 100%;
}
input:focus { outline: none; border-color: var(--accent); }

.screen { min-height: 100%; }
#join, #lobby { display: grid; place-items: center; padding: 16px; }
#join { grid-template-rows: auto 1fr; }
#join > .ph-bar { align-self: start; }
.card {
  background: var(--paper); border-radius: 18px; padding: 28px; width: min(400px, 100%);
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgb(0 0 0 / .35);
}
.card.wide { width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
.row { display: flex; gap: 8px; }
/* A room name is four words: the box takes a full line and the buttons share the one below. */
.join-row { flex-wrap: wrap; }
.join-row > button { flex: 1; }
#code { flex: 1 1 100%; min-width: 0; font-weight: 700; text-align: center; }
.card label.check { flex-direction: row; align-items: center; font-weight: 400; }
.card label.check input { width: auto; }
.card label.inline { flex-direction: row; align-items: center; flex-wrap: wrap; font-weight: 400; }
.card label.inline input[type=number] { width: 5em; padding: 6px 8px; }
select { font: inherit; padding: 6px 8px; border: 2px solid var(--field-line); border-radius: var(--radius); background: var(--field-bg); color: var(--ink); }
.house-rules { border: 1px solid var(--field-line); border-radius: var(--radius); padding: 10px 14px 14px; margin: 0;
  display: flex; flex-direction: column; gap: 10px; }
.house-rules legend { font-weight: 700; padding: 0 6px; }
.house-rules:disabled { opacity: .75; }
.rule-status { list-style: none; margin: 0; padding: 8px; display: flex; flex-direction: column; gap: 6px;
  background: rgb(0 0 0 / .18); border-radius: 8px; font-size: 13px; color: var(--on-felt); }
.rule-status li { display: grid; grid-template-columns: 1.2em 1fr; }
.rule-status li::before { content: "\2717"; color: var(--bad-light); font-weight: 700; }
.rule-status li.ok::before { content: "\2713"; color: var(--good-light); }
.rule-status small { grid-column: 2; color: var(--side-text); }
button.icon { font-size: 20px; padding: 8px 12px; line-height: 1; }
.or { text-align: center; color: var(--muted); font-size: 13px; }
.solo-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.solo-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; }
.solo-btn small { font-weight: 400; font-size: 12px; opacity: .8; }
.scores-link { justify-self: center; align-self: center; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--on-accent); }
.scores { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.scores li { display: grid; grid-template-columns: 2em 1fr auto auto; gap: 8px; align-items: baseline; padding: 6px 10px; background: var(--row); border-radius: 8px; }
.scores li.me { outline: 2px solid var(--accent); }
.scores li.empty { display: block; text-align: center; color: var(--muted); }
.scores .rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.scores .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.scores .time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.result-scores { display: grid; gap: 6px; }
.result-scores h3 { margin: 4px 0 0; font-size: 16px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.tagline { margin: -6px 0 4px; color: var(--muted); }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ul { padding-left: 18px; margin: 8px 0 0; font-size: 14px; line-height: 1.5; }

.logo { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 40px; letter-spacing: -.5px; }
.logo span {
  display: inline-grid; place-items: center; width: 1.15em; height: 1.15em; margin-right: 2px;
  background: var(--tile); border: 2px solid var(--tile-edge); border-radius: .2em; color: var(--tile-ink);
}
.logo.small { font-size: 20px; color: var(--on-felt); }

.phrase { font-size: 30px; font-weight: 700; line-height: 1.2; text-align: center; overflow-wrap: anywhere; }
.phrase b { color: var(--accent); }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: .15em; }
.center { text-align: center; }
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.players li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--row); border-radius: 8px; }
.players li .count { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.players li.off { opacity: .5; }
.players li.me { outline: 2px solid var(--accent); }
.tag { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: var(--accent); color: var(--on-accent); }

/* Game layout */
#game { display: flex; flex-direction: column; height: 100dvh; }
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; color: var(--on-felt); }
.bar > * { flex-shrink: 0; }
.pill { background: var(--pill); padding: 4px 10px; border-radius: 99px; font-size: 14px; }
/* One line whatever the message, so a status change never changes the bar's height and shifts the board. */
.status {
  flex: 1 1 0; min-width: 0; text-align: right; font-size: 14px; font-weight: 600; line-height: 20px; height: 20px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status.good { color: var(--good-light); }
.status.bad { color: var(--bad-light); }

.table { flex: 1; display: flex; min-height: 0; }
.board-area { flex: 1; display: flex; position: relative; min-width: 0; min-height: 0; }
.zoom { position: absolute; left: 10px; bottom: 10px; z-index: 5; display: flex; gap: 4px; }
.zoom button { min-width: 36px; height: 36px; padding: 0 10px; border-radius: 99px; font-size: 18px; line-height: 1; box-shadow: 0 2px 6px rgb(0 0 0 / .35); }
.zoom #zoomFit { font-size: 14px; }
.board-wrap { flex: 1; overflow: auto; position: relative; outline: none; touch-action: none; cursor: grab; }
.board-wrap.panning { cursor: grabbing; }
.board {
  --cell: calc(var(--cell-base) * var(--zoom, 1));
  position: relative; width: calc(var(--cell) * 100); height: calc(var(--cell) * 100);
  background-color: var(--felt);
  background-image:
    linear-gradient(var(--felt-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--felt-line) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
}
.cursor {
  position: absolute; width: var(--cell); height: var(--cell); border: 3px solid var(--accent);
  border-radius: 8px; pointer-events: none; z-index: 2;
}
.cursor::after {
  position: absolute; color: var(--accent); font-weight: 900; font-size: 16px;
  content: "›"; right: -12px; top: 50%; transform: translateY(-55%);
}
.cursor.down::after { content: "›"; right: 50%; top: auto; bottom: -16px; transform: translateX(50%) rotate(90deg); }

.tile {
  width: calc(var(--cell) - 4px); height: calc(var(--cell) - 4px); margin: 2px;
  display: grid; place-items: center; user-select: none; touch-action: none;
  background: var(--tile); border-radius: 7px; border-bottom: 3px solid var(--tile-edge);
  font: 700 calc(var(--cell) * .55)/1 Georgia, "Times New Roman", serif; color: var(--tile-ink);
  cursor: grab; box-shadow: 0 1px 2px rgb(0 0 0 / .3);
}
.board .tile { position: absolute; margin: 2px; z-index: 1; }
.tile.bad { background: var(--tile-bad); border-bottom-color: var(--bad); }
.tile.fresh { animation: pop .8s ease-out; }
.tile.dragging { position: fixed; z-index: 100; pointer-events: none; transform: scale(1.12); box-shadow: 0 10px 24px rgb(0 0 0 / .4); margin: 0; }
.tile.ghost { opacity: .3; }
.tile.sel { outline: 3px solid var(--select); outline-offset: -1px; }
.tile.group-anchor > .tile { position: absolute; margin: 0; }
.board-wrap { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.board-wrap.lassoing { cursor: crosshair; }
.lasso { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 3; }
.lasso polygon { fill: rgb(108 196 255 / .15); stroke: var(--select); stroke-width: 2; stroke-dasharray: 6 4; }
@keyframes pop { 0% { transform: scale(.4); background: #fff3b0; } 60% { transform: scale(1.15); } 100% { transform: none; } }

.side { width: 220px; padding: 10px; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.players.compact li { padding: 6px 8px; font-size: 14px; }
.log { list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--side-text); display: flex; flex-direction: column; gap: 4px; }

.tray {
  display: flex; gap: 12px; align-items: center; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--tray); border-top: 4px solid var(--tray-edge);
}
.rack { flex: 1; display: flex; flex-wrap: wrap; gap: 2px; min-height: calc(var(--cell) + 4px); align-content: flex-start; }
.rack.over, .swap-zone.over { outline: 3px dashed var(--accent); outline-offset: 2px; }
.rack:empty::before { content: "Rack empty"; color: var(--tray-muted); font-size: 14px; align-self: center; padding-left: 6px; }
.actions { display: flex; gap: 8px; align-items: center; }
.swap-zone {
  border: 2px dashed var(--tray-muted); color: var(--tray-text); border-radius: var(--radius); padding: 6px 12px;
  text-align: center; font-weight: 700; font-size: 14px; line-height: 1.1;
}
.swap-zone small { display: block; font-weight: 400; font-size: 11px; opacity: .8; }
button.big { padding: 14px 22px; font-size: 18px; }
button.ready { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 35%, transparent); } }

.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.mini {
  --cell: 26px; display: grid; gap: 0; justify-content: safe center; overflow: auto;
  padding: 8px; background: var(--felt); border-radius: 10px;
}
.mini .tile { margin: 1px; width: calc(var(--cell) - 2px); height: calc(var(--cell) - 2px); cursor: default; }
.mini.empty { color: var(--side-text); font-size: 14px; padding: 14px; text-align: center; }
.others h3 { margin: 18px 0 6px; font-size: 16px; display: flex; justify-content: space-between; gap: 8px; }
.others h3 .muted { font-weight: 400; }

.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 200;
  background: #1f2420; color: #fff; padding: 10px 18px; border-radius: 99px; font-weight: 600;
  box-shadow: 0 8px 24px rgb(0 0 0 / .35); max-width: calc(100% - 32px);
}

@media (max-width: 760px) {
  .card.wide { padding: 18px 14px; }
  :root { --cell-base: 34px; }
  .table { flex-direction: column-reverse; }
  .side { width: auto; flex-direction: row; padding: 6px 10px; overflow-x: auto; }
  .side .log { display: none; }
  .rule-status { flex-direction: row; padding: 4px 8px; white-space: nowrap; }
  .rule-status small { display: none; }
  .players.compact { flex-direction: row; }
  .players.compact li { white-space: nowrap; }
  .tray { flex-direction: column; align-items: stretch; }
  .actions { justify-content: space-between; gap: 6px; }
  .actions button { padding: 10px 12px; }
  .actions button.icon { padding: 8px 10px; }
  .actions .big { padding: 10px 14px; }
  .bar .logo { display: none; }
  .bar { flex-wrap: wrap; row-gap: 4px; }
  .bar > .status { flex-basis: 100%; text-align: left; order: 1; }
}

/* Settings */
button.gear, button.bar-icon {
  margin-left: 4px; padding: 4px 8px; font-size: 20px; line-height: 1;
  background: var(--pill); color: var(--on-felt);
}
#settings { z-index: 60; }
.theme-pick { border: 0; padding: 0; margin: 0; font-size: 14px; }
.theme-pick legend { font-weight: 700; padding: 0 0 8px; }
.theme-pick .ph-note { margin: 0 0 8px; color: var(--muted); font-size: 13px; }

/* Spectator view: every board at once */
#watch { display: flex; flex-direction: column; min-height: 100dvh; }
.watchers { margin: 0; font-size: 13px; color: var(--side-text); }
.watchers:empty { display: none; }
.watch-boards {
  flex: 1; display: grid; gap: 12px; padding: 4px 14px 14px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
}
.watch-card { background: var(--paper); color: var(--ink); border-radius: 14px; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.watch-card h3 { margin: 0; font-size: 16px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.watch-card.off { opacity: .6; }
.watch-card.won { outline: 3px solid var(--accent); }
.watch-card .mini { min-height: 120px; align-content: center; }
.watch-log { padding: 0 14px 14px; }

/* Other players' tiles left to place, in the stats bar */
.bar > .others { flex-shrink: 1; min-width: 0; display: flex; gap: 10px; overflow: hidden; white-space: nowrap; }
.others .rival b { margin-left: 2px; }
.others .rival.done b { color: var(--bad-light); }

/* Result screen: grids never squash inside the scrolling card */
.card > .mini, .others .mini { flex-shrink: 0; }
.mini-rack { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 6px; --cell: 24px; }
.mini-rack .tile { margin: 0; width: var(--cell); height: var(--cell); font-size: 14px; cursor: default; border-bottom-width: 2px; }

/* Draws left in the pool */
.pill .draws { opacity: .8; font-size: 13px; }
.pill.low { background: color-mix(in srgb, var(--accent) 35%, transparent); }
.pill.flash { background: var(--accent); color: var(--on-accent); animation: flash 1s ease-in-out infinite; }
@keyframes flash { 50% { filter: brightness(1.35); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 40%, transparent); } }

button.leave { align-self: center; color: var(--muted); }

.others .rival .pts { opacity: .8; font-size: 12px; }

/* On-screen arrows for the typing cursor, bottom right of the board. */
.dpad {
  position: absolute; right: 10px; bottom: 10px; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); gap: 3px;
}
.dpad[hidden] { display: none; }
.dpad button { width: 40px; height: 40px; padding: 0; border-radius: 10px; font-size: 16px; line-height: 1; box-shadow: 0 2px 6px rgb(0 0 0 / .35); touch-action: manipulation; }
.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .mid { grid-area: 2 / 2; font-size: 18px; color: var(--accent); }
.dpad .right { grid-area: 2 / 3; }
.dpad .down { grid-area: 3 / 2; }

/* Recent games on the join screen. */
.recent ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
.recent li { display: flex; align-items: stretch; gap: 4px; }
.recent-open {
  flex: 1; min-width: 0; display: grid; gap: 2px; text-align: left; padding: 8px 10px;
  border-radius: 10px; background: var(--row); color: var(--ink); font-weight: 400;
}
.recent-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.recent-head b { min-width: 0; }
.recent-head > span { white-space: nowrap; }
.recent-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-drop { padding: 0 8px; font-size: 20px; color: var(--muted); }

/* Friends */
.links-row { display: flex; justify-content: center; gap: 18px; }
.online-count { display: inline-block; min-width: 1.5em; padding: 0 5px; border-radius: 99px; background: var(--good, #2e7d32); color: #fff; font-size: 12px; text-decoration: none; }
.share-row { display: flex; gap: 8px; }
.share-row > * { flex: 1; }
a.button { display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius); padding: 10px 16px; font-weight: 600; text-decoration: none; }
a.wa { background: #25d366; color: #0b2e17; }
a.wa:hover { filter: brightness(1.05); }
.friends { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 40vh; overflow: auto; }
.friends li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--row); border-radius: 8px; }
.friends li .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friends li button { padding: 6px 10px; font-size: 14px; }
.friends li button.remove { background: none; color: var(--muted); padding: 4px 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); opacity: .5; flex: none; }
.dot.on { background: #2fbf5b; opacity: 1; }
.friends li .who .where { color: var(--muted); font-size: .85em; }
.invite-banner {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 210; width: min(420px, calc(100% - 32px));
  background: var(--paper); color: var(--ink); border-radius: 14px; padding: 12px 14px; box-shadow: 0 12px 36px rgb(0 0 0 / .4);
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-weight: 600;
}
.invite-banner #inviteText { flex: 1 1 200px; }
.invite-actions { display: flex; gap: 8px; }
.notify-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--row); }
.notify-row span { flex: 1; }

/* Solo pause: the board and rack are hidden, not just covered. */
#game.paused .table, #game.paused .tray { visibility: hidden; }
.pause-screen { position: fixed; inset: 56px 0 0; /* top is set below the bar by renderPause */ display: grid; place-items: center; padding: 16px; background: var(--felt-dark); z-index: 40; }
.pause-screen .card { text-align: center; align-items: center; }
.offline-note { text-align: center; margin-top: 8px; }
.go-offline { background: var(--accent); color: var(--on-accent); border: 0; border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }

/* Players who ask their system for less motion get no popping, pulsing or flashing. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
