:root {
  --bg-dark: #141826;
  --panel-bg: #1e2438;
  --card-bg: #fffdf5;
  --ink: #1a1c2c;
  --muted: #5a637a;
  --gold: #f5b82e;
  --gold-dark: #c9830a;
  --red: #e54b4b;
  --green: #2ebd6b;
  --blue: #3b82f6;
  --left-bg: #0284c7;
  --right-bg: #ea580c;
  --both-bg: #16a34a;
  --border: #1a1c2c;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  overflow: hidden;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
}

/* 顶部 HUD */
.hud-bar {
  height: 50px;
  padding: 0 16px;
  background: #101420;
  border-bottom: 3px solid #2c3554;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  border: 2px solid #000;
  box-shadow: 0 2px 0 #000;
}

.badge-level {
  background: #3b82f6;
  color: #fff;
}

.badge-coins {
  background: #f5b82e;
  color: #1a1c2c;
}

.badge-progress {
  background: #2b3450;
  color: #e6ecff;
}

.metric {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: #a9b8dc;
  background: #1b2236;
  padding: 4px 9px;
  border-radius: 5px;
  border: 1px solid #323e61;
}

.metric-pose {
  color: #7bf0a8;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-icon {
  background: #232c45;
  color: #fff;
  border: 2px solid #000;
  box-shadow: 0 2px 0 #000;
  border-radius: 6px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
}

.btn-icon:hover {
  background: #313d60;
}

/* 主舞台 */
.stage-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d111a;
  overflow: hidden;
}

#game-canvas {
  width: 100%;
  height: 100%;
  max-width: calc((100vh - 50px) * 16 / 9);
  max-height: calc(100vw * 9 / 16);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-left: 3px solid #000;
  border-right: 3px solid #000;
  background: #5c94fc;
}

/* 2-3米外清晰可读：超大字指令条 + 左/右强提示徽章 */
.action-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  min-width: min(520px, 90%);
  max-width: 92%;
  background: rgba(15, 20, 34, 0.94);
  border: 5px solid var(--gold);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.55);
  border-radius: 16px;
  padding: 14px 28px 16px;
  text-align: center;
  pointer-events: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
  z-index: 10;
}

.action-banner.danger {
  border-color: #ff4d4f;
  background: rgba(130, 16, 16, 0.96);
  animation: pulseBanner 0.42s infinite alternate;
}

.action-banner.success {
  border-color: #34d399;
  background: rgba(12, 54, 42, 0.94);
}

.action-banner.side-left {
  border-color: #38bdf8;
}

.action-banner.side-right {
  border-color: #fb923c;
}

@keyframes pulseBanner {
  from { transform: translateX(-50%) scale(1); }
  to { transform: translateX(-50%) scale(1.035); }
}

.action-header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.side-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 18px;
  border-radius: 12px;
  font-size: clamp(24px, 3.4vw, 42px);
  font-weight: 950;
  letter-spacing: 1px;
  color: #fff;
  border: 3px solid #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.55);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.7);
  line-height: 1.1;
  flex-shrink: 0;
}

.side-badge.left {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
}

.side-badge.right {
  background: linear-gradient(135deg, #f97316, #dc2626);
}

.side-badge.both {
  background: linear-gradient(135deg, #22c55e, #15803d);
}

.side-badge.warn {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
}

.action-title {
  font-size: clamp(30px, 4.2vw, 50px);
  font-weight: 950;
  letter-spacing: 0.5px;
  line-height: 1.15;
  color: #fff;
  text-shadow: 3px 3px 0 #000;
}

.action-sub {
  margin-top: 6px;
  font-size: clamp(18px, 2.1vw, 26px);
  color: #fde68a;
  font-weight: 800;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.8);
}

.action-bar-wrap {
  margin-top: 12px;
  width: 100%;
  height: 22px;
  background: #1a2134;
  border: 3px solid #fff;
  border-radius: 6px;
  overflow: hidden;
}

.action-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #34d399, #facc15);
  transition: width 0.08s linear;
}

