:root {
  --bg-top: #2b1d17;
  --bg-bottom: #120d0a;
  --panel: rgba(58, 37, 28, 0.9);
  --panel-border: rgba(215, 188, 141, 0.18);
  --gold: #b99653;
  --gold-soft: #e8d4a5;
  --ink: #f5ecdc;
  --muted: #bda98c;
  --accent: #6f8a6d;
  --danger: #d88c70;
  --tile-size: 72px;
  --gap: 10px;
  --lane-size: calc(var(--tile-size) + var(--gap));
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 14%, rgba(191, 152, 89, 0.09), transparent 20%),
    radial-gradient(circle at 82% 18%, rgba(110, 138, 109, 0.08), transparent 18%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  -webkit-tap-highlight-color: transparent;
}

body::before,
body::after {
  content: "";
  position: fixed;
  width: 320px;
  height: 320px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(185, 150, 83, 0.1), transparent 70%);
  pointer-events: none;
  filter: blur(8px);
}

body::before {
  top: -80px;
  right: -80px;
}

body::after {
  bottom: -100px;
  left: -100px;
}

.app-shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 24px auto;
  padding: 26px;
  background:
    linear-gradient(180deg, rgba(255, 245, 225, 0.04), rgba(255, 245, 225, 0.01)),
    var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 30px;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 244, 223, 0.04);
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  align-items: center;
}

.brand-block {
  display: flex;
  align-items: center;
}

.game-title {
  margin: 0;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1;
  letter-spacing: 4px;
  color: #f5e7c8;
  text-shadow:
    0 2px 0 rgba(56, 32, 20, 0.5),
    0 8px 18px rgba(0, 0, 0, 0.24);
}

.level-switch,
.status-strip,
.controls-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.level-btn,
.tool-btn,
.sound-toggle {
  border: 0;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.level-btn {
  padding: 13px 20px;
  background: linear-gradient(180deg, #6a4c3a, #4a3429);
  border-radius: 999px;
  font-weight: 700;
  color: #f1e6d2;
  box-shadow:
    inset 0 1px 0 rgba(255, 239, 214, 0.08),
    0 8px 18px rgba(0, 0, 0, 0.16);
  border: 1px solid rgba(215, 188, 141, 0.1);
}

.level-btn.active {
  background: linear-gradient(180deg, #d3b171, #b58b48);
  color: #3b2618;
  box-shadow: 0 10px 22px rgba(181, 139, 72, 0.24);
}

.status-card {
  min-width: 120px;
  padding: 12px 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 245, 225, 0.08), rgba(255, 245, 225, 0.03));
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ink);
  border: 1px solid rgba(215, 188, 141, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 244, 223, 0.04);
}

.status-card span:last-child {
  font-weight: 800;
}

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

.sound-panel-wrap {
  position: relative;
}

.sound-toggle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(180deg, #6a4c3a, #4a3429);
  font-size: 22px;
  color: #f1e6d2;
  box-shadow:
    inset 0 1px 0 rgba(255, 239, 214, 0.08),
    0 8px 18px rgba(0, 0, 0, 0.16);
  border: 1px solid rgba(215, 188, 141, 0.1);
}

.sound-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 280px;
  padding: 14px;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(83, 55, 41, 0.98), rgba(55, 37, 29, 0.98));
  color: var(--ink);
  border: 1px solid rgba(215, 188, 141, 0.14);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.24);
  z-index: 30;
}

.sound-panel.hidden {
  display: none;
}

.sound-panel-title {
  margin-bottom: 10px;
  font-size: 16px;
  font-weight: 800;
  color: #f1dfb3;
}

.sound-row {
  display: grid;
  grid-template-columns: 74px 1fr 46px;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 14px;
}

.sound-row input[type="range"] {
  accent-color: var(--gold);
}

