* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
  background: #bfe8fb;
  color: #24516e;
  font-family: "Avenir Next", "Nunito", "PingFang SC", "Hiragino Sans", "Microsoft YaHei", sans-serif;
}

/* 文字放大到 200% 时也不要把布局撑破 */
html {
  -webkit-text-size-adjust: 100%;
}

body {
  /* iOS 竖屏底部会有一条横条，Safari 会算进 100vh，用 dvh 才准 */
  min-height: 100dvh;
}

#app {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #a8ddf5 0%, #d9f2fd 68%, #dff4c4 68%, #caeaa5 100%);
}

/* 语言切换：固定在左下角，两个界面都不挡事 */
.lang-btn {
  position: fixed;
  z-index: 30;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(10px, env(safe-area-inset-bottom));
  min-width: 46px;
  min-height: 32px;
  padding: 5px 11px;
  border: 1px solid #b2dce9;
  border-radius: 16px;
  background: rgba(255, 255, 255, .88);
  color: #3f7f9b;
  font: 700 12px/1 inherit;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(82, 156, 190, .18);
}

.lang-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* 触屏设备不显示"按空格 / 按 F"这类按键提示 */
body[data-input="touch"] .kbd-desktop { display: none; }

#app::before {
  content: "";
  position: absolute;
  z-index: -2;
  inset: auto 0 0;
  height: 18%;
  background: radial-gradient(ellipse at 6% 100%, #9ecf78 0 18%, transparent 18.4%), radial-gradient(ellipse at 26% 100%, #a8d582 0 23%, transparent 23.4%), radial-gradient(ellipse at 60% 100%, #97c971 0 20%, transparent 20.4%), radial-gradient(ellipse at 87% 100%, #a6d47e 0 26%, transparent 26.4%);
}

