/* ============ 《花光马斯克的钱》卡通主题 ============ */

@font-face {
  font-family: "KuaiLe";
  src: url("../assets/fonts/ZCOOLKuaiLe-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg: #FDF3E3;
  --ink: #2B2B2B;
  --red: #FF5D5D;
  --orange: #FFA94D;
  --yellow: #FFD43B;
  --green: #69DB7C;
  --blue: #4DABF7;
  --purple: #9775FA;
  --pink: #F783AC;
  --paper: #FFFFFF;
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --font-cartoon: "KuaiLe", "Hiragino Sans GB", "Yuanti SC", "STHeiti", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-cartoon);
  background: var(--bg);
  background-image: radial-gradient(#F5E3C0 12%, transparent 13%),
                    radial-gradient(#F5E3C0 12%, transparent 13%);
  background-size: 48px 48px;
  background-position: 0 0, 24px 24px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ============ 顶栏 ============ */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--yellow);
  border-bottom: 4px solid var(--ink);
  box-shadow: 0 4px 0 rgba(43,43,43,.15);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto;
  padding: 10px 16px;
  display: flex; align-items: center; gap: 18px;
  flex-wrap: wrap;
}
.who { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 64px; height: 64px; border-radius: 50%;
  border: 3px solid var(--ink); box-shadow: var(--shadow-sm);
  background: #fff; object-fit: cover;
  transition: transform .2s;
}
.avatar:hover { transform: rotate(-6deg) scale(1.06); }
.site-title { font-size: 26px; letter-spacing: 2px; line-height: 1.1; }
.site-sub { font-size: 13px; opacity: .65; }

.balance-box { flex: 1; min-width: 260px; text-align: center; }
.balance-label { font-size: 12px; opacity: .6; letter-spacing: 4px; }
.balance {
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1.15;
  color: var(--ink);
  text-shadow: 2px 2px 0 #fff;
  transition: color .15s;
}
.balance.flash { color: var(--red); animation: shake .35s; }
.balance-unit { font-size: 14px; opacity: .75; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}
.spent-bar {
  height: 10px; margin: 6px auto 2px; max-width: 420px;
  background: #fff; border: 2px solid var(--ink); border-radius: 99px;
  overflow: hidden;
}
.spent-bar i {
  display: block; height: 100%; width: 0%;
  background: repeating-linear-gradient(45deg, var(--red) 0 8px, var(--orange) 8px 16px, var(--yellow) 16px 24px);
  transition: width .4s;
}
.stats { font-size: 16px; opacity: 1; margin-top: 3px; }

.actions { display: flex; gap: 10px; }

/* ============ 按钮 ============ */
.btn {
  font-family: var(--font-cartoon);
  font-size: 16px; letter-spacing: 1px;
  padding: 8px 16px;
  background: #fff; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 14px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
  white-space: nowrap;
}
.btn:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(3px,3px); box-shadow: none; }
.btn-receipt { background: var(--blue); color: #fff; }
.btn-reset { background: #fff; }
.btn-print { background: var(--green); }

/* ============ 主体 ============ */
#main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; }

.sec { margin-bottom: 34px; }
.sec-head {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--paper);
  border: 3px solid var(--ink); border-radius: 99px;
  box-shadow: var(--shadow-sm);
  padding: 6px 22px;
  margin-bottom: 16px;
  font-size: 22px; letter-spacing: 2px;
  position: relative; top: 2px;
}
.sec-head .cnt { font-size: 14px; opacity: .55; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}

.card {
  background: var(--paper);
  border: 3px solid var(--ink); border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: transform .12s;
  position: relative;
}
.card:hover { transform: translate(-2px,-2px); box-shadow: 6px 6px 0 var(--ink); }
.card.shake { animation: shake .35s; }

.imgwrap {
  position: relative; aspect-ratio: 1/1;
  background: #F7F7F5; border-bottom: 3px solid var(--ink);
  overflow: hidden;
}
.imgwrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.imgwrap .ph {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  font-size: 64px; background: #FFF6E5;
}
.imgwrap.noimg .ph { display: flex; }
.qty-badge {
  position: absolute; top: 10px; right: 10px;
  min-width: 34px; text-align: center;
  background: var(--red); color: #fff;
  border: 3px solid var(--ink); border-radius: 12px;
  font-size: 15px; padding: 2px 8px;
  box-shadow: var(--shadow-sm);
  display: none;
}
.card.owned .qty-badge { display: block; }
.card.owned .imgwrap img { filter: saturate(.92); }

.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.cname { font-size: 18px; line-height: 1.25; }
.cprice { font-size: 20px; color: #E8590C; }
.cprice small { display: block; font-size: 11px; color: #A8A29E; font-family: Menlo, monospace; }
.cnote { font-size: 12px; color: #8C8A84; line-height: 1.4; flex: 1; }

.controls { display: flex; gap: 8px; align-items: stretch; margin-top: 4px; }
.btn-buy {
  flex: 1;
  font-family: var(--font-cartoon);
  font-size: 18px; letter-spacing: 2px;
  padding: 8px 0;
  background: var(--green); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer; transition: transform .08s, box-shadow .08s, opacity .2s;
}
.btn-buy:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.btn-buy:active { transform: translate(3px,3px); box-shadow: none; }
.btn-buy:disabled { opacity: .38; cursor: not-allowed; }
.btn-buy:disabled:hover { transform: none; box-shadow: var(--shadow-sm); }

.stepper { display: none; flex: 1; gap: 8px; }
.card.owned .stepper { display: flex; }
.card.owned .btn-buy { display: none; }
.stepper button {
  font-family: var(--font-cartoon);
  width: 40px; font-size: 20px;
  border: 3px solid var(--ink); border-radius: 12px;
  box-shadow: var(--shadow-sm); cursor: pointer;
  background: #fff; transition: transform .08s, box-shadow .08s;
}
.stepper button:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.stepper button:active { transform: translate(3px,3px); box-shadow: none; }
.stepper .plus { background: var(--green); }
.stepper .qty-num {
  flex: 1; display: flex; align-items: center; justify-content: center;
  font-size: 18px; background: #FFF6E5;
  border: 3px solid var(--ink); border-radius: 12px;
}
.btn-sell {
  width: 52px; font-size: 13px;
  font-family: var(--font-cartoon);
  border: 3px solid var(--ink); border-radius: 12px;
  box-shadow: var(--shadow-sm); cursor: pointer;
  background: var(--pink); color: var(--ink);
}
.btn-sell:active { transform: translate(3px,3px); box-shadow: none; }

/* 钞票粒子 */
.bill {
  position: fixed; z-index: 300; pointer-events: none;
  font-size: 22px;
  animation: fly .8s ease-out forwards;
}
@keyframes fly {
  0% { transform: translate(0,0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}

/* ============ toast ============ */
.toast-wrap {
  position: fixed; top: 86px; left: 50%; transform: translateX(-50%);
  z-index: 400; display: flex; flex-direction: column; gap: 10px; align-items: center;
  width: max-content; max-width: 92vw;
}
.toast {
  background: var(--ink); color: #FFE8A3;
  border: 3px solid #fff; border-radius: 16px;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
  padding: 14px 28px; font-size: 20px; letter-spacing: 1px;
  animation: toastIn .3s ease-out;
  text-align: center;
}
@keyframes toastIn { from { transform: translateY(-14px) scale(.9); opacity: 0; } }

/* ============ 小票 ============ */
.modal-mask {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(43,43,43,.55);
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; padding: 4vh 12px;
}
.modal-mask[hidden] { display: none; }
.receipt {
  background: #fff; width: 360px; max-width: 94vw;
  padding: 22px 20px 18px;
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  font-family: "Menlo", "SF Mono", monospace;
  position: relative;
}
.receipt::before, .receipt::after {
  content: ""; position: absolute; left: 0; right: 0; height: 10px;
  background: linear-gradient(135deg, transparent 5px, #fff 0) 0 0 / 14px 100%,
              linear-gradient(-135deg, transparent 5px, #fff 0) 7px 0 / 14px 100%;
}
.receipt::before { top: -9px; }
.receipt::after { bottom: -9px; transform: scaleY(-1); }
.receipt-head { text-align: center; border-bottom: 2px dashed #999; padding-bottom: 10px; margin-bottom: 10px; }
.receipt-title { font-size: 20px; letter-spacing: 2px; color: var(--ink); }
.receipt-sub { font-size: 13px; color: #666; margin-top: 2px; }
.receipt-date { font-size: 11px; color: #999; margin-top: 4px; }
.receipt-lines { max-height: 44vh; overflow-y: auto; margin-bottom: 8px; }
.rl { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 4px 0; }
.rl .n { flex: 1; word-break: break-all; }
.rl .m { white-space: nowrap; }
.rl-head { font-weight: bold; color: #999; border-bottom: 1px solid #ddd; }
.receipt-total {
  display: flex; justify-content: space-between;
  border-top: 2px dashed #999; padding-top: 10px;
  font-size: 16px; font-weight: bold;
}
.receipt-egg { font-size: 11px; color: #E8590C; margin-top: 6px; text-align: center; line-height: 1.5; }
.receipt-barcode {
  height: 36px; margin: 12px auto 4px; width: 82%;
  background: repeating-linear-gradient(90deg, #111 0 2px, #fff 2px 4px, #111 4px 5px, #fff 5px 9px, #111 9px 12px, #fff 12px 14px);
}
.receipt-thanks { text-align: center; font-size: 11px; color: #999; }
.receipt-btns { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.receipt-btns .btn { font-family: var(--font-cartoon); }

@media print {
  body > *:not(.modal-mask) { display: none !important; }
  .modal-mask { position: static; background: none; padding: 0; }
  .modal-mask[hidden] { display: none !important; }
  .receipt-btns { display: none !important; }
}

/* ============ 花光庆祝 ============ */
.win-mask {
  position: fixed; inset: 0; z-index: 600;
  background: rgba(255, 213, 79, .92);
  display: flex; align-items: center; justify-content: center;
}
.win-mask[hidden] { display: none; }
.win-card {
  text-align: center;
  background: #fff; border: 4px solid var(--ink); border-radius: 24px;
  box-shadow: 8px 8px 0 var(--ink);
  padding: 36px 30px; max-width: 92vw;
  animation: winPop .45s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes winPop { from { transform: scale(.5) rotate(-4deg); opacity: 0; } }
.win-emoji { font-size: 40px; }
.win-title {
  font-size: clamp(26px, 5vw, 40px); letter-spacing: 2px; margin: 10px 0;
  color: var(--red); text-shadow: 2px 2px 0 var(--yellow);
}
.win-sub { font-size: 16px; line-height: 1.6; margin-bottom: 20px; }
.win-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.confetti-holder { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti {
  position: absolute; top: -20px;
  width: 12px; height: 20px;
  animation: drop linear infinite;
}
@keyframes drop {
  0% { transform: translateY(-30px) rotate(0); }
  100% { transform: translateY(105vh) rotate(720deg); }
}

/* ============ 页脚 ============ */
.foot { text-align: center; padding: 10px 16px 30px; font-size: 13px; color: #A8A29E; }

/* ============ 移动端 ============ */
@media (max-width: 720px) {
  .topbar-inner { justify-content: center; text-align: center; gap: 10px; }
  .who { flex-direction: column; gap: 4px; }
  .site-title { font-size: 20px; }
  .avatar { width: 52px; height: 52px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .card-body { padding: 10px; }
  .cname { font-size: 15px; }
  .cprice { font-size: 16px; }
  .cnote { font-size: 11px; }
  .actions { width: 100%; justify-content: center; }
  .stats { font-size: 14px; }
  .toast { font-size: 17px; padding: 12px 20px; }
}
