/* AI 塔防实验室 - 扁平卡通风格界面 */
:root {
  --bg: #eaf6e1;
  --bg2: #dcefca;
  --panel: #fdfff8;
  --ink: #38432c;
  --muted: #7c8a66;
  --line: #cfe6b4;
  --brand: #f0a13c;
  --brand-d: #d8842a;
  --green: #6fc44b;
  --red: #e2584d;
  --blue: #4bb3d6;
  --purple: #9b6bd6;
  --shadow: 0 3px 0 rgba(90, 74, 50, .16), 0 8px 20px rgba(90, 74, 50, .10);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: linear-gradient(160deg, #eef7e3 0%, #dcefca 100%);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 14px 16px 28px;
}

/* ---------- 顶栏 ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow);
}

.brand {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--brand);
  border: 2px solid #b96f1f;
  position: relative;
}
.logo::after {
  content: "";
  position: absolute;
  left: 3px; top: 3px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #fff6e2;
}

.stats { display: flex; gap: 10px; flex: 1; flex-wrap: wrap; }
.stat {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 5px 10px;
  font-size: 15px;
  font-weight: 700;
  min-width: 78px;
}
.stat b { font-size: 16px; }
.ic { width: 18px; height: 18px; }
.ic.heart { fill: var(--red); stroke: #a93b32; stroke-width: 1.6; }
.ic.coin { fill: #f5c53d; stroke: #c99a17; stroke-width: 1.6; }
.ic.coin .in { fill: none; stroke: #c99a17; stroke-width: 1.6; }
.ic.wave { fill: none; stroke: var(--blue); stroke-width: 2; stroke-linecap: round; }
.ic.star { fill: #f5c53d; stroke: #c99a17; stroke-width: 1.6; stroke-linejoin: round; }
.ic.flag { fill: none; stroke: var(--green); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.tools { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 按钮 ---------- */
.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: transform .06s ease, filter .12s ease;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--brand);
  border-color: #c87b23;
  color: #fff;
  box-shadow: 0 3px 0 #c87b23;
}
.btn.primary:disabled {
  background: #d9d0bb; border-color: #c3b9a3; color: #8b8172;
  box-shadow: none; cursor: not-allowed;
}
.btn.ok { background: var(--green); border-color: #4e9c33; color: #fff; box-shadow: 0 3px 0 #4e9c33; }
.btn.danger { background: var(--red); border-color: #b53d34; color: #fff; box-shadow: 0 3px 0 #b53d34; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.on { background: var(--brand); border-color: #c87b23; color: #fff; }

/* ---------- 主区 ---------- */
#main { display: flex; gap: 16px; margin-top: 14px; align-items: flex-start; }
#left { flex: 1 1 auto; min-width: 0; max-width: 900px; }

#board {
  position: relative;
  background: #d6efb4;
  border: 3px solid #a9d27e;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  line-height: 0;
}
#game { display: block; width: 100%; height: auto; touch-action: none; cursor: pointer; }

#boardBar {
  display: flex; align-items: center; gap: 12px;
  margin-top: 10px;
}
#waveHint { font-size: 14px; color: var(--muted); font-weight: 600; }