.sky-decor { position: absolute; z-index: -1; pointer-events: none; }
.decor-cloud { width: 170px; height: 38px; border-radius: 40px; background: rgba(255,255,255,.72); filter: drop-shadow(0 8px 12px rgba(57,119,155,.08)); }
.decor-cloud::before, .decor-cloud::after { content: ""; position: absolute; background: inherit; border-radius: 50%; }
.decor-cloud::before { width: 64px; height: 64px; left: 27px; bottom: 0; }
.decor-cloud::after { width: 86px; height: 86px; right: 19px; bottom: 0; }
.cloud-one { top: 13%; left: 7%; transform: scale(.65); }
.cloud-two { top: 30%; right: 4%; transform: scale(.48); opacity: .8; }
.cloud-three { bottom: 19%; left: 16%; transform: scale(.36); opacity: .7; }
.balloon { top: 9%; right: 12%; width: 42px; height: 56px; border-radius: 50% 50% 46% 46%; background: #ff9d76; animation: float 5s ease-in-out infinite; }
.balloon::after { content: ""; position: absolute; width: 0; height: 0; bottom: -12px; left: 16px; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 13px solid #e97d60; }
.balloon i { position: absolute; inset: 12px 9px 11px; border-left: 3px solid rgba(255,255,255,.72); border-right: 3px solid rgba(255,255,255,.72); border-radius: 50%; }
.balloon b { position: absolute; width: 12px; height: 7px; border-radius: 2px; bottom: -20px; left: 15px; background: #9d7052; }
@keyframes float { 50% { transform: translateY(13px) rotate(2deg); } }

.screen {
  width: 100%;
  max-width: 960px;
  padding: 28px 32px;
}

.hidden {
  display: none !important;
}

/* 选角界面 */
#selectScreen {
  text-align: center;
}

.site-header { display: flex; align-items: center; justify-content: space-between; margin: 0 auto 35px; max-width: 860px; }
.brand { display: inline-flex; align-items: center; gap: 9px; color: #2672a2; text-decoration: none; font-size: 20px; font-weight: 800; letter-spacing: -.5px; }
.brand-mark { display: grid; place-items: center; width: 33px; height: 33px; color: #fff; border-radius: 12px 12px 12px 4px; background: #52b6e7; font-size: 25px; line-height: 1; box-shadow: 0 5px 0 #3494c8; }
.header-tag { color: #5c93a9; font-size: 13px; font-weight: 700; }
.hero-copy { animation: enter .55s ease-out both; }
.eyebrow { margin: 0 0 8px; color: #4aa9d3; font-size: 12px; letter-spacing: 2.2px; font-weight: 800; }
#selectScreen h1 { margin: 0; color: #276583; font-size: clamp(30px, 4vw, 46px); line-height: 1.18; letter-spacing: -1.8px; }
.lead { margin: 13px 0 28px; color: #6392a7; font-size: 15px; }
@keyframes enter { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

.char-cards {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.char-card {
  position: relative;
  width: 238px;
  overflow: hidden;
  background: rgba(255,255,255,.94);
  border: 3px dashed #8ccde8;
  border-radius: 23px;
  padding: 15px 15px 17px;
  color: #35718d;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: 0 12px 0 rgba(87,151,181,.17), 0 20px 30px rgba(63,130,162,.15);
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
  animation: enter .55s ease-out both;
}
.char-card:nth-child(2) { animation-delay: .1s; }
.char-card:nth-child(3) { animation-delay: .2s; }

.char-card:hover,
.char-card:active {
  transform: translateY(-7px) rotate(-1deg);
  border-color: #42b3e5;
  box-shadow: 0 17px 0 rgba(87,151,181,.15), 0 25px 32px rgba(63,130,162,.18);
}

.card-ribbon { position: absolute; top: 12px; right: -32px; padding: 5px 34px; transform: rotate(38deg); color: #fff; background: #f3aa56; font-size: 10px; font-weight: 800; letter-spacing: .4px; }
.portrait-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 150px;
  margin-bottom: 4px;
  border-radius: 15px;
  background: linear-gradient(145deg, #dff5ff, #f5fcff);
}

/* 精灵图没下完时的占位，别让卡片空着像坏了 */
.portrait-hint {
  position: absolute;
  color: #7fa9bd;
  font-size: 13px;
  font-weight: 700;
  animation: loadingPulse 1.1s ease-in-out infinite;
}

@keyframes loadingPulse { 50% { opacity: .35; } }

.char-card[data-loading] .portrait-hint { display: block; }
.char-card:not([data-loading]) .portrait-hint { display: none; }
/* 还没加载完不让点，省得点进去角色是空的 */
.char-card[data-loading] { opacity: .72; cursor: progress; }

.char-portrait {
  width: 142px;
  height: 142px;
  image-rendering: -webkit-optimize-contrast;
}

.character-name { font-size: 19px; font-weight: 800; }
.char-card small { color: #79a0b2; font-size: 12px; }

.hint {
  margin: 25px 0 0;
  color: #618da1;
  font-size: 13px;
}
.hint span { margin-right: 8px; font-weight: 700; }
kbd { display: inline-block; padding: 1px 5px; color: #4f8197; font: 700 11px inherit; background: rgba(255,255,255,.75); border: 1px solid #abd7e9; border-bottom-width: 2px; border-radius: 5px; }

/* 游戏界面 */
#gameScreen {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

#hud {
  width: 100%;
  max-width: 860px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 15px;
  font-weight: 800;
  color: #367593;
}

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

#scoreLabel {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 20px;
  background: rgba(255,255,255,.85);
  box-shadow: 0 3px 0 rgba(82,156,190,.18);
}

#scoreLabel.pulse { animation: scorePulse .45s ease; }
@keyframes scorePulse {
  30% { transform: scale(1.18); background: #fff3c9; color: #d97a1f; }
}

#bestLabel {
  padding: 8px 14px;
  border-radius: 20px;
  background: rgba(255,255,255,.6);
  color: #5b93ad;
  font-size: 13px;
  box-shadow: 0 3px 0 rgba(82,156,190,.1);
}

#switchBtn, #muteBtn {
  white-space: nowrap;
  background: #fff;
  color: #44809b;
  border: 1px solid #b2dce9;
  border-radius: 18px;
  padding: 8px 13px;
  cursor: pointer;
  font-size: 14px;
}

#attackBtn {
  white-space: nowrap;
  -webkit-touch-callout: none;
  background: #ffd166;
  color: #7a4c12;
  border: none;
  border-radius: 18px;
  padding: 8px 13px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 3px 0 #e0a93a;
  transition: transform .1s ease, box-shadow .1s ease;
}
#attackBtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #e0a93a; }
#attackBtn kbd { margin-left: 2px; }

/* 画布永远不超过"可用高度 × 8/3"，手机上不会被裁掉 */
#gameCanvas {
  width: min(100%, 800px, calc((100dvh - 132px) * 8 / 3));
  max-width: 100%;
  aspect-ratio: 8 / 3;
  background: linear-gradient(180deg, #9eddf7 0%, #e4f7ff 72%, #c7e993 72%, #b4d97b 100%);
  border: 5px solid rgba(255,255,255,.86);
  border-radius: 20px;
  box-shadow: 0 11px 0 rgba(80,143,169,.18), 0 20px 36px rgba(60,124,150,.16);
  display: block;
  touch-action: manipulation;
  -webkit-touch-callout: none; /* 长按不要弹出 iOS 的"拷贝/选取"菜单 */
}

#tip {
  margin-top: 10px;
  color: #477f98;
  font-size: 14px;
}

#milestone {
  height: 26px;
  margin: 4px 0 -6px;
  color: #f0932b;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -.3px;
  opacity: 0;
  text-shadow: 0 2px 0 rgba(255,255,255,.75);
}

#milestone.show { animation: milestonePop 1.5s ease-out; }

@keyframes milestonePop {
  0% { opacity: 0; transform: translateY(10px) scale(.7); }
  18% { opacity: 1; transform: translateY(-2px) scale(1.12); }
  32% { transform: translateY(0) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-8px); }
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(42, 105, 136, .35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.panel {
  position: relative;
  background: #fff;
  border-radius: 23px;
  padding: 40px 36px 28px;
  text-align: center;
  color: #336d89;
  border: 4px solid #e7f8ff;
  box-shadow: 0 12px 35px rgba(21,79,109,.22);
}

.panel-icon {
  position: absolute;
  top: -34px;
  left: 50%;
  width: 74px;
  height: 74px;
  transform: translateX(-50%) rotate(-6deg);
  filter: drop-shadow(0 8px 10px rgba(21,79,109,.22));
}

.panel h2 {
  margin: 0;
  font-size: 29px;
}

.panel button {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  border: none;
  font-size: 16px;
  cursor: pointer;
}

#retryBtn {
  background: #58bde9;
  color: #fff;
  font-weight: 700;
}

#backToSelectBtn {
  background: #f2fbff;
  color: #4d89a5;
  border: 1px solid #bde4f4;
}

#bestScoreLine {
  margin: 6px 0 0;
  font-size: 14px;
  font-weight: 800;
  color: #6b9cb2;
}

#bestScoreLine.record {
  color: #f0932b;
}

/* 触屏拇指区：只有竖屏 + 触屏才出现，把「挥击」挪到够得着的地方 */
#touchControls {
  display: none;
  width: 100%;
  justify-content: center;
  padding: 6px 0 2px;
}

#attackBtnTouch {
  width: min(58vw, 260px);
  min-height: 54px;
  border: none;
  border-radius: 27px;
  background: #ffd166;
  color: #7a4c12;
  font: 800 17px/1 inherit;
  cursor: pointer;
  box-shadow: 0 4px 0 #e0a93a, 0 10px 20px rgba(122, 76, 18, .18);
}

#attackBtnTouch:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #e0a93a;
}

