html, body { height: 100%; }

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 16px;
  overflow: hidden;
  --board: min(78vh, 92vw);
}

/* ---- board ---- */
#stage {
  position: relative;
  width: var(--board);
  aspect-ratio: 1;
  background: var(--paper);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 30px rgba(0, 0, 0, .06);
}

#canvas, #canvas svg { width: 100%; height: 100%; display: block; }

#timer {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

#progress {
  position: absolute;
  right: 14px;
  bottom: 10px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

#guessForm { display: flex; gap: 8px; width: var(--board); }

#guessForm input {
  flex: 1;
  min-width: 0;
  font-size: 18px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

#guessForm input:focus { outline: 2px solid var(--ink); outline-offset: 1px; }

.primary {
  font-size: 18px;
  padding: 10px 20px;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
}

/* ---- top bar ---- */
#origin {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

#topLeft { position: fixed; top: 14px; left: 16px; z-index: 20; display: flex; align-items: center; gap: 10px; }

#online { font-size: 13px; color: var(--muted); }

/* Leaderboard: a side panel when there is room left of the board, otherwise a drop-down. */
#leaderboard {
  position: fixed;
  top: 54px;
  left: 16px;
  z-index: 19;
  width: 170px;
  padding: 10px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .06);
  font-size: 13px;
  display: none;
}

#leaderboard.open, body.side-board #leaderboard { display: block; }

body.side-board #rankBtn { display: none; }

#leaderboard h2 { margin: 0 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

#rankList { margin: 0; padding: 0; list-style: none; }

#rankList li { display: flex; gap: 6px; padding: 3px 0; }

#rankList .rank { width: 1.6em; color: var(--muted); font-variant-numeric: tabular-nums; }

#rankList .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#rankList .score { font-variant-numeric: tabular-nums; }

#rankList li.me { font-weight: 700; }

#rankList .empty { color: var(--muted); }

#account { position: fixed; top: 14px; right: 16px; z-index: 20; font-size: 13px; }

.chip {
  font-size: 13px;
  padding: 6px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chip:hover { background: var(--hover); }

#userWrap { position: relative; }

#menu {
  position: absolute;
  right: 0;
  top: 34px;
  min-width: 140px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .08);
}

#menu a { color: inherit; text-decoration: none; font-size: 13px; padding: 7px 10px; border-radius: 6px; }

#menu a:hover { background: var(--hover); }

#menu button { text-align: left; font-size: 13px; border: 0; background: transparent; padding: 7px 10px; border-radius: 6px; }

#menu button:hover { background: var(--hover); }

/* ---- feedback ---- */
#toast {
  position: fixed;
  top: 54px;
  right: 16px;
  z-index: 30;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  opacity: 0;
  transition: opacity .18s;
  pointer-events: none;
}

#toast.show, #overlay.show { opacity: 1; }

#overlay {
  position: fixed;
  inset: 0;
  z-index: 22;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s;
}

#overlay .title {
  white-space: pre-line;
  text-align: center;
  font-size: min(5vh, 7vw);
  font-weight: 700;
  background: rgba(255, 253, 248, .9);
  padding: 10px 18px;
  border-radius: 12px;
}

#overlay .number {
  font-size: min(16vh, 24vw);
  font-weight: 800;
  line-height: 1.1;
  text-shadow: 0 0 8px var(--paper), 0 0 16px var(--paper);
}

/* ---- dialogs ---- */
dialog {
  width: min(92vw, 320px);
  padding: 18px;
  border: 0;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
}

dialog::backdrop { background: rgba(31, 29, 26, .28); }

dialog form { display: flex; gap: 8px; margin-top: 10px; }

dialog input { flex: 1; min-width: 0; font-size: 15px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

dialog .primary { font-size: 14px; padding: 9px 12px; }

.close { display: block; margin-left: auto; border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 4px; }

.hint { margin-top: 8px; font-size: 12px; color: var(--muted); word-break: break-all; }

@media (max-width: 520px) {
  body { --board: min(64vh, 94vw); }
  #origin { font-size: 12px; max-width: 80vw; overflow: hidden; text-overflow: ellipsis; }
}
