:root {
  --cell: 52px;
  --slot-h: calc(var(--cell) * 0.72);
  --radius: 12px;
  --ink: #463529;
  --tile-bg: #fffaf0;
  --tile-border: #e6d8bb;
  --accent: #ff8a3d;
  --card-bg: #fffdf6;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  background: linear-gradient(160deg, #9fe3c2, #d8f5d8 55%, #fff3d0);
}

body[data-theme="forest"] {
  background: linear-gradient(160deg, #9fe3c2 0%, #d8f5d8 55%, #f7f3d3 100%);
}

body[data-theme="savanna"] {
  background: linear-gradient(160deg, #ffd9a3 0%, #ffeac2 55%, #fff6dc 100%);
}

body[data-theme="snow"] {
  background: linear-gradient(160deg, #cfe9ff 0%, #eaf5ff 55%, #ffffff 100%);
}

body[data-theme="abyss"] {
  background: linear-gradient(160deg, #8d7fc2 0%, #b9abe9 55%, #e8e0ff 100%);
}

body[data-theme="volcano"] {
  background: linear-gradient(160deg, #ffb37a 0%, #ffd9a8 55%, #fff0da 100%);
}

#app {
  max-width: 520px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
}

#btn-levels {
  width: 42px;
  height: 42px;
  flex: none;
  border: none;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.85);
  font-size: 20px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  cursor: pointer;
}

.title-wrap {
  flex: 1;
  min-width: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
}

#level-name {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 2px;
}

#level-rare {
  margin-top: 3px;
  color: #b65b15;
  font-size: 11px;
  font-weight: 700;
}

#stats {
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

#board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#board {
  position: relative;
}

.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--tile-bg);
  border: 1.5px solid var(--tile-border);
  box-shadow: 0 2px 3px rgba(90, 70, 35, 0.16);
}

.tile.free {
  cursor: pointer;
  transition: transform 0.06s ease;
}

.tile.free:hover {
  transform: scale(1.05);
}

.tile.free:active {
  transform: scale(0.92);
}

.tile.covered {
  filter: grayscale(0.5) brightness(0.66);
  box-shadow: none;
}

.tile.sealed {
  filter: none;
  border-color: #c58b32;
  background: #fff0c5;
  box-shadow: inset 0 0 0 2px rgba(197, 139, 50, 0.25);
}

.seal-lock {
  position: absolute;
  right: -5px;
  top: -7px;
  display: grid;
  place-items: center;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #80501e;
  border: 1px solid #fff6dc;
  color: #fff;
  font-size: 12px;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(70, 40, 10, 0.35);
}

#slots,
#storage {
  display: flex;
  gap: 5px;
  height: var(--slot-h);
}

#storage {
  margin-bottom: 8px;
}

.slot {
  flex: 1;
  min-width: 0;
  border: 2px dashed rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.storage-box {
  background: rgba(255, 255, 255, 0.2);
}

.storage-box.clickable {
  cursor: pointer;
}

.slot-tile {
  width: 88%;
  height: 88%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tile-bg);
  border: 1.5px solid var(--tile-border);
  border-radius: 9px;
  box-shadow: 0 2px 3px rgba(90, 70, 35, 0.2);
  font-size: calc(var(--slot-h) * 0.5);
  animation: popIn 0.18s ease-out;
}

.slot-tile.clearing {
  animation: clearOut 0.4s ease-in forwards;
}

@keyframes popIn {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes clearOut {
  0% { transform: scale(1); opacity: 1; }
  55% { transform: scale(1.3); opacity: 1; background: #ffe08a; border-color: #ffb94d; }
  100% { transform: scale(0.05); opacity: 0; }
}

#tools {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.tool {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 11px 2px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.88);
  border: none;
  border-radius: 14px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  touch-action: manipulation;
}

.tool:active {
  transform: scale(0.96);
}

.tool .count {
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.tool.disabled {
  opacity: 0.4;
  pointer-events: none;
}

#overlay {
  position: fixed;
  inset: 0;
  /* 牌面按层级使用较大的 z-index；引导弹窗必须始终压在所有牌面之上。 */
  z-index: 10000;
  background: rgba(35, 30, 55, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#overlay.hidden {
  display: none;
}

.card {
  width: 100%;
  max-width: 350px;
  max-height: 88dvh;
  overflow: auto;
  background: var(--card-bg);
  border-radius: 22px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  animation: cardIn 0.22s ease-out;
}

@keyframes cardIn {
  from { transform: translateY(14px) scale(0.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.card h2 {
  font-size: 22px;
  margin: 6px 0 10px;
}

.card p {
  font-size: 14px;
  line-height: 1.6;
  opacity: 0.85;
}

.emoji.big {
  font-size: 56px;
  line-height: 1;
}

.stars {
  font-size: 26px;
  letter-spacing: 4px;
  margin: 8px 0;
}

.rules {
  list-style: none;
  text-align: left;
  margin: 10px 0 16px;
  font-size: 14px;
  line-height: 1.9;
}

.btns {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  flex: 1;
  padding: 12px 6px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  border: none;
  border-radius: 14px;
  background: #f1e7d2;
  color: var(--ink);
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn:active {
  transform: scale(0.97);
}

.level-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 8px 0 2px;
}

.level-card {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 10px;
  align-items: center;
  text-align: left;
  padding: 12px;
  border: 2px solid #f0e3c8;
  border-radius: 14px;
  background: #fffdf6;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
}

.level-card.current {
  border-color: var(--accent);
  background: #fff4e6;
}

.level-card .lc-emoji {
  grid-row: 1 / 3;
  font-size: 34px;
  text-align: center;
}

.level-card .lc-name {
  font-size: 15px;
  font-weight: 700;
}

.level-card .lc-diff {
  font-size: 12px;
}

.level-card .lc-desc {
  grid-column: 2 / 4;
  font-size: 12px;
  opacity: 0.7;
}

.level-card .lc-rare {
  grid-column: 2 / 4;
  color: #b65b15;
  font-size: 12px;
  font-weight: 700;
}
