:root {
  --bg: #f2f4f8;
  --panel: #f6f8fc;
  --white: #ffffff;
  --ink: #1f3557;
  --muted: #637a99;
  --line: #d6deea;
  --brand: #2b67f6;
  --brand-dark: #1f57da;
  --ok: #24c084;
  --radius: 16px;
  --shadow: 0 10px 26px rgba(28, 48, 85, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* Prevent horizontal overflow on small devices */
html, body { width: 100%; overflow-x: hidden; }

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 30px 20px 24px;
}

.page-header {
  text-align: center;
  margin-bottom: 24px;
}

.page-header h1 {
  margin: 0;
  font-size: 52px;
  letter-spacing: 2px;
  font-weight: 900;
}

.subtitle {
  margin: 10px 0 0;
  font-size: 26px;
  color: var(--muted);
  font-weight: 600;
}

.layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

.main-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
}

/* Drag highlight: when user is dragging over a module */
.drag-highlight {
  border-color: var(--brand) !important;
  box-shadow: 0 10px 30px rgba(43,103,246,0.12);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.side-panel {
  display: grid;
  gap: 20px;
}

.stepper {
  display: inline-flex;
  gap: 10px;
  padding: 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  margin-bottom: 14px;
}

.step {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
}

.step.active {
  color: #fff;
  background: var(--brand);
}

.field-block {
  margin-bottom: 18px;
}

h2, h3 {
  margin: 0 0 12px;
  font-size: 20px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 12px;
}

.preset-button {
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  font-size: 24px;
  padding: 14px 12px;
  cursor: pointer;
}

.preset-button.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.custom-amount,
.player-section {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

label {
  color: var(--muted);
  font-weight: 700;
  font-size: 18px;
}

input[type="text"],
input[type="number"] {
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 0 16px;
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
}

.hint,
.payment-tip,
.summary-hint {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.summary-grid {
  display: grid;
  gap: 10px;
}

.summary-row {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  font-size: 20px;
}

.summary-value {
  font-weight: 800;
}

.payment-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.payment-button {
  height: 72px;
  border-radius: 14px;
  border: 1px solid #acc2f6;
  background: #eaf0ff;
  color: var(--brand);
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 18px;
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.payment-button .payment-icon {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  color: inherit;
  transition: color 160ms ease, fill 160ms ease, transform 160ms ease;
}
.payment-button:hover {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand-dark);
  box-shadow: 0 8px 22px rgba(31,87,218,0.14);
  transform: translateY(-2px);
}
.payment-button:hover .payment-icon { color: #fff; }

/* Icon coloration and hover inversion */
.payment-icon .icon-bg,
.payment-icon .icon-fg,
.payment-icon .icon-dot { transition: fill 160ms ease, stroke 160ms ease; }

.payment-button:hover .payment-icon .icon-bg { fill: #fff !important; }
.payment-button:hover .payment-icon .icon-fg { fill: var(--brand) !important; stroke: var(--brand) !important; }
.payment-button:hover .payment-icon .icon-dot { fill: var(--brand) !important; }
.leaderboard-section,
.about-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.order-info {
  display: grid;
  justify-items: center;
  gap: 12px;
}

#qrcode canvas,
#qrcode img {
  width: 220px;
  height: 220px;
}

.qrcode-inline {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 8px;
  cursor: pointer;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 18px;
  cursor: pointer;
}

.pig-card {
  text-align: center;
}

.pig-avatar {
  font-size: 88px;
  line-height: 1;
}

.pig-card h3 {
  font-size: 34px;
}

.pig-card p {
  margin: 0;
  color: var(--muted);
  font-size: 17px;
}

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

/* Carousel styles for leaderboard */
.leaderboard-carousel {
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  height: 360px; /* fixed height to show multiple items */
}
.leaderboard-track {
  display: flex;
  flex-direction: column;
  transition: transform 400ms ease;
}

/* Continuous scroll animation */
.leaderboard-track {
  animation-play-state: running;
}

@keyframes leaderboard-scroll {
  from { transform: translateY(0); }
  to { transform: translateY(calc(-1 * var(--scroll-distance))); }
}

/* Pause on hover */
.leaderboard-carousel:hover .leaderboard-track {
  animation-play-state: paused;
}

/* Top and bottom fade overlays */
.leaderboard-carousel {
  position: relative;
}
.leaderboard-carousel::before,
.leaderboard-carousel::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 56px;
  pointer-events: none;
  z-index: 2;
}
.leaderboard-carousel::before {
  top: 0;
  background: linear-gradient(to bottom, var(--panel), rgba(246,248,252,0));
}
.leaderboard-carousel::after {
  bottom: 0;
  background: linear-gradient(to top, var(--panel), rgba(246,248,252,0));
}
.leaderboard-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
  min-height: 64px;
}
.leaderboard-avatar {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: #f0f4ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--brand);
}
.leaderboard-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.leaderboard-name {
  font-weight: 800;
  font-size: 18px;
}
.leaderboard-date {
  color: var(--muted);
  font-size: 13px;
}
.leaderboard-amount {
  color: var(--brand);
  font-weight: 800;
  font-size: 20px;
}

@media (max-width: 980px) {
  .leaderboard-carousel { height: 300px; }
}

.leaderboard-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 24px;
}

.about-card {
  margin-top: 20px;
}

.about-card p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

/* Note under leaderboard carousel */
.leaderboard-note {
  margin-top: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  padding: 8px 6px 2px 6px;
}
.leaderboard-note p { margin: 6px 0; }

/* Links under leaderboard */
.leaderboard-links {
  margin-top: 12px;
  display: flex;
  gap: 10px;
}
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--brand);
  font-weight: 700;
  text-decoration: none;
  transition: background-color 160ms ease, color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.link-button:hover {
  background: var(--brand);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(31,87,218,0.08);
}

