* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  background: #BEF3EB;
  color: #285C4E;
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}
button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
button:focus { outline: none; }
button:focus-visible { outline: 2px solid #FF8A3D; outline-offset: 2px; }
body.is-drag, body.is-drag #app { touch-action: none; }

#app {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  background: linear-gradient(180deg, #FFF7EF 0%, #FFE8D2 46%, #FFF6EE 100%);
  box-shadow: 0 0 0 1px rgba(180, 100, 40, 0.06);
}

.screen { display: none; height: 100%; overflow: auto; -webkit-overflow-scrolling: touch; }
.screen.active { display: block; }
#screen-play.active {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#screen-start { padding-top: calc(10px + env(safe-area-inset-top)); padding-bottom: calc(18px + env(safe-area-inset-bottom)); }

.hero {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 16px;
  padding: 16px 10px 16px 18px;
  min-height: 196px;
  border-radius: 28px;
  background:
    radial-gradient(circle at 88% 0%, rgba(255,255,255,.28), transparent 42%),
    linear-gradient(155deg, #FFB24A 0%, #FF8A3D 55%, #FF7440 100%);
  box-shadow: 0 14px 28px rgba(230, 110, 30, .28);
  overflow: visible;
}
.hero::after {
  content: "";
  position: absolute;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  right: -36px;
  bottom: -48px;
  background: rgba(255, 220, 140, .18);
  pointer-events: none;
}
.hero-copy { position: relative; z-index: 2; flex: 1; min-width: 0; }
.hero h1 {
  margin: 0;
  font-size: clamp(32px, 8.6vw, 42px);
  line-height: 1.05;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 3px 0 rgba(214, 96, 20, .35);
}
.hero h1 em { font-style: normal; color: #FFE38A; }
.hero-sub {
  margin: 8px 0 0;
  color: rgba(255,255,255,.96);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
}
.start-btn {
  margin-top: 14px;
  height: 48px;
  padding: 0 16px 0 20px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, #FFE9B0, #FFC83D);
  color: #12C69F;
  font-size: 17px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  box-shadow: 0 5px 0 #2EE3DF, 0 10px 16px rgba(180, 70, 0, .22);
}
.start-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #2EE3DF; }
.start-btn .mp-icon { width: 18px; height: 18px; color: #12C69F; }

.sound-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,.28);
  color: #fff;
  display: grid;
  place-items: center;
}
.sound-btn:active { transform: scale(0.94); }
.sound-btn .mp-icon, .text-sound .mp-icon { width: 20px; height: 20px; }
.js-sound .ic-off { display: none; }
.js-sound.muted .ic-on { display: none; }
.js-sound.muted .ic-off { display: inline-block; }

.hero-art-col {
  position: relative;
  width: 44%;
  flex: none;
  display: flex;
  align-items: flex-end;
  padding-top: 28px;
  z-index: 1;
}
.hero-art {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 16px;
  border: 4px solid #fff;
  overflow: hidden;
  transform: rotate(7deg);
  box-shadow: 0 12px 22px rgba(160, 60, 0, .28);
  background: #c5e6ff;
}
.hero-art canvas { width: 100%; height: 100%; display: block; }
.floater {
  position: absolute;
  pointer-events: none;
  z-index: 3;
  filter: drop-shadow(0 4px 4px rgba(120, 50, 10, .25));
}
.f1 { width: 48px; height: 48px; left: -16px; top: 22px; transform: rotate(-18deg); }
.f2 { width: 40px; height: 40px; right: -8px; bottom: -4px; transform: rotate(14deg); }
.f3 { width: 34px; height: 34px; right: 8px; top: 8px; transform: rotate(18deg); }

.diff {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 16px 0;
}
.diff-btn {
  height: 46px;
  border-radius: 16px;
  border: 2px solid transparent;
  background: #fff;
  color: #488A7B;
  font-size: 15px;
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(160, 90, 30, .08);
}
.diff-btn.on {
  border-color: #FF8A3D;
  color: #1AE8B9;
  background: #FFF4EA;
}
.diff-btn:active { transform: scale(0.98); }

.record-bar {
  display: none;
  margin: 12px 16px 0;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 14px;
  padding: 10px 12px;
  color: #20A898;
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 6px 16px rgba(160, 90, 30, .08);
}
.record-bar.show { display: flex; }
.record-bar .mp-icon { width: 22px; height: 22px; color: #FFB020; }

.sec-label {
  margin: 16px 16px 8px;
  font-size: 13px;
  font-weight: 800;
  color: #68A79C;
  letter-spacing: 1px;
}
.themes {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0 16px;
}
.theme {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  padding: 8px 4px 6px;
  border-radius: 16px;
  border: none;
  background: var(--card, #fff);
  box-shadow: 0 8px 18px rgba(150, 80, 30, .08);
  min-height: 112px;
}
.theme:active { transform: scale(0.97); }
.theme-pic { height: 72px; display: flex; align-items: center; justify-content: center; }
.theme-pic canvas {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  border: 2px solid #fff;
  box-shadow: 0 6px 10px rgba(80, 40, 10, .16);
  transform: rotate(-7deg);
  background: #fff;
}
.theme-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  margin-top: 2px;
  padding: 0 2px;
  color: var(--ink, #2AC5A5);
  font-weight: 800;
  font-size: 11px;
}
.theme-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.theme-go { flex: none; }
.theme-go {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,.75);
  display: grid;
  place-items: center;
}
.theme-go .mp-icon { width: 14px; height: 14px; }
.foot-tip {
  margin: 14px 16px 0;
  text-align: center;
  color: #84B1A8;
  font-size: 12px;
  font-weight: 700;
}

.hud {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 0;
}
.spacer { flex: 1; }
.round {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: #32C4A2;
  box-shadow: 0 6px 14px rgba(160, 90, 30, .12);
  display: grid;
  place-items: center;
  flex: none;
}
.round:active { transform: scale(0.94); }
.round .mp-icon { width: 22px; height: 22px; }
.pill {
  height: 36px;
  padding: 0 10px;
  border-radius: 999px;
  background: #fff;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #326B5C;
  font-weight: 800;
  font-size: 13px;
  box-shadow: 0 6px 14px rgba(160, 90, 30, .08);
  flex: none;
}
.pill .mp-icon { width: 16px; height: 16px; color: #FF8A3D; }
.pill b, .score-pill { font-variant-numeric: tabular-nums; }
.score-pill { color: #1AE8B9; }
.thumb {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 12px;
  border: 2px solid #fff;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 6px 14px rgba(160, 90, 30, .12);
  flex: none;
}
.thumb canvas { width: 100%; height: 100%; display: block; }

.play-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px 0;
  color: #488A7B;
}
.play-meta b { font-size: 15px; color: #285C4E; }
.meta-right { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 800; }
.text-sound {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #32C4A2;
  display: grid;
  place-items: center;
  padding: 0;
}
.bar {
  height: 8px;
  margin: 8px 16px 0;
  background: rgba(255,255,255,.85);
  border-radius: 99px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(220, 170, 120, .35);
}
.bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #FFC14D, #FF8A3D);
  transition: width .25s ease;
}
.board-wrap { display: flex; justify-content: center; padding: 8px 16px 0; }
.board {
  position: relative;
  border-radius: 22px;
  overflow: hidden;
  background: #F3E2D0;
  box-shadow: 0 14px 30px rgba(170, 90, 30, .16), inset 0 0 0 3px #fff;
}
#ghost, #slots, #locked, .board-tip { position: absolute; inset: 0; }
#ghost { width: 100%; height: 100%; }
#slots, #locked, .board-tip { pointer-events: none; }
.slot {
  position: absolute;
  border-radius: 12px;
  background: rgba(255,255,255,.12);
  box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.7);
}
.slot.hot {
  background: rgba(255, 138, 61, .34);
  box-shadow: inset 0 0 0 3px #FF8A3D;
}
.board-tip { display: flex; align-items: center; justify-content: center; }
.board-tip span {
  background: rgba(255,255,255,.86);
  color: #3A8A79;
  font-size: 14px;
  font-weight: 800;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(80, 40, 10, .08);
}
.board.done { box-shadow: 0 0 0 4px #FFD56A, 0 14px 30px rgba(255, 138, 61, .35); }
.hint-line {
  margin: 8px 16px;
  text-align: center;
  color: #84B1A8;
  font-size: 12px;
  font-weight: 700;
}
.tray-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(12px + env(safe-area-inset-bottom));
}
.tray {
  display: grid;
  gap: 6px;
  padding: 10px;
  background: rgba(255,255,255,.78);
  border-radius: 20px;
  box-shadow: 0 8px 20px rgba(160, 90, 30, .06);
}
.piece { touch-action: none; }
.tray .piece { width: 100%; aspect-ratio: 1; }
.piece canvas {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 3px 3px rgba(70, 30, 10, .3));
}
.piece.dragging { z-index: 90; }
.piece.dragging canvas { filter: drop-shadow(0 12px 14px rgba(70, 30, 10, .35)); }
.piece.locked canvas { filter: drop-shadow(0 1px 0 rgba(80, 40, 10, .28)); }
.piece.hint { animation: bob 1.15s ease-in-out infinite; }
.piece.shake { animation: shake .28s ease; }
.piece.locked { animation: pop .28s ease; }
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-6px); }
  60% { transform: translateX(6px); }
}
@keyframes pop {
  0% { transform: scale(0.92); }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.end-wrap {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: calc(22px + env(safe-area-inset-top)) 20px calc(22px + env(safe-area-inset-bottom));
}
.end-kicker {
  display: inline-flex;
  margin: 0 auto;
  background: #FFF1E4;
  color: #1AE8B9;
  font-weight: 800;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
}
.end-title {
  margin: 10px 0 0;
  font-size: 34px;
  line-height: 1.15;
  color: #285C4E;
  letter-spacing: 1px;
}
.ribbon {
  display: none;
  margin: 8px auto 0;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #12C69F;
  font-weight: 800;
  font-size: 14px;
}
.ribbon.show { display: flex; }
.ribbon .mp-icon { width: 18px; height: 18px; color: #FFB020; }
.stars { display: flex; justify-content: center; gap: 6px; margin-top: 6px; }
.stars .mp-icon { width: 28px; height: 28px; color: #E6D5C8; }
.stars .mp-icon.on { color: #FFB020; }
.end-sub { margin: 6px 0 0; color: #68A79C; font-size: 14px; font-weight: 700; }
.end-art {
  width: min(100%, 280px);
  margin: 12px auto 0;
  padding: 8px;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 12px 28px rgba(160, 80, 20, .16);
}
.end-art canvas { width: 100%; height: auto; display: block; border-radius: 16px; }
.bonus { margin: 10px 0 0; min-height: 18px; color: #4AC9B7; font-size: 13px; font-weight: 800; }
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0 0;
}
.stats div {
  background: #fff;
  border-radius: 16px;
  padding: 10px 4px 8px;
  box-shadow: 0 6px 14px rgba(160, 90, 30, .08);
}
.stats b {
  display: block;
  font-size: 18px;
  color: #1AE8B9;
  font-variant-numeric: tabular-nums;
}
.stats span { font-size: 12px; color: #84B1A8; font-weight: 700; }
.best-line { margin: 10px 0 14px; min-height: 18px; color: #68A79C; font-size: 13px; font-weight: 700; }
.primary, .secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 52px;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 800;
  border: none;
}
.primary {
  background: linear-gradient(180deg, #FFA15A, #FF7A2E);
  color: #fff;
  box-shadow: 0 8px 0 #1CE2B1, 0 12px 20px rgba(220, 100, 30, .22);
}
.primary:active { transform: translateY(2px); box-shadow: 0 4px 0 #1CE2B1; }
.primary .mp-icon { width: 20px; height: 20px; color: #fff; }
.secondary {
  margin-top: 10px;
  background: #fff;
  color: #32C4A2;
  box-shadow: 0 6px 16px rgba(160, 90, 30, .08);
}
.secondary:active { transform: scale(0.98); }

.mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(62, 32, 12, .46);
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.mask.show { display: flex; }
#peek.show { align-items: center; }
.sheet {
  width: min(480px, 100%);
  background: #FFF8F2;
  border-radius: 24px 24px 0 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(80, 30, 0, .12);
}
.handle { width: 40px; height: 4px; border-radius: 99px; background: #E7D5C6; margin: 0 auto 8px; }
.sheet h3 { margin: 4px 0 0; text-align: center; font-size: 20px; color: #285C4E; }
.sheet p { margin: 8px 0 16px; text-align: center; color: #68A79C; font-size: 14px; font-weight: 700; }
.peek-card {
  width: min(360px, calc(100% - 36px));
  background: #FFF8F2;
  border-radius: 24px;
  padding: 14px 14px 16px;
  box-shadow: 0 16px 40px rgba(60, 20, 0, .2);
  text-align: center;
}
.peek-card canvas { width: 100%; height: auto; border-radius: 16px; display: block; }
.peek-card p { margin: 10px 0 12px; color: #68A79C; font-size: 13px; font-weight: 700; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.confetti i {
  position: absolute;
  top: -16px;
  height: 12px;
  border-radius: 3px;
  animation: fall 1.1s ease-in forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(220deg); opacity: .15; }
}
.score-pop {
  position: fixed;
  z-index: 70;
  color: #FF8A3D;
  font-weight: 900;
  font-size: 18px;
  pointer-events: none;
  animation: floatUp .7s ease forwards;
  text-shadow: 0 2px 0 #fff;
}
@keyframes floatUp {
  to { transform: translateY(-28px); opacity: 0; }
}

@media (max-height: 680px) {
  .hero { min-height: 168px; padding-top: 12px; padding-bottom: 12px; }
  .theme { min-height: 96px; }
  .theme-pic { height: 58px; }
  .theme-pic canvas { width: 52px; height: 52px; }
  .end-art { width: min(100%, 220px); }
  .end-title { font-size: 28px; }
}
