:root {
  --cream: #FBF3E7;
  --cream-2: #F4E9D8;
  --plum: #2E2247;
  --plum-soft: #4A3A6B;
  --gold: #E8A93B;
  --gold-soft: #F3CC85;
  --coral: #F2836B;
  --sage: #8FAE8B;
  --white: #FFFDF9;

  --font-display: "Baloo 2", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;

  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 10px;

  --shadow-soft: 0 12px 30px rgba(46, 34, 71, 0.12);
  --shadow-lift: 0 20px 40px rgba(46, 34, 71, 0.18);
}

* { box-sizing: border-box; }

/* [hidden] duu их эрэмбийн класс тохиргоог дийлж unhide хийгдэхээс сэргийлнэ */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--plum);
  font-family: var(--font-body);
  overflow-x: hidden;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ---------- background sky ---------- */

.sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.star {
  position: absolute;
  color: var(--gold-soft);
  opacity: 0.55;
  font-size: 22px;
  animation: twinkle 4s ease-in-out infinite;
}
.s1 { top: 8%; left: 6%; font-size: 18px; animation-delay: 0s; }
.s2 { top: 18%; left: 88%; font-size: 26px; animation-delay: 1.1s; }
.s3 { top: 62%; left: 92%; font-size: 16px; animation-delay: 2s; }
.s4 { top: 78%; left: 4%; font-size: 20px; animation-delay: 0.6s; }
.s5 { top: 40%; left: 50%; font-size: 14px; animation-delay: 1.7s; opacity: 0.35;}

@keyframes twinkle {
  0%, 100% { opacity: 0.25; transform: scale(0.9); }
  50% { opacity: 0.7; transform: scale(1.1); }
}

/* ---------- layout shell ---------- */

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 6vw;
}
.logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  color: var(--plum);
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.logo span { color: var(--coral); }
.logo small {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sage);
}
.topbar-badge {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--plum);
  color: var(--cream);
  padding: 6px 14px;
  border-radius: 999px;
}

main {
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: 0 6vw 80px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.auth-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--plum-soft);
}
.logout-link {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 12px;
  color: var(--coral);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* ---------- auth landing ---------- */

.auth-card {
  max-width: 380px;
  margin: 20px auto 60px;
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-soft);
}
.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 22px;
  background: var(--cream);
  border-radius: 999px;
  padding: 4px;
}
.auth-tab {
  flex: 1;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--plum-soft);
  background: none;
  border: none;
  border-radius: 999px;
  padding: 10px;
  cursor: pointer;
}
.auth-tab.active {
  background: var(--white);
  color: var(--coral);
  box-shadow: 0 2px 6px rgba(46,34,71,0.1);
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-error {
  color: var(--coral);
  font-size: 13px;
  text-align: center;
  margin: 0;
}
.link-btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 12.5px;
  color: var(--plum-soft);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-align: center;
  padding: 0;
}
.auth-form-hint {
  font-size: 13px;
  color: var(--plum-soft);
  text-align: center;
  margin: 0 0 4px;
}
.auth-success {
  text-align: center;
  padding: 10px 0;
}
.auth-success p {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--sage);
  font-size: 15px;
  margin: 0 0 8px;
}
.auth-success-hint {
  font-family: var(--font-body) !important;
  font-weight: 400 !important;
  font-size: 13px !important;
  color: var(--plum-soft) !important;
}
.verify-status {
  text-align: center;
  padding: 16px;
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
}
.verify-status.verify-loading { background: var(--cream); color: var(--plum-soft); }
.verify-status.verify-success { background: #d8ecd4; color: #2f6b2a; }
.verify-status.verify-error { background: #f3d6d0; color: #9a3b2a; }

.hero {
  text-align: center;
  padding: 40px 0 20px;
}
.eyebrow {
  font-family: var(--font-body);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--coral);
  margin: 0 0 10px;
}
.hero h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(32px, 5.5vw, 52px);
  line-height: 1.15;
  margin: 0 0 18px;
  color: var(--plum);
}
.hero h1 em {
  font-style: normal;
  color: var(--coral);
  position: relative;
}
.hero-sub {
  max-width: 520px;
  margin: 0 auto;
  font-size: 17px;
  line-height: 1.6;
  color: var(--plum-soft);
}

/* ---------- story card ---------- */

.story-card {
  display: flex;
  align-items: center;
  gap: 22px;
  background: var(--white);
  border: 1px solid rgba(46,34,71,0.08);
  border-radius: var(--radius-lg);
  padding: 22px 26px;
  margin: 34px 0;
  box-shadow: var(--shadow-soft);
}
.story-cover {
  flex: 0 0 auto;
  width: 68px;
  height: 68px;
  border-radius: var(--radius-md);
  background: linear-gradient(160deg, var(--sage), #6f9169);
  display: grid;
  place-items: center;
  font-size: 32px;
}
.story-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sage);
  margin-bottom: 4px;
}
.story-info h2 {
  font-family: var(--font-display);
  font-size: 21px;
  margin: 0 0 6px;
  color: var(--plum);
}
.story-info p {
  margin: 0;
  font-size: 14.5px;
  color: var(--plum-soft);
  line-height: 1.5;
}

