/* ============================================================
   往生遺照生成器 — Memorial Portrait Photo Generator
   Premium Stylesheet · Pure Vanilla CSS
   ============================================================ */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@400;600;700&family=Inter:wght@300;400;500;600&display=swap');

/* ── Design Tokens (CSS Custom Properties) ───────────────── */
:root {
  /* Background palette */
  --bg-deepest:    #0f0f1a;
  --bg-deep:       #1a1a2e;
  --bg-mid:        #16213e;
  --bg-card:       rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);
  --bg-input:      rgba(0, 0, 0, 0.35);
  --bg-overlay:    rgba(10, 10, 22, 0.88);

  /* Gold accent */
  --gold:          #c9a96e;
  --gold-light:    #dbb887;
  --gold-dim:      rgba(201, 169, 110, 0.25);
  --gold-glow:     rgba(201, 169, 110, 0.35);
  --gold-gradient: linear-gradient(135deg, #c9a96e, #dbb887, #c9a96e);
  --gold-btn:      linear-gradient(135deg, #c9a96e 0%, #dbb887 50%, #c9a96e 100%);

  /* Text */
  --text-primary:  #f5f5f0;
  --text-muted:    #a0a0b0;
  --text-dim:      #6a6a7a;

  /* Feedback */
  --success:       #5cb77a;
  --error:         #e05555;
  --info:          #5b8bd4;

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-light:  rgba(255, 255, 255, 0.10);
  --border-gold:   rgba(201, 169, 110, 0.40);

  /* Radii */
  --radius-sm:  8px;
  --radius-md:  14px;
  --radius-lg:  20px;
  --radius-xl:  28px;

  /* Shadows */
  --shadow-sm:    0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md:    0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg:    0 8px 40px rgba(0, 0, 0, 0.45);
  --shadow-gold:  0 0 20px rgba(201, 169, 110, 0.15);
  --shadow-glow:  0 0 30px rgba(201, 169, 110, 0.25);

  /* Transitions */
  --ease:     0.3s ease;
  --ease-out: 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);

  /* Typography */
  --font-serif: 'Noto Serif TC', 'Georgia', serif;
  --font-sans:  'Inter', -apple-system, 'Segoe UI', sans-serif;

  /* Layout */
  --max-width:  900px;
  --gutter:     24px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  background: var(--bg-deepest);
  background-image:
    radial-gradient(ellipse at 20% 0%,  rgba(22, 33, 62, 0.6) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(26, 26, 46, 0.5) 0%, transparent 60%),
    linear-gradient(175deg, var(--bg-deepest) 0%, var(--bg-deep) 45%, var(--bg-mid) 100%);
  background-attachment: fixed;
}

a { color: var(--gold-light); text-decoration: none; }
a:hover { color: var(--gold); }

::selection {
  background: var(--gold-dim);
  color: var(--text-primary);
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--gold-dim);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--gold); }

/* ============================================================
   KEYFRAME ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

@keyframes lotusRotate {
  0%   { transform: rotate(0deg)   scale(1); }
  25%  { transform: rotate(90deg)  scale(1.05); }
  50%  { transform: rotate(180deg) scale(1); }
  75%  { transform: rotate(270deg) scale(1.05); }
  100% { transform: rotate(360deg) scale(1); }
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 15px rgba(201, 169, 110, 0.15); }
  50%      { box-shadow: 0 0 35px rgba(201, 169, 110, 0.35); }
}

@keyframes floatUp {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

@keyframes textFade {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 1; }
}

/* ============================================================
   1.  APP CONTAINER
   ============================================================ */
.app-container {
  width: 80%;
  max-width: 1800px;
  min-width: 1200px;
  margin: 0 auto;
  padding: 10px var(--gutter);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn 0.6s var(--ease-out);
}

/* ============================================================
   2.  HEADER
   ============================================================ */
.header {
  text-align: center;
  padding: 10px 0 5px;
  animation: slideUp 0.7s var(--ease-out);
}

.header h1 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 2.0rem;
  letter-spacing: 0.04em;
  line-height: 1.2;
  background: var(--gold-gradient);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none; /* clip overrides text-shadow; we use filter instead */
  filter: drop-shadow(0 0 12px rgba(201, 169, 110, 0.30))
          drop-shadow(0 2px 4px  rgba(0, 0, 0, 0.40));
  animation: shimmer 6s linear infinite;
}

