/* ═══ Astro Book — Dark Mystical Theme ═══ */

:root {
  --bg: #0a0a1a;
  --bg-card: #111128;
  --bg-card-hover: #181840;
  --gold: #c9a84c;
  --gold-dim: #a08030;
  --gold-glow: rgba(201, 168, 76, 0.15);
  --text: #e0ddd5;
  --text-dim: #8a8778;
  --text-bright: #fff;
  --border: #2a2a4a;
  --error: #e74c3c;
  --success: #27ae60;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

/* ═══ Language Switcher ═══ */
.lang-switcher {
  position: absolute;
  top: 1.2rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  z-index: 10;
}
.lang-icon {
  font-size: 1.1rem;
  margin-right: 0.2rem;
}
.lang-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: all 0.2s;
  font-family: inherit;
}
.lang-btn:hover {
  color: var(--gold);
}
.lang-btn.active {
  color: var(--gold);
  border-color: var(--gold);
  background: var(--gold-glow);
}
.lang-sep {
  color: var(--text-dim);
  font-size: 0.85rem;
  user-select: none;
}

/* ═══ Header ═══ */
.header {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.header h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.2rem;
  color: var(--gold);
  letter-spacing: 0.02em;
  margin-bottom: 0.3rem;
}
.header .subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* ═══ Container ═══ */
.container {
  max-width: 780px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

/* ═══ Sections ═══ */
.section { display: none; }
.section.active { display: block; }

/* ═══ Form ═══ */
.form-group {
  margin-bottom: 1.2rem;
}
.form-group label {
  display: block;
  color: var(--gold);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
}
.form-group input, .form-group select {
  width: 100%;
  padding: 0.7rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-glow);
}
.form-group input::placeholder {
  color: var(--text-dim);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}

/* Gender selector */
.gender-select {
  display: flex;
  gap: 0.8rem;
}
.gender-btn {
  flex: 1;
  padding: 0.7rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
}
.gender-btn:hover { border-color: var(--gold-dim); }
.gender-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-glow);
}

/* City autocomplete */
.city-wrapper { position: relative; }
.city-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}
.city-results.show { display: block; }
.city-result {
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.city-result:hover { background: var(--bg-card-hover); }
.city-result:last-child { border-bottom: none; }

/* ═══ Buttons ═══ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.8rem 2rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  color: var(--bg);
  width: 100%;
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--gold-glow);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--gold);
}
.btn-secondary:hover {
  border-color: var(--gold);
  background: var(--gold-glow);
}
.btn-sm {
  padding: 0.5rem 1.2rem;
  font-size: 0.85rem;
}

/* ═══ Chart Summary ═══ */
.chart-summary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.chart-summary h2 {
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--gold);
  font-size: 1.4rem;
  margin-bottom: 1rem;
}
.big-three {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
.big-three-item {
  text-align: center;
  padding: 0.8rem;
  background: rgba(201, 168, 76, 0.05);
  border-radius: 8px;
  border: 1px solid rgba(201, 168, 76, 0.1);
}
.big-three-item .label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.big-three-item .value {
  font-size: 0.95rem;
  color: var(--text-bright);
  margin-top: 0.3rem;
}

.elements-bar {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.8rem;
}
.element-tag {
  padding: 0.3rem 0.7rem;
  border-radius: 20px;
  font-size: 0.8rem;
  background: rgba(201, 168, 76, 0.08);
  border: 1px solid var(--border);
}

/* ═══ Progress Bar ═══ */
.progress-wrap {
  margin-bottom: 1.5rem;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-dim));
  border-radius: 4px;
  transition: width 0.5s ease;
  width: 0%;
}