/* ---------- result-area: story approval ---------- */

.result-story-ready {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.story-ready-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--plum);
  margin: 0 0 10px;
  text-align: center;
}

.story-outline {
  list-style: none;
  counter-reset: page-counter;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.story-outline:empty { display: none; }
.story-outline li {
  counter-increment: page-counter;
  background: var(--white);
  border: 1px solid rgba(46,34,71,0.08);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--plum-soft);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
}
.story-outline li::before {
  content: counter(page-counter);
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--coral);
  flex: 0 0 auto;
  min-width: 18px;
  padding-top: 8px;
}
.outline-textarea {
  flex: 1;
  border: 1px solid transparent;
  background: transparent;
  padding: 6px 8px;
  font-family: var(--font-body);
  font-size: 13.5px;
  color: var(--plum-soft);
  border-radius: 8px;
  resize: vertical;
  min-height: 40px;
}
.outline-textarea:hover, .outline-textarea:focus {
  border-color: var(--cream-2);
  background: var(--cream);
  color: var(--plum);
  outline: none;
}
.story-outline li.active {
  border-color: var(--gold);
  background: var(--cream-2);
  font-weight: 700;
  color: var(--plum);
}
.story-outline li.done::after {
  content: "✓";
  margin-left: auto;
  color: var(--sage);
  font-weight: 700;
}

.btn-approve {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--white);
  background: linear-gradient(135deg, var(--sage), #6f9169);
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(143,174,139,0.4);
  transition: transform 0.12s ease;
  width: 100%;
}
.btn-approve:hover { transform: translateY(-1px); }
.btn-approve:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.approve-hint {
  font-size: 12px;
  color: rgba(74,58,107,0.65);
  margin: 8px 0 0;
  text-align: center;
}

/* ---------- result-area: захиалгын CTA / форм / баталгаа ---------- */

.page-edit-area {
  width: 100%;
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.btn-edit-text {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  color: var(--plum-soft);
  background: var(--cream);
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
}
.page-edit-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.btn-regenerate {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--white);
  background: linear-gradient(135deg, var(--gold), #d99a2b);
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
}
.btn-regenerate:disabled { opacity: 0.6; cursor: not-allowed; }

.order-cta-area {
  width: 100%;
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px dashed rgba(46,34,71,0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.order-cta-text {
  margin: 0;
  font-size: 13.5px;
  color: var(--plum-soft);
  max-width: 320px;
}
.btn-order {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: var(--white);
  background: linear-gradient(135deg, var(--gold), #d99a2b);
  border: none;
  border-radius: 999px;
  padding: 15px 26px;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(232,169,59,0.4);
  transition: transform 0.12s ease;
}
.btn-order:hover { transform: translateY(-1px); }

.order-form {
  width: 100%;
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px dashed rgba(46,34,71,0.15);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.btn-order-submit {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--white);
  background: linear-gradient(135deg, var(--coral), #e06b50);
  border: none;
  border-radius: 999px;
  padding: 14px 20px;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(242,131,107,0.35);
}
.btn-order-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.order-done {
  width: 100%;
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px dashed rgba(46,34,71,0.15);
  text-align: center;
}
.order-done p {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--sage);
  font-size: 15px;
  margin: 0;
}
.bank-info {
  background: var(--cream);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 14px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}
.bank-info div {
  font-family: var(--font-body);
  font-size: 13.5px;
  color: var(--plum);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.bank-info span { color: var(--plum-soft); font-weight: 400; }
.bank-info b { font-weight: 700; }
.order-done-note {
  font-family: var(--font-body) !important;
  font-weight: 400 !important;
  font-size: 12px !important;
  color: rgba(74,58,107,0.65) !important;
}

/* ---------- workspace ---------- */

.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  align-items: start;
}
@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }
}

.gen-form {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.field { display: flex; flex-direction: column; gap: 8px; }
.field-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--plum);
}

input[type="text"], input[type="number"], input[type="email"], input[type="password"], input[type="tel"], select, textarea {
  font-family: var(--font-body);
  font-size: 16px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--cream-2);
  background: var(--cream);
  color: var(--plum);
  outline: none;
  transition: border-color 0.15s ease;
  resize: vertical;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="email"]:focus, input[type="password"]:focus, input[type="tel"]:focus, select:focus, textarea:focus {
  border-color: var(--coral);
}

