* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: #FFE8D2;
  color: #3B2418;
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}
body { overflow-x: hidden; }
body {
  overscroll-behavior: none;
}
button, input { font-family: inherit; }
button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:focus { outline: none; }
button:focus-visible { outline: 2px solid #FF8A3D; outline-offset: 2px; }
.stage, button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
input { user-select: text; }

.stage {
  width: 100%;
  max-width: 480px;
  min-height: 100%;
  min-height: 100dvh;
  margin: 0 auto;
  position: relative;
  background:
    radial-gradient(circle at 8% -8%, #FFD7B0 0, transparent 42%),
    radial-gradient(circle at 110% 6%, #FFC9A0 0, transparent 34%),
    radial-gradient(circle at 90% 100%, #FFE1C4 0, transparent 42%),
    #FFF1E4;
}

.screen { display: none; }
.screen.on {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  min-height: 100dvh;
  padding: calc(8px + env(safe-area-inset-top)) 16px calc(12px + env(safe-area-inset-bottom));
}

.hero {
  position: relative;
  height: 196px;
  flex: none;
}
.mini {
  position: absolute;
  left: 8px;
  top: 18px;
  width: 168px;
  transform: rotate(-8deg);
  background: #fff;
  border-radius: 22px;
  padding: 10px;
  box-shadow: 0 12px 28px rgba(180, 80, 20, 0.16);
  border: 1px solid #FFF6EC;
}
.mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.mini-grid span {
  aspect-ratio: 1;
  border-radius: 12px;
  background: var(--c);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 22px;
  color: #3B2418;
  position: relative;
}
.mini-grid span.x::after,
.cell.bad::after {
  content: "";
  position: absolute;
  inset: 24%;
  background:
    linear-gradient(#E24B4B, #E24B4B) center / 100% 2px no-repeat,
    linear-gradient(#E24B4B, #E24B4B) center / 2px 100% no-repeat;
  transform: rotate(45deg);
  opacity: 0.55;
  z-index: 2;
  pointer-events: none;
}
.mascot {
  position: absolute;
  right: -6px;
  bottom: 0;
  width: 148px;
  height: auto;
  filter: drop-shadow(0 8px 10px rgba(180, 80, 20, 0.16));
}

.logo {
  margin: 2px 0 0;
  text-align: center;
  font-size: 34px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: 1px;
  color: #3B2418;
}
.logo span { color: #FF8A3D; }
.lead {
  margin: 6px 0 0;
  text-align: center;
  color: #8A624C;
  font-size: 14px;
  line-height: 1.5;
}

.nick {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  background: #fff;
  border-radius: 16px;
  padding: 8px 12px;
  border: 1px solid #F3E2D2;
  box-shadow: 0 3px 0 #F0D7C4;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #FF8A3D;
  color: #fff;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.nick input {
  flex: 1;
  border: 0;
  background: transparent;
  font-size: 16px;
  font-weight: 700;
  color: #3B2418;
  min-width: 0;
  outline: none;
}
.nick .mp-icon { width: 18px; height: 18px; color: #C9A48A; flex: none; }

.diffs { margin-top: 14px; }
.diff {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 12px 14px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid #F3E2D2;
  box-shadow: 0 3px 0 #F0D7C4;
  color: #3B2418;
  margin: 0 0 8px;
}
.diff span { display: block; min-width: 0; }
.diff b { display: block; font-size: 16px; }
.diff small { display: block; margin-top: 2px; font-size: 12px; color: #A07B66; font-weight: 500; }
.diff .mp-icon { margin-left: auto; width: 20px; height: 20px; color: #FF8A3D; opacity: 0; flex: none; }
.diff.on {
  border-color: #FF8A3D;
  background: #FFF7F0;
  box-shadow: 0 3px 0 #F0B48A;
}
.diff.on .mp-icon { opacity: 1; }
.diff:active { transform: translateY(2px); box-shadow: 0 1px 0 #F0D7C4; }

.best {
  margin: 2px 0 0;
  text-align: center;
  color: #A07B66;
  font-size: 12px;
}

.start-actions, .end-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
}

.btn {
  height: 54px;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 800;
  border: 0;
}
.btn.primary {
  background: linear-gradient(#FFA15C, #FF7A2A);
  color: #fff;
  box-shadow: 0 5px 0 #D86520, 0 12px 20px rgba(255, 122, 42, 0.22);
}
.btn.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #D86520; }
.btn.primary:disabled { opacity: 0.7; }
.btn.ghost {
  background: #fff;
  color: #8A624C;
  border: 1px solid #F3E2D2;
  box-shadow: 0 3px 0 #F0D7C4;
}
.btn.ghost:active { transform: translateY(2px); box-shadow: 0 1px 0 #F0D7C4; }

#view-play.screen.on {
  height: 100%;
  height: 100dvh;
  overflow: auto;
  gap: 10px;
}
.hud {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  gap: 6px;
  align-items: center;
  background: #fff;
  border-radius: 18px;
  padding: 8px 8px 8px 12px;
  box-shadow: 0 8px 20px rgba(150, 70, 20, 0.08);
  border: 1px solid #F6E6D6;
}
.hud-mid { text-align: center; min-width: 64px; }
.hud-side.right { text-align: right; }
.hud-time {
  font-size: 20px;
  font-weight: 800;
  color: #3B2418;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.hud-label { font-size: 11px; color: #A07B66; margin-top: 2px; }
.hud-label b { color: #E36A22; font-weight: 800; }
.hearts { display: flex; gap: 1px; color: #FF5B6E; min-height: 18px; }
.hearts .mp-icon { width: 18px; height: 18px; }
.hearts .broken { color: #E4CFC4; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: 1px solid #F3E2D2;
  background: #FFF7F1;
  color: #8A624C;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 #F0D7C4;
  padding: 0;
}
.icon-btn .mp-icon { width: 20px; height: 20px; }
.icon-btn:active { transform: translateY(1px); }

.board-slot {
  flex: 1 0 auto;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.board-card {
  background: #FFFBF7;
  border-radius: 20px;
  padding: 8px;
  box-shadow: 0 10px 28px rgba(150, 70, 20, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.9);
}
.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: #6A4632;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid #6A4632;
}
.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid #E7D3C0;
  border-bottom: 1px solid #E7D3C0;
  background: #FFFCF8;
  color: #E36A22;
  font-weight: 800;
  font-size: inherit;
  line-height: 1;
  min-width: 0;
  min-height: 0;
  -webkit-appearance: none;
  appearance: none;
}
.cell.shade { background: #FFF3E6; }
.cell.c-last { border-right: 0; }
.cell.r-last { border-bottom: 0; }
.cell.b-r { box-shadow: inset -3px 0 0 #6A4632; }
.cell.b-b { box-shadow: inset 0 -3px 0 #6A4632; }
.cell.b-r.b-b { box-shadow: inset -3px -3px 0 #6A4632; }
.cell.given { background: var(--g, #FFE08A); color: #3B2418; }
.cell.bad { background: #FFE4E4; color: #D23B3B; }
.cell.peer { background-image: linear-gradient(rgba(255, 168, 90, 0.16), rgba(255, 168, 90, 0.16)); }
.cell.same { background-image: linear-gradient(rgba(255, 138, 61, 0.28), rgba(255, 138, 61, 0.28)); }
.cell.sel {
  outline: 2px solid #FF8A3D;
  outline-offset: -3px;
  z-index: 1;
}
.cell .num {
  position: relative;
  z-index: 1;
  font-size: 0.56em;
  font-variant-numeric: tabular-nums;
}
.cell.just .num { animation: pop 0.18s ease; }
.cell .notes {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 1px;
}
.cell .notes i {
  font-style: normal;
  font-size: 0.22em;
  color: #C47A45;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
}
.cell .notes i.on { visibility: visible; }
.cell.hinted::before {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #FF8A3D;
  top: 3px;
  left: 3px;
  z-index: 1;
}
.cell:active { filter: brightness(0.96); }

.tools {
  flex: none;
  display: grid;
  grid-template-columns: 1fr 1fr 1.25fr;
  gap: 8px;
}
.tool {
  height: 48px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid #F0DCC8;
  box-shadow: 0 3px 0 #F0D2B8;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-weight: 800;
  font-size: 14px;
  color: #6A4632;
  padding: 0 6px;
}
.tool .mp-icon { width: 20px; height: 20px; }
.tool em {
  font-style: normal;
  font-size: 10px;
  background: #FFF0E4;
  color: #E36A22;
  border-radius: 999px;
  padding: 2px 6px;
  font-weight: 800;
}
.tool.on {
  background: #FF8A3D;
  color: #fff;
  border-color: #E36A22;
  box-shadow: 0 3px 0 #D86520;
}
.tool:active { transform: translateY(2px); box-shadow: 0 1px 0 #F0D2B8; }
.tool.hint { color: #E36A22; }

.pad {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.pad button {
  position: relative;
  height: 46px;
  border: 0;
  border-radius: 14px;
  background: #fff;
  color: #F07A2A;
  font-size: 22px;
  font-weight: 800;
  box-shadow: 0 3px 0 #F0D2B8;
  border: 1px solid #F6E6D6;
}
.pad button .left {
  position: absolute;
  right: 8px;
  top: 4px;
  font-size: 10px;
  color: #C9A48A;
  font-weight: 700;
}
.pad button.on {
  background: #FF8A3D;
  color: #fff;
  box-shadow: 0 3px 0 #D86520;
}
.pad button.on .left { color: rgba(255, 255, 255, 0.85); }
.pad button.done { opacity: 0.38; }
.pad button:active { transform: translateY(2px); box-shadow: 0 1px 0 #F0D2B8; }

.end-badge {
  width: 84px;
  height: 84px;
  border-radius: 28px;
  margin: 18px auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #FF8A3D;
  color: #fff;
  box-shadow: 0 8px 0 #E36A22;
  flex: none;
}
.end-badge .mp-icon { width: 44px; height: 44px; }
.end-badge.lose { background: #FF6B6B; box-shadow: 0 8px 0 #E25555; }
.end-title {
  margin: 14px 0 0;
  text-align: center;
  font-size: 28px;
  font-weight: 800;
}
.end-sub, .end-name {
  margin: 6px 0 0;
  text-align: center;
  color: #8A624C;
  font-size: 14px;
}
.end-name { font-weight: 700; color: #3B2418; }
.score-card {
  margin-top: 16px;
  background: #fff;
  border-radius: 22px;
  padding: 18px 16px 16px;
  text-align: center;
  box-shadow: 0 10px 24px rgba(150, 70, 20, 0.1);
  border: 1px solid #F6E6D6;
}
.score-num {
  font-size: 56px;
  font-weight: 800;
  color: #FF8A3D;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.score-label { margin-top: 4px; color: #A07B66; font-size: 13px; }
.record {
  display: inline-block;
  margin-top: 8px;
  background: #FFF0E0;
  color: #E36A22;
  font-size: 12px;
  font-weight: 800;
  border-radius: 999px;
  padding: 4px 10px;
}
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.stats div {
  background: #fff;
  border-radius: 16px;
  padding: 12px 6px;
  text-align: center;
  border: 1px solid #F6E6D6;
  box-shadow: 0 3px 0 #F6E6D6;
}
.stats b {
  display: block;
  font-size: 16px;
  color: #3B2418;
  font-variant-numeric: tabular-nums;
}
.stats span { display: block; margin-top: 4px; font-size: 12px; color: #A07B66; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: rgba(59, 36, 24, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 40;
  max-width: calc(100% - 48px);
  text-align: center;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

.mask {
  position: fixed;
  inset: 0;
  background: rgba(48, 24, 12, 0.46);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
  padding: 16px;
}
.mask.on { display: flex; }
.mask.center { align-items: center; }
.sheet, .ad-card {
  width: min(440px, 100%);
  background: #FFFBF7;
  border-radius: 22px;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 16px 40px rgba(80, 30, 0, 0.18);
}
.mask.center .sheet, .ad-card { padding-bottom: 16px; }
.sheet h3, .ad-card h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}
.sheet p, .ad-card p {
  margin: 8px 0 0;
  color: #8A624C;
  font-size: 14px;
  line-height: 1.5;
}
.sheet .btn, .ad-card .btn { width: 100%; margin-top: 10px; }
.ad-top {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #E36A22;
  font-weight: 800;
}
.ad-top .mp-icon { width: 22px; height: 22px; }
.ad-bar {
  margin-top: 14px;
  height: 10px;
  background: #F3E4D6;
  border-radius: 99px;
  overflow: hidden;
}
.ad-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #FFB067, #FF8A3D);
}
.ad-count {
  margin-top: 8px;
  text-align: center;
  font-weight: 800;
  color: #3B2418;
}

.board.shake { animation: shake 0.28s linear; }
@keyframes pop {
  0% { transform: scale(0.55); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
@media (prefers-reduced-motion: reduce) {
  .cell.just .num, .board.shake { animation: none; }
}
