/* ============================================
   Design System & Variables
   ============================================ */
:root {
  /* Colors - Apple Inspired */
  --bg-page: #F5F5F7;
  --bg-card: #FFFFFF;
  --bg-glass: rgba(255, 255, 255, 0.72);
  
  --text-primary: #1D1D1F;
  --text-secondary: #86868B;
  --text-tertiary: #BFBFBF;

  --accent-blue: #0071E3;
  --accent-purple: #BF5AF2;
  --accent-pink: #FF375F;
  --accent-orange: #FF9F0A;
  --accent-green: #34C759;
  
  /* Brand Colors */
  --brand-gradient: linear-gradient(135deg, #1D1D1F 0%, #434343 100%);
  --vip-gold: linear-gradient(135deg, #FFD700 0%, #FDB931 100%);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 0 20px rgba(255, 215, 0, 0.3);

  /* Radius */
  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 32px;

  /* Animation */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Chat Variables (Keeping consistent) */
  --chat-bg: #F2F2F7;
  --chat-surface: #FFFFFF;
  --chat-primary: #0071E3;
  --chat-primary-light: #E1F0FF;
  --chat-bubble-incoming: #FFFFFF;
  --chat-bubble-outgoing: #0071E3;
  --chat-text: #1D1D1F;
  --chat-text-secondary: #86868B;
  --chat-border: rgba(0, 0, 0, 0.1);
  --chat-shadow-soft: 0 2px 12px rgba(0, 0, 0, 0.05);
}

/* ============================================
   Reset & Base Styles
   ============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ============================================
   Loading Screen
   ============================================ */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-page);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s var(--ease-smooth), visibility 0.5s;
}

.loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
}

.loading-content {
  text-align: center;
  width: 100%;
  max-width: 300px;
}

.loading-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 24px;
  color: var(--text-primary);
  animation: logo-pulse 2s infinite ease-in-out;
}

@keyframes logo-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.9); opacity: 0.8; }
}

.loading-text {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.progress-container {
  height: 4px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--text-primary);
  transition: width 0.1s linear;
}

/* ============================================
   App Container & Header
   ============================================ */
.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  /* background: rgba(245, 245, 247, 0.8); */ /* Optional: Sticky header bg */
  /* backdrop-filter: blur(20px); */
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 24px;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-vip {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  background: var(--vip-gold);
  color: #5a3e36;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.5);
  transition: all 0.3s var(--ease-smooth);
}

.icon-btn:hover {
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  transform: rotate(90deg);
}

/* ============================================
   Hero Section
   ============================================ */
.hero-section {
  text-align: center;
  padding: 60px 0 80px;
  animation: fade-up 0.8s var(--ease-spring) backwards;
}

.hero-title {
  font-size: clamp(40px, 8vw, 64px);
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 24px;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -1px;
}

.hero-subtitle {
  font-size: clamp(16px, 4vw, 20px);
  color: var(--text-secondary);
  font-weight: 500;
  max-width: 600px;
  margin: 0 auto;
}

/* ============================================
   Bento Grid
   ============================================ */
.bento-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
  width: 100%;
  animation: fade-up 0.8s var(--ease-spring) 0.2s backwards;
}

/* Desktop Specific Grid Layout */
@media (min-width: 900px) {
  .bento-grid {
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 240px;
  }
  
  .card-ai {
    grid-column: span 1;
    grid-row: span 2;
  }
  
  .card-love {
    grid-column: span 2;
  }
}

.bento-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 32px;
  position: relative;
  overflow: hidden;
  transition: all 0.4s var(--ease-spring);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.02);
}

.bento-card:hover {
  transform: translateY(-8px) scale(1.02);
  box-shadow: var(--shadow-lg);
}

