/* 机甲狗斗场 — 2D 基础层样式
   配色对比度均已用 WCAG 相对亮度公式计算校验（见任务报告表），
   全部文字/背景组合 >= 4.5:1（含 hover / disabled / chip 态）。
*/

:root {
  --bg: #0c1220;
  --bg-panel: #121a2c;
  --bg-card: #16203a;
  --bg-card-hover: #1c2947;
  --bg-well: #0f1626;
  --bg-scrim: rgba(9, 13, 24, 0.88);

  --border: rgba(61, 219, 255, 0.28);
  --border-orange: rgba(255, 138, 61, 0.28);
  --border-soft: rgba(255, 255, 255, 0.08);

  --text: #eef2fa;
  --text-muted: #c3ccdc;

  --cyan: #3ddbff;
  --orange: #ff8a3d;
  --red: #ff6b6b;
  --green: #4ade80;
  --gold: #facc15;

  --radius: 10px;
  --radius-sm: 6px;
  --header-h: min(52px, 9vh);

  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button {
  font-family: inherit;
  letter-spacing: inherit;
}

/* ---------------------------------------------------------------- app shell */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 min(16px, 3vw);
  background: linear-gradient(180deg, var(--bg-panel), var(--bg));
  border-bottom: 1px solid var(--border-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: min(16px, 4vw);
  color: var(--text);
  letter-spacing: 0.08em;
}

.brand-mark {
  color: var(--cyan);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--bg-card);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border);
}

.icon-btn:focus-visible,
button:focus-visible,
.ladder-item:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- panels */

#panels {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

.panel {
  display: none;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: min(20px, 3vh) min(24px, 4vw);
  overflow: hidden;
}

.panel.active {
  display: flex;
}

.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: min(14px, 2vh);
}

.panel-head h2 {
  margin: 0;
  font-size: min(20px, 5vw);
  letter-spacing: 0.06em;
}

.panel-foot {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  margin-top: min(14px, 2vh);
}

/* ---------------------------------------------------------------- buttons */

.btn {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--bg-card);
  color: var(--text);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease);
}

.btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  cursor: not-allowed;
  color: var(--text-muted);
  border-style: dashed;
  border-color: var(--border-soft);
}

.btn-primary {
  background: rgba(61, 219, 255, 0.14);
  border-color: var(--cyan);
  color: var(--text);
}

.btn-primary:hover:not(:disabled) {
  background: rgba(61, 219, 255, 0.24);
  border-color: var(--cyan);
}

.btn-orange {
  background: rgba(255, 138, 61, 0.14);
  border-color: var(--orange);
}

.btn-orange:hover:not(:disabled) {
  background: rgba(255, 138, 61, 0.24);
  border-color: var(--orange);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-soft);
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-card);
  color: var(--text);
}

/* ---------------------------------------------------------------- chips */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
}

/* ================================================================== 标题屏 */

#panel-title {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.title-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: min(10px, 2vh);
}

.title-glyph {
  font-size: min(56px, 12vh, 14vw);
  filter: drop-shadow(0 0 18px rgba(61, 219, 255, 0.45));
}

.title-name {
  margin: 0;
  font-size: min(40px, 8vh, 9vw);
  font-weight: 800;
  letter-spacing: 0.12em;
  background: linear-gradient(90deg, var(--cyan), var(--orange));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-sub {
  margin: 0 0 min(18px, 3vh);
  color: var(--text-muted);
  font-size: min(15px, 3.6vw);
  letter-spacing: 0.06em;
}

.title-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.title-actions .btn {
  min-width: 120px;
  padding: 12px 20px;
  font-size: 15px;
}

/* ================================================================== 机库 */

.parts-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--gold);
  font-weight: 700;
  font-size: 14px;
}

.hangar-grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  padding-bottom: 4px;
}

.mech-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}

.mech-card.is-active {
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px var(--cyan) inset, 0 0 16px rgba(61, 219, 255, 0.18);
}

.mech-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.mech-name {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.mech-title {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
}

.mech-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-row {
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.stat-label {
  color: var(--text-muted);
}

.pips {
  display: flex;
  gap: 3px;
}

.pip {
  width: 12px;
  height: 8px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-soft);
}

.pip.filled {
  background: var(--cyan);
  border-color: var(--cyan);
}

.stat-lvl {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.btn-upgrade {
  padding: 4px 8px;
  font-size: 11px;
  min-width: 56px;
}

.mech-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mech-card.locked {
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 150px;
  color: var(--text-muted);
}

.locked-glyph {
  font-size: 24px;
  margin-bottom: 4px;
}

.locked-hint {
  font-size: 11px;
  color: var(--text-muted);
}

/* ================================================================== 擂台 */

#panel-arena {
  padding-bottom: min(12px, 2vh);
}

.arena-select {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.ladder-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}

.ladder-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-size: 13px;
}

