:root {
  --bordo: #8B1A1A;
  --zloto: #C9A84C;
  --zloto-jasne: #F0D080;
  --ciemny: #1a1008;
  --tekst: #2d1a00;
  --tlo: #fdf8f0;
  --szary: #f0e8d8;
  --cien: 0 4px 24px rgba(139,26,26,0.10);
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--tlo);
  color: var(--tekst);
  line-height: 1.6;
}

/* NAV */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 2rem;
  background: rgba(253,248,240,0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--szary);
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--bordo);
}

.nav-logo img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 50%;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-link {
  text-decoration: none;
  color: #7a5c2a;
  font-size: 0.9rem;
  font-weight: 600;
  transition: color 0.2s;
}

.nav-link:hover { color: var(--bordo); }

#nav-auth {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-coins {
  font-weight: 700;
  color: var(--bordo);
  font-size: 0.95rem;
  white-space: nowrap;
}

.nav-email {
  font-size: 0.78rem;
  color: #7a5c2a;
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-nav-login {
  background: var(--bordo);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.btn-nav-logout {
  background: transparent;
  border: 1.5px solid #c0a060;
  color: #7a5c2a;
  border-radius: 10px;
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

/* HERO + GENERATOR */
.hero-generator {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  min-height: calc(100vh - 57px);
  background: linear-gradient(135deg, var(--bordo) 0%, #5a0f0f 100%);
  position: relative;
  overflow: hidden;
}

.hero-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 2rem;
  position: relative;
}

.hero-janusz {
  max-height: 75vh;
  max-width: 100%;
  object-fit: contain;
  filter: drop-shadow(0 20px 40px rgba(0,0,0,0.5));
  position: relative;
  z-index: 1;
}

.hero-bubble {
  position: absolute;
  top: 15%;
  right: -10px;
  background: white;
  color: var(--tekst);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  padding: 0.8rem 1.1rem;
  border-radius: 16px 16px 4px 16px;
  box-shadow: var(--cien);
  z-index: 2;
  max-width: 200px;
}

.hero-right {
  padding: 3rem 2.5rem 3rem 2rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.5rem;
}

.hero-tagline h1 {
  font-size: clamp(2rem, 3.5vw, 2.8rem);
  font-weight: 800;
  color: white;
  line-height: 1.2;
  margin-bottom: 0.5rem;
}

.hero-tagline h1 span { color: var(--zloto-jasne); }

.hero-tagline p {
  color: rgba(255,255,255,0.8);
  font-size: 1rem;
}

/* TRYB TOGGLE */
.mode-toggle {
  display: inline-flex;
  background: rgba(0,0,0,0.25);
  border-radius: 12px;
  padding: 4px;
  align-self: flex-start;
}

.mode-toggle button {
  padding: 0.5rem 1.1rem;
  border: none;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: rgba(255,255,255,0.7);
  transition: all 0.2s;
}

.mode-toggle button.active {
  background: white;
  color: var(--bordo);
}

/* PROMPT BOX */
.prompt-box {
  background: white;
  border-radius: 20px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

#prompt-input {
  width: 100%;
  min-height: 160px;
  border: none;
  outline: none;
  font-size: 1rem;
  resize: vertical;
  font-family: inherit;
  color: var(--tekst);
  line-height: 1.6;
}

#prompt-input::placeholder { color: #b0946a; }

.prompt-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--szary);
  flex-wrap: wrap;
}

/* ENHANCED PREVIEW */
.enhanced-preview {
  background: rgba(255,255,255,0.12);
  border: 1px solid var(--zloto);
  border-radius: 14px;
  padding: 1rem 1.25rem;
  display: none;
}

.enhanced-preview.visible { display: block; }
.enhanced-preview p { font-size: 0.88rem; color: rgba(255,255,255,0.85); margin-bottom: 0.5rem; }
.enhanced-preview .preview-text { font-style: italic; color: white; margin-bottom: 0.75rem; }
.enhanced-actions { display: flex; gap: 0.5rem; }

/* KREATOR */
#kreator-panel { display: none; gap: 1rem; flex-direction: column; }
#kreator-panel.visible { display: flex; }

.kreator-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}

