/* 数学小星球 —— DOM UI 叠加层样式（大字、圆角、糖果色，6-8 岁友好） */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden; background: #9fd8ff;
  font-family: "PingFang SC", "Microsoft YaHei", "Heiti SC", sans-serif;
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
  overscroll-behavior: none; touch-action: none; /* 禁止移动端整页橡皮筋回弹/双指缩放误触 */
  position: fixed; inset: 0;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* UI 覆盖层：默认不挡 3D 交互，只有子元素可点 */
#ui-layer { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#ui-layer > * { pointer-events: auto; }

#top-bar {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center;
  justify-content: space-between; pointer-events: none;
  padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
           12px calc(16px + env(safe-area-inset-left));
}
#top-bar > * { pointer-events: auto; }
.top-right { display: flex; gap: 10px; }
.icon-btn {
  width: 56px; height: 56px; border: none; border-radius: 50%; font-size: 28px;
  background: #fff; box-shadow: 0 4px 0 rgba(0,0,0,0.12); cursor: pointer;
  transition: transform .1s; display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.12); }

#title-bubble {
  background: #fff; color: #5B4636; font-size: 26px; font-weight: 800;
  padding: 10px 24px; border-radius: 28px; box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  display: none; max-width: 56%; text-align: center;
}

#speech {
  position: absolute; left: 50%; transform: translateX(-50%); top: 88px;
  background: #FFF6E5; color: #5B4636; font-size: 22px; font-weight: 700;
  padding: 14px 26px; border-radius: 24px; box-shadow: 0 5px 0 rgba(0,0,0,0.08);
  display: none; max-width: 84%; text-align: center; border: 3px solid #fff; line-height: 1.4;
}
#speech.pop { animation: pop .35s ease; }
@keyframes pop {
  0% { transform: translateX(-50%) scale(.7); }
  60% { transform: translateX(-50%) scale(1.08); }
  100% { transform: translateX(-50%) scale(1); }
}

#stars { position: absolute; top: 84px; right: 18px; display: none; gap: 4px; }
.star { font-size: 34px; color: #e3e3e3; text-shadow: 0 2px 0 rgba(0,0,0,.08); transition: transform .2s; }
.star.on { color: #FFD23F; transform: scale(1.1); }

#bottom-bar {
  position: absolute; left: 0; right: 0; bottom: calc(28px + env(safe-area-inset-bottom));
  display: flex; gap: 16px; justify-content: center; flex-wrap: wrap;
  padding: 0 calc(16px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left));
}
.big-btn {
  border: none; border-radius: 30px; font-size: 24px; font-weight: 800; color: #5B4636;
  background: #fff; padding: 16px 30px; box-shadow: 0 6px 0 rgba(0,0,0,0.15); cursor: pointer;
  font-family: inherit; transition: transform .1s; min-height: 56px; min-width: 56px;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,0.15); }