.header .subtitle {
  margin-top: 6px;
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* Thin gold ornament line */
.header::after {
  content: '';
  display: block;
  width: 60px;
  height: 1px;
  margin: 12px auto 0;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

/* ============================================================
   3.  AUTH SECTION
   ============================================================ */
.auth-section {
  display: flex;
  justify-content: center;
  padding: 20px 0 40px;
  animation: slideUp 0.8s var(--ease-out);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 36px 32px 32px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: var(--shadow-lg);
}

/* ── Auth Tabs ── */
.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 28px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.auth-tab {
  flex: 1;
  padding: 10px 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--ease);
  letter-spacing: 0.02em;
}

.auth-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.auth-tab.active {
  color: var(--bg-deepest);
  background: var(--gold-gradient);
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(201, 169, 110, 0.25);
}

/* ── Auth Form ── */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gold-light);
  letter-spacing: 0.03em;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  outline: none;
  transition: all var(--ease);
}

.form-group input::placeholder {
  color: var(--text-dim);
}

.form-group input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim), var(--shadow-sm);
}

/* ── Auth Button ── */
.auth-btn {
  width: 100%;
  padding: 13px 0;
  margin-top: 4px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--gold-btn);
  background-size: 200% auto;
  color: var(--bg-deepest);
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all var(--ease);
  box-shadow: 0 2px 12px rgba(201, 169, 110, 0.20);
}

.auth-btn:hover {
  background-position: right center;
  box-shadow: var(--shadow-glow), 0 4px 16px rgba(201, 169, 110, 0.30);
  transform: translateY(-1px);
}

.auth-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 6px rgba(201, 169, 110, 0.15);
}

/* ── Auth Error ── */
.auth-error {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(224, 85, 85, 0.12);
  border: 1px solid rgba(224, 85, 85, 0.25);
  color: #f08080;
  font-size: 0.85rem;
  animation: slideUp 0.3s var(--ease-out);
}

/* ============================================================
   4.  MAIN APP
   ============================================================ */
.main-app {
  display: none;
  animation: fadeIn 0.5s var(--ease-out);
}

.main-app.visible {
  display: block;
}

/* ── User Bar ── */
.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  margin-bottom: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-sm);
  font-size: 0.9rem;
  color: var(--text-muted);
  animation: slideUp 0.5s var(--ease-out);
}

.user-bar .username {
  font-weight: 500;
  color: var(--text-primary);
}

.quota-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 20px;
  background: var(--gold-dim);
  border: 1px solid var(--border-gold);
  color: var(--gold-light);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.quota-badge::before {
  content: '✦';
  font-size: 0.7rem;
  color: var(--gold);
}

.user-bar .logout-btn {
  padding: 6px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--ease);
}

.user-bar .logout-btn:hover {
  border-color: var(--error);
  color: var(--error);
  background: rgba(224, 85, 85, 0.08);
}

/* ============================================================
   5.  UPLOAD SECTION
   ============================================================ */
.upload-section {
  margin-bottom: 40px;
  animation: slideUp 0.6s var(--ease-out) 0.1s both;
}

.upload-zone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  cursor: pointer;
  transition: all var(--ease);
  overflow: hidden;
}

.upload-zone:hover {
  border-color: var(--gold-dim);
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-gold);
}

.upload-zone.dragover {
  border-color: var(--gold);
  border-style: solid;
  background: rgba(201, 169, 110, 0.06);
  box-shadow: var(--shadow-glow);
  animation: glow 1.5s ease-in-out infinite;
}

.upload-zone.has-file {
  border-color: var(--gold-dim);
  border-style: solid;
  height: auto;
  min-height: 200px;
  padding: 24px;
}

.upload-icon {
  font-size: 2.8rem;
  margin-bottom: 12px;
  filter: grayscale(0.3);
  transition: all var(--ease);
}

.upload-zone:hover .upload-icon {
  filter: grayscale(0);
  transform: scale(1.08);
}

.upload-text {
  font-size: 0.95rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}

.upload-text strong {
  color: var(--gold-light);
  font-weight: 500;
}

/* ── Preview ── */
.preview-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: fadeIn 0.4s var(--ease-out);
}

.preview-container img {
  max-height: 300px;
  max-width: 100%;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  object-fit: contain;
}

.remove-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-light);
  border-radius: 50%;
  background: rgba(224, 85, 85, 0.10);
  color: #f08080;
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--ease);
  line-height: 1;
}

