/**
 * OneRealm International - Home Page Styles
 * Telegram Mini App Version
 */

/* ========== CSS Variables ========== */
:root {
  /* Telegram theme (defaults, overridden by Telegram WebApp) */
  --tg-bg-color: #1a1a2e;
  --tg-text-color: #ffffff;
  --tg-hint-color: rgba(255, 255, 255, 0.6);
  --tg-link-color: #667eea;
  --tg-button-color: #667eea;
  --tg-button-text-color: #ffffff;
  --tg-secondary-bg-color: rgba(255, 255, 255, 0.1);

  /* App colors */
  --primary-color: #667eea;
  --secondary-color: #764ba2;
  --background-color: #0f0f1a;
  --surface-color: rgba(255, 255, 255, 0.1);
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-hint: rgba(255, 255, 255, 0.5);

  /* Spacing */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ========== Reset & Base ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--background-color);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ========== Gradient Background ========== */
.gradient-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  overflow: hidden;
  contain: strict;
}

.gradient-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: 300% 300%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: translateZ(0);
}

.gradient-main {
  background: linear-gradient(135deg, #1a237e, #00695c, #004d40, #1a237e);
  animation: gradientShift 20s ease-in-out infinite;
  opacity: 1;
}

.gradient-overlay {
  background: linear-gradient(225deg, rgba(102, 126, 234, 0.4), rgba(118, 75, 162, 0.4), rgba(0, 0, 0, 0.3));
  animation: gradientShift 25s ease-in-out infinite reverse;
  opacity: 0.6;
}

@keyframes gradientShift {
  0%, 100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

.gradient-main,
.gradient-overlay {
  transition: background 2s ease-in-out;
}

/* ========== App Container ========== */
.app-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: calc(20px + var(--safe-area-top)) 0 calc(20px + var(--safe-area-bottom));
}

/* ========== Header ========== */
.header {
  text-align: center;
  padding: 10px 20px 20px;
}

.brand-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  letter-spacing: 1px;
}

.brand-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 400;
}

/* ========== Category Selector ========== */
.category-selector {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 0 20px;
  margin-bottom: 24px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}

.category-selector::-webkit-scrollbar {
  display: none;
}

.category-item {
  flex-shrink: 0;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 25px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
  border: 2px solid transparent;
}

.category-item:hover {
  background: rgba(255, 255, 255, 0.15);
}

.category-item:active {
  transform: scale(0.98);
}

.category-item.selected {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
  font-weight: 600;
  border-color: rgba(255, 255, 255, 0.4);
}

/* ========== Scene Carousel ========== */
.scene-carousel-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 0 16px;
}

.scene-carousel {
  display: flex;
  gap: 16px;
  padding: 0 20px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  align-items: center;
}

/* 单个场景时居中 */
.scene-carousel.single-scene {
  justify-content: center;
}

.scene-carousel::-webkit-scrollbar {
  display: none;
}

/* ========== Scene Card ========== */
.scene-card {
  flex-shrink: 0;
  width: calc(100vw - 80px);
  max-width: 320px;
  min-height: 280px;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.3), rgba(118, 75, 162, 0.3));
  padding: 24px;
  scroll-snap-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.scene-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: inherit;
  border-radius: inherit;
  z-index: -1;
}

.scene-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.scene-card:active {
  transform: scale(0.98);
}

.scene-card.active {
  transform: scale(1.02);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.scene-card-icon {
  font-size: 48px;
  margin-bottom: 16px;
  text-align: center;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.scene-card-name {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.scene-card-description {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.scene-card-duration {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-primary);
  margin-top: 16px;
  width: fit-content;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.scene-card-duration::before {
  content: '\23F1';
  font-size: 14px;
}

/* ========== Carousel Indicators ========== */
.carousel-indicators {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 16px 0;
}

.indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.3);
  transition: all 0.3s ease;
  cursor: pointer;
}

.indicator-dot.active {
  width: 24px;
  background: var(--text-primary);
}

/* ========== Start Button ========== */
.start-button-container {
  padding: 0 20px 10px;
}

.start-button {
  width: 100%;
  padding: 18px 32px;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  border: none;
  border-radius: 30px;
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
  position: relative;
  overflow: hidden;
}

.start-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.start-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
}

.start-button:hover::before {
  left: 100%;
}

.start-button:active {
  transform: translateY(0) scale(0.98);
}

.start-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Pulse animation for button */
@keyframes buttonPulse {
  0%, 100% {
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
  }
  50% {
    box-shadow: 0 4px 30px rgba(102, 126, 234, 0.6);
  }
}

.start-button.pulse {
  animation: buttonPulse 2s ease-in-out infinite;
}

/* ========== Loading Overlay ========== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--background-color);
}

.loading-overlay.show {
  display: flex;
}

.loading-icon {
  width: 80px;
  height: 80px;
  object-fit: contain;
  margin-bottom: 24px;
  border-radius: 16px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

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

.loading-text {
  font-size: 16px;
  color: var(--text-secondary);
}

/* ========== Empty State ========== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 16px;
  color: var(--text-secondary);
}

/* ========== Error State ========== */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.error-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.error-state-text {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.retry-button {
  padding: 12px 24px;
  background: var(--surface-color);
  border: none;
  border-radius: 25px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.retry-button:hover {
  background: rgba(255, 255, 255, 0.15);
}

.retry-button:active {
  transform: scale(0.98);
}

/* ========== Mobile Optimization ========== */
@media (max-width: 480px) {
  .brand-title {
    font-size: 24px;
  }

  .brand-subtitle {
    font-size: 13px;
  }

  .scene-card {
    min-height: 260px;
    padding: 20px;
  }

  .scene-card-icon {
    font-size: 40px;
  }

  .scene-card-name {
    font-size: 20px;
  }

  .scene-card-description {
    font-size: 13px;
  }

  .start-button {
    padding: 16px 28px;
    font-size: 16px;
  }
}

/* Small screens */
@media (max-height: 600px) {
  .header {
    padding: 5px 20px 15px;
  }

  .scene-card {
    min-height: 220px;
    padding: 16px;
  }

  .category-selector {
    margin-bottom: 16px;
  }

  .carousel-indicators {
    padding: 10px 0;
  }
}

/* ========== Reduced Motion ========== */
@media (prefers-reduced-motion: reduce) {
  .gradient-main,
  .gradient-overlay,
  .start-button.pulse {
    animation: none;
  }

  .scene-card,
  .category-item,
  .start-button,
  .indicator-dot {
    transition: none;
  }
}
