:root {
  --page: #fbe3c0;
  --ink: #3a2618;
  --bar: #6b3f1f;
  --bar-ink: #fff4e6;
  --btn: #e2822a;
  --btn-hover: #c96c17;
  --card: #fff8ee;
  --line: #e4c9a2;
  font-family: Fredoka, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--page);
  overflow: hidden;
}

/* The game fills the window: a slim bar on top, the room, the chat bar below. */
#app {
  position: relative;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.top {
  background: var(--bar);
  color: var(--bar-ink);
  padding: 6px 12px;
}

.logo { font-size: 1.15rem; letter-spacing: .02em; }
#where { opacity: .85; font-size: .95rem; flex: 1; min-width: 0; }
.tools { display: flex; gap: 6px; align-items: center; }

/* Live now: who is online in every room */
.top .live-btn { display: inline-flex; align-items: center; gap: 7px; background: rgba(255, 255, 255, .2); }
.live-btn .dot { width: 9px; height: 9px; border-radius: 50%; background: #5ee07a; box-shadow: 0 0 0 0 rgba(94, 224, 122, .7); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(94, 224, 122, 0); } 100% { box-shadow: 0 0 0 0 rgba(94, 224, 122, 0); } }
.live-panel {
  position: absolute;
  top: 44px;
  right: 12px;
  z-index: 5;
  width: min(340px, calc(100vw - 24px));
  max-height: min(70dvh, 560px);
  overflow: auto;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 14px 40px rgba(58, 38, 24, .3);
  padding: 10px 12px 12px;
}
.live-panel[hidden] { display: none; }
.live-panel h2 { margin: 0 0 6px; font-size: 1.05rem; }
.live-panel h3 { margin: 10px 0 4px; font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; opacity: .65; }
.live-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.live-row canvas { width: 48px; height: 40px; flex: none; }
.live-row .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.live-row .you { font-weight: 400; opacity: .6; }
.live-row button { padding: 4px 11px; font-size: .82rem; flex: none; }
.live-empty { margin: 4px 0 0; opacity: .7; font-size: .9rem; }

button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  background: var(--btn);
  color: #fff;
  cursor: pointer;
}
button:hover { background: var(--btn-hover); }
button { transition: transform .12s ease, background .15s ease; }
button:active:not(:disabled) { transform: scale(.93); }
button:focus-visible, input:focus-visible { outline: 3px solid #2f7de1; outline-offset: 2px; }
button:disabled { opacity: .5; cursor: default; }
.top button { background: rgba(255, 255, 255, .16); padding: 5px 12px; font-size: .9rem; white-space: nowrap; }
.treats { white-space: nowrap; }
.top button:hover { background: rgba(255, 255, 255, .28); }

.stage { position: relative; line-height: 0; flex: 1; min-height: 0; overflow: hidden; }

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #8fd3ff;
  cursor: pointer;
  touch-action: manipulation;
}
#game.door { cursor: alias; }

#log {
  position: absolute;
  left: 10px;
  top: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: min(46%, 340px);
  line-height: 1.3;
  font-size: 13px;
  pointer-events: none;
}
#log li {
  background: rgba(255, 248, 238, .82);
  border-radius: 8px;
  padding: 3px 8px;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
  animation: fade 30s forwards;
}
#log b { color: var(--bar); }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

#notice {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(58, 38, 24, .6);
  color: #fff;
  line-height: 1.4;
  font-size: 1.1rem;
  text-align: center;
  padding: 16px;
}
#notice[hidden] { display: none; }
#notice p { margin: 0; }

.bottom {
  background: var(--card);
  border-top: 2px solid var(--line);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}
