* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #17251b; font-family: system-ui, "Microsoft YaHei", "PingFang SC", sans-serif; user-select: none; -webkit-user-select: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ================= 大厅 ================= */
#lobby {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow-y: auto;
  background:
    radial-gradient(1100px 520px at 50% -8%, rgba(255, 214, 130, .18), transparent 60%),
    radial-gradient(900px 640px at 88% 108%, rgba(46, 122, 61, .35), transparent 60%),
    linear-gradient(178deg, #2c4a34 0%, #1e3325 46%, #142218 100%);
}
#lobby::before {
  content: ''; position: fixed; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(115deg, transparent 0 34px, rgba(255,255,255,.022) 34px 36px);
}
.lobbyCard {
  position: relative; width: min(600px, 94vw);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 30px 26px 22px; border-radius: 22px;
  background: linear-gradient(165deg, rgba(38, 62, 46, .88), rgba(20, 34, 24, .92));
  border: 1px solid rgba(255, 215, 106, .22);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .08);
  backdrop-filter: blur(6px);
}
#lobby h1 {
  color: #ffe9a8; font-size: 36px; letter-spacing: 2px;
  text-shadow: 0 2px 0 rgba(120, 70, 10, .35), 0 6px 18px rgba(0, 0, 0, .45);
}
#lobby .sub { color: #bcd9b2; font-size: 13px; letter-spacing: 1px; }
#lobby .sub span { color: #ffd76a; font-weight: 700; }
#user, #pass {
  width: min(300px, 86vw); padding: 12px 16px; border-radius: 12px; border: 1px solid rgba(255,255,255,.14);
  background: rgba(0, 0, 0, .28); color: #fff; font-size: 16px; outline: none; transition: border .15s, box-shadow .15s;
}
#user:focus, #pass:focus { border-color: #ffd76a; box-shadow: 0 0 0 3px rgba(255, 215, 106, .18); }
#user::placeholder, #pass::placeholder { color: rgba(255,255,255,.4); }

