:root {
  --ink: #3f4f3c;
  --muted: #6e7d64;
  --mint: #58b998;
  --pink: #ec8fa5;
  --cream: #fffdf4;
  --line: #dce6c9;
  --gold: #f4bd4d;
  --danger: #e67788;
  --accent: #58b998;
  --accent-glow: #9bd7b780;
  --text-main: #3f4f3c;
  --text-muted: #6e7d64;
  --bg-panel: #fffdf4;
  --bg-card: #f6f8ec;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: 'Trebuchet MS', 'Segoe UI', 'Microsoft YaHei', sans-serif;
  background: #e5f3d6;
}

body {
  background: url('assets/garden-background.webp') center center / cover no-repeat;
  user-select: none;
}

#fxCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 95;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  border: 0;
  font-weight: 800;
  transition: transform 0.14s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.14s;
}

button:hover {
  filter: brightness(1.04);
  transform: translateY(-2px);
}

button:active {
  transform: translateY(1px) scale(0.97);
}

button:focus-visible {
  outline: 3px solid #5ba88b;
  outline-offset: 3px;
}

img {
  object-fit: contain;
  pointer-events: none;
}

/* Unified Commercial Center Stage */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100dvh;
  max-width: 740px;
  margin: 0 auto;
  padding: 8px 16px max(10px, env(safe-area-inset-bottom));
  gap: 7px;
}

/* 1. Top Bar HUD */
.top-bar {
  width: 100%;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.brand-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.game-logo {
  width: 96px;
  height: 54px;
  flex-shrink: 0;
  filter: drop-shadow(0 3px 4px rgba(72, 100, 55, 0.25));
}

.icon-btns {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ui-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.level-pill, .coin-pill, .icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--cream);
  border: 2px solid #fff;
  box-shadow: 0 3px 0 #c2d4aa, 0 5px 12px rgba(75, 105, 50, 0.14);
  border-radius: 14px;
  min-height: 36px;
  padding: 4px 10px;
  font-size: 11px;
  white-space: nowrap;
}