.remove-btn:hover {
  background: rgba(224, 85, 85, 0.25);
  border-color: var(--error);
  transform: rotate(90deg) scale(1.1);
}

/* ============================================================
   6.  BACKGROUND SECTION
   ============================================================ */
.background-section {
  margin-bottom: 40px;
  animation: slideUp 0.6s var(--ease-out) 0.2s both;
}

.section-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 22px;
  padding-bottom: 10px;
  position: relative;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 48px;
  height: 2px;
  background: var(--gold-gradient);
  border-radius: 1px;
}

.bg-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.bg-card {
  position: relative;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--ease);
  box-shadow: var(--shadow-sm);
}

.bg-card:hover {
  transform: scale(1.03);
  border-color: var(--border-gold);
  box-shadow: var(--shadow-gold), var(--shadow-md);
}

.bg-card.selected {
  border-color: var(--gold);
  box-shadow: var(--shadow-glow), 0 0 0 1px var(--gold);
}

.bg-card.selected::after {
  content: '✓';
  position: absolute;
  top: 12px;
  right: 12px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gold);
  color: var(--bg-deepest);
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 50%;
  z-index: 2;
  animation: fadeIn 0.25s var(--ease-out);
}

.bg-preview {
  height: 180px;
  transition: all var(--ease);
}

.bg-card:hover .bg-preview {
  filter: brightness(1.08) saturate(1.1);
}

.bg-preview.mountain {
  background: linear-gradient(
    180deg,
    #a8c7c0 0%,
    #7ba6a0 25%,
    #4a7c6f 50%,
    #2d5a4e 70%,
    #1a3a30 100%
  );
}

.bg-preview.ocean {
  background: linear-gradient(
    180deg,
    #f7c59f 0%,
    #e8956a 20%,
    #5b8fbe 45%,
    #3a6d99 70%,
    #1e3d5c 100%
  );
}

.bg-preview.flowers {
  background: linear-gradient(
    180deg,
    #e8b4d0 0%,
    #c77dba 25%,
    #9b59a6 50%,
    #7b3f8e 70%,
    #4a2060 100%
  );
}

.bg-preview.gradient {
  background: linear-gradient(
    to top,
    #2a52be 0%,
    #ffffff 100%
  );
}

.bg-label {
  padding: 14px 16px;
  font-family: var(--font-serif);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  letter-spacing: 0.03em;
}

/* ============================================================
   7.  TEXT SECTION
   ============================================================ */
.text-section {
  margin-bottom: 40px;
  animation: slideUp 0.6s var(--ease-out) 0.3s both;
}

.text-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 14px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: all var(--ease);
  user-select: none;
}

.text-toggle:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
}

.text-toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid var(--border-light);
  position: relative;
  cursor: pointer;
  transition: all var(--ease);
  flex-shrink: 0;
}

.text-toggle input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all var(--ease);
}

.text-toggle input[type="checkbox"]:checked {
  background: var(--gold-dim);
  border-color: var(--gold);
}

.text-toggle input[type="checkbox"]:checked::after {
  left: 22px;
  background: var(--gold);
}

.text-toggle span {
  font-size: 0.92rem;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.02em;
}

.text-fields {
  display: none;
  flex-direction: column;
  gap: 18px;
  margin-top: 18px;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  animation: slideUp 0.35s var(--ease-out);
}

.text-fields.visible {
  display: flex;
}

.text-field-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
}

.text-field-row .form-group {
  flex: 1;
}

/* Reuse form-group input styles from auth */
.text-fields .form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gold-light);
  letter-spacing: 0.03em;
}

.text-fields .form-group input,
.text-fields .form-group select,
.text-fields .form-group textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  outline: none;
  transition: all var(--ease);
}

.text-fields .form-group input:focus,
.text-fields .form-group select:focus,
.text-fields .form-group textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim), var(--shadow-sm);
}

/* ============================================================
   8.  GENERATE SECTION
   ============================================================ */
.generate-section {
  text-align: center;
  margin-bottom: 48px;
  animation: slideUp 0.6s var(--ease-out) 0.35s both;
}

.generate-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 280px;
  padding: 16px 48px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--gold-btn);
  background-size: 200% auto;
  color: var(--bg-deepest);
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all var(--ease);
  box-shadow: 0 4px 20px rgba(201, 169, 110, 0.25);
  position: relative;
  overflow: hidden;
}

