:root {
  --bg: #f5f0e8;
  --bg-card: #fffdf9;
  --text: #2c2416;
  --text-muted: #6b5d4a;
  --accent: #8b7355;
  --accent-soft: #c4b5a0;
  --border: #e5ddd0;
  --primary: #7d6b4f;
  --primary-hover: #6b5a42;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(44, 36, 22, 0.06);
  --font-serif: "Noto Serif SC", "Source Han Serif CN", serif;
  --font-sans: "Zen Kaku Gothic New", "PingFang SC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  min-height: 100vh;
}

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

.header {
  position: relative;
}

.header-links {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 1rem;
}

.nav-link {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
}

.header-links .nav-link {
  position: static;
  transform: none;
}

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

.header h1 {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0 0 0.25rem 0;
  color: var(--text);
}

.tagline {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0;
}

.section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.section.hidden {
  display: none;
}

.section h2 {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 500;
  margin: 0 0 1.25rem 0;
  color: var(--text);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-row label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.form-row input[type="date"],
.form-row input[type="time"],
.form-row input[type="text"] {
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}

.form-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-row input[type="checkbox"] {
  margin-right: 0.5rem;
  accent-color: var(--primary);
}

.btn {
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

/* Map picker */
.map-picker {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.map-search-row {
  display: flex;
  gap: 0.5rem;
}

.map-search-row input {
  flex: 1;
}

.map-container {
  height: 240px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.map-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

.selected-place {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text);
}

.selected-place.hidden {
  display: none;
}

.btn-clear {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}

.btn-clear:hover {
  color: var(--text);
}

/* Chart summary */
.chart-summary {
  background: var(--bg);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  max-height: 180px;
  overflow-y: auto;
}

.chart-summary .planet-row {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border);
}

.chart-summary .planet-row:last-child {
  border-bottom: none;
}

.chart-summary .retrograde {
  color: var(--accent);
  font-size: 0.8rem;
}

/* Chat */
.chat-container {
  margin-bottom: 1rem;
}

.messages {
  min-height: 200px;
  max-height: 360px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.message {
  padding: 1rem 1.25rem;
  border-radius: 10px;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  line-height: 1.7;
}

.message.user {
  background: var(--bg);
  color: var(--text);
  margin-left: 0;
  margin-right: 2rem;
}

.message.assistant {
  background: linear-gradient(135deg, #f0ebe3 0%, #e8e2d8 100%);
  border: 1px solid var(--border);
  margin-left: 2rem;
  margin-right: 0;
  white-space: pre-wrap;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.chat-form input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg-card);
}

.chat-form input:focus {
  outline: none;
  border-color: var(--accent);
}

#back-btn {
  width: 100%;
  margin-top: 0.5rem;
}

/* Loading */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(245, 240, 232, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 100;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Responsive */
@media (max-width: 480px) {
  .app {
    padding: 1.25rem 1rem;
  }

  .message.user {
    margin-right: 1rem;
  }

  .message.assistant {
    margin-left: 1rem;
  }
}