.big-btn.primary { background: #FFD23F; }
.big-btn.green { background: #5FD3A3; color: #fff; }
.big-btn.purple { background: #7C6CE0; color: #fff; }
.big-btn.pink { background: #FF7BA9; color: #fff; }

#loading {
  position: absolute; inset: 0; background: rgba(127,200,248,0.96); display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 20px; z-index: 50;
}
.spinner {
  width: 64px; height: 64px; border: 8px solid #fff; border-top-color: #FFD23F;
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: #fff; font-size: 22px; font-weight: 800; }

#confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-piece {
  position: absolute; top: -20px; width: 14px; height: 14px; border-radius: 3px;
  animation: fall 2s ease-in forwards;
}
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: .85; } }

#parent-panel {
  position: absolute; inset: 0; background: rgba(0,0,0,0.4); display: none;
  align-items: center; justify-content: center; z-index: 60; padding: 20px;
}
.parent-card { background: #fff; border-radius: 28px; padding: 32px; max-width: 440px; text-align: center; }
.parent-card h2 { font-size: 26px; color: #5B4636; margin-bottom: 16px; }
.parent-card p { font-size: 18px; color: #5B4636; margin-bottom: 14px; line-height: 1.6; }
.parent-card .muted { color: #999; font-size: 15px; }
.parent-card .stars-total { font-size: 28px; color: #FF9A52; font-weight: 800; }

/* 首页中/美版切换胶囊（仅大厅显示，置于左上角房子按钮下方的空地） */
.lang-switch {
  position: absolute; z-index: 40;
  top: calc(78px + env(safe-area-inset-top)); left: calc(16px + env(safe-area-inset-left));
  display: inline-flex; align-items: center; gap: 4px;
  border: none; border-radius: 24px; font-family: inherit; cursor: pointer;
  font-size: 18px; font-weight: 800; color: #5B4636;
  background: rgba(255,255,255,0.94); padding: 10px 20px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.12); transition: transform .1s;
}
.lang-switch:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.12); }

/* ===== 移动端 / iPad 响应式 ===== */

/* 竖屏手机：提示横过来玩（iPad 竖屏 ≥768px 不触发，3D 自带 FOV 自适应兜底） */
#rotate-hint {
  position: absolute; inset: 0; display: none; z-index: 70;
  flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: linear-gradient(160deg, #7FC8F8, #9fd8ff); text-align: center; padding: 24px;
}
#rotate-hint .rotate-icon { font-size: 76px; animation: rotateWiggle 1.8s ease-in-out infinite; }
#rotate-hint .rotate-text { font-size: 22px; font-weight: 800; color: #5B4636; max-width: 80%; line-height: 1.5; }
@keyframes rotateWiggle {
  0%, 100% { transform: rotate(-12deg); }
  50% { transform: rotate(78deg); }
}
@media (hover: none) and (orientation: portrait) and (max-width: 540px) {
  #rotate-hint { display: flex; }
}

/* 窄屏（手机，无论横竖）：缩小按钮/气泡，防止长中文按钮溢出换行错乱 */
@media (max-width: 600px) {
  .icon-btn { width: 48px; height: 48px; font-size: 24px; }
  #title-bubble { font-size: 20px; padding: 8px 16px; max-width: 58%; }
  #speech { font-size: 18px; padding: 10px 18px; max-width: 92%; top: 76px; overflow-wrap: break-word; }
  #stars { top: 72px; }
  .star { font-size: 28px; }
  #bottom-bar { gap: 10px; }
  .big-btn { font-size: 19px; padding: 12px 18px; min-width: 0; max-width: 46vw; overflow-wrap: anywhere; }
  .lang-switch { font-size: 16px; padding: 8px 16px; top: calc(70px + env(safe-area-inset-top)); }
}

/* 极窄屏（小手机竖屏）：底部按钮竖排，避免横向挤爆 */
@media (max-width: 380px) {
  #bottom-bar { flex-direction: column; align-items: center; gap: 8px; }
  .big-btn { width: 86%; max-width: 320px; }
}

/* 矮屏（手机横屏，高 ≤480px）：压缩纵向 DOM，给 3D 视口让位，避免上下遮挡 */
@media (max-height: 480px) {
  #top-bar { padding-top: calc(6px + env(safe-area-inset-top)); }
  .icon-btn { width: 44px; height: 44px; font-size: 22px; }
  #speech { top: calc(54px + env(safe-area-inset-top)); font-size: 17px; padding: 8px 16px; line-height: 1.3; }
  #stars { top: calc(54px + env(safe-area-inset-top)); }
  .star { font-size: 24px; }
  #bottom-bar { bottom: calc(10px + env(safe-area-inset-bottom)); gap: 8px; }
  .big-btn { font-size: 17px; padding: 9px 16px; }
  .lang-switch { font-size: 15px; padding: 7px 14px; top: calc(54px + env(safe-area-inset-top)); }
}