.ladder-item:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border);
}

.ladder-item:disabled {
  cursor: not-allowed;
  color: var(--text-muted);
  border-style: dashed;
}

.ladder-item-name {
  font-weight: 700;
}

.ladder-item-mech {
  color: var(--text-muted);
  font-size: 12px;
}

.ladder-item-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.arena-battle {
  display: none;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  gap: min(10px, 1.6vh);
}

.arena-battle.active {
  display: flex;
}

.arena-topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.opp-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.round-counter {
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* 回合数逼近判定线（≥25/30）：提前预警，别让玩家死磕到超时才发现 */
.round-counter--warn {
  color: var(--orange);
  font-weight: 700;
}

.tell-strip {
  flex: 0 0 auto;
  display: none;
  align-items: center;
  gap: 8px;
  background: rgba(250, 204, 21, 0.12);
  border: 1px solid rgba(250, 204, 21, 0.4);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text);
}

.tell-strip.show {
  display: flex;
}

.arena-stage {
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(20vh, 150px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: min(18px, 4vw);
}

.mech-slot {
  flex: 1 1 0;
  max-width: 220px;
  height: 100%;
  display: flex;
}

.mech-slot-card {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
}

#slot-p .mech-slot-card {
  border-color: var(--border);
}

#slot-e .mech-slot-card {
  border-color: var(--border-orange);
}

.slot-glyph {
  font-size: min(30px, 5vh);
}

.slot-name {
  font-size: 13px;
  font-weight: 700;
}

.slot-style {
  font-size: 11px;
  color: var(--text-muted);
}

.vs-marker {
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 700;
}

/* 3D 演出层挂载点：app.js 探测成功后动态创建、插入 .arena-stage；
   失败前 2D 卡片一直是唯一可见内容，零布局跳变。 */
.stage-3d {
  display: none;
  flex: 1 1 auto;
  align-self: stretch;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0c1220;
}

.stage-3d canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.arena-stage.has-3d {
  /* 固定尺寸而非可协商的 flex 1：3D 画布不能像 2D 卡片一样被日志内容挤到 0——
     flex-shrink:0 + min-height 等于 max-height，把「让位」的角色完全留给
     自带 overflow-y:auto 的 .arena-log。 */
  flex: 0 0 min(34vh, 260px);
  min-height: min(34vh, 260px);
  max-height: min(34vh, 260px);
}

.arena-stage.has-3d .mech-slot,
.arena-stage.has-3d .vs-marker {
  display: none;
}

.arena-stage.has-3d .stage-3d {
  display: flex;
  /* 短视口下 stage 只有 150px 高却铺满整行宽度，宽高比会被拉到 8:1+，机甲取景再怎么
     调也会被巨量两侧死空间衬得很小；封个宽度上限，讲台在视觉上更像"一块台子"而不是
     一条缝，.arena-stage 自身的 justify-content:center 负责把它居中。 */
  max-width: min(760px, 94%);
}

.arena-hpbars {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hp-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hp-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.hp-name {
  font-weight: 700;
  color: var(--text);
}

.hp-value {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.hp-track {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-well);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--cyan);
  transition: width 0.3s var(--ease);
}

.hp-fill.side-e {
  background: var(--orange);
}

.hp-fill.low {
  background: var(--red);
}

.energy-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.energy-pips {
  display: flex;
  gap: 3px;
}

.energy-pip {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-soft);
}

.energy-pip.filled {
  background: var(--cyan);
  border-color: var(--cyan);
}

.energy-pip.filled.side-e {
  background: var(--orange);
  border-color: var(--orange);
}

.arena-log {
  flex: 1 1 auto;
  min-height: 44px;
  overflow-y: auto;
  background: var(--bg-well);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
}

.log-line {
  color: var(--text);
  opacity: 0;
  transform: translateY(4px);
  animation: log-in 0.22s var(--ease) forwards;
}

@keyframes log-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.log-line--good {
  color: var(--green);
}

.log-line--bad {
  color: var(--orange);
}