.generate-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 35%,
    rgba(255, 255, 255, 0.25) 50%,
    transparent 65%
  );
  background-size: 250% 100%;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.generate-btn:hover {
  background-position: right center;
  box-shadow: var(--shadow-glow), 0 6px 30px rgba(201, 169, 110, 0.35);
  transform: translateY(-2px);
}

.generate-btn:hover::before {
  opacity: 1;
  animation: shimmer 1.8s linear infinite;
}

.generate-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 10px rgba(201, 169, 110, 0.20);
}

.generate-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  filter: grayscale(0.4);
}

.generate-btn:disabled:hover {
  transform: none;
  box-shadow: none;
}

.generate-btn:disabled::before {
  display: none;
}

.generate-btn.loading {
  pointer-events: none;
  animation: pulse 1.8s ease-in-out infinite;
}

.generate-btn.loading::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--bg-deepest);
  border-top-color: transparent;
  border-radius: 50%;
  animation: lotusRotate 0.8s linear infinite;
}

/* ============================================================
   9.  LOADING OVERLAY
   ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 32px;
  background: var(--bg-overlay);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fadeIn 0.4s var(--ease-out);
}

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

/* ── Lotus Loader ── */
.lotus-loader {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  animation: lotusFloat 4s ease-in-out infinite;
}

.lotus-flower {
  position: relative;
  width: 100px;
  height: 100px;
  animation: lotusRotateSlow 20s linear infinite;
}

.lotus-center {
  position: absolute;
  width: 20px;
  height: 20px;
  background: radial-gradient(circle, var(--gold-light) 0%, var(--gold) 70%, transparent 100%);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 20px var(--gold-light), 0 0 40px var(--gold);
  z-index: 10;
}

.lotus-flower .petal {
  position: absolute;
  width: 24px;
  height: 48px;
  /* Lotus petal shape: pointy top, rounded base */
  border-radius: 50% 50% 50% 50% / 80% 80% 20% 20%;
  background: linear-gradient(to top, rgba(201, 169, 110, 0.15), rgba(255, 230, 180, 0.85));
  box-shadow: inset 0 0 6px rgba(255, 255, 255, 0.3), 0 0 12px rgba(201, 169, 110, 0.2);
  top: 50%;
  left: 50%;
  transform-origin: 50% 100%;
  opacity: 0.85;
}

.lotus-flower .petal.outer {
  --scale-min: 0.3;
  --scale-max: 1.0;
  --angle-offset: 0deg;
  animation: petalBloomOuter 4s ease-in-out infinite;
}

.lotus-flower .petal.inner {
  width: 18px;
  height: 38px;
  background: linear-gradient(to top, rgba(201, 169, 110, 0.3), rgba(255, 250, 230, 0.95));
  --scale-min: 0.2;
  --scale-max: 0.85;
  --angle-offset: 22.5deg; /* Offset inner petals to fill the gaps */
  animation: petalBloomInner 4s ease-in-out infinite;
  z-index: 5;
}

@keyframes petalBloomOuter {
  0%, 100% {
    transform: translate(-50%, -100%) rotate(var(--angle)) scale(var(--scale-min));
    opacity: 0.3;
  }
  50% {
    transform: translate(-50%, -100%) rotate(var(--angle)) scale(var(--scale-max)) rotate(5deg);
    opacity: 0.9;
    filter: drop-shadow(0 0 8px rgba(255, 230, 180, 0.5));
  }
}

@keyframes petalBloomInner {
  0%, 100% {
    transform: translate(-50%, -100%) rotate(calc(var(--angle) + var(--angle-offset))) scale(var(--scale-min));
    opacity: 0.2;
  }
  50% {
    transform: translate(-50%, -100%) rotate(calc(var(--angle) + var(--angle-offset))) scale(var(--scale-max)) rotate(-5deg);
    opacity: 0.95;
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.6));
  }
}

@keyframes lotusFloat {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@keyframes lotusRotateSlow {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--gold-light);
  letter-spacing: 0.06em;
  animation: textFade 2.5s ease-in-out infinite;
}

/* ============================================================
   10.  RESULT SECTION
   ============================================================ */
.result-section {
  display: none;
  margin-bottom: 48px;
  animation: slideUp 0.6s var(--ease-out);
}

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