.kreator-card {
  background: rgba(255,255,255,0.1);
  border: 1.5px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 0.75rem 0.5rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
}

.kreator-card:hover, .kreator-card.active {
  background: rgba(255,255,255,0.2);
  border-color: var(--zloto);
}

.kreator-card .emoji { font-size: 1.5rem; display: block; margin-bottom: 0.2rem; }
.kreator-card .label { font-size: 0.78rem; font-weight: 600; color: white; }

.kreator-form {
  background: white;
  border-radius: 16px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  display: none;
}

.kreator-form.visible { display: block; }

.kreator-form label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: #7a5c2a;
  margin-bottom: 0.25rem;
  margin-top: 0.6rem;
}

.kreator-form input, .kreator-form select {
  width: 100%;
  padding: 0.55rem 0.85rem;
  border: 2px solid var(--szary);
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--tekst);
  background: var(--tlo);
  outline: none;
  transition: border-color 0.2s;
}

.kreator-form input:focus, .kreator-form select:focus { border-color: var(--zloto); }

.kreator-form-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.kreator-prompt-preview {
  background: #fdf3e3;
  border: 1.5px solid var(--zloto);
  border-radius: 10px;
  padding: 0.85rem 1.1rem;
  margin-top: 1rem;
}

.kreator-prompt-preview-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--zloto);
  margin-bottom: 0.5rem;
}

.kreator-prompt-preview-text {
  font-size: 0.88rem;
  color: #2d1a00;
  line-height: 1.65;
  font-style: normal;
  word-break: break-word;
  white-space: pre-wrap;
  max-height: 160px;
  overflow-y: auto;
}

/* PRZYCISKI */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.7rem 1.5rem;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: transform 0.15s, box-shadow 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.18); }
.btn:active { transform: translateY(0); }

.btn-zloto { background: var(--zloto); color: var(--ciemny); }
.btn-bordo { background: var(--bordo); color: white; }
.btn-outline { background: transparent; border: 2px solid rgba(255,255,255,0.5); color: white; }
.btn-outline-dark { background: transparent; border: 2px solid var(--bordo); color: var(--bordo); }
.btn-lg { padding: 0.85rem 2rem; font-size: 1rem; }

/* WYNIK GENERACJI */
#result-section {
  max-width: 760px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
  display: none;
}

#result-section.visible { display: block; }

.loading-overlay {
  background: white;
  border-radius: 20px;
  padding: 4rem 2rem;
  text-align: center;
  box-shadow: var(--cien);
  display: none;
}

.loading-overlay.visible { display: block; }

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--szary);
  border-top-color: var(--bordo);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay p { color: #7a5c2a; font-style: italic; }

#result-image-wrap {
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--cien);
}

#result-image-wrap img { width: 100%; display: block; }

.result-actions {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
  justify-content: center;
}

/* CTA SECTION */
.cta-section {
  background: linear-gradient(135deg, var(--bordo) 0%, #5a0f0f 100%);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 3rem 5rem 0 5rem;
  gap: 2rem;
  overflow: hidden;
}

.cta-content {
  padding-bottom: 3rem;
  max-width: 500px;
}

.cta-content h2 {
  font-size: 2rem;
  font-weight: 800;
  color: white;
  margin-bottom: 0.75rem;
}

.cta-content p {
  color: rgba(255,255,255,0.8);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.cta-janusz {
  max-height: 380px;
  object-fit: contain;
  filter: drop-shadow(0 -10px 30px rgba(0,0,0,0.4));
  align-self: flex-end;
}

/* MOJE GENERACJE */
#moje-generacje {
  background: var(--tlo);
  padding: 5rem 2rem;
  border-top: 2px solid var(--szary);
}

/* GALERIA */
#galeria {
  background: var(--szary);
  padding: 5rem 2rem;
}

.section-header {
  text-align: center;
  margin-bottom: 3rem;
}

.section-header h2 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--bordo);
  margin-bottom: 0.4rem;
}

.section-header p { color: #7a5c2a; }

.galeria-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  max-width: 1100px;
  margin: 0 auto;
}

.galeria-card {
  background: white;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--cien);
  transition: transform 0.2s;
}

