:root {
  --panel: #fff6e5;
  --ink: #3b2414;
  --pumpkin: #f07b1f;
  --maple: #c8371d;
  --gold: #f5b82e;
  --moss: #6b8e23;
  --plum: #7a3b69;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Nunito", "Varela Round", ui-rounded, system-ui, sans-serif;
  color: var(--ink);
  background: #f3c98b;
}

#world { position: fixed; inset: 0; }
#world canvas { display: block; }

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  font-weight: bold;
  color: #fff;
  background: linear-gradient(160deg, var(--maple), var(--pumpkin), var(--gold));
  z-index: 10;
  transition: opacity .6s;
}
#loading.done { opacity: 0; pointer-events: none; }

.topbar {
  position: fixed;
  top: 10px; left: 12px; right: 12px;
  border-radius: 999px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px 8px 22px;
  background: linear-gradient(90deg, rgba(226, 104, 72, .9), rgba(244, 150, 80, .9), rgba(247, 196, 92, .9));
  color: #fff;
  box-shadow: 0 8px 24px rgba(120, 60, 20, .18);
  backdrop-filter: blur(6px);
  z-index: 5;
}
.topbar h1 { margin: 0; font-size: 1.4rem; font-weight: 800; text-shadow: 0 2px 6px rgba(120, 50, 10, .25); }
.season, .sample {
  font-size: .75rem;
  padding: 3px 10px;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 6px;
}
.season { background: var(--plum); }
.sample { background: #2b1d14; }
.stats { display: flex; gap: 10px; font-weight: bold; align-items: center; }
.stats span { background: rgba(255, 255, 255, .22); padding: 5px 14px; border-radius: 999px; }
.toggle {
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .22);
  color: #fff;
  font-size: 1.1rem;
  padding: 4px 12px;
  cursor: pointer;
}

.sidebar {
  position: fixed;
  top: 76px; right: 14px; bottom: 14px;
  width: 340px;
  display: flex;
  flex-direction: column;
  background: rgba(255, 246, 229, .94);
  border-radius: 26px;
  overflow: hidden;
  z-index: 5;
  box-shadow: 0 12px 36px rgba(120, 60, 20, .22);
  backdrop-filter: blur(8px);
  transition: transform .3s;
}
.sidebar.closed { transform: translateX(380px); }
.tabs { display: flex; gap: 4px; margin: 10px 10px 0; padding: 4px; background: #f6e1bf; border-radius: 999px; flex-shrink: 0; }
.tab {
  flex: 1;
  border: 0;
  background: none;
  padding: 7px 2px;
  border-radius: 999px;
  font: inherit;
  font-size: .78rem;
  cursor: pointer;
  color: var(--ink);
  transition: background .2s;
}
.tab.active { background: #fff; font-weight: bold; box-shadow: 0 2px 8px rgba(120, 60, 20, .15); }
.panel { display: none; padding: 12px; overflow-y: auto; flex: 1; }
.panel.active { display: block; }

.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 16px;
  cursor: pointer;
  transition: background .2s, transform .2s;
}
.leaderboard li:nth-child(odd) { background: #fbe8c8; }
.leaderboard li.elder { background: linear-gradient(90deg, #f3e1ff, #ffe9c7); }
.leaderboard li:hover { background: #ffe0b0; transform: translateX(-2px); }
.rank { width: 26px; font-weight: bold; text-align: center; }
.who { flex: 1; }
.who small { display: block; color: #8a5a36; }
.coins { font-weight: bold; color: #b06a00; white-space: nowrap; }

.card {
  background: #fff;
  border-radius: 20px;
  padding: 12px 14px;
  box-shadow: 0 4px 16px rgba(245, 184, 46, .35);
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 6px; }
.card .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: .9rem; }
.card p { margin: 6px 0 0; }
.hidden { display: none !important; }

.building {
  background: #fbe8c8;
  border-radius: 16px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background .2s;
}
.building:hover { background: #ffe0b0; }
.building b { font-size: 1rem; }
.building small { color: #8a5a36; display: block; }
.bar { height: 8px; background: #e2c49c; border-radius: 99px; margin-top: 5px; overflow: hidden; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--moss), var(--gold)); }

.shop h4 { margin: 14px 0 6px; color: var(--plum); }
.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 16px;
  background: #fbe8c8;
  margin-bottom: 6px;
}
.item .icon { font-size: 1.4rem; }
.item .name { flex: 1; }

.feed { list-style: none; margin: 0; padding: 0; font-size: .9rem; }
.feed li { padding: 7px 4px; border-bottom: 1px dashed #d9b98f; }
.feed time { color: #8a5a36; font-size: .8rem; display: block; }

.rules { padding-left: 18px; line-height: 1.5; }
.rules em { color: #b06a00; font-style: normal; font-weight: bold; }
.note { background: #fbe8c8; padding: 10px 12px; border-radius: 16px; }

/* labels floating over the 3D world */
.label {
  font: bold 12px "Nunito", ui-rounded, sans-serif;
  color: #fff;
  background: rgba(59, 36, 20, .78);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
.label.building-label { background: rgba(140, 78, 124, .85); font-size: 13px; border-radius: 14px; padding: 4px 12px; }
.label.building-label small { display: block; font-weight: normal; font-size: 11px; color: #ffe3a3; }
.label.person-label { background: rgba(240, 123, 31, .88); font-size: 11px; padding: 2px 8px; margin-top: 22px; }
.label.person-label.selected { background: var(--maple); font-size: 13px; outline: 2px solid #fff; }

@media (max-width: 800px) {
  .topbar { border-radius: 22px; }
  .sidebar { top: auto; left: 8px; right: 8px; width: auto; height: 45%; }
  .sidebar.closed { transform: translateY(110%); }
}

/* what each villager is doing, and coin pops for new actions */
.bubble {
  font-size: 15px;
  background: #fff;
  border-radius: 999px;
  padding: 1px 5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
  pointer-events: none;
}
.coin-pop {
  display: inline-block;
  font: bold 15px "Nunito", ui-rounded, sans-serif;
  color: #fff;
  background: var(--gold);
  box-shadow: 0 3px 10px rgba(176, 106, 0, .4);
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
  animation: coin-rise 2.2s ease-out forwards;
}
@keyframes coin-rise {
  from { transform: translateY(0) scale(.6); opacity: 0; }
  15% { transform: translateY(-6px) scale(1.15); opacity: 1; }
  to { transform: translateY(-60px) scale(1); opacity: 0; }
}

.speech {
  font: bold 12px "Nunito", ui-rounded, sans-serif;
  color: var(--ink);
  background: #fff;
  border-radius: 16px;
  padding: 4px 10px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .18);
  white-space: nowrap;
  pointer-events: none;
}
.panel h4 { margin: 14px 0 4px; color: var(--plum); }
code { background: #f3d9b1; padding: 1px 6px; border-radius: 8px; }
