:root {
  --durian-green: #7cb342;
  --durian-green-dark: #558b2f;
  --custard: #ffd54f;
  --custard-deep: #f5b301;
  --cream: #fff8e1;
  --ink: #2f2a1d;
  --ink-soft: #6b6450;
  --teal: #00897b;
  --sky-1: #ffd9a0;
  --sky-2: #7fd6c7;
  --danger: #e85d4e;
  --shadow: 0 10px 30px rgba(47, 42, 29, 0.18);
  --radius: 22px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Inter", system-ui, sans-serif;
  color: var(--ink);
  background: #1b2a25;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  overscroll-behavior: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px clamp(14px, 4vw, 28px);
  pointer-events: none;
}

.hud-pill {
  background: rgba(255, 248, 225, 0.92);
  backdrop-filter: blur(8px);
  border-radius: 16px;
  padding: 8px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 78px;
}
.hud-pill--combo { align-items: flex-end; }
.hud-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
}
.hud-value {
  font-family: "Baloo 2", cursive;
  font-size: 22px;
  font-weight: 800;
  color: var(--durian-green-dark);
}
.hud-pill--combo .hud-value { color: var(--custard-deep); }

.hud-progress-wrap { flex: 1; padding: 0 4px; }
.hud-progress-track {
  position: relative;
  height: 14px;
  background: rgba(255, 248, 225, 0.55);
  border-radius: 999px;
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.15);
  overflow: visible;
}
.hud-progress-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--durian-green), var(--custard));
  transition: width 0.35s cubic-bezier(.4,1.3,.5,1);
  box-shadow: 0 0 10px rgba(245,179,1,0.6);
}
.hud-progress-flag {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  top: -22px;
  font-size: 11px;
  font-weight: 700;
  color: var(--cream);
  white-space: nowrap;
  font-family: "Baloo 2", cursive;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 30%, rgba(0,137,123,0.35), rgba(27,42,37,0.78));
  backdrop-filter: blur(3px);
  animation: fadeIn 0.4s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  width: min(400px, 92vw);
  max-height: 92dvh;
  overflow-y: auto;
  touch-action: pan-y;
  background: linear-gradient(160deg, var(--cream), #fff);
  border-radius: var(--radius);
  padding: clamp(16px, 4vw, 24px);
  text-align: center;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255,255,255,0.6) inset;
  animation: popIn 0.45s cubic-bezier(.2,1.4,.4,1);
}
@keyframes popIn { from { transform: scale(0.85) translateY(20px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }

.badge {
  display: inline-block;
  background: var(--teal);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 14px;
  box-shadow: 0 4px 12px rgba(0,137,123,0.35);
}

.hero-talam {
  width: 90px;
  height: auto;
  margin: 0 auto 6px;
  display: block;
  filter: drop-shadow(0 12px 16px rgba(245,179,1,0.4));
  animation: bob 3s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-10px) rotate(2deg); } }

.title {
  font-family: "Baloo 2", cursive;
  font-size: clamp(26px, 7vw, 36px);
  font-weight: 800;
  line-height: 1.1;
  color: var(--durian-green-dark);
  margin-bottom: 8px;
}
.title span { color: var(--custard-deep); display: block; font-size: clamp(24px, 6vw, 32px); }

.subtitle {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.4;
  margin-bottom: 12px;
}
.subtitle strong { color: var(--durian-green-dark); }

.how-to {
  text-align: left;
  background: rgba(124,179,66,0.1);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 14px;
  display: grid;
  gap: 6px;
}
.how-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
}
.how-icon { font-size: 16px; }

.btn {
  font-family: "Baloo 2", cursive;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  width: 100%;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: linear-gradient(135deg, var(--durian-green), var(--durian-green-dark));
  color: #fff;
  box-shadow: 0 8px 20px rgba(85,139,47,0.45);
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 10px 26px rgba(85,139,47,0.55); }
.btn-ghost {
  background: transparent;
  color: var(--durian-green-dark);
  box-shadow: inset 0 0 0 2px var(--durian-green);
}
.btn-ghost:hover { background: rgba(124,179,66,0.12); }

.best-line {
  margin-top: 14px;
  font-size: 13px;
  color: var(--ink-soft);
}
.best-line strong { color: var(--custard-deep); }