@media (max-width: 820px) {
  .leaderboard-links {
    flex-direction: column;
  }
  .link-button {
    width: 100%;
    justify-content: center;
  }
}


.qr-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.qr-modal.show {
  display: flex;
}

.qr-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 38, 65, 0.52);
}

.qr-modal-panel {
  position: relative;
  width: min(90vw, 720px);
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  z-index: 1;
}

/* QR modal layout: left QR, right info */
.qr-modal-content {
  display: flex;
  gap: 18px;
  align-items: flex-start;
}
.qr-modal-qr {
  flex: 0 0 300px;
}
.qr-modal-qr img,
.qr-modal-qr canvas {
  width: 300px;
  height: 300px;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.qr-modal-info {
  flex: 1 1 auto;
  text-align: left;
}
.qr-modal-info .info-row {
  margin-bottom: 10px;
}
.qr-modal-info .info-row .label {
  color: var(--muted);
  font-size: 13px;
}
.qr-modal-info .info-row .value {
  font-weight: 800;
  font-size: 18px;
  color: var(--ink);
}
.qr-modal-info .notice {
  background: #fff7ea;
  border: 1px solid #f2dab0;
  padding: 12px;
  border-radius: 8px;
  color: #8a5a00;
  font-size: 13px;
}

.qr-modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
}

.qr-modal-body canvas,
.qr-modal-body img {
  width: 300px;
  height: 300px;
  max-width: 72vw;
  max-height: 72vw;
}

.qr-modal-hint {
  margin-top: 10px;
  color: var(--muted);
}

.qr-modal-close {
  position: absolute;
  right: 10px;
  top: 10px;
  border: none;
  background: #eef2fa;
  border-radius: 999px;
  width: 34px;
  height: 34px;
  font-size: 21px;
  cursor: pointer;
}

.qr-modal-help {
  position: absolute;
  right: 54px;
  top: 10px;
  border: none;
  background: #fff6e6;
  border-radius: 999px;
  width: 34px;
  height: 34px;
  font-size: 20px;
  cursor: pointer;
  color: #8a5a00;
}

.qr-modal-help-tooltip {
  position: absolute;
  right: 10px;
  top: 54px;
  width: 260px;
  background: #fff7ea;
  border: 1px solid #f2dab0;
  color: #8a5a00;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 3;
  box-shadow: 0 6px 18px rgba(28,48,85,0.08);
}

.qr-modal-help-tooltip[hidden] { display: none; }

/* show class used to toggle via JS */
.qr-modal-help-tooltip.show { display: block; }

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .container { padding-left: 14px; padding-right: 14px; }

  .page-header h1 {
    font-size: 40px;
  }

  .subtitle {
    font-size: 20px;
  }

  .preset-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .payment-options {
    grid-template-columns: 1fr;
  }
}