body[data-input="touch"] #attackBtnTouch { -webkit-touch-callout: none; }

/* 竖屏提示：不挡操作，自己消失 */
#portraitTip {
  position: fixed;
  z-index: 35;
  left: 50%;
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 74px);
  transform: translateX(-50%);
  max-width: 88vw;
  padding: 9px 15px;
  border-radius: 18px;
  background: rgba(31, 74, 99, .82);
  color: #eaf7ff;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  animation: tipFloat .5s ease-out;
}

@keyframes tipFloat {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* 提示条（iOS 全屏引导等） */
#toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  top: max(14px, env(safe-area-inset-top));
  transform: translateX(-50%);
  max-width: min(420px, 88vw);
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(31, 74, 99, .94);
  color: #eaf7ff;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 10px 28px rgba(20, 55, 75, .3);
}

/* 全屏时铺满、去掉圆角阴影 */
#app:fullscreen,
#app:-webkit-full-screen {
  background: #bfe8fb;
}

#app:fullscreen #gameCanvas,
#app:-webkit-full-screen #gameCanvas {
  border-radius: 10px;
}

#fsBtn {
  background: #fff;
  color: #44809b;
  border: 1px solid #b2dce9;
  border-radius: 18px;
  min-width: 40px;
  min-height: 34px;
  padding: 6px 11px;
  cursor: pointer;
  font-size: 15px;
}