/* ---------- Game over ---------- */
.hero-mascot {
  width: 110px;
  height: auto;
  margin: 0 auto 4px;
  display: block;
  filter: drop-shadow(0 10px 14px rgba(85,139,47,0.35));
  animation: bob 3s ease-in-out infinite;
}
.over-title {
  font-family: "Baloo 2", cursive;
  font-size: clamp(28px, 7vw, 38px);
  color: var(--durian-green-dark);
  margin-bottom: 6px;
}
.over-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 20px;
  line-height: 1.5;
}
.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.result-box {
  background: rgba(124,179,66,0.1);
  border-radius: 14px;
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.result-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  font-weight: 600;
}
.result-num {
  font-family: "Baloo 2", cursive;
  font-size: 24px;
  font-weight: 800;
  color: var(--durian-green-dark);
}
.contribution {
  background: linear-gradient(135deg, rgba(0,137,123,0.12), rgba(245,179,1,0.12));
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  margin-bottom: 20px;
}
.contribution strong { color: var(--teal); }
.over-actions { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  z-index: 25;
  font-family: "Baloo 2", cursive;
  font-size: clamp(30px, 9vw, 52px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 4px 14px rgba(0,0,0,0.35);
  pointer-events: none;
  opacity: 0;
}
.toast.show {
  animation: toastPop 0.9s ease forwards;
}
@keyframes toastPop {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  25% { transform: translate(-50%, -60%) scale(1.1); opacity: 1; }
  70% { transform: translate(-50%, -70%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -110%) scale(0.9); opacity: 0; }
}

@media (min-width: 640px) {
  #app { box-shadow: 0 0 60px rgba(0,0,0,0.4); }
}

/* ---------- Mute button ---------- */
.mute-btn {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 40;
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 248, 225, 0.92);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.mute-btn:hover { filter: brightness(1.05); }
.mute-btn:active { transform: scale(0.92); }

/* ---------- Mayor greeting card ---------- */
.mayor-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 8px 10px;
  background: linear-gradient(135deg, rgba(0,137,123,0.1), rgba(245,179,1,0.12));
  border-radius: 12px;
  text-align: left;
  border: 1px solid rgba(0,137,123,0.18);
}
.mayor-photo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: #fff;
  box-shadow: 0 3px 10px rgba(47,42,29,0.18);
  border: 2px solid var(--custad-deep, var(--custard-deep));
}
/* Fallback ketika foto belum tersedia */
.mayor-photo--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--teal), var(--durian-green));
  position: relative;
}
.mayor-photo--empty::after {
  content: "🏛️";
  font-size: 20px;
}
.mayor-info { display: flex; flex-direction: column; line-height: 1.2; }
.mayor-greeting {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--teal);
  font-weight: 700;
}
.mayor-name {
  font-family: "Baloo 2", cursive;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.mayor-role { font-size: 10px; color: var(--ink-soft); }

/* ---------- Name input + Leaderboard ---------- */
.name-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.name-input {
  flex: 1;
  font-family: "Inter", sans-serif;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid rgba(0,137,123,0.25);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease;
}
.name-input:focus { border-color: var(--teal); }
.btn-compact { width: auto; padding: 10px 16px; font-size: 15px; }

.leaderboard {
  background: rgba(0,137,123,0.06);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  text-align: left;
}
.lb-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.lb-title {
  font-family: "Baloo 2", cursive;
  font-weight: 700;
  font-size: 14px;
  color: var(--durian-green-dark);
}
.lb-scope {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--teal);
  font-weight: 700;
}
.lb-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 140px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none; /* Firefox */
}
.lb-list::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}
.lb-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: #fff;
  border-radius: 8px;
  font-size: 13px;
}
.lb-rank { width: 22px; text-align: center; font-weight: 700; }
.lb-name {
  flex: 1;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-meters {
  font-family: "Baloo 2", cursive;
  font-weight: 700;
  color: var(--custard-deep);
}
.lb-empty {
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
  padding: 8px;
}

/* ---------- Player identity (start screen) ---------- */
.identity {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.avatar-pick {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  cursor: pointer;
  overflow: hidden;
  background: rgba(0,137,123,0.08);
  box-shadow: inset 0 0 0 2px rgba(0,137,123,0.3);
}
.avatar-pick img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
.avatar-plus {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--teal);
  line-height: 1;
}
.avatar-plus small { font-size: 7px; letter-spacing: 0.05em; margin-top: 1px; }
.identity .name-input { flex: 1; }

/* ---------- Leaderboard avatars ---------- */
.lb-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: rgba(124,179,66,0.18);
}
.lb-avatar--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.lb-item--me {
  outline: 2px solid var(--custard-deep);
  background: #fffdf3;
}
