* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overscroll-behavior: none;
}
body {
  display: flex;
  justify-content: center;
  background: #272b3d;
  font-family: Arial, "Microsoft YaHei", "PingFang SC", sans-serif;
  color: #fff;
}
button,
input {
  font: inherit;
}
button {
  cursor: pointer;
  border: 0;
  background: none;
  color: inherit;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
button:active {
  transform: scale(0.96);
}
button:focus-visible {
  outline: 2px solid #7ed6c4;
  outline-offset: 3px;
}
[hidden] {
  display: none !important;
}
#game {
  width: min(100%, 480px);
  height: 100dvh;
  max-height: 1040px;
  display: flex;
  flex-direction: column;
  background: #3c415b;
  overflow: hidden;
  position: relative;
  border-radius: 5px;
}
header {
  flex: 0 0 64px;
  height: 64px;
  position: relative;
  border-bottom: 2px solid #656b88;
}
.header-tools {
  position: absolute;
  top: 7px;
  left: 13.4%;
  display: flex;
  gap: 13px;
  align-items: center;
}
.icon {
  width: 33px;
  height: 33px;
}
/* 游戏页 header 右上角的「关卡地图」链接 */
.map-link-top {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  color: #7db8e8;
  text-decoration: none;
  font-size: 13px;
  line-height: 1;
  padding: 7px 14px;
  border: 1px solid #3a3f5c;
  border-radius: 14px;
  background: rgba(43, 47, 68, 0.85);
  transition: background 0.12s ease, color 0.12s ease;
}
.map-link-top:hover {
  background: #353a55;
  color: #a9d3f5;
}
.map-link-top:active {
  background: #2b2f44;
}
.icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#theme-toggle {
  width: 55px;
  height: 27px;
  border-radius: 20px;
  background: #5983b8;
  position: relative;
}
#theme-toggle img {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 19px;
  height: 19px;
  object-fit: contain;
}
#theme-toggle:after {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #4c5ca0;
  z-index: 0;
}
#theme-toggle img {
  z-index: 1;
}
.level-status {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  flex-direction: column;
}
.level-status strong {
  font-size: 20px;
  font-weight: 800;
  height: 22px;
  line-height: 22px;
  white-space: nowrap;
}
#hearts {
  display: flex;
  gap: 2px;
  height: 20px;
  align-items: center;
}
#hearts img {
  width: 20px;
  height: 19px;
  object-fit: contain;
}
.clock {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
  font-size: 16px;
  line-height: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.clock img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}
#play {
  position: relative;
  flex: 1;
  min-height: 100px;
  overflow: hidden;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}