/* 摄像头画中画 */
.pip-panel {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 240px;
  height: 180px;
  background: #0b0e17;
  border: 3px solid #fff;
  box-shadow: 0 4px 0 #000;
  border-radius: 10px;
  overflow: hidden;
  z-index: 25;
  transition: width 0.2s ease, height 0.2s ease;
}

.pip-panel.large {
  width: 360px;
  height: 270px;
}

.pip-panel.minimized {
  width: 140px;
  height: 105px;
}

#webcam {
  display: none;
}

#pose-canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.pip-status {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  background: rgba(0, 0, 0, 0.72);
  color: #f8fafc;
}

.pip-status.ok {
  color: #6ee7b7;
}

.pip-status.warn {
  color: #fde047;
}

/* 弹窗遮罩 */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(12, 16, 28, 0.75);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}

.hidden {
  display: none !important;
}

.pixel-card {
  background: var(--card-bg);
  color: var(--ink);
  border: 4px solid var(--border);
  box-shadow: 0 8px 0 #000;
  border-radius: 14px;
  padding: 20px 24px;
  max-width: 880px;
  width: 100%;
  max-height: calc(100vh - 76px);
  overflow-y: auto;
}

.pixel-card.compact {
  max-width: 460px;
  text-align: center;
}

.pixel-card h1 {
  font-size: 26px;
  font-weight: 900;
}

.pixel-card h2 {
  font-size: 26px;
  font-weight: 900;
  margin-bottom: 10px;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.version-tag {
  font-size: 12px;
  font-weight: 800;
  background: #e0f2fe;
  color: #0369a1;
  border: 2px solid #0369a1;
  padding: 3px 8px;
  border-radius: 6px;
}

.lead {
  font-size: 14px;
  line-height: 1.5;
  color: #334155;
  margin-bottom: 12px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.action-grid-7 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 760px) {
  .action-grid, .action-grid-7 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.act-box {
  background: #f3f0e4;
  border: 3px solid #1a1c2c;
  border-radius: 10px;
  padding: 9px 8px;
  text-align: center;
  transition: transform 0.12s ease, background 0.15s ease;
}

.act-box.flash {
  background: #bbf7d0;
  transform: translateY(-3px);
  border-color: #15803d;
}

.act-emoji {
  font-size: 22px;
  margin-bottom: 2px;
}

.act-name {
  font-size: 14px;
  font-weight: 900;
  margin-bottom: 2px;
}

.act-desc {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  line-height: 1.3;
}

.act-count {
  font-size: 12px;
  font-weight: 800;
  color: #0f172a;
  background: #fff;
  border: 2px solid #cbd5e1;
  border-radius: 6px;
  padding: 2px 6px;
}

.setup-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #f1f5f9;
  border-radius: 8px;
  border: 2px solid #cbd5e1;
}

.toggle-pill {
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.toggle-pill select {
  font-size: 13px;
  font-weight: 700;
  padding: 4px 8px;
  border: 2px solid #1a1c2c;
  border-radius: 6px;
  background: #fff;
}

.load-msg {
  font-size: 13px;
  font-weight: 700;
  color: #1d4ed8;
}

.load-msg.ok {
  color: #15803d;
}

.load-msg.err {
  color: #b91c1c;
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 900;
  border: 3px solid #1a1c2c;
  box-shadow: 0 4px 0 #1a1c2c;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #1a1c2c;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--green);
  color: #fff;
}

.btn-accent {
  background: var(--gold);
  color: #1a1c2c;
}

.btn-secondary {
  background: #e2e8f0;
  color: #1a1c2c;
}

.btn-ghost {
  background: transparent;
  color: #475569;
  border-style: dashed;
  box-shadow: none;
}

.kb-hint {
  margin-top: 10px;
  font-size: 12px;
  color: #64748b;
  text-align: center;
  line-height: 1.5;
}

.kb-hint code {
  background: #e2e8f0;
  color: #0f172a;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stats-grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 640px) {
  .stats-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-item {
  background: #f3f0e4;
  border: 2px solid #1a1c2c;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.stat-item span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-item strong {
  font-size: 20px;
  font-weight: 900;
  color: var(--ink);
}
