* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #eef6ea;
  color: #23412b;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; cursor: pointer; border: none; border-radius: 10px; }
.hidden { display: none !important; }

.screen { display: none; max-width: 600px; margin: 0 auto; padding: 16px; }
.screen.active { display: block; }

/* 菜单 */
#menu h1 { text-align: center; margin: 12px 0 4px; font-size: 32px; }
.sub { text-align: center; margin: 0 0 20px; color: #5d7a63; }
.field { margin-bottom: 18px; }
.field > label, .field > .label { display: block; font-weight: 600; margin-bottom: 8px; }
select { width: 100%; padding: 10px; font-size: 16px; border-radius: 10px; border: 2px solid #b9d6b0; background: #fff; }
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; padding: 10px 6px; background: #fff; border: 2px solid #b9d6b0; color: #23412b;
  font-size: 16px; display: flex; flex-direction: column; align-items: center;
}
.seg button small { font-size: 12px; color: #7a947f; margin-top: 2px; }
.seg button.on { border-color: #3c9d4e; background: #dff2d8; font-weight: 600; }
#unit-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.unit-btn {
  padding: 14px 12px; background: #fff; border: 2px solid #b9d6b0; text-align: left; color: #23412b;
}
.unit-btn:hover { border-color: #3c9d4e; }
.unit-btn .t { font-weight: 600; }
.unit-btn .s { font-size: 13px; color: #7a947f; margin-top: 4px; }
.tip { font-size: 13px; color: #7a947f; text-align: center; }

/* 游戏 */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
#unit-name { font-weight: 600; }
#hearts { font-size: 20px; letter-spacing: 2px; }
.ghost { background: #fff; border: 2px solid #b9d6b0; padding: 8px 14px; color: #23412b; }
.ghost.small { padding: 4px 10px; font-size: 14px; }
.primary { background: #3c9d4e; color: #fff; padding: 12px 20px; font-size: 17px; font-weight: 600; }

.prompt {
  background: #fff; border-radius: 14px; padding: 12px 14px; margin-bottom: 10px;
  text-align: center; position: relative; min-height: 110px;
}
.prompt-meta { font-size: 13px; color: #7a947f; display: flex; justify-content: center; gap: 8px; }
.tag { background: #ffb347; color: #fff; padding: 0 8px; border-radius: 8px; }
#prompt-cn { font-size: 26px; font-weight: 700; margin: 4px 0; min-height: 34px; }
#prompt-word { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 30px; letter-spacing: 6px; min-height: 40px; }
#prompt-word .done { color: #3c9d4e; }
#prompt-word .next { color: #e07b00; text-decoration: underline; }
#prompt-word .todo { color: #b5c4b8; }
#prompt-word .hintch { color: #e07b00; opacity: .6; }
#btn-speak { position: absolute; right: 10px; top: 10px; }

.board-wrap { position: relative; }
#board { width: 100%; display: block; border-radius: 14px; touch-action: none; background: #fff; }
#board-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 700; color: #fff; background: rgba(35, 65, 43, .45); border-radius: 14px;
}

.controls { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.dpad { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(2, 46px); gap: 6px; }
.dpad button { background: #fff; border: 2px solid #b9d6b0; font-size: 18px; color: #3c9d4e; }
.dpad [data-dir="up"] { grid-column: 2; grid-row: 1; }
.dpad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad [data-dir="down"] { grid-column: 2; grid-row: 2; }
.dpad [data-dir="right"] { grid-column: 3; grid-row: 2; }
@media (hover: hover) and (pointer: fine) { .dpad { display: none; } }

/* 弹层 */
.overlay {
  position: fixed; inset: 0; background: rgba(20, 40, 25, .5);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10;
}
.panel {
  background: #fff; border-radius: 18px; padding: 24px; width: 100%; max-width: 400px; text-align: center;
  animation: pop .25s ease-out;
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.card-good { color: #3c9d4e; font-weight: 700; }
#card-en { font-size: 44px; font-weight: 800; margin: 8px 0 0; letter-spacing: 2px; }
#card-ph { color: #7a947f; font-size: 18px; }
#card-cn { font-size: 24px; margin: 8px 0 12px; }
.card-ex { background: #f3f9f0; border-radius: 12px; padding: 10px; margin-bottom: 14px; }
#card-ex { font-size: 17px; }
#card-excn { font-size: 14px; color: #7a947f; margin-top: 4px; }
.row { display: flex; gap: 10px; justify-content: center; margin-bottom: 14px; }
#card-next { width: 100%; }
#result-title { font-size: 26px; font-weight: 800; }
#result-stars { font-size: 40px; margin: 8px 0; letter-spacing: 6px; }
#result-detail { color: #5d7a63; margin-bottom: 10px; }
#result-wrong { text-align: left; background: #fff6ec; border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; font-size: 15px; }
#result-wrong:empty { display: none; }
#result-wrong b { color: #e07b00; }

/* 奖励 */
.hud { display: flex; align-items: center; gap: 10px; }
#score { font-weight: 700; color: #e07b00; }
#card-reward { color: #e0447a; font-weight: 700; margin-top: 4px; min-height: 22px; }
#result-score { margin-bottom: 10px; }
#result-score b { color: #e07b00; }
.unlock { margin-top: 8px; padding: 8px; background: #fff0f6; color: #c4306a; border-radius: 10px; font-weight: 700; }
.field .label small { font-weight: 400; color: #e07b00; margin-left: 6px; }
#skin-list { display: flex; gap: 8px; flex-wrap: wrap; }
.skin-btn {
  flex: 1; min-width: 92px; padding: 8px 6px; background: #fff; border: 2px solid #b9d6b0; color: #23412b;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 14px;
}
.skin-btn .sw { width: 34px; height: 14px; border-radius: 7px; }
.skin-btn small { font-size: 12px; color: #7a947f; }
.skin-btn.on { border-color: #3c9d4e; background: #dff2d8; font-weight: 600; }
.skin-btn.locked { opacity: .55; cursor: default; }

/* 多教材 */
.book-pick { display: grid; grid-template-columns: 3fr 2fr; gap: 10px; }
#book-info { font-weight: 400; color: #7a947f; margin-left: 6px; }
#unit-list { grid-template-columns: 1fr; }
.unit-card { background: #fff; border: 2px solid #b9d6b0; border-radius: 12px; padding: 10px 12px; }
.unit-card .t { font-weight: 600; }
.unit-card .s { font-size: 13px; color: #7a947f; margin: 2px 0 8px; }
.levels { display: flex; flex-wrap: wrap; gap: 6px; }
.level-btn {
  background: #f3f9f0; border: 2px solid #cfe5c7; color: #23412b; padding: 6px 10px; font-size: 14px;
  display: flex; flex-direction: column; align-items: center; min-width: 64px;
}
.level-btn:hover { border-color: #3c9d4e; }
.level-btn small { font-size: 11px; color: #e0a000; letter-spacing: 1px; }
.loading { color: #7a947f; padding: 12px; text-align: center; }
#prompt-cn.long { font-size: 18px; font-weight: 600; }
#prompt-word .fixed { color: #23412b; }
#card-note { color: #7a947f; font-size: 14px; margin: -6px 0 10px; }
#card-note:empty, .card-ex.empty { display: none; }
#prompt-word.long { font-size: 22px; letter-spacing: 3px; }

/* 记忆曲线 */
.mem-panel {
  background: #fff; border: 2px solid #b9d6b0; border-radius: 14px; padding: 12px 14px; margin-bottom: 18px;
  display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center;
}
.mem-head { font-weight: 700; grid-column: 1 / -1; }
.mem-stats { display: flex; gap: 18px; }
.mem-stats div { display: flex; flex-direction: column; align-items: center; }
.mem-stats b { font-size: 24px; color: #3c9d4e; line-height: 1.1; }
.mem-stats div:first-child b { color: #e07b00; }
.mem-stats span { font-size: 12px; color: #7a947f; }
#btn-review { padding: 10px 14px; font-size: 15px; }
#btn-review:disabled { background: #cfd8cc; cursor: default; }
#mem-next { grid-column: 1 / -1; font-size: 13px; color: #7a947f; }
#card-mem { font-size: 13px; color: #5d7a63; margin-top: 4px; min-height: 18px; }
#card-mem .dots { color: #3c9d4e; letter-spacing: 1px; }
#result-mem { color: #3c7d9d; font-size: 14px; margin-bottom: 10px; }
#result-mem:empty { display: none; }

/* 加速 */
.ctl-left { display: flex; align-items: center; gap: 10px; }
.key-tip { font-size: 13px; color: #7a947f; }
.boost {
  display: none; background: #fff3d6; border: 2px solid #f0b13c; color: #8a4b00; font-size: 22px;
  width: 78px; height: 78px; border-radius: 50%; flex-direction: column; align-items: center; justify-content: center;
  -webkit-touch-callout: none; touch-action: none;
}
.boost small { font-size: 11px; }
.boost.on { background: #f0b13c; color: #fff; transform: scale(.95); }

/* 游戏页铺满一屏：棋盘按剩余空间缩放 */
body.in-game { overflow: hidden; overscroll-behavior: none; }
#game.active {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
#game .topbar, #game .prompt, #game .controls { flex: none; }
.board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; touch-action: none; }
.board-inner { position: relative; }
#board { width: 100%; height: 100%; }
#unit-name { flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 8px; }
.panel { max-height: 92vh; max-height: 92dvh; overflow-y: auto; }

/* 触屏设备：显示方向键和加速键 */
@media (pointer: coarse) {
  .dpad { display: grid; grid-template-columns: repeat(3, 60px); grid-template-rows: repeat(2, 54px); }
  .dpad button { font-size: 22px; }
  .boost { display: flex; }
  .key-tip { display: none; }
  .ctl-left { flex-direction: row-reverse; }
}
@media (pointer: fine) { .boost { display: none; } }

/* 矮屏幕（手机）压缩提示区 */
@media (max-height: 760px), (max-width: 480px) {
  .screen { padding: 10px 12px; }
  #game .topbar { margin-bottom: 6px; }
  #game .ghost { padding: 5px 10px; }
  .prompt { padding: 8px 10px; min-height: 0; margin-bottom: 6px; }
  #prompt-cn { font-size: 20px; min-height: 26px; margin: 2px 0; }
  #prompt-word { font-size: 24px; letter-spacing: 4px; min-height: 30px; }
  #btn-speak { top: 6px; right: 6px; }
  .controls { margin-top: 6px; }
  #menu h1 { font-size: 26px; margin-top: 4px; }
  .panel { padding: 18px 16px; }
  #card-en { font-size: 34px; }
}

/* 双人对战 */
.dpad-p2 { display: none !important; }
.row-p { display: flex; align-items: center; justify-content: center; gap: 2px; line-height: 1.25; }
.row-p .dot { width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; flex: none; }
#score span { font-weight: 800; }
@media (pointer: coarse) {
  /* 双人：两组方向键分在两边，中间是暂停；加速键单人才有 */
  body.versus .dpad-p2 { display: grid !important; }
  body.versus .boost { display: none; }
  body.versus .controls { justify-content: space-between; }
  body.versus .dpad-p1 { order: -1; } /* 玩家1 的蛇在左边，方向键也放左边 */
  body.versus .dpad { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(2, 46px); }
}
@media (pointer: coarse) {
  body.versus .dpad-p1 button { border-color: var(--p1); color: var(--p1); }
  body.versus .dpad-p2 button { border-color: var(--p2); color: var(--p2); }
}
@media (pointer: coarse) and (max-width: 480px) {
  body.versus .dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(2, 40px); gap: 4px; }
}
