:root {
  --bg: #0b0f17;
  --card: rgba(20, 26, 38, 0.88);
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef2f8;
  --muted: #93a0b5;
  --accent: #5fe06d;
  --accent-ink: #0b1a0d;
  --warn: #ff7a6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none; /* no pull to refresh or swipe back bounce */
  -webkit-tap-highlight-color: transparent;
}

/* While playing, nothing can be selected or long-press highlighted. */
body[data-screen="game"] {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

[hidden] { display: none !important; }

#bg, #game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#game { touch-action: none; cursor: crosshair; }

#lobby {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

/* The lobby card and the all-time board sit side by side, and stack when narrow. */
.lobby-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  align-items: flex-start;
  margin: auto;
  width: 100%;
  max-width: 830px; /* room for both cards side by side; narrower screens stack them */
}
.lobby-wrap > .card { margin: 0; }
.lobby-wrap > .lobby-card { flex: 0 1 460px; }
.board-card { flex: 0 1 340px; max-width: 340px; }
.board-card h2 { margin: 0 0 10px; font-size: 18px; color: #ffcf4d; }

.board { list-style: none; margin: 0; padding: 0; text-align: left; }
.board li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 14px;
}
.board li:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.board li.mine { background: rgba(255, 207, 77, 0.18); outline: 1px solid rgba(255, 207, 77, 0.6); }
.board .b-rank { width: 30px; color: var(--muted); font-variant-numeric: tabular-nums; }
.board .b-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.board .b-name small { font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 12px; }
.board .b-score { font-variant-numeric: tabular-nums; font-weight: 700; }
.board .board-empty { color: var(--muted); font-style: italic; justify-content: center; }
.board-small li { font-size: 13px; padding: 3px 8px; }

.board-line { margin: 4px 0 8px; font-weight: 600; }

/* Watch an ad to respawn: offered on the death screen with a 10 second ring. */
.revive-panel {
  position: relative;
  margin: 8px 0 10px;
  padding: 12px 12px 12px 58px;
  border-radius: 12px;
  border: 1px solid rgba(255, 207, 77, 0.55);
  background: rgba(255, 207, 77, 0.1);
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.35s ease, margin 0.35s ease, padding 0.35s ease;
  max-height: 200px;
}
.revive-panel.folding { max-height: 0; opacity: 0; margin: 0; padding-top: 0; padding-bottom: 0; }
.revive-panel p { margin: 0 0 10px; font-weight: 700; }
.revive-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.revive-buttons > button { flex: 1 1 110px; padding: 10px 12px; font-size: 15px; white-space: nowrap; }
.revive-ring { position: absolute; left: 12px; top: 14px; width: 36px; height: 36px; transform: rotate(-90deg); }
.revive-ring circle { fill: none; stroke-width: 3.5; }
.revive-ring .track { stroke: rgba(255, 255, 255, 0.15); }
.revive-ring .left { stroke: #ffcf4d; stroke-dasharray: 97.4; stroke-dashoffset: 0; }
.revive-panel.counting .revive-ring .left { animation: revive-ring var(--revive-ms, 10000ms) linear forwards; }
@keyframes revive-ring { to { stroke-dashoffset: 97.4; } }
.revive-msg { margin: 0 0 8px; color: var(--muted); font-size: 13px; text-align: center; }
.death-actions.waiting { opacity: 0.4; pointer-events: none; }

/* The test ad (only with ?ads=test or on localhost with ADS_PROVIDER=fake). */
#adOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(6, 5, 4, 0.86);
  color: #fff;
  text-align: center;
}
#adOverlay .ad-title { font-size: 28px; font-weight: 800; letter-spacing: 1px; }
#adOverlay .ad-count { font-size: 56px; font-weight: 800; color: #ffcf4d; font-variant-numeric: tabular-nums; }
#adOverlay .ad-note { color: var(--muted); font-size: 14px; }
#bestLine { text-align: center; margin: 0 0 6px; }