/* Card Specific Styles */
.card-ai {
  background: linear-gradient(135deg, #1D1D1F 0%, #2C2C2E 100%);
  color: white;
}

.card-ai .card-icon-bg {
  width: 64px;
  height: 64px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: auto;
}

.card-ai h3 {
  font-size: 24px;
  margin-bottom: 8px;
}

.card-ai p {
  color: rgba(255, 255, 255, 0.6);
}

.card-bg-decoration {
  position: absolute;
  font-size: 120px;
  opacity: 0.05;
  right: -20px;
  bottom: -20px;
  transform: rotate(-15deg);
  pointer-events: none;
  transition: transform 0.4s ease;
}

.bento-card:hover .card-bg-decoration {
  transform: rotate(0deg) scale(1.1);
  opacity: 0.1;
}

.emoji-icon {
  font-size: 48px;
  margin-bottom: 24px;
}

.card-content h3 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.card-content p {
  font-size: 14px;
  color: var(--text-secondary);
}

.card-arrow {
  position: absolute;
  bottom: 32px;
  right: 32px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  opacity: 0;
  transform: translateX(-10px);
}

.bento-card:hover .card-arrow {
  opacity: 1;
  transform: translateX(0);
}

.card-ai .card-arrow {
  background: rgba(255,255,255,0.2);
  color: white;
}

/* Colorful Cards */
.card-self {
  background: linear-gradient(135deg, #FFF5F5 0%, #FFF 100%);
}
.card-self h3 { color: #FF375F; }

.card-friend {
  background: linear-gradient(135deg, #F0F8FF 0%, #FFF 100%);
}
.card-friend h3 { color: #0071E3; }

.card-blessings {
  background: linear-gradient(135deg, #FFF8E1 0%, #FFF 100%);
}
.card-blessings h3 { color: #FF9F0A; }

.card-newyear {
  background: linear-gradient(135deg, #FFF0F0 0%, #FFF 100%);
}
.card-newyear h3 { color: #D32F2F; }

.card-love {
  background: linear-gradient(135deg, #FFEBF0 0%, #FFF 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-content-row {
  display: flex;
  align-items: center;
  gap: 24px;
  width: 100%;
}

.card-love .emoji-icon {
  margin-bottom: 0;
  font-size: 56px;
}

.card-love h3 {
  color: #E91E63;
  font-size: 24px;
}

/* ============================================
   Footer
   ============================================ */
.app-footer {
  margin-top: auto;
  padding-top: 60px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

.app-footer a {
  color: var(--text-primary);
  font-weight: 600;
  border-bottom: 1px dashed var(--text-secondary);
}

.version {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
  font-family: monospace;
}

/* ============================================
   Modal (Settings/More)
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s var(--ease-smooth);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95) translateY(10px);
  transition: all 0.4s var(--ease-spring);
  overflow: hidden;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close:hover {
  background: rgba(0,0,0,0.1);
  transform: rotate(90deg);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.modal-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.action-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--bg-page);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-item:hover {
  background: #EAEAEA;
  transform: translateX(4px);
}

.action-item.expanded {
  background: var(--bg-page); /* Keep styling when expanded */
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  margin-bottom: 0;
}

.action-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.action-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.action-title {
  font-weight: 600;
  font-size: 15px;
}

.action-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

.action-arrow {
  color: var(--text-tertiary);
  font-size: 20px;
  font-weight: 300;
}

/* Expandable Content */
.expandable-content {
  display: none;
  background: var(--bg-page);
  margin-top: -8px; /* overlap with item above */
  margin-bottom: 8px;
  padding: 24px;
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
  animation: slide-down 0.3s var(--ease-smooth);
}

.expandable-content.active {
  display: block;
}

@keyframes slide-down {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.qr-wrapper {
  text-align: center;
}

.qr-wrapper img {
  width: 180px;
  height: 180px;
  border-radius: 12px;
  margin-bottom: 12px;
}

.qr-wrapper p {
  font-size: 14px;
  color: var(--text-secondary);
}

.info-box {
  background: white;
  padding: 16px;
  border-radius: 12px;
  text-align: center;
}

.copy-btn {
  margin-top: 12px;
  padding: 6px 16px;
  background: var(--accent-pink);
  color: white;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.log-item {
  border-left: 2px solid var(--accent-blue);
  padding-left: 12px;
}

.log-ver {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
}

.log-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ============================================
   Animations
   ============================================ */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   Chat Window (Adapting old CSS to new vars)
   ============================================ */
/* Chat Overlay */
.chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.4s var(--ease-smooth), background 0.4s var(--ease-smooth), backdrop-filter 0.4s var(--ease-smooth), visibility 0s linear 0.4s;
}

.chat-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: opacity 0.4s var(--ease-smooth), background 0.4s var(--ease-smooth), backdrop-filter 0.4s var(--ease-smooth), visibility 0s linear 0s;
}

.chat-overlay.closing {
  opacity: 0;
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
}

/* Chat Window Main */
.chat-window {
  width: 100%;
  max-width: 420px;
  height: 85vh;
  max-height: 700px;
  background: var(--chat-bg);
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.25), 0 10px 30px rgba(0, 0, 0, 0.12);
  transform: scale(0.75) translateY(80px);
  opacity: 0;
  transition: transform 0.5s var(--ease-spring), opacity 0.4s var(--ease-smooth);
}

.chat-overlay.active .chat-window {
  transform: scale(1) translateY(0);
  opacity: 1;
  animation: windowBounceIn 0.6s var(--ease-spring);
}

@keyframes windowBounceIn {
  0% { transform: scale(0.6) translateY(100px); opacity: 0; }
  50% { transform: scale(1.03) translateY(-10px); opacity: 1; }
  70% { transform: scale(0.97) translateY(5px); }
  100% { transform: scale(1) translateY(0); }
}

.chat-overlay.closing .chat-window {
  transform: scale(0.8) translateY(60px);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.4, 0, 1, 1), opacity 0.3s ease-out;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--chat-border);
  position: relative;
  z-index: 10;
}

.chat-close-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px 8px 8px;
  border-radius: 8px;
  color: var(--chat-primary);
  transition: background 0.2s;
}

.chat-close-btn:hover {
  background: rgba(0,0,0,0.05);
}

.chat-contact {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: center; /* Center title in header like iOS */
  padding-right: 40px; /* Offset for close btn to center perfectly */
}

.chat-avatar-wrapper {
  position: relative;
  flex-shrink: 0;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
  box-shadow: var(--chat-shadow-soft);
}

.chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: #34c759;
  border-radius: 50%;
  border: 2px solid white;
}

.chat-contact-info {
  text-align: center;
}

.chat-contact-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--chat-text);
  margin: 0;
}

.chat-status {
  font-size: 11px;
  color: var(--chat-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.status-icon {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8e8e93;
}

.status-icon.ai { background: #605BEC; }
.status-icon.human-online { background: #34c759; }

/* Chat Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  background: var(--chat-bg);
}

.chat-date-divider {
  display: flex;
  justify-content: center;
  padding: 12px 0;
}

.chat-date-divider span {
  font-size: 11px;
  font-weight: 600;
  color: var(--chat-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.message-group {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: message-fade-in 0.35s var(--ease-spring) backwards;
}

@keyframes message-fade-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.message-group.incoming { align-self: flex-start; }
.message-group.outgoing { align-self: flex-end; flex-direction: row-reverse; }

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  align-self: flex-end;
  background: #eee;
}

.message-avatar img { width: 100%; height: 100%; object-fit: cover; }

.message-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message-group.outgoing .message-content { align-items: flex-end; }

.message-bubble {
  padding: 8px 14px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.4;
  position: relative;
  max-width: 100%;
}

.message-bubble p { margin: 0; }

.message-group.incoming .message-bubble {
  background: var(--chat-bubble-incoming);
  color: var(--chat-text);
  border-bottom-left-radius: 4px;
}

.message-group.outgoing .message-bubble {
  background: var(--chat-bubble-outgoing);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-time {
  font-size: 10px;
  color: var(--chat-text-secondary);
  margin-top: 4px;
  opacity: 0.8;
}

/* Chat Input Area */
.chat-input-area {
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--chat-border);
}

.chat-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--chat-bg);
  border-radius: 24px;
  padding: 6px;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.chat-input-wrapper:focus-within {
  border-color: rgba(0,0,0,0.1);
  background: white;
}

.chat-emoji-btn, .chat-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-text-secondary);
  transition: all 0.2s;
}

.chat-emoji-btn:hover { color: var(--text-primary); background: rgba(0,0,0,0.05); }

.chat-send-btn {
  background: var(--chat-primary);
  color: white;
  opacity: 0.5;
  transform: scale(0.9);
}

.chat-send-btn.active {
  opacity: 1;
  transform: scale(1);
}

.chat-input {
  flex: 1;
  height: 36px;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--chat-text);
  outline: none;
  padding: 0 4px;
}

.chat-hint {
  text-align: center;
  font-size: 11px;
  color: var(--chat-text-secondary);
  margin: 8px 0 0;
}

/* Mobile Responsive */
@media (max-width: 600px) {
  .app-container {
    padding: 0 16px 30px;
  }

  .hero-title {
    font-size: 42px;
  }

  .bento-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .bento-card {
    min-height: 180px;
  }

  .chat-window {
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    width: 100%;
    max-width: 100%;
  }

  .chat-overlay.active .chat-window {
    transform: translateY(0);
    animation: mobileSlideIn 0.4s var(--ease-spring);
  }

  @keyframes mobileSlideIn {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
}
