/* ============ CS 1.5 H5 样式 ============ */
:root {
  --bg: #0b0d10;
  --bg2: #12161c;
  --panel: rgba(18, 22, 28, 0.94);
  --line: #2a313b;
  --amber: #d89a2b;
  --amber-dim: rgba(216, 154, 43, 0.35);
  --green: #57a05a;
  --red: #c94f4f;
  --txt: #d8dde4;
  --txt-dim: #8a93a0;
  --safet: env(safe-area-inset-top, 0px);
  --safeb: env(safe-area-inset-bottom, 0px);
  --safel: env(safe-area-inset-left, 0px);
  --safer: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  background: var(--bg); color: var(--txt);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  overflow: hidden; overscroll-behavior: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
body { position: fixed; inset: 0; }
.hidden { display: none !important; }

#game {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  background: #000;
  touch-action: none;
  image-rendering: auto;
}

/* ============ 通用屏幕层 ============ */
.screen {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(216,154,43,0.08), transparent 60%),
    var(--bg);
  padding: calc(var(--safet) + 12px) calc(var(--safel) + 12px) calc(var(--safeb) + 12px) calc(var(--safer) + 12px);
  overflow-y: auto;
}

.logo {
  font-size: clamp(30px, 8vw, 54px);
  font-weight: 900; letter-spacing: 0.12em; text-align: center;
  color: var(--amber);
  text-shadow: 0 0 24px rgba(216,154,43,0.35);
  font-family: Impact, "Arial Black", sans-serif;
}
.logo.small { font-size: clamp(20px, 5vw, 30px); }
.logo-sub {
  text-align: center; color: var(--txt-dim);
  margin: 8px 0 22px; font-size: 13px; letter-spacing: 0.2em;
}

/* ============ 启动页 ============ */
.boot-inner { width: min(520px, 92vw); text-align: center; }
.boot-status { margin-top: 14px; color: var(--txt-dim); font-size: 14px; }
.boot-log {
  margin-top: 10px; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px; color: #5b6570; height: 3.2em; overflow: hidden;
  white-space: pre-wrap; word-break: break-all;
}
.progress {
  margin-top: 26px; height: 10px; border-radius: 6px;
  background: #1a2028; border: 1px solid var(--line); overflow: hidden;
}
#boot-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--amber-dim), var(--amber));
  transition: width 0.15s linear;
  border-radius: 6px;
}
#boot-error-btn {
  margin-top: 18px; padding: 10px 34px; font-size: 15px;
  background: var(--amber); color: #101317; border: 0; border-radius: 8px; font-weight: 700;
}

/* ============ 主菜单 ============ */
.menu-inner { width: min(720px, 94vw); }
.map-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 10px; margin-bottom: 18px;
}
.map-card {
  position: relative; height: 76px; border-radius: 10px;
  border: 1px solid var(--line); background: linear-gradient(160deg, #171d25, #10141a);
  color: var(--txt); font-size: 14px; font-weight: 700; letter-spacing: 0.06em;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  cursor: pointer; transition: transform 0.08s, border-color 0.12s;
}
.map-card .map-en { font-size: 10px; color: var(--txt-dim); font-weight: 400; margin-top: 3px; }
.map-card:active { transform: scale(0.95); border-color: var(--amber); }
.menu-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.menu-dl-status {
  display: flex; align-items: center; gap: 10px;
  margin: 0 auto 14px; width: min(420px, 90%);
  font-size: 12px; color: var(--txt-dim);
}
.mdl-bar {
  flex: 1; height: 6px; border-radius: 4px;
  background: #1a2028; border: 1px solid var(--line); overflow: hidden;
}
.mdl-fill { height: 100%; width: 0%; background: var(--green); transition: width 0.2s linear; }
.mdl-txt { white-space: nowrap; }
.map-card .map-dl {
  position: absolute; top: 6px; right: 8px;
  font-size: 13px; color: var(--amber); font-weight: 900;
}
.mbtn {
  padding: 10px 22px; font-size: 14px; border-radius: 8px;
  background: var(--bg2); color: var(--txt); border: 1px solid var(--line);
}
.mbtn:active { border-color: var(--amber); color: var(--amber); }
.footer-note { margin-top: 22px; text-align: center; font-size: 11px; color: #4d5560; }

/* ============ 触控层 ============ */
#touch-ui { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
#zone-move {
  position: absolute; top: 0; bottom: 0; left: 0; width: 42%;
  pointer-events: auto; touch-action: none;
}
#zone-look {
  position: absolute; top: 0; bottom: 0; right: 0; width: 58%;
  pointer-events: auto; touch-action: none;
}
#touch-ui.lefty #zone-move { left: auto; right: 0; }
#touch-ui.lefty #zone-look { right: auto; left: 0; }
#touch-ui.noinput #zone-move,
#touch-ui.noinput #zone-look { pointer-events: none; }