.level-pill {
  background: linear-gradient(180deg, #f4fbea 0%, #e6f4d3 100%);
}

.coin-pill {
  background: linear-gradient(180deg, #fff9df 0%, #ffefb5 100%);
  min-width: 74px;
  font-weight: 900;
  color: #7d5d1a;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.coin-pill .ui-icon {
  width: 24px;
  height: 24px;
}

.coin-pill.coin-pop {
  animation: coinBounce 0.36s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.square-btn {
  width: 36px;
  padding: 5px;
}

.mode-btn {
  font-size: 11px;
  background: linear-gradient(180deg, #ffffff 0%, #eef6e4 100%);
}

.diff-tag {
  font-size: 8px;
  letter-spacing: 0.4px;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 900;
}

.diff-easy { background: #cfeab9; color: #397550; }
.diff-normal { background: #d4eaf4; color: #397496; }
.diff-hard { background: #ffe0bf; color: #b26b35; }
.diff-boss { background: #f8cfe0; color: #ad466a; }

/* 2. Top Collection & Waiting Dock Deck (Directly above Maze Exit!) */
.left-column.top-collection-deck {
  width: 100%;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1.08fr 1fr;
  align-items: stretch;
  gap: 10px;
  background: rgba(255, 253, 243, 0.95);
  padding: 8px 12px;
  border: 3px solid #ffffff;
  border-radius: 22px;
  box-shadow: 0 5px 0 #c9d8b0, 0 10px 24px rgba(68, 98, 44, 0.16);
}

.order-section, .dock-section {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #f4f8ea;
  border: 1.5px solid #e3ecd2;
  border-radius: 15px;
  padding: 6px 10px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-weight: 900;
  font-size: 10px;
  letter-spacing: 0.6px;
  color: #546949;
}

.section-caption {
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
}

.active-boxes {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 3px;
  min-height: 68px;
}

.order-box {
  position: relative;
  flex: 1;
  max-width: 138px;
  height: 68px;
  background-position: center bottom;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 2px;
  isolation: isolate;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.order-box.box-bounce {
  animation: boxBounce 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.order-box-title {
  font-size: 8.5px;
  font-weight: 900;
  color: #4c593f;
  background: rgba(255, 253, 242, 0.92);
  border: 1px solid #fff;
  border-radius: 7px;
  padding: 1px 6px;
  white-space: nowrap;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.order-slots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  margin-top: 9px;
}

.order-hole {
  width: 22px;
  height: 22px;
  background: rgba(255, 255, 255, 0.62);
  border: 1.5px dashed #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.order-hole img {
  width: 25px;
  height: 25px;
  max-width: none;
}

.order-hole.filled {
  border-color: transparent;
  background: transparent;
  animation: holePopIn 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.queue-preview {
  display: flex;
  align-items: center;
  gap: 4px;
}

.queue-label {
  font-size: 9px;
  color: var(--muted);
  font-weight: 800;
}

.queue-dots {
  display: flex;
  gap: 2px;
  align-items: center;
}

.queue-dot {
  width: 16px;
  height: 16px;
}

.free-banner {
  font-size: 10.5px;
  line-height: 1.4;
  text-align: left;
  color: #42856d;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 64px;
  padding: 2px 4px;
}

.free-banner img {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}

/* Waiting Dock */
.remain-pill {
  background: #e1eed0;
  color: #4f733b;
  border-radius: 7px;
  padding: 1px 6px;
  font-size: 9.5px;
  font-weight: 900;
}

.dock-slots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 5px 6px;
  background: #e8eed8;
  border: 1.5px solid #d8e1c3;
  border-radius: 14px;
  min-height: 46px;
  margin-top: 3px;
  box-shadow: inset 0 2px 4px rgba(95, 115, 65, 0.16);
}

.dock-slot {
  position: relative;
  flex: 0 1 36px;
  min-width: 0;
  aspect-ratio: 1;
  background: url('assets/socket.webp') center / 100% 100% no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dock-slot > img {
  width: 90%;
  height: 90%;
  animation: holePopIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dock-slot.vip-locked {
  background: linear-gradient(180deg, #fff9df 0%, #ffefba 100%);
  border: 1.5px dashed #d3b257;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
}

.vip-tag {
  font-size: 7.5px;
  line-height: 1.1;
  text-align: center;
  color: #8f7224;
  font-weight: 900;
}

.vip-tag img {
  display: block;
  width: 15px;
  height: 15px;
  margin: 0 auto 1px;
}

.dock-hint {
  font-size: 9px;
  color: var(--muted);
  line-height: 1.2;
  text-align: center;
  margin-top: 2px;
}

.danger-glow {
  border-color: #e67788 !important;
  background: #fde2e4 !important;
  animation: dangerPulse 0.7s infinite alternate;
}

/* 3. Center Maze Board Stage */
.right-column {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.board-area {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#mazeCanvas {
  border-radius: 22px;
  background: #f3f3dc;
  box-shadow:
    0 0 0 5px #fff9e9,
    0 0 0 8px #c4d5ab,
    0 8px 0 8px #b2c596,
    0 16px 32px rgba(65, 95, 38, 0.26);
  touch-action: none;
  cursor: pointer;
  flex-shrink: 0;
}

.hammer-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 460px);
  display: none;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 2px solid #fff7e6;
  border-radius: 14px;
  background: rgba(255, 236, 209, 0.97);
  box-shadow: 0 6px 16px rgba(145, 95, 45, 0.28);
  color: #935d38;
  font-size: 11px;
  font-weight: 900;
  z-index: 20;
}

.hammer-banner button {
  padding: 4px 10px;
  border-radius: 8px;
  background: #fff;
  color: #b55d52;
  margin-left: auto;
  box-shadow: 0 2px 0 #e5c6b8;
}

.hammer-banner .ui-icon {
  width: 24px;
  height: 24px;
}

/* 4. Bottom Rescue Power-Up Dock & Tip Bar */
.bottom-hud {
  width: 100%;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tools-section {
  width: 100%;
}

.powerup-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.power-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
  padding: 6px 8px;
  border: 2.5px solid #ffffff;
  border-radius: 16px;
  background: linear-gradient(180deg, #faeff4 0%, #f2e2ea 100%);
  box-shadow: 0 4px 0 #d9c5d0, 0 6px 14px rgba(85, 65, 78, 0.12);
  min-height: 48px;
}

.power-btn:nth-child(2) {
  background: linear-gradient(180deg, #eef9fa 0%, #dff0f2 100%);
  box-shadow: 0 4px 0 #bcd7da, 0 6px 14px rgba(55, 95, 100, 0.12);
}

.power-btn:nth-child(3) {
  background: linear-gradient(180deg, #f3f0fa 0%, #e7e2f5 100%);
  box-shadow: 0 4px 0 #cec5e3, 0 6px 14px rgba(75, 65, 105, 0.12);
}

.power-btn:nth-child(4) {
  background: linear-gradient(180deg, #f0f8e8 0%, #e2f0d5 100%);
  box-shadow: 0 4px 0 #c3d8b0, 0 6px 14px rgba(65, 95, 50, 0.12);
}

.power-icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.power-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}

.power-name {
  font-size: 10px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.shortcut-key {
  position: absolute;
  left: 5px;
  top: 3px;
  font-size: 8px;
  color: #8f858b;
  font-weight: 900;
}

.cost-badge {
  font-size: 9px;
  display: inline-flex;
  gap: 3px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 1px 6px;
  background: #fffaf0;
  color: #7d6732;
  border: 1px solid rgba(220, 195, 130, 0.5);
}

.cost-badge img {
  width: 12px;
  height: 12px;
}

.cost-ad {
  background: #fff0bf;
  color: #87691d;
}

.active-tool, .power-btn.tut-pulse {
  outline: 2.5px solid #f59e0b;
  outline-offset: 2px;
  animation: pulseTool 0.65s infinite alternate;
}

.tip-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: rgba(246, 250, 236, 0.92);
  border: 1.5px solid #ffffff;
  border-radius: 12px;
  padding: 4px 12px;
  box-shadow: 0 2px 8px rgba(75, 105, 50, 0.1);
}

.tip-icon {
  width: 18px;
  height: 20px;
  flex-shrink: 0;
}

.rules-bar {
  font-size: 10.5px;
  color: #5d6e50;
  line-height: 1.35;
  text-align: center;
}

.rules-bar b {
  color: #3d5630;
}

/* Toast Notification */
#toastBox {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  pointer-events: none;
  max-width: 90vw;
  padding: 9px 18px;
  border: 2.5px solid #fff;
  border-radius: 16px;
  background: rgba(255, 253, 242, 0.97);
  box-shadow: 0 5px 0 #d1dbb7, 0 10px 22px rgba(65, 95, 45, 0.25);
  font-size: 12px;
  font-weight: 900;
  color: #46593c;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.2s;
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  z-index: 120;
  background: rgba(68, 96, 66, 0.45);
  backdrop-filter: blur(8px);
  padding: 18px;
}

.modal-card {
  max-width: 420px;
  width: 100%;
  padding: 22px;
  border-radius: 28px;
  border: 4px solid #fff;
  background: #fffdf2;
  box-shadow: 0 8px 0 #d3dfb8, 0 24px 60px rgba(55, 80, 40, 0.32);
  text-align: center;
  max-height: calc(100dvh - 36px);
  overflow: auto;
  animation: popIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-title {
  font-size: 21px;
  font-weight: 900;
  line-height: 1.25;
  margin: 2px 0 8px;
  color: #4d8268;
}

.modal-desc {
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
  margin-bottom: 14px;
}

.modal-emblem {
  width: 58px;
  height: 58px;
  margin-bottom: 4px;
}

.result-art {
  width: 100%;
  height: 170px;
  object-fit: contain;
  margin-top: -6px;
  margin-bottom: 2px;
}

.modal-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 45px;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 12.5px;
  line-height: 1.4;
  margin-top: 10px;
  border: 2px solid #fff;
  box-shadow: 0 4px 0 #c5d5ac;
}

.modal-btn img {
  width: 22px;
  height: 22px;
}

.btn-gold {
  background: linear-gradient(180deg, #ffe596 0%, #f8d264 100%);
  color: #7c5e24;
  box-shadow: 0 4px 0 #dbb44e;
}

.btn-blue {
  background: linear-gradient(180deg, #b0e8d1 0%, #8ed4b8 100%);
  color: #2c644f;
  box-shadow: 0 4px 0 #6cb397;
}

.btn-dark {
  background: #e9efd9;
  color: #62784c;
}

/* 6-Chapter Level Select Modal & Locked States */
.level-card {
  max-width: 450px;
}

.chapter-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 12px 0;
}

.chap-tab {
  background: #edf1e2;
  border: 1.5px solid #dee6d1;
  color: #778762;
  font-size: 10px;
  border-radius: 10px;
  padding: 7px 4px;
}

.chap-tab.active {
  background: #d0e9c2;
  color: #3f764b;
  border-color: #9ec98f;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  max-height: 260px;
  overflow: auto;
  padding: 4px 4px 8px;
}

.lvl-btn {
  position: relative;
  background: #f1f6e8;
  border: 2px solid #fff;
  box-shadow: 0 3px 0 #cfdcc0;
  border-radius: 12px;
  min-height: 44px;
  font-size: 13px;
  color: #546946;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.lvl-btn.current {
  background: linear-gradient(180deg, #8ed4b0 0%, #6ec096 100%);
  color: #fff;
  box-shadow: 0 3px 0 #559e78;
}

.lvl-btn.locked {
  background: #e6eadf;
  color: #9aa391;
  box-shadow: 0 2px 0 #cfd5c7;
  opacity: 0.78;
}

.lvl-btn .lvl-lock-icon {
  width: 14px;
  height: 14px;
  margin-bottom: 1px;
  opacity: 0.8;
}

.lvl-btn.lvl-hard { border-color: #efd5aa; }
.lvl-btn.lvl-boss { border-color: #e5b7cb; }

.lvl-btn small {
  display: block;
  font-size: 6.5px;
  letter-spacing: 0.5px;
  margin-top: 1px;
}

/* Tutorial Modal */
.tut-badge {
  display: inline-block;
  border-radius: 12px;
  padding: 4px 10px;
  font-size: 9.5px;
  background: #e3f0d5;
  color: #5e8650;
  margin-bottom: 8px;
  letter-spacing: 0.4px;
  font-weight: 900;
}

.tutorial-card { max-width: 440px; }
.tutorial-card .modal-title { font-size: 20px; }

.tut-visual-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #edf3e2;
  border-radius: 18px;
  padding: 12px;
  margin: 12px 0;
}

.tut-visual-box img {
  width: 54px;
  height: 60px;
}

.tut-arrow {
  color: #82a369;
  font-size: 22px;
  padding: 0 4px;
}

.guide-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 290px;
  overflow: auto;
  text-align: left;
  scrollbar-width: thin;
}

.guide-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f0f4e7;
  border-radius: 14px;
  padding: 9px 10px;
}

.guide-icon {
  flex-shrink: 0;
  width: 38px;
}

.guide-icon img {
  width: 38px;
  height: 38px;
}

.guide-text {
  font-size: 11px;
  line-height: 1.5;
  color: #6b7a60;
}

.guide-text b {
  display: block;
  color: #496344;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 4px solid #e1ecd4;
  border-top-color: #8fc9a5;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 12px auto 18px;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes popIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes holePopIn {
  0% { transform: scale(0.3); opacity: 0.2; }
  70% { transform: scale(1.22); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes boxBounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.12) translateY(-3px); }
  75% { transform: scale(0.96); }
  100% { transform: scale(1); }
}
@keyframes coinBounce {
  0% { transform: scale(1); }
  45% { transform: scale(1.22); filter: brightness(1.12); }
  100% { transform: scale(1); }
}
@keyframes dangerPulse {
  to { box-shadow: 0 0 0 3px rgba(230, 119, 136, 0.35); }
}
@keyframes pulseTool {
  to { transform: translateY(-2px) scale(1.03); }
}

/* Mobile / Portrait Responsive Adjustments */
@media (max-width: 600px) {
  #app {
    padding: 6px 10px max(8px, env(safe-area-inset-bottom));
    gap: 5px;
  }
  .game-logo {
    width: 74px;
    height: 44px;
  }
  .level-pill, .coin-pill, .icon-btn {
    min-height: 31px;
    padding: 3px 7px;
    font-size: 10px;
    border-radius: 11px;
  }
  .square-btn {
    width: 31px;
  }
  .ui-icon {
    width: 18px;
    height: 18px;
  }
  .left-column.top-collection-deck {
    grid-template-columns: 1fr;
    gap: 5px;
    padding: 6px 8px;
    border-radius: 18px;
  }
  .order-section, .dock-section {
    padding: 4px 8px;
  }
  .active-boxes {
    min-height: 58px;
  }
  .order-box {
    height: 58px;
    max-width: 122px;
  }
  .order-slots {
    margin-top: 6px;
  }
  .order-hole {
    width: 19px;
    height: 19px;
  }
  .order-hole img {
    width: 22px;
    height: 22px;
  }
  .dock-slots {
    min-height: 38px;
    padding: 3px 4px;
  }
  .dock-slot {
    flex-basis: 31px;
  }
  .dock-hint {
    display: none;
  }
  .powerup-bar {
    gap: 5px;
  }
  .power-btn {
    padding: 4px 5px;
    min-height: 42px;
    border-radius: 13px;
  }
  .power-icon {
    width: 26px;
    height: 26px;
  }
  .power-name {
    font-size: 8.5px;
  }
  .cost-badge {
    font-size: 8px;
    padding: 1px 4px;
  }
  .shortcut-key {
    display: none;
  }
  .tip-card {
    padding: 3px 8px;
  }
  .rules-bar {
    font-size: 9.5px;
  }
}

/* Short-Height Landscape Viewport (e.g. 1024x580 / Mobile Landscape) */
@media (max-height: 670px) and (min-width: 601px) {
  #app {
    padding: 4px 14px 6px;
    gap: 4px;
  }
  .game-logo {
    width: 76px;
    height: 42px;
  }
  .level-pill, .coin-pill, .icon-btn {
    min-height: 30px;
    padding: 2px 8px;
    font-size: 10px;
  }
  .left-column.top-collection-deck {
    padding: 5px 10px;
    gap: 8px;
  }
  .active-boxes {
    min-height: 56px;
  }
  .order-box {
    height: 56px;
  }
  .order-slots {
    margin-top: 5px;
  }
  .order-hole {
    width: 19px;
    height: 19px;
  }
  .dock-slots {
    min-height: 38px;
  }
  .dock-hint {
    display: none;
  }
  .power-btn {
    min-height: 40px;
    padding: 3px 6px;
  }
  .power-icon {
    width: 26px;
    height: 26px;
  }
  .tip-card {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