#chars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: min(540px, 90vw); margin-top: 2px; }
.card {
  position: relative; background: rgba(255,255,255,.06); border: 2px solid transparent; border-radius: 14px;
  padding: 10px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: #fff; cursor: pointer; transition: all .15s;
}
.card:hover { background: rgba(255,255,255,.1); }
.card.sel { border-color: #ffd76a; background: rgba(255, 215, 106, .14); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(255, 175, 55, .18); }
.card .emoji { font-size: 54px; filter: drop-shadow(0 3px 4px rgba(0,0,0,.4)); }
.card .charimg { height: 104px; width: auto; object-fit: contain; filter: drop-shadow(0 4px 5px rgba(0,0,0,.35)); }
.card .cname { font-size: 14px; font-weight: 600; }
.card .row { display: flex; align-items: center; gap: 5px; }
.card .cgen { font-size: 14px; }
.card .cgen.f { color: #ff9ec4; }
.card .cgen.m { color: #7fc4ff; }
/* 设置面板里的小号形象卡 */
.card.small .emoji { font-size: 34px; }
.card.small .charimg { height: 64px; }
.card.small .cname { font-size: 12px; }
.card.taken { opacity: .38; cursor: not-allowed; }
.card .takenTag {
  position: absolute; top: 5px; right: 6px; font-size: 10px; color: #ffb0b0;
  background: rgba(120, 20, 20, .55); border-radius: 6px; padding: 1px 5px;
}
.err { color: #ff9b9b; min-height: 18px; font-size: 14px; text-align: center; }

.joinRow { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.joinRow button {
  border: none; border-radius: 13px; padding: 13px 22px; font-size: 16px; font-weight: 700; cursor: pointer;
  color: #fff; transition: transform .1s, box-shadow .1s, filter .15s;
}
#registerBtn { background: linear-gradient(180deg, #4db35e, #358a44); box-shadow: 0 4px 0 #256631, 0 8px 18px rgba(0,0,0,.3); }
#loginBtn { background: linear-gradient(180deg, #5b93d8, #3f74b5); box-shadow: 0 4px 0 #2c5488, 0 8px 18px rgba(0,0,0,.3); }
.joinRow button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.3); }
.joinRow button:disabled { opacity: .55; pointer-events: none; }
.ghostBtn {
  border: 1px dashed rgba(255,255,255,.3); background: transparent; color: #cfe0c8;
  border-radius: 12px; padding: 9px 18px; font-size: 13px; cursor: pointer; transition: all .15s;
}
.ghostBtn:hover { border-color: #ffd76a; color: #ffe9a8; }
.ghostBtn:disabled { opacity: .55; }
#lobby .tip { color: #93b78c; font-size: 12px; text-align: center; line-height: 1.85; margin-top: 2px; }

/* ================= HUD ================= */
#hud {
  position: fixed; top: 8px; left: 10px; z-index: 10; display: flex; flex-direction: column; gap: 6px;
  pointer-events: none; max-width: min(46vw, 340px);
}
#hudTop { display: flex; gap: 6px; }
#hudTop button {
  pointer-events: auto; border: none; border-radius: 12px; cursor: pointer;
  background: rgba(14, 28, 18, .78); color: #ffe9a8; font-size: 12px; font-weight: 700;
  padding: 8px 12px; box-shadow: 0 2px 8px rgba(0,0,0,.4); border: 1px solid rgba(255, 215, 106, .2);
  backdrop-filter: blur(4px);
}
#hudTop button:active { transform: translateY(1px); }
.bar { display: flex; align-items: center; gap: 6px; color: #fff; font-size: 12px;
  background: rgba(14, 28, 18, .6); border-radius: 20px; padding: 4px 10px 4px 7px; width: fit-content;
  border: 1px solid rgba(255,255,255,.08); backdrop-filter: blur(4px); }
.bar .track { width: 120px; height: 7px; background: rgba(0,0,0,.5); border-radius: 4px; overflow: hidden; }
#hpFill { height: 100%; width: 100%; background: linear-gradient(90deg, #e05b5b, #ff8a8a); border-radius: 4px; transition: width .3s; }
#hungerFill { height: 100%; width: 100%; background: linear-gradient(90deg, #d99a2b, #ffd76a); border-radius: 4px; transition: width .3s; }
.bar em { font-style: normal; font-size: 11px; color: #e8f2e4; }
#inv { display: flex; flex-wrap: wrap; gap: 5px; max-width: min(46vw, 340px); }
#inv .chip {
  display: inline-flex; align-items: center; gap: 3px; color: #ffe9a8; font-size: 13px;
  background: rgba(14, 28, 18, .68); border-radius: 16px; padding: 4px 10px;
  border: 1px solid rgba(255, 215, 106, .16); backdrop-filter: blur(4px);
}
#inv .chip b { font-size: 13px; font-weight: 700; color: #fff; }
#levelInfo { color: #ffd76a; font-size: 13px; font-weight: 700; text-shadow: 0 1px 3px rgba(0,0,0,.7); }
#players { color: #cfe8c6; font-size: 12px; text-shadow: 0 1px 3px rgba(0,0,0,.7); }
#clock { color: #e8f2e4; font-size: 12px; text-shadow: 0 1px 3px rgba(0,0,0,.7); }

/* ================= 触屏控制 ================= */
#touch { display: none; position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#actBtns { position: absolute; right: 6px; bottom: 6px; display: grid; grid-template-columns: repeat(3, 48px); gap: 6px; pointer-events: auto; }
#actBtns button {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid rgba(255,255,255,.12);
  background: radial-gradient(circle at 32% 28%, rgba(72, 110, 82, .9), rgba(14, 28, 18, .88));
  color: #fff; padding: 2px 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  touch-action: none; box-shadow: 0 3px 8px rgba(0,0,0,.5);
}
#actBtns button:active { transform: scale(.93); filter: brightness(1.25); }
#actBtns button span { font-size: 15px; line-height: 1; }
#actBtns button b { font-size: 10px; font-weight: 600; line-height: 1.1; }

/* ================= 聊天 ================= */
#chatWrap { position: fixed; left: 10px; bottom: 10px; z-index: 8; width: min(430px, calc(100vw - 20px)); }
#chatLog {
  max-height: 110px; overflow-y: auto; background: rgba(10, 20, 13, .5); border-radius: 12px;
  padding: 7px 11px; font-size: 13px; color: #e8f2e4; margin-bottom: 6px; scrollbar-width: thin;
  border: 1px solid rgba(255,255,255,.07); backdrop-filter: blur(4px);
}
#chatRow { display: flex; gap: 6px; }
#chatInput { flex: 1; padding: 9px 14px; border-radius: 20px; border: 1px solid rgba(255,255,255,.14); background: rgba(10, 20, 13, .6); color: #fff; font-size: 14px; outline: none; min-width: 0; backdrop-filter: blur(4px); }
#chatInput::placeholder { color: rgba(255,255,255,.35); }
#chatSend { border: none; border-radius: 20px; background: linear-gradient(180deg, #ffc25e, #f0a03a); color: #3a2a08; font-weight: 700; padding: 0 18px; cursor: pointer; }
#chatSend:active { transform: scale(.96); }
#chatToggle { display: none; }

