:root {
  --grass-deep: #3d8b4f;
  --grass: #5cb86a;
  --cream: #fff8e8;
  --ink: #234028;
  --ink-soft: #3f5d45;
  --gold: #f0b429;
  --gold-deep: #d4920f;
  --panel: rgba(255, 250, 235, 0.96);
  --shadow: 0 12px 28px rgba(35, 64, 40, 0.22);
  --radius: 18px;
  --font-display: "Fredoka", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at 78% 8%, rgba(255, 255, 210, 0.7) 0 6%, transparent 26%),
    linear-gradient(180deg, #7ec8e8 0%, #b8e4f5 40%, #e8f7d8 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button { font: inherit; cursor: pointer; border: none; }

.app {
  width: min(1000px, calc(100% - 1.2rem));
  margin: 0 auto;
  padding: 0.9rem 0 2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.brand-mark {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 700;
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
  line-height: 1;
}

.brand-tag {
  margin: 0.2rem 0 0;
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 0.85rem;
}

.stats { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.stat {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  font-weight: 800;
  box-shadow: 0 4px 0 var(--gold-deep), var(--shadow);
}

.stat.money {
  background: linear-gradient(180deg, #ffe9a8, #f6c84c);
  color: #5a3d08;
  min-width: 4.5rem;
  justify-content: center;
}

.stat.online {
  background: linear-gradient(180deg, #cdeecf, #9fd8a6);
  color: #1e4526;
  box-shadow: 0 4px 0 #4f8a58, var(--shadow);
}

.ghost-btn {
  background: rgba(255, 248, 232, 0.85);
  color: var(--ink-soft);
  border: 2px solid rgba(61, 139, 79, 0.28);
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  font-weight: 800;
}
.ghost-btn:hover { background: var(--cream); }
.ghost-btn:active { transform: translateY(1px); }

/* 聊天 */
.chat {
  margin-top: 0.7rem;
  background: var(--panel);
  border: 3px solid rgba(143, 98, 48, 0.28);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.chat-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.85rem;
  background: rgba(255, 255, 255, 0.5);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
}
.chat-head:hover { background: rgba(255, 255, 255, 0.8); }
.chat-toggle-icon { font-size: 0.8rem; color: var(--ink-soft); }

.chat-log {
  height: 150px;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.chat-line {
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--ink);
  word-break: break-word;
}
.chat-name { color: var(--ink-soft); font-weight: 800; }
.chat-line.mine .chat-name { color: #2f7a3b; }
.chat-line.mine { background: rgba(146, 214, 155, 0.22); border-radius: 8px; padding: 0 0.3rem; }

.chat-form {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem 0.7rem;
}
.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  border-radius: 999px;
  border: 2px solid rgba(61, 139, 79, 0.3);
  background: #fff;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
}
.chat-form input:focus { outline: none; border-color: var(--grass); }
.chat-send {
  flex: 0 0 auto;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #62c46f, #3f9a4d);
  box-shadow: 0 3px 0 #2f7a3b;
}
.chat-send:active { transform: translateY(2px); box-shadow: 0 1px 0 #2f7a3b; }

/* 种子商店的稀有度筛选 */
.rarity-tabs {
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  padding-bottom: 0.35rem;
  margin-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
}
.rarity-tabs::-webkit-scrollbar { height: 4px; }
.rarity-tabs::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.18); border-radius: 4px; }
.rarity-tab {
  flex: 0 0 auto;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  border: 2px solid transparent;
  font-weight: 800;
  font-size: 0.76rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
.rarity-tab.active {
  border-color: var(--grass);
  background: #e8fbe4;
  color: var(--ink);
}
.rarity-tab.r-rare { color: #2f6ea8; }
.rarity-tab.r-epic { color: #7b4bd8; }
.rarity-tab.r-legendary { color: #b8730f; }
.rarity-tab.r-giant { color: #c43c1b; }
.rarity-tab.r-mythic { color: #c02b6a; }
.rarity-tab.r-divine { color: #9a7b00; }

/* 交易按钮 + 未读角标 */
.ghost-btn.trade { position: relative; }
.ghost-btn.trade.has-offers {
  background: linear-gradient(180deg, #ffd6ea, #ff9ec9);
  border-color: rgba(150, 30, 90, 0.35);
  color: #6d1440;
  animation: nudge 1.4s ease-in-out infinite;
}
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.3rem;
  margin-left: 0.3rem;
  border-radius: 999px;
  background: #e0245e;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 900;
}
.badge.inline { background: #3f9a4d; }
@keyframes nudge {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

/* 交易面板 */
.trade-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin: 0.5rem 0 0.7rem;
}
.trade-tabs.small { margin: 0.35rem 0 0.5rem; }
.trade-h3 {
  margin: 0.9rem 0 0.4rem;
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--ink);
}
.trade-card {
  padding: 0.65rem 0.7rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.75);
  border: 2px solid rgba(61, 139, 79, 0.25);
}
.trade-who { margin: 0 0 0.35rem; font-weight: 800; font-size: 0.9rem; color: var(--ink-soft); }
.trade-line { margin: 0.15rem 0; font-size: 0.88rem; font-weight: 700; line-height: 1.4; }
.trade-line.get b { color: #2f7a3b; }
.trade-line.pay b { color: #a8452a; }
.trade-actions { display: flex; gap: 0.4rem; margin-top: 0.55rem; }
.mini-btn {
  flex: 1;
  padding: 0.45rem 0.5rem;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.82rem;
  color: #fff;
}
.mini-btn.ok { background: linear-gradient(180deg, #62c46f, #3f9a4d); }
.mini-btn.danger { background: linear-gradient(180deg, #f08a8a, #d45b5b); }
.mini-btn:active { transform: translateY(1px); }

.qty-row { grid-template-columns: auto 1fr auto; }
.qty-row.picked { border-color: var(--grass); background: #e8fbe4; }
.qty-box { display: flex; align-items: center; gap: 0.3rem; }
.qty-btn {
  width: 1.8rem; height: 1.8rem;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.08);
  font-weight: 900;
  color: var(--ink);
  line-height: 1;
}
.qty-btn:hover { background: rgba(0, 0, 0, 0.16); }
.qty-num { min-width: 1.3rem; text-align: center; font-weight: 800; }

.money-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-weight: 800;
  color: var(--ink-soft);
  font-size: 0.88rem;
}
.money-field input {
  width: 7rem;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  border: 2px solid rgba(61, 139, 79, 0.3);
  background: #fff;
  font: inherit;
  font-weight: 800;
  color: var(--ink);
}
.name-field select {
  padding: 0.55rem 0.7rem;
  border-radius: 12px;
  border: 2px solid rgba(61, 139, 79, 0.3);
  background: #fff;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
}
.trade-summary {
  margin: 0.8rem 0 0;
  padding: 0.6rem 0.7rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.5;
}

/* 「找我」——高亮自己的小人 */
.ghost-btn.find-me {
  background: linear-gradient(180deg, #ffe9a8, #f6c84c);
  border-color: rgba(120, 80, 0, 0.35);
  color: #5a3d08;
}
.ghost-btn.find-me:hover { filter: brightness(1.06); }

.stage {
  position: relative;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  border: 4px solid var(--gold-deep);
  box-shadow: var(--shadow);
  line-height: 0;
}

#world {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  image-rendering: -webkit-optimize-contrast;
}

.prompt {
  position: absolute;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  background: rgba(35, 64, 40, 0.92);
  color: #f4ffe9;
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.9rem;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.prompt b {
  background: var(--gold);
  color: #4a3306;
  padding: 0 0.4rem;
  border-radius: 6px;
}

/* ---- Weather events ---- */
.event-banner {
  position: absolute;
  top: 3%;
  left: 50%;
  transform: translateX(-50%);
  max-width: 92%;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.9rem;
  text-align: center;
  white-space: nowrap;
  z-index: 6;
  pointer-events: none;
  box-shadow: var(--shadow);
  animation: pop 0.3s ease both;
}
.event-banner.rain { background: linear-gradient(90deg, #6eb6e8, #9ad0f5); color: #12384f; }
.event-banner.galaxy { background: linear-gradient(90deg, #1b1340, #4b2f8a 50%, #1b1340); color: #f4e8ff; }
.event-banner.tornado { background: linear-gradient(90deg, #8a8f97, #c5cad1); color: #24303a; }

.event-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.event-fx.active { opacity: 1; }

/* One layer per running event, so two or three blend on screen together. */
.event-fx-layer { position: absolute; inset: 0; }
.event-fx-layer.rain {
  background: repeating-linear-gradient(
    110deg, transparent 0 10px, rgba(180, 220, 255, 0.28) 10px 12px);
  animation: rain-fall 0.7s linear infinite;
}
.event-fx-layer.galaxy {
  background:
    radial-gradient(circle at 20% 30%, rgba(180, 120, 255, 0.4), transparent 25%),
    radial-gradient(circle at 80% 20%, rgba(120, 200, 255, 0.35), transparent 22%),
    radial-gradient(circle at 50% 70%, rgba(255, 180, 255, 0.28), transparent 28%),
    rgba(12, 8, 40, 0.24);
  animation: galaxy-twinkle 2.4s ease-in-out infinite alternate;
}
.event-fx-layer.tornado {
  background: rgba(120, 130, 140, 0.2);
  animation: tornado-shake 0.18s linear infinite;
}

/* Banner holds one chip per event when several run at once. */
.event-banner.multi {
  background: rgba(20, 32, 24, 0.82);
  color: #f4ffe9;
  white-space: normal;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: center;
  border-radius: 14px;
  padding: 0.4rem 0.5rem;
}
.event-chip {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}
.event-chip.rain { background: linear-gradient(90deg, #6eb6e8, #9ad0f5); color: #12384f; }
.event-chip.galaxy { background: linear-gradient(90deg, #4b2f8a, #7b4bd8); color: #f4e8ff; }
.event-chip.tornado { background: linear-gradient(90deg, #8a8f97, #c5cad1); color: #24303a; }
@keyframes rain-fall { from { background-position: 0 0; } to { background-position: 40px 60px; } }
@keyframes galaxy-twinkle { from { filter: brightness(0.95) saturate(1); } to { filter: brightness(1.15) saturate(1.3); } }
@keyframes tornado-shake {
  0% { transform: translateX(0); } 25% { transform: translateX(-3px); }
  50% { transform: translateX(3px); } 75% { transform: translateX(-2px); } 100% { transform: translateX(0); }
}

.help {
  margin: 0.7rem 0 0;
  text-align: center;
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.5;
}
.help b { color: var(--ink); }

/* Touch controls (shown only on touch devices) */
.touch-controls {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}
body.touch .touch-controls { display: block; }

.dpad {
  position: absolute;
  left: 3%;
  bottom: 4%;
  width: 132px;
  height: 132px;
  pointer-events: auto;
}
.pad {
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 248, 232, 0.85);
  border: 2px solid rgba(61, 139, 79, 0.35);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
  display: grid;
  place-items: center;
}
.pad:active { background: var(--gold); }
.pad.up { top: 0; left: 44px; }
.pad.down { bottom: 0; left: 44px; }
.pad.left { top: 44px; left: 0; }
.pad.right { top: 44px; right: 0; }

.action-btn {
  position: absolute;
  right: 4%;
  bottom: 6%;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: linear-gradient(180deg, #62c46f, #3f9a4d);
  color: #fff;
  font-size: 1.6rem;
  font-weight: 900;
  box-shadow: 0 5px 0 #2f7a3b, var(--shadow);
  pointer-events: auto;
}
.action-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #2f7a3b; }

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(24, 40, 28, 0.5);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 30;
  animation: fade 0.18s ease both;
}
/* The author `display` above overrides the [hidden] attribute, so hide explicitly. */
.overlay[hidden] { display: none; }

.sheet {
  position: relative;
  width: min(440px, 100%);
  max-height: 82vh;
  overflow-y: auto;
  background: var(--panel);
  border: 3px solid rgba(143, 98, 48, 0.3);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem 1.1rem 1.3rem;
  animation: pop 0.2s ease both;
}

.close-btn {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.08);
  color: var(--ink);
  font-weight: 900;
}
.close-btn:hover { background: rgba(0, 0, 0, 0.16); }

.panel-body h2 {
  margin: 0.2rem 0 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.4rem;
}
.panel-note {
  margin: 0.35rem 0 0.85rem;
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 0.9rem;
}

.row-list { display: grid; gap: 0.5rem; }

.item-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.55rem;
  align-items: center;
  padding: 0.55rem 0.6rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  border: 2px solid transparent;
  text-align: left;
  width: 100%;
  color: inherit;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}
.item-row:hover { background: #fff; }
.item-row.active {
  border-color: var(--grass);
  background: #e8fbe4;
  transform: scale(1.01);
}
.item-emoji { font-size: 1.5rem; width: 1.9rem; text-align: center; }
.item-meta { display: grid; gap: 0.1rem; min-width: 0; }
.item-name { font-weight: 800; font-size: 0.95rem; }
.item-sub { font-size: 0.76rem; color: var(--ink-soft); font-weight: 700; }
.item-action {
  font-weight: 800;
  color: #6b4a10;
  background: linear-gradient(180deg, #ffe7a0, #f0c24d);
  border-radius: 999px;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

.empty-note {
  margin: 0.4rem 0 0;
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 0.9rem;
}

.primary-btn {
  width: 100%;
  margin-top: 0.9rem;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #62c46f, #3f9a4d);
  box-shadow: 0 4px 0 #2f7a3b;
}
.primary-btn:hover { filter: brightness(1.05); }
.primary-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #2f7a3b; }
.primary-btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.name-field { display: grid; gap: 0.35rem; font-weight: 800; color: var(--ink-soft); }
.name-field input {
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  border: 2px solid rgba(61, 139, 79, 0.3);
  background: #fff;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.4rem;
  transform: translateX(-50%) translateY(12px);
  background: rgba(35, 64, 40, 0.94);
  color: #f4ffe9;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 40;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
