/* Discovery page styles */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0f1117;
  color: #e0e0e0;
  min-height: 100vh;
  background-image: repeating-linear-gradient(-45deg, transparent, transparent 40px, rgba(230,57,70,0.03) 40px, rgba(230,57,70,0.03) 41px);
}

/* ---- Header ---- */
.discover-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: #1a1d27;
  border-bottom: 1px solid #2d3148;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #e63946, #ff6b6b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-decoration: none;
  letter-spacing: -0.5px;
}

.nav-tabs {
  display: flex;
  gap: 4px;
}

.nav-tab {
  padding: 8px 16px;
  background: none;
  border: none;
  color: #888;
  font-size: 14px;
  cursor: pointer;
  transition: color .2s, background .2s;
  border-bottom: 2px solid transparent;
}

.nav-tab:hover { color: #ccc; }
.nav-tab.active {
  color: #e63946;
  border-bottom-color: #e63946;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  white-space: nowrap;
}

#auth-area {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

/* Language switcher */
.lang-switcher { padding: 4px 8px; background: transparent; border: 1px solid #2d3148; color: #8888aa; font-size: 11px; cursor: pointer; margin-right: 4px; appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23e63946' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
.lang-switcher:hover { border-color: #e63946; color: #e0e0e0; }
.lang-switcher:focus { border-color: #e63946; outline: none; }
.lang-switcher option { background: #12141d; color: #e0e0e0; }

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ccc;
  font-size: 13px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #e63946, #ff6b6b);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.btn-header-login {
  padding: 7px 18px;
  background: linear-gradient(135deg, #e63946, #ff6b6b);
  border: none;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
}

.btn-header-login:hover { opacity: 0.85; }

.btn-header-studio {
  padding: 6px 14px;
  background: linear-gradient(135deg, #e63946, #ff6b6b);
  border: none;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .2s;
}
.btn-header-studio:hover { opacity: 0.85; }

.btn-header-logout {
  padding: 6px 14px;
  background: none;
  border: 1px solid #e63946;
  color: #e63946;
  font-size: 12px;
  cursor: pointer;
  transition: background .2s;
}

.btn-header-logout:hover { background: rgba(230,57,70,0.1); }

/* ---- Main Content ---- */
.discover-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px 80px;
}

.view-panel { display: none; }
.view-panel.active { display: block; }

/* ---- Waterfall Grid ---- */
.discover-grid {
  columns: 2;
  column-gap: 12px;
}

@media (min-width: 640px) { .discover-grid { columns: 3; } }
@media (min-width: 960px) { .discover-grid { columns: 4; } }

/* ---- Cards ---- */
.discover-card {
  break-inside: avoid;
  margin-bottom: 12px;
  background: #1a1d27;
  border: 1px solid #2d3148;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s;
  cursor: default;
}

.discover-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.discover-card .image-grid { width: 100%; }
.discover-card .image-grid.cols-1 img {
  width: 100%;
  display: block;
}

.discover-card .image-grid.cols-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
}

.discover-card .image-grid.cols-2 img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.discover-card video {
  width: 100%;
  display: block;
}

.discover-card .card-info {
  padding: 10px 12px;
}

.prompt-text {
  font-size: 12px;
  color: #bbb;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
  margin-bottom: 8px;
  word-break: break-word;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.author {
  font-size: 11px;
  color: #666;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-like {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: #888;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
  transition: color .2s;
}

.btn-like:hover { color: #e63946; }
.btn-like.liked { color: #e63946; }

.btn-like svg {
  width: 16px;
  height: 16px;
}

.btn-use {
  padding: 4px 12px;
  background: rgba(230,57,70,0.15);
  border: 1px solid rgba(230,57,70,0.3);
  color: #e63946;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}

.btn-use:hover { background: rgba(230,57,70,0.25); }

/* ---- Template Cards ---- */
.tpl-card {
  break-inside: avoid;
  margin-bottom: 12px;
  background: #1a1d27;
  border: 1px solid #2d3148;
  overflow: hidden;
  display: block;
  text-decoration: none;
  color: inherit;
  transition: transform .2s, box-shadow .2s;
}

.tpl-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.tpl-cover {
  width: 100%;
  display: block;
}

.tpl-cover-placeholder {
  width: 100%;
  aspect-ratio: 16/10;
  background: linear-gradient(135deg, #1a1d27, #2d3148);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  font-weight: 700;
  color: #e63946;
}

.tpl-info {
  padding: 12px 14px;
}

.tpl-category {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #e63946;
  background: rgba(230,57,70,0.12);
  padding: 2px 8px;
  margin-bottom: 6px;
}

.tpl-title {
  font-size: 15px;
  font-weight: 600;
  color: #e0e0e0;
  margin: 0 0 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tpl-desc {
  font-size: 12px;
  color: #888;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
}

.tpl-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.tpl-tag {
  font-size: 10px;
  padding: 2px 6px;
  background: #12141d;
  border: 1px solid #2d3148;
  color: #888;
}

.tpl-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #2d314840;
}

.tpl-author {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #888;
}

.tpl-author-avatar {
  width: 20px;
  height: 20px;
  object-fit: cover;
  display: block;
}

.tpl-author-letter {
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, #e63946, #ff6b6b);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
}

.tpl-like {
  font-size: 12px;
}

/* ---- Loading ---- */
.load-more {
  text-align: center;
  padding: 30px;
  color: #666;
  font-size: 13px;
}

.loader {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid #333;
  border-top-color: #e63946;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: #555;
}

.empty-state h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: #777;
}

/* ---- Templates placeholder ---- */
.templates-placeholder {
  text-align: center;
  padding: 100px 20px;
  color: #555;
}

.templates-placeholder h2 {
  font-size: 24px;
  margin-bottom: 12px;
  color: #777;
}

/* ---- Login Modal ---- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.login-modal {
  width: 380px;
  max-width: 90vw;
  background: #1a1d27;
  border: 1px solid #2d3148;
  padding: 32px 28px;
}

.login-modal h2 {
  font-size: 20px;
  margin-bottom: 4px;
  color: #e0e0e0;
}

.login-modal .subtitle {
  font-size: 13px;
  color: #666;
  margin-bottom: 24px;
}

.login-modal .form-group {
  margin-bottom: 14px;
}

.login-modal label {
  display: block;
  font-size: 12px;
  color: #999;
  margin-bottom: 4px;
}

.login-modal input {
  width: 100%;
  padding: 10px 12px;
  background: #12141d;
  border: 1px solid #2d3148;
  color: #e0e0e0;
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}

.login-modal input:focus { border-color: #e63946; }

.login-error {
  display: none;
  color: #ef4444;
  font-size: 12px;
  margin-bottom: 10px;
}

.btn-login {
  width: 100%;
  padding: 10px;
  background: linear-gradient(135deg, #e63946, #ff6b6b);
  border: none;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 12px;
  transition: opacity .2s;
}

.btn-login:hover { opacity: 0.85; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: #555;
  font-size: 12px;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #2d3148;
}

.btn-google {
  width: 100%;
  padding: 10px;
  background: #12141d;
  border: 1px solid #2d3148;
  color: #888;
  font-size: 13px;
  cursor: not-allowed;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
}

.btn-google .coming-soon {
  position: absolute;
  right: 10px;
  font-size: 9px;
  padding: 2px 6px;
  background: rgba(230,57,70,0.15);
  color: #e63946;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: #666;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { color: #e0e0e0; }

/* ---- Lightbox ---- */
.lightbox {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.9);
  z-index: 300;
  align-items: center;
  justify-content: center;
}

.lightbox.active { display: flex; }

.lightbox img, .lightbox video {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
}

.lb-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 32px;
  cursor: pointer;
}

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(230,57,70,0.3);
  border: none;
  color: #fff;
  font-size: 28px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-nav:hover { background: rgba(230,57,70,0.5); }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }

.lb-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: #aaa;
  font-size: 13px;
}

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  background: #1a1d27;
  border: 1px solid #2d3148;
  color: #e0e0e0;
  font-size: 13px;
  min-width: 200px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.toast-success { border-color: #22c55e; color: #22c55e; }

/* ---- Header Avatar ---- */
.header-avatar-img {
  width: 28px;
  height: 28px;
  object-fit: cover;
  display: block;
}

/* ---- Profile Modal ---- */
.profile-avatar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile-avatar-img {
  width: 48px;
  height: 48px;
  object-fit: cover;
}

.profile-avatar-placeholder {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #e63946, #ff6b6b);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}

.btn-upload-avatar {
  padding: 6px 14px;
  background: #12141d;
  border: 1px solid #2d3148;
  color: #aaa;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .2s;
}

.btn-upload-avatar:hover { border-color: #e63946; color: #e63946; }
.toast-error { border-color: #ef4444; color: #ef4444; }
.toast-warn { border-color: #f59e0b; color: #f59e0b; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0f1117; }
::-webkit-scrollbar-thumb { background: #2d3148; }
::-webkit-scrollbar-thumb:hover { background: #3d4158; }

/* ---- Mobile ---- */
@media (max-width: 640px) {
  .discover-header { padding: 0 12px; }
  .logo { font-size: 17px; }
  .nav-tab { padding: 6px 10px; font-size: 13px; }
  .discover-main { padding: 12px 10px 80px; }
  .discover-grid { column-gap: 8px; }
  .discover-card .card-info { padding: 8px 10px; }
  .login-modal { padding: 24px 20px; }
  .header-left { gap: 16px; }
}
