/* ==========================================================================
   style.css — dark basement chrome around the canvas
   ========================================================================== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  background: #070503;
  overflow: hidden;
  font-family: "Trebuchet MS", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #e8dcc0;
  user-select: none;
  touch-action: none;
}

body {
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 40%, #241a10 0%, #0b0704 62%, #030201 100%);
}

#stage {
  position: relative;
  width: 900px; height: 540px;
  /* Must not be flex-shrunk: the box is a fixed 900x540 that JS scales with a
     transform, and letting flex squeeze it first clipped the canvas on phones. */
  flex: 0 0 auto;
  transform-origin: center center;
  box-shadow: 0 0 0 3px #1d1409, 0 0 42px 8px rgba(0,0,0,0.9), 0 0 120px 20px rgba(120,20,20,0.09);
  border-radius: 3px;
  overflow: hidden;
}

#game {
  display: block;
  width: 900px; height: 540px;
  image-rendering: auto;
  background: #0a0705;
}

/* ---------------- overlay screens ---------------- */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: space-between;
  padding: 30px 24px 24px;
  text-align: center;
  z-index: 5;
}
.screen.hidden { display: none; }

#screen-dead, #screen-win, #screen-pause {
  justify-content: center;
  gap: 14px;
  background: rgba(6, 3, 2, 0.55);
  backdrop-filter: blur(2px);
}

