:root {
  --bg: #f3e6d4;
  --ink: #3b2a22;
  --muted: #7a6256;
  --paper: #fff8ee;
  --line: #c9ad93;
  --wood: #c0784a;
  --wood-dark: #8a4e2e;
  --floor: #e8d0a8;
  --wall: #d9b48a;
  --door: #5c3d2e;
  --gold: #e2b14a;
  --btn: #c45c32;
  --btn-ink: #fffaf3;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% -10%, #fff6e8, transparent 60%),
    repeating-linear-gradient(90deg, #edd9c0 0 12px, #e8d3b8 12px 24px);
  min-height: 100%;
}
#app { min-height: 100%; }
.screen {
  display: none;
  min-height: 100%;
  padding: calc(20px + var(--safe-t)) 18px calc(24px + var(--safe-b));
}
.screen.active { display: flex; justify-content: center; align-items: flex-start; }
.panel { width: min(520px, 100%); }
.card {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 18px;
  padding: 22px 20px 20px;
  box-shadow: 4px 5px 0 var(--ink);
}
h1, h2 { margin: 0 0 8px; letter-spacing: 0.06em; }
h1 { font-size: clamp(32px, 8vw, 44px); text-align: center; }
h2 { font-size: 24px; }
.tag, .lead, .best, .tip {
  color: var(--muted);
  line-height: 1.65;
  text-align: center;
}
.lead { text-align: left; margin: 0 0 16px; }
.tag { margin: 0 0 12px; font-weight: 600; }
ol { padding-left: 1.2em; line-height: 1.7; color: var(--ink); }
.btn-col { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.center { text-align: center; margin-top: 8px; }
.btn {
  appearance: none;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  min-height: 46px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 2px 3px 0 var(--ink);
}
.btn.primary { background: var(--btn); color: var(--btn-ink); }
.btn.tiny { font-weight: 600; }
.btn:active { transform: translate(1px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.logo-mark {
  width: 64px; height: 64px; margin: 8px auto 10px;
  background:
    linear-gradient(#c0784a, #a35c32) 8px 18px / 34px 22px no-repeat,
    linear-gradient(#7a5c45, #5c4033) 40px 22px / 12px 28px no-repeat,
    linear-gradient(#e8d4b8, #e8d4b8);
  border: 2px solid var(--ink);
  border-radius: 16px;
  box-shadow: 3px 3px 0 var(--ink);
}
.title-art {
  height: 120px;
  margin: 0 0 14px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background:
    linear-gradient(180deg, #f4e4c8 0 28px, #e8d0a8 28px),
    #e8d0a8;
  position: relative;
  overflow: hidden;
}
.title-art::before, .title-art::after { content: ""; position: absolute; }
.title-art::before {
  left: 16px; bottom: 18px; width: 70px; height: 42px;
  background: #c0784a; border: 2px solid var(--ink); border-radius: 6px;
}
.title-art::after {
  right: 18px; top: 20px; bottom: 16px; width: 22px;
  background: #5c3d2e; border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 5px #e8d0a8;
  clip-path: polygon(0 12px, 100% 0, 100% 100%, 0 100%);
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 12px 0 16px;
}
.level-btn {
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.level-btn.clear { background: #f3d9a4; }
.level-btn:active { transform: translateY(1px); }
.hud {
  width: min(520px, 100%);
  display: grid;
  grid-template-columns: 1.4fr 1fr 0.8fr auto;
  gap: 8px;
  align-items: end;
  margin: 0 auto 10px;
}
.hud-k { font-size: 11px; color: var(--muted); }
.hud-v { font-weight: 800; font-variant-numeric: tabular-nums; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px;
  border: 2px solid var(--ink); background: var(--paper);
  font: inherit; cursor: pointer;
}
#board-wrap {
  width: min(520px, 100%);
  margin: 0 auto;
  position: relative;
  padding: 14px 28px 14px 14px;
  background: repeating-linear-gradient(90deg, #d9b48a 0 6px, #d2ab80 6px 12px);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 4px 5px 0 var(--ink);
}
#board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background:
    repeating-linear-gradient(90deg, #e4c38e 0 2px, transparent 2px 16.666%),
    repeating-linear-gradient(#e4c38e 0 2px, transparent 2px 16.666%),
    #f0d8a8;
  border: 2px solid var(--ink);
  border-radius: 8px;
  touch-action: none;
}
#board-wrap::after {
  content: "出门";
  position: absolute;
  right: 2px;
  top: 36.5%;
  width: 24px;
  height: 16.6%;
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  font-size: 11px;
  font-weight: 800;
  color: #fff8ee;
  background: var(--door);
  border: 2px solid var(--ink);
  border-left: 0;
  letter-spacing: 0.15em;
}
.piece {
  position: absolute;
  border: 2px solid var(--ink);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  padding: 2px;
  user-select: none;
  cursor: pointer;
  box-shadow: 1px 2px 0 rgba(59,42,34,0.25);
  transition: left 0.12s ease, top 0.12s ease;
}
.piece.selected { outline: 3px solid #fff; box-shadow: 0 0 0 5px var(--ink); z-index: 2; }
.piece.goal {
  box-shadow: 0 0 0 2px var(--gold), 1px 2px 0 rgba(59,42,34,0.25);
  animation: glow 1.4s ease-in-out infinite;
}
@keyframes glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.08); }
}
.toolbar {
  width: min(520px, 100%);
  margin: 12px auto 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.stars { font-size: 28px; letter-spacing: 0.2em; margin-bottom: 6px; color: #c78b14; }
#screen-game.active { flex-direction: column; align-items: center; }
@media (max-width: 420px) {
  .piece { font-size: 11px; }
  .hud { grid-template-columns: 1.3fr 0.9fr 0.8fr auto; }
}