#text {
  flex: 1 1 180px;
  min-width: 0;
  font: inherit;
  padding: 7px 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
}
.emotes { display: flex; flex-wrap: wrap; gap: 6px; }
.emotes button { background: #fff; color: var(--ink); border: 2px solid var(--line); padding: 5px 11px; }
.emotes button:hover { background: #ffeed6; }

dialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(58, 38, 24, .35);
}
dialog::backdrop { background: rgba(58, 38, 24, .45); }
#join-form { padding: 20px 22px 18px; display: flex; flex-direction: column; gap: 12px; }
#join h1 { margin: 0; text-align: center; font-size: 1.7rem; }
#preview { width: 240px; height: 170px; align-self: center; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.field input {
  font: inherit;
  font-weight: 400;
  padding: 9px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
fieldset { border: 0; margin: 0; padding: 0; }
legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-size: .92rem;
}
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label:has(input:checked) { border-color: var(--btn); background: #ffeed6; }
.chips label:has(input:focus-visible) { outline: 3px solid #2f7de1; outline-offset: 2px; }
.swatch { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); }
#join-error { margin: 0; color: #b42318; min-height: 1.2em; }
#join-error:empty { display: none; }
#go { padding: 11px; font-size: 1.05rem; }
.fine { margin: 0; font-size: .82rem; opacity: .7; text-align: center; }

@media (max-width: 600px) {
  .top button, .treats { padding: 4px 9px; font-size: .8rem; }
  #banner { font-size: .8rem; white-space: normal; text-align: center; width: max-content; max-width: 92%; }
  .tools { gap: 4px; flex-wrap: wrap; }
  .logo { font-size: 1rem; }
  #where { flex-basis: 100%; order: 3; font-size: .85rem; }
  #log { font-size: 11px; max-width: 60%; }
  .emotes button { padding: 4px 9px; font-size: .85rem; }
}

/* ---------- batch 2: treats, hint, throw, shop, sheep field ---------- */

.treats {
  align-self: center;
  background: #ffcc33;
  color: var(--ink);
  font-weight: 700;
  font-size: .85rem;
  border-radius: 999px;
  padding: 4px 10px;
}
.zoom { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; line-height: 1; }
.zoom button {
  width: 38px; height: 38px; padding: 0;
  font-size: 1.35rem; font-weight: 700;
  background: rgba(255, 248, 238, .92); color: var(--ink);
  border: 2px solid var(--line);
  box-shadow: 0 2px 8px rgba(58, 38, 24, .2);
}
.zoom button:hover { background: #fff; }
.zoom button:disabled { opacity: .4; }
.meters { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 8px; line-height: 1; pointer-events: none; }
.meters span { display: flex; align-items: center; gap: 4px; background: rgba(255, 248, 238, .9); border-radius: 999px; padding: 4px 8px; font-size: .85rem; }
.meters i { display: block; width: 54px; height: 7px; background: #f3e4cf; border-radius: 999px; overflow: hidden; }
.meters b { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #9bdcff, #ffd23f); border-radius: 999px; transition: width .5s; }
.meters.full span { animation: wobble2 .35s ease-in-out infinite alternate; }
@keyframes wobble2 { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
.potty { background: #ffd23f; color: var(--ink); }
.potty:hover { background: #ffc400; }
.dance-pads { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 10px; }
.dance-pads button { width: 64px; height: 64px; font-size: 1.8rem; font-weight: 900; background: rgba(20, 12, 40, .7); color: var(--c); border: 3px solid var(--c); border-radius: 16px; }
.dance-pads button:active { background: var(--c); color: #1b1430; }
@media (hover: hover) and (pointer: fine) { .dance-pads button { width: 52px; height: 52px; font-size: 1.4rem; opacity: .8; } }
#casino { width: min(520px, calc(100vw - 32px)); padding: 18px 20px; }
.reels { display: flex; justify-content: center; gap: 10px; margin: 12px 0; }
.reel { width: 76px; height: 76px; display: grid; place-items: center; font-size: 2.6rem; background: #fff; border: 3px solid var(--line); border-radius: 14px; }
.casino-msg { font-weight: 700; text-align: center; margin: 6px 0; }
.bet-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 6px 0; }
.pays { display: flex; flex-wrap: wrap; gap: 6px 12px; justify-content: center; font-size: .82rem; opacity: .8; }
.chip { background: var(--chip); color: var(--ink); text-transform: capitalize; }
.chip.picked, button.picked { outline: 3px solid var(--ink); outline-offset: 1px; }
#banner {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  margin: 0; padding: 8px 18px; border-radius: 999px;
  background: rgba(255, 248, 238, .95); border: 2px solid #c9a7ff; color: var(--ink);
  font-weight: 700; line-height: 1.3; white-space: nowrap; box-shadow: 0 6px 18px rgba(58, 38, 24, .18);
}
#banner[hidden] { display: none; }
#banner.hot { background: #ffe08a; border-color: #e2822a; animation: wobble .4s ease-in-out infinite alternate; }
@keyframes wobble { from { transform: translateX(-50%) rotate(-2deg) scale(1.03); } to { transform: translateX(-50%) rotate(2deg) scale(1.03); } }
.top .quest-btn { background: rgba(255, 255, 255, .2); }
.top .quest-btn.all-done { background: #5ee07a; color: var(--ink); }
#music[aria-pressed="false"], #sound[aria-pressed="false"] { opacity: .5; }
.quest { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 7px 0; border-bottom: 1px dashed var(--line); line-height: 1.3; }
.quest small { font-weight: 700; opacity: .75; }
.quest .bar { grid-column: 1 / -1; height: 8px; background: #f3e4cf; border-radius: 999px; overflow: hidden; }
.quest .bar span { display: block; height: 100%; background: linear-gradient(90deg, #ffb3d1, #e2822a); border-radius: 999px; transition: width .4s ease; }
.quest.done span:first-child { opacity: .7; }
#log li.news { background: rgba(255, 236, 170, .9); font-style: italic; }
#hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  margin: 0;
  background: rgba(58, 38, 24, .82);
  color: #fff;
  line-height: 1.3;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: .9rem;
  pointer-events: none;
  white-space: nowrap;
}
.throw { background: #2f9b4f; }
.throw:hover { background: #24803f; }
.throw.armed { background: #2f7de1; }
button.ghost { background: #fff; color: var(--ink); border: 2px solid var(--line); }
button.ghost:hover { background: #ffeed6; }

#shop { width: min(640px, calc(100vw - 32px)); padding: 18px 20px; }
.shop-head { display: flex; align-items: center; gap: 12px; }
.shop-head h2 { margin: 0; flex: 1; }
.shop-wallet { background: #ffcc33; border-radius: 999px; padding: 4px 12px; font-weight: 700; }
.shop-close { background: #fff; color: var(--ink); border: 2px solid var(--line); }
.shop-featured { margin: 10px 0 4px; font-weight: 600; color: #b5541a; }
.shop-error { margin: 0; color: #b42318; }
.shop-error:empty { display: none; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 10px 0; }
.shop-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 8px 8px 10px;
  text-align: center;
}
.shop-item.deal { border-color: #e2822a; box-shadow: 0 0 0 3px #ffe2b8; }
.shop-item b { font-size: .92rem; }
.shop-item .price { font-size: .85rem; opacity: .8; }
.shop-item s { opacity: .6; }
.shop-item button { padding: 5px 12px; font-size: .88rem; }

#herd { position: absolute; inset: 0; line-height: 1.35; }
#herd canvas { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.herd-hud {
  position: absolute;
  top: 8px; left: 8px; right: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.herd-hud > * { pointer-events: auto; }
.herd-time, .herd-count {
  background: rgba(255, 248, 238, .9);
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.herd-quit { margin-left: auto; background: #fff; color: var(--ink); border: 2px solid var(--line); }
.herd-card {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
  background: var(--card);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: 0 12px 40px rgba(58, 38, 24, .35);
}
.herd-card[hidden] { display: none; }
.herd-card h3 { margin: 0 0 6px; }
.herd-card h4 { margin: 10px 0 4px; }
.herd-card p { margin: 0 0 6px; font-size: .92rem; }
.herd-board { margin: 0 0 8px; padding-left: 22px; font-size: .92rem; }
.herd-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

@media (max-width: 600px) {
  .emotes { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; }
  .emotes button { flex: none; }
  #hint { font-size: .78rem; white-space: normal; width: max-content; max-width: 90%; text-align: center; border-radius: 12px; }
  .herd-card p { font-size: .82rem; }
}
