/* ============ 亲子象棋 全局样式 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: linear-gradient(160deg, #f7e9cd 0%, #efd7a7 55%, #e6c48a 100%);
  color: #5a3a1a;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 700px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- 顶栏 ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 4px;
}
.title { font-size: 18px; font-weight: 800; letter-spacing: 1px; color: #6b4218; text-shadow: 0 1px 0 rgba(255,255,255,.6); }
#turn-info { display: flex; align-items: center; gap: 7px; font-size: 15px; font-weight: 700; color: #7a4a21; }
#turn-check { font-size: 13px; color: #e2402a; font-weight: 800; animation: blink 0.6s infinite alternate; }
@keyframes blink { from { opacity: .5; } to { opacity: 1; } }
.turn-dot { width: 13px; height: 13px; border-radius: 50%; box-shadow: 0 0 6px rgba(0,0,0,.3); }
.turn-dot.red { background: radial-gradient(circle at 35% 30%, #ffb46b, #e2482a); }
.turn-dot.black { background: radial-gradient(circle at 35% 30%, #7a8df5, #2c3e8c); }
.icon-btn {
  border: none; border-radius: 999px; padding: 5px 11px;
  font-size: 12px; font-weight: 700; color: #7a4a21; cursor: pointer;
  background: rgba(255,255,255,.55); box-shadow: 0 1px 3px rgba(90,50,10,.25);
  transition: all .2s;
}
.icon-btn.active { background: #6b4218; color: #ffe9c2; }
.icon-btn:active { transform: scale(.94); }
#top-btns { display: flex; gap: 6px; }

/* ---------- 统计栏 ---------- */
#statsbar {
  display: flex; align-items: center; justify-content: space-around;
  padding: 4px 10px 6px;
  font-size: 12px; font-weight: 700; color: #7a4a21;
  background: rgba(255,255,255,.35);
  border-radius: 10px;
  margin: 0 12px 2px;
  gap: 6px;
  flex-wrap: wrap;
}
.stat-move {
  font-size: 13px; color: #e2482a; font-weight: 800;
  min-width: 70px; text-align: center;
}

