:root {
  --paper: #f8f6f0;
  --paper-card: #ffffff;
  --paper-soft: #f0ede4;
  --ink: #1e293b;
  --ink-strong: #0f172a;
  --muted: #64748b;
  --border: rgba(30, 41, 59, 0.12);
  --l1: #e63946;
  --l2: #1d6fd6;
  --l3: #18a558;
  --l4: #e59f00;
  --danger: #dc2626;
  --gold: #d97706;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: radial-gradient(circle at 50% 0%, #2b3441 0%, #161b22 72%);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.hidden {
  display: none !important;
}

/* 9:16 微信小游戏竖屏外壳 */
.wx-shell {
  width: 100%;
  max-width: 430px;
  height: min(100dvh, 860px);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.1);
  border-radius: 22px;
  user-select: none;
  -webkit-user-select: none;
}

@media (max-width: 450px) {
  .wx-shell {
    max-width: 100%;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
}

/* 顶部模拟微信导航栏 */
.wx-topbar {
  height: 48px;
  flex-shrink: 0;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  z-index: 20;
}

.wx-back {
  text-decoration: none;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--paper-soft);
  transition: background 0.15s ease, transform 0.12s ease;
  white-space: nowrap;
}

.wx-back:hover {
  background: #e5e0d4;
}

.wx-back:active {
  transform: scale(0.96);
}

.wx-title {
  font-size: 14.5px;
  font-weight: 800;
  color: var(--ink-strong);
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 6px;
}

.wx-capsule {
  display: flex;
  align-items: center;
  background: var(--paper-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  height: 30px;
  padding: 0 4px;
  flex-shrink: 0;
}

.wx-icon-btn {
  border: none;
  background: transparent;
  width: 30px;
  height: 26px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13.5px;
  display: grid;
  place-items: center;
  color: var(--ink-strong);
  transition: background 0.15s ease;
}

.wx-icon-btn:hover {
  background: rgba(15, 23, 42, 0.08);
}

.wx-capsule-sep {
  width: 1px;
  height: 14px;
  background: rgba(15, 23, 42, 0.16);
}

/* 局内 HUD */
.hud-bar {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  padding: 7px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 15;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-pill {
  flex: 1;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.hud-timer.rush {
  background: #fef2f2;
  border-color: rgba(220, 38, 38, 0.4);
  animation: timerPulse 1s ease-in-out infinite;
}

.hud-timer.rush .hud-val {
  color: var(--danger);
}

@keyframes timerPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.18); }
  50% { box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.08); }
}

.hud-label {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.3px;
  line-height: 1.1;
}

.hud-val-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hud-val {
  font-size: 16px;
  font-weight: 900;
  color: var(--ink-strong);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.hud-val.small {
  font-size: 14px;
}

.rush-mult {
  font-size: 10px;
  font-weight: 900;
  background: linear-gradient(135deg, #f59e0b, #dc2626);
  color: #fff;
  padding: 1px 5px;
  border-radius: 999px;
}

.speed-pill {
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink-strong);
  font-size: 12.5px;
  font-weight: 900;
  border-radius: 10px;
  width: 40px;
  height: 38px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.speed-pill.fast {
  background: #1e293b;
  color: #f8fafc;
  border-color: #1e293b;
}

.upgrade-track-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.upgrade-track {
  flex: 1;
  height: 5px;
  border-radius: 999px;
  background: #e5e2d8;
  overflow: hidden;
}

.upgrade-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #1d6fd6, #18a558);
  border-radius: 999px;
  transition: width 0.25s linear;
}

.upgrade-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 画布舞台 */
.stage-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--paper);
  overflow: hidden;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* 晚高峰横幅 */