/* 竖屏 + 触屏：显示拇指区按钮，提示条上移一点 */
@media (orientation: portrait) and (pointer: coarse) {
  #touchControls { display: flex; }
  #portraitTip { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 132px); }
  /* HUD 顶到上面、画布占中间、挥击按钮压到下面，竖着的空间用起来 */
  #gameScreen { justify-content: flex-start; }
  #hud { margin-top: 4vh; }
  #gameCanvas { margin-top: auto; margin-bottom: auto; }
  #touchControls { margin-top: 0; padding-bottom: max(3vh, env(safe-area-inset-bottom)); }
}

@media (max-width: 560px) {
  #app { align-items: flex-start; overflow-y: auto; }
  .screen { padding: 22px 18px 30px; }
  .site-header { margin-bottom: 28px; }
  .header-tag { display: none; }
  .lead { margin-bottom: 22px; }
  .char-cards { gap: 13px; flex-wrap: nowrap; }
  .char-cards { gap: 8px; }
  /* 三张卡并排：按屏宽三等分（两侧各 18px 边距 + 两个 8px 间隙） */
  .char-card { width: calc((100vw - 36px - 16px) / 3); max-width: 215px; padding: 8px 5px 10px; border-radius: 16px; }
  .portrait-wrap { height: 100px; border-radius: 12px; }
  .char-portrait { width: 92px; height: 92px; }
  .card-ribbon { top: 8px; right: -44px; font-size: 7px; }
  #gameScreen { justify-content: center; }
  #gameCanvas { border-width: 4px; border-radius: 15px; }
  #hud { margin-bottom: 6px; }
  #attackBtn kbd { display: none; }
  #bestLabel { padding: 7px 10px; font-size: 12px; }
  /* 触屏：按钮给足点击面积 */
  #switchBtn, #muteBtn, #attackBtn { min-height: 40px; padding: 9px 12px; }
  /* 屏幕窄就只留箭头，HUD 不换行 */
  .btn-label { display: none; }
  #hud { gap: 6px; }
  .hud-left, .hud-right { gap: 6px; }
  #milestone { height: 22px; font-size: 17px; margin: 2px 0 -4px; }
}

/* 横屏手机：屏幕矮，把画布顶到最大，提示文字让位 */
@media (orientation: landscape) and (max-height: 560px) {
  .screen { padding: 12px 16px; }
  .site-header { margin-bottom: 14px; }
  #selectScreen h1 { font-size: clamp(22px, 4.4vh, 32px); }
  .lead { margin: 6px 0 14px; font-size: 13px; }
  .char-cards { gap: 16px; }
  .char-card { width: min(30vw, 210px); padding: 8px 8px 10px; }
  .portrait-wrap { height: 21vh; min-height: 84px; }
  .char-portrait { width: 19vh; height: 19vh; }
  .hint { margin-top: 12px; }
  #gameScreen { gap: 0; }
  #hud { margin-bottom: 4px; font-size: 14px; }
  #scoreLabel, #bestLabel { padding: 5px 11px; }
  #tip { display: none; }
  #milestone { height: 20px; font-size: 16px; margin: 0; }
  .panel { padding: 30px 26px 20px; }
  .panel-icon { width: 58px; height: 58px; top: -28px; }
  .panel h2 { font-size: 24px; }
}

@media (orientation: landscape) and (max-height: 560px) {
  #gameCanvas { width: min(100%, 800px, calc((100dvh - 76px) * 8 / 3)); }
}


