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

:root {
  --color-bg: #fff;
  --color-text: #1d1d1f;
  --color-secondary: #6e6e73;
  --color-accent: #0071e3;
  --color-accent-hover: #0077ed;
  --color-border: #d2d2d7;
  --color-surface: #f5f5f7;
  --color-nav: #1d1d1f;
  --color-nav-text: #f5f5f7;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  --max-width: 1200px;
  --nav-height: 48px;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* ========== Navigation ========== */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-nav);
  backdrop-filter: saturate(180%) blur(20px);
  height: var(--nav-height);
}

.nav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-logo {
  color: var(--color-nav-text);
  font-weight: 600;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-logo:hover { text-decoration: none; }

.nav-logo-img {
  height: 28px;
  width: auto;
}

.nav-links {
  display: flex;
  gap: 24px;
}
.nav-links a {
  color: var(--color-nav-text);
  font-size: 13px;
  opacity: 0.8;
  transition: opacity 0.2s;
}
.nav-links a:hover { opacity: 1; text-decoration: none; }

.nav-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-cart {
  color: var(--color-nav-text);
  position: relative;
  display: flex;
  align-items: center;
}

.cart-badge {
  position: absolute;
  top: -6px;
  right: -8px;
  background: var(--color-accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-account {
  color: var(--color-nav-text);
  font-size: 13px;
  opacity: 0.8;
}
.nav-account:hover { opacity: 1; text-decoration: none; }

/* ========== Hero ========== */
.hero {
  padding: 80px 24px;
  text-align: center;
  background: var(--color-surface);
}

.hero-inner {
  max-width: var(--max-width);
  margin: 0 auto;
}

.hero h1 {
  font-size: clamp(32px, 5vw, 56px);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}

.hero-subtitle {
  font-size: clamp(16px, 2vw, 21px);
  color: var(--color-secondary);
  max-width: 600px;
  margin: 0 auto;
}

/* ========== Sections ========== */
.section {
  padding: 64px 24px;
}

.section-dark {
  background: var(--color-surface);
}

.section-inner {
  max-width: var(--max-width);
  margin: 0 auto;
}

.section-title {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 32px;
}

.page-header {
  padding: 40px 24px 0;
}
.page-header .section-inner { max-width: var(--max-width); margin: 0 auto; }
.page-header h1 { font-size: 32px; font-weight: 600; }
.page-header p { color: var(--color-secondary); margin-top: 4px; }

/* ========== Breadcrumb ========== */
.breadcrumb {
  font-size: 13px;
  color: var(--color-secondary);
  margin-bottom: 16px;
}
.breadcrumb a { color: var(--color-accent); }

/* ========== Category Grid ========== */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.category-card {
  display: block;
  background: var(--color-surface);
  border-radius: 16px;
  overflow: hidden;
  color: var(--color-text);
  transition: transform 0.3s, box-shadow 0.3s;
}
.category-card:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
  text-decoration: none;
}
.category-card h3 { font-size: 18px; font-weight: 600; margin-bottom: 2px; }
.category-card p { font-size: 14px; color: var(--color-secondary); }
.category-card h3,
.category-card p { padding: 0 16px; }
.category-card h3 { padding-top: 12px; }
.category-card p { padding-bottom: 14px; }

/* ========== Subcategory Grid ========== */
.subcategory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.subcategory-card {
  display: block;
  background: var(--color-surface);
  border-radius: 16px;
  overflow: hidden;
  color: var(--color-text);
  transition: transform 0.3s, box-shadow 0.3s;
}
.subcategory-card:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
  text-decoration: none;
}
.subcategory-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 2px; }
.subcategory-card p { font-size: 13px; color: var(--color-secondary); }
.subcategory-card h3,
.subcategory-card p { padding: 0 16px; }
.subcategory-card h3 { padding-top: 12px; }
.subcategory-card p { padding-bottom: 14px; }

.subcategory-previews {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  aspect-ratio: 4/3;
  overflow: hidden;
}
.subcategory-previews img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ========== Template Grid & Cards ========== */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 24px;
}

.template-card {
  border-radius: 16px;
  overflow: hidden;
  background: var(--color-surface);
  transition: transform 0.3s, box-shadow 0.3s;
}
.template-card:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
}

.template-card img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
}

.template-card-info {
  padding: 12px 16px 4px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.template-card-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
}
.template-card-name:hover { text-decoration: none; color: var(--color-accent); }

.template-card-price {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-accent);
}
.template-card-price--free { color: #34c759; }

.btn-add-cart {
  display: block;
  width: calc(100% - 32px);
  margin: 8px 16px 16px;
  padding: 8px;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}
.template-card:hover .btn-add-cart { opacity: 1; }
.btn-add-cart:hover { background: var(--color-accent-hover); }

/* Mobile: always show add to cart */
@media (max-width: 768px) {
  .btn-add-cart { opacity: 1; }
}

/* ========== Template Detail ========== */
.template-detail { padding: 40px 24px 64px; }

.template-detail-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px;
  align-items: start;
}