.result-card {
  padding: 28px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.result-image {
  max-width: 100%;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  margin-bottom: 24px;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--gold-btn);
  background-size: 200% auto;
  color: var(--bg-deepest);
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all var(--ease);
  box-shadow: 0 2px 12px rgba(201, 169, 110, 0.20);
}

.download-btn:hover {
  background-position: right center;
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.download-btn:active {
  transform: translateY(0);
}

.retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 32px;
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--gold-light);
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all var(--ease);
}

.retry-btn:hover {
  background: var(--gold-dim);
  border-color: var(--gold);
  box-shadow: var(--shadow-gold);
  transform: translateY(-1px);
}

.retry-btn:active {
  transform: translateY(0);
}

/* ============================================================
   11.  TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  max-width: 400px;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  background: rgba(26, 26, 46, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  font-size: 0.88rem;
  pointer-events: auto;
  animation: slideInRight 0.4s var(--ease-out);
  transition: all var(--ease);
}

.toast::before {
  flex-shrink: 0;
  font-size: 1.1rem;
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.success::before {
  content: '✓';
  color: var(--success);
}

.toast.error {
  border-left: 3px solid var(--error);
}

.toast.error::before {
  content: '✕';
  color: var(--error);
}

.toast.info {
  border-left: 3px solid var(--info);
}

.toast.info::before {
  content: 'ℹ';
  color: var(--info);
}

.toast.fade-out {
  opacity: 0;
  transform: translateX(100px);
}

/* ============================================================
   UTILITY & MISC
   ============================================================ */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Shared card glass mixin ── */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: var(--shadow-md);
}

/* ============================================================
   RESPONSIVE — TABLET (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --gutter: 18px;
  }

  .app-container {
    padding: 28px var(--gutter) 60px;
  }

  .header {
    padding: 36px 0 30px;
  }

  .header h1 {
    font-size: 2rem;
  }

  .header .subtitle {
    font-size: 0.95rem;
  }

  .bg-options {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .bg-preview {
    height: 140px;
  }

  .user-bar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
    font-size: 0.85rem;
  }

  .generate-btn {
    min-width: 240px;
    padding: 14px 36px;
    font-size: 1.05rem;
  }

  .text-field-row {
    flex-direction: column;
    gap: 14px;
  }

  .result-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .download-btn,
  .retry-btn {
    justify-content: center;
  }

  .toast-container {
    top: 12px;
    right: 12px;
    left: 12px;
  }

  .toast {
    min-width: unset;
    max-width: unset;
    width: 100%;
  }
}

/* ============================================================
   RESPONSIVE — MOBILE (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
  :root {
    --gutter: 14px;
  }

  html {
    font-size: 15px;
  }

  .app-container {
    padding: 20px var(--gutter) 48px;
  }

  .header {
    padding: 28px 0 22px;
  }

  .header h1 {
    font-size: 1.65rem;
  }

  .header .subtitle {
    font-size: 0.88rem;
  }

  .header::after {
    width: 60px;
    margin-top: 20px;
  }

  .auth-card {
    padding: 28px 20px 24px;
    border-radius: var(--radius-md);
  }

  .auth-tabs {
    margin-bottom: 22px;
  }

  .auth-tab {
    padding: 9px 0;
    font-size: 0.85rem;
  }

  .form-group input {
    padding: 11px 14px;
    font-size: 0.9rem;
  }

  .upload-zone {
    height: 160px;
    border-radius: var(--radius-md);
  }

  .upload-icon {
    font-size: 2.2rem;
  }

  .upload-text {
    font-size: 0.88rem;
  }

  .preview-container img {
    max-height: 220px;
  }

  .section-title {
    font-size: 1.1rem;
  }

  .bg-preview {
    height: 120px;
  }

  .bg-label {
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  .generate-btn {
    width: 100%;
    min-width: unset;
    padding: 14px 24px;
    font-size: 1rem;
    border-radius: var(--radius-sm);
  }

  .result-card {
    padding: 18px;
    border-radius: var(--radius-md);
  }

  .download-btn,
  .retry-btn {
    padding: 11px 24px;
    font-size: 0.88rem;
    width: 100%;
    justify-content: center;
  }

  .user-bar {
    padding: 10px 14px;
    font-size: 0.82rem;
    border-radius: var(--radius-sm);
  }

  .quota-badge {
    padding: 4px 10px;
    font-size: 0.78rem;
  }

  .text-toggle {
    padding: 12px 16px;
  }

  .text-fields {
    padding: 18px;
  }

  .lotus-spinner {
    width: 64px;
    height: 64px;
  }

  .loading-text {
    font-size: 0.95rem;
  }
}

/* ============================================================
   SPLIT CONTAINER & PREVIEW PANELS
   ============================================================ */
