* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
button, input, .key { touch-action: manipulation; }
html, body { overflow-x: hidden; }
:root {
  --bg: #0f1117; --panel: #1a1d27; --text: #eceef3; --dim: #8b90a0;
  --green: #4caf6e; --yellow: #d4b13f; --gray: #3a3f4d; --edge: #2a2e3b;
  --accent: #6c8cff;
}
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center;
}
header {
  width: 100%; max-width: 520px; display: flex; justify-content: space-between;
  align-items: center; padding: 14px 18px;
}
h1 { font-size: 24px; letter-spacing: 1px; }
h1 span { color: var(--accent); }
#timer { font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 700; }
#timer.low { color: #ff6b6b; }

.view { width: 100%; max-width: 520px; padding: 12px 18px 30px; display: flex; flex-direction: column; gap: 14px; }
.hidden { display: none !important; }
.tag { color: var(--dim); text-align: center; }

input {
  background: var(--panel); border: 1px solid var(--edge); color: var(--text);
  border-radius: 10px; padding: 14px; font-size: 17px; width: 100%; text-align: center;
}
button {
  background: var(--panel); border: 1px solid var(--edge); color: var(--text);
  border-radius: 10px; padding: 14px 16px; font-size: 16px; cursor: pointer;
}
button.primary { background: var(--accent); border: none; color: #fff; font-weight: 700; }
.or { color: var(--dim); text-align: center; font-size: 13px; }
.joinrow { display: flex; gap: 10px; }
.joinrow input { flex: 1; letter-spacing: 6px; font-weight: 700; }

#roombar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel); border-radius: 10px; padding: 10px 14px;
}
#roombar b { letter-spacing: 3px; color: var(--accent); }
#roombar button { padding: 8px 12px; font-size: 13px; }

#waiting { text-align: center; display: flex; flex-direction: column; gap: 12px; }
#playerlist { line-height: 1.7; }
#playerlist .me { color: var(--accent); font-weight: 700; }

#banner {
  text-align: center; padding: 14px; border-radius: 12px; font-size: 18px; font-weight: 700;
  background: var(--panel); border: 1px solid var(--edge);
}
#banner.win { background: #1e3527; border-color: var(--green); }
#banner.lose { background: #35231e; border-color: #ff6b6b; }

#board { display: grid; grid-template-rows: repeat(6, 1fr); gap: 6px; justify-content: center; }
.row { display: grid; grid-template-columns: repeat(5, 56px); gap: 6px; }
.cell {
  width: 56px; height: 56px; border: 2px solid var(--edge); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; text-transform: uppercase;
}
.cell.filled { border-color: var(--dim); }
.cell.green { background: var(--green); border-color: var(--green); }
.cell.yellow { background: var(--yellow); border-color: var(--yellow); color: #1a1a1a; }
.cell.gray { background: var(--gray); border-color: var(--gray); }
.row.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-6px);} 40%,80% { transform: translateX(6px);} }

#opponents { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.opp { text-align: center; }
.opp .oname { font-size: 12px; color: var(--dim); margin-bottom: 4px; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp .oname.done { color: var(--green); font-weight: 700; }
.mini { display: grid; grid-template-rows: repeat(6, 1fr); gap: 2px; }
.mrow { display: grid; grid-template-columns: repeat(5, 13px); gap: 2px; }
.mcell { width: 13px; height: 13px; border-radius: 2px; background: var(--edge); }
.mcell.green { background: var(--green); }
.mcell.yellow { background: var(--yellow); }
.mcell.gray { background: var(--gray); }

#keyboard { display: flex; flex-direction: column; gap: 6px; user-select: none; }
.krow { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1 1 0; min-width: 0; padding: 0; max-width: 44px; height: 52px; background: #aab2c4; border: none; border-radius: 6px;
  color: #14161d; font-size: 15px; font-weight: 700; text-transform: uppercase;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.key.wide { flex: 1.4 1 0; max-width: 64px; font-size: 12px; }
.key.green { background: var(--green); color: #fff; }
.key.yellow { background: var(--yellow); color: #1a1a1a; }
.key.gray { background: #1c1f28; color: #4a4f5e; }

@media (max-width: 380px) {
  .row { grid-template-columns: repeat(5, 48px); }
  .cell { width: 48px; height: 48px; font-size: 22px; }
  .view { padding: 10px 8px 24px; }
  .krow { gap: 4px; }
}

#mystats {
  background: var(--panel); border: 1px solid var(--edge); border-radius: 10px;
  padding: 12px; text-align: center; font-size: 14px; color: var(--dim);
}
#mystats b { color: var(--accent); }
#leaderboard h2 { font-size: 16px; margin-bottom: 8px; text-align: center; }
#lbtable { width: 100%; border-collapse: collapse; font-size: 14px; }
#lbtable th { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
#lbtable th, #lbtable td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--edge); }
#lbtable td:nth-child(2), #lbtable th:nth-child(2) { text-align: left; }