.log-line--ko {
  color: var(--gold);
  font-weight: 700;
}

.log-line--info {
  color: var(--text-muted);
}

.arena-actions {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.action-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 4px 6px;
  cursor: pointer;
  min-height: 64px;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}

.action-btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--cyan);
}

.action-btn:disabled {
  cursor: not-allowed;
  border-style: dashed;
}

.action-icon {
  font-size: 18px;
}

.action-name {
  font-size: 12.5px;
  font-weight: 700;
}

.action-sub {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.25;
}

.action-btn:disabled .action-sub {
  color: var(--text-muted);
}

.action-key {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 9px;
  color: var(--text-muted);
  border: 1px solid var(--border-soft);
  border-radius: 3px;
  padding: 0 3px;
}

/* ================================================================== 召唤 */

#summon-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}

#summon-panel h2 {
  margin: 0;
  font-size: 20px;
}

#summon-panel p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  max-width: 320px;
}

/* ---------------------------------------------------------------- 星核经济（Task 9） */

.hidden {
  display: none !important;
}

.pouch-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pouch-warn {
  margin: 0;
  color: var(--red);
  font-weight: 700;
  font-size: 13px;
  max-width: 340px;
  line-height: 1.6;
}

.pouch-foot {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.7;
  max-width: 360px;
}

.pouch-foot a {
  color: var(--cyan);
  text-decoration: underline;
}

.pouch-foot a:hover {
  color: var(--text);
}

.pouch-foot b {
  color: var(--gold);
}

.pouch-reveal-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  padding: 14px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--cyan);
  background: rgba(61, 219, 255, 0.1);
  animation: pouch-reveal-in 0.4s var(--ease);
}

.pouch-reveal-card.is-new {
  border-color: var(--gold);
  background: rgba(250, 204, 21, 0.12);
}

.pouch-reveal-glyph {
  font-size: 28px;
}

.pouch-reveal-name {
  font-size: 15px;
  font-weight: 800;
}

.pouch-reveal-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.06em;
}

.pouch-reveal-badge.dup {
  color: var(--text-muted);
}

@keyframes pouch-reveal-in {
  from { opacity: 0; transform: scale(0.85) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

body.reduce-motion .pouch-reveal-card {
  animation: none;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: min(24px, 4vh);
  transform: translateX(-50%) translateY(8px);
  max-width: min(420px, 90vw);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
  z-index: 80;
}

#toast.on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ================================================================== overlays */

.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.overlay.hidden {
  display: none;
}

.overlay-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: min(24px, 4vh) min(24px, 5vw);
  max-width: min(420px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.overlay-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.overlay-body {
  margin: 0;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.6;
}

.overlay-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tut-dots {
  display: flex;
  gap: 6px;
}

.tut-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
}

.tut-dot.active {
  background: var(--cyan);
}

.result-title {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.result-title.win {
  color: var(--green);
}

.result-title.lose {
  color: var(--red);
}

.result-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--text);
}

.result-row.callout {
  color: var(--gold);
  font-weight: 700;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex: 0 0 auto;
}

.toggle input {
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  position: absolute;
  inset: 0;
  z-index: 1;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.15s var(--ease), background 0.15s var(--ease);
}

.toggle input:checked ~ .toggle-track {
  background: rgba(61, 219, 255, 0.22);
  border-color: var(--cyan);
}

.toggle input:checked ~ .toggle-track .toggle-thumb {
  transform: translateX(18px);
  background: var(--cyan);
}

/* reduce-motion: Task 7 消费此 body class 关停 3D 动效；2D 层顺带关闭战报打字与过场动画 */
body.reduce-motion .log-line {
  animation: none;
  opacity: 1;
  transform: none;
}

body.reduce-motion * {
  transition-duration: 0.01ms !important;
}

/* ================================================================== 响应式 */

@media (max-width: 480px) {
  .arena-actions {
    gap: 5px;
  }
  .action-sub {
    display: none;
  }
  .action-btn {
    min-height: 52px;
    padding: 6px 2px 4px;
  }
  .action-icon {
    font-size: 16px;
  }
  .action-name {
    font-size: 11px;
  }
  .title-actions .btn {
    min-width: 100px;
  }
}

@media (max-height: 620px) {
  .arena-stage {
    max-height: 100px;
  }
  .arena-stage.has-3d {
    flex: 0 0 150px;
    min-height: 150px;
    max-height: 150px;
  }
  .slot-glyph {
    font-size: 22px;
  }
}