.rush-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #dc2626, #ea580c);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(220, 38, 38, 0.35);
  z-index: 12;
  pointer-events: none;
  animation: bannerBounce 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes bannerBounce {
  0% { opacity: 0; transform: translate(-50%, -14px) scale(0.92); }
  100% { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

.toast-pill {
  position: absolute;
  top: 46px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  color: #f8fafc;
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
  z-index: 12;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.drag-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(30, 41, 59, 0.16);
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  z-index: 10;
  transition: opacity 0.35s ease;
}

.drag-hint.fade-out {
  opacity: 0;
}

/* 底部线路工具栏 */
.toolbar {
  flex-shrink: 0;
  background: #ffffff;
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: stretch;
  gap: 6px;
  z-index: 20;
}

.line-buttons {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.line-btn {
  border: 2px solid transparent;
  background: var(--paper);
  border-radius: 12px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.line-btn:active {
  transform: scale(0.95);
}

.line-btn.active {
  background: #ffffff;
  border-color: var(--ink-strong);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.14);
  transform: translateY(-1px);
}

.line-btn.locked {
  opacity: 0.55;
  background: #eceae2;
}

.line-swatch {
  width: 26px;
  height: 7px;
  border-radius: 999px;
  background: var(--lc);
  display: block;
}

.line-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}

.line-name {
  font-size: 11.5px;
  font-weight: 900;
  color: var(--ink-strong);
}

.line-info {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.clear-btn {
  width: 56px;
  flex-shrink: 0;
  border: 1px solid rgba(220, 38, 38, 0.28);
  background: #fef2f2;
  color: #b91c1c;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}

.clear-btn:hover {
  background: #fee2e2;
}

.clear-btn:active {
  transform: scale(0.95);
}

.clear-icon {
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
}

.clear-txt {
  font-size: 10px;
  font-weight: 800;
}

/* 弹窗层 */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(248, 246, 240, 0.84);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 30;
}

.panel {
  width: 100%;
  max-width: 372px;
  background: #ffffff;
  border: 1.5px solid rgba(15, 23, 42, 0.12);
  border-radius: 20px;
  padding: 20px 18px;
  box-shadow: 0 20px 44px rgba(15, 23, 42, 0.14);
  display: flex;
  flex-direction: column;
  gap: 13px;
}

/* 伦敦/东京地铁圆标风格 */
.roundel-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.transit-roundel {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 7px solid var(--l1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: #ffffff;
}

.roundel-bar {
  background: var(--l2);
  color: #ffffff;
  font-size: 9.5px;
  font-weight: 900;
  letter-spacing: 1px;
  padding: 3px 9px;
  border-radius: 3px;
  position: absolute;
  white-space: nowrap;
}

.brand-tag {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.4px;
  color: var(--muted);
}

.game-logo {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}

.logo-main {
  font-size: 28px;
  font-weight: 900;
  color: var(--ink-strong);
  letter-spacing: 1px;
}

.logo-sub {
  font-size: 15px;
  font-weight: 800;
  color: var(--l2);
  margin-top: 2px;
}

.line-swatch-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.swatch-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.swatch-line {
  width: 28px;
  height: 4px;
}

.swatch-dot.l1, .swatch-line.l1 { background: var(--l1); }
.swatch-dot.l2, .swatch-line.l2 { background: var(--l2); }
.swatch-dot.l3, .swatch-line.l3 { background: var(--l3); }
.swatch-dot.l4 { background: var(--l4); }

.intro-text {
  font-size: 12.5px;
  line-height: 1.55;
  color: #334155;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-btn {
  border: 2px solid var(--border);
  background: var(--paper);
  border-radius: 12px;
  padding: 9px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  text-align: left;
  transition: all 0.15s ease;
}

.mode-btn.active {
  background: #eff6ff;
  border-color: var(--l2);
  box-shadow: 0 4px 12px rgba(29, 111, 214, 0.14);
}

.mode-title {
  font-size: 12px;
  font-weight: 900;
  color: var(--ink-strong);
}

.mode-desc {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
}

.best-strip {
  text-align: center;
  font-size: 12px;
  color: #475569;
  font-weight: 700;
}

.best-strip strong {
  color: var(--ink-strong);
  font-size: 14px;
}

.primary-btn {
  border: none;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: #ffffff;
  font-size: 15px;
  font-weight: 900;
  padding: 13px 16px;
  border-radius: 14px;
  cursor: pointer;
  width: 100%;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.22);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.primary-btn:hover {
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.28);
}

.primary-btn:active {
  transform: scale(0.98);
}

.secondary-btn {
  border: 1.5px solid var(--border);
  background: var(--paper);
  color: var(--ink-strong);
  font-size: 14px;
  font-weight: 800;
  padding: 11px 16px;
  border-radius: 13px;
  cursor: pointer;
  width: 100%;
  text-align: center;
  text-decoration: none;
  display: block;
}

.secondary-btn:hover {
  background: #eae6dc;
}

.ghost-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 8px;
  cursor: pointer;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shape-legend {
  display: flex;
  justify-content: space-around;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding-top: 2px;
}

/* 暂停 & 升级弹窗 */
.modal-badge {
  align-self: center;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--paper-soft);
  color: var(--ink);
}

.modal-badge.accent {
  background: #eff6ff;
  color: var(--l2);
}

.modal-title {
  text-align: center;
  font-size: 20px;
  font-weight: 900;
  color: var(--ink-strong);
}

.modal-sub {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: -6px;
}

.upgrade-cards {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.upgrade-card {
  border: 1.5px solid var(--border);
  background: var(--paper);
  border-radius: 14px;
  padding: 12px 13px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.upgrade-card:hover {
  background: #ffffff;
  border-color: var(--l2);
  box-shadow: 0 6px 16px rgba(29, 111, 214, 0.12);
  transform: translateY(-1px);
}

.upgrade-card:active {
  transform: scale(0.98);
}

.upg-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 22px;
  flex-shrink: 0;
}

.upg-body {
  flex: 1;
  min-width: 0;
}

.upg-name {
  font-size: 14px;
  font-weight: 900;
  color: var(--ink-strong);
  margin-bottom: 2px;
}

.upg-desc {
  font-size: 11.5px;
  line-height: 1.4;
  color: #475569;
}

/* 结算报告 */
.end-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.end-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.report-kicker {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.4px;
}

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

.rank-stamp {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 900;
  color: #ffffff;
  background: var(--l1);
  flex-shrink: 0;
  transform: rotate(-6deg);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.rank-stamp.rank-S { background: linear-gradient(135deg, #f59e0b, #dc2626); }
.rank-stamp.rank-A { background: linear-gradient(135deg, #1d6fd6, #0ea5e9); }
.rank-stamp.rank-B { background: linear-gradient(135deg, #18a558, #10b981); }
.rank-stamp.rank-C { background: linear-gradient(135deg, #64748b, #475569); }

.end-reason {
  font-size: 12.5px;
  line-height: 1.5;
  color: #334155;
  background: var(--paper);
  border-radius: 10px;
  padding: 9px 11px;
  border: 1px solid var(--border);
}

.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.report-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
}

.report-card.highlight {
  background: #eff6ff;
  border-color: rgba(29, 111, 214, 0.35);
}

.report-lbl {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
}

.report-num {
  font-size: 20px;
  font-weight: 900;
  color: var(--ink-strong);
  font-variant-numeric: tabular-nums;
}

.new-record-tag {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 9px;
  font-weight: 900;
  background: #f59e0b;
  color: #ffffff;
  padding: 1px 5px;
  border-radius: 999px;
}
