:root {
  --paper: #f6eedc;
  --paper-2: #efe3c8;
  --card: #fdf9ef;
  --ink: #2b2620;
  --ink-soft: #6b5f50;
  --line: #d9c9a8;
  --stroke-idle: #c9bfb1;
  --stroke-on: #1f1a15;
  --accent: #5cb83a;
  --accent-dark: #3f8f24;
  --gold: #e8a33a;
  --red: #c8432b;
  --radius: 14px;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  background-image:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,.55) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, rgba(255,255,255,.45) 0 2px, transparent 3px);
  background-size: 46px 46px, 64px 64px;
  color: var(--ink);
  user-select: none;
}
#app { max-width: 520px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; padding: 0 14px 10px; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 999px; font: inherit; font-weight: 700; cursor: pointer;
  padding: 10px 22px; font-size: 16px; transition: transform .08s, filter .15s;
}
.btn:active { transform: translateY(2px); }
.btn-primary {
  background: linear-gradient(#78d04f, var(--accent)); color: #fff;
  box-shadow: 0 4px 0 var(--accent-dark), 0 6px 14px rgba(60,120,30,.25);
  text-shadow: 0 1px 1px rgba(0,0,0,.25);
}
.btn-primary:active { box-shadow: 0 2px 0 var(--accent-dark); }
.btn-ghost {
  background: var(--card); color: var(--ink); border: 2px solid var(--line);
  box-shadow: 0 3px 0 var(--line);
}
.btn-big { font-size: 20px; padding: 14px 48px; }
.btn-small { padding: 8px 14px; font-size: 15px; }
.btn[disabled] { filter: grayscale(1) opacity(.5); cursor: default; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--card); font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink);
  box-shadow: 0 3px 0 var(--line);
}
.link-btn { background: none; border: 0; color: var(--ink-soft); font: inherit; font-size: 14px; cursor: pointer; padding: 6px 4px; }
.badge {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--red); color: #fff;
  font-size: 12px; line-height: 20px; margin-left: 4px;
}

/* ---------- home ---------- */
#home { justify-content: center; }
.home-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; padding: 24px 0; }
.logo { display: flex; gap: 8px; margin: 0 0 4px; }
.logo span {
  width: 72px; height: 72px; display: grid; place-items: center; font-size: 46px; font-weight: 800;
  background: var(--card); border: 2px solid var(--line); border-radius: 12px;
  background-image: linear-gradient(45deg, transparent 49.3%, rgba(200,67,43,.18) 49.3% 50.7%, transparent 50.7%),
                    linear-gradient(-45deg, transparent 49.3%, rgba(200,67,43,.18) 49.3% 50.7%, transparent 50.7%);
  box-shadow: 0 4px 0 var(--line);
}
.logo span:nth-child(odd) { transform: rotate(-4deg); }
.logo span:nth-child(even) { transform: rotate(3deg); color: var(--red); }
.tagline { color: var(--ink-soft); margin: 0 0 12px; }
.home-stats { color: var(--ink-soft); font-size: 14px; min-height: 1em; }
.howto { max-width: 340px; text-align: left; color: var(--ink-soft); font-size: 14px; }
.howto summary { cursor: pointer; text-align: center; }
.howto ol { padding-left: 20px; line-height: 1.7; }