footer {
  flex: 0 0 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 2px solid #656b88;
  gap: 10px;
  padding: 5px 9.5% 4px 11%;
  background: #3c415b;
}
#ads {
  flex: 0 0 50px;
  height: 50px;
  width: 330px;
  max-width: calc(100% - 20px);
  margin: 6px auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2b2f44;
  border-radius: 6px;
  overflow: hidden;
  text-align: center;
}
#ads .ads-placeholder {
  color: #9aa0c0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
}
body.light-mode #ads {
  background: #e6e8f0;
}
body.light-mode #ads .ads-placeholder {
  color: #6b7090;
}
.tool {
  flex: 0 0 45px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 13px;
  height: 49px;
  justify-content: flex-end;
  white-space: nowrap;
}
.tool-ring {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 43px;
  height: 40px;
  border: 2px solid #438e91;
  border-radius: 50%;
}
.tool-ring > img {
  width: 31px;
  height: 33px;
  object-fit: contain;
}
.tool .add-badge {
  position: absolute;
  width: 14px;
  height: 14px;
  right: -4px;
  top: 1px;
}
.tool#hint .add-badge {
  left: -1px;
  right: auto;
}
.tool[aria-pressed="true"] .tool-ring {
  background: #2e777f;
}
.tool[aria-pressed="true"] .add-badge {
  display: none;
}
.zoom {
  display: flex;
  flex: 1;
  min-width: 80px;
  align-items: center;
  height: 24px;
  gap: 12px;
  border-radius: 14px;
  background: #454965;
  padding: 3px 9px;
  margin-top: -1px;
}
.zoom button {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
}
.zoom img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.zoom input {
  flex: 1;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  height: 7px;
  background: #9aa0af;
  border-radius: 6px;
  margin: 0;
  cursor: pointer;
  touch-action: none;
}
.zoom input::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: #32c6b3;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 0 1px #aaa;
}
.zoom input::-moz-range-thumb {
  width: 8px;
  height: 8px;
  border: 3px solid white;
  background: #32c6b3;
  border-radius: 50%;
}
#toast {
  position: absolute;
  left: 50%;
  bottom: 15px;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  background: #202537dd;
  padding: 9px 18px;
  border-radius: 18px;
  font-size: 14px;
  white-space: nowrap;
  transition: opacity 0.2s;
}
#toast.visible {
  opacity: 1;
}
body.light-mode #game,
body.light-mode footer {
  background: #f4f5fa;
  color: #353b56;
}
body.light-mode .zoom {
  background: #dce2f0;
}
body.light-mode #theme-toggle img {
  right: 30px;
}
body.light-mode #theme-toggle:after {
  right: 28px;
}
body.light-mode .clock img {
  filter: brightness(0.5);
}
dialog {
  padding: 0;
  width: min(88vw, 360px);
  border: 3px solid #8cadd6;
  border-radius: 24px;
  background: #f7f8fc;
  color: #444b59;
  box-shadow: 0 12px 0 #344c7322;
  max-height: 85dvh;
}
dialog::backdrop {
  background: #28304680;
}
#modal-content {
  padding: 26px;
  text-align: center;
}
dialog h2 {
  margin: 0 0 18px;
  font-size: 25px;
}
dialog p {
  line-height: 1.8;
  font-size: 15px;
}
dialog .primary,
dialog .secondary {
  display: block;
  width: 100%;
  padding: 13px 14px;
  margin-top: 14px;
  border-radius: 25px;
  font-size: 18px;
  font-weight: bold;
  background: #7aabed;
  color: white;
  box-shadow: 0 4px #5484bf;
}
dialog .secondary {
  background: #e7ebf3;
  color: #6a7483;
  box-shadow: 0 4px #d0d5df;
}
.level-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.level-list button {
  background: #e3eafa;
  border-radius: 12px;
  padding: 15px 5px;
  font-size: 18px;
}
.level-list .current {
  background: #75a2db;
  color: white;
}
.trophy {
  height: 100px;
  width: 100px;
  object-fit: contain;
}
#modal.win-ad {
  width: min(96vw, 396px);
}
#modal.win-ad #modal-content {
  max-height: 80dvh;
  overflow-y: auto;
  padding: 16px 20px;
}
#modal.win-ad .trophy {
  height: 60px;
  width: 60px;
}
#modal.win-ad h2 {
  margin: 0 0 6px;
  font-size: 20px;
}
#modal.win-ad p {
  line-height: 1.35;
  font-size: 13px;
  margin: 0;
}
#modal.win-ad .win-head {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}
#modal.win-ad .win-head-text {
  text-align: left;
}
#ads-win {
  width: 336px;
  max-width: 100%;
  height: 280px;
  margin: 10px auto 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e7ebf3;
  border-radius: 8px;
  overflow: hidden;
}
#ads-win .ads-win-placeholder {
  color: #9aa0c0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 1px;
}
.option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 20px 0;
  font-size: 17px;
}
.option input {
  width: 24px;
  height: 24px;
  accent-color: #729ed6;
}
@media (max-height: 670px) {
  header {
    padding-top: 10px;
  }
  .status {
    padding-top: 5px;
    padding-bottom: 9px;
  }
  footer {
    padding: 8px;
    gap: 33px;
  }
  footer img {
    width: 39px;
    height: 39px;
  }
  .instruction {
    margin: 6px 0;
  }
  .bottom {
    padding-bottom: 8px;
  }
}

.level-list {
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-height: 42dvh;
  overflow: auto;
  padding: 4px;
}
.level-list button {
  padding: 10px 3px;
  font-size: 16px;
}
.level-list .missing {
  background: #edeef2;
  color: #afb4be;
}
.level-list small {
  display: block;
  font-size: 10px;
  margin-top: 3px;
}
.filter {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin: 16px 0;
}
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 17px;
  font-size: 13px;
}
.pagination button:disabled {
  opacity: 0.3;
}
#jump-form {
  display: flex;
  gap: 8px;
}
#jump-stage {
  width: 0;
  flex: 1;
  border: 1px solid #bcc9dc;
  border-radius: 8px;
  padding: 9px;
  font: inherit;
}
.jump-button {
  background: #7aabed;
  color: white;
  border-radius: 8px;
  padding: 9px 16px;
}
.dark-board #play {
  background: #262935;
}
.dark-board .instruction {
  color: #888;
}

