:root {
  --bg: #0f1420;
  --panel: #182034;
  --panel-edge: #26314c;
  --ink: #e8edf7;
  --ink-dim: #93a0bd;
  --accent: #4f8cff;
  --found: #2fbf82;
  --warn: #f0b64a;
  --danger: #e5544b;
  --cell: #1f2942;
  --cell-ink: #d5def2;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ---- top bar ---------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--panel-edge);
  background: var(--panel);
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.connection {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  white-space: nowrap;
}

.connection.ok { color: var(--found); border-color: rgba(47, 191, 130, 0.4); }
.connection.bad { color: var(--danger); border-color: rgba(229, 84, 75, 0.4); }

.who {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.who:hover { color: var(--accent); }

.btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 0.5rem 0.95rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { filter: brightness(1.1); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--panel-edge);
  color: var(--ink-dim);
}

.btn-ghost:hover { color: var(--ink); border-color: var(--accent); filter: none; }

.btn-danger { background: var(--danger); }

/* ---- layout ----------------------------------------------------------- */

.layout {
  flex: 1;
  display: flex;
  gap: 1.25rem;
  padding: 1.25rem;
  align-items: flex-start;
  justify-content: center;
}

.board-panel {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
}

.grid {
  display: grid;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 10px;
  touch-action: none;          /* we handle drag gestures ourselves */
  user-select: none;
  -webkit-user-select: none;
  width: clamp(280px, min(72vh, 100%), 620px);
  aspect-ratio: 1 / 1;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell);
  color: var(--cell-ink);
  border-radius: 5px;
  font-weight: 600;
  font-size: clamp(0.85rem, 2.6vh, 1.35rem);
  line-height: 1;
  cursor: pointer;
  transition: background-color 90ms ease, color 90ms ease;
}

.cell.selecting { background: var(--accent); color: #fff; }
.cell.found { background: var(--found); color: #06231a; }
.cell.found.selecting { background: var(--accent); color: #fff; }

.grid.shake { animation: shake 260ms ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.hint { margin: 0; color: var(--ink-dim); font-size: 0.85rem; }

/* ---- sidebar ---------------------------------------------------------- */

.side-panel {
  flex: 0 0 280px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 1.1rem;
}

.score { display: flex; align-items: baseline; gap: 0.5rem; }
.score-value { font-size: 1.6rem; font-weight: 700; }
.score-label { color: var(--ink-dim); font-size: 0.85rem; }

.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--cell);
  margin: 0.7rem 0 1rem;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--found);
  transition: width 200ms ease;
}

.word-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }

.word-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.38rem 0.55rem;
  border-radius: 5px;
  background: var(--cell);
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}

.word-list li.found { background: transparent; }

/* The newest find sits at the bottom of the list — mark it so it is easy to spot. */
.word-list li.latest {
  background: rgba(47, 191, 130, 0.10);
  box-shadow: inset 2px 0 0 var(--found);
}

.word-list li.found .word-text { color: var(--found); text-decoration: line-through; }

.word-finder {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-dim);
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.word-list li.mine .word-finder { color: var(--accent); }

.status { min-height: 1.2rem; margin: 0.9rem 0 0; font-size: 0.88rem; color: var(--ink-dim); }
.status.good { color: var(--found); }
.status.warn { color: var(--warn); }
.status.win { color: var(--found); font-weight: 700; }

.players { margin-top: 1.1rem; border-top: 1px solid var(--panel-edge); padding-top: 0.9rem; }

.players h2 {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-dim);
}

.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.15rem; }

.player-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.5rem;
  border-radius: 5px;
  font-size: 0.85rem;
  color: var(--ink);
}

.player-list li.empty {
  color: var(--ink-dim);
  font-size: 0.8rem;
  padding-left: 0;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--found);
  flex: 0 0 auto;
}

.player-list li.offline .dot { background: var(--panel-edge); }
.player-list li.offline { color: var(--ink-dim); }

.player-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-list li.me .player-name { color: var(--accent); font-weight: 600; }

.player-count {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--ink-dim);
}

/* Whoever is ahead — ties are all marked, so a reward never picks itself. */
.player-list li.leader {
  background: rgba(47, 191, 130, 0.12);
}

.player-list li.leader .player-count { color: var(--found); }

.player-list li.leader .player-name::after {
  content: "★";
  margin-left: 0.35rem;
  color: var(--found);
  font-size: 0.75rem;
}

/* ---- modals ----------------------------------------------------------- */

.modal[hidden] { display: none; }   /* author display beats the UA hidden rule */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 20, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 10;
}

.modal-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 1.4rem;
  display: grid;
  gap: 0.7rem;
}

.modal-card h2 { margin: 0; font-size: 1.15rem; }
.modal-note { margin: 0; color: var(--ink-dim); font-size: 0.85rem; }
.modal-error { margin: 0; min-height: 1rem; color: var(--danger); font-size: 0.82rem; }

.input {
  background: var(--cell);
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  color: var(--ink);
  font-size: 1rem;
  width: 100%;
}

.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; }

/* ---- phones ----------------------------------------------------------- */

@media (max-width: 780px) {
  .layout { flex-direction: column; align-items: stretch; padding: 0.9rem; gap: 0.9rem; }
  .topbar { padding: 0.6rem 0.9rem; }
  .topbar h1 { font-size: 0.92rem; }
  .grid { width: min(96vw, 520px); align-self: center; }
  .side-panel { flex: 1 1 auto; }
  .word-list { grid-template-columns: repeat(2, 1fr); }
  .word-list li { flex-direction: column; align-items: flex-start; gap: 0.1rem; }
  .word-finder { max-width: 100%; }
}