/* ---------- bar ---------- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0 8px; }
.bar h2 { margin: 0; font-size: 22px; }
.bar-title { text-align: center; }
.bar-title h2 { font-size: 26px; letter-spacing: 1px; }
.bar-title p { margin: 2px 0 0; font-weight: 700; color: var(--ink-soft); font-size: 15px; }
.bar-right { min-width: 40px; text-align: right; color: var(--ink-soft); font-size: 14px; }

/* ---------- level grid ---------- */
.level-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; padding-bottom: 20px; }
.level-cell {
  aspect-ratio: 1; border-radius: 10px; border: 2px solid var(--line); background: var(--card);
  display: grid; place-items: center; cursor: pointer; font-weight: 700; color: var(--ink-soft);
  position: relative; font-size: 15px;
}
.level-cell.done { background: #e6f4d9; border-color: #a8d48a; color: var(--ink); font-size: 22px; }
.level-cell.done::after { content: attr(data-n); position: absolute; right: 3px; bottom: 1px; font-size: 9px; color: var(--ink-soft); }
.level-cell.current { outline: 3px solid var(--gold); }

/* ---------- slots ---------- */
.slots { display: grid; grid-template-columns: repeat(var(--cols, 8), 1fr); gap: 5px; margin: 4px 0 6px; }
.slot { display: flex; flex-direction: column; align-items: center; }
.slot .py { height: 15px; font-size: 11px; color: var(--ink-soft); line-height: 15px; white-space: nowrap; }
.slot .box {
  width: 100%; aspect-ratio: 1; border-radius: 6px; border: 1.5px solid #b7a586; background: var(--card);
  display: grid; place-items: center; font-size: calc(var(--box, 40px) * .62); font-weight: 500;
  background-image: linear-gradient(45deg, transparent 49.4%, rgba(185,160,120,.35) 49.4% 50.6%, transparent 50.6%),
                    linear-gradient(-45deg, transparent 49.4%, rgba(185,160,120,.35) 49.4% 50.6%, transparent 50.6%),
                    linear-gradient(transparent 49.4%, rgba(185,160,120,.25) 49.4% 50.6%, transparent 50.6%),
                    linear-gradient(90deg, transparent 49.4%, rgba(185,160,120,.25) 49.4% 50.6%, transparent 50.6%);
  box-shadow: 0 2px 0 rgba(0,0,0,.08);
}
.slot.filled .box { border-color: var(--ink-soft); }
.slot.new .box { animation: pop .45s ease; background-color: #fff6c9; }
.slot.hinted .py { color: var(--red); font-weight: 700; }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }

.bonus { font-size: 13px; color: var(--ink-soft); margin: 0 0 6px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.bonus .chip { background: #fff3d6; border: 1px solid #ecc879; border-radius: 6px; padding: 0 6px; color: var(--ink); font-size: 15px; }

/* ---------- board ---------- */
.board-wrap { position: relative; }
.board {
  position: relative; background: var(--card); border: 2px solid var(--line); border-radius: 18px;
  padding: 4%; box-shadow: inset 0 0 0 6px #faf3e3, 0 4px 0 var(--line);
}
.board::before, .board::after {
  content: ""; position: absolute; width: 18px; height: 18px; border: 2px solid #cbb78f; opacity: .7;
}
.board::before { left: 10px; top: 10px; border-right: 0; border-bottom: 0; }
.board::after { right: 10px; bottom: 10px; border-left: 0; border-top: 0; }
#glyph { width: 100%; display: block; touch-action: none; }
#glyph .stroke { fill: var(--stroke-idle); transition: fill .12s; }
#glyph .stroke.on { fill: var(--stroke-on); }
#glyph .stroke { --flash-base: var(--stroke-idle); }
#glyph .stroke.on { --flash-base: var(--stroke-on); }
#glyph .stroke.flash { animation: flash 1.6s ease infinite; }
@keyframes flash { 0%, 100% { fill: var(--flash-base); } 20%, 60% { fill: var(--gold); } 40%, 80% { fill: #f6d28e; } }
#glyph .hit { fill: none; stroke: transparent; stroke-width: 70; stroke-linecap: round; stroke-linejoin: round; cursor: pointer; pointer-events: stroke; }
.board.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.toast {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(.9); opacity: 0;
  background: rgba(43,38,32,.88); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 17px;
  pointer-events: none; transition: opacity .2s, transform .2s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast.good { background: rgba(63,143,36,.92); }
.toast.gold { background: rgba(214,140,30,.94); }

/* ---------- actions ---------- */
.actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
.btn-submit { flex: 1; max-width: 220px; font-size: 20px; padding: 12px 0; }
.actions-minor { margin-top: 6px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(30,25,20,.45); display: grid; place-items: center; z-index: 10; padding: 20px; }
.modal-card {
  background: var(--card); border-radius: 20px; padding: 22px 20px; width: 100%; max-width: 380px; text-align: center;
  border: 3px solid var(--gold); box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: pop .4s ease;
}
.modal-card h3 { margin: 0 0 8px; font-size: 26px; color: var(--red); }
.modal-card p { margin: 0 0 12px; color: var(--ink-soft); }
.modal-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 16px; font-size: 22px; }
.modal-list span { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 6px; background: #f3ead6; }
.modal-list span.b { background: #ffeec2; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

.credits { text-align: center; font-size: 11px; color: #a0937f; padding: 8px 0 12px; }
.credits a { color: inherit; }

@media (max-width: 380px) {
  .logo span { width: 60px; height: 60px; font-size: 38px; }
  .level-grid { grid-template-columns: repeat(5, 1fr); }
}