.dark-board #play {
  background: #3c415b;
}
body.light-mode #play {
  background: #f4f5fa;
}
@media (min-width: 480px) {
  footer {
    padding-left: 11%;
    padding-right: 9.5%;
  }
}

footer {
  padding-left: 13.4%;
  padding-right: 10%;
}
@media (min-width: 480px) {
  footer {
    padding-left: 13.4%;
    padding-right: 10%;
  }
}

.victory-confetti {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  pointer-events: none;
  z-index: 10;
  cursor: default;
}

/* The game owns gestures; do not select text or move the browser viewport. */
html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}
#game,
#game *,
#modal,
#modal * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#game img,
#modal img {
  -webkit-user-drag: none;
}
#game {
  touch-action: none;
}
#board {
  touch-action: none;
}
#modal {
  touch-action: pan-y;
  overscroll-behavior: contain;
}

/* ===== 关卡地图 map.html ===== */
body.map-page {
  /* 地图页：顶部 header 固定，仅关卡列表区域可滚动；整页内容宽度固定 480 并居中 */
  position: static;
  inset: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: auto;
  touch-action: auto;
  margin: 0;
  background: #20232f;
  color: #e9ecf5;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
/* 根元素 html 不再承担滚动（改为 #map 内部滚动） */
html:has(body.map-page) {
  height: auto;
  overflow: visible;
  overscroll-behavior: auto;
}
#map-wrap {
  width: 480px;
  max-width: 100%;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
}
/* 让关卡列表整体与吸顶头部拉开距离，避免与上方文字（标题/图例）贴在一起 */
#map {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0;
  padding-bottom: 16px;
  scroll-margin-top: 0;
}
/* 细滚动条（Chrome/Edge/Safari） */
#map::-webkit-scrollbar {
  width: 4px;
}
#map::-webkit-scrollbar-track {
  background: transparent;
}
#map::-webkit-scrollbar-thumb {
  background: #5a6bb0;
  border-radius: 2px;
}
#map::-webkit-scrollbar-thumb:hover {
  background: #7385cf;
}
/* 细滚动条（Firefox） */
#map {
  scrollbar-width: thin;
  scrollbar-color: #5a6bb0 transparent;
}
.map-group {
  padding: 0 12px;
}
.map-group h2 {
  font-size: 14px;
  font-weight: 600;
  color: #aab;
  margin: 18px 4px 10px;
  padding-left: 10px;
  border-left: 3px solid #5a6bb0;
}
.map-bar {
  position: relative;
  flex: 0 0 auto;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 12px 20px;
  background: #2b2f44;
  border-bottom: 1px solid #3a3f5c;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  height:120px;
}
.map-bar h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: 1px;
}
.map-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 13px;
  color: #aab;
}
#done-count {
  font-weight: 600;
  color: #7ee0a0;
}
.map-link {
  color: #7db8e8;
  text-decoration: none;
  border: 1px solid #3a3f5c;
  padding: 4px 12px;
  border-radius: 6px;
  transition: background 0.12s ease;
}
.map-link:hover {
  background: #353a55;
}
#filter {
  flex: 1 1 240px;
  min-width: 180px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #3a3f5c;
  background: #1b1e2b;
  color: #e9ecf5;
  font-size: 14px;
}
#filter:focus {
  outline: none;
  border-color: #5a6bb0;
}
.map-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  width: 100%;
  font-size: 12px;
  color: #aab;
  padding-top: 2px;
}
.map-legend .lg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.map-legend .lg::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.map-legend .st-none::before {
  background: #555b78;
}
.map-legend .st-started::before {
  background: #ffcc24;
}
.map-legend .st-lost::before {
  background: #e89292;
}
.map-legend .st-won::before {
  background: #4be084;
}
.map-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 0 4px 12px;
}
.map-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  background: linear-gradient(160deg, #2f3450, #262a3e);
  color: #e9ecf5;
  text-decoration: none;
  font-weight: 600;
  font-size: 18px;
  border: 1px solid #3a3f5c;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.1s ease, background 0.12s ease,
    box-shadow 0.12s ease, border-color 0.12s ease;
}
.map-cell:hover {
  transform: translateY(-3px);
  background: linear-gradient(160deg, #3a4063, #2f3450);
  border-color: #5a6bb0;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  z-index: 2;
}
.map-cell .map-dot {
  display: none;
}
.map-cell::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  font-size: 11px;
  line-height: 17px;
  text-align: center;
  font-weight: 700;
  color: #fff;
}
.map-cell.st-none::after {
  display: none;
}
.map-cell.st-started::after {
  content: "◐";
  background: #e0a32e;
}
.map-cell.st-lost::after {
  content: "✕";
  background: #d4564f;
}
.map-cell.st-won::after {
  content: "✓";
  background: #2f9e63;
}
.map-cell.st-started {
  background: linear-gradient(160deg, #4a4226, #39331f);
  border-color: #7d6a2f;
}
.map-cell.st-lost {
  background: linear-gradient(160deg, #4a2f33, #39252a);
  border-color: #7d3a3a;
}
.map-cell.st-won {
  background: linear-gradient(160deg, #1f4a37, #163a2b);
  border-color: #2f7d57;
}
.map-loading {
  padding: 24px;
  color: #aab;
}

/* 浅色模式 */
body.light-mode.map-page {
  background: #eef1f7;
  color: #1d2333;
}
body.light-mode #map {
  scrollbar-color: #b6c0dd transparent;
}
body.light-mode #map::-webkit-scrollbar-thumb {
  background: #b6c0dd;
}
body.light-mode #map::-webkit-scrollbar-thumb:hover {
  background: #96a4cd;
}
body.light-mode .map-bar {
  background: #ffffff;
  border-color: #e2e6ef;
}
body.light-mode #done-count {
  color: #1f9e63;
}
body.light-mode .map-link {
  color: #2b7cc4;
  border-color: #d4dae6;
}
body.light-mode .map-link:hover {
  background: #f1f4fa;
}
body.light-mode .map-link-top {
  color: #2b7cc4;
  border-color: #d4dae6;
  background: rgba(255, 255, 255, 0.85);
}
body.light-mode .map-link-top:hover {
  background: #f1f4fa;
  color: #1d5fa0;
}
body.light-mode #filter {
  background: #f5f7fb;
  border-color: #d4dae6;
  color: #1d2333;
}
body.light-mode .map-legend {
  color: #66708a;
}
body.light-mode .map-cell {
  background: linear-gradient(160deg, #ffffff, #f3f5fb);
  color: #1d2333;
  border-color: #dde2ec;
  box-shadow: 0 1px 2px rgba(20, 30, 60, 0.08);
}
body.light-mode .map-cell:hover {
  background: linear-gradient(160deg, #f7f9ff, #eef2fb);
  border-color: #b9c4e0;
  box-shadow: 0 8px 18px rgba(20, 30, 60, 0.14);
}
body.light-mode .map-cell.st-started {
  background: linear-gradient(160deg, #fdf6e3, #f8efd2);
  border-color: #e0c98a;
}
body.light-mode .map-cell.st-lost {
  background: linear-gradient(160deg, #fbe9e9, #f6dada);
  border-color: #e0a0a0;
}
body.light-mode .map-cell.st-won {
  background: linear-gradient(160deg, #e6f6ec, #d8f0e0);
  border-color: #8ed3aa;
}
body.light-mode .map-group h2 {
  color: #66708a;
  border-left-color: #9fb4e0;
}

/* ============================================================
   广告位
   ------------------------------------------------------------
   这里只负责「留出位置」，不设宽高、不设 overflow、不加背景和标签。
   广告尺寸完全由 Google 决定，页面跟着它走。
   ============================================================ */
/* 游戏页底部：只保留与游戏区的 10px 间隔，高度由广告自己撑 */
.ad-down {
  flex: 0 0 auto;
  margin-top: 10px;
  text-align: center;
  line-height: 0;          /* 消除 inline-block 基线间隙，不影响广告本身 */
}

/* 结算页 / 目录页：只控制上下间距 */
.ad-wrap {
  margin: 26px 0;
}


html[lang="en"] .level-status strong{font-size:17px}html[lang="en"] .tool{font-size:10px}html[lang="en"] .map-link-top{font-size:12px}html[lang="en"] .revive-sub{white-space:normal}html[lang="en"] #btn-next{white-space:normal;line-height:1.35}
