:root {
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;

  /* 浅色主题变量 */
  --bg-main: #f3f6f4;
  --bg-card: #ffffff;
  --bg-card-sub: #f8fafc;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-light: #d1fae5;
  --secondary: #f1f5f9;
  --secondary-hover: #e2e8f0;
  --danger: #ef4444;
  --highlight: #f59e0b;

  --canvas-bg: #111827;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 6px 16px -2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 16px 32px -4px rgba(0, 0, 0, 0.08);
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --bg-main: #090d16;
  --bg-card: #131b2e;
  --bg-card-sub: #1e293b;
  --border-color: #27354f;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #10b981;
  --primary-hover: #34d399;
  --primary-light: rgba(16, 185, 129, 0.2);
  --secondary: #1e293b;
  --secondary-hover: #2e3e5c;
  --danger: #f87171;
  --highlight: #fbbf24;

  --canvas-bg: #090d16;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 16px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 16px 32px -4px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-stack);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.noscript-banner {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  padding: 14px;
  background: var(--danger);
  color: #fff;
  text-align: center;
  font-weight: 600;
  z-index: 9999;
}

.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
}

/* 顶部导航 */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 28px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  z-index: 20;
}

.nav-left, .nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.home-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--text-main);
  background: var(--secondary);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s ease;
}

.home-btn:hover {
  background: var(--secondary-hover);
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title h1 {
  font-size: 18px;
  font-weight: 700;
}

.brand-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  letter-spacing: 0.5px;
}

.tool-btn, .pill-btn {
  border: 1px solid var(--border-color);
  background: var(--secondary);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.tool-btn {
  width: 36px;
  height: 36px;
  font-size: 16px;
}

.pill-btn {
  padding: 0 14px;
  height: 36px;
  font-size: 13px;
  font-weight: 600;
}

.tool-btn:hover, .pill-btn:hover {
  background: var(--secondary-hover);
}

/* 核心工作区：统一卡片容器，彻底消灭上下错位与孤立悬浮 */
.main-workspace {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: center;
  justify-content: center;
}

@media (min-width: 900px) {
  .main-workspace {
    flex-direction: row;
    align-items: flex-start; /* 严禁垂直错位，顶部绝对齐平 */
    justify-content: center;
    padding: 40px 24px;
    gap: 32px;
  }
}

/* 主舞台画布侧 */
.stage-section {
  width: 100%;
  max-width: 580px;
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.canvas-box {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background-color: var(--canvas-bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* 侧边仪表盘 */
.sidebar-section {
  width: 100%;
  max-width: 580px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (min-width: 900px) {
  .sidebar-section {
    width: 340px;
    flex-shrink: 0;
  }
}

.dashboard-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat-cell {
  background: var(--bg-card-sub);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.stat-num {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.text-highlight {
  color: var(--highlight) !important;
}

/* 难度选择器 */
.panel-diff-selector, .difficulty-select-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.selector-title, .diff-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.diff-btn-group, .diff-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.diff-tag, .diff-btn {
  padding: 9px 4px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--secondary);
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}

.diff-tag.active, .diff-btn.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.quick-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 按钮通用规范 */
.btn {
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  transition: all 0.15s ease;
}

.w-100 {
  width: 100%;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--secondary-hover);
}

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

.btn-ghost:hover {
  background: var(--secondary);
  color: var(--text-main);
}

/* 画布弹窗系统 */
.modal-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 15, 29, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  z-index: 30;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.modal-layer.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 26px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-badge {
  font-size: 42px;
  line-height: 1;
}

.modal-card h2 {
  font-size: 21px;
  font-weight: 700;
  color: var(--text-main);
}

.modal-text {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.score-summary {
  background: var(--bg-card-sub);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.summary-line {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--text-muted);
}

.rules-card {
  text-align: left;
  max-width: 440px;
}

.rules-body {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rules-body h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 4px;
}

.rules-body ul {
  padding-left: 18px;
}

/* 触控虚拟按键 (移动端自适应) */
.mobile-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
}

.dpad-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.dpad-mid {
  justify-content: space-between;
  max-width: 260px;
}

.dpad-key {
  width: 68px;
  height: 50px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 20px;
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.05s ease, background 0.1s ease;
}

.dpad-key-sub {
  width: 54px;
  font-size: 15px;
  font-weight: 700;
}

.dpad-key:active {
  transform: scale(0.93);
  background: var(--secondary-hover);
}

@media (min-width: 900px) {
  .mobile-dpad {
    display: none;
  }
}

.app-footer {
  padding: 16px 28px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
