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

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --border: #2a2a4a;
  --accent: #7c6af7;
  --accent2: #e879a0;
  --gold: #f0c060;
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --user-bubble: #2a2060;
  --ai-bubble: #1a2a40;
  --error: #ff6b6b;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  font-family: 'Hiragino Kaku Gothic ProN', 'Yu Gothic', 'メイリオ', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

/* ── Screens ────────────────────────────────────────────────────────────── */
.screen { display: none; height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }

/* ── Setup Screen ───────────────────────────────────────────────────────── */
#setup-screen {
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at 30% 20%, #1a0a3a 0%, var(--bg) 60%);
}

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
}

.setup-title {
  text-align: center;
  margin-bottom: 28px;
}

.setup-title h1 {
  font-size: 1.6rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

.setup-title p {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}

.form-row {
  display: flex;
  gap: 8px;
}

.form-row input, .form-row select { flex: 1; }

input, select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

input[type="number"]::-webkit-inner-spin-button { opacity: 0.5; }

.persona-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.persona-preset {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
  padding: 4px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.persona-preset:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary {
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 1rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: 0.06em;
  margin-top: 8px;
  transition: opacity 0.2s, transform 0.1s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }

/* ── Chat Screen ────────────────────────────────────────────────────────── */
#chat-screen {
  background: var(--bg);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-title {
  flex: 1;
}

.chat-header-title h2 {
  font-size: 1rem;
  font-weight: bold;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#natal-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

#natal-summary span {
  font-size: 0.72rem;
  color: var(--text-dim);
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  cursor: help;
  white-space: nowrap;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-icon:hover { border-color: var(--error); color: var(--error); }

#profile-date {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Messages ───────────────────────────────────────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.message {
  display: flex;
  max-width: 85%;
}

.message.user { align-self: flex-end; justify-content: flex-end; }
.message.assistant { align-self: flex-start; }
.message.error { align-self: flex-start; }

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.7;
  font-size: 0.92rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--user-bubble);
  border: 1px solid #3a2880;
  border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.thinking .bubble {
  color: var(--text-dim);
  font-style: italic;
}

.message.thinking .bubble::after {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s infinite;
}

.message.error .bubble {
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid var(--error);
  color: var(--error);
}

/* 3ステップ鑑定のセクション見出し */
.bubble .section-head {
  display: block;
  margin-top: 14px;
  margin-bottom: 4px;
  font-weight: bold;
  color: var(--gold);
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  border-bottom: 1px solid rgba(240,192,96,0.2);
  padding-bottom: 4px;
}
.bubble .section-head:first-child {
  margin-top: 0;
}

/* ルーター注記（どの占術を使ったか） */
.bubble .route-note {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  font-style: italic;
}

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

/* ── Input area ─────────────────────────────────────────────────────────── */
.chat-input-area {
  padding: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.mood-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

#mood-input {
  font-size: 0.82rem;
  padding: 7px 10px;
}

.persona-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
}

.persona-row label {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
}

#persona-input-chat {
  flex: 1;
  font-size: 0.82rem;
  padding: 6px 10px;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#question-input {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 12px;
  font-size: 0.92rem;
}

.btn-send {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 10px;
  color: #fff;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: opacity 0.2s;
  white-space: nowrap;
  align-self: flex-end;
  height: 44px;
}
.btn-send:hover { opacity: 0.88; }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Quick question chips ───────────────────────────────────────────────── */
.quick-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 0;
}

.quick-q {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
  padding: 5px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.quick-q:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(240, 192, 96, 0.06);
}

/* ── Biorhythm strip ────────────────────────────────────────────────────── */
#biorhythm-strip {
  padding: 8px 14px 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.bio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 22px;
}

.bio-label {
  width: 56px;
  font-size: 0.72rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.bio-track {
  flex: 1;
  height: 5px;
  background: var(--surface2);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}

/* Center zero line */
.bio-track::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  background: var(--border);
  z-index: 1;
}

.bio-fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 3px;
  opacity: 0.85;
  transition: width 0.4s ease, left 0.4s ease;
}

.bio-pct {
  width: 38px;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
  flex-shrink: 0;
}

.bio-status {
  width: 48px;
  font-size: 0.7rem;
  flex-shrink: 0;
}

.bio-days {
  margin-top: 4px;
  font-size: 0.65rem;
  color: var(--text-dim);
  text-align: right;
  opacity: 0.6;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .setup-card { padding: 24px 18px; }
  .message { max-width: 92%; }
  .chat-header { flex-wrap: wrap; }
  #natal-summary { display: none; }
}
