* { box-sizing: border-box; }
:root {
  --yellow: #ffcf3f;
  --yellow-dark: #e8a900;
  --orange: #ff8a3d;
  --brown: #6b4a2b;
  --ink: #2c2418;
  --paper: #fffdf5;
  --green: #6fcf6a;
  --red: #ff5b5b;
  --blue: #4aa8ff;
  --shadow: 0 12px 30px rgba(60, 40, 10, .18);
}
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--ink);
  overflow: hidden;
  background: #bfe6ff;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }

/* ---------- 登录 ---------- */
#login {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(#8fd3ff 0%, #c9ecff 55%, #eaf9d8 100%);
  overflow: hidden;
}
.sky { position: absolute; inset: 0; overflow: hidden; }
.sun {
  position: absolute; top: 7%; right: 9%; width: 120px; height: 120px; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #fff8c9, #ffd75e 60%, rgba(255,215,94,0) 72%);
  filter: blur(2px);
}
.cloud {
  position: absolute; height: 46px; border-radius: 999px;
  background: rgba(255,255,255,.88); filter: blur(.3px);
  box-shadow: 0 10px 30px rgba(120,170,210,.16);
  animation: drift 90s linear infinite;
}
.cloud::before, .cloud::after {
  content: ""; position: absolute; background: inherit; border-radius: 50%;
}
.cloud::before { width: 70px; height: 70px; left: 26px; top: -32px; }
.cloud::after { width: 44px; height: 44px; right: 30px; top: -20px; }
.c1 { width: 190px; top: 16%; left: -220px; animation-duration: 70s; }
.c2 { width: 140px; top: 32%; left: -180px; animation-duration: 95s; animation-delay: -30s; opacity: .8; }
.c3 { width: 240px; top: 8%; left: -300px; animation-duration: 120s; animation-delay: -70s; opacity: .6; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(130vw); } }
.hills {
  position: absolute; left: -10%; right: -10%; bottom: -8%; height: 38%;
  background:
    radial-gradient(60% 100% at 20% 100%, #9fdc7b 0 60%, transparent 61%),
    radial-gradient(55% 90% at 55% 100%, #8ed46a 0 62%, transparent 63%),
    radial-gradient(65% 100% at 85% 100%, #a7e083 0 60%, transparent 61%);
  opacity: .85;
}
.login-card {
  position: relative; z-index: 2; width: min(400px, calc(100vw - 32px));
  background: rgba(255,253,245,.94); border: 2px solid #fff;
  border-radius: 28px; padding: 34px 30px 26px;
  box-shadow: 0 24px 60px rgba(50, 80, 110, .28);
  text-align: center;
  backdrop-filter: blur(8px);
  animation: pop .5s cubic-bezier(.2,1.3,.5,1);
}
@keyframes pop { from { transform: translateY(16px) scale(.96); opacity: 0; } }
.logo {
  font-size: 62px; line-height: 1; margin-bottom: 6px;
  filter: drop-shadow(0 8px 12px rgba(220,160,0,.3));
  animation: bob 3s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-7px) } }
.login-card h1 { margin: 4px 0 2px; font-size: 32px; letter-spacing: 4px; color: #4a3418; }
.tagline { margin: 0 0 22px; color: #8a7a5e; font-size: 13px; }
.form-group { text-align: left; margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: #7b6a4d; margin: 0 0 6px 4px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 12px 14px; font-size: 15px; color: var(--ink);
  border: 2px solid #efe3c8; border-radius: 14px; background: #fffef9;
  outline: none; transition: .18s;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { border-color: var(--yellow); box-shadow: 0 0 0 4px rgba(255,207,63,.18); }
.btn {
  border: 0; cursor: pointer; font-family: inherit; font-weight: 700;
  border-radius: 14px; padding: 11px 18px; font-size: 15px;
  background: #f0ead9; color: #6b5a3a; transition: transform .12s, filter .12s;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(#ffd953, var(--yellow)); color: #5a3f00; box-shadow: 0 6px 0 #d9a200; }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #d9a200; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; margin-top: 6px; }
.btn.blue { background: linear-gradient(#7cc4ff, var(--blue)); color: #fff; box-shadow: 0 5px 0 #2b7fc4; }
.btn.red { background: linear-gradient(#ff8f8f, var(--red)); color: #fff; box-shadow: 0 5px 0 #c93b3b; }
.btn.ghost { background: #f4efe3; color: #8a7a5e; box-shadow: none; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.hint { color: #a2947a; font-size: 12px; margin: 16px 0 0; }
.login-foot {
  position: absolute; bottom: 18px; left: 0; right: 0; text-align: center;
  font-size: 12px; color: rgba(60,80,90,.55); z-index: 2;
}
.form-error {
  background: #fff0f0; color: #c43b3b; border: 1px solid #ffd1d1;
  padding: 9px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 14px;
}

/* ---------- 游戏 ---------- */
#game { background: #9fd9ff; }
#canvas-wrap { position: absolute; inset: 0; }
#canvas-wrap canvas { display: block; }

.hud-top {
  position: absolute; top: 14px; left: 14px; right: 14px; z-index: 10;
  display: flex; gap: 10px; align-items: flex-start; pointer-events: none;
  flex-wrap: wrap;
}
.hud-card {
  background: rgba(255,253,245,.92); border-radius: 16px; padding: 8px 14px;
  box-shadow: 0 8px 24px rgba(40,60,80,.16);
  display: flex; align-items: center; gap: 10px;
  pointer-events: auto; backdrop-filter: blur(6px);
}
.hud-card.identity { min-width: 172px; }
.avatar {
  width: 40px; height: 40px; border-radius: 12px; background: #fff3c4;
  display: grid; place-items: center; font-size: 26px;
}
.pname { font-weight: 800; font-size: 15px; line-height: 1.2; }
.pdist { font-size: 12px; color: #9a8a6a; margin-top: 2px; }
.hud-card.stat { flex-direction: column; align-items: stretch; gap: 6px; min-width: 220px; }
.hud-card.stat .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.points { font-size: 14px; color: #7a5a10; }
.points b { font-size: 17px; color: #d18a00; }
.points .unit { font-size: 11px; color: #b09a70; }
.streak { font-size: 11px; color: #c45a3b; }
.hunger-row { gap: 8px; }
.hbar { flex: 1; height: 9px; background: #f0e6cd; border-radius: 99px; overflow: hidden; }
.hbar i { display: block; height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, #ffd15c, #79d05a); transition: width .3s; }
.hgrams { font-size: 11px; color: #8a7a5a; white-space: nowrap; }

.hud-actions { margin-left: auto; display: flex; gap: 8px; pointer-events: auto; flex-wrap: wrap; justify-content: flex-end; }
.hbtn {
  border: 0; cursor: pointer; font-family: inherit; font-weight: 700; font-size: 13px;
  background: rgba(255,253,245,.94); color: #6b5a3a; padding: 10px 14px; border-radius: 12px;
  box-shadow: 0 6px 18px rgba(40,60,80,.14); text-decoration: none; transition: .15s;
  backdrop-filter: blur(6px);
}
.hbtn:hover { background: #fff; transform: translateY(-1px); }
.hbtn.ghost { background: rgba(255,255,255,.55); color: #7d8a90; }
.hbtn.admin { background: #3b3f4a; color: #ffd15c; }

.jail-banner {
  position: absolute; top: 92px; left: 50%; transform: translateX(-50%); z-index: 12;
  background: rgba(20,20,24,.9); color: #ffd15c; padding: 10px 20px; border-radius: 99px;
  font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35); border: 1px solid #4a4a55;
}
.jicon { font-size: 17px; }

.action-bar {
  position: absolute; bottom: 74px; left: 50%; transform: translateX(-50%); z-index: 11;
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; width: min(760px, 96vw);
  pointer-events: none;
}
.act-group {
  background: rgba(255,253,245,.96); border-radius: 18px; padding: 8px 10px 10px;
  box-shadow: 0 14px 34px rgba(30,50,70,.22); display: flex; gap: 7px; align-items: center;
  pointer-events: auto; flex-wrap: wrap; justify-content: center;
  animation: pop .22s ease-out; border: 1px solid #fff;
}
.act-label { font-size: 13px; font-weight: 800; color: #6b5a3a; padding: 0 4px; }
.act-group .btn { font-size: 13px; padding: 8px 12px; }
.act-group .btn.danger { background: #ffe6e6; color: #c43b3b; }
.act-group .btn.money { background: #fff1c9; color: #966800; }
.act-group .btn.enter { background: linear-gradient(#ffd953, var(--yellow)); color: #5a3f00; box-shadow: 0 4px 0 #d9a200; }

.chat-log {
  position: absolute; left: 14px; bottom: 14px; z-index: 10;
  width: min(330px, 46vw); max-height: 190px; overflow: hidden;
  display: flex; flex-direction: column; gap: 6px; justify-content: flex-end;
  pointer-events: none;
}
.chat-line {
  background: rgba(255,253,245,.9); border-radius: 10px; padding: 6px 10px;
  font-size: 12.5px; color: #4a4030; box-shadow: 0 4px 14px rgba(30,50,70,.12);
  animation: slidein .25s ease-out;
}
.chat-line b { color: #d18a00; }
.chat-line.self { background: rgba(255,247,214,.95); }
@keyframes slidein { from { opacity: 0; transform: translateX(-10px); } }

.toast-wrap {
  position: fixed; top: 100px; left: 50%; transform: translateX(-50%); z-index: 30;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
  width: min(520px, 92vw);
}
.toast {
  background: rgba(34,30,22,.92); color: #ffe9a8; padding: 10px 18px; border-radius: 12px;
  font-size: 13.5px; font-weight: 600; box-shadow: 0 10px 26px rgba(0,0,0,.28);
  animation: toastin .25s ease-out; max-width: 100%; text-align: center;
}
.toast.err { background: rgba(150,35,35,.94); color: #ffe3e3; }
.toast.ok { background: rgba(35,110,60,.94); color: #e4ffe9; }
@keyframes toastin { from { opacity: 0; transform: translateY(-8px); } }

.hint-bar {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  font-size: 11.5px; color: rgba(45,60,70,.55); z-index: 9; pointer-events: none;
  background: rgba(255,255,255,.45); padding: 5px 12px; border-radius: 99px;
  white-space: nowrap;
}

/* ---------- 弹窗 ---------- */
.modal-wrap {
  position: fixed; inset: 0; z-index: 40; background: rgba(20,30,40,.42);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--paper); border-radius: 22px; width: min(560px, 100%);
  max-height: min(86vh, 720px); display: flex; flex-direction: column;
  box-shadow: 0 30px 80px rgba(20,30,50,.35); border: 2px solid #fff;
  animation: pop .25s cubic-bezier(.2,1.3,.5,1);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 12px; border-bottom: 1px solid #f0e8d4;
}
.modal-head h2 { margin: 0; font-size: 18px; letter-spacing: 1px; }
.modal-x {
  border: 0; background: #f4efe3; width: 32px; height: 32px; border-radius: 50%;
  font-size: 19px; color: #8a7a5e; cursor: pointer; line-height: 1;
}
.modal-body { padding: 16px 20px 22px; overflow: auto; }
.modal-body p { line-height: 1.65; font-size: 14px; color: #5a4f3d; margin: 8px 0; }
.modal-body h3 { font-size: 14px; margin: 18px 0 8px; color: #7a6a4d; }
.modal-body .sub { font-size: 12.5px; color: #9a8a6a; }
.modal-body textarea { resize: vertical; min-height: 74px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 11px 14px; background: #fffdf6; border: 1px solid #f0e8d4; border-radius: 13px;
}
.item .meta { min-width: 0; }
.item .title { font-weight: 700; font-size: 14px; }
.item .desc { font-size: 12px; color: #9a8a6a; margin-top: 2px; }
.item .price { color: #d18a00; font-weight: 800; font-size: 14px; white-space: nowrap; }
.item .right { display: flex; align-items: center; gap: 10px; }
.tag { font-size: 11px; padding: 3px 8px; border-radius: 99px; background: #eee7d5; color: #8a7a5e; }
.tag.green { background: #e2f6e0; color: #3f8f3f; }
.tag.red { background: #ffe4e4; color: #c43b3b; }
.tag.blue { background: #e2f0ff; color: #2f7ac4; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pick {
  border: 2px solid #f0e8d4; background: #fffdf6; border-radius: 13px; padding: 11px;
  cursor: pointer; text-align: center; font-family: inherit; font-size: 13px; font-weight: 700;
  color: #6b5a3a; transition: .15s;
}
.pick:hover { border-color: var(--yellow); background: #fff9e3; }
.pick.current { border-color: var(--yellow); background: #fff3c4; }
.pick .small { display: block; font-weight: 500; font-size: 11px; color: #a2947a; margin-top: 3px; }
.pick:disabled { opacity: .4; cursor: not-allowed; }

.shop-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 0; border-bottom: 1px dashed #efe6d0; }
.shop-row:last-child { border-bottom: 0; }
.shop-name { font-weight: 700; font-size: 14px; }
.shop-price { color: #d18a00; font-weight: 800; font-size: 13px; }

/* ---------- 死亡 ---------- */
.death-wrap {
  position: fixed; inset: 0; z-index: 60; background: rgba(10,10,14,.86);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(4px);
}
.death-card {
  background: #1c1b20; border: 1px solid #3a3844; border-radius: 24px;
  width: min(400px, 100%); padding: 32px 26px; text-align: center; color: #e8e2d4;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.skull { font-size: 54px; filter: grayscale(1); }
.death-card h2 { color: #ff7b7b; margin: 8px 0 10px; letter-spacing: 3px; }
.death-card p { font-size: 14px; line-height: 1.7; color: #b9b2a4; }
.death-note { font-size: 12.5px !important; color: #8a8478 !important; margin: 14px 0 18px !important; }
.death-card .btn.primary { box-shadow: 0 6px 0 #a87d00; }
.death-points { font-size: 13px; color: #8a8478; margin-top: 14px; }
.death-points span { color: #ffd15c; font-weight: 800; }

/* ---------- WebGL 不可用 ---------- */
.webgl-fail {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  padding: 30px; background: linear-gradient(180deg, #bfe7ff, #e9f8d8);
  color: #4a3f2a; font-family: inherit;
}
.webgl-fail .wf-icon { font-size: 64px; margin-bottom: 10px; }
.webgl-fail h3 { font-size: 20px; margin: 0 0 10px; }
.webgl-fail p { font-size: 13.5px; line-height: 1.8; color: #6b5c42; max-width: 420px; margin: 0; }

@media (max-width: 720px) {
  .hud-top { top: 8px; left: 8px; right: 8px; gap: 6px; }
  .hud-card { padding: 6px 10px; border-radius: 13px; }
  .hud-card.identity { min-width: 0; }
  .avatar { width: 32px; height: 32px; font-size: 20px; }
  .pname { font-size: 13px; }
  .pdist { font-size: 11px; }
  .hud-card.stat { min-width: 170px; flex: 1; }
  .hud-actions { width: 100%; justify-content: flex-start; gap: 6px; }
  .hbtn { padding: 8px 10px; font-size: 12px; }
  .chat-log { width: 62vw; bottom: 52px; }
  .action-bar { bottom: 96px; }
  .hint-bar { display: none; }
  .login-card { padding: 26px 22px 20px; }
  .modal-body { padding: 14px 14px 18px; }
  .grid3 { grid-template-columns: 1fr 1fr; }
}