/* 摇杆 */
#joy { position: absolute; z-index: 21; pointer-events: none; }
#joy-base {
  position: absolute; left: 0; top: 0;
  width: var(--joy-size, 120px); height: var(--joy-size, 120px);
  margin-left: calc(var(--joy-size, 120px) / -2);
  margin-top: calc(var(--joy-size, 120px) / -2);
  border-radius: 50%;
  border: 2px solid rgba(216,154,43,0.4);
  background: rgba(216,154,43,0.08);
  box-shadow: 0 0 30px rgba(0,0,0,0.5);
}
#joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 46%; height: 46%;
  margin-left: -23%; margin-top: -23%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(216,154,43,0.95), rgba(150,100,20,0.9));
  box-shadow: 0 2px 10px rgba(0,0,0,0.6);
}

/* 按钮 */
#btns { position: absolute; z-index: 22; pointer-events: none; }
.tbtn {
  pointer-events: auto;
  border-radius: 50%;
  border: 1px solid rgba(216,154,43,0.5);
  background: rgba(14, 17, 22, 0.72);
  color: var(--txt);
  font-size: 12px; font-weight: 800; letter-spacing: 0.05em;
  width: 62px; height: 62px;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  touch-action: none;
}
.tbtn.active { background: rgba(216,154,43,0.55); color: #101317; }
.tbtn.fire {
  width: 84px; height: 84px; font-size: 15px;
  background: rgba(180, 60, 45, 0.62);
  border-color: rgba(255, 120, 90, 0.75);
}
.tbtn.fire.active { background: rgba(255, 90, 60, 0.9); color: #fff; }
.tbtn.small { width: 52px; height: 52px; font-size: 11px; }
.tbtn.mini { width: 42px; height: 42px; font-size: 15px; }

/* 顶栏 */
#topbar {
  position: absolute; z-index: 23; top: calc(var(--safet) + 8px);
  right: calc(var(--safer) + 10px);
  display: flex; gap: 8px; pointer-events: none;
}
#topbar .tbtn { pointer-events: auto; }

#hud-hint {
  position: absolute; z-index: 23;
  top: calc(var(--safet) + 10px); left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.55); color: var(--amber);
  font-size: 12px; padding: 6px 14px; border-radius: 14px;
  pointer-events: none;
}

/* ============ 面板 ============ */
.panel {
  width: min(560px, 92vw); max-height: 88vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 18px; font-weight: 800; color: var(--amber); margin-bottom: 14px;
}
.pbtn {
  display: block; width: 100%; margin: 10px 0; padding: 13px;
  font-size: 15px; border-radius: 10px;
  background: var(--bg2); color: var(--txt); border: 1px solid var(--line);
  text-align: left;
}
.pbtn:active { border-color: var(--amber); color: var(--amber); }
.pbtn.close { width: auto; margin: 0; padding: 6px 14px; }
.pbtn.warn { color: var(--red); }

