:root {
  --ink: #2b3140;
  --muted: #6b7485;
  --bg: #eef5f7;
  --panel: #ffffff;
  --line: #d7e2e6;
  --accent: #ff7a59;
  --accent-dark: #e85d3d;
  --teal: #19a186;
  --gold: #f7c948;
  --sky: #aee0f5;
  --sky-deep: #7fc9ea;
  --wood: #b7794a;
  --wall: #ffe3c9;
}

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

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  user-select: none;
}

button {
  font: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 12px 12px;
}

#topbar {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-bottom: 8px;
}

.order-card {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 66px;
}

.order-icon {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  font-size: 26px;
  background: #fff4e8;
  border-radius: 8px;
}

.order-info {
  flex: 1;
  min-width: 0;
}

.order-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.order-progress {
  height: 7px;
  background: #e8eef1;
  border-radius: 4px;
  margin: 6px 0 4px;
  overflow: hidden;
}

.order-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--teal), #5fc7a9);
  border-radius: 4px;
  transition: width 0.2s ease;
}

.order-count {
  font-size: 11px;
  color: var(--muted);
}

.status-stack {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  gap: 6px;
}

.coin-pill {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  text-align: center;
}

.xp-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.xp-bar {
  width: 54px;
  height: 7px;
  background: #e8eef1;
  border-radius: 4px;
  overflow: hidden;
}

#xpFill {
  height: 100%;
  width: 0%;
  background: var(--gold);
  border-radius: 4px;
  transition: width 0.25s ease;
}

.combo-pill {
  background: var(--gold);
  color: var(--ink);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.icon-btn {
  width: 34px;
  height: 34px;
  align-self: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
  color: var(--muted);
}

.icon-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

#boardWrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  width: min(92vw, 56vh, 500px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 3px;
  background: #d7e2e6;
  border: 4px solid #c2d3d8;
  border-radius: 8px;
  padding: 4px;
}

.cell {
  aspect-ratio: 1;
  background: #ffffff;
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: clamp(14px, 4.6vw, 26px);
  line-height: 1;
  transition: transform 0.08s ease;
}

.cell.tile {
  font-weight: 700;
}

.cell.ghost-ok {
  background: rgba(25, 161, 134, 0.35);
  box-shadow: inset 0 0 0 2px rgba(25, 161, 134, 0.55);
}

.cell.ghost-bad {
  background: rgba(232, 93, 61, 0.3);
  box-shadow: inset 0 0 0 2px rgba(232, 93, 61, 0.55);
}

.cell.clearing {
  animation: clear-pop 0.22s ease forwards;
}

@keyframes clear-pop {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.55); opacity: 0; }
}

#tray {
  padding-top: 8px;
}

#trayPieces {
  display: flex;
  justify-content: center;
  gap: 14px;
  min-height: 112px;
  align-items: center;
}

.tray-piece {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  display: grid;
  width: 88px;
  height: 96px;
  place-items: center;
  touch-action: none;
  cursor: grab;
}

.tray-piece:active {
  cursor: grabbing;
}

.tray-piece.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 122, 89, 0.35);
}

.mini-grid {
  display: grid;
  gap: 2px;
  --cell: 20px;
}

.mini-cell {
  width: var(--cell);
  height: var(--cell);
  position: relative;
  display: grid;
  place-items: center;
  font-size: calc(var(--cell) * 0.75);
  background: #f4f7f8;
  border-radius: 4px;
}

.origin-cell::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink);
  border: 1px solid #ffffff;
}

.mini-empty {
  background: transparent;
  box-shadow: inset 0 0 0 1px #d3e0e4;
  opacity: 0.55;
}

.rot-anim .mini-grid {
  animation: quarter-turn 0.18s ease;
}

@keyframes quarter-turn {
  from { transform: rotate(0deg); }
  to { transform: rotate(90deg); }
}

.rotate-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: #eef4f6;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
}

.drag-piece {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  filter: drop-shadow(0 8px 12px rgba(43, 49, 64, 0.25));
}

