:root {
  --bg-top: #1a2138;
  --bg-bottom: #0d111f;
  --panel: #171d31;
  --border: #334066;
  --gold: #ffd447;
  --pink: #ff6b9d;
  --strawberry: #ff4466;
  --text: #f8fafc;
  --muted: #cbd5e1;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 25%, #27345a 0%, var(--bg-top) 48%, var(--bg-bottom) 100%);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

body.is-fullscreen {
  touch-action: none;
  background: #070b16;
}

.cabinet {
  position: relative;
  width: 100%;
  max-width: 1120px;
  height: 100%;
  max-height: 100vh;
  max-height: 100dvh;
  padding: max(44px, env(safe-area-inset-top)) 14px max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
}

.stage-rotator {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.stage-slot {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.screen-frame {
  position: relative;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  background: #5c94fc;
  border: 4px solid #394873;
  border-radius: 14px;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.65),
    inset 0 0 0 2px rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(12, 18, 36, 0.56);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 5;
  transition: opacity 0.2s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.card {
  width: min(540px, 94%);
  background: linear-gradient(160deg, rgba(28, 36, 62, 0.96), rgba(17, 23, 41, 0.97));
  border: 2px solid rgba(255, 212, 71, 0.55);
  border-radius: 18px;
  padding: 18px 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.card-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff5d8f, #ff8fab);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.card h1,
.card h2 {
  margin: 4px 0 6px;
  font-size: clamp(20px, 3vw, 27px);
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

.card p {
  margin: 0 0 10px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--muted);
}

.world-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 6px 0;
}

.world-tab {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.world-tab.active {
  background: rgba(56, 189, 248, 0.22);
  border-color: #38bdf8;
  color: #ffffff;
}

.stage-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin: 6px 0 10px;
}

.stage-pill {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  padding: 6px 4px;
  background: rgba(255, 255, 255, 0.07);
  color: #e2e8f0;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
  transition: transform 0.1s, border-color 0.15s, background 0.15s;
}

.stage-pill small {
  display: block;
  font-size: 10px;
  font-weight: 500;
  color: #cbd5e1;
  margin-top: 2px;
}

.stage-pill.active {
  background: rgba(255, 107, 157, 0.28);
  border-color: #ff8fab;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 143, 171, 0.45);
}

.stage-pill:active {
  transform: scale(0.97);
}

.hero-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 8px 0 12px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.preview-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #f1f5f9;
}

.preview-item img {
  width: 52px;
  height: 52px;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.45));
}

.preview-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0 16px;
}

.stat-box {
  background: rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 8px 6px;
}

.stat-box strong {
  display: block;
  font-size: 18px;
  color: var(--gold);
}

.stat-box span {
  font-size: 11px;
  color: var(--muted);
}

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

.btn-primary {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 10px 24px;
  font-size: 15.5px;
  font-weight: 800;
  color: #2b1400;
  background: linear-gradient(180deg, #ffe270 0%, #ffb703 100%);
  box-shadow: 0 4px 0 #b87300, 0 10px 20px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.08s;
  font-family: inherit;
}

.btn-primary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #b87300;
}

.btn-secondary {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.09);
  cursor: pointer;
  font-family: inherit;
}

.toolbar {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding: 0 4px;
}

.hints {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid #495a88;
  border-bottom-width: 2px;
  background: #1b2440;
  color: #f8fafc;
  font-weight: 700;
  font-size: 11px;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tool-btn {
  appearance: none;
  border: 1px solid #3c4b74;
  background: #1a233d;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.tool-btn:hover {
  background: #253154;
  border-color: #5e72ab;
}

.tool-btn.active {
  background: rgba(255, 107, 157, 0.22);
  border-color: var(--pink);
  color: #ffd6e6;
}

.touch-controls {
  width: 100%;
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px 2px;
  gap: 12px;
  z-index: 6;
}

.touch-controls.force-visible {
  display: flex;
}

.touch-controls.force-hidden {
  display: none !important;
}

.touch-cluster {
  display: flex;
  gap: 10px;
  align-items: center;
  pointer-events: auto;
}

.touch-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.42);
  background: rgba(30, 41, 72, 0.78);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  display: grid;
  place-items: center;
  touch-action: none;
  font-family: inherit;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.touch-btn.pressed {
  background: rgba(255, 212, 71, 0.55);
  border-color: #ffd447;
  transform: scale(0.95);
}

.touch-btn.jump-btn {
  width: 60px;
  height: 60px;
  background: rgba(255, 86, 128, 0.72);
  border-color: rgba(255, 190, 210, 0.85);
  font-size: 15px;
}