.upload-box {
  position: relative;
  border: 2px dashed rgba(46,34,71,0.22);
  border-radius: var(--radius-md);
  background: var(--cream);
  min-height: 180px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  overflow: hidden;
}
.upload-box:hover, .upload-box.dragover {
  border-color: var(--coral);
  background: var(--cream-2);
}
.upload-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 20px;
  color: var(--plum-soft);
  font-weight: 600;
  font-size: 14.5px;
}
.upload-icon { font-size: 30px; }
.upload-hint {
  font-weight: 400;
  font-size: 12.5px;
  color: rgba(74,58,107,0.7);
}
.upload-preview {
  width: 100%;
  height: 100%;
  min-height: 180px;
  object-fit: cover;
}
.upload-confirm {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--sage);
  color: var(--white);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 12.5px;
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 6px 14px rgba(46,34,71,0.25);
}

.btn-generate {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: var(--white);
  background: linear-gradient(135deg, var(--coral), #e06b50);
  border: none;
  border-radius: 999px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(242,131,107,0.38);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn-generate:hover { transform: translateY(-1px); box-shadow: 0 14px 28px rgba(242,131,107,0.45); }
.btn-generate:active { transform: translateY(0); }
.btn-generate:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}
.btn-spark {
  display: inline-block;
  animation: spin-spark 3s linear infinite;
}
@keyframes spin-spark {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}

.form-note {
  margin: 0;
  font-size: 12.5px;
  text-align: center;
  color: rgba(74,58,107,0.65);
}

.consent-field {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  color: var(--plum-soft);
  line-height: 1.4;
  cursor: pointer;
}
.consent-field input[type="checkbox"] {
  flex: 0 0 auto;
  margin-top: 2px;
  width: 16px;
  height: 16px;
  accent-color: var(--coral);
}
.consent-field a {
  color: var(--coral);
  font-weight: 700;
}

/* ---------- result area ---------- */

.result-area {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  min-height: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
}

.result-placeholder, .result-loading, .result-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  color: var(--plum-soft);
}

.placeholder-frame {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--cream);
  display: grid;
  place-items: center;
  font-size: 34px;
  border: 2px dashed rgba(46,34,71,0.18);
}

.loading-book {
  font-size: 44px;
  animation: bounce-book 1.1s ease-in-out infinite;
}
@keyframes bounce-book {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-10px) rotate(3deg); }
}
.loading-hint { font-size: 12.5px; color: rgba(74,58,107,0.65); margin: 0; }

.result-error .error-title {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--coral);
  font-size: 17px;
  margin: 0;
}
.error-detail { font-size: 13.5px; margin: 0; max-width: 320px; }
.btn-retry {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 14px;
  color: var(--plum);
  background: var(--cream-2);
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  cursor: pointer;
  margin-top: 6px;
}

.result-pair {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.polaroid {
  margin: 0;
  background: var(--white);
  border: 1px solid rgba(46,34,71,0.08);
  border-radius: var(--radius-sm);
  padding: 10px 10px 16px;
  box-shadow: var(--shadow-lift);
  width: 190px;
  text-align: center;
  transform: rotate(-3deg);
}
.polaroid.generated {
  transform: rotate(3deg);
  border-color: var(--gold-soft);
}
.polaroid img {
  width: 100%;
  height: 190px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}
.polaroid figcaption {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--plum-soft);
  margin-top: 10px;
}

.wand {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--gold);
  animation: pulse-wand 1.6s ease-in-out infinite;
}
@keyframes pulse-wand {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* ---------- pages gallery + next page ---------- */

.pages-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  width: 100%;
  margin-top: 18px;
}
.pages-gallery:empty { display: none; margin-top: 0; }

.pages-gallery .polaroid {
  width: 150px;
  transform: rotate(-2deg);
}
.pages-gallery .polaroid:nth-child(even) { transform: rotate(2deg); }
.pages-gallery .polaroid img { height: 150px; }

.next-page-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
  width: 100%;
}
.btn-next-page {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--white);
  background: linear-gradient(135deg, var(--sage), #6f9169);
  border: none;
  border-radius: 999px;
  padding: 13px 24px;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(143,174,139,0.4);
  transition: transform 0.12s ease;
}
.btn-next-page:hover { transform: translateY(-1px); }
.btn-next-page:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.next-page-hint {
  font-size: 12.5px;
  color: rgba(74,58,107,0.65);
  margin: 0;
  text-align: center;
}

.story-done {
  margin-top: 20px;
  text-align: center;
}
.story-done p {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--gold);
  font-size: 15px;
  margin: 0;
}

/* ---------- footer ---------- */

footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 30px 0 50px;
  font-size: 12.5px;
  color: rgba(74,58,107,0.55);
}