/* ---------- 覆盖层 ---------- */
.overlay {
  position: absolute; inset: 0;
  background: rgba(40, 33, 24, .55);
  display: flex; align-items: center; justify-content: center;
  line-height: 1.5;
  z-index: 5;
}
.overlay.hidden { display: none; }
.ovcard {
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: 18px;
  padding: 22px 26px;
  width: min(560px, 88%);
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.agehint {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: #7a6c55;
  background: var(--bg2);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 4px;
}
.ovcard h2 { margin: 0 0 6px; font-size: 26px; }
.ovcard p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.ovbtns { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.levels { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.lvbtn {
  font-family: inherit;
  cursor: pointer;
  background: var(--bg);
  border: 3px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  width: 140px;
  text-align: left;
  transition: transform .08s ease;
}
.lvbtn:hover { transform: translateY(-2px); border-color: var(--brand); }
.lvbtn .lvname { font-weight: 800; font-size: 15px; }
.lvbtn .lvmeta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.lvbtn.wide { width: 100%; max-width: 430px; text-align: center; }

/* 玩家身份 / 记录 */
.ovplayer { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.ovplayer input {
  font-family: inherit; font-size: 13px; padding: 5px 10px;
  border: 2px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); width: 140px; text-align: center;
}
.ovplayer input:focus { outline: none; border-color: var(--brand); }
.pshint { font-size: 11.5px; color: var(--muted); }
.tag { font-size: 11.5px; font-weight: 800; color: #fff; background: var(--green); border-radius: 6px; padding: 2px 8px; }
.rec { font-size: 13px; font-weight: 700; color: var(--ink); }
.ovrec { width: 100%; font-size: 12.5px; color: var(--muted); font-weight: 600; text-align: center; margin-top: 2px; }

/* ---------- 侧栏 ---------- */
#sidebar {
  width: 306px;
  flex: 0 0 306px;
  display: flex; flex-direction: column; gap: 12px;
}
.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
.ptitle {
  font-size: 13px; font-weight: 800; color: var(--muted);
  letter-spacing: 1px; margin-bottom: 8px;
}

.shop { display: flex; flex-direction: column; gap: 8px; }
.card {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 11px;
  padding: 7px 9px;
  transition: transform .06s ease, border-color .12s ease;
}
.card:hover { border-color: var(--brand); }
.card.active { border-color: var(--brand); background: #fdeed6; }
.card.poor { opacity: .55; }
.cico {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 9px;
  background: #fff;
  border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.cico svg { width: 28px; height: 28px; }
.cmeta { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.cname { display: block; font-weight: 800; font-size: 14px; }
.cdesc { display: block; font-size: 11.5px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cprice {
  font-weight: 800; font-size: 14px; color: #a97f22;
  background: #fbe9c2; border-radius: 8px; padding: 3px 7px;
}

.info-empty { font-size: 13px; color: var(--muted); padding: 6px 2px; }
.tinfo { font-size: 13px; }
.tinfo .row {
  display: flex; justify-content: space-between;
  padding: 3px 0; border-bottom: 1px dashed var(--line);
}
.tinfo .row:last-child { border-bottom: 0; }
.tinfo .k { color: var(--muted); }
.tinfo .v { font-weight: 700; }
.tinfo .up { color: #4e9c33; }
.tinfo .head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tinfo .head .nm { font-weight: 800; font-size: 15px; }
.tinfo .head .lv {
  font-size: 11px; font-weight: 800; color: #fff;
  background: var(--brand); border-radius: 6px; padding: 2px 6px;
}
.tinfo .acts { display: flex; gap: 8px; margin-top: 10px; }
.tinfo .acts .btn { flex: 1; padding: 7px 6px; font-size: 13px; }

.preview { display: flex; flex-wrap: wrap; gap: 6px; }
.pv {
  display: flex; align-items: center; gap: 5px;
  background: var(--bg); border: 2px solid var(--line);
  border-radius: 9px; padding: 4px 8px; font-size: 12px; font-weight: 700;
}
.pv .dot { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid rgba(0,0,0,.18); }

.tips ul { margin: 0; padding-left: 18px; }
.tips li { font-size: 12.5px; color: var(--muted); line-height: 1.8; }

/* ---------- 免责声明 ---------- */
#disclaimer {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}
.dline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.agebadge {
  font-size: 12px; font-weight: 800; color: #fff;
  background: var(--green); border-radius: 8px; padding: 3px 9px;
  white-space: nowrap;
}
.dtech { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.dnote { margin: 8px 0 0; font-size: 12px; color: var(--muted); line-height: 1.7; }

/* ---------- 响应式 ---------- */
@media (max-width: 1000px) {
  #main { flex-direction: column; }
  #sidebar { width: 100%; flex: 1 1 auto; flex-direction: row; flex-wrap: wrap; }
  #sidebar .panel { flex: 1 1 260px; }
  .tips { display: none; }
}

@media (max-width: 620px) {
  #app { padding: 10px 10px 20px; }
  #topbar { gap: 10px; padding: 8px 10px; }
  .brand { font-size: 16px; }
  .stat { min-width: 62px; padding: 4px 8px; font-size: 14px; }
  .stat b { font-size: 14px; }
  .btn { padding: 7px 10px; font-size: 13px; }
  #boardBar { flex-wrap: wrap; gap: 8px; }
  #btnWave { flex: 1 1 100%; }
  .ovcard { padding: 16px 16px; }
  .ovcard h2 { font-size: 21px; }
  .lvbtn { width: 100%; }
  .dtech { font-size: 11.5px; }
}

/* ---------- 竖屏旋转提示 ---------- */
#rotateTip {
  position: fixed; inset: 0; z-index: 99;
  display: none;
  align-items: center; justify-content: center; text-align: center;
  background: linear-gradient(160deg, #eef7e3, #cfe6a8);
  color: #38432c; padding: 24px;
}
#rotateTip .box { max-width: 320px; }
#rotateTip .ico {
  width: 34px; height: 56px; margin: 0 auto 14px;
  border: 4px solid #6f9a3f; border-radius: 9px; position: relative;
  animation: rot 2s ease-in-out infinite;
}
#rotateTip .ico::after {
  content: ""; position: absolute; left: 50%; top: 7px; transform: translateX(-50%);
  width: 14px; height: 3px; border-radius: 2px; background: #6f9a3f;
}
#rotateTip h3 { font-size: 20px; margin: 0 0 8px; }
#rotateTip p { font-size: 14px; color: #6f7d58; line-height: 1.7; margin: 0; }
@keyframes rot { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(90deg); } }

/* 小屏竖屏时提示横屏游玩，但允许用户手动跳过 */
@media (max-width: 920px) and (orientation: portrait) {
  #rotateTip { display: flex; }
  html.portrait-ok #rotateTip { display: none !important; }
}
.portrait-btn {
  margin-top: 18px;
  background: transparent;
  border: 1.5px solid #6f9a3f;
  color: #4a6a2a;
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 700;
}
.portrait-btn:active { background: rgba(111, 154, 63, .14); }

/* ---------- Toast 提示 ---------- */
#toast {
  position: fixed; left: 50%; bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(40, 48, 30, .92); color: #fff;
  font-size: 14px; font-weight: 700;
  padding: 10px 18px; border-radius: 999px; z-index: 120;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 掉落奖励横幅 ---------- */
#rewardFeed {
  position: absolute; top: 12px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; z-index: 60; pointer-events: none; width: max-content;
}
.reward-item {
  display: flex; align-items: center; gap: 7px;
  background: rgba(40, 48, 30, .92); color: #fff;
  font-size: 13px; font-weight: 800;
  padding: 7px 15px; border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, .22);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  animation: rewardIn .3s cubic-bezier(.2, .9, .3, 1.35) both;
  transition: opacity .4s ease, transform .4s ease;
}
.reward-item.out { opacity: 0; transform: translateY(-12px) scale(.9); }
.reward-item .rico { width: 17px; height: 17px; flex: 0 0 auto; }
.reward-life { background: rgba(34, 110, 48, .94); border-color: rgba(180, 255, 190, .45); }
.reward-gold { background: rgba(151, 104, 14, .94); border-color: rgba(255, 215, 94, .55); }
.reward-tower { background: rgba(85, 52, 135, .94); border-color: rgba(216, 180, 254, .5); }
@keyframes rewardIn {
  from { opacity: 0; transform: translateY(-16px) scale(.82); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- 快捷武器盘（点空地弹出） ---------- */
#quickBar {
  position: absolute; left: 50%; top: 0;
  transform: translate(-50%, -100%);
  display: none; gap: 6px; z-index: 70;
  background: rgba(40, 48, 30, .95);
  padding: 7px; border-radius: 13px;
  border: 2px solid rgba(255, 255, 255, .22);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .32);
}
#quickBar.show { display: flex; }
#quickBar .qbtn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: rgba(255, 255, 255, .08);
  border: 1.5px solid rgba(255, 255, 255, .25);
  border-radius: 10px;
  padding: 5px 8px 4px;
  cursor: pointer; min-width: 48px;
}
#quickBar .qbtn:active { background: rgba(255, 255, 255, .24); }
#quickBar .qbtn .qico { width: 27px; height: 27px; display: block; }
#quickBar .qbtn .qico svg { width: 100%; height: 100%; display: block; }
#quickBar .qbtn .qprice { font-size: 11px; font-weight: 800; color: #ffd75e; }
#quickBar .qbtn.poor { opacity: .45; }
#quickBar .qbtn.capped { opacity: .5; }
#quickBar .qbtn.capped .qprice { color: #b9bdb6; }

/* 商店锁定的塔 */
.card.locked { opacity: .45; filter: grayscale(.55); }
.card.capped { opacity: .55; filter: grayscale(.35); }

/* ---------- 升级/卖出确认框（点塔弹出） ---------- */
#confirmBar {
  position: absolute; left: 50%; top: 0;
  transform: translate(-50%, -100%);
  display: none; align-items: center; gap: 8px; z-index: 70;
  background: rgba(40, 48, 30, .95);
  padding: 8px 10px 8px 14px; border-radius: 999px;
  border: 2px solid rgba(255, 215, 94, .4);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .32);
}
#confirmBar.show { display: flex; }
#confirmBar .ctext { font-size: 13px; font-weight: 800; color: #fff; white-space: nowrap; }
#confirmBar .cbtn {
  border: none; border-radius: 999px;
  font-size: 12.5px; font-weight: 800;
  padding: 6px 14px; cursor: pointer;
}
#confirmBar .cbtn.ok { background: #ffd75e; color: #5a4405; }
#confirmBar .cbtn.ok:active { background: #eec344; }
#confirmBar .cbtn.sell { background: rgba(226, 88, 77, .92); color: #fff; }
#confirmBar .cbtn.sell:active { background: #c96b60; }
#confirmBar .cbtn.no { background: rgba(255, 255, 255, .16); color: #fff; }
#confirmBar .cbtn.no:active { background: rgba(255, 255, 255, .3); }