.drag-piece .mini-grid {
  gap: 3px;
}

.drag-piece .mini-cell {
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(43, 49, 64, 0.12);
}

.tab-btn {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  background: var(--teal);
  color: #ffffff;
  font-weight: 700;
  border-radius: 8px;
  font-size: 15px;
}

.view {
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.shop-header .tab-btn {
  width: auto;
  padding: 0 16px;
  margin: 0;
  background: var(--accent);
}

.storefront {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--sky);
}

.sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--sky) 0%, var(--sky-deep) 78%, #cfe8c9 78%);
}

.sun {
  position: absolute;
  top: 9%;
  right: 10%;
  width: 42px;
  height: 42px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 26px rgba(247, 201, 72, 0.8);
}

.cloud {
  position: absolute;
  width: 58px;
  height: 20px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 20px;
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
}

.cloud::before {
  width: 26px;
  height: 26px;
  left: 10px;
  top: -12px;
}

.cloud::after {
  width: 18px;
  height: 18px;
  right: 8px;
  top: -7px;
}

.c1 {
  top: 12%;
  left: 8%;
}

.c2 {
  top: 30%;
  left: 38%;
  transform: scale(0.8);
}

.lights-row {
  position: absolute;
  top: 4%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 15px;
  letter-spacing: 6px;
}

.shop {
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  width: 74%;
  height: 66%;
}

.roof {
  position: absolute;
  top: 0;
  left: -4%;
  right: -4%;
  height: 26%;
  background: var(--accent);
  border-radius: 6px 6px 0 0;
  clip-path: polygon(2% 100%, 0 0, 100% 0, 98% 100%);
}

.awning {
  position: absolute;
  top: 20%;
  left: 6%;
  width: 88%;
  height: 12%;
  background: repeating-linear-gradient(90deg, #ffffff 0 14px, var(--accent) 14px 28px);
  border-radius: 4px 4px 10px 10px;
  opacity: 0;
  transition: opacity 0.25s ease;
  box-shadow: 0 4px 8px rgba(43, 49, 64, 0.15);
}

.awning.owned {
  opacity: 1;
}

.shop-body {
  position: absolute;
  top: 30%;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--wall);
  border-radius: 8px 8px 4px 4px;
}

.window {
  position: absolute;
  top: 8%;
  left: 8%;
  width: 40%;
  height: 62%;
  background: #bfe8f7;
  border: 5px solid var(--wood);
  border-radius: 6px;
}

.plant-spot {
  position: absolute;
  bottom: -18px;
  left: 8%;
  font-size: 28px;
}

.flowerbox-spot {
  position: absolute;
  bottom: -14px;
  right: 8%;
  font-size: 26px;
}

.door {
  position: absolute;
  top: 10%;
  right: 8%;
  width: 34%;
  height: 72%;
  background: var(--wood);
  border-radius: 8px 8px 4px 4px;
}

.door-knob {
  position: absolute;
  right: 12%;
  top: 46%;
  width: 8px;
  height: 8px;
  background: var(--gold);
  border-radius: 50%;
}

.wreath-spot {
  position: absolute;
  top: 8%;
  left: 8%;
  font-size: 24px;
}

.pet-spot {
  position: absolute;
  bottom: 2%;
  font-size: 30px;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.pet-spot.owned {
  opacity: 1;
}

.pet-left {
  left: 2%;
}

.pet-right {
  right: 2%;
}

.sign-spot {
  position: absolute;
  top: -8%;
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
  border: 3px solid var(--ink);
  border-radius: 6px;
  color: var(--accent-dark);
  font-weight: 800;
  font-size: 12px;
  padding: 3px 8px;
  opacity: 0;
  transition: opacity 0.25s ease;
  white-space: nowrap;
}

.sign-spot.owned {
  opacity: 1;
}

.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 16%;
  background: #cfe8c9;
  border-top: 4px solid #b9d9b2;
}

