:root {
  --jungle-deep: #0d2818;
  --jungle: #143d24;
  --board: #1b4d2e;
  --board-edge: #0a1f12;
  --slot: #0c2416;
  --river: #2a7f9e;
  --sand: #e8dcc0;
  --text: #eaf3ec;
  --muted: #93b19f;
  --gold: #f2b134;
  --peg-size: 46px;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, #1d5c36 0%, transparent 60%),
    linear-gradient(170deg, var(--jungle) 0%, var(--jungle-deep) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

#app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px 14px calc(24px + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.01em; }

/* ---------- shared bits ---------- */

.card {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 16px;
}

button {
  font: inherit;
  font-weight: 700;
  color: #10240f;
  background: var(--gold);
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  cursor: pointer;
  box-shadow: 0 3px 0 #b8801f;
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
}

button:hover:not(:disabled) { filter: brightness(1.06); }

button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 0 0 #b8801f;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}

button.ghost {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}

/* Fixed width so swapping to the confirm label does not reflow the header. */
button.ghost.leave { min-width: 118px; }

button.ghost.danger {
  background: #8c3535;
  color: #fff;
  box-shadow: 0 3px 0 #5c2020;
}

input[type="text"] {
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 12px 14px;
  width: 100%;
}

input[type="text"]:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }

/* ---------- lobby ---------- */

.lobby {
  max-width: 460px;
  margin: 6vh auto 0;
  text-align: center;
}

.lobby h1 { font-size: 34px; line-height: 1.1; }

.lobby .tagline { color: var(--muted); margin: 8px 0 26px; }

.lobby-animals { font-size: 34px; letter-spacing: 6px; margin-bottom: 10px; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.12);
}

.code-input { text-transform: uppercase; letter-spacing: 0.3em; text-align: center; font-weight: 800; }

/* ---------- header ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.room-code {
  font-weight: 800;
  letter-spacing: 0.2em;
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 10px;
  border-radius: 8px;
}

.scoreline { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 14px; }

.score-chip {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 999px;
  padding: 6px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.score-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf6d;
}

.score-chip.offline .dot { background: #8a5a5a; }
.score-chip.you { outline: 1px solid var(--gold); }

/* ---------- layout ---------- */

.game {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

@media (min-width: 860px) {
  .game { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
}

/* ---------- board ---------- */

.board {
  background: linear-gradient(180deg, var(--board) 0%, var(--board-edge) 100%);
  border: 2px solid rgba(0, 0, 0, 0.35);
  border-radius: 18px;
  padding: 14px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.07), 0 10px 24px rgba(0, 0, 0, 0.35);
}

.board-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
  gap: 10px;
  flex-wrap: wrap;
}

.level-label { color: var(--muted); font-size: 13px; }

.guess-row {
  display: grid;
  grid-template-columns: 26px max-content max-content;
  justify-content: start;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: 12px;
}

.guess-row + .guess-row { margin-top: 4px; }

.guess-row.active {
  background: rgba(242, 177, 52, 0.1);
  box-shadow: inset 0 0 0 1px rgba(242, 177, 52, 0.35);
}

.guess-row.pending { opacity: 0.4; }

.row-num {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}

.pegs { display: flex; gap: 8px; }

.peg {
  width: var(--peg-size);
  height: var(--peg-size);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: calc(var(--peg-size) * 0.55);
  line-height: 1;
  border: none;
  padding: 0;
  color: inherit;
  background: var(--slot);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.6);
  flex: none;
}

.peg.filled {
  background: radial-gradient(circle at 34% 26%, rgba(255, 255, 255, 0.55), transparent 55%), var(--peg-color, #888);
  box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.35), 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* Only pegs that just arrived animate, so re-renders do not replay the board. */
.peg.filled.pop { animation: drop 0.22s cubic-bezier(0.3, 1.5, 0.5, 1); }

.peg.hidden-peg { font-size: calc(var(--peg-size) * 0.42); color: var(--muted); }

@keyframes drop {
  from { transform: translateY(-14px) scale(0.8); opacity: 0; }
  to { transform: none; opacity: 1; }
}

button.peg { cursor: pointer; box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.6); }
button.peg.filled { cursor: pointer; }
button.peg:active { transform: scale(0.92); }

/* clue pegs: the white "toothy" markers from the box */

.clues {
  display: flex;
  gap: 4px;
  margin-left: 8px;
  padding-left: 12px;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.clue {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #0a1f12;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.7);
  flex: none;
}

.clue.hit {
  background: radial-gradient(circle at 35% 28%, #fff, #d3dbd2 70%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.clue.hit.pop { animation: pop 0.3s backwards cubic-bezier(0.3, 1.6, 0.5, 1); }

@keyframes pop {
  from { transform: scale(0); }
  to { transform: none; }
}

/* ---------- animal picker ---------- */

/* Pinned to the bottom of the viewport so the guesser never has to scroll past
   ten rows to reach the animals. */
.controls {
  position: sticky;
  bottom: 0;
  margin: 12px -14px -14px;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(10, 31, 18, 0.82), rgba(10, 31, 18, 0.97));
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0 0 16px 16px;
}

.picker { margin-top: 14px; }

.controls .picker { margin-top: 0; }

.picker-label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.picker-pegs { display: flex; gap: 8px; flex-wrap: wrap; }

.levels { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

.level-btn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  padding: 9px 14px;
  font-size: 14px;
}

.level-btn.on {
  background: var(--gold);
  color: #10240f;
  box-shadow: 0 2px 0 #b8801f;
}

/* ---------- status panels ---------- */

.status {
  text-align: center;
  padding: 22px 16px;
}

.status .big { font-size: 22px; font-weight: 800; margin-bottom: 6px; }

.waiting-dots::after {
  content: "";
  animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

.secret-strip {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.secret-strip .label { font-size: 13px; color: var(--muted); }
.secret-strip .pegs { --peg-size: 34px; }

/* ---------- chat ---------- */

.chat { display: flex; flex-direction: column; max-height: 420px; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
  margin-bottom: 10px;
  padding-right: 4px;
}

.chat-msg { font-size: 14px; line-height: 1.35; }
.chat-msg .who { font-weight: 800; color: var(--gold); margin-right: 6px; }
.chat-msg.mine .who { color: #8fd6a6; }
.chat-empty { color: var(--muted); font-size: 14px; }
.chat-form { display: flex; gap: 8px; }
.chat-form button { padding: 12px 14px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #7a2f2f;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  z-index: 10;
  max-width: min(92vw, 420px);
  text-align: center;
}

.banner {
  background: rgba(0, 0, 0, 0.3);
  border-left: 3px solid var(--gold);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 12px;
}

@media (max-width: 520px) {
  .topbar { gap: 8px; margin-bottom: 10px; }
  .topbar h2 { font-size: 20px; }
  .topbar button.ghost { padding: 7px 11px; font-size: 13px; }
  .scoreline .muted { display: none; }
  .score-chip { padding: 5px 10px; font-size: 13px; }
}

@media (max-width: 420px) {
  :root { --peg-size: 40px; }
  .lobby h1 { font-size: 28px; }
  .lobby { margin-top: 3vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