.touch-btn.run-btn {
  width: 50px;
  height: 50px;
  font-size: 13px;
  background: rgba(56, 189, 248, 0.58);
}

.touch-btn.down-btn {
  width: 44px;
  height: 44px;
  font-size: 15px;
}

.fs-bar {
  flex: 0 0 auto;
  width: 100%;
  display: none;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  z-index: 12;
  pointer-events: auto;
}

.fs-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(17, 24, 46, 0.85);
  color: #f8fafc;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  font-family: inherit;
  touch-action: manipulation;
}

.fs-btn:active {
  transform: scale(0.96);
}

.fs-btn.fs-exit {
  background: rgba(225, 29, 72, 0.72);
  border-color: rgba(255, 190, 210, 0.5);
}

/* 紧凑/竖屏小框内卡片自适应，防止文字或按钮被 16:9 画框裁切 */
.screen-frame.is-compact-frame .overlay {
  padding: 8px;
}

.screen-frame.is-compact-frame .card {
  padding: 10px 12px;
  border-radius: 14px;
  max-height: 100%;
  overflow-y: auto;
}

.screen-frame.is-compact-frame .card-badge {
  padding: 2px 8px;
  font-size: 10px;
  margin-bottom: 3px;
}

.screen-frame.is-compact-frame .card h1,
.screen-frame.is-compact-frame .card h2 {
  font-size: clamp(15px, 2.7vw, 20px);
  margin: 2px 0 3px;
}

.screen-frame.is-compact-frame .card p {
  font-size: 11.5px;
  line-height: 1.35;
  margin-bottom: 6px;
}

.screen-frame.is-compact-frame .world-tabs {
  gap: 5px;
  margin: 4px 0;
}

.screen-frame.is-compact-frame .world-tab {
  padding: 4px 6px;
  font-size: 11px;
}

.screen-frame.is-compact-frame .stage-picker {
  gap: 5px;
  margin: 4px 0 6px;
}

.screen-frame.is-compact-frame .stage-pill {
  padding: 4px 3px;
  font-size: 11px;
}

.screen-frame.is-compact-frame .hero-preview {
  margin: 5px 0 8px;
  padding: 5px 8px;
  gap: 12px;
}

.screen-frame.is-compact-frame .preview-item img,
.screen-frame.is-compact-frame .preview-icon {
  width: 36px;
  height: 36px;
}

.screen-frame.is-compact-frame .btn-primary {
  padding: 7px 16px;
  font-size: 13.5px;
}

.screen-frame.is-compact-frame .btn-secondary {
  padding: 6px 12px;
  font-size: 12.5px;
}

.screen-frame.is-tiny-frame .overlay {
  padding: 4px;
}

.screen-frame.is-tiny-frame .card {
  padding: 7px 9px;
  border-radius: 10px;
}

.screen-frame.is-tiny-frame .card-badge {
  display: none;
}

.screen-frame.is-tiny-frame .card p {
  font-size: 10.5px;
  line-height: 1.25;
  margin-bottom: 4px;
}

.screen-frame.is-tiny-frame .world-tabs {
  gap: 4px;
  margin: 3px 0;
}

.screen-frame.is-tiny-frame .world-tab {
  padding: 3px 5px;
  font-size: 10px;
}

.screen-frame.is-tiny-frame .stage-picker {
  gap: 4px;
  margin: 3px 0 4px;
}

.screen-frame.is-tiny-frame .stage-pill {
  padding: 3px 2px;
  font-size: 10px;
}

.screen-frame.is-tiny-frame .stage-pill small {
  display: none;
}

.screen-frame.is-tiny-frame .hero-preview {
  margin: 3px 0 5px;
  padding: 3px 6px;
  gap: 8px;
}

.screen-frame.is-tiny-frame .preview-item {
  font-size: 10px;
  gap: 2px;
}

.screen-frame.is-tiny-frame .preview-item img,
.screen-frame.is-tiny-frame .preview-icon {
  width: 26px;
  height: 26px;
}

.screen-frame.is-tiny-frame .stat-grid {
  margin: 4px 0 5px;
  gap: 5px;
}

.screen-frame.is-tiny-frame .stat-box {
  padding: 4px;
}

.screen-frame.is-tiny-frame .stat-box strong {
  font-size: 13px;
}

.screen-frame.is-tiny-frame .btn-primary {
  padding: 5px 12px;
  font-size: 12.5px;
}