/* ---------- 棋谱面板 ---------- */
#movelist {
  position: fixed; inset: 0; z-index: 45;
  display: flex; flex-direction: column;
  background: rgba(60, 30, 5, .45);
  backdrop-filter: blur(3px);
  padding-top: 10vh;
  align-items: center;
}
#movelist.hidden { display: none; }
.ml-header {
  display: flex; align-items: center; justify-content: space-between;
  width: min(92vw, 420px);
  padding: 10px 16px;
  background: linear-gradient(160deg, #fff3d9, #ffe4ae);
  border-radius: 14px 14px 0 0;
  font-weight: 900; color: #6b4218;
}
#ml-body {
  width: min(92vw, 420px);
  max-height: 55vh;
  overflow-y: auto;
  background: rgba(255, 244, 222, .97);
  border-radius: 0 0 14px 14px;
  padding: 8px 12px;
}
.ml-row {
  display: grid; grid-template-columns: 36px 1fr 1fr;
  padding: 5px 6px; font-size: 14px; font-weight: 700; color: #6b4218;
  border-bottom: 1px dashed rgba(122, 74, 33, .18);
}
.ml-row:last-child { border-bottom: none; }
.ml-no { color: #a97b45; font-size: 12px; }
.ml-red { color: #c0392b; }
.ml-black { color: #2c3e8c; }

/* ---------- 棋盘：尽量撑满剩余空间 ---------- */
#board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 4px 6px;
}
#board {
  position: relative;
  /* 去掉 520px 硬上限，只受视口宽高约束，让棋盘尽量大 */
  width: min(98vw, 98%, calc((100dvh - 150px) * 0.92));
  aspect-ratio: 9 / 10;
  background:
    radial-gradient(ellipse at 30% 20%, #f4cc88 0%, #e3af63 55%, #ce9246 100%);
  border-radius: 10px;
  box-shadow:
    0 8px 24px rgba(90, 50, 10, .35),
    inset 0 2px 6px rgba(255,255,255,.35),
    inset 0 -4px 10px rgba(90,50,10,.25);
  transition: transform .45s cubic-bezier(.4,.1,.3,1.1);
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
}
#board.flipped { transform: rotate(180deg); }
#board-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- 横屏适配 ---------- */
@media (orientation: landscape) {
  #app { max-width: none; }
  #topbar { padding: 4px 12px 2px; }
  #statsbar { padding: 2px 8px 4px; font-size: 11px; margin: 0 8px 1px; }
  #controlbar { padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); }
  /* 横屏：棋盘高度撑满剩余空间，宽度按 9:10 比例自适应 */
  #board {
    width: calc((100dvh - 130px) * 0.94);
    max-width: 92vw;
  }
  #board-wrap { padding: 2px 4px; }
  .title { font-size: 16px; }
}

#promo-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 6; }
#pieces-layer { position: absolute; inset: 0; z-index: 2; }
#fx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* ---------- 棋子：精致玉石/木质质感 ---------- */
.piece {
  position: absolute; left: 0; top: 0;
  width: var(--piece-size); height: var(--piece-size);
  margin-left: calc(var(--piece-size) / -2);
  margin-top: calc(var(--piece-size) / -2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--piece-size) * .44); font-weight: 900;
  z-index: 2;
  will-change: transform;
  cursor: pointer;
  /* 细腻立体感：外投影 + 内侧立体圈 + 内高光 */
  box-shadow:
    0 4px 8px rgba(0,0,0,.4),
    0 1px 2px rgba(0,0,0,.25),
    inset 0 2px 3px rgba(255,255,255,.55),
    inset 0 -4px 8px rgba(0,0,0,.28);
  transition: transform .4s cubic-bezier(.3,.8,.4,1);
}
/* 内环装饰线（用 ::after 画），增强精致度 */
.piece::after {
  content: '';
  position: absolute; inset: 12%;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.28);
  pointer-events: none;
  box-shadow: inset 0 0 6px rgba(0,0,0,.15);
}
.piece.red {
  background:
    radial-gradient(circle at 32% 28%, #ffe7b8 0%, #ffb469 38%, #e96f2e 68%, #c94d18 100%);
  color: #8a2c06;
  border: 2px solid #b0451c;
  text-shadow: 0 1px 0 rgba(255,255,255,.55), 0 -1px 2px rgba(120,30,0,.3);
}
.piece.black {
  background:
    radial-gradient(circle at 32% 28%, #c6cffc 0%, #6a7ad9 40%, #3946a0 68%, #232e7c 100%);
  color: #f6f7ff;
  border: 2px solid #232d6e;
  text-shadow: 0 1px 0 rgba(255,255,255,.25), 0 -1px 2px rgba(0,0,10,.6);
}
.piece.selected {
  z-index: 3;
  box-shadow:
    0 0 0 3px #fff, 0 0 18px rgba(255,255,255,.95),
    0 6px 12px rgba(0,0,0,.35), inset 0 2px 3px rgba(255,255,255,.6);
  filter: brightness(1.08);
}
.piece.in-check {
  z-index: 4;
  animation: checkPulse .55s infinite alternate;
}
@keyframes checkPulse {
  from { box-shadow: 0 0 0 3px rgba(255,60,60,.55), 0 0 12px rgba(255,60,60,.6); }
  to   { box-shadow: 0 0 0 6px rgba(255,60,60,.95), 0 0 18px rgba(255,60,60,.9); }
}
.piece.hit {
  z-index: 1;
  animation: hitAnim .32s forwards;
}
@keyframes hitAnim {
  0%   { transform: scale(1); filter: brightness(1.8); }
  45%  { transform: scale(1.18) rotate(10deg); filter: brightness(2.4); }
  100% { transform: scale(.15) rotate(-24deg); opacity: 0; filter: brightness(3); }
}

/* ---------- 走子提示点 ---------- */
.dot {
  position: absolute;
  width: 13px; height: 13px; border-radius: 50%;
  background: rgba(70, 160, 70, .6);
  box-shadow: 0 0 8px rgba(70,160,70,.7);
  transform: translate(-50%,-50%);
  pointer-events: none;
  z-index: 5;
  animation: dotIn .18s ease-out;
}
@keyframes dotIn { from { transform: translate(-50%,-50%) scale(0); } to { transform: translate(-50%,-50%) scale(1); } }
.dot-capture {
  width: 17px; height: 17px;
  background: rgba(226, 60, 40, .65);
  box-shadow: 0 0 10px rgba(226,60,40,.85);
}
.dot.hint-dot {
  width: 10px; height: 10px;
  background: rgba(255,255,255,.55);
  box-shadow: 0 0 5px rgba(255,255,255,.7);
}

/* ---------- 特效元素 ---------- */
.pop {
  position: absolute;
  transform: translate(-50%,-50%);
  font-weight: 900; font-size: 26px; color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,.45), -1px -1px 0 rgba(0,0,0,.3), 1px 1px 0 rgba(0,0,0,.3);
  pointer-events: none; white-space: nowrap;
  animation: popUp .65s ease-out forwards;
}
.pop-hit {
  color: #ffd23f; font-size: 32px;
  text-shadow: 0 0 14px rgba(255,120,40,.9), 0 2px 6px rgba(0,0,0,.5);
}
.pop-win { font-size: 22px; color: #7ff0a0; }
@keyframes popUp {
  0%   { opacity: 0; transform: translate(-50%,-50%) scale(.3); }
  22%  { opacity: 1; transform: translate(-50%,-70%) scale(1.25); }
  100% { opacity: 0; transform: translate(-50%,-170%) scale(1); }
}
.aim-line {
  position: absolute; height: 4px;
  background: linear-gradient(90deg, rgba(255,120,60,.95), rgba(255,210,63,.25));
  border-radius: 4px;
  transform-origin: 0 50%;
  box-shadow: 0 0 10px rgba(255,140,60,.9);
  pointer-events: none;
  z-index: 6;
}
.bullet {
  position: absolute;
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6c8, #ffb347 50%, #ff6b2a 100%);
  box-shadow: 0 0 20px rgba(255,150,50,1), 0 0 40px rgba(255,120,40,.6);
  pointer-events: none; z-index: 7;
}

/* ---------- 震动 ---------- */
#board-wrap.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translate(0,0); }
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(5px, -4px); }
  60% { transform: translate(-3px, -3px); }
  80% { transform: translate(4px, 4px); }
}
#board-wrap.shake-strong { animation: shakeStrong .5s; }
@keyframes shakeStrong {
  0%, 100% { transform: translate(0,0) scale(1); }
  15% { transform: translate(-10px, 5px) scale(1.01); }
  30% { transform: translate(8px, -7px) scale(1.02); }
  45% { transform: translate(-6px, -5px) scale(1.01); }
  60% { transform: translate(7px, 6px) scale(1.02); }
  80% { transform: translate(-4px, 3px) scale(1.01); }
}