.mini-toggle {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  color: #332115;
  font-weight: 700;
  background: linear-gradient(180deg, #d3b171, #b58b48);
  box-shadow: 0 8px 16px rgba(181, 139, 72, 0.16);
}

.game-panel {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.level-switch-panel {
  justify-content: center;
}

.controls-panel {
  justify-content: center;
}

.controls-panel-bottom {
  margin-top: 2px;
}

.tool-btn {
  padding: 14px 22px;
  border-radius: 18px;
  background: linear-gradient(180deg, #f1e2bf, #d8bb82);
  font-size: 16px;
  font-weight: 700;
  color: #3b2618;
  box-shadow: 0 8px 18px rgba(181, 139, 72, 0.16);
  border: 1px solid rgba(215, 188, 141, 0.12);
}

.tool-btn.secondary {
  background: linear-gradient(180deg, #7a8d71, #5f7258);
  color: #f5ecdc;
  box-shadow: 0 8px 18px rgba(95, 114, 88, 0.16);
}

.tool-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

.level-btn:hover,
.tool-btn:hover,
.sound-toggle:hover {
  transform: translateY(-2px);
}

.board-frame {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 420px;
  padding: 28px;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 245, 225, 0.08), rgba(255, 245, 225, 0.03));
  overflow: auto;
  border: 1px solid rgba(215, 188, 141, 0.08);
  -webkit-overflow-scrolling: touch;
}

.board-stage {
  position: relative;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: var(--lane-size);
  border-radius: 26px;
  background:
    radial-gradient(circle at center, rgba(255, 245, 225, 0.04), transparent 55%),
    linear-gradient(180deg, #475946, #344334);
  box-shadow:
    inset 0 0 0 1px rgba(255, 245, 225, 0.08),
    0 14px 28px rgba(0, 0, 0, 0.22);
}

#path-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}

.board {
  position: relative;
  z-index: 2;
  display: grid;
  gap: var(--gap);
  justify-content: center;
  align-content: center;
}

.tile {
  position: relative;
  width: var(--tile-size);
  height: var(--tile-size);
  padding: 4px;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(180deg, #fffdf8, #efe3c8);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.88),
    inset 0 -6px 0 rgba(122, 85, 34, 0.2),
    0 10px 16px rgba(0, 0, 0, 0.16);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, outline-color 0.18s ease;
  touch-action: manipulation;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 14px;
  border: 1px solid rgba(131, 97, 47, 0.18);
  pointer-events: none;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.tile.selected {
  outline: 3px solid rgba(52, 196, 154, 0.95);
  outline-offset: 2px;
  transform: translateY(-2px) scale(1.03);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.92),
    inset 0 -6px 0 rgba(122, 85, 34, 0.2),
    0 16px 28px rgba(28, 38, 33, 0.16),
    0 0 0 4px rgba(52, 196, 154, 0.16);
}

.tile.hint {
  animation: hintPulseStrong 1.45s ease-in-out 4;
  outline: 4px solid rgba(255, 218, 92, 0.98);
  outline-offset: 3px;
  z-index: 12;
}

.tile.invalid {
  animation: invalidShake 0.32s ease-in-out 1;
}

.tile.removing {
  animation: dissolveTile 0.55s ease forwards;
}

.tile.removing img {
  animation: dissolveImage 0.55s ease forwards;
}

.tile.removing::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 12px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.92), transparent 28%),
    radial-gradient(circle at 78% 28%, rgba(255, 238, 190, 0.78), transparent 26%),
    radial-gradient(circle at 38% 74%, rgba(246, 200, 95, 0.7), transparent 24%);
  animation: emberFade 0.55s ease forwards;
}

.tile.empty {
  visibility: hidden;
  pointer-events: none;
}

.tile:hover {
  transform: translateY(-3px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.9),
    inset 0 -6px 0 rgba(122, 85, 34, 0.2),
    0 16px 28px rgba(0, 0, 0, 0.26);
}

.message-row {
  display: flex;
  justify-content: center;
}

.message {
  min-height: 34px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 245, 225, 0.08);
  border: 1px solid rgba(215, 188, 141, 0.08);
  color: #e6d7b5;
  text-align: center;
}

.win-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 10, 18, 0.55);
  backdrop-filter: blur(8px);
  z-index: 60;
}

.win-modal.hidden {
  display: none;
}

.win-modal-card {
  position: relative;
  width: min(480px, calc(100vw - 28px));
  padding: 28px 26px 24px;
  border-radius: 28px;
  text-align: center;
  background:
    radial-gradient(circle at top, rgba(185, 150, 83, 0.14), transparent 34%),
    linear-gradient(180deg, rgba(83, 55, 41, 0.98), rgba(55, 37, 29, 0.98));
  border: 1px solid rgba(215, 188, 141, 0.12);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
  animation: winModalRise 0.42s ease;
}

.win-modal-title {
  font-size: 30px;
  font-weight: 900;
  color: #f2e3c0;
  margin-bottom: 14px;
}

.win-summary {
  font-size: 18px;
  line-height: 1.7;
  color: #f5ecdc;
  margin-bottom: 10px;
}

.win-best-message {
  min-height: 34px;
  margin-bottom: 18px;
  font-size: 17px;
  color: #e8d4a5;
  font-weight: 800;
}

.play-again-btn {
  min-width: 180px;
}

.win-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.win-burst span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  margin: -5px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff4bf, #f6c85f);
  box-shadow: 0 0 18px rgba(255, 221, 125, 0.75);
  animation: burstOut 1.15s ease-out infinite;
}

.win-burst span:nth-child(1) { animation-delay: 0s; }
.win-burst span:nth-child(2) { animation-delay: 0.16s; }
.win-burst span:nth-child(3) { animation-delay: 0.32s; }
.win-burst span:nth-child(4) { animation-delay: 0.48s; }
.win-burst span:nth-child(5) { animation-delay: 0.64s; }
.win-burst span:nth-child(6) { animation-delay: 0.8s; }