.app-triple-container {
  display: grid;
  grid-template-columns: 380px 380px 1fr; /* Three columns for settings, text option, and preview */
  gap: 24px;
  margin-top: 15px;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 290px); /* Adjusted to accommodate the 120px calligraphy text in the footer */
}

.left-panel,
.middle-panel {
  overflow-y: auto;
  padding-right: 15px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100%;
}

/* Customize scrollbar for left and middle panels */
.left-panel::-webkit-scrollbar,
.middle-panel::-webkit-scrollbar {
  width: 6px;
}
.left-panel::-webkit-scrollbar-track,
.middle-panel::-webkit-scrollbar-track {
  background: transparent;
}
.left-panel::-webkit-scrollbar-thumb,
.middle-panel::-webkit-scrollbar-thumb {
  background: var(--gold-dim);
  border-radius: 3px;
}
.left-panel::-webkit-scrollbar-thumb:hover,
.middle-panel::-webkit-scrollbar-thumb:hover {
  background: var(--gold);
}

.right-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  height: 100%;
  position: relative;
  overflow-y: auto; /* Enable scrollbar if the image details stretch on small screen sizes */
}

.preview-placeholder-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  gap: 15px;
  padding: 40px;
  animation: fadeIn 0.5s ease-out;
}

.preview-placeholder-card .placeholder-icon {
  font-size: 4rem;
  opacity: 0.35;
  filter: grayscale(0.5);
  animation: floatUp 3s ease-in-out infinite;
}

.preview-placeholder-card p {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-muted);
}

.preview-placeholder-card .placeholder-sub {
  font-size: 0.88rem;
  opacity: 0.6;
}

/* Adjust result card to fit beautifully inside the right panel */
.right-panel .result-section {
  width: 100%;
  height: 100%;
  margin-bottom: 0;
  animation: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.right-panel .result-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px;
  margin-top: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.right-panel .result-image-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: calc(100% - 150px); /* Leave plenty of space for text and download buttons */
  min-height: 0; /* Prevents flex content from pushing siblings out of container */
  overflow: hidden;
}

.right-panel .result-image {
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  margin-bottom: 0;
}

.right-panel .result-info {
  margin: 15px 0 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.right-panel .result-actions {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-top: 5px;
}

/* Make background options cleaner for 4 items */
.bg-options {
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 12px !important;
}

.bg-preview {
  height: 110px !important;
}

.bg-label {
  padding: 8px 10px !important;
  font-size: 0.85rem !important;
}

.bg-desc {
  font-size: 0.75rem !important;
  margin-bottom: 8px !important;
}

.upload-zone {
  height: 150px !important;
}

.preview-container img {
  max-height: 130px !important;
}

.generate-section {
  margin-bottom: 15px !important;
}

.footer {
  padding: 10px 0 !important;
}

/* ============================================================
   PRINT (hide interactive elements)
   ============================================================ */
@media print {
  body {
    background: #fff;
    color: #000;
  }

  .auth-section,
  .user-bar,
  .upload-section,
  .background-section,
  .text-section,
  .generate-section,
  .loading-overlay,
  .toast-container {
    display: none !important;
  }

  .result-card {
    box-shadow: none;
    border: 1px solid #ccc;
    background: #fff;
  }

  .result-actions {
    display: none !important;
  }
}

.calligraphy-text {
  font-family: 'DFKai-SB', 'BiauKai', 'KaiTi', 'Noto Serif TC', serif;
  font-size: 16px; /* Size 120px calligraphic text */
  font-weight: 700;
  background: var(--gold-gradient);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 24px;
  text-indent: 24px; /* Offset letter-spacing to center text precisely */
  margin: 10px 0 5px;
  text-align: center;
  line-height: 1.2;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4))
          drop-shadow(0 0 12px rgba(201, 169, 110, 0.2));
  animation: shimmer 6s linear infinite;
  user-select: none;
}

.signature-watermark {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 180px; /* Elegant signature size */
  opacity: 0.15; /* 15% transparency */
  pointer-events: none; /* Prevents blocking clicks or selections */
  user-select: none;
  z-index: 100; /* Stays visible above backgrounds */
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}
