:root {
  --sky-1: #7fd3ff;
  --sky-2: #c9f0ff;
  --grass-1: #7ed957;
  --grass-2: #4caf50;
  --grass-3: #2e8b3e;
  --ink: #18352a;
  --ink-soft: #49675a;
  --card: rgba(255, 255, 255, 0.86);
  --card-border: rgba(255, 255, 255, 0.9);
  --accent: #ff8a00;
  --good: #22b35e;
  --bad: #e5484d;
  --shadow: 0 10px 30px rgba(20, 60, 40, 0.18);
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Fredoka', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(var(--sky-1), var(--sky-2) 55%, var(--grass-1) 55%);
  overflow: hidden;
}
button { font: inherit; cursor: pointer; }

/* ---------- Pemandangan ---------- */
.scene { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.sun {
  position: absolute; top: 4vh; right: 8vw; width: 110px; height: 110px; border-radius: 50%;
  background: radial-gradient(circle, #fff7b0, #ffd43b 60%, #ffb703);
  box-shadow: 0 0 60px 20px rgba(255, 214, 59, 0.55);
  animation: sunPulse 4s ease-in-out infinite;
}
.sun .rays {
  position: absolute; inset: -40px; border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 230, 120, 0.45) 0 10deg, transparent 10deg 30deg);
  mask: radial-gradient(circle, transparent 52%, #000 53%, transparent 72%);
  -webkit-mask: radial-gradient(circle, transparent 52%, #000 53%, transparent 72%);
  animation: spin 30s linear infinite;
}
@keyframes sunPulse { 50% { transform: scale(1.06); } }
@keyframes spin { to { transform: rotate(360deg); } }

.cloud {
  position: absolute; width: 180px; height: 56px; border-radius: 60px; background: #fff; opacity: 0.92;
  filter: drop-shadow(0 6px 8px rgba(0, 80, 140, 0.12));
  animation: drift linear infinite;
}
.cloud::before, .cloud::after { content: ''; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 80px; height: 80px; top: -40px; left: 28px; }
.cloud::after { width: 100px; height: 100px; top: -54px; left: 72px; }
.c1 { top: 10vh; animation-duration: 70s; animation-delay: -10s; }
.c2 { top: 22vh; transform: scale(0.7); animation-duration: 95s; animation-delay: -50s; }
.c3 { top: 6vh; transform: scale(0.5); animation-duration: 120s; animation-delay: -80s; }
.c4 { top: 30vh; transform: scale(0.85); animation-duration: 85s; animation-delay: -30s; }
@keyframes drift { from { left: -260px; } to { left: 110vw; } }

.hill { position: absolute; border-radius: 50%; }
.h1 { width: 90vw; height: 50vh; left: -20vw; bottom: 22vh; background: radial-gradient(ellipse at 50% 30%, #9be36d, var(--grass-2)); }
.h2 { width: 80vw; height: 44vh; right: -25vw; bottom: 20vh; background: radial-gradient(ellipse at 50% 30%, #8ad65f, #3f9d48); }
.h3 { width: 160vw; height: 60vh; left: -30vw; bottom: -30vh; background: radial-gradient(ellipse at 50% 20%, var(--grass-1), var(--grass-3)); }

.flora { position: absolute; inset: auto 0 2vh 0; display: flex; justify-content: space-around; font-size: 30px; }
.flora span { animation: sway 3s ease-in-out infinite; transform-origin: bottom center; }
.flora span:nth-child(odd) { animation-delay: -1.5s; }
@keyframes sway { 50% { transform: rotate(8deg); } }

.butterfly { position: absolute; font-size: 26px; animation: flutter 18s ease-in-out infinite; }
.b1 { top: 40vh; left: 10vw; }
.b2 { top: 55vh; left: 70vw; animation-delay: -9s; animation-duration: 22s; }
@keyframes flutter {
  0%, 100% { transform: translate(0, 0) rotate(-10deg); }
  25% { transform: translate(20vw, -10vh) rotate(10deg); }
  50% { transform: translate(35vw, 5vh) rotate(-5deg); }
  75% { transform: translate(10vw, 12vh) rotate(12deg); }
}

/* ---------- Layout ---------- */
.app { position: relative; z-index: 1; height: 100%; display: flex; flex-direction: column; padding: 14px 18px 18px; gap: 14px; }
.topbar { display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 46px; animation: logoHop 1.6s ease-in-out infinite; display: inline-block; }
@keyframes logoHop {
  0%, 60%, 100% { transform: translateY(0) scale(1, 1); }
  10% { transform: translateY(0) scale(1.15, 0.85); }
  30% { transform: translateY(-14px) scale(0.92, 1.1); }
  50% { transform: translateY(0) scale(1.1, 0.9); }
}
.brand h1 {
  margin: 0; font-size: clamp(26px, 3vw, 40px); line-height: 1; letter-spacing: 0.5px; color: #fff;
  text-shadow: 0 3px 0 #2e8b3e, 0 6px 14px rgba(0, 0, 0, 0.2);
}
.brand h1 span { color: #ffe066; }
.brand p { margin: 4px 0 0; font-size: 14px; color: #0f3d2a; font-weight: 500; }
.status {
  flex: 1; text-align: center; font-size: clamp(15px, 1.6vw, 22px); font-weight: 600;
  background: var(--card); border-radius: 999px; padding: 10px 18px; box-shadow: var(--shadow);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 52px;
}
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0; background: var(--card); font-size: 20px; box-shadow: var(--shadow);
}

.main { flex: 1; min-height: 0; display: flex; gap: 16px; }
.board-wrap {
  flex: 1; min-width: 0; position: relative; border-radius: 28px; padding: 10px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.25), transparent 40%),
    linear-gradient(160deg, rgba(126, 217, 87, 0.85), rgba(46, 139, 62, 0.85));
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.5), var(--shadow);
}
.board { position: relative; width: 100%; height: 100%; }
.path { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

/* ---------- Petak ---------- */
.tile {
  position: absolute; display: grid; place-items: center; border-radius: 26%;
  font-weight: 700; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.18), inset 0 4px 0 rgba(255, 255, 255, 0.35), 0 6px 12px rgba(0, 0, 0, 0.18);
  transition: transform 0.2s;
  animation: tileIn 0.5s backwards cubic-bezier(.3, 1.6, .5, 1);
}
.tile .n { line-height: 1; }
.tile small { position: absolute; bottom: 8%; font-size: 0.32em; letter-spacing: 1px; opacity: 0.9; }
.tile.start { background: linear-gradient(#4dabf7, #1c7ed6); }
.tile.finish {
  background: repeating-conic-gradient(#222 0 25%, #fff 0 50%) 0 0 / 30% 30%;
  color: #ffe066; text-shadow: 0 2px 0 #000, 0 0 12px #000;
  animation: tileIn 0.5s backwards, finishGlow 1.6s ease-in-out infinite;
}
@keyframes finishGlow {
  50% { box-shadow: 0 0 0 6px rgba(255, 224, 102, 0.9), 0 0 36px 10px rgba(255, 200, 0, 0.7); }
}
.tile.pulse { animation: tilePulse 0.45s; }
@keyframes tilePulse { 40% { transform: scale(1.18); filter: brightness(1.25); } }
@keyframes tileIn { from { transform: scale(0) rotate(-30deg); opacity: 0; } }

/* ---------- Token karakter ---------- */
.token { position: absolute; left: 0; top: 0; will-change: transform; z-index: 3; }
.token .shadow {
  position: absolute; left: 50%; bottom: -6%; width: 70%; height: 18%; translate: -50% 0;
  border-radius: 50%; background: rgba(0, 0, 0, 0.28); filter: blur(2px);
}
.token .body { position: relative; display: grid; place-items: center; transform-origin: 50% 100%; }
.token .ring {
  position: absolute; inset: 6%; border-radius: 50%; background: var(--c); opacity: 0.35;
  box-shadow: 0 0 0 3px #fff;
}
.token .sprite { position: relative; line-height: 1; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.3)); transition: transform 0.15s; }
.token .tag {
  position: absolute; bottom: 100%; left: 50%; translate: -50% 0; margin-bottom: 2px;
  font-size: 12px; font-weight: 600; white-space: nowrap; color: #fff; background: var(--c);
  padding: 1px 8px; border-radius: 999px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.token.active { z-index: 5; }
.token.active .ring { opacity: 0.8; animation: ringPulse 1s ease-in-out infinite; }
.token.idle .body { animation: idleBob 2.2s ease-in-out infinite; }
.token.offline { opacity: 0.45; filter: grayscale(0.8); }
@keyframes ringPulse { 50% { transform: scale(1.25); opacity: 0.4; } }
@keyframes idleBob { 50% { transform: translateY(-6%) scale(1.03, 0.97); } }

/* ---------- Efek ---------- */
#fx { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.puff { position: absolute; width: 14px; height: 14px; border-radius: 50%; background: rgba(255, 255, 255, 0.9); }
.step-num {
  position: absolute; font-weight: 700; font-size: 28px; color: #fff; translate: -50% -50%;
  text-shadow: 0 3px 0 var(--c, #2e8b3e), 0 0 8px rgba(0, 0, 0, 0.3);
}
.status { display: flex; align-items: center; justify-content: center; gap: 10px; }
.status .timer {
  --p: 1; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; flex: none;
  background: conic-gradient(var(--accent) calc(var(--p) * 360deg), #ffe8cc 0);
}
.status .timer b { width: 30px; height: 30px; border-radius: 50%; background: #fff; display: grid; place-items: center; }
.status .phone { display: inline-block; font-size: 26px; animation: shakePhone 0.35s ease-in-out infinite; }
@keyframes shakePhone { 25% { transform: rotate(-18deg); } 75% { transform: rotate(18deg); } }
@keyframes dropIn { from { transform: translateY(-30px) scale(0.8); opacity: 0; } }

.toast {
  position: fixed; left: 50%; top: 50%; translate: -50% -50%; z-index: 40; padding: 22px 38px; border-radius: 26px;
  font-size: clamp(22px, 3vw, 42px); font-weight: 700; color: #fff; text-align: center; box-shadow: var(--shadow);
  animation: toastIn 0.5s cubic-bezier(.3, 1.6, .5, 1);
}
.toast.good { background: linear-gradient(#34d27a, #1f9d55); }
.toast.bad { background: linear-gradient(#ff6b6b, #d6336c); }
.toast.warn { background: linear-gradient(#ffb347, #f76707); }
.toast small { display: block; font-size: 0.5em; font-weight: 500; margin-top: 6px; opacity: 0.95; }
@keyframes toastIn { from { transform: scale(0.3) rotate(-8deg); opacity: 0; } }

/* ---------- Panel ---------- */
.panel { width: 310px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.card { background: var(--card); border: 2px solid var(--card-border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; backdrop-filter: blur(6px); }
.join-card { display: flex; gap: 12px; align-items: center; }
.join-card img { width: 92px; height: 92px; border-radius: 12px; background: #fff; flex: none; }
.join-card b { display: block; font-size: 18px; }
.join-card small { color: var(--ink-soft); word-break: break-all; font-size: 12px; }
.players-card h2, .board-card h2 { margin: 0 0 8px; font-size: 18px; display: flex; justify-content: space-between; }
.players-card h2 span { color: var(--ink-soft); font-weight: 500; }
.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 4px 10px; align-items: center; padding: 8px 10px; border-radius: 14px;
  background: #fff; border: 2px solid transparent; transition: border-color 0.2s, transform 0.2s;
}
.player-list li.new { animation: slideIn 0.4s cubic-bezier(.3, 1.4, .5, 1); }
.player-list li.busy { border-color: var(--c); transform: scale(1.03); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 25%, transparent); }
.player-list li.off { opacity: 0.5; }
.player-list .av { grid-row: span 2; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; background: color-mix(in srgb, var(--c) 25%, #fff); }
.player-list .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list .ps { font-weight: 700; color: var(--c); }
.player-list .bar { grid-column: 2 / 4; height: 8px; border-radius: 99px; background: #e9f5ec; overflow: hidden; }
.player-list .bar i { display: block; height: 100%; background: var(--c); border-radius: inherit; transition: width 0.5s; }
.player-list .st { grid-column: 2 / 4; font-size: 12px; color: var(--ink-soft); }
.player-list li.empty, .leaderboard li.empty { display: block; background: none; }
.leaderboard li.empty::before { content: none; }
.empty { color: var(--ink-soft); font-size: 14px; text-align: center; padding: 12px 0; }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } }

.btn { border: 0; border-radius: 14px; padding: 10px 12px; font-weight: 600; background: #eef6f0; color: var(--ink); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.1); transition: transform 0.1s; }
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(#ffb347, #ff8a00); color: #fff; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18); }
.btn.danger { color: var(--bad); }
.btn.big { font-size: 22px; padding: 14px 28px; }

.board-wrap { position: relative; }

/* ---------- Gelembung status di atas karakter ---------- */
.bubble {
  position: absolute; translate: -50% -100%; padding: 3px 10px; border-radius: 999px; font-size: 14px; font-weight: 700; white-space: nowrap;
  background: #fff; color: var(--ink); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); z-index: 7;
}
.bubble.good { background: var(--good); color: #fff; }
.bubble.bad { background: var(--bad); color: #fff; }
.token .mood {
  position: absolute; right: -14%; top: -10%; font-size: 0.42em; line-height: 1; background: #fff; border-radius: 50%;
  padding: 3px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.token .mood:empty { display: none; }
.token.done .ring { opacity: 0.9; }
.token.out { filter: grayscale(1); opacity: 0.6; }

/* ---------- Dadu mini per pemain ---------- */
.throw { position: absolute; left: 0; top: 0; z-index: 8; }
.throw .badge {
  position: absolute; left: 50%; top: 100%; translate: -50% 4px; font-weight: 700; color: #fff; font-size: 22px;
  background: var(--accent); border-radius: 999px; padding: 0 10px; opacity: 0;
}

/* ---------- Stopwatch & leaderboard ---------- */
.player-list .tm { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.player-list li.done { background: #fffbe6; }
.board-card { flex: 1; min-height: 0; overflow: auto; }
.leaderboard { margin: 0; padding: 0; list-style: none; counter-reset: lb; display: flex; flex-direction: column; gap: 6px; }
.leaderboard li {
  counter-increment: lb; display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 2px 8px;
  padding: 6px 8px; border-radius: 12px; background: #fff;
}
.leaderboard li::before { content: counter(lb); grid-row: span 2; font-weight: 700; text-align: center; color: var(--ink-soft); }
.leaderboard li:nth-child(1)::before { content: '🥇'; font-size: 20px; }
.leaderboard li:nth-child(2)::before { content: '🥈'; font-size: 20px; }
.leaderboard li:nth-child(3)::before { content: '🥉'; font-size: 20px; }
.leaderboard li.fresh { animation: lbFresh 1.6s ease-out; }
.leaderboard .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .t { font-weight: 700; color: var(--good); font-variant-numeric: tabular-nums; }
.leaderboard small { grid-column: 2 / 4; color: var(--ink-soft); font-size: 12px; }
@keyframes lbFresh { 0% { background: #ffe066; transform: scale(1.05); } }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100%; padding: 10px 12px 16px; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .status { order: 3; flex-basis: 100%; white-space: normal; font-size: 15px; }
  .top-actions { margin-left: auto; }
  .logo { font-size: 36px; }
  .brand p { font-size: 12px; }
  .main { flex-direction: column; }
  .board-wrap { flex: none; height: min(135vw, 78vh); padding: 6px; border-radius: 20px; }
  .panel { width: 100%; }
  .sun { width: 70px; height: 70px; }
  .flora { font-size: 22px; }
  .token .tag { font-size: 10px; padding: 0 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .cloud, .butterfly, .sun .rays, .flora span { animation: none; }
}
