:root {
  --bg-top: #79b8ff;
  --bg-bottom: #cbe6ff;
  --modal-blue: #2f75d6;
  --modal-blue-dark: #2157a8;
  --modal-green: #2cc76f;
  --modal-green-dark: #1d9a53;
  --text-main: #28354a;
  --text-muted: #6c7a8e;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, #5da4f5 0%, #96ccff 50%, #cde7ff 100%);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Segoe UI", sans-serif;
  touch-action: manipulation;
}

.game-shell {
  width: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.canvas-stage {
  position: relative;
  height: min(calc(100dvh - 16px), 920px);
  width: min(calc(100vw - 16px), calc(min(calc(100dvh - 16px), 920px) * 450 / 800));
  aspect-ratio: 450 / 800;
  border-radius: 26px;
  overflow: hidden;
  box-shadow:
    0 22px 54px rgba(17, 63, 128, 0.28),
    0 0 0 3px rgba(255, 255, 255, 0.55);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

@media (max-width: 520px) {
  body {
    background: linear-gradient(180deg, #78b9ff 0%, #a2d2ff 55%, #cce7ff 100%);
  }

  .game-shell {
    padding: 0;
  }

  .canvas-stage {
    width: min(100vw, calc(100dvh * 450 / 800));
    height: min(100dvh, calc(100vw * 800 / 450));
    max-width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.home-screen {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 28px 26px;
  background: linear-gradient(180deg, #74b8ff 0%, #9fd0ff 55%, #cce7ff 100%);
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}

.home-screen.hidden {
  opacity: 0;
  transform: scale(1.03);
  pointer-events: none;
}

.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.home-emblem {
  width: 184px;
  height: 126px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 10px 18px rgba(24, 72, 148, 0.22));
}

.home-emblem-svg {
  width: 100%;
  height: 100%;
}

.home-title {
  font-size: 32px;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: 0.05em;
  text-shadow:
    0 3px 0 #2157a8,
    0 8px 18px rgba(17, 57, 122, 0.3);
}

.home-progress-card {
  width: 100%;
  max-width: 310px;
  background: rgba(255, 255, 255, 0.94);
  border: 3px solid #ffffff;
  border-radius: 22px;
  padding: 18px 20px;
  text-align: center;
  box-shadow: 0 12px 26px rgba(20, 66, 138, 0.16);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.home-level-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.home-level-value {
  font-size: 28px;
  font-weight: 900;
  color: #2157a8;
  font-variant-numeric: tabular-nums;
}

.home-unlock-info {
  font-size: 12px;
  font-weight: 700;
  color: #4f6789;
  font-variant-numeric: tabular-nums;
}

.home-actions {
  width: 100%;
  max-width: 310px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.home-start-btn {
  padding: 14px 18px;
  font-size: 20px;
}

.home-levels-btn {
  padding: 13px 18px;
  font-size: 17px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 34, 64, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
  opacity: 1;
  transition: opacity 0.18s ease-out;
}

.modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.game-modal {
  width: 100%;
  max-width: 340px;
  background: #ffffff;
  border-radius: 24px;
  border: 4px solid var(--modal-blue);
  box-shadow: 0 18px 40px rgba(15, 42, 84, 0.35);
  overflow: hidden;
  transform: scale(1);
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-backdrop.hidden .game-modal {
  transform: scale(0.92);
}

.modal-header {
  position: relative;
  background: linear-gradient(180deg, #4b8ff0 0%, var(--modal-blue) 100%);
  color: #ffffff;
  padding: 13px 44px;
  text-align: center;
  border-bottom: 3px solid var(--modal-blue-dark);
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 0 rgba(16, 48, 98, 0.45);
}

.modal-close-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close-btn:active {
  transform: translateY(-50%) scale(0.92);
}

.modal-body {
  padding: 18px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  color: var(--text-main);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f2f7ff;
  border-radius: 14px;
  padding: 10px 14px;
  border: 1.5px solid #dce8fa;
}

.setting-label {
  font-size: 15px;
  font-weight: 700;
}

.pill-toggle {
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  background: #c7d2e3;
  color: #3a4659;
  cursor: pointer;
}

.pill-toggle.active {
  background: #33c570;
  color: #ffffff;
  box-shadow: 0 3px 0 #219652;
}

.level-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

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

.unlock-progress {
  font-size: 12px;
  font-weight: 700;
  color: #2f75d6;
  font-variant-numeric: tabular-nums;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.level-chip {
  position: relative;
  border: 2px solid #d5e3f8;
  background: #f6faff;
  color: var(--text-main);
  border-radius: 10px;
  padding: 8px 2px;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.14s ease-out, background-color 0.14s ease-out, border-color 0.14s ease-out;
}

.level-chip:not(:disabled):hover {
  border-color: #6ea6f5;
}

.level-chip.cleared {
  background: #ebfaf1;
  border-color: #8ee0b0;
  color: #1c7c48;
}

.level-chip.current {
  background: #3d84eb;
  border-color: #2157a8;
  color: #ffffff;
  box-shadow: 0 3px 0 #2157a8;
}

.level-chip.locked,
.level-chip:disabled {
  background: #eef1f6;
  border-color: #dde3ec;
  color: #9ba6b8;
  cursor: not-allowed;
}

.level-badge {
  font-size: 10px;
  line-height: 1;
}

.level-pagination {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.page-btn {
  width: 32px;
  height: 30px;
  border: 1.5px solid #cbdcf5;
  background: #f4f8ff;
  color: #2f5596;
  border-radius: 9px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease-out, background-color 0.12s ease-out;
}

.page-btn:not(:disabled):hover {
  background: #e3efff;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-info {
  font-size: 12px;
  font-weight: 700;
  color: #4f5f78;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.revive-secondary-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.confirm-backdrop {
  z-index: 30;
}

.confirm-body {
  text-align: center;
  gap: 18px;
}

.confirm-message {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.5;
  color: #34435a;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-primary,
.btn-secondary,
.btn-green-cta {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease-out;
}

.btn-primary {
  background: linear-gradient(180deg, #4b94f7 0%, #2b6fd8 100%);
  color: #ffffff;
  box-shadow: 0 4px 0 #1b4ea3;
}

.btn-secondary {
  background: #edf3fc;
  color: #344a6e;
  border: 2px solid #cbdcf5;
}

.btn-green-cta {
  background: linear-gradient(180deg, #47dc85 0%, var(--modal-green) 100%);
  color: #ffffff;
  box-shadow: 0 4px 0 var(--modal-green-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 18px;
}

.btn-primary:active,
.btn-secondary:active,
.btn-green-cta:active {
  transform: translateY(2px);
}

.revive-body,
.victory-body {
  align-items: center;
  text-align: center;
}

.revive-illustration {
  width: 180px;
  height: 98px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.revive-svg {
  width: 100%;
  height: 100%;
}

.revive-desc {
  font-size: 17px;
  font-weight: 800;
  color: #2c384b;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.25);
  font-size: 12px;
}

.btn-text-muted {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 8px;
}

.victory-stars {
  font-size: 34px;
  letter-spacing: 6px;
  color: #ffb800;
  text-shadow: 0 3px 0 #c97f00;
}

.victory-desc {
  font-size: 16px;
  font-weight: 700;
  color: #36455c;
}

.ad-body {
  align-items: center;
  text-align: center;
  gap: 16px;
}

.ad-screen-box {
  width: 100%;
  min-height: 154px;
  background: #d7dde6;
  border: 2px solid #b5c0d0;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px;
  box-shadow: inset 0 2px 6px rgba(34, 48, 74, 0.08);
}

.ad-playing-text {
  font-size: 18px;
  font-weight: 800;
  color: #3d495c;
  letter-spacing: 0.02em;
}

.ad-reward-hint {
  font-size: 13px;
  font-weight: 700;
  color: #606e82;
}

@media (prefers-reduced-motion: reduce) {
  .home-screen,
  .modal-backdrop,
  .game-modal,
  .level-chip,
  .btn-primary,
  .btn-secondary,
  .btn-green-cta {
    transition: none;
  }
}
