:root {
  --ink: #1d2419;
  --paper: #fffefa;
  --lime: #d8fd71;
  --dark: #292a23;
  --panel: rgba(255, 254, 250, 0.94);
  --shadow: 0 10px 30px rgba(20, 40, 20, 0.25);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #9fd6f5;
  color: var(--ink);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#flash {
  position: fixed;
  inset: 0;
  background: #ff3b3b;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease-out;
}
#flash.on { opacity: 0.35; transition: none; }

/* ---- the start.ng player card */
.startng-card {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 6px;
  border-radius: 999px;
  background: var(--dark);
  color: var(--paper);
  box-shadow: var(--shadow);
  z-index: 5;
  max-width: calc(100vw - 24px);
}
.startng-card img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--lime);
  object-fit: cover;
  flex: none;
}
.startng-card .who { display: flex; flex-direction: column; min-width: 0; }
.startng-card b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.startng-card span { font-size: 12px; opacity: 0.7; white-space: nowrap; }
.startng-card button {
  margin-left: 6px;
  border: 0;
  border-radius: 999px;
  padding: 7px 13px;
  background: var(--lime);
  color: var(--ink);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

/* ---- in-game HUD */
.hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 5;
}
.stat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-weight: 800;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.hearts i {
  display: inline-block;
  width: 16px;
  height: 16px;
  background: #ff3b5c;
  clip-path: polygon(50% 100%, 0 38%, 0 20%, 18% 0, 50% 18%, 82% 0, 100% 20%, 100% 38%);
  transition: transform 0.2s, opacity 0.2s;
}
.hearts i.lost { opacity: 0.18; transform: scale(0.8); }
.gem-icon {
  width: 14px;
  height: 14px;
  background: linear-gradient(135deg, #9ae8ff, #2aa6d8);
  transform: rotate(45deg);
  border-radius: 2px;
}

.toast {
  position: fixed;
  left: 50%;
  top: 22%;
  transform: translate(-50%, 0);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--dark);
  color: var(--lime);
  font-weight: 800;
  font-size: 18px;
  z-index: 5;
  pointer-events: none;
  animation: pop 0.9s ease-out forwards;
}
@keyframes pop {
  0% { transform: translate(-50%, 10px) scale(0.8); opacity: 0; }
  15% { transform: translate(-50%, 0) scale(1.05); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -24px) scale(1); opacity: 0; }
}

/* ---- touch controls */
#joystick {
  position: fixed;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.6);
  transform: translate(-50%, -50%);
  z-index: 6;
  pointer-events: none;
}
#joystick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  transform: translate(-50%, -50%);
}
#jump-btn {
  position: fixed;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(26px, env(safe-area-inset-bottom));
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 0;
  background: var(--lime);
  color: var(--ink);
  font-weight: 900;
  font-size: 15px;
  box-shadow: var(--shadow);
  z-index: 6;
  font-family: inherit;
}
#jump-btn:active { transform: scale(0.94); }

/* ---- overlay panel (start / game over) */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 40, 30, 0.35);
  z-index: 10;
  backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }
.panel {
  width: min(440px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 22px 22px 18px;
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}
.brand {
  display: inline-block;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--lime);
}
.brand span { opacity: 0.6; }
.panel h1 {
  margin: 12px 0 4px;
  font-size: clamp(34px, 8vw, 44px);
  letter-spacing: -0.02em;
}
.panel p { margin: 6px 0 14px; font-size: 15px; line-height: 1.4; }
.panel .note { font-size: 14px; font-weight: 700; color: #1f6f3f; margin-top: -6px; }
.result {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin: 4px 0 14px;
}
.result div { display: flex; flex-direction: column; }
.result b { font-size: 34px; line-height: 1; font-variant-numeric: tabular-nums; }
.result span { font-size: 12px; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.08em; }
.buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.panel button {
  border: 0;
  border-radius: 999px;
  padding: 12px 26px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  font-family: inherit;
}
.panel button.secondary { background: #e7e9df; color: var(--ink); }
.panel button:disabled { opacity: 0.5; cursor: default; }
.hint { font-size: 12px; opacity: 0.7; margin-top: 14px; }
@media (pointer: coarse) { .hint { display: none; } }

#board {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 14px;
}
#board li {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 10px;
  align-items: center;
  font-variant-numeric: tabular-nums;
}
#board li:nth-child(odd) { background: rgba(0, 0, 0, 0.04); }
#board li.me { background: var(--lime); font-weight: 800; }
#board li .rank { opacity: 0.6; font-weight: 700; }
#board li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
#board li .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#board li .n { font-weight: 700; }
#board li .t { opacity: 0.7; min-width: 42px; text-align: right; }
#board .empty { display: block; text-align: center; opacity: 0.7; padding: 10px; }