/* ---------- 全屏闪光 ---------- */
#flash {
  position: fixed; inset: 0; z-index: 40;
  background: #fff; pointer-events: none;
  opacity: 0;
}
#flash.on { animation: flashAnim .4s ease-out forwards; }
@keyframes flashAnim {
  0%   { opacity: .85; }
  100% { opacity: 0; }
}

/* ---------- 底栏按钮 ---------- */
#controlbar {
  display: flex; flex-direction: column; gap: 6px;
  padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
}
.ctrl-row { display: flex; gap: 6px; justify-content: center; }
.ctrl-btn {
  flex: 1; max-width: 92px;
  border: none; border-radius: 12px;
  padding: 9px 0; font-size: 13px; font-weight: 700;
  color: #6b4218; cursor: pointer;
  background: rgba(255,255,255,.65);
  box-shadow: 0 2px 5px rgba(90,50,10,.28), inset 0 1px 0 rgba(255,255,255,.7);
  transition: all .15s;
}
.ctrl-btn:active { transform: scale(.95); box-shadow: 0 1px 2px rgba(90,50,10,.3); }
.ctrl-btn.active { background: #ffd23f; color: #6b4218; }

/* ---------- 结束弹窗 ---------- */
#overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(60, 30, 5, .45);
  backdrop-filter: blur(3px);
}
#overlay.hidden { display: none; }
.overlay-card {
  background: linear-gradient(160deg, #fff3d9, #ffe4ae);
  border-radius: 24px;
  padding: 34px 46px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(60,30,5,.5);
  animation: cardIn .45s cubic-bezier(.2,1.4,.4,1);
}
@keyframes cardIn { from { transform: scale(.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#overlay-emoji { font-size: 56px; margin-bottom: 6px; }
#overlay-title { font-size: 28px; font-weight: 900; color: #6b4218; margin-bottom: 6px; }
#overlay-sub { font-size: 15px; color: #9a6a33; margin-bottom: 22px; }
#overlay-btns { display: flex; gap: 12px; justify-content: center; }
#btn-restart {
  border: none; border-radius: 999px; padding: 12px 28px;
  font-size: 16px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, #ff8a3c, #e2482a);
  box-shadow: 0 5px 14px rgba(226,72,42,.45);
  cursor: pointer;
}
#btn-restart:active { transform: scale(.95); }
.btn-secondary {
  border: 2px solid #b0451c; border-radius: 999px; padding: 10px 24px;
  font-size: 15px; font-weight: 800; color: #b0451c;
  background: #fff3d9; cursor: pointer;
}
.btn-secondary:active { transform: scale(.95); }

/* ========== 复盘控制条 ========== */
#repctrl {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 108px; z-index: 40;
  width: min(94vw, 480px);
  background: linear-gradient(160deg, #fff3d9, #ffe4ae);
  border-radius: 18px;
  padding: 10px 12px 12px;
  box-shadow: 0 10px 30px rgba(60,30,5,.4);
  animation: cardIn .35s cubic-bezier(.2,1.4,.4,1);
}
#repctrl.hidden { display: none; }
.rep-head { font-size: 13px; font-weight: 800; color: #6b4218; text-align: center; margin-bottom: 6px; }
.rep-body { display: flex; align-items: center; gap: 6px; }
.rep-btn {
  border: none; border-radius: 10px; padding: 7px 9px;
  font-size: 14px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, #ff8a3c, #e2482a);
  box-shadow: 0 2px 6px rgba(226,72,42,.4);
  cursor: pointer; flex-shrink: 0;
}
.rep-btn:active { transform: scale(.93); }
.rep-btn.rep-exit { background: linear-gradient(135deg, #9a9a9a, #6a6a6a); box-shadow: 0 2px 6px rgba(0,0,0,.3); }
#rep-slider { flex: 1; min-width: 60px; accent-color: #e2482a; }
#rep-label { font-size: 12px; font-weight: 700; color: #9a6a33; flex-shrink: 0; }

/* ========== 弹层系统 ========== */
#modal-root { position: fixed; inset: 0; z-index: 60; display: none; }
#modal-root.open { display: block; }
.modal-mask { position: absolute; inset: 0; background: rgba(50, 25, 5, .5); backdrop-filter: blur(3px); }
.modal {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(92vw, 460px); max-height: 86vh; overflow-y: auto;
  background: linear-gradient(170deg, #fff8e8, #ffe9c2);
  border-radius: 22px;
  padding: 16px 18px 20px;
  box-shadow: 0 18px 50px rgba(60,30,5,.55);
  animation: cardIn .4s cubic-bezier(.2,1.4,.4,1);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { font-size: 19px; font-weight: 900; color: #6b4218; margin: 0; }
.modal-head h3 em { font-style: normal; font-size: 13px; color: #b0451c; }
.modal-x {
  border: none; border-radius: 999px; width: 30px; height: 30px;
  font-size: 14px; font-weight: 800; color: #7a4a21;
  background: rgba(255,255,255,.7); cursor: pointer;
}
.modal-x:active { transform: scale(.92); }

/* 模式选择 */
.mode-modal .modal-body { display: flex; flex-direction: column; gap: 10px; }
.mode-card {
  display: flex; align-items: center; gap: 12px;
  border: none; border-radius: 16px; padding: 13px 16px;
  text-align: left; cursor: pointer;
  background: rgba(255,255,255,.75);
  box-shadow: 0 2px 6px rgba(90,50,10,.2), inset 0 1px 0 rgba(255,255,255,.8);
  transition: all .15s;
}
.mode-card:active { transform: scale(.97); }
.mode-ico { font-size: 30px; }
.mode-name { font-size: 16px; font-weight: 900; color: #6b4218; display: block; }
.mode-sub { font-size: 12px; color: #9a6a33; display: block; margin-top: 2px; }

/* 残局选关 */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  flex: 1; border: none; border-radius: 999px; padding: 8px 0;
  font-size: 13px; font-weight: 800; color: #9a6a33;
  background: rgba(255,255,255,.6); cursor: pointer;
}
.tab.on { background: #6b4218; color: #ffe9c2; }
.lv-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.lv-card {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  border: 2px solid transparent; border-radius: 14px; padding: 9px 12px;
  text-align: left; cursor: pointer;
  background: rgba(255,255,255,.7);
  box-shadow: 0 2px 5px rgba(90,50,10,.18);
  transition: all .15s;
}
.lv-card:active { transform: scale(.96); }
.lv-card.done { border-color: #6bcb77; background: rgba(190, 245, 190, .45); }
.lv-no { position: absolute; top: 6px; right: 8px; font-size: 11px; font-weight: 800; color: #c9a06a; }
.lv-name { font-size: 14px; font-weight: 900; color: #6b4218; }
.lv-diff { font-size: 10px; font-weight: 700; color: #b0451c; }
.lv-star { font-size: 13px; color: #ffb703; letter-spacing: 1px; }
.lv-ok { position: absolute; top: 4px; right: 30px; font-size: 13px; font-weight: 900; color: #2f9e44; }

/* 教学选关 */
.tut-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tut-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  border: 2px solid transparent; border-radius: 14px; padding: 10px 12px;
  text-align: left; cursor: pointer;
  background: rgba(255,255,255,.7);
  box-shadow: 0 2px 5px rgba(90,50,10,.18);
  transition: all .15s;
}
.tut-card:active { transform: scale(.96); }
.tut-card.done { border-color: #6bcb77; background: rgba(190, 245, 190, .45); }
.tut-ico { font-size: 22px; }
.tut-name { font-size: 14px; font-weight: 900; color: #6b4218; }
.tut-go { font-size: 11px; font-weight: 800; color: #b0451c; }
.tut-card.done .tut-go { color: #2f9e44; }

/* 战绩面板 */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: rgba(255,255,255,.75); border-radius: 14px; padding: 10px 6px; text-align: center; box-shadow: 0 2px 4px rgba(90,50,10,.15); }
.stat b { display: block; font-size: 22px; font-weight: 900; color: #6b4218; }
.stat.red b { color: #d43a2f; }
.stat.black b { color: #3b4a6b; }
.stat span { font-size: 11px; font-weight: 700; color: #9a6a33; }
.stat-prog { background: rgba(255,255,255,.6); border-radius: 12px; padding: 10px 12px; font-size: 13px; font-weight: 700; color: #6b4218; line-height: 1.8; margin-bottom: 12px; }
.ach-title { font-size: 15px; font-weight: 900; color: #6b4218; margin: 4px 0 8px; }
.ach-title em { font-style: normal; font-size: 12px; color: #b0451c; }
.ach-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.ach {
  display: flex; flex-direction: column; gap: 2px;
  background: rgba(255,255,255,.65); border-radius: 12px; padding: 8px 10px;
  border: 2px solid transparent;
}
.ach.got { border-color: #ffd23f; background: rgba(255, 210, 63, .18); }
.ach.no { opacity: .55; }
.ach-ico { font-size: 20px; }
.ach-name { font-size: 13px; font-weight: 900; color: #6b4218; }
.ach-desc { font-size: 10px; color: #9a6a33; }

/* ========== 轻提示 toast ========== */
#toast {
  position: fixed; left: 50%; top: 18%; transform: translate(-50%, -8px);
  z-index: 80; max-width: 86vw;
  background: rgba(60, 30, 5, .88); color: #ffe9c2;
  border-radius: 999px; padding: 9px 20px;
  font-size: 14px; font-weight: 800;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ========== 教学目标星星 ========== */
.target-star {
  position: absolute; transform: translate(-50%, -50%);
  font-size: calc(var(--cell, 38px) * 0.62);
  color: #ffd23f; text-shadow: 0 0 8px rgba(255, 210, 63, .9), 0 0 18px rgba(255, 170, 0, .6);
  pointer-events: none; z-index: 5;
  animation: starPulse 1.2s ease-in-out infinite;
}
.target-star.cur { animation: starPulse 1s ease-in-out infinite; }
.target-star.got { color: #6bcb77; text-shadow: 0 0 6px rgba(107, 203, 119, .8); animation: none; }
@keyframes starPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.28); }
}