.screen-frame.is-tiny-frame .btn-secondary {
  padding: 4px 10px;
  font-size: 11.5px;
}

/* 全屏模式（原生全屏 + iOS/微信伪全屏统一） */
.cabinet:fullscreen {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  padding: 0;
  background: #070b16;
}

.cabinet.is-fullscreen {
  max-width: none;
  width: 100%;
  height: 100%;
  max-height: none;
  padding: 0;
  background: #070b16;
}

.cabinet.is-pseudo-fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  z-index: 2147483100;
}

.cabinet.is-fullscreen .stage-rotator {
  padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  gap: 6px;
}

.cabinet.is-fullscreen.is-rotated-landscape .stage-rotator {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--rot-w, 100dvh);
  height: var(--rot-h, 100dvw);
  max-width: none;
  max-height: none;
  transform: translate(-50%, -50%) rotate(90deg);
  padding:
    max(6px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(6px, env(safe-area-inset-left))
    max(10px, env(safe-area-inset-top));
}

.cabinet.is-fullscreen .screen-frame {
  border-width: 2px;
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.72);
}

.cabinet.is-fullscreen .toolbar {
  display: none;
}

.cabinet.is-fullscreen .fs-bar {
  display: flex;
}

.cabinet.is-fullscreen.is-landscape-play .touch-controls {
  position: absolute;
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  width: auto;
  padding: 0;
  pointer-events: none;
}

.cabinet.is-fullscreen.is-rotated-landscape .touch-controls {
  left: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-bottom));
  bottom: max(10px, env(safe-area-inset-left));
}

.cabinet.is-fullscreen.is-landscape-play .touch-cluster {
  gap: 7px;
}

.cabinet.is-fullscreen.is-landscape-play .touch-btn {
  width: 44px;
  height: 44px;
  font-size: 16px;
  background: rgba(15, 23, 42, 0.52);
  border-color: rgba(255, 255, 255, 0.36);
}

.cabinet.is-fullscreen.is-landscape-play .touch-btn.jump-btn {
  width: 54px;
  height: 54px;
  font-size: 14px;
  background: rgba(255, 86, 128, 0.68);
}

.cabinet.is-fullscreen.is-landscape-play .touch-btn.run-btn {
  width: 44px;
  height: 44px;
  font-size: 12px;
}

.cabinet.is-fullscreen.is-landscape-play .touch-btn.down-btn {
  width: 38px;
  height: 38px;
  font-size: 13px;
}

.cabinet.overlay-open.is-landscape-play .touch-controls {
  opacity: 0.16;
}

.cabinet.overlay-open.is-landscape-play .touch-cluster {
  pointer-events: none;
}

@media (max-width: 820px), (pointer: coarse), (hover: none) {
  .cabinet:not(.is-fullscreen) {
    padding: max(42px, env(safe-area-inset-top)) 8px max(10px, env(safe-area-inset-bottom));
  }

  .cabinet:not(.is-fullscreen) .stage-rotator {
    gap: 8px;
  }

  .cabinet:not(.is-fullscreen) .screen-frame {
    border-width: 2px;
    border-radius: 10px;
  }

  .hints {
    display: none;
  }

  .toolbar {
    justify-content: center;
  }

  .touch-controls {
    display: flex;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 560px), (hover: none) and (orientation: landscape) and (max-height: 560px) {
  .cabinet:not(.is-fullscreen) {
    max-width: none;
    padding: max(38px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .cabinet:not(.is-fullscreen) .stage-rotator {
    gap: 4px;
  }

  .cabinet:not(.is-fullscreen) .toolbar {
    flex-wrap: nowrap;
  }

  .cabinet:not(.is-fullscreen) .tools {
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    gap: 5px;
  }

  .cabinet:not(.is-fullscreen) .tool-btn {
    padding: 4px 8px;
    font-size: 11px;
    white-space: nowrap;
  }

  .cabinet:not(.is-fullscreen) .touch-controls {
    position: absolute;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: 36px;
    width: auto;
    padding: 0;
    pointer-events: none;
  }

  .cabinet:not(.is-fullscreen) .touch-btn {
    width: 46px;
    height: 46px;
    background: rgba(15, 23, 42, 0.45);
  }

  .cabinet:not(.is-fullscreen) .touch-btn.jump-btn {
    width: 54px;
    height: 54px;
    background: rgba(255, 86, 128, 0.62);
  }

  .cabinet:not(.is-fullscreen) .touch-btn.down-btn {
    width: 40px;
    height: 40px;
  }
}
