/* ===== 全局 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", sans-serif;
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  color: #e0e0e0; min-height: 100vh; padding-bottom: 40px;
  -webkit-tap-highlight-color: transparent;
}

/* ===== 告警条 ===== */
.alert-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 999;
  background: #d32f2f; color: #fff; text-align: center;
  padding: 8px 12px; font-size: 13px;
}
.hidden { display: none !important; }

/* ===== 提示弹窗 ===== */
.tooltip-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.6); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.tooltip-box {
  background: #1e2a45; border: 1px solid #3a5a8a; border-radius: 12px;
  padding: 20px; max-width: 360px; width: 90%; color: #ddd;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.tooltip-title { font-size: 16px; font-weight: bold; color: #ffd54f; margin-bottom: 10px; }
.tooltip-body { font-size: 13px; line-height: 1.8; margin-bottom: 14px; }

/* ===== 可点击提示 ===== */
.tip-click { cursor: pointer; border-bottom: 1px dashed rgba(255,255,255,.3); }

/* ===== 头部 ===== */
header {
  background: linear-gradient(90deg, #0f3460, #1a237e, #533483);
  color: #fff; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}
header h1 { font-size: 18px; letter-spacing: 2px; white-space: nowrap; }
.header-stats { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.header-stats b { color: #ffd54f; }
.header-actions { display: flex; gap: 6px; }

/* ===== 按钮 ===== */
.btn {
  padding: 8px 16px; border: none; border-radius: 8px; cursor: pointer;
  font-size: 13px; background: #3949ab; color: #fff;
  transition: all .2s; touch-action: manipulation;
}
.btn:hover { background: #283593; transform: scale(1.02); }
.btn:active { transform: scale(0.97); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-lg { padding: 12px 28px; font-size: 15px; }
.btn-accent { background: linear-gradient(135deg, #f57c00, #e65100); }
.btn-accent:hover { background: linear-gradient(135deg, #e65100, #bf360c); }
.btn-danger { background: #c62828; }
.btn-danger:hover { background: #b71c1c; }
.btn:disabled { background: #555; cursor: not-allowed; opacity: .6; }
.boost-btn-main { font-size: 18px; padding: 14px 40px; margin: 10px 0; }

/* ===== 进度条 ===== */
.progress-section {
  display: flex; gap: 12px; padding: 8px 16px;
  background: rgba(255,255,255,.05); border-bottom: 1px solid rgba(255,255,255,.08);
}
.progress-item { flex: 1; }
.progress-item label { font-size: 11px; color: #aaa; }
.progress-bar {
  height: 8px; background: rgba(255,255,255,.1); border-radius: 4px;
  overflow: hidden; margin-top: 3px;
}
.progress-fill { height: 100%; border-radius: 4px; transition: width .3s; }
.gold-fill { background: linear-gradient(90deg, #ffd54f, #ff8f00); }
.dia-fill { background: linear-gradient(90deg, #4fc3f7, #0288d1); }

/* ===== 标签导航 ===== */
#tab-nav {
  display: flex; background: rgba(255,255,255,.05);
  border-bottom: 2px solid #3949ab; overflow-x: auto;
}
.tab-btn {
  flex: 1; padding: 10px 8px; border: none; background: transparent; cursor: pointer;
  font-size: 13px; color: #888; border-bottom: 3px solid transparent;
  transition: all .2s; white-space: nowrap; text-align: center;
}
.tab-btn.active { color: #ffd54f; border-bottom-color: #ffd54f; font-weight: bold; }
.tab-btn:hover { color: #fff; }

/* ===== 标签内容 ===== */
.tab-content { display: none; padding: 16px; }
.tab-content.active { display: block; }

/* ===== 马厩 ===== */
.section-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap;
}
.section-header h2 { font-size: 17px; color: #ffd54f; }
.horse-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px;
}

/* ===== 马匹卡片 ===== */
.horse-card {
  background: linear-gradient(135deg, #1e2a45, #162447);
  border-radius: 12px; padding: 14px; cursor: pointer;
  border: 2px solid rgba(255,255,255,.08);
  box-shadow: 0 4px 16px rgba(0,0,0,.3); transition: all .25s;
  position: relative; overflow: hidden;
}
.horse-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.horse-card.selected { border-color: #ffd54f; background: linear-gradient(135deg, #2a1f00, #1e2a45); }
.horse-card .rarity-banner {
  position: absolute; top: 8px; right: 8px;
  padding: 2px 10px; border-radius: 10px; font-size: 11px; font-weight: bold;
}
.rarity-N { background: #616161; color: #ddd; }
.rarity-R { background: #1565c0; color: #fff; }
.rarity-SR { background: #6a1b9a; color: #fff; }
.rarity-SSR { background: linear-gradient(90deg, #ff8f00, #f44336); color: #fff; }
.rarity-UR { background: linear-gradient(90deg, #ffd54f, #ff6f00, #d50000); color: #fff; text-shadow: 0 0 4px rgba(0,0,0,.5); }

/* 2D马匹图示 */
.horse-avatar {
  width: 100%; height: 80px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px; position: relative;
}
.horse-sprite {
  font-size: 56px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.5));
  animation: horseIdle 2s ease-in-out infinite;
}
@keyframes horseIdle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.horse-card.selected .horse-sprite { animation: horseActive 0.6s ease-in-out infinite; }
@keyframes horseActive {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-6px) scale(1.05); }
}

.horse-card h3 { font-size: 14px; color: #ffd54f; margin-bottom: 4px; }
.horse-card .horse-meta { font-size: 11px; color: #999; margin-bottom: 4px; line-height: 1.6; }
.horse-card .horse-score {
  display: inline-block; padding: 2px 10px; border-radius: 8px;
  font-size: 12px; font-weight: bold; margin-bottom: 6px;
}
.score-tier-S { background: #ff8f00; color: #fff; }
.score-tier-A { background: #7b1fa2; color: #fff; }
.score-tier-B { background: #1565c0; color: #fff; }
.score-tier-C { background: #2e7d32; color: #fff; }
.score-tier-D { background: #616161; color: #ddd; }

.horse-card .horse-attrs {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; margin: 6px 0;
}
.horse-card .attr-item {
  text-align: center; font-size: 10px; color: #aaa; cursor: pointer;
  padding: 4px 0; border-radius: 6px; background: rgba(255,255,255,.04);
  transition: background .2s;
}
.horse-card .attr-item:hover { background: rgba(255,255,255,.1); }
.horse-card .attr-val { font-size: 16px; font-weight: bold; color: #4fc3f7; }
.horse-card .horse-extra { font-size: 11px; color: #888; margin-top: 4px; }

.energy-bar {
  height: 6px; background: rgba(255,255,255,.1); border-radius: 3px;
  margin-top: 4px; overflow: hidden;
}
.energy-fill { height: 100%; border-radius: 3px; transition: width .3s; background: #66bb6a; }
.energy-fill.low { background: #ef5350; }

/* ===== 训练 ===== */
.train-layout { display: flex; gap: 16px; flex-wrap: wrap; }
.train-left { flex: 2; min-width: 280px; }
.train-right { flex: 1; min-width: 240px; }
.info-box {
  background: rgba(255,255,255,.06); border-radius: 10px; padding: 14px;
  margin-bottom: 14px; font-size: 13px; line-height: 1.8;
  border: 1px solid rgba(255,255,255,.08);
}
.train-types { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.train-btn { min-width: 80px; }
.hint { font-size: 11px; color: #777; }
.log-box {
  background: rgba(0,0,0,.2); border-radius: 10px; padding: 10px;
  height: 300px; overflow-y: auto; font-size: 12px; line-height: 1.8;
  border: 1px solid rgba(255,255,255,.06);
}
.log-entry { border-bottom: 1px solid rgba(255,255,255,.04); padding: 2px 0; }
.log-success { color: #66bb6a; }
.log-fail { color: #ef5350; }
.log-info { color: #4fc3f7; }

/* ===== 比赛 ===== */
.race-setup { max-width: 600px; }
.race-options {
  display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap;
}
.race-options select {
  padding: 8px 12px; border-radius: 8px; border: 1px solid #3a5a8a;
  background: #1e2a45; color: #ddd; font-size: 13px; flex: 1; min-width: 200px;
}
.track-info-box {
  margin-top: 10px; padding: 10px 14px; background: rgba(255,255,255,.06);
  border-radius: 8px; font-size: 12px; line-height: 1.8; color: #bbb;
  border: 1px solid rgba(255,255,255,.06);
}
.track-tag, .race-track-tag {
  display: inline-block; padding: 2px 10px; border-radius: 6px;
  font-size: 11px; color: #fff; margin-right: 4px;
}
.track-grass { background: #2e7d32; }
.track-mud { background: #5d4037; }
.track-highland { background: #3949ab; }
.track-snow { background: #0288d1; }
.track-desert { background: #e65100; }
.track-night { background: #263238; }
.track-storm { background: #4a148c; }
.track-volcano { background: #b71c1c; }

.race-live { text-align: center; }
.race-hud {
  display: flex; justify-content: center; gap: 14px; margin: 10px 0;
  font-size: 13px; background: rgba(255,255,255,.06); padding: 10px;
  border-radius: 10px; flex-wrap: wrap;
}
.boost-msg {
  font-weight: bold; min-width: 80px; display: block;
  text-align: center; font-size: 14px; margin: 4px 0;
}
.race-track-visual { margin: 10px auto; overflow-x: auto; }
canvas {
  background: linear-gradient(180deg, #1a1a2e, #0f3460);
  border-radius: 10px; display: block; margin: 0 auto; max-width: 100%;
}
.race-result { max-width: 100%; overflow-x: auto; }
.race-result table {
  width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 12px;
}
.race-result th, .race-result td {
  padding: 6px 8px; border: 1px solid rgba(255,255,255,.1); text-align: center;
}
.race-result th { background: rgba(255,255,255,.08); color: #ffd54f; }
.race-result tr.player-row { background: rgba(255,213,79,.1); color: #ffd54f; font-weight: bold; }
.stage-table { margin: 12px 0; }
.stage-table th { background: rgba(79,195,247,.1); color: #4fc3f7; }
.race-time-col { color: #4fc3f7; font-weight: bold; }
.time-best { color: #66bb6a; font-weight: bold; }

/* ===== 建筑 ===== */
.building-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px;
}
.building-card {
  background: linear-gradient(135deg, #1e2a45, #162447);
  border-radius: 12px; padding: 18px; text-align: center;
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.building-card h3 { font-size: 15px; color: #ffd54f; margin-bottom: 6px; }
.building-card .blv { font-size: 28px; color: #ff8f00; font-weight: bold; }
.building-card .bdesc { font-size: 12px; color: #999; margin: 6px 0; }
.building-card .bcost { font-size: 13px; color: #ef5350; margin-bottom: 8px; }

/* ===== 帮助 ===== */
.help-section { padding: 10px 16px; }
.help-section details {
  background: rgba(255,255,255,.05); border-radius: 10px;
  padding: 12px 16px; font-size: 13px;
  border: 1px solid rgba(255,255,255,.06);
}
.help-section summary { cursor: pointer; font-weight: bold; color: #ffd54f; }
.help-section p { margin: 4px 0 4px 16px; color: #aaa; }

/* ===== 调试面板 ===== */
.debug-section { padding: 10px 16px; margin-top: 8px; }
.debug-section details {
  background: rgba(198,40,40,.1); border-radius: 10px;
  padding: 12px 16px; font-size: 13px;
  border: 1px solid rgba(198,40,40,.2);
}
.debug-section summary { cursor: pointer; font-weight: bold; color: #ef5350; }
.debug-grid { display: flex; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.debug-grid label { display: flex; flex-direction: column; font-size: 12px; color: #aaa; }
.debug-grid input {
  width: 110px; padding: 5px; margin-top: 3px;
  border: 1px solid #3a5a8a; border-radius: 6px;
  background: #1e2a45; color: #ddd;
}
.debug-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.sim-result { font-size: 12px; color: #ccc; margin-top: 6px; white-space: pre-wrap; }

/* ===== 适性标签 ===== */
.fit-tags { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.fit-tag { font-size: 10px; padding: 1px 6px; border-radius: 3px; color: #fff; }
.fit-S { background: #e65100; }
.fit-A { background: #2e7d32; }
.fit-B { background: #616161; }
.fit-C { background: #37474f; color: #aaa; }

/* ===== 响应式：手机端 ===== */
@media (max-width: 768px) {
  body { min-width: unset; }
  header { padding: 8px 10px; }
  header h1 { font-size: 15px; }
  .header-stats { gap: 8px; font-size: 12px; }
  .tab-btn { font-size: 12px; padding: 8px 4px; }
  .tab-content { padding: 10px; }
  .horse-grid { grid-template-columns: 1fr; }
  .building-grid { grid-template-columns: repeat(2, 1fr); }
  .train-layout { flex-direction: column; }
  .train-left, .train-right { min-width: unset; }
  .race-hud { gap: 8px; font-size: 12px; }
  .boost-btn-main { font-size: 16px; padding: 12px 30px; width: 100%; }
  .race-options { flex-direction: column; }
  .race-options select { width: 100%; }
  .race-result table { font-size: 11px; }
  .race-result th, .race-result td { padding: 4px 3px; }
  .debug-grid { flex-direction: column; }
  .debug-grid input { width: 100%; }
  canvas { height: auto; }
}

@media (max-width: 400px) {
  header h1 { font-size: 13px; letter-spacing: 1px; }
  .header-stats { font-size: 11px; gap: 6px; }
  .building-grid { grid-template-columns: 1fr; }
  .horse-card .horse-attrs { grid-template-columns: repeat(5, 1fr); gap: 2px; }
  .horse-card .attr-val { font-size: 14px; }
}

/* ===== 抽马弹窗 ===== */
.gacha-modal {
  background: #1e2a45; border: 1px solid #3a5a8a; border-radius: 12px;
  padding: 20px; max-width: 720px; width: 95%; color: #ddd;
  box-shadow: 0 8px 32px rgba(0,0,0,.5); max-height: 90vh; overflow-y: auto;
}
.gacha-title { font-size: 16px; font-weight: bold; color: #ffd54f; margin-bottom: 14px; text-align: center; }
.gacha-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.gacha-card {
  background: linear-gradient(135deg, #162447, #1e2a45);
  border-radius: 10px; padding: 12px; text-align: center;
  border: 2px solid rgba(255,255,255,.1); position: relative;
}
.gacha-card h3 { font-size: 14px; margin: 6px 0; }
.gacha-card .horse-meta { font-size: 11px; margin: 4px 0; color: #aaa; }
.gacha-card .horse-attrs { font-size: 11px; margin: 6px 0; }
.gacha-attr { display: inline-block; margin: 1px 3px; padding: 1px 4px; background: rgba(255,255,255,.06); border-radius: 3px; }
.gacha-tier { font-size: 18px; font-weight: bold; }
.gacha-price { font-size: 13px; color: #ffd54f; margin: 8px 0 6px; }
.rarity-border-UR { border-color: #d50000 !important; box-shadow: 0 0 12px rgba(213,0,0,.4); }
.rarity-border-SSR { border-color: #ff8f00 !important; box-shadow: 0 0 8px rgba(255,143,0,.3); }
.rarity-border-SR { border-color: #6a1b9a !important; box-shadow: 0 0 6px rgba(106,27,154,.3); }
.rarity-border-R { border-color: #1565c0 !important; }
.rarity-border-N { border-color: #616161 !important; }

/* ===== 训练按钮改版 ===== */
.train-btn { min-width: 120px; text-align: center; line-height: 1.4; padding: 8px 12px; }
.train-btn small { font-size: 10px; color: #aaa; display: block; margin-top: 2px; }
.train-btn-diamond { background: linear-gradient(135deg, #1a237e, #4a148c) !important; border-color: #ce93d8 !important; }
.train-btn-diamond:hover { background: linear-gradient(135deg, #283593, #6a1b9a) !important; }

@media (max-width: 500px) {
  .gacha-grid { grid-template-columns: 1fr; }
  .train-types { flex-direction: column; }
  .train-btn { min-width: auto; width: 100%; }
}