/* Responsive adjustments for QR modal and touch devices */
@media (max-width: 820px) {
  .qr-modal-panel {
    width: min(94vw, 560px);
    padding: 16px;
  }
  .qr-modal-content { gap: 12px; }
  .qr-modal-qr img, .qr-modal-qr canvas { width: 240px; height: 240px; }
}

@media (max-width: 480px) {
  .qr-modal-panel {
    width: 94vw;
    max-height: 94vh;
    overflow: auto;
    padding: 12px;
    border-radius: 12px;
  }
  .qr-modal-content { flex-direction: column; align-items: center; gap: 12px; }
  .qr-modal-qr img, .qr-modal-qr canvas { width: 220px; height: 220px; }
  .qr-modal-info { width: 100%; }
  .qr-modal-info .info-row { display: flex; justify-content: space-between; align-items: baseline; }
  .qr-modal-info .info-row .label { font-size: 12px; }
  .qr-modal-info .info-row .value { font-size: 16px; }
  .qr-modal-info .notice { font-size: 12px; padding: 10px; }
  .qr-modal-close { width: 40px; height: 40px; }
}

/* Prevent tooltip or other absolutes from forcing page width */
.qr-modal-help-tooltip {
  max-width: calc(100vw - 32px);
  box-sizing: border-box;
  word-break: break-word;
}

/* Ensure leaderboard track and cards do not exceed container width */
.leaderboard-carousel, .leaderboard-track, .leaderboard-card {
  box-sizing: border-box;
  max-width: 100%;
}

/* Slightly tighter preset grid on very small screens */
@media (max-width: 420px) {
  .preset-grid { grid-template-columns: repeat(2, minmax(100px, 1fr)); gap: 10px; }
  .preset-button { font-size: 22px; padding: 12px 10px; }
}

/* Mobile-specific adjustments */
@media (max-width: 820px) {
  /* Place help tooltip centered below header on small screens */
  .qr-modal-help-tooltip {
    position: absolute;
    right: 50%;
    transform: translateX(50%);
    top: 56px;
    left: 12px;
    width: calc(100% - 48px);
    box-sizing: border-box;
  }

  /* Increase touch targets */
  .payment-button {
    height: 76px;
    font-size: 22px;
    border-radius: 16px;
  }
  /* Slightly smaller icons on mobile to fit compact layouts */
  .payment-button .payment-icon {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
  }

  .preset-button {
    font-size: 28px;
    padding: 16px 12px;
  }

  input[type="text"], input[type="number"] {
    height: 68px;
    font-size: 26px;
    padding: 0 14px;
  }

  /* Leaderboard: disable auto animation on touch devices and allow native scrolling */
  .leaderboard-track {
    animation: none !important;
    display: block;
  }
  .leaderboard-carousel {
    height: auto;
    max-height: 420px;
    overflow: auto;
  }
  .leaderboard-card { margin-bottom: 12px; }

  /* Make modal action buttons easier to tap */
  .qr-modal-close, .qr-modal-help { width: 44px; height: 44px; }
}

/* For very small phones, ensure tooltip doesn't cover QR */
@media (max-width: 420px) {
  .qr-modal-help-tooltip { top: auto; bottom: 14px; transform: none; left: 12px; right: 12px; width: auto; }
  .qr-modal-qr img, .qr-modal-qr canvas { width: 200px; height: 200px; }
}

/* Improve touch target and centering for small screens */
.qr-modal-close { touch-action: manipulation; }
.qr-modal { align-items: center; justify-content: center; padding: 10px; }

/* Fireworks overlay and message */
.fireworks-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2000;
}

.fireworks-message {
  position: fixed;
  left: 50%;
  top: 32%;
  transform: translateX(-50%) translateY(-20%);
  z-index: 2001;
  background: rgba(255,255,255,0.9);
  color: var(--brand-dark);
  padding: 18px 26px;
  border-radius: 14px;
  font-size: 28px;
  font-weight: 900;
  box-shadow: 0 12px 32px rgba(28,48,85,0.14);
  opacity: 0;
  transition: transform 360ms cubic-bezier(.2,.9,.2,1), opacity 360ms ease;
}

/* fireworks removed */
