* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #10131a;
  color: #f2f2f2;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

body {
  display: grid;
  place-items: center;
}

/* The game is always 16:9 and as large as fits the window (or the iframe). */
#game {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  font-size: clamp(10px, 1.6vw, 15px);
}

#canvas {
  /* Absolute, so the canvas's own size (1920 × 1080) never stretches the 16:9 box. */
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  cursor: pointer;
}

.panel {
  position: absolute;
  background: rgba(10, 12, 20, 0.62);
  border-radius: 8px;
  padding: 0.5em 0.7em;
}

#status {
  bottom: 0.6em;
  left: 0.6em;
  font-size: 0.85em;
}

#players {
  top: 0.6em;
  right: 0.6em;
  min-width: 9em;
  max-height: 45%;
  overflow-y: auto;
}

#players h2 {
  margin: 0 0 0.3em;
  font-size: 1em;
}

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

#player-list li {
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.1em 0;
}

#player-list .dot {
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  flex: none;
}

/* ---- Chat, top left (like Roblox) ----
   #chat.active  = you're typing or pointing at it: dark box + typing bar
   #chat.faded   = 3 s after the last message: messages fade away too
   #chat[hidden] = turned off with the 💬 button */
#chat-area {
  position: absolute;
  top: 0.6em;
  left: 0.6em;
  width: min(24em, 45%);
}

#chat-toggle {
  position: relative;
  font-size: 1.1em;
  line-height: 1;
  padding: 0.3em 0.45em;
  border: 0;
  border-radius: 8px;
  background: rgba(10, 12, 20, 0.62);
  cursor: pointer;
}

#chat-toggle[aria-pressed="false"] {
  opacity: 0.6;
}

/* Red dot: new messages while the chat is hidden */
#chat-dot {
  position: absolute;
  top: -0.2em;
  right: -0.2em;
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  background: #e74c3c;
}

#chat {
  margin-top: 0.4em;
  padding: 0.4em 0.6em;
  border-radius: 8px;
  background: transparent;
  transition: background 0.3s;
}

#chat.active {
  background: rgba(10, 12, 20, 0.62);
}

#chat-log {
  list-style: none;
  margin: 0 0 0.4em;
  padding: 0;
  max-height: 8em;
  overflow: hidden;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 2px #000, 0 0 3px #000; /* readable on the map without a box */
  transition: opacity 1s;
}

#chat.active #chat-log {
  overflow-y: auto;
}

#chat.faded:not(.active) #chat-log {
  opacity: 0;
}

#chat-log li {
  padding: 0.05em 0;
}

#chat-log .who {
  font-weight: 700;
}

#chat-log .system {
  color: #a9b3c9;
  font-style: italic;
}

#help {
  right: 0.6em;
  bottom: 0.6em;
  font-size: 0.8em;
  color: #c4cbe0;
}

#sign-popup {
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  width: min(26em, 80%);
  padding: 0.9em 1.2em;
  text-align: center;
  background: rgba(10, 12, 20, 0.85);
  border: 2px solid #c87400;
}

#sign-popup p {
  margin: 0 0 0.4em;
  font-size: 1.15em;
  font-weight: 700;
}

#sign-popup #sign-reward {
  font-size: 1em;
  color: #ffd166;
}

#sign-popup #sign-reward:empty {
  display: none;
}

#claim-button {
  font: inherit;
  font-weight: 700;
  margin: 0.2em 0 0.5em;
  padding: 0.45em 1.6em;
  border: 2px solid #000;
  border-radius: 8px;
  background: #ffb000;
  color: #1b1b1b;
  cursor: pointer;
}

#claim-button:hover {
  filter: brightness(1.08);
}

#claim-button:disabled {
  opacity: 0.6;
  cursor: default;
}

#sign-popup small {
  color: #a9b3c9;
}

#players.hidden {
  display: none;
}

#chat-input {
  width: 100%;
  font: inherit;
  padding: 0.4em 0.6em;
  border: 1px solid #39405a;
  border-radius: 6px;
  background: #1b2030;
  color: inherit;
  transition: opacity 0.3s;
}

/* The typing bar is invisible until you press / or click it (still clickable). */
#chat:not(.active) #chat-input {
  opacity: 0;
}

#notice {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7em;
  background: rgba(10, 12, 20, 0.85);
  text-align: center;
  padding: 1em;
}

#notice h1 {
  margin: 0;
  font-size: 2em;
}

#notice p {
  margin: 0;
  color: #c4cbe0;
}

#notice a {
  font-weight: 700;
  padding: 0.5em 2em;
  border-radius: 6px;
  background: #e74c3c;
  color: #fff;
  text-decoration: none;
}

#notice.hidden {
  display: none;
}
