/* React Native 스타일과 완전 동일하게 구현 */
:root {
  --primary-dark: #3E3D7B;
  --primary-mid: #2A1F63;
  --primary-light: #6B46C1;
  --accent-yellow: #FACC15;
  --accent-orange: #FFA500;
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --border-light: #E5E7EB;
  --border-purple: #E8E0FF;
  --bg-purple-light: #FAF8FF;
  --bg-glass: rgba(255, 255, 255, 0.6);
  --border-glass: rgba(232, 232, 232, 0.6);
  --discount-red: #EA0004;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #FFFFFF;
  color: var(--text-primary);
  min-height: 100vh;
  margin: 0;
  padding: 0;
  /* Safe Area 처리 */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Wrapper for desktop gradient background */
.wrapper {
  min-height: 100vh;
  background: #FFFFFF;
  position: relative;
}

/* Container - max-width 600px */
.container {
  max-width: 600px;
  margin: 0 auto;
  background: #FFFFFF;
  min-height: 100vh;
  position: relative;
  padding-bottom: calc(140px + env(safe-area-inset-bottom)); /* 버튼 공간 + Safe Area */
}

/* Desktop styles */
@media (min-width: 601px) {
  .wrapper {
    background: linear-gradient(180deg, #1A1440 0%, #000000 100%);
    padding: 0;
    position: relative;
    overflow: hidden;
  }

  /* Glassmorphism overlay for smooth transition */
  .wrapper::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 800px;
    height: 100%;
    background: radial-gradient(
      ellipse at center,
      rgba(255, 255, 255, 0.15) 0%,
      rgba(255, 255, 255, 0.08) 30%,
      rgba(255, 255, 255, 0.03) 50%,
      transparent 70%
    );
    pointer-events: none;
    z-index: 1;
  }

  .container {
    position: relative;
    z-index: 2;
    /* Glassmorphism effect */
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    /* Soft feathered edges using multiple shadows */
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.5),
      0 0 60px rgba(107, 70, 193, 0.1),
      0 0 100px rgba(107, 70, 193, 0.08),
      0 20px 60px -20px rgba(0, 0, 0, 0.15);
    /* Mask for soft edges */
    mask-image: linear-gradient(
      to right,
      transparent 0%,
      black 2%,
      black 98%,
      transparent 100%
    );
    -webkit-mask-image: linear-gradient(
      to right,
      transparent 0%,
      black 2%,
      black 98%,
      transparent 100%
    );
  }

  /* Additional gradient overlay on sides for smoother blend */
  .container::before,
  .container::after {
    content: '';
    position: absolute;
    top: 0;
    width: 100px;
    height: 100%;
    pointer-events: none;
    z-index: -1;
  }

  .container::before {
    left: -100px;
    background: linear-gradient(
      to right,
      transparent 0%,
      rgba(255, 255, 255, 0.4) 50%,
      rgba(255, 255, 255, 0.8) 100%
    );
  }

  .container::after {
    right: -100px;
    background: linear-gradient(
      to left,
      transparent 0%,
      rgba(255, 255, 255, 0.4) 50%,
      rgba(255, 255, 255, 0.8) 100%
    );
  }
}

/* Wallpaper Section - Safe Area 포함한 높이 */
.wallpaper-section {
  position: relative;
  width: 100%;
  height: calc(589px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  overflow: hidden;
  margin-top: calc(-1 * env(safe-area-inset-top)); /* Safe area 영역까지 확장 */
}

.wallpaper-image {
  position: absolute;
  width: 100%;
  height: calc(589px + env(safe-area-inset-top));
  top: 0;
  left: 0;
  object-fit: cover;
  opacity: 1; /* 기본적으로 보이도록 설정 */
}

.wallpaper-gradient {
  position: absolute;
  width: 100%;
  height: calc(589px + env(safe-area-inset-top));
  top: 0;
  left: 0;
  background: linear-gradient(
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.1) 17.79%,
    rgba(255, 255, 255, 0) 32.69%
  );
}

.wallpaper-content {
  position: absolute;
  width: 100%;
  top: 0;
  left: 0;
  padding: 0;
}

.title-container {
  margin-top: 100px;
  text-align: center;
}