/* ---------------- 背包 ---------------- */
#screen-backpack {
  justify-content: center;
  gap: 12px;
  background: rgba(6, 3, 2, 0.72);
  backdrop-filter: blur(3px);
}
.backpack-sub { font-size: 13px; color: #b3a181; letter-spacing: 1px; }
.backpack-sub b { color: #e2cf9f; }
.backpack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  width: 100%; max-width: 640px;
  max-height: 300px; overflow-y: auto;
  padding: 2px;
}
.backpack-empty { font-size: 14px; color: #8d7c5c; letter-spacing: 2px; }
.bp-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: rgba(14, 9, 5, 0.8);
  border: 2px solid rgba(220, 200, 160, 0.18);
  border-radius: 7px;
  padding: 8px 8px 9px;
}
.bp-icon { width: 44px; height: 44px; image-rendering: auto; }
.bp-name {
  font-size: 11px; font-weight: 800; letter-spacing: 0.5px; color: #f2e4c4;
  text-align: center; line-height: 1.1; min-height: 24px;
}
.bp-desc { font-size: 10px; color: #9d8c6c; text-align: center; line-height: 1.15; }
.bp-drop {
  font-family: inherit; font-size: 11px; font-weight: 800; letter-spacing: 1px;
  color: #ffc9b8; cursor: pointer;
  padding: 3px 12px; margin-top: 2px;
  background: linear-gradient(180deg, #7a2c1e 0%, #561c12 100%);
  border: 2px solid #1a0a05; border-radius: 5px;
  box-shadow: inset 0 1px 0 rgba(255,180,150,0.25), 0 3px 0 #1a0a05;
  transition: transform .07s, box-shadow .07s, filter .12s;
}
.bp-drop:hover { filter: brightness(1.18); }
.bp-drop:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255,180,150,0.2), 0 1px 0 #1a0a05; }

/* ---------------- 进入游戏加载界面 ---------------- */
#loading {
  position: absolute; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 40%, #241a10 0%, #0b0704 62%, #030201 100%);
  transition: opacity .5s ease;
}
#loading.done { opacity: 0; pointer-events: none; }

.loading-inner { text-align: center; }
.loading-hero {
  font-size: 30px; letter-spacing: 6px; font-weight: 900;
  color: #ffe9b0;
  margin-bottom: 14px;
  text-shadow: 0 0 8px rgba(255,200,60,0.9), 0 0 22px rgba(255,160,40,0.6), 0 3px 0 #7a4a12;
  animation: loading-pulse 1.2s ease-in-out infinite;
}
@keyframes loading-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.72; transform: scale(1.05); }
}
.loading-title {
  font-size: 46px; letter-spacing: 9px; font-weight: 900;
  background: linear-gradient(180deg, #f4e3bd 0%, #d8b077 45%, #8f2020 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 0 #170d08) drop-shadow(0 0 22px rgba(180,30,30,0.45));
}
.loading-sub {
  margin-top: 6px; font-size: 16px; letter-spacing: 7px; color: #a99772;
  text-shadow: 0 2px 0 #150c07;
}
.loading-bar {
  width: 260px; height: 10px; margin: 26px auto 16px;
  background: #1d1409;
  border: 2px solid #191009;
  border-radius: 6px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.8);
  overflow: hidden;
}
.loading-fill {
  height: 100%; width: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, #8f2020 0%, #d96a3a 55%, #eec15a 100%);
  box-shadow: 0 0 12px rgba(224, 100, 40, 0.6);
  animation: loading-fill 0.95s ease forwards;
}
@keyframes loading-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.loading-text { font-size: 13px; letter-spacing: 4px; color: #9b8a6b; }

.title-block { margin-top: 8px; }

.game-title {
  font-size: 62px; letter-spacing: 9px; font-weight: 900;
  background: linear-gradient(180deg, #f4e3bd 0%, #d8b077 45%, #8f2020 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 0 #170d08) drop-shadow(0 0 22px rgba(180,30,30,0.45));
  line-height: 1;
}
.game-sub {
  margin-top: 8px; font-size: 17px; letter-spacing: 7px; color: #a99772;
  text-shadow: 0 2px 0 #150c07;
}

.title-foot { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.dead-title, .win-title, .pause-title {
  font-size: 56px; font-weight: 900; letter-spacing: 8px;
  filter: drop-shadow(0 4px 0 #170d08);
}
.dead-title { color: #c8302e; text-shadow: 0 0 30px rgba(200,40,40,0.5); }
.win-title  { color: #ffd95a; text-shadow: 0 0 30px rgba(255,215,90,0.45); }
.pause-title { color: #e8dcc0; }
.dead-sub { font-size: 15px; color: #b3a181; letter-spacing: 2px; }

.stat-grid {
  display: grid; grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px 14px; margin-top: 6px;
}
.stat-cell {
  background: rgba(14, 9, 5, 0.78);
  border: 2px solid rgba(220, 200, 160, 0.2);
  border-radius: 7px;
  padding: 9px 14px 10px;
  min-width: 130px;
}
.stat-cell .k { display: block; font-size: 11px; letter-spacing: 2px; color: #9d8c6c; }
.stat-cell .v { display: block; font-size: 25px; font-weight: 800; color: #f2e4c4; line-height: 1.15; }
.stat-cell.hl .v { color: #ffd95a; }

.item-recap {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  max-width: 660px; font-size: 11.5px; color: #b8a680;
}
.item-recap span {
  border: 1px solid rgba(220,200,160,0.22);
  background: rgba(14,9,5,0.6);
  border-radius: 4px; padding: 3px 7px;
}
.item-recap .none { border: none; background: none; color: #7a6d55; }

.btn {
  font-family: inherit; font-size: 19px; font-weight: 800; letter-spacing: 5px;
  color: #f4e6c4; cursor: pointer;
  padding: 13px 34px;
  background: linear-gradient(180deg, #59401f 0%, #3a2712 100%);
  border: 3px solid #191009;
  border-radius: 6px;
  box-shadow: inset 0 2px 0 rgba(255,225,170,0.25), 0 5px 0 #191009, 0 8px 18px rgba(0,0,0,0.6);
  transition: transform .07s, box-shadow .07s, filter .12s;
}
.btn:hover { filter: brightness(1.16); }
.btn:active { transform: translateY(4px); box-shadow: inset 0 2px 0 rgba(255,225,170,0.2), 0 1px 0 #191009; }

.hint { font-size: 12.5px; color: #9b8a6b; letter-spacing: 1px; }
.hint b { color: #e2cf9f; }

.title-links { display: flex; align-items: center; gap: 10px; }
.title-links a {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; letter-spacing: 1px; text-decoration: none;
  color: #9b8a6b;
  background: rgba(14, 9, 5, 0.6);
  border: 1px solid rgba(220, 200, 160, 0.22);
  border-radius: 4px;
  padding: 5px 12px;
  transition: color .12s, border-color .12s, background .12s;
}
.title-links a:hover {
  color: #f0dcae;
  background: rgba(42, 28, 14, 0.8);
  border-color: rgba(226, 207, 159, 0.5);
}
.title-links svg { width: 13px; height: 13px; flex: 0 0 auto; }

/* ---------------- 登录/注册 ---------------- */
#screen-auth { justify-content: center; gap: 14px; }
.auth-title {
  font-size: 40px; font-weight: 900; letter-spacing: 8px; color: #e8dcc0;
  filter: drop-shadow(0 4px 0 #170d08);
}
.auth-box {
  display: flex; flex-direction: column; gap: 13px; width: min(320px, 78vw);
  background: rgba(10, 6, 3, 0.8);
  border: 2px solid rgba(220, 200, 160, 0.25);
  border-radius: 9px;
  padding: 22px 24px 20px;
}
.auth-label {
  display: block; text-align: left; font-size: 12px; letter-spacing: 2px;
  color: #9d8c6c;
}
/* 通用隐藏（.hidden 单独使用也生效，避免被 .auth-label 等 display 规则覆盖） */
.hidden { display: none; }
.auth-input {
  display: block; width: 100%; margin-top: 5px; box-sizing: border-box;
  font-family: inherit; font-size: 16px; color: #f2e4c4;
  background: #191009; border: 2px solid rgba(220,200,160,0.28);
  border-radius: 5px; padding: 9px 12px; outline: none;
}
.auth-input:focus { border-color: rgba(226,207,159,0.6); }
/* 密码输入框 + 眼睛按钮（点击切换明文/密文） */
.pwd-wrap { position: relative; display: block; }
.pwd-wrap .auth-input { padding-right: 38px; }
.pwd-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; line-height: 1;
  padding: 6px 8px; opacity: 0.85;
}
.pwd-eye svg { display: block; }
.pwd-eye:hover { opacity: 1; }
.pwd-eye.on { opacity: 1; }
.auth-error {
  font-size: 12.5px; color: #ff8a75; letter-spacing: 0.5px; margin: -2px 0 0;
}
.auth-switch { font-size: 12.5px; color: #9b8a6b; margin-top: 4px; }
.auth-switch a { color: #e2cf9f; text-decoration: underline; cursor: pointer; }

/* ---------------- 暂停菜单 ---------------- */
.pause-controls {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  margin-top: 6px;
}
.vol-row {
  display: flex; align-items: center; gap: 12px;
  background: rgba(14, 9, 5, 0.78);
  border: 2px solid rgba(220, 200, 160, 0.2);
  border-radius: 7px; padding: 10px 16px;
}
.vol-label { font-size: 13px; letter-spacing: 3px; color: #9d8c6c; }
.vol-input { width: 150px; accent-color: #c8302e; cursor: pointer; }
.vol-num { font-size: 14px; font-weight: 800; color: #f2e4c4; min-width: 26px; text-align: right; }
.btn-sm { font-size: 15px; padding: 9px 26px; letter-spacing: 3px; }

/* ---------------- 登录后主菜单 ---------------- */
#screen-menu, #screen-leaderboard, #screen-settings, #screen-duo {
  justify-content: center; gap: 16px;
  background: rgba(6, 3, 2, 0.55);
  backdrop-filter: blur(2px);
}
.menu-title {
  font-size: 42px; font-weight: 900; letter-spacing: 9px; color: #e8dcc0;
  filter: drop-shadow(0 4px 0 #170d08);
}
.menu-user { font-size: 13px; color: #b3a181; letter-spacing: 2px; }
.menu-box { display: flex; flex-direction: column; gap: 13px; width: min(340px, 80vw); }
.menu-box .btn { width: 100%; }
.btn-danger { background: linear-gradient(180deg, #6b2a22 0%, #431712 100%); }
.badge {
  display: inline-block; margin-left: 8px; font-size: 11px; letter-spacing: 1px;
  color: #ffd95a; border: 1px solid rgba(255, 215, 90, 0.4);
  border-radius: 4px; padding: 1px 6px; vertical-align: middle;
}
.muted { color: #9b8a6b; font-size: 13px; }
.settings-box {
  display: flex; flex-direction: column; gap: 14px; align-items: center;
  background: rgba(14, 9, 5, 0.78); border: 2px solid rgba(220, 200, 160, 0.2);
  border-radius: 9px; padding: 18px 26px; min-width: 320px;
}
.settings-user { font-size: 14px; color: #f2e4c4; letter-spacing: 1px; }
.duo-status {
  font-size: 18px; color: #f2e4c4; letter-spacing: 2px; margin-top: 8px;
  text-align: center; max-width: 340px;
  min-height: 30px;                       /* 避免状态行高度跳动 */
}
.duo-countdown {
  display: flex; align-items: baseline; justify-content: center; gap: 12px;
  margin: 22px 0 8px;
}
.duo-countdown.hidden { display: none; }
.duo-count-num {
  font-size: 52px; font-weight: 700; color: #ffd95a;
  text-shadow: 0 0 22px rgba(255, 217, 90, 0.5);
}
.duo-count-text { font-size: 18px; letter-spacing: 3px; color: #d8c8a4; }
.duo-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; width: min(300px, 74vw); }
.duo-actions .btn { width: 100%; }
.duo-hint { font-size: 13px; color: #9b8a6b; letter-spacing: 1px; max-width: 320px; text-align: center; margin-top: 6px; }
.duo-result-sub { font-size: 15px; color: #f2e4c4; letter-spacing: 2px; margin: 8px 0 20px; text-align: center; }

/* 排行榜表格 */
.lb-tabs { display: flex; gap: 8px; margin: 4px 0 10px; }
.lb-tab {
  font-size: 13px; letter-spacing: 2px; padding: 6px 16px;
  color: #9b8a6b; background: rgba(20, 12, 6, 0.6);
  border: 1px solid rgba(220, 200, 160, 0.25); border-radius: 4px;
  cursor: pointer; transition: color .15s, border-color .15s, background .15s;
}
.lb-tab:hover { color: #e2cf9f; border-color: rgba(226, 207, 159, 0.5); }
.lb-tab.active { color: #ffd95a; background: rgba(20, 12, 6, 0.9); border-color: #e2cf9f; font-weight: 700; }
.lb-list { max-height: 300px; overflow-y: auto; padding: 0 6px; }
.lb-table { border-collapse: collapse; font-size: 13px; min-width: 400px; }
.lb-table th, .lb-table td {
  border: 1px solid rgba(220, 200, 160, 0.18); padding: 6px 12px; text-align: center;
}
.lb-table th { color: #e2cf9f; background: rgba(20, 12, 6, 0.7); font-weight: 700; }
.lb-table td { color: #d8c8a4; }
.lb-table tr:nth-child(1) td { color: #ffd95a; font-weight: 700; }

/* ---------------- mobile touch controls ---------------- */
#touch-ui { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#touch-ui.hidden { display: none; }

#joystick {
  position: fixed; left: 22px; bottom: 22px;
  width: 138px; height: 138px; border-radius: 50%;
  background: radial-gradient(circle, rgba(60,44,26,0.5) 0%, rgba(20,13,7,0.42) 70%);
  border: 3px solid rgba(226, 207, 159, 0.3);
  pointer-events: auto;
  touch-action: none;
}
#joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 58px; height: 58px; margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #cbb68b, #6f5934);
  border: 3px solid #1a1109;
  box-shadow: 0 3px 10px rgba(0,0,0,0.7);
}

#shoot-pad {
  position: fixed; right: 20px; bottom: 18px;
  width: 168px; height: 168px;
  pointer-events: none;
}
.sbtn {
  position: absolute;
  width: 58px; height: 58px;
  font-size: 21px; line-height: 1; color: #f1dfae;
  font-family: inherit;
  background: radial-gradient(circle at 40% 32%, rgba(150,44,44,0.85), rgba(72,18,18,0.9));
  border: 3px solid #1a0d09;
  border-radius: 50%;
  box-shadow: inset 0 2px 0 rgba(255,200,180,0.28), 0 4px 10px rgba(0,0,0,0.65);
  pointer-events: auto;
  touch-action: none;
}
.sbtn.on { filter: brightness(1.55); transform: scale(0.93); }
#sb-up    { left: 55px; top: 0; }
#sb-down  { left: 55px; bottom: 0; }
#sb-left  { left: 0; top: 55px; }
#sb-right { right: 0; top: 55px; }

#rotate-hint {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 196px;
  align-items: center; justify-content: center; gap: 8px;
  font-size: 12.5px; letter-spacing: 1px; color: #9b8a6b;
  z-index: 15; pointer-events: none;
}
#rotate-hint .ph {
  display: inline-block; width: 13px; height: 20px;
  border: 2px solid #9b8a6b; border-radius: 3px;
  animation: tilt 2.4s ease-in-out infinite;
}
@keyframes tilt {
  0%, 45% { transform: rotate(0deg); }
  60%, 90% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

#btn-rotate {
  position: fixed; top: 14px; right: 14px;
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #dff0ff;
  background: radial-gradient(circle at 40% 32%, rgba(52,110,170,0.88), rgba(22,44,80,0.92));
  border: 3px solid #0d1a2c;
  box-shadow: inset 0 2px 0 rgba(200,230,255,0.28), 0 4px 10px rgba(0,0,0,0.65);
  pointer-events: auto;
  touch-action: manipulation;
  z-index: 21;
}
#btn-rotate:active { transform: scale(0.92); }
#btn-rotate svg { width: 22px; height: 22px; display: block; }

#btn-pause {
  position: fixed; top: 14px; left: 14px;
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #ffe9b0;
  background: radial-gradient(circle at 40% 32%, rgba(150,110,40,0.88), rgba(90,60,18,0.92));
  border: 3px solid #2a1c08;
  box-shadow: inset 0 2px 0 rgba(255,230,180,0.28), 0 4px 10px rgba(0,0,0,0.65);
  pointer-events: auto;
  touch-action: manipulation;
  z-index: 21;
}
#btn-pause:active { transform: scale(0.92); }
#btn-pause svg { width: 22px; height: 22px; display: block; }

#btn-backpack {
  position: fixed; top: 70px; left: 14px;
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #bff3d8;
  background: radial-gradient(circle at 40% 32%, rgba(38,150,120,0.88), rgba(16,80,64,0.92));
  border: 3px solid #0a2a20;
  box-shadow: inset 0 2px 0 rgba(200,255,228,0.28), 0 4px 10px rgba(0,0,0,0.65);
  pointer-events: auto;
  touch-action: manipulation;
  z-index: 21;
}
#btn-backpack:active { transform: scale(0.92); }
#btn-backpack svg { width: 22px; height: 22px; display: block; }

/* portrait phones: reserve the bottom of the screen for thumbs, centre the
   canvas in what's left, and nudge the player towards landscape */
@media (max-aspect-ratio: 1/1) {
  body { align-items: center; padding-bottom: 210px; }
  #rotate-hint { display: flex; }
}
