:root {
  --bg: #0f1720;
  --bg-2: #131c27;
  --panel: #1a2432;
  --panel-2: #22303f;
  --border: #2b3a4d;
  --text: #e8eef5;
  --muted: #93a4b8;
  --accent: #6aaa64;
  --yellow: #c9b458;
  --gray: #3a3a3c;
  --danger: #d9534f;
  --focus: #66c2ff;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 800px at 20% -10%, #1a2c40 0%, var(--bg) 55%) fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.skip-link {
  position: absolute; left: -9999px;
}
.skip-link:focus {
  left: 8px; top: 8px; background: #fff; color: #000; padding: 6px 10px; border-radius: 4px; z-index: 100;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(15,23,32,.75);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-name { font-size: 20px; margin: 0; letter-spacing: 1px; }
.logo { display: inline-flex; gap: 3px; }
.logo .tile { width: 22px; height: 22px; font-size: 12px; border-radius: 4px; }

.status { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.round-info { font-weight: 600; color: var(--text); }
.online-count { padding: 3px 8px; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; }
.conn-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 8px currentColor; }
.conn-dot.online { background: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 480px) 1fr;
  gap: 24px;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
}

.board-column { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 5 / 6;
}
.row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }

.tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  background: var(--panel);
  border: 2px solid var(--border);
  color: var(--text);
  font-size: clamp(20px, 6vw, 32px);
  font-weight: 800;
  text-transform: uppercase;
  border-radius: 6px;
  user-select: none;
  transition: transform .12s ease, background .2s ease, border-color .2s ease;
}
.tile.filled { border-color: #5a6b80; animation: pop .12s ease; }
.tile.g { background: var(--accent); border-color: var(--accent); color: #fff; }
.tile.y { background: var(--yellow); border-color: var(--yellow); color: #1a1a1a; }
.tile.x { background: var(--gray); border-color: var(--gray); color: #fff; }
.tile.mini { width: 20px; height: 20px; aspect-ratio: 1; font-size: 11px; border-radius: 3px; }

@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
.tile.flip { animation: flip .5s ease forwards; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}
.row.shake { animation: shake .4s ease; }

.message {
  min-height: 24px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}
.message.win { color: var(--accent); font-weight: 700; }
.message.lose { color: var(--danger); font-weight: 700; }

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 500px;
  padding: 6px 0;
}
.kb-row { display: flex; justify-content: center; gap: 4px; }
.key {
  min-width: 30px;
  flex: 1 1 30px;
  height: 48px;
  font-weight: 700;
  font-size: 14px;
  background: var(--panel-2);
  color: var(--text);
  border: none;
  border-radius: 5px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background .15s;
}
.key:hover { background: #2f4056; }
.key.wide { flex: 1 1 60px; font-size: 12px; }
.key.g { background: var(--accent); color: #fff; }
.key.y { background: var(--yellow); color: #1a1a1a; }
.key.x { background: var(--gray); color: #fff; }

.side-column {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  min-height: 300px;
}
.side-title { margin: 0 0 12px; font-size: 16px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.players {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
}
.player {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.player.me { border-color: var(--focus); }
.player.winner { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.player-head { display: flex; justify-content: space-between; align-items: center; }
.player-name { font-weight: 700; }
.player-score { color: var(--muted); font-size: 13px; }
.player-guesses { display: flex; gap: 3px; flex-wrap: wrap; }
.mini-row { display: flex; gap: 2px; }
.mini-cell {
  width: 12px; height: 12px; border-radius: 2px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.mini-cell.g { background: var(--accent); border-color: var(--accent); }
.mini-cell.y { background: var(--yellow); border-color: var(--yellow); }
.mini-cell.x { background: var(--gray); border-color: var(--gray); }

.leaderboard { margin: 0 0 20px; }
.leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.lb-row.lb-me { border-color: var(--focus); }
.lb-row:first-child { border-color: #c9b458; background: rgba(201,180,88,.08); }
.lb-rank { width: 20px; font-weight: 700; color: var(--muted); text-align: center; flex-shrink: 0; }
.lb-row:first-child .lb-rank { color: #c9b458; }
.lb-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { color: var(--accent); font-weight: 700; flex-shrink: 0; }
.lb-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

.about h2 { font-size: 16px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.about p { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 8px 0; }
.legend { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 4px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

.seo {
  max-width: 1200px;
  margin: 20px auto 0;
  padding: 24px;
  color: var(--muted);
}
.seo h2 { color: var(--text); font-size: 20px; }
.seo h3 { color: var(--text); font-size: 16px; margin-top: 20px; }
.seo p { line-height: 1.6; font-size: 14px; }
.seo details { margin: 8px 0; padding: 10px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.seo summary { cursor: pointer; font-weight: 600; color: var(--text); }
.seo details p { margin: 8px 0 0; }

.footer {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
  margin-top: 20px;
}

.modal {
  position: fixed; inset: 0;
  background: rgba(5,10,15,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 0 8px; }
.modal-card p { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.modal-card input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  margin-bottom: 12px;
}
.modal-card input:focus { outline: 2px solid var(--focus); }
.modal-card button {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.modal-card button:hover { background: #5c9a56; }

.toast {
  position: fixed;
  top: 60px; left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 6px;
  font-weight: 600;
  z-index: 30;
  animation: fadeUp .3s ease;
  box-shadow: var(--shadow);
}
@keyframes fadeUp { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }
