/* ==================== CSS Variables ==================== */
:root {
  --red: #9A1010;
  --red-dark: #7a0c0c;
  --gold: #D4AF37;
  --gold-light: #ffe7b3;
  --paper: #F3E9D2;
  --ink: #2c2c2c;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.22);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
  --transition-fast: 0.12s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --blur-glass: blur(6px);
}

/* ==================== Reset & Base ==================== */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  background: radial-gradient(circle, var(--red) 0%, var(--red-dark) 100%);
  font-family: 'Ma Shan Zheng', cursive, system-ui;
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--paper);
  overflow-x: hidden;
  padding: 18px 14px;
  position: relative;
}

/* ==================== Banner ==================== */
.banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border: 1px solid rgba(212, 175, 55, 0.55);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  box-shadow: var(--shadow-md);
  text-align: center;
  max-width: min(92vw, 560px);
  line-height: 1.2;
  z-index: 10;
  animation: fadeInDown 0.6s ease;
}

.banner__title {
  color: var(--gold-light);
  font-weight: 500;
  display: block;
}

.banner__subtitle {
  display: block;
  opacity: 0.9;
  margin-top: 4px;
  font-size: 0.9em;
}

/* ==================== Content Container ==================== */
.content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 60px;
}

/* ==================== Mode Switch (Tabs) ==================== */
.mode-switch {
  display: flex;
  gap: 10px;
  margin: 12px 0 24px;
}

.chip {
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid rgba(212, 175, 55, 0.55);
  background: rgba(0, 0, 0, 0.18);
  color: var(--paper);
  cursor: pointer;
  user-select: none;
  transition: all var(--transition-fast);
  font-family: inherit;
  font-size: 1rem;
}

.chip:hover {
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(212, 175, 55, 0.75);
}

.chip:active {
  transform: scale(0.98);
}

.chip--active {
  background: rgba(212, 175, 55, 0.25);
  border-color: rgba(212, 175, 55, 0.9);
  box-shadow: var(--shadow-sm);
}

/* ==================== Card Container ==================== */
.card-container {
  perspective: 1200px;
  width: min(300px, 86vw);
  height: min(500px, 68vh);
  margin-bottom: 20px;
  cursor: pointer;
  transform-origin: center bottom;
  transition: transform var(--transition-normal);
}

.card-container:hover {
  transform: scale(1.02);
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--transition-slow);
}

.card--flipped {
  transform: rotateY(180deg);
}

.card--shaking {
  animation: shake 0.3s ease-in-out infinite;
}

/* ==================== Card Faces ==================== */
.card__face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  background-color: var(--paper);
  color: var(--ink);
  border: 4px solid var(--gold);
  overflow: hidden;
  padding: 20px;
}

.card__face--front {
  z-index: 2;
}

.card__face--back {
  transform: rotateY(180deg);
  position: relative;
}

/* 正面元素 */
.fu {
  font-size: clamp(5.8rem, 10vw, 8rem);
  color: var(--red);
  border: 4px solid var(--red);
  border-radius: 50%;
  width: 160px;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-10deg);
  position: relative;
  transition: transform var(--transition-normal);
}

.card-container:hover .fu {
  transform: rotate(0deg);
}

.couplet {
  position: absolute;
  top: 20px;
  writing-mode: vertical-rl;
  text-orientation: upright;
  color: rgba(154, 16, 16, 0.7);
  font-size: 18px;
  letter-spacing: 5px;
}

.couplet--left {
  left: 20px;
}

.couplet--right {
  right: 20px;
  color: rgba(154, 16, 16, 0.65);
}

.card__hint {
  margin-top: 16px;
  color: #666;
  font-size: 1.05rem;
}

/* 背面元素 */
.card__face--back::after {
  content: "马年大吉";
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 12px;
  color: var(--red);
  opacity: 0.5;
  writing-mode: vertical-rl;
}

.card__level {
  font-size: 2.4rem;
  color: var(--red);
  margin-bottom: 20px;
  border-bottom: 2px solid var(--gold);
  padding-bottom: 8px;
  width: 80%;
  text-align: center;
}

.card__blessing {
  font-size: 1.7rem;
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 6px;
  line-height: 2.2;
  white-space: pre-line;
  padding: 0 12px;
  max-height: 280px;
  overflow-y: auto;
}

.card__share-btn {
  position: absolute;
  bottom: 16px;
  right: 16px;
  background: rgba(212, 175, 55, 0.15);
  border: 1px solid rgba(212, 175, 55, 0.5);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--red);
  transition: all var(--transition-fast);
}

.card__share-btn:hover {
  background: rgba(212, 175, 55, 0.3);
  transform: scale(1.1);
}

/* ==================== Buttons ==================== */
.btn {
  background: linear-gradient(to bottom, #e6c880, #c5a059);
  border: none;
  padding: 16px 48px;
  border-radius: 50px;
  font-size: 1.4rem;
  color: #5a1216;
  font-family: inherit;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: transform var(--transition-fast);
  position: relative;
  min-width: 160px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.35);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  filter: grayscale(0.8);
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.btn__spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(90, 18, 22, 0.3);
  border-top-color: #5a1216;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.btn:disabled .btn__spinner {
  display: block;
}

.subbtn {
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid rgba(212, 175, 55, 0.55);
  background: rgba(0, 0, 0, 0.18);
  color: var(--paper);
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
}

.subbtn:hover {
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(212, 175, 55, 0.75);
}

.subbtn:active {
  transform: scale(0.98);
}

.subbtn svg {
  flex-shrink: 0;
}

/* ==================== History Section ==================== */
.history {
  width: 100%;
  max-width: 320px;
  margin-top: 20px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 12px;
  padding: 12px;
  animation: fadeIn 0.4s ease;
}

.history__toggle {
  cursor: pointer;
  color: var(--gold-light);
  font-size: 1rem;
  user-select: none;
  padding: 4px;
}

.history__toggle:hover {
  color: var(--gold);
}

.history__list {
  margin-top: 12px;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history__item {
  background: rgba(243, 233, 210, 0.1);
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.9rem;
  color: var(--paper);
  transition: all var(--transition-fast);
}

.history__item:hover {
  background: rgba(243, 233, 210, 0.2);
  border-color: rgba(212, 175, 55, 0.5);
}

.history__item-level {
  color: var(--gold);
  font-weight: bold;
  margin-bottom: 4px;
}

.history__item-text {
  font-size: 0.85rem;
  opacity: 0.9;
}

.history__item-time {
  font-size: 0.75rem;
  opacity: 0.6;
  margin-top: 4px;
}

/* ==================== Greet Panel ==================== */
.greet-panel {
  width: min(340px, 92vw);
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(212, 175, 55, 0.55);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow-md);
  display: flex;
  gap: 14px;
  flex-direction: column;
  animation: fadeIn 0.4s ease;
}

.greet-panel__input-row {
  display: flex;
  gap: 10px;
}

.input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(212, 175, 55, 0.35);
  background: rgba(243, 233, 210, 0.92);
  font-family: inherit;
  font-size: 1.05rem;
  outline: none;
  color: var(--ink);
  transition: border var(--transition-fast);
}

.input::placeholder {
  color: rgba(44, 44, 44, 0.5);
}

.input:focus {
  border-color: rgba(212, 175, 55, 0.7);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1);
}

.quote {
  background: rgba(243, 233, 210, 0.92);
  color: var(--ink);
  border-radius: 12px;
  border: 1px solid rgba(212, 175, 55, 0.35);
  padding: 14px;
  font-size: 1.1rem;
  line-height: 1.6;
  min-height: 80px;
  white-space: pre-line;
}

.greet-panel__actions {
  display: flex;
  gap: 10px;
}

/* ==================== Toast ==================== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(0, 0, 0, 0.9);
  color: var(--paper);
  padding: 12px 24px;
  border-radius: 50px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition-normal);
  z-index: 1000;
  max-width: 90vw;
  text-align: center;
}

.toast--show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ==================== Effects Canvas ==================== */
#fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

/* ==================== Animations ==================== */
@keyframes shake {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(3deg); }
  75% { transform: rotate(-3deg); }
}

@keyframes spin {
  to { transform: translateY(-50%) rotate(360deg); }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ==================== Responsive ==================== */
@media (max-width: 480px) {
  .banner {
    top: 10px;
    padding: 8px 12px;
    font-size: 0.9rem;
  }

  .content {
    margin-top: 50px;
  }

  .card-container {
    height: min(450px, 60vh);
  }

  .btn {
    padding: 14px 36px;
    font-size: 1.2rem;
  }

  .greet-panel__input-row {
    flex-direction: column;
  }
}

/* ==================== Accessibility ==================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ==================== Scrollbar Styling ==================== */
.history__list::-webkit-scrollbar,
.card__blessing::-webkit-scrollbar {
  width: 6px;
}

.history__list::-webkit-scrollbar-track,
.card__blessing::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

.history__list::-webkit-scrollbar-thumb,
.card__blessing::-webkit-scrollbar-thumb {
  background: rgba(212, 175, 55, 0.5);
  border-radius: 3px;
}

.history__list::-webkit-scrollbar-thumb:hover,
.card__blessing::-webkit-scrollbar-thumb:hover {
  background: rgba(212, 175, 55, 0.7);
}