.item-title {
  font-size: 30px;
  font-weight: 800;
  line-height: 36px;
  color: #000000;
  margin-bottom: 8px;
}

.item-subtitle {
  font-size: 15px;
  font-weight: 400;
  line-height: 20px;
  color: #000000;
}

/* 가격 배지 - 377px top 위치 */
.price-badge-container {
  position: absolute;
  width: 100%;
  top: 377px;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.price-badge {
  width: 294px;
  height: 40px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  gap: 4px;
  text-align: center;
}

.free-text,
.price-text {
  font-size: 13px;
  font-weight: 400;
  line-height: 20px;
  color: #000000;
}

.star-emoji {
  font-size: 13px;
}

.original-price {
  font-size: 13px;
  font-weight: 400;
  line-height: 20px;
  color: #888888;
  text-decoration: line-through;
}

.final-price {
  font-size: 13px;
  font-weight: 400;
  line-height: 20px;
  color: #000000;
}

.discount-percent {
  font-size: 13px;
  font-weight: 600;
  line-height: 20px;
  color: var(--discount-red);
}

.discount-time {
  font-size: 13px;
  font-weight: 400;
  line-height: 20px;
  color: #000000;
}

/* 통계 컨테이너 - 449px top 위치 */
.stats-container {
  position: absolute;
  top: 449px;
  left: 50%;
  transform: translateX(-50%);
  width: 345px;
  height: 43px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-item {
  flex: 1;
  text-align: center;
  max-width: 115px;
}

.stat-label {
  font-size: 12px;
  font-weight: 400;
  line-height: 18px;
  color: rgba(0, 0, 0, 0.8);
}

.stat-value {
  font-size: 15px;
  font-weight: 500;
  line-height: 22.5px;
  color: #000000;
  margin-top: 2px;
}

.stat-divider {
  width: 1px;
  height: 18px;
  background: #A5A5A5;
}

/* 콘텐츠 섹션 */
.content-section {
  padding: 0 24px;
  background: white;
}

.content-section.with-wallpaper {
  margin-top: -82px;
  position: relative;
  z-index: 1;
}

/* 본문 스타일 (WebView 내부 스타일과 동일) */
.astro-preview {
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-primary);
}

.astro-preview p {
  margin: 2px 0 4px 0;
}

.astro-preview p:empty {
  min-height: 1.5em;
  margin: 0.75em 0;
}

.astro-preview h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 1.25rem 0 0.75rem;
}

.astro-preview h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 1.1rem 0 0.6rem;
}

.astro-preview h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 1rem 0 0.5rem;
}

.astro-preview ul, .astro-preview ol {
  padding-left: 1.5rem;
  margin: 0.5rem 0;
}

.astro-preview li {
  margin: 0.15rem 0;
}

.astro-preview blockquote {
  border-left: 3px solid #D1D5DB;
  padding: 8px 14px;
  margin: 12px 0;
}

.astro-preview hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 24px 0;
}

.astro-preview img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* 리뷰 섹션 */
.review-section {
  padding: 48px 24px 24px;
}

.review-summary {
  margin-bottom: 16px;
  position: relative;
}

.review-top-reaction {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.review-total {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 56px;
}

/* 리뷰 차트 */
.review-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 140px;
  margin-top: 16px;
  margin-bottom: 24px;
  gap: 8px;
  padding: 0 8px;
}

.chart-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

.chart-bar {
  width: 14px;
  background: var(--border-purple);
  border-radius: 6px;
  margin-bottom: 8px;
}

.chart-bar-top {
  background: var(--primary-light);
}

.chart-emoji {
  width: 35px;
  height: 35px;
  object-fit: contain;
  display: block;
}

.chart-emoji-fallback {
  width: 35px;
  height: 35px;
  font-size: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.chart-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  text-align: center;
}

.chart-count {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
  text-align: center;
}

/* 리뷰 리스트 */
.review-list {
  margin-top: 16px;
}

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 0;
}

.review-list-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.review-see-all {
  font-size: 13px;
  font-weight: 500;
  color: var(--primary-light);
  text-decoration: none;
}