.decoration-list {
  flex: 0 1 auto;
  max-height: 34vh;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.decoration-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.decoration-icon {
  font-size: 30px;
  line-height: 1;
}

.decoration-name {
  font-size: 14px;
  font-weight: 700;
}

.decoration-cost {
  font-size: 12px;
  color: var(--muted);
}

.buy-btn {
  min-height: 36px;
  background: var(--accent);
  color: #ffffff;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
}

.buy-btn:disabled {
  background: #e2e9ec;
  color: #98a3ad;
}

.achievement-section {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.achievement-section h2 {
  margin: 8px 0 10px;
  font-size: 16px;
}

.achievement-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.achievement-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  opacity: 0.55;
}

.achievement-card.unlocked {
  opacity: 1;
  border-color: var(--teal);
}

.achievement-icon {
  font-size: 24px;
  line-height: 1;
}

.achievement-name {
  font-size: 13px;
  font-weight: 700;
  margin: 5px 0 3px;
}

.achievement-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.daily-section,
.offer-section,
.record-section {
  flex: 0 0 auto;
}

.daily-section h2,
.offer-section h2,
.record-section h2 {
  margin: 8px 0 10px;
  font-size: 16px;
}

.daily-list,
.offer-list,
.record-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.daily-card,
.offer-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.daily-card.done {
  border-color: var(--teal);
}

.daily-icon {
  font-size: 22px;
  line-height: 1;
}

.daily-body {
  flex: 1;
  min-width: 0;
}

.daily-name {
  font-size: 13px;
  font-weight: 700;
}

.daily-bar {
  height: 6px;
  background: #e8eef1;
  border-radius: 4px;
  margin: 5px 0 3px;
  overflow: hidden;
}

.daily-bar div {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), #5fc7a9);
  border-radius: 4px;
  transition: width 0.2s ease;
}

.daily-count {
  font-size: 11px;
  color: var(--muted);
}

.offer-card {
  justify-content: space-between;
}

.offer-info {
  min-width: 0;
}

.offer-name {
  font-size: 13px;
  font-weight: 700;
}

.offer-desc {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.record-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
}

.record-item b {
  color: var(--accent-dark);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(28, 34, 46, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.overlay-card {
  width: min(92vw, 360px);
  background: var(--panel);
  border-radius: 8px;
  padding: 22px 18px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(28, 34, 46, 0.3);
}

.overlay-card h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.overlay-sub {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.tutorial-list {
  text-align: left;
  margin: 0 auto 16px;
  padding-left: 20px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.9;
}

.primary-btn,
.ghost-btn {
  width: 100%;
  min-height: 46px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 15px;
}

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

.ghost-btn {
  margin-top: 8px;
  background: #eef4f6;
  color: var(--ink);
}

.primary-btn:disabled {
  background: #e2e9ec;
  color: #98a3ad;
}

.privacy-link {
  display: inline-block;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}

.overlay-stats {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 8px 0 16px;
  font-size: 15px;
  font-weight: 700;
}

.best-line {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.ad-card {
  width: min(92vw, 320px);
}

.ad-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.ad-box {
  background: linear-gradient(135deg, #ffd166, #ff7a59);
  border-radius: 8px;
  padding: 22px 10px;
  margin-bottom: 12px;
  color: #ffffff;
}

.ad-emoji {
  font-size: 46px;
}

.ad-title {
  font-size: 18px;
  font-weight: 800;
  margin: 4px 0;
}

.ad-countdown {
  font-size: 26px;
  font-weight: 800;
}

.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: var(--ink);
  color: #ffffff;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 8px 20px rgba(28, 34, 46, 0.25);
}

@media (max-width: 420px) {
  #app {
    padding: 6px 8px 8px;
  }

  .order-card {
    min-height: 60px;
    padding: 6px 8px;
  }

  .order-icon {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
    font-size: 22px;
  }

  #trayPieces {
    gap: 10px;
    min-height: 100px;
  }

  .tray-piece {
    width: 80px;
    height: 88px;
  }

  #trayPieces .mini-grid {
    --cell: 18px;
  }
}