.template-detail-preview img {
  width: 100%;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.template-detail-info h1 {
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 8px;
}

.template-detail-category {
  color: var(--color-secondary);
  margin-bottom: 16px;
}

.template-detail-price {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 24px;
}

@media (max-width: 768px) {
  .template-detail-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }
}

/* ========== Buttons ========== */
.btn-primary {
  display: inline-block;
  padding: 12px 24px;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  text-align: center;
}
.btn-primary:hover { background: var(--color-accent-hover); text-decoration: none; }

.btn-secondary {
  display: inline-block;
  padding: 10px 20px;
  background: transparent;
  color: var(--color-accent);
  border: 1px solid var(--color-accent);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: rgba(0,113,227,0.05); text-decoration: none; }

.btn-add-cart-detail {
  width: 100%;
  padding: 14px;
  font-size: 16px;
}

.btn-apple {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 20px;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-apple:hover { background: #333; }

/* ========== Cart ========== */
.cart-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 32px;
  align-items: start;
}

.cart-items { display: flex; flex-direction: column; gap: 16px; }

.cart-item {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: var(--color-surface);
  border-radius: 12px;
  align-items: center;
}

.cart-item img {
  width: 80px;
  border-radius: 8px;
}

.cart-item-info { flex: 1; }
.cart-item-name { font-weight: 500; }
.cart-item-price { color: var(--color-secondary); font-size: 14px; }

.cart-item-remove {
  background: none;
  border: none;
  color: var(--color-secondary);
  cursor: pointer;
  font-size: 13px;
}
.cart-item-remove:hover { color: #ff3b30; }

.cart-summary {
  padding: 24px;
  background: var(--color-surface);
  border-radius: 16px;
  position: sticky;
  top: calc(var(--nav-height) + 24px);
}

.cart-total {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.btn-checkout { width: 100%; }

.cart-empty { text-align: center; padding: 64px 0; }

@media (max-width: 768px) {
  .cart-layout { grid-template-columns: 1fr; }
}

/* ========== Auth ========== */
.input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 16px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}
.input:focus { border-color: var(--color-accent); }

.login-divider {
  text-align: center;
  margin: 24px 0;
  position: relative;
}
.login-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--color-border);
}
.login-divider span {
  background: var(--color-bg);
  padding: 0 12px;
  position: relative;
  color: var(--color-secondary);
  font-size: 13px;
}

.error-text { color: #ff3b30; font-size: 14px; margin-top: 12px; text-align: center; }

/* ========== Success ========== */
.success-downloads {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 24px 0;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.success-hint {
  color: var(--color-secondary);
  margin: 24px 0 12px;
  font-size: 14px;
}

/* ========== Account ========== */
.purchase-list { display: flex; flex-direction: column; gap: 12px; }

.purchase-item {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 16px;
  background: var(--color-surface);
  border-radius: 12px;
}

.purchase-item > div { flex: 1; }

.purchase-item-preview {
  width: 60px;
  border-radius: 8px;
}

.purchase-item-name { font-weight: 500; }
.purchase-item-date { font-size: 13px; color: var(--color-secondary); }

/* ========== App Promo ========== */
.hero-app { padding: 100px 24px; }

.app-badges {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 24px;
}
.app-badge img { height: 44px; }

.app-screenshots {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding: 16px 0;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  margin-top: 32px;
}

.feature-card {
  padding: 32px;
  border-radius: 16px;
  background: var(--color-bg);
}
.feature-card h3 { margin-bottom: 8px; }
.feature-card p { color: var(--color-secondary); font-size: 14px; }

/* ========== Legal ========== */
.legal-content { max-width: 720px; }
.legal-content h2 { font-size: 20px; margin: 32px 0 12px; }
.legal-content p { color: var(--color-secondary); margin-bottom: 16px; }

/* ========== Footer ========== */
.footer {
  padding: 24px;
  border-top: 1px solid var(--color-border);
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.footer-links { display: flex; gap: 24px; }
.footer-links a { color: var(--color-secondary); font-size: 13px; }

.footer-copy { color: var(--color-secondary); font-size: 13px; }

@media (max-width: 768px) {
  .footer-inner { flex-direction: column; gap: 12px; text-align: center; }
}

/* ========== Spinner ========== */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

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

/* ========== Animations ========== */
.fade-in {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s, transform 0.6s;
}

.fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ========== Responsive nav ========== */
@media (max-width: 768px) {
  .nav-links { display: none; }
  .template-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
}