/* 리뷰 카드 - 캐러셀처럼 보이게 */
.review-cards {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  margin: 0 -24px;
  padding: 0 24px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.review-cards::-webkit-scrollbar {
  display: none;
}

.review-card {
  flex: 0 0 calc(100vw - 24px - 40px);
  max-width: 335px;
  min-height: 140px;
  background: var(--bg-purple-light);
  border: 1px solid var(--border-purple);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.review-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.review-reaction {
  display: flex;
  align-items: center;
  gap: 8px;
}

.review-reaction-emoji {
  width: 35px;
  height: 35px;
  object-fit: contain;
}

.review-reaction-emoji-fallback {
  width: 35px;
  height: 35px;
  font-size: 35px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}


.review-reaction-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.review-date {
  font-size: 11px;
  color: var(--text-tertiary);
}

.review-content {
  font-size: 13px;
  line-height: 19px;
  color: var(--text-primary);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.review-author {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  margin-top: auto;
}

/* 구매 버튼 - 뷰포트 하단 고정 */
.purchase-button-container {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  width: 100%;
  max-width: 600px;
  padding: 0 24px;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
}

/* Desktop에서도 뷰포트 하단 고정 유지 */
@media (min-width: 601px) {
  .purchase-button-container {
    position: fixed !important;
    bottom: 32px !important;
    z-index: 1000 !important;
    left: 50%;
    transform: translateX(-50%);
  }
}

.purchase-button {
  width: 345px;
  height: 48px;
  background: var(--primary-dark);
  border: none;
  border-radius: 50px;
  color: white;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 16px;
  transition: background 0.3s;
}

.purchase-button:hover {
  background: var(--primary-mid);
}

.button-timer {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  font-weight: 400;
  height: 18px;
}

.timer-text {
  color: #FFFFFF;
}

.button-text {
  font-size: 16px;
  font-weight: 500;
  line-height: 22px;
}

/* 할인이 있을 때 버튼 높이 조정 */
.purchase-button.with-discount {
  height: 64px;
}

/* Wallpaper 없는 버전 스타일 */
.no-wallpaper-header {
  padding: 24px;
  margin-bottom: 24px;
}

.item-title-plain {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.item-subtitle-plain {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 20px;
}

/* 가격 섹션 */
.price-section {
  margin-bottom: 24px;
}

.price-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.original-price-plain {
  font-size: 14px;
  font-weight: 400;
  color: #999999;
  text-decoration: line-through;
}

.final-price-plain {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.discount-percent-plain {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-yellow);
}

.single-price {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

/* 할인 정보 박스 - React Native 스타일과 동일 */
.discount-info-box {
  background-color: #F9FAFB;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 24px;
  border: 1px solid var(--border-light);
}

.discount-header {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  gap: 8px;
}

.discount-final-price {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.discount-message {
  font-size: 12px;
  color: var(--text-secondary);
  flex: 1;
}

.discount-details {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.discount-amount {
  font-size: 12px;
  color: var(--accent-yellow);
  font-weight: 600;
}

.discount-timer {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* 통계 행 - wallpaper 없을 때만 */
.stats-row {
  display: flex;
  align-items: center;
  padding: 16px 0;
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
}

.stat-row-item {
  flex: 1;
  text-align: center;
}

.stat-row-value {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.stat-row-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.stat-row-divider {
  width: 1px;
  height: 24px;
  background-color: var(--border-light);
}

/* Mobile responsive design */
@media (max-width: 600px) {
  .wrapper {
    background: #FFFFFF;
  }

  .container {
    box-shadow: none;
  }

  .stats-container {
    width: calc(100vw - 48px);
    max-width: 345px;
  }

  .purchase-button {
    width: calc(100vw - 48px);
    max-width: 345px;
  }

  .price-badge {
    width: auto;
    max-width: 294px;
    padding: 10px 16px;
  }
}

/* 에러 페이지 */
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  text-align: center;
}

.error-container h1 {
  font-size: 18px;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.error-container a {
  color: var(--primary-light);
  text-decoration: none;
  font-weight: 500;
}

/* Animation styles for smooth transitions - wallpaper 제거 (위에 이미 정의됨) */

.content-section {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.content-section.loaded {
  opacity: 1;
  transform: translateY(0);
}

.review-cards {
  scroll-behavior: smooth;
  cursor: grab;
}

.review-cards:active {
  cursor: grabbing;
}

.purchase-button {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.purchase-button:active {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}