:root {
  --bg: #0b0f17;
  --panel: rgba(255,255,255,0.06);
  --panel2: rgba(255,255,255,0.08);
  --border: rgba(255,255,255,0.12);
  --text: #e7eefc;
  --muted: rgba(231,238,252,0.72);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }

.topbar {
  display:flex; align-items:center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.22);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { color: var(--text); text-decoration:none; font-weight: 800; }
.h-title { font-weight: 900; flex: 1; text-align: center; }

.layout {
  padding: 14px;
  display: grid;
  grid-template-columns: 360px 1fr 340px;
  gap: 14px;
}
@media (max-width: 1060px) {
  .layout { grid-template-columns: 1fr; }
}

.panel { min-width: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

.cardTitle { font-weight: 900; margin-bottom: 10px; }
.sub { color: var(--muted); font-size: 13px; line-height: 1.35; }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

.row { display:flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }

.field { display:flex; flex-direction: column; gap: 6px; flex: 1; }
label { font-size: 12px; color: var(--muted); }

input, select, button {
  width: 100%;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.25);
  color: var(--text);
}
button { cursor: pointer; background: rgba(255,255,255,0.10); }
button.primary { background: rgba(90, 170, 255, 0.22); border-color: rgba(90,170,255,0.35); }
button.secondary { background: rgba(255,255,255,0.09); }
button.danger { background: rgba(255,90,90,0.18); border-color: rgba(255,90,90,0.35); }
button.ghost { width: auto; padding: 8px 12px; background: transparent; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.meta {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.18);
  font-size: 13px;
}

.hidden { display:none !important; }

.players, .leaderboard {
  display:flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.row .name { flex: 2; font-weight: 800; }
.row .pts, .row .sol { flex: 1; text-align: right; color: var(--muted); }

.tag {
  display:inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.08);
  font-size: 11px;
  color: var(--text);
}

.topRow {
  display:flex;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
}

.gridWrap { overflow: auto; padding: 10px 2px; }

table.sudoku {
  border-collapse: separate;
  border-spacing: 2px;
  background: rgba(255,255,255,0.10);
  padding: 2px;
  border-radius: 14px;
  border: 1px solid var(--border);
  margin: 0 auto;
}

table.sudoku td {
  padding: 0;
}

table.sudoku td.box-r { border-right: 3px solid rgba(255,255,255,0.22); padding-right: 2px; }
table.sudoku td.box-b { border-bottom: 3px solid rgba(255,255,255,0.22); padding-bottom: 2px; }

input.cell {
  width: 40px;
  height: 40px;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(0,0,0,0.30);
}

input.cell.clue {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.14);
}

/* Chat */
.chatCard { height: calc(100vh - 110px); min-height: 520px; display:flex; flex-direction: column; }
.chatLog { flex: 1; overflow:auto; display:flex; flex-direction: column; gap: 10px; padding-right: 6px; }
.chatRow { display:flex; gap: 10px; margin-top: 10px; }
.chatRow input { flex: 1; }
.chatRow button { width: 110px; }

.chat-msg {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.18);
}
.chat-msg .meta { margin: 0 0 4px; padding: 0; border: 0; background: transparent; display:flex; justify-content: space-between; color: var(--muted); }
.chat-msg .from { font-weight: 900; color: var(--text); }
.chat-msg .text { font-size: 13px; line-height: 1.35; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display:flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.modalCard {
  width: min(520px, 96vw);
  background: #0f1522;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
}

.modalHeader { display:flex; align-items:center; justify-content: space-between; gap: 10px; }
.modalTitle { font-weight: 900; }
.modalBody { margin-top: 12px; display:flex; flex-direction: column; gap: 14px; }
.modalFooter { margin-top: 12px; }


/* Helpers */
.helpers { align-items: stretch; }
.helperCard {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  min-height: 56px;
}
.helperTitle { font-weight: 800; font-size: 12px; letter-spacing: 0.4px; text-transform: uppercase; opacity: 0.9; margin-bottom: 6px; }
.missingCounts { display:flex; flex-wrap: wrap; gap: 10px; }
.missingCounts .miss b { font-weight: 900; }
.tipsRow { display:flex; align-items:center; gap: 10px; }
.cell.tip { outline: 2px solid rgba(255,255,255,0.25); }

/* Number picker popup */
input.cell:not(.clue):not(.tip) { cursor: pointer; }

.numPopup {
  position: absolute;
  width: min(320px, calc(100vw - 24px));
  background: #0f1522;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px;
  z-index: 50;
  box-shadow: 0 16px 40px rgba(0,0,0,0.55);
}

.numPopupHeader {
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.numPopupTitle { font-weight: 900; font-size: 13px; color: var(--text); }

.numPopupBtns {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.pickBtn {
  width: 100%;
  padding: 12px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.10);
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
}

.pickBtn.secondary {
  background: rgba(255,255,255,0.06);
  font-weight: 800;
}

@media (max-width: 420px) {
  .numPopupBtns { grid-template-columns: repeat(4, 1fr); }
}
