:root {
  --xy-yellow: #ffda44;
  --xy-yellow-dark: #f5c800;
  --xy-black: #1f1f1f;
  --xy-bg: #f5f5f5;
  --xy-text: #333;
  --xy-muted: #999;
  --xy-scalper-bubble: #fff;
  --xy-user-bubble: #ffda44;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif;
  background: var(--xy-bg);
  color: var(--xy-text);
  overflow: hidden;
}

#app {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Loading */
#loading {
  align-items: center;
  justify-content: center;
  background: var(--xy-yellow);
}

.loader-wrap {
  text-align: center;
}

.loader-y {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border: 4px solid var(--xy-black);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Start */
#start {
  background: linear-gradient(180deg, var(--xy-yellow) 0%, #fff6b8 45%, var(--xy-bg) 100%);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.start-inner {
  text-align: center;
  width: 100%;
  animation: fadeUp 0.5s ease;
}

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

.logo-badge {
  font-size: 64px;
  line-height: 1;
  margin-bottom: 12px;
}

.game-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--xy-black);
  margin: 0 0 12px;
  line-height: 1.3;
}

.start-sub {
  color: #666;
  font-size: 15px;
  margin: 0 0 32px;
}

.btn-primary,
.btn-secondary {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  padding: 14px 20px;
  border: none;
  border-radius: 24px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn-primary {
  background: var(--xy-black);
  color: var(--xy-yellow);
  box-shadow: 0 4px 0 #000;
}

.btn-secondary {
  background: #fff;
  color: var(--xy-black);
  border: 2px solid var(--xy-black);
  margin-top: 12px;
}

.btn-primary:active,
.btn-secondary:active,
.option-btn:active {
  transform: scale(0.97);
}

/* Chat header - 闲鱼风格商品卡 */
#chat {
  background: #ebebeb;
}

.chat-header {
  flex-shrink: 0;
  background: #fff;
  border-bottom: 1px solid #e8e8e8;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
}

.product-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fafafa;
  border-radius: 8px;
  padding: 10px;
  border: 1px solid #eee;
}

.product-thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: var(--xy-yellow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.product-info {
  flex: 1;
  min-width: 0;
}

.product-name {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-meta {
  font-size: 11px;
  color: var(--xy-muted);
  margin: 0 0 4px;
}

.product-price {
  font-size: 13px;
  color: #e65100;
  font-weight: 700;
  margin: 0;
}

.product-tag {
  font-size: 11px;
  background: var(--xy-yellow);
  color: var(--xy-black);
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 600;
  flex-shrink: 0;
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  padding-bottom: 8px;
}

.chat-footer {
  flex-shrink: 0;
  background: #fff;
  border-top: 1px solid #e8e8e8;
  padding: 10px 12px calc(10px + var(--safe-bottom));
}

.options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-btn {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  font-size: 15px;
  color: var(--xy-text);
  line-height: 1.4;
}

.option-btn:active {
  background: #fff9d6;
  border-color: var(--xy-yellow-dark);
}

/* Messages */
.msg {
  margin-bottom: 12px;
  animation: msgIn 0.28s ease;
}

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg-system {
  text-align: center;
  padding: 4px 0;
}

.msg-system span {
  display: inline-block;
  max-width: 90%;
  font-size: 12px;
  color: var(--xy-muted);
  background: rgba(0, 0, 0, 0.06);
  padding: 4px 10px;
  border-radius: 4px;
  line-height: 1.5;
}

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.msg-user {
  flex-direction: row-reverse;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #ddd;
}

.bubble-wrap {
  max-width: 72%;
}

.bubble {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.bubble-scalper {
  background: var(--xy-scalper-bubble);
  border-top-left-radius: 4px;
}

.bubble-user {
  background: var(--xy-user-bubble);
  border-top-right-radius: 4px;
}

.cursor {
  animation: blink 0.7s step-end infinite;
  color: #999;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.msg-trade-card {
  display: flex;
  justify-content: center;
  margin: 16px 0;
}

.trade-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 2px solid var(--xy-yellow);
  border-radius: 12px;
  padding: 14px 18px;
  min-width: 240px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.trade-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #4caf50;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: bold;
}

.trade-body strong {
  display: block;
  font-size: 16px;
}

.trade-body p {
  margin: 4px 0 0;
  font-size: 12px;
  color: #888;
}

/* Ending — 卡通剧场风 */
#ending {
  background: linear-gradient(165deg, #fff9c4 0%, #ffe566 38%, #fff3b0 100%);
  overflow-y: auto;
  padding: 20px 16px calc(20px + var(--safe-bottom));
}

.ending-scene {
  position: relative;
  max-width: 360px;
  margin: 0 auto;
  animation: fadeUp 0.5s ease;
}

.ending-card {
  position: relative;
  z-index: 0;
  isolation: isolate;
  background: #fff;
  border: 4px solid var(--xy-black);
  border-radius: 24px;
  padding: 28px 20px 20px;
  margin-top: 36px;
  box-shadow: 8px 8px 0 var(--xy-black);
}

.ending-card::before {
  content: '';
  position: absolute;
  z-index: 0;
  inset: 8px;
  border: 2px dashed rgba(255, 218, 68, 0.8);
  border-radius: 18px;
  pointer-events: none;
}

.ending-stamp {
  position: absolute;
  z-index: 3;
  top: -14px;
  right: 16px;
  background: #ff6b6b;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 999px;
  border: 3px solid var(--xy-black);
  transform: rotate(8deg);
  box-shadow: 2px 2px 0 var(--xy-black);
}

.ending-badge {
  position: relative;
  z-index: 2;
  width: 72px;
  height: 72px;
  margin: -52px auto 8px;
  background: var(--xy-yellow);
  border: 4px solid var(--xy-black);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  box-shadow: 4px 4px 0 var(--xy-black);
  animation: badgePop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ending-title,
.ending-bubble,
.ending-quote-card {
  position: relative;
  z-index: 1;
}

@keyframes badgePop {
  from {
    transform: scale(0.3) rotate(-20deg);
    opacity: 0;
  }
  to {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

.ending-title {
  font-size: 24px;
  font-weight: 900;
  color: var(--xy-black);
  margin: 0 0 14px;
  text-align: center;
  line-height: 1.35;
  letter-spacing: 0.02em;
}

.ending-bubble {
  background: #fffde7;
  border: 3px solid var(--xy-black);
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 14px;
  position: relative;
}

.ending-bubble::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 28px;
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 12px solid var(--xy-black);
}

.ending-bubble::before {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 30px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 10px solid #fffde7;
  z-index: 1;
}

.ending-desc {
  font-size: 15px;
  line-height: 1.65;
  color: #333;
  margin: 0;
}

.ending-quote-card {
  background: linear-gradient(135deg, #ffda44 0%, #ffc107 100%);
  border: 3px solid var(--xy-black);
  border-radius: 14px;
  padding: 12px 14px;
  margin-top: 8px;
  box-shadow: 3px 3px 0 var(--xy-black);
}

.quote-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  background: var(--xy-black);
  color: var(--xy-yellow);
  padding: 2px 8px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.ending-quote {
  font-size: 15px;
  font-weight: 700;
  color: var(--xy-black);
  margin: 0;
  line-height: 1.5;
}

/* 结局主题色 */
.ending-card.theme-god {
  border-color: #7b1fa2;
  box-shadow: 8px 8px 0 #7b1fa2;
}
.ending-card.theme-god .ending-badge {
  background: #e1bee7;
}

.ending-card.theme-win {
  border-color: #2e7d32;
  box-shadow: 8px 8px 0 #2e7d32;
}
.ending-card.theme-win .ending-badge {
  background: #c8e6c9;
}

.ending-card.theme-lose {
  border-color: #c62828;
  box-shadow: 8px 8px 0 #c62828;
}
.ending-card.theme-lose .ending-badge {
  background: #ffcdd2;
}

.ending-card.theme-neutral {
  border-color: var(--xy-black);
}

.share-hint {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #5d4037;
  margin: 20px 0 16px;
}

.ending-actions {
  max-width: 300px;
  margin: 0 auto;
}

.btn-cartoon {
  border-radius: 20px !important;
  border: 3px solid var(--xy-black) !important;
  box-shadow: 4px 4px 0 var(--xy-black) !important;
  font-weight: 800 !important;
}

.btn-cartoon:active {
  box-shadow: 1px 1px 0 var(--xy-black) !important;
  transform: translate(3px, 3px) scale(0.98) !important;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 999;
  max-width: 85%;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