/* ================= 手机布局 ================= */
@media (pointer: coarse) {
  #touch { display: block; }
  #chatWrap { bottom: 216px; width: min(330px, calc(100vw - 20px)); }
  #chatToggle { display: block; position: fixed; right: 10px; bottom: 262px; width: 46px; height: 46px; border-radius: 50%; border: 1px solid rgba(255,255,255,.12); background: rgba(14, 28, 18, .78); color: #fff; font-size: 17px; z-index: 9; }
  #chatWrap.collapsed #chatLog, #chatWrap.collapsed #chatRow { display: none; }
  #micBtn { right: 10px; bottom: 326px; }
  #sfxBtn { right: 10px; bottom: 394px; }
  #chatLog { max-height: 90px; }
  #hud { max-width: 60vw; }
  #inv { max-width: 60vw; }
}

/* ================= 语音 / 声音 ================= */
#micBtn { position: fixed; right: 20px; bottom: 20px; width: 60px; height: 60px; border-radius: 50%; border: 1px solid rgba(255,255,255,.12); background: rgba(14, 28, 18, .78); color: #fff; font-size: 22px; z-index: 12; box-shadow: 0 3px 10px rgba(0,0,0,.5); touch-action: none; }
#micBtn.on { background: radial-gradient(circle at 32% 28%, #3f9e4f, #256631); box-shadow: 0 0 0 3px rgba(120,255,140,.5); }
#sfxBtn { position: fixed; right: 20px; bottom: 88px; width: 60px; height: 60px; border-radius: 50%; border: 1px solid rgba(255,255,255,.12); background: rgba(14, 28, 18, .78); color: #fff; font-size: 22px; z-index: 12; box-shadow: 0 3px 10px rgba(0,0,0,.5); touch-action: none; }
#sfxBtn.off { opacity: .55; }
#voiceInfo { color: #7fe08f; font-size: 13px; font-weight: 600; }

/* ================= 通用弹窗 ================= */
#shopBox, #buildBox, #helpBox, #settingsBox { display: none; position: fixed; inset: 0; z-index: 40; background: rgba(6, 12, 8, .6); align-items: center; justify-content: center; backdrop-filter: blur(3px); }
#helpBox { z-index: 45; }
#shopBox .panel, #buildBox .panel, #helpBox .panel, #settingsBox .panel {
  background: linear-gradient(165deg, #2a4232, #1a2c20);
  border: 1px solid rgba(255, 215, 106, .25); border-radius: 18px; padding: 20px 22px;
  width: min(340px, 90vw); text-align: center; color: #fff;
  box-shadow: 0 24px 60px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.07);
  animation: popIn .18s ease-out;
}
@keyframes popIn { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#shopBox h3, #buildBox h3, #helpBox h3, #settingsBox h3 { color: #ffe9a8; margin-bottom: 10px; letter-spacing: 1px; }
#shopBox p, #buildBox p, #settingsBox p { font-size: 13px; color: #cfe8c6; line-height: 1.65; margin-bottom: 12px; }
#shopBox p b, #buildBox p b, #settingsBox p b { color: #ffe9a8; }
#shopBtns, #buildBtns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
#shopBtns button, #buildBtns button, #setClose, #nickSave {
  padding: 11px 0; border: none; border-radius: 11px; cursor: pointer;
  background: linear-gradient(180deg, #ffc25e, #f0a03a); color: #3a2a08; font-weight: 700; font-size: 14px;
  box-shadow: 0 3px 0 #b06f1c;
}
#shopBtns button small { font-weight: 600; font-size: 11px; opacity: .8; }
#shopBtns button:active, #buildBtns button:active, #nickSave:active, #setClose:active { transform: translateY(2px); box-shadow: 0 1px 0 #b06f1c; }
#shopBtns button.cancel, #buildBtns button.cancel, #setClose.cancel { background: rgba(255,255,255,.12); color: #eee; box-shadow: 0 3px 0 rgba(0,0,0,.3); }

/* ================= 设置面板 ================= */
#settingsBox .panel { width: min(420px, 92vw); text-align: left; }
#acctLine.acctLine { background: rgba(0,0,0,.24); border-radius: 10px; padding: 8px 12px; font-size: 13px; margin-bottom: 10px; }
.setRow { display: flex; gap: 8px; margin-bottom: 12px; }
#nickInput { flex: 1; padding: 11px 14px; border-radius: 11px; border: 1px solid rgba(255,255,255,.16); background: rgba(0,0,0,.28); color: #fff; font-size: 15px; outline: none; min-width: 0; }
#nickInput:focus { border-color: #ffd76a; }
#nickSave { padding: 0 18px; white-space: nowrap; }
.setTitle { color: #ffd76a; font-size: 14px; margin: 2px 0 8px; }
#setChars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
#statLine {
  font-size: 13px; color: #cfe8c6; line-height: 1.9; text-align: center;
  background: rgba(0,0,0,.24); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px;
}
#statLine b { color: #ffe9a8; }
#setClose { display: block; width: 100%; }

/* ================= 建房风格 ================= */
.styleRow { font-size: 13px; color: #cfe8c6; display: flex; align-items: center; gap: 6px; justify-content: center; margin-bottom: 10px; }
.styleRow button { border: 2px solid transparent; border-radius: 10px; background: rgba(255,255,255,.1); color: #fff; padding: 5px 10px; font-size: 12px; cursor: pointer; }
.styleRow button.sel { border-color: #ffd76a; background: rgba(255, 215, 106, .2); }

/* ================= 宠物 ================= */
#petInfo { color: #ffd76a; font-size: 13px; font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,.7); }
#btnFeed { grid-column: 1 / -1; width: 100%; height: 40px; border-radius: 20px; flex-direction: row; gap: 4px; }
#btnFeed span { font-size: 16px; }
#btnFeed b { font-size: 12px; }
#shopBox h4.petTitle { color: #ffe9a8; margin: 12px 0 8px; font-size: 14px; border-top: 1px dashed rgba(255, 215, 106, .3); padding-top: 10px; }
#petBtns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
#petBtns button { padding: 10px 2px; border: none; border-radius: 11px; background: rgba(255,255,255,.09); color: #fff; font-weight: 700; font-size: 13px; cursor: pointer; line-height: 1.4; border: 1px solid rgba(255,255,255,.1); }
#petBtns button:active { transform: translateY(1px); }
#petBtns button small { display: block; font-weight: 500; font-size: 10px; opacity: .85; margin-top: 3px; }

/* ================= 帮助 ================= */
#helpBtn { position: fixed; top: 10px; right: 10px; width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(255,255,255,.12); background: rgba(14, 28, 18, .78); color: #fff; font-size: 19px; z-index: 30; box-shadow: 0 3px 10px rgba(0,0,0,.5); touch-action: none; }
#helpBox .panel { width: min(600px, 92vw); max-height: 84vh; overflow-y: auto; }
#helpBox h4 { color: #ffd76a; font-size: 14px; margin: 8px 0 4px; }
#helpBox .helpDoc section { margin-bottom: 12px; }
#helpBox .helpDoc h4 { margin: 0 0 5px; border-left: 3px solid #ffb347; padding-left: 8px; }
#helpBox .helpDoc p { margin: 3px 0; font-size: 13px; color: #e8f2e4; line-height: 1.8; }
#helpBox .helpDoc p b { color: #ffe9a8; }
#helpClose { display: block; margin: 12px auto 0; border: none; border-radius: 11px; background: linear-gradient(180deg, #ffc25e, #f0a03a); color: #3a2a08; font-weight: 700; padding: 10px 36px; font-size: 14px; cursor: pointer; box-shadow: 0 3px 0 #b06f1c; }
#helpClose:active { transform: translateY(2px); box-shadow: 0 1px 0 #b06f1c; }
@media (max-width: 480px) { #helpBox .panel, #settingsBox .panel { padding: 14px; } }

/* ================= 存档退出 ================= */
#quitBtn { pointer-events: auto; }

/* ================= 提示 ================= */
#toast {
  position: fixed; left: 50%; top: 16%; transform: translateX(-50%);
  background: rgba(12, 22, 14, .88); color: #ffe9a8; padding: 10px 20px; border-radius: 14px;
  font-size: 15px; z-index: 50; opacity: 0; transition: opacity .3s; pointer-events: none;
  max-width: 86vw; text-align: center; border: 1px solid rgba(255, 215, 106, .25);
  box-shadow: 0 10px 30px rgba(0,0,0,.45); white-space: pre-wrap;
}