/* Arrived from a challenge link: the friend's score, above the server list. */
.beat-banner {
  margin: 0 0 8px;
  padding: 7px 12px;
  border-radius: 9px;
  background: rgba(255, 207, 77, 0.14);
  border: 1px solid rgba(255, 207, 77, 0.5);
  color: #ffcf4d;
  font-weight: 700;
  font-size: 14px;
}
.board-line.made {
  font-size: 20px;
  font-weight: 800;
  color: transparent;
  background: linear-gradient(100deg, #ffcf4d 0%, #ffcf4d 40%, #fff6d2 50%, #ffcf4d 60%, #ffcf4d 100%);
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: shine 1.4s ease-out 2;
}
@keyframes shine {
  from { background-position: 100% 0; }
  to { background-position: -50% 0; }
}

.card {
  width: 100%;
  max-width: 460px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px 24px 18px;
  backdrop-filter: blur(8px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  margin: auto;
}

h1 {
  margin: 0;
  font-size: 44px;
  letter-spacing: 0.5px;
  text-align: center;
  background: linear-gradient(90deg, #5fe06d, #3ee0c8, #4ea6ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tag { margin: 4px 0 18px; text-align: center; color: var(--muted); font-size: 14px; }
/* "Savory worm snacks." Like the label on a snack bag: tiny, cream, a little spaced out. */
.snack-tag {
  margin: -2px 0 0;
  text-align: center;
  color: #e6d5b1;
  opacity: 0.8;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.6px;
}
.snack-tag + .tag { margin-top: 2px; }

/* About, privacy, terms and contact: small and out of the way under the lobby. */
.site-links { flex: 1 1 100%; display: flex; justify-content: center; gap: 16px; margin-top: -4px; font-size: 12px; }
.site-links a { color: var(--muted); text-decoration: none; opacity: 0.8; }
.site-links a:hover { color: var(--text); text-decoration: underline; }

/* Cookie choice for visitors in Europe and the UK (consent.js). */
#consentBanner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 60;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 207, 77, 0.45);
  background: rgba(20, 15, 11, 0.96);
  color: #f3ead8;
  font-size: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
#consentBanner p { flex: 1 1 260px; margin: 0; }
#consentBanner a { color: #7fd3ff; }
#consentBanner .consent-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
#consentBanner button { padding: 8px 14px; font-size: 14px; }

.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }

#skins { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.skin {
  padding: 0;
  height: 44px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}
.skin canvas { width: 100%; height: 100%; display: block; }
.skin[aria-checked="true"] { border-color: var(--accent); background: rgba(95, 224, 109, 0.1); }
.skin:focus-visible { outline: 2px solid #4ea6ff; outline-offset: 2px; }

.pickline { margin: -2px 0 8px; font-size: 13px; color: var(--muted); }
.room {
  display: flex;
  flex-wrap: wrap;
  row-gap: 6px;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  margin-bottom: 4px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
}
.room.selected { border-color: rgba(95, 224, 109, 0.6); background: rgba(95, 224, 109, 0.08); }
.room .rname { flex: 1 1 110px; font-weight: 600; }
.room .count { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; min-width: 48px; text-align: right; }
.room .count.full { color: var(--warn); }
/* While a row says "Copied! Paste it anywhere", hide its count and let the name shrink
   so Join stays on the same line. */
.room:has(.invite.done) .count { display: none; }
.room:has(.invite.done) .rname { flex-basis: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room .invite.done { font-size: 12px; padding-left: 8px; padding-right: 8px; }

button {
  font: inherit;
  cursor: pointer;
}
.join, .primary {
  border: 0;
  border-radius: 9px;
  padding: 8px 16px;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-ink);
}
.join:hover:not(:disabled), .primary:hover { filter: brightness(1.1); }
.join:disabled { background: rgba(255, 255, 255, 0.1); color: var(--muted); cursor: not-allowed; }

.msg { min-height: 1.2em; margin: 6px 0 0; font-size: 13px; color: var(--warn); }
/* Invite friends: gold outline, white text, reads as an action. */
.invite {
  border: 2px solid #ffcf4d;
  border-radius: 9px;
  padding: 6px 12px;
  background: rgba(255, 207, 77, 0.08);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}
.invite:hover { background: rgba(255, 207, 77, 0.2); }
.invite.done { background: #ffcf4d; color: #1d1405; }
.invite.big { padding: 12px 20px; font-size: 16px; }
.invite.pill {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 999px;
  padding: 6px 16px;
  background: rgba(10, 8, 6, 0.72);
  z-index: 5;
}
.invite.pill.done { background: #ffcf4d; }
.invite-hint { margin: -2px 0 6px 12px; font-size: 12px; color: #ffcf4d; }
.death-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.death-actions > button { flex: 1 1 140px; }
#linkBox {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: 460px;
  z-index: 10;
}
#linkBox p { margin: 0 0 8px; font-size: 14px; }
#linkBox input { margin-bottom: 10px; }

.linkbtn {
  border: 0;
  background: none;
  padding: 2px 0;
  color: #4ea6ff;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.help span { display: block; }
#tagline { color: var(--text); font-weight: 600; margin-bottom: 2px; }
.help { margin: 4px 0 0; text-align: center; font-size: 13px; color: var(--muted); }

#death {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 16px;
  background: rgba(5, 8, 12, 0.55);
}
.death-card { text-align: center; max-width: 360px; }
.death-card h2 { margin: 0 0 6px; font-size: 30px; }
.death-card p { color: var(--muted); margin: 0 0 16px; }
.death-card p.death-level { margin: -10px 0 16px; color: #ffcf4d; font-weight: 600; }
.stats { display: flex; gap: 10px; margin-bottom: 10px; }
.stats + .stats { margin-bottom: 18px; }
.stats > div { flex: 1; background: rgba(255, 255, 255, 0.04); border-radius: 10px; padding: 10px; }
.stats span { display: block; font-size: 12px; color: var(--muted); }
.stats strong { font-size: 26px; font-variant-numeric: tabular-nums; }
.primary { padding: 12px 28px; font-size: 17px; }

/* ---------- Suggestions ---------- */
.secondary {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 9px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-weight: 600;
}
.secondary:hover { background: rgba(255, 255, 255, 0.12); }
.suggest-btn { width: 100%; margin: 2px 0 10px; }

#suggest {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  padding: 16px;
}
.suggest-wrap { max-width: 900px; margin: 0 auto; padding-bottom: 40px; }
.suggest-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.suggest-head h1 { font-size: 30px; text-align: left; }
#suggest h2 { margin: 16px 0 2px; font-size: 18px; color: #ffcf4d; }
#suggest h3 { margin: 18px 0 8px; font-size: 14px; color: #5fe06d; text-transform: uppercase; letter-spacing: 0.8px; }
.suggest-sub { margin: 0 0 10px; color: var(--muted); font-size: 13px; }

.sugg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.sugg-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  min-height: 92px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.sugg-card:not(:disabled):hover { border-color: rgba(255, 207, 77, 0.6); transform: translateY(-1px); }
.sugg-card:disabled { cursor: default; }
.sugg-card.voted { border-color: #ffcf4d; }
.sugg-card.pending { border-style: dashed; opacity: 0.85; }
.sugg-card.fresh { animation: slidein 0.4s ease-out; }
.done-grid .sugg-card { min-height: 0; opacity: 0.8; }
@keyframes slidein {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.sugg-text { font-size: 15px; font-weight: 600; line-height: 1.35; }
.sugg-foot { display: flex; align-items: center; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.sugg-votes { font-weight: 800; font-variant-numeric: tabular-nums; }
.sugg-you { color: #ffcf4d; font-weight: 600; }
.sugg-pill { margin-left: auto; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.sugg-pill.planned { background: rgba(255, 207, 77, 0.18); color: #ffcf4d; }
.sugg-pill.done { background: rgba(95, 224, 109, 0.18); color: #5fe06d; }
.sugg-pill.pending { background: rgba(255, 255, 255, 0.1); color: var(--muted); }
.sugg-empty { color: var(--muted); font-style: italic; }

.or-rule { display: flex; align-items: center; gap: 12px; margin: 26px 0 6px; color: var(--muted); font-weight: 800; letter-spacing: 2px; }
.or-rule::before, .or-rule::after { content: ""; flex: 1; height: 1px; background: rgba(255, 207, 77, 0.35); }

.suggest-form { display: flex; gap: 8px; margin-top: 8px; }
.suggest-form input { flex: 1; min-width: 0; }
.suggest-form .join { padding: 10px 18px; }
.suggest-count { text-align: right; font-size: 12px; color: var(--muted); margin-top: 4px; }
.suggest-count .near { color: #ffcf4d; }
.suggest-msg { min-height: 1.3em; margin: 6px 0; color: #ffcf4d; font-size: 14px; }
.dup-box { margin-top: 8px; padding: 12px; border: 1px solid rgba(255, 207, 77, 0.4); border-radius: 12px; background: rgba(255, 207, 77, 0.06); }
.dup-box p { margin: 0 0 10px; font-weight: 600; }
.dup-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* Sound toggle, top right, just left of the leaderboard. Shown on every screen. */
#muteBtn {
  position: fixed;
  top: 12px;
  right: 244px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(10, 8, 6, 0.6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  padding: 0;
}
body[data-screen="lobby"] #muteBtn, body[data-screen="suggest"] #muteBtn { right: 12px; }
#muteBtn .cross { display: none; }
#muteBtn.muted .cross { display: inline; }
#muteBtn.muted .waves { display: none; }
#muteBtn.muted { color: #ff8a80; }
@media (max-width: 560px) { #muteBtn { right: 12px; top: auto; bottom: 12px; } }

/* Phones (body.compact, set by viewport.js) while playing: one row along the top edge.
   Server name on the left (drawn on the canvas), then Invite friends and the mute
   button on the right. The one-line leaderboard sits just under them. */
body.compact[data-screen="game"] #muteBtn,
body.compact[data-screen="death"] #muteBtn {
  top: 8px;
  right: 10px;
  bottom: auto;
  width: 30px;
  height: 30px;
}
body.compact .invite.pill {
  top: 8px;
  left: auto;
  right: 48px;
  transform: none;
  padding: 5px 12px;
  font-size: 12px;
}

/* ?debug=1: tiny size readout in the bottom left, on every screen. */
#debugReadout {
  position: fixed;
  left: 4px;
  bottom: 2px;
  z-index: 50;
  padding: 1px 4px;
  font: 10px/1.3 ui-monospace, Consolas, monospace;
  color: rgba(255, 255, 255, 0.8);
  background: rgba(0, 0, 0, 0.55);
  border-radius: 3px;
  pointer-events: none;
}

#boostBtn {
  position: fixed;
  left: 18px;
  bottom: 70px;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 700;
  touch-action: none;
  user-select: none;
}
#boostBtn.down { background: rgba(95, 224, 109, 0.45); }

/* Stacked layout: the columns dissolve and the help line moves to the bottom. */
.lobby-card { display: flex; flex-direction: column; }
.lobby-card .col { display: contents; }
.lobby-card .help { order: 1; }

/* Phones held sideways: two columns so everything fits without scrolling. */
@media (max-height: 520px) and (min-width: 560px) {
  .lobby-card {
    max-width: 760px;
    flex-direction: row;
    gap: 22px;
    padding: 14px 18px;
  }
  .lobby-card .col { display: block; flex: 1; min-width: 0; }
  .lobby-wrap { max-width: 780px; }
  .lobby-wrap > .lobby-card { flex: 0 1 760px; max-width: 760px; }
  .room { gap: 6px; }
  .room .rname { flex: 1 1 80px; font-size: 14px; }
  .room .count { min-width: 0; font-size: 12px; }
  .room .invite { font-size: 12px; padding: 4px 8px; }
  .lobby-card .help { text-align: left; }
  h1 { font-size: 30px; text-align: left; }
  .tag { text-align: left; margin-bottom: 10px; }
  .field { margin-bottom: 10px; }
  .room { padding: 4px 6px 4px 10px; margin-bottom: 3px; }
  .join { padding: 5px 14px; }
  #skins { grid-template-columns: repeat(3, 1fr); }
  .skin { height: 38px; }
}
@media (max-height: 520px) and (max-width: 559px) {
  .card { padding: 14px 18px 12px; }
  h1 { font-size: 30px; }
}