/* ═══ Chapters ═══ */
.chapter {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 0.8rem;
  overflow: hidden;
  transition: border-color 0.2s;
}
.chapter:hover { border-color: var(--gold-dim); }
.chapter-header {
  padding: 1rem 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  user-select: none;
}
.chapter-emoji { font-size: 1.3rem; }
.chapter-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.95rem;
}
.chapter-status {
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
}
.chapter-status.pending {
  color: var(--text-dim);
  background: rgba(255,255,255,0.05);
}
.chapter-status.loading {
  color: var(--gold);
  background: var(--gold-glow);
  animation: pulse 1.5s infinite;
}
.chapter-status.done {
  color: var(--success);
  background: rgba(39, 174, 96, 0.1);
}
.chapter-chevron {
  color: var(--text-dim);
  transition: transform 0.2s;
  font-size: 0.8rem;
}
.chapter.open .chapter-chevron { transform: rotate(180deg); }
.chapter-body {
  display: none;
  padding: 0 1.2rem 1.2rem;
}
.chapter.open .chapter-body { display: block; }
.chapter-content {
  font-size: 0.95rem;
  line-height: 1.7;
}
.chapter-content h1, .chapter-content h2, .chapter-content h3 {
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--gold);
  margin-top: 1.2em;
  margin-bottom: 0.5em;
}
.chapter-content h1 { font-size: 1.3rem; }
.chapter-content h2 { font-size: 1.15rem; }
.chapter-content h3 { font-size: 1rem; }
.chapter-content p { margin-bottom: 0.8em; }
.chapter-content strong { color: var(--text-bright); }
.chapter-content em { color: var(--gold-dim); }
.chapter-content ul, .chapter-content ol {
  padding-left: 1.5em;
  margin-bottom: 0.8em;
}
.chapter-content li { margin-bottom: 0.3em; }
.chapter-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5em 0;
}
.chapter-content blockquote {
  border-left: 3px solid var(--gold);
  padding-left: 1em;
  color: var(--text-dim);
  font-style: italic;
  margin: 1em 0;
}
.chapter-content code {
  background: rgba(201, 168, 76, 0.1);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

/* ═══ Actions Bar ═══ */
.actions-bar {
  display: flex;
  gap: 0.8rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* ═══ Relocation Section ═══ */
.relocation-prompt {
  background: var(--bg-card);
  border: 1px solid var(--gold-dim);
  border-radius: 12px;
  padding: 1.5rem;
  margin-top: 2rem;
  text-align: center;
}
.relocation-prompt h3 {
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--gold);
  margin-bottom: 0.8rem;
}
.relocation-prompt p {
  color: var(--text-dim);
  margin-bottom: 1rem;
}
.relocation-buttons {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
}

.relocation-form {
  display: none;
  margin-top: 1rem;
}
.relocation-form.show { display: block; }

/* Comparison */
.comparison-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  margin-bottom: 0.8rem;
}
.comparison-item h3 {
  color: var(--gold);
  font-size: 1rem;
  margin-bottom: 0.5rem;
}
.change-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  background: rgba(201, 168, 76, 0.1);
  color: var(--gold);
  margin: 0.2rem;
}

/* ═══ Spinner ═══ */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ═══ Stars background ═══ */
.stars {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: -1;
  background:
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 60% 70%, rgba(255,255,255,0.2), transparent),
    radial-gradient(1px 1px at 80% 20%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 40% 80%, rgba(255,255,255,0.15), transparent),
    radial-gradient(1px 1px at 10% 60%, rgba(255,255,255,0.2), transparent),
    radial-gradient(1.5px 1.5px at 90% 40%, rgba(201,168,76,0.3), transparent),
    radial-gradient(1.5px 1.5px at 50% 50%, rgba(201,168,76,0.2), transparent);
  background-size: 550px 550px;
}

/* ═══ Error ═══ */
.error-msg {
  background: rgba(231, 76, 60, 0.1);
  border: 1px solid var(--error);
  color: var(--error);
  padding: 0.8rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  display: none;
}
.error-msg.show { display: block; }

/* ═══ Loading overlay ═══ */
.loading-overlay {
  display: none;
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
}
.loading-overlay.show { display: block; }
.loading-overlay .spinner { width: 32px; height: 32px; margin-bottom: 1rem; }

/* ═══ Responsive ═══ */
@media (max-width: 600px) {
  .header h1 { font-size: 1.6rem; }
  .big-three { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .container { padding: 1rem 0.8rem; }
  .actions-bar { flex-direction: column; }
  .btn { width: 100%; }
}

/* Edit data button */
.btn-edit-data {
  background: none;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-size: 0.85rem;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  margin-left: 0.75rem;
  vertical-align: middle;
  transition: all 0.2s;
}
.btn-edit-data:hover {
  background: var(--gold);
  color: var(--bg);
}

/* Chapter generation loading */
.generating-indicator {
  text-align: center;
  padding: 3rem 1rem;
}
.generating-indicator p {
  color: #c9a84c;
  font-size: 1.1rem;
  margin-top: 1.5rem;
  font-style: italic;
}
.spinner-large {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(201,168,76,0.2);
  border-top-color: #c9a84c;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto;
}