/* 购买菜单 */
.buy-panel { width: min(680px, 94vw); }
.buy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.buy-item {
  border: 1px solid var(--line); border-radius: 9px;
  background: linear-gradient(160deg, #171d25, #10141a);
  padding: 10px 6px; text-align: center;
  font-size: 12px; color: var(--txt);
}
.buy-item .bname { font-weight: 700; font-size: 12px; }
.buy-item .bprice { color: var(--amber); font-size: 11px; margin-top: 3px; }
.buy-item:active { border-color: var(--green); background: rgba(87,160,90,0.18); }
.buy-cat {
  grid-column: 1 / -1; font-size: 12px; color: var(--txt-dim);
  letter-spacing: 0.15em; margin: 8px 0 0;
}

/* 设置 */
.settings-body label {
  display: block; margin: 14px 0; font-size: 14px; color: var(--txt);
}
.settings-body input[type=range] { width: 100%; margin-top: 6px; accent-color: var(--amber); }
.settings-body .chk { display: flex; align-items: center; gap: 10px; }
.settings-body .chk input { width: 18px; height: 18px; accent-color: var(--amber); }
.settings-body span { color: var(--amber); font-weight: 700; }

/* 文本输入 */
#textinput {
  position: absolute; z-index: 40;
  left: 0; right: 0; bottom: calc(var(--safeb) + 12px);
  display: flex; gap: 8px; padding: 10px;
  background: rgba(10, 12, 16, 0.92);
  border-top: 1px solid var(--line);
  align-items: center;
}
#textinput-title {
  position: absolute; top: -34px; left: 12px;
  font-size: 12px; color: var(--amber); background: rgba(10,12,16,0.85);
  padding: 3px 10px; border-radius: 8px;
}
#textinput-field {
  flex: 1; min-width: 0; height: 42px;
  background: #171d25; border: 1px solid var(--line); border-radius: 8px;
  color: var(--txt); font-size: 15px; padding: 0 12px; outline: none;
}
#textinput-field:focus { border-color: var(--amber); }

/* 提示 */
#toast {
  position: absolute; z-index: 50; left: 50%; top: calc(var(--safet) + 20%);
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8); color: var(--amber);
  font-size: 14px; padding: 10px 22px; border-radius: 20px;
  pointer-events: none; white-space: nowrap;
}

/* 控制台 */
#console {
  position: absolute; z-index: 45; left: 0; right: 0; bottom: 0;
  height: 38vh; background: rgba(8, 10, 13, 0.96);
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column;
}
#console-head {
  padding: 8px 14px; font-size: 13px; color: var(--amber);
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between;
}
#console-head button {
  background: none; border: 0; color: var(--txt-dim); font-size: 14px;
}
#console-body {
  flex: 1; overflow-y: auto; padding: 10px 14px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px; color: #9aa4b0; white-space: pre-wrap; word-break: break-all;
}

/* FPS */
#fps {
  position: absolute; z-index: 24; top: calc(var(--safet) + 8px); left: 10px;
  font-family: ui-monospace, monospace; font-size: 12px; color: #6fdd76;
  text-shadow: 0 1px 2px #000; pointer-events: none;
}

.about-body p { font-size: 13.5px; line-height: 1.7; color: var(--txt); }
.about-body b { color: var(--amber); }

/* ============ 竖屏提示 ============ */
#rotate-hint {
  position: absolute; inset: 0; z-index: 60;
  background: rgba(5,6,8,0.96); color: var(--txt);
  display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; text-align: center;
}
#rotate-hint .icon { font-size: 52px; animation: rot 1.6s ease-in-out infinite; }
@keyframes rot { 0%,100% { transform: rotate(0); } 50% { transform: rotate(90deg); } }
#rotate-hint .txt { font-size: 15px; color: var(--txt-dim); max-width: 260px; line-height: 1.6; }
#rotate-hint button {
  padding: 10px 30px; background: var(--amber); color: #101317;
  border: 0; border-radius: 8px; font-size: 15px; font-weight: 700;
}

@media (orientation: landscape) {
  #btns { right: calc(var(--safer) + 14px); bottom: calc(var(--safeb) + 26px); }
  .tbtn { margin-left: 10px; }
}
@media (orientation: portrait) {
  #btns { right: 10px; bottom: calc(var(--safeb) + 70px); }
  .tbtn { margin-left: 6px; }
  #zone-move { width: 46%; }
  #zone-look { width: 54%; }
}