.galeria-card:hover { transform: translateY(-4px); }
.galeria-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }

.galeria-card-body { padding: 0.9rem 1rem; }

.galeria-card-body p {
  font-size: 0.82rem;
  color: #7a5c2a;
  margin-bottom: 0.6rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.galeria-load-more { text-align: center; margin-top: 2rem; }

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,16,8,0.75);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

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

.modal {
  background: white;
  border-radius: 24px;
  padding: 2.5rem;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  position: relative;
}

.modal h2 { font-size: 1.5rem; color: var(--bordo); margin-bottom: 0.4rem; }
.modal > p { color: #7a5c2a; margin-bottom: 1.5rem; font-size: 0.9rem; }

.modal-pakiety {
  display: grid;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}

.modal-pakiet {
  border: 2px solid var(--szary);
  border-radius: 12px;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s;
  font-size: 0.9rem;
}

.modal-pakiet:hover, .modal-pakiet.selected {
  border-color: var(--bordo);
  background: #fff5f5;
}

.modal-pakiet-left { display: flex; flex-direction: column; }
.modal-pakiet .pakiet-nazwa { font-weight: 700; color: var(--tekst); }
.modal-pakiet .pakiet-info { font-size: 0.78rem; color: #7a5c2a; margin-top: 0.1rem; }
.modal-pakiet .pakiet-cena { font-weight: 800; font-size: 1.1rem; color: var(--bordo); }

.modal-email { margin-bottom: 1rem; }

.modal-email label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #7a5c2a;
  margin-bottom: 0.4rem;
}

.modal-email input {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 2px solid var(--szary);
  border-radius: 12px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.modal-email input:focus { border-color: var(--zloto); }

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #b0946a;
  line-height: 1;
}

/* PREVIEW LIGHTBOX */
.modal-preview-inner {
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-preview-inner img {
  width: 100%;
  border-radius: 12px;
  display: block;
  flex-shrink: 0;
  max-height: 55vh;
  object-fit: contain;
  background: #f0e8d8;
}

.preview-prompt-text {
  margin-top: 1rem;
  color: #7a5c2a;
  font-size: 0.9rem;
  line-height: 1.5;
  font-style: italic;
  overflow-y: auto;
  flex-shrink: 1;
}

/* FOOTER */
footer {
  background: var(--ciemny);
  color: rgba(255,255,255,0.55);
  text-align: center;
  padding: 2rem;
  font-size: 0.85rem;
}

footer a { color: var(--zloto); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* RESPONSIVE */
@media (max-width: 900px) {
  .hero-generator {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .hero-left {
    display: none;
  }

  .hero-right {
    padding: 2.5rem 1.5rem;
  }

  .cta-section {
    padding: 3rem 2rem 0;
    flex-direction: column;
  }

  .cta-janusz { max-height: 220px; align-self: center; }
  .galeria-grid { grid-template-columns: 1fr 1fr; }
  .kreator-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 540px) {
  .galeria-grid { grid-template-columns: 1fr; }
  .prompt-actions { justify-content: stretch; }
  .prompt-actions .btn { flex: 1; justify-content: center; }
}

/* MODAL HISTORII */
.modal-historia-inner { max-width: 520px; max-height: 80vh; overflow-y: auto; }
.historia-saldo {
  display: flex;
  align-items: center;
  background: var(--szary);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  margin-bottom: 1.25rem;
}
.historia-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--szary);
}
.historia-tab {
  background: none;
  border: none;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #999;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.historia-tab.active { color: var(--bordo); border-bottom-color: var(--bordo); }
.historia-lista { display: flex; flex-direction: column; gap: 0.5rem; }
.historia-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  background: var(--szary);
  border-radius: 8px;
  font-size: 0.85rem;
  gap: 1rem;
}
.historia-row-left { color: var(--tekst); flex: 1; min-width: 0; }
.historia-row-left p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.historia-row-left small { color: #999; font-size: 0.75rem; }
.historia-row-right { color: var(--bordo); font-weight: 700; white-space: nowrap; }
.historia-empty { text-align: center; color: #b0946a; padding: 2rem; font-size: 0.9rem; }
