* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f2e8d5;
  --panel: #fffaf0;
  --wood: #5d4a2f;
  --green: #5a9e4b;
  --green-dark: #41773a;
  --gold: #e0a72e;
  --red: #d9534f;
  --text: #4a3a2a;
  --shadow: 3px 3px 0 rgba(70, 45, 15, .25);
}
html, body { height: 100%; }
body {
  font-family: "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: linear-gradient(#cfe8c0, var(--bg) 240px);
  color: var(--text);
}
#app { max-width: 800px; margin: 0 auto; padding: 12px; }

/* ---- 頂欄 ---- */
#topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
  background: var(--panel); border: 3px solid var(--wood); border-radius: 8px;
  padding: 8px 14px; box-shadow: var(--shadow); margin-bottom: 10px; font-weight: 700;
}
.stat { display: flex; align-items: center; gap: 6px; }
.stamina .bar { width: 100px; height: 12px; background: #e4d9c3; border: 2px solid var(--wood); overflow: hidden; }
.stamina .fill { height: 100%; width: 100%; background: linear-gradient(90deg, #f5c542, #7ec850); transition: width .3s; }
#buffBar { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.buff-chip {
  background: #eaf6e2; border: 2px solid #7da868; border-radius: 4px;
  padding: 2px 8px; font-size: 13px; font-weight: 600;
}

/* ---- 快捷列 ---- */
/* 快捷列:單排,用左右箭頭橫向切換 */
#quickBarWrap { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
#quickBar {
  display: flex; gap: 8px; flex: 1; min-width: 0;
  flex-wrap: nowrap; overflow-x: auto; scroll-behavior: smooth;
  scrollbar-width: none; -ms-overflow-style: none;
}
#quickBar::-webkit-scrollbar { display: none; }
#quickBar > button { flex: 0 0 auto; white-space: nowrap; }
/* 分類標籤:非按鈕,作為快捷列的群組分隔 */
.qb-cat {
  flex: 0 0 auto; align-self: center; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 12px; font-weight: 800; color: var(--wood);
  letter-spacing: .3px; padding: 3px 8px 3px 10px;
  border-left: 3px dotted rgba(120, 85, 40, .5);
}
.qb-cat:first-child { border-left: none; padding-left: 2px; }
.qb-arrow {
  flex: 0 0 auto; border: 3px solid var(--wood); border-radius: 6px;
  background: var(--wood); color: #fff; font-size: 15px; font-weight: 700;
  padding: 8px 10px; cursor: pointer; font-family: inherit; align-self: stretch;
  box-shadow: 2px 2px 0 rgba(70, 45, 15, .3);
}
.qb-arrow:hover { filter: brightness(1.1); }
.qb-arrow:active { transform: translate(2px, 2px); box-shadow: none; }
.qb-arrow:disabled { opacity: .35; cursor: default; box-shadow: none; }

/* ---- 像素世界 ---- */
#world {
  display: block; width: 100%;
  border: 4px solid var(--wood); border-radius: 6px;
  box-shadow: var(--shadow); cursor: pointer; background: #6fbf4a;
}
#worldHint { margin-top: 8px; }
.hint { font-size: 13.5px; color: #8a7a62; margin-bottom: 10px; }

/* ---- 按鈕 ---- */
button.act, .big-btn {
  border: 3px solid var(--wood); border-radius: 6px; padding: 8px 14px;
  font-size: 14px; font-weight: 700; background: var(--green); color: #fff;
  cursor: pointer; font-family: inherit; box-shadow: 2px 2px 0 rgba(70, 45, 15, .3);
}
button.act:hover, .big-btn:hover { background: var(--green-dark); }
button.act:active, .big-btn:active { transform: translate(2px, 2px); box-shadow: none; }
button.act:disabled, .big-btn:disabled { background: #c0b8a6; cursor: not-allowed; }
button.gold { background: var(--gold); }
button.gold:hover { background: #c08f1f; }
button.ninja { background: #4a3f63; }
button.ninja:hover { background: #372e4d; }
button.adventure { background: #2f7d4f; }
button.adventure:hover { background: #246340; }
button.rebirth { background: linear-gradient(135deg, #b8860b, #e0a72e); }
button.rebirth:hover { background: #9a7209; }
button.world2 { background: linear-gradient(135deg, #6a3fb0, #a34fd0); }
button.world2:hover { background: #5a2f9a; }
button.world3 { background: linear-gradient(135deg, #23203a, #4a3a6a); border-color: #4a3a6a; }
button.world3:hover { background: #191627; }
button.world4 { background: linear-gradient(135deg, #8a1f1f, #d84315); border-color: #8a1f1f; }
button.world4:hover { background: #6f1616; }
/* 🛠️ 管理員機器面板 */
.admin-qty {
  width: 110px; border: 3px solid var(--wood); border-radius: 6px;
  padding: 10px; font-size: 14.5px; font-family: inherit; background: #fffaf0; color: var(--text);
}
.admin-label { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: #6b5b43; font-weight: 700; white-space: nowrap; }
/* 物品/加成選擇 grid:點磁磚選取 */
.admin-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px;
  max-height: 210px; overflow-y: auto; margin: 8px 0; padding: 6px;
  background: #f3ecdd; border: 2px solid #d8ccb2; border-radius: 8px;
}
.admin-tile {
  border: 2px solid #d8ccb2; border-radius: 6px; background: #fffaf0;
  padding: 7px 4px; text-align: center; cursor: pointer;
  font-size: 12.5px; font-weight: 700; font-family: inherit; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.admin-tile .em { display: block; font-size: 21px; margin-bottom: 2px; }
.admin-tile:hover { border-color: var(--gold); }
.admin-tile.sel { border-color: var(--green); background: #eaf6e2; box-shadow: 0 0 0 2px var(--green) inset; }
.admin-buff-grid { max-height: none; overflow: visible; }
button.ranch { background: #a5673f; }
button.ranch:hover { background: #8a5433; }
button.ghost-act { background: #8a7a62; }
button.ghost-act:hover { background: #6f6250; }
.big-btn { padding: 12px 20px; font-size: 16px; }
.big-btn.danger { background: var(--red); }
.big-btn.danger:hover { background: #b94440; }
.big-btn.danger:disabled, button.act:disabled, .big-btn:disabled { background: #c0b8a6 !important; cursor: not-allowed; }
.big-btn.ghost { background: #d8ccb2; color: var(--text); }
.big-btn.primary { background: #5b7fd9; }
.big-btn.primary:hover { background: #4a6bc0; }

/* 📡 廣播機器輸入框 */
#broadcastText {
  width: 100%; box-sizing: border-box; border: 3px solid var(--wood); border-radius: 8px;
  padding: 10px; font-size: 15px; font-family: inherit; background: #fffaf0; color: var(--text);
  resize: vertical; margin: 4px 0 10px;
}

/* 🌀 傳送面板 */
#teleportList { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.teleport-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: linear-gradient(100deg, #f3ecff, #ece4fb); border: 2px solid #c9b8ee;
  border-radius: 10px; cursor: pointer; transition: transform .08s, box-shadow .1s;
}
.teleport-row:hover:not(.locked):not(.here) { transform: translateY(-1px); box-shadow: 0 3px 0 #b79fe0; }
.teleport-row:active:not(.locked):not(.here) { transform: translateY(1px); box-shadow: none; }
.teleport-row.here { border-color: var(--green); background: linear-gradient(100deg, #eaf6e2, #d8efc8); cursor: default; }
.teleport-row.locked { opacity: .68; filter: grayscale(.35); cursor: not-allowed; background: #f0ece2; border-color: #d8ccb2; }
.teleport-row .tp-icon { font-size: 30px; width: 34px; text-align: center; }
.teleport-row .tp-info { flex: 1; min-width: 120px; }
.teleport-row .tp-info b { display: block; font-size: 15.5px; }
.teleport-row .tp-info small { color: #7a6a52; }
.tp-tag { font-size: 12.5px; font-weight: 700; white-space: nowrap; padding: 4px 8px; border-radius: 20px; background: #e6ddf5; color: #6a4fa0; }
.tp-tag.go { background: #5b7fd9; color: #fff; }
.tp-tag.lock { background: #e2d9c8; color: #8a7a62; }
.teleport-row.here .tp-tag { background: var(--green); color: #fff; }

/* 📡 管理員廣播橫幅(所有玩家畫面上方) */
#broadcastBanner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 300;
  display: flex; align-items: center; gap: 10px; justify-content: center;
  padding: 12px 18px; box-sizing: border-box;
  background: linear-gradient(100deg, #2b3f63, #3d5a8a); color: #fff;
  font-weight: 700; font-size: 15px; text-align: center;
  box-shadow: 0 3px 12px rgba(0,0,0,.35); border-bottom: 3px solid #7fd0ff;
}
#broadcastBanner.hidden { display: none; }
#broadcastBanner #broadcastBannerIcon { font-size: 22px; animation: bcPulse 1s ease-in-out infinite; }
#broadcastBanner #broadcastBannerText { word-break: break-word; }
#broadcastBanner.bc-show { animation: bcDrop .35s ease-out; }
@keyframes bcDrop { from { transform: translateY(-100%); } to { transform: translateY(0); } }
@keyframes bcPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.25); } }

/* ---- 通用列 ---- */
.row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: #f7f0df; border: 2px solid #d8ccb2; border-radius: 6px;
  margin-bottom: 8px; flex-wrap: wrap;
}
.row .icon { font-size: 26px; }
.row .info { flex: 1; min-width: 140px; }
.row .info b { display: block; }
.row .info small { color: #8a7a62; }
.row button { white-space: nowrap; }
.seed-cat { margin: 14px 0 8px; color: #6b5b43; }
.row.wearing { border-color: var(--green); background: #eaf6e2; }
/* 商店精選特賣 / 變異作物 */
.row.deal-head { background: #fff3d6; border-color: #e9c66a; }
.row.deal-row { background: #fffaf0; border-color: #e9c66a; }
.row.deal-row s { color: #b3a892; font-size: 12px; }
.deal-tag { background: var(--red); color: #fff; border-radius: 4px; padding: 0 6px; font-size: 12px; }
.row.rare-deal { background: linear-gradient(100deg, #fff0fb, #f3ecff); border-color: #c77dff; }
.row.mut-row { background: linear-gradient(100deg, #fffbe6, #fff0fb); border-color: #f0c14b; }
.row.gamble-row { background: linear-gradient(100deg, #fff6d8, #ffe2c0); border-color: #e0892e; }
/* 隨機庫存:缺貨的種子列變灰、標題灰底;庫存數字用綠色強調 */
.row.out-stock { opacity: .5; filter: grayscale(.5); }
.stock-n { color: #3f8f4a; }
.row.out-stock .stock-n { color: var(--red); }
.row.stock-note { background: #eef4e6; border-color: #bcd3a3; border-style: dashed; }
.row.stock-note .info small { color: #6f7e58; }
/* 成就 */
.ach-summary { margin: 4px 0 10px; font-weight: bold; color: #6b5b43; }
.row.ach-got { background: linear-gradient(100deg, #fff7e0, #fff0c4); border-color: #e9c66a; }
/* 金色成就(兌換碼限定):整列金光閃閃 */
.row.ach-goldrow {
  background: linear-gradient(100deg, #ffe98a, #ffd94d 55%, #ffe98a);
  border-color: #b8860b;
  box-shadow: 0 0 10px rgba(255, 200, 40, .45), inset 0 1px 0 #fff3a8;
}
.row.ach-goldrow .info b { color: #7a5200; text-shadow: 0 1px 0 #fff3a8; }
.row.ach-goldrow .info small { color: #8a6a1a; }
.row.ach-lock { opacity: .82; }
.row.ach-lock .info b { color: #8a7a62; }
.ach-icon { width: 30px; text-align: center; }
.ach-prog {
  position: relative; min-width: 120px; height: 18px; border-radius: 9px;
  background: #e3dac4; overflow: hidden; border: 1px solid #cdbf9f;
}
.ach-prog-fill { position: absolute; inset: 0; width: 0; background: linear-gradient(90deg, #7cc04a, #5aa83c); }
.ach-prog span {
  position: relative; display: block; text-align: center; line-height: 18px;
  font-size: 11px; font-weight: bold; color: #3a3122; text-shadow: 0 1px 0 #ffffff80;
}
/* 背景音樂面板 */
.music-now {
  text-align: center; font-weight: bold; color: #5b4a2f; font-size: 16px;
  background: #fff7e0; border: 2px solid #e9c66a; border-radius: 8px; padding: 10px; margin-bottom: 10px;
}
.music-controls { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; flex-wrap: wrap; }
.music-controls .big-btn { flex: 1; min-width: 90px; }
.music-vol {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px; padding: 8px 12px;
  background: #f7f0df; border: 2px solid #d8ccb2; border-radius: 8px; font-weight: 700; color: #5b4a2f;
}
.music-vol input[type=range] { flex: 1; accent-color: var(--green); cursor: pointer; }
.music-vol #musicVolVal { min-width: 42px; text-align: right; }
.row.music-cur { background: linear-gradient(100deg, #fff7e0, #fff0c4); border-color: #e9c66a; }
/* 養殖牧場 */
.row.ranch-hungry { background: linear-gradient(100deg, #fff2e0, #ffe4c4); border-color: #e0982e; }
.row.ranch-grown { background: linear-gradient(100deg, #eaf6e2, #d8efc8); border-color: var(--green); }
.ranch-prog { margin-top: 6px; max-width: 200px; }
.ranch-full { font-size: 13px; font-weight: 700; color: #8a7a62; white-space: nowrap; }
/* 帳號資訊 */
.profile-dialog { max-width: 420px; }
.prof-card {
  display: flex; align-items: center; gap: 16px; padding: 16px;
  background: linear-gradient(120deg, #fff7e0, #ffe9c0);
  border: 2px solid #e9c66a; border-radius: 14px; margin-bottom: 8px;
}
.prof-avatar-wrap {
  position: relative; padding: 0; border: none; background: none; cursor: pointer; flex: 0 0 auto;
}
.prof-avatar {
  font-size: 46px; width: 84px; height: 84px; display: flex; align-items: center; justify-content: center;
  background: #fffdf5; border: 3px solid var(--wood); border-radius: 50%; overflow: hidden;
  box-shadow: 2px 2px 0 rgba(70, 45, 15, .25);
}
.prof-avatar img { width: 100%; height: 100%; object-fit: cover; }
.prof-avatar-wrap:hover .prof-avatar { border-color: var(--green); }
.prof-avatar-cam {
  position: absolute; right: -2px; bottom: -2px; width: 26px; height: 26px; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  background: var(--green); color: #fff; border: 2px solid #fffdf5; border-radius: 50%;
}
.prof-card-info { min-width: 0; }
.prof-name-big { font-size: 22px; font-weight: 800; color: #5b4a2f; word-break: break-all; }
.prof-account { font-size: 13px; color: #8a7a62; margin-top: 2px; }
.prof-hint { font-size: 12.5px; color: #a2937b; text-align: center; margin: 0 0 14px; }
.prof-section { margin-bottom: 14px; }
.prof-section .coop-row { align-items: stretch; margin-bottom: 0; }
.prof-label { display: block; font-weight: 700; color: #6b5b43; margin-bottom: 8px; }
#profNameInput {
  flex: 1; min-width: 0; padding: 12px 14px;
  border: 2.5px solid #d8ccb2; border-radius: 10px;
  font-size: 17px; font-weight: 700; font-family: inherit; color: #5b4a2f;
  background: #fffdf7; box-shadow: inset 0 2px 4px rgba(70,45,15,.08);
  transition: border-color .15s, box-shadow .15s;
}
#profNameInput::placeholder { color: #bcae95; font-weight: 400; }
#profNameInput:focus {
  outline: none; border-color: var(--green);
  box-shadow: inset 0 2px 4px rgba(70,45,15,.06), 0 0 0 4px rgba(90,158,75,.2);
}
.prof-section #profRenameBtn { border-radius: 10px; padding-left: 22px; padding-right: 22px; }
.prof-note { font-size: 13px; color: #8a7a62; margin: 8px 0 0; }
.prof-note.warn { color: #c0392b; font-weight: 700; }
.prof-logout { border-top: 2px dashed #e0d6c0; padding-top: 14px; margin-bottom: 0; }
.prof-logout .big-btn { width: 100%; }
button.profile-btn { background: #5a6b8a; }
button.profile-btn:hover { background: #48566f; }
.row.rb-row { background: linear-gradient(100deg, #f3ecff, #eadcff); border-color: #b083e0; }
.row.rb-locked { background: #efe7f7; border-color: #cdbbe0; opacity: .85; }
.row.rb-locked b { color: #8a6fb0; }
.row.w2-row { background: linear-gradient(100deg, #ece4ff, #e0d0ff); border-color: #a34fd0; }
.row.w3-row { background: linear-gradient(100deg, #e6e2f0, #d4cce8); border-color: #4a3a6a; }
.weather-chip { background: #dcecff; border-color: #7da6d8; }
/* 工作台:重生代幣兌換 */
.row.token-row { background: linear-gradient(100deg, #fff6e0, #f3ecff); border-color: #c9a24b; }
.outfit-prev { width: 48px; height: 64px; image-rendering: pixelated; flex-shrink: 0; }
.pet-prev { width: 40px; height: 40px; image-rendering: pixelated; flex-shrink: 0; }
.pet-lv { background: var(--gold); color: #fff; border-radius: 4px; padding: 0 5px; font-size: 12px; }
.pet-exp { height: 5px; background: #e4d9c3; border: 1px solid #b8945c; border-radius: 3px; margin-top: 4px; overflow: hidden; }
.pet-exp > div { height: 100%; background: linear-gradient(90deg, #f5c542, #7ec850); }
.pet-btns { display: flex; flex-direction: column; gap: 5px; }

/* ---- 登入 / 註冊 ---- */
#loginOverlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,.18), transparent 40%),
    linear-gradient(160deg, #9ad86f, #5a9e4b 55%, #3f6f37);
}
#loginOverlay.hidden { display: none !important; }
.login-card {
  width: 100%; max-width: 360px; background: linear-gradient(#fffaf0, #f3ead2);
  border: 5px solid var(--wood); border-radius: 18px; padding: 30px 26px 24px;
  box-shadow: 0 18px 46px rgba(30, 50, 15, .45); text-align: center;
}
.login-logo { font-size: 66px; line-height: 1; filter: drop-shadow(0 5px 6px rgba(0,0,0,.2)); animation: float 3s ease-in-out infinite; }
.login-title { font-size: 32px; color: var(--green-dark); margin: 8px 0 2px; letter-spacing: 4px; }
.login-tag { color: #8a7a62; font-size: 14px; margin-bottom: 22px; }
.login-input {
  display: block; width: 100%; padding: 13px 14px; margin-bottom: 12px;
  border: 3px solid #d8ccb2; border-radius: 11px; font-size: 16px; font-family: inherit;
  background: #fff; color: var(--text); transition: border-color .15s, box-shadow .15s;
}
.login-input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 4px rgba(90,158,75,.2); }
.login-msg { min-height: 20px; font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.login-msg.ok { color: var(--green-dark); }
.login-msg.err { color: var(--red); }
.login-btns { display: flex; flex-direction: column; gap: 10px; }
.login-go, .login-reg {
  padding: 14px; border: 3px solid var(--wood); border-radius: 11px;
  font-size: 16px; font-weight: 800; font-family: inherit; cursor: pointer;
  box-shadow: 2px 2px 0 rgba(70, 45, 15, .3); color: #fff;
}
.login-go:active, .login-reg:active { transform: translate(2px, 2px); box-shadow: none; }
.login-go { background: var(--green); }
.login-go:hover { background: var(--green-dark); }
.login-reg { background: var(--gold); }
.login-reg:hover { background: #c08f1f; }
.login-hint { font-size: 12.5px; color: #a99c84; margin-top: 18px; line-height: 1.6; }

/* ---- 抽抽樂 ---- */
.gacha-prize {
  text-align: center; border: 3px solid #d8ccb2; border-radius: 10px;
  padding: 14px; margin-bottom: 12px; background: #fffaf0;
}
.gacha-prize.empty { color: #8a7a62; font-size: 15px; }
.gacha-prize small { color: #8a7a62; }
.gacha-prize .gp-label { font-size: 22px; font-weight: 800; margin: 6px 0; }
.gp-tier { color: #fff; border-radius: 4px; padding: 1px 8px; font-size: 12px; font-weight: 700; }
.gacha-status { display: flex; justify-content: space-around; font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.gacha-status b { color: var(--green-dark); font-size: 18px; }
.gacha-btns { display: flex; gap: 10px; }
.gacha-btns .big-btn { flex: 1; }
.odds-row { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-bottom: 1px solid #eee3cc; font-size: 13.5px; }
.odds-row .odds-label { flex: 1; }
.odds-row .odds-pct { font-weight: 700; color: #6b5b43; }

/* ---- 兌換碼(美化版)---- */
.code-dialog {
  position: relative; max-width: 380px; text-align: center;
  background: linear-gradient(160deg, #fffdf7, #f3ead6);
  border-width: 5px; box-shadow: 0 12px 30px rgba(70, 45, 15, .35), var(--shadow);
}
.code-close { position: absolute; top: 12px; right: 12px; }
.code-hero {
  font-size: 56px; line-height: 1; margin: 4px 0 2px;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.2));
  animation: codeBob 2.6s ease-in-out infinite;
}
@keyframes codeBob { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-8px) rotate(3deg); } }
.code-title { font-size: 24px; color: var(--wood); margin: 2px 0 6px; letter-spacing: 2px; }
.code-sub { color: #8a7a62; font-size: 14px; line-height: 1.6; margin-bottom: 16px; }
.code-sub span { font-size: 12px; opacity: .8; }
.code-input-row { display: flex; gap: 8px; margin-bottom: 10px; }
#codeInput {
  flex: 1; min-width: 0; padding: 12px 14px; border: 3px solid #d8ccb2; border-radius: 10px;
  font-size: 17px; font-weight: 700; font-family: inherit; background: #fff; color: var(--text);
  text-align: center; letter-spacing: 3px; text-transform: uppercase; transition: border-color .15s, box-shadow .15s;
}
#codeInput::placeholder { letter-spacing: 1px; text-transform: none; font-weight: 400; color: #b9ad95; }
#codeInput:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(90,158,75,.2); }
#redeemCodeBtn { padding: 12px 18px; white-space: nowrap; }
.code-msg { min-height: 22px; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.code-msg.ok { color: var(--green-dark); }
.code-msg.err { color: var(--red); }
.code-redeemed { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.code-chip {
  background: #eaf6e2; border: 2px solid #7da868; border-radius: 999px;
  padding: 3px 12px; font-size: 12.5px; font-weight: 700; color: var(--green-dark);
}
.code-redeemed .empty { color: #a99c84; font-size: 13px; }

/* ---- 對話框 ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(40, 30, 15, .55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.overlay.night { background: linear-gradient(#0b1030ee, #1a1340ee); }
.dialog {
  background: var(--panel); border: 4px solid var(--wood); border-radius: 8px;
  padding: 20px; max-width: 420px; width: 100%;
  box-shadow: 6px 6px 0 rgba(0, 0, 0, .35); text-align: center;
}
.dialog.wide { max-width: 560px; text-align: left; max-height: 84vh; overflow-y: auto; }
.dialog h3 { margin-bottom: 8px; }
.dialog h4 { margin: 14px 0 8px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dlg-head h3 { margin: 0; }
.close-x {
  background: var(--red); color: #fff; border: 2px solid var(--wood); border-radius: 6px;
  width: 30px; height: 30px; font-weight: 700; cursor: pointer; font-size: 14px;
}
#seedPickerList .row { text-align: left; }

/* ---- 好友(獨立面板)---- */
.friends-dialog { max-width: 440px; text-align: left; }
.friend-add { display: flex; gap: 8px; margin-bottom: 12px; }
.friend-add input {
  flex: 1; min-width: 0; padding: 12px 14px; border: 3px solid #d8ccb2; border-radius: 10px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--text);
}
.friend-add input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(90,158,75,.2); }
.friend-add .big-btn { padding: 12px 16px; white-space: nowrap; }
.friend-summary { font-size: 13px; font-weight: 700; color: #6b5b43; margin-bottom: 10px; }
.friends-list { max-height: 46vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.friend-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px;
  border: 2px solid #e2d8c0; background: linear-gradient(#fffdf7, #f6efdd);
}
.friend-row.online { border-color: #9ed27f; background: linear-gradient(#f1fbeb, #e6f6da); }
.friend-av {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; position: relative;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  background: #e7ddc6; border: 2px solid #cdbf9e;
}
.friend-row.online .friend-av { background: #d6efc6; border-color: #9ed27f; }
.friend-av .dot {
  position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%;
  background: #b9ad95; border: 2px solid var(--panel);
}
.friend-av .dot.on { background: #4fc23a; }
.friend-info { flex: 1; min-width: 0; }
.friend-info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.friend-info small { color: #8a7a62; font-size: 12.5px; }
.friend-row.online .friend-info small { color: #4a8a3a; font-weight: 700; }
.friend-row button.invite { white-space: nowrap; }
.friend-empty { text-align: center; color: #a99c84; padding: 24px 8px; font-size: 14px; line-height: 1.8; }
.friend-empty .big { font-size: 38px; display: block; margin-bottom: 6px; }
.friend-foot { margin-top: 12px; }

/* ---- 好友房間邀請橫幅 ---- */
#roomInvite {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 90;
  background: #2f3b66; color: #fff; border: 3px solid #1b2545; border-radius: 12px;
  padding: 12px 16px; box-shadow: 0 8px 22px rgba(0,0,0,.4);
  display: flex; align-items: center; gap: 14px; max-width: 92vw;
  animation: slideIn .25s ease;
}
#roomInvite.hidden { display: none !important; }
#roomInviteText { font-weight: 700; font-size: 14.5px; }
.ri-btns { display: flex; gap: 8px; }

/* ---- 邀請好友 ---- */
#inviteBox {
  background: linear-gradient(120deg, #fff3d6, #ffe9c4);
  border: 2px solid #e9c66a; border-radius: 8px; padding: 12px 14px; margin-bottom: 14px;
}
#inviteBox h4 { margin: 0 0 4px; color: #9a6b1a; }
#inviteLink {
  flex: 1; min-width: 0; padding: 9px 10px; border: 2px solid #d8ccb2; border-radius: 6px;
  font-size: 13px; font-family: inherit; background: #fff; color: var(--text);
}
#inviteStats { margin: 8px 0 0; font-weight: 600; color: #8a6b2a; }

/* ---- 聯機 ---- */
.coop-row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
#playerName, #roomCodeInput, #stealCode {
  padding: 10px 12px; border: 3px solid #d8ccb2; border-radius: 6px;
  font-size: 16px; font-family: inherit; background: #fff;
}
#roomCodeInput, #stealCode { width: 150px; text-transform: uppercase; letter-spacing: 3px; }
.room-code { font-size: 20px; margin-bottom: 10px; }
.room-code b { color: var(--green-dark); letter-spacing: 4px; font-size: 26px; }
.player-chip {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 8px 8px 0;
  background: #eaf6e2; border: 2px solid #7da868; border-radius: 4px; padding: 6px 12px; font-weight: 700;
}
#leaveRoomBtn { margin-top: 8px; }

/* ---- 睡覺 ---- */
.sleep-dialog { background: #181c3a; color: #dfe3ff; border-color: #2c3263; }
#sleepEmoji { font-size: 64px; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-10px);} }
#sleepInfo { margin: 14px 0; font-size: 15px; line-height: 1.8; }
#sleepInfo .mult { font-size: 26px; font-weight: 800; color: #9db4ff; }
#idleLoot {
  margin-top: 12px; padding: 10px 12px; border-radius: 8px;
  background: rgba(255, 215, 64, .1); border: 2px solid #6a5d2f;
  font-size: 14px; line-height: 1.7; color: #ffe9a0; text-align: left;
}
#idleLoot b { color: #ffd24a; }
#sleepWarnings { min-height: 24px; margin-bottom: 10px; }
.sleep-warning { color: #ffb3a8; font-weight: 700; font-size: 14px; margin: 4px 0; }
.sleep-buttons { display: flex; gap: 10px; justify-content: center; }

/* ---- 提示訊息 ---- */
#toasts { position: fixed; top: 14px; right: 14px; z-index: 99; display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.toast {
  background: #3f3527; color: #fff; padding: 10px 14px; border: 2px solid #1f1a12; border-radius: 6px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
  animation: slideIn .25s ease;
}
.toast.warn { background: #a33d2c; }
.toast.good { background: var(--green-dark); }
@keyframes slideIn { from { opacity: 0; transform: translateX(30px);} to { opacity: 1; transform: none;} }

/* ---- 聯機聊天框 ---- */
#chatBox {
  position: fixed; left: 12px; bottom: 12px; z-index: 45; width: 270px; max-width: 70vw;
  background: rgba(40, 30, 18, .9); border: 3px solid var(--wood); border-radius: 10px;
  overflow: hidden; box-shadow: var(--shadow); color: #fff;
}
#chatHead {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; font-weight: 700; background: rgba(0,0,0,.25); cursor: pointer; font-size: 14px;
}
#chatToggle { background: none; border: none; color: #fff; font-size: 16px; cursor: pointer; }
#chatBox.collapsed #chatBody { display: none; }
#chatBox.collapsed #chatToggle { transform: rotate(180deg); }
#chatLog {
  height: 130px; overflow-y: auto; padding: 8px 10px; font-size: 13px; line-height: 1.5;
  display: flex; flex-direction: column; gap: 3px;
}
#chatLog .cm b { color: #ffe9a0; }
#chatLog .cm.me b { color: #9be072; }
#chatLog .sys { color: #c9bfa6; font-style: italic; }
#chatInputRow { display: flex; gap: 6px; padding: 8px; background: rgba(0,0,0,.2); }
#chatInput {
  flex: 1; min-width: 0; padding: 8px 10px; border: 2px solid #d8ccb2; border-radius: 6px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--text);
}
#chatSend { padding: 8px 12px; }

/* ---- 手機虛擬方向鍵 ---- */
#dpad {
  position: fixed; right: 16px; bottom: 16px; z-index: 40;
  display: grid; gap: 6px;
  grid-template-areas: ". u ." "l . r" ". d .";
}
.dpad-btn {
  width: 56px; height: 56px; font-size: 20px; font-weight: 700;
  border: 3px solid var(--wood); border-radius: 10px;
  background: rgba(90, 158, 75, .85); color: #fff; cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none;
  box-shadow: 2px 2px 0 rgba(70, 45, 15, .3);
}
.dpad-btn:active { background: var(--green-dark); transform: translate(1px, 1px); }

/* ---- 新手教學 ---- */
#tutorial { background: rgba(20, 30, 12, .72); z-index: 60; }
.tut-dialog {
  max-width: 440px; text-align: center; position: relative;
  background: linear-gradient(#fffaf0, #f3ead2);
  border-width: 5px; box-shadow: 7px 7px 0 rgba(0,0,0,.32);
}
#tutSkipRow { position: absolute; top: 10px; right: 12px; }
.tut-skip {
  background: none; border: none; color: #9a8a6e; font-family: inherit;
  font-size: 13px; font-weight: 700; cursor: pointer; padding: 4px;
}
.tut-skip:hover { color: var(--red); text-decoration: underline; }
#tutIcon { font-size: 60px; line-height: 1; margin: 6px 0 4px; animation: float 3s ease-in-out infinite; }
.tut-dialog h2 { margin: 4px 0 10px; color: var(--green-dark); }
#tutText { font-size: 15.5px; line-height: 1.85; min-height: 96px; color: var(--text); padding: 0 6px; }
#tutText b { color: var(--green-dark); }
#tutDots { display: flex; justify-content: center; gap: 7px; margin: 14px 0 16px; }
#tutDots span { width: 9px; height: 9px; border-radius: 50%; background: #d8ccb2; transition: background .2s, transform .2s; }
#tutDots span.on { background: var(--green); transform: scale(1.3); }
.tut-buttons { display: flex; gap: 10px; justify-content: center; }
.tut-buttons .big-btn { min-width: 120px; }

.hidden { display: none !important; }

@media (max-width: 560px) {
  #topbar { gap: 8px; font-size: 14px; }
  .stamina .bar { width: 70px; }
}