@keyframes hintPulseStrong {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      inset 0 2px 0 rgba(255, 255, 255, 0.88),
      inset 0 -6px 0 rgba(122, 85, 34, 0.2),
      0 12px 20px rgba(0, 0, 0, 0.22),
      0 0 0 0 rgba(255, 210, 70, 0.2);
  }
  50% {
    transform: scale(1.11);
    box-shadow:
      inset 0 2px 0 rgba(255, 255, 255, 0.9),
      inset 0 -6px 0 rgba(122, 85, 34, 0.2),
      0 18px 30px rgba(0, 0, 0, 0.28),
      0 0 0 8px rgba(255, 210, 70, 0.22),
      0 0 24px rgba(255, 218, 92, 0.65);
  }
}

@keyframes winModalRise {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes burstOut {
  0% {
    transform: translate(-50%, -50%) scale(0.4);
    opacity: 0;
  }
  25% {
    opacity: 1;
  }
  100% {
    transform:
      translate(
        calc(-50% + (var(--burst-x, 0px))),
        calc(-50% + (var(--burst-y, -120px)))
      )
      scale(1.3);
    opacity: 0;
  }
}

.win-burst span:nth-child(1) { --burst-x: -150px; --burst-y: -90px; }
.win-burst span:nth-child(2) { --burst-x: 145px; --burst-y: -110px; }
.win-burst span:nth-child(3) { --burst-x: -170px; --burst-y: 48px; }
.win-burst span:nth-child(4) { --burst-x: 168px; --burst-y: 54px; }
.win-burst span:nth-child(5) { --burst-x: -40px; --burst-y: -155px; }
.win-burst span:nth-child(6) { --burst-x: 26px; --burst-y: 160px; }

@keyframes invalidShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

@keyframes dissolveTile {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(1.1); }
}

@keyframes dissolveImage {
  from { opacity: 1; filter: blur(0); transform: scale(1); }
  to { opacity: 0; filter: blur(12px); transform: scale(1.18); }
}

@keyframes emberFade {
  from { opacity: 0.85; transform: scale(0.8); }
  to { opacity: 0; transform: scale(1.28); }
}

@media (max-width: 980px) {
  :root {
    --tile-size: 62px;
    --gap: 8px;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .status-strip,
  .level-switch,
  .controls-panel {
    justify-content: center;
  }

  .brand-block {
    justify-content: center;
  }

  .sound-toggle {
    justify-self: center;
  }

  .sound-panel {
    right: 50%;
    transform: translateX(50%);
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 16px, 100%);
    margin: 8px auto;
    padding: 12px;
    border-radius: 24px;
  }

  .status-card {
    min-width: 88px;
    padding: 8px 12px;
  }

  .level-btn,
  .tool-btn {
    min-height: 42px;
    padding: 10px 14px;
    font-size: 14px;
  }

  .board-frame {
    min-height: 320px;
    padding: 12px;
  }

  .board-stage {
    padding: calc(var(--tile-size) * 0.8);
  }

  .win-modal-card {
    width: min(100vw - 24px, 100%);
    padding: 22px 18px 18px;
    border-radius: 22px;
  }

  .win-modal-title {
    font-size: 24px;
  }
}

@media (max-width: 520px) {
  .topbar {
    gap: 10px;
  }

  .game-title {
    font-size: 28px;
    letter-spacing: 2px;
  }

  .status-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .status-card {
    min-width: 0;
    padding: 8px 10px;
    border-radius: 14px;
  }

  .label {
    font-size: 11px;
  }

  .sound-panel {
    width: min(92vw, 300px);
  }

  .controls-panel,
  .level-switch {
    gap: 8px;
  }

  .tool-btn,
  .level-btn {
    flex: 1 1 calc(50% - 8px);
  }

  .controls-panel-bottom .tool-btn {
    flex-basis: calc(33.333% - 8px);
    min-width: 92px;
  }

  .message {
    width: 100%;
    font-size: 13px;
    line-height: 1.5;
  }
}

@media (max-width: 420px) {
  .app-shell {
    width: calc(100vw - 10px);
    margin: 5px auto;
    padding: 10px;
    border-radius: 20px;
  }

  .topbar {
    gap: 8px;
  }

  .game-title {
    font-size: 24px;
  }

  .status-strip {
    gap: 6px;
  }

  .status-card {
    padding: 7px 8px;
  }

  .board-frame {
    padding: 8px;
    min-height: 260px;
    border-radius: 20px;
  }

  .board-stage {
    border-radius: 18px;
    padding: calc(var(--tile-size) * 0.68);
  }

  .controls-panel-bottom .tool-btn,
  .level-btn {
    min-height: 40px;
    padding: 8px 10px;
    font-size: 13px;
  }

  .sound-toggle {
    width: 42px;
    height: 42px;
    font-size: 20px;
  }

  .sound-panel {
    width: min(96vw, 280px);
    padding: 12px;
  }

  .sound-row {
    grid-template-columns: 62px 1fr 40px;
    gap: 8px;
    font-size: 13px;
  }
}
