:root {
  --bg: #0f1220;
  --bg-elevated: #171b2e;
  --card-bg: #1c2138;
  --text: #eef0fb;
  --text-dim: #9aa0c3;
  --border: #2b3155;
  --accent: #7c8cff;
  --doom: #ff5470;
  --doom-bg: #2a1420;
  --light: #2fd6a7;
  --light-bg: #10281f;
  --dream: #ffd166;
  --dream-bg: #2c2410;
  --radius: 16px;
  --radius-sm: 10px;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 20% 0%, #1b2040 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 24px 14px 60px;
}

#app {
  width: 100%;
  max-width: 640px;
}

.screen {
  animation: fadeIn 0.35s ease;
}

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

h1,
h2,
h3 {
  margin: 0 0 8px;
  line-height: 1.35;
}

p {
  line-height: 1.7;
}

/* ---------- Intro ---------- */
.hero {
  text-align: center;
  margin-bottom: 20px;
}
.hero h1 {
  font-size: 1.6rem;
  margin-top: 10px;
}
.subtitle {
  color: var(--text-dim);
  margin: 0;
}
.lead {
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 24px;
}

.hero-compact {
  margin-bottom: 16px;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 8px 0 0;
}

.privacy-link-wrap {
  text-align: center;
  margin-top: 14px;
}
.privacy-link {
  color: var(--text-dim);
  font-size: 0.78rem;
  text-decoration: underline;
}
.privacy-link:hover {
  color: var(--accent);
}

/* ---------- チャットスレッド ---------- */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-composer {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.chat-composer textarea {
  width: 100%;
  resize: vertical;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
}
.chat-composer textarea:focus {
  outline: 2px solid var(--accent);
}
.chat-composer .btn-start {
  margin-top: 12px;
}

.chat-bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.6;
  font-size: 0.95rem;
  animation: fadeIn 0.25s ease;
  white-space: pre-wrap;
}
.chat-bot {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}
.chat-user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), #5b6bff);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: chatTypingBounce 1.1s ease-in-out infinite;
}
.chat-typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.chat-typing span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes chatTypingBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}
@media (prefers-reduced-motion: reduce) {
  .chat-typing span {
    animation: none;
    opacity: 0.8;
  }
}

.chat-options {
  align-self: flex-start;
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chat-option-btn {
  padding: 10px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  font-size: 0.9rem;
}
.chat-option-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg-elevated);
}
.chat-option-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--accent), #5b6bff);
  color: #fff;
  font-weight: 700;
  border: none;
  box-shadow: 0 8px 24px -8px rgba(124, 140, 255, 0.6);
}
.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  display: block;
  margin: 20px auto 0;
  padding: 10px 18px;
  background: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover {
  color: var(--text);
  border-color: var(--accent);
}

.options {
  display: grid;
  gap: 10px;
  margin-bottom: 8px;
}
.options-vertical {
  grid-template-columns: 1fr;
}
.options-grid {
  grid-template-columns: repeat(2, 1fr);
}

.btn-option {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 14px 16px;
  background: var(--bg-elevated);
  color: var(--text);
}
.btn-option:hover {
  border-color: var(--accent);
  background: var(--card-bg);
}
.opt-key {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}
.opt-label {
  flex: 1;
}

.btn-genre {
  padding: 20px 10px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
}
.btn-genre:hover {
  border-color: var(--accent);
  background: var(--card-bg);
}

/* ---------- Progress ---------- */
.progress-track {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 24px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--light));
  transition: width 0.3s ease;
}

.q-badge {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  margin-bottom: 10px;
}
.q-text {
  font-size: 1.2rem;
  margin-bottom: 20px;
}

/* ---------- Result ---------- */
.result-header {
  text-align: center;
  padding: 24px 16px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  margin-bottom: 28px;
}
.sev-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  margin-bottom: 10px;
}
.result-header.sev-3 .sev-badge {
  background: #cbd5e1;
  color: #1a1a1a;
}
.result-genre {
  color: var(--text-dim);
  font-size: 0.9rem;
}
.result-title {
  font-size: 1.4rem;
  margin-top: 4px;
}
.free-echo {
  margin-top: 14px;
  font-style: italic;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.route-section {
  margin-bottom: 28px;
}
.route-heading {
  font-size: 1rem;
  margin-bottom: 12px;
  padding-left: 4px;
}
.route-doom .route-heading {
  color: var(--doom);
}
.route-light .route-heading {
  color: var(--light);
}
.route-dream .route-heading {
  color: var(--dream);
  font-weight: 800;
  letter-spacing: 0.5px;
  text-shadow: 0 0 14px rgba(255, 209, 102, 0.55);
}
.route-dream .route-heading::after {
  content: "✨";
  display: inline-block;
  margin-left: 6px;
  animation: dreamTwinkle 2s ease-in-out infinite;
}

.route-accordion-toggle {
  all: unset;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  box-sizing: border-box;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: inherit;
  font: inherit;
  font-weight: inherit;
  cursor: pointer;
}
.route-accordion-toggle:hover {
  border-color: currentColor;
}
.route-accordion-toggle .chevron {
  transition: transform 0.2s ease;
  font-size: 0.85em;
}
.route-accordion-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.card-list {
  display: grid;
  gap: 14px;
  margin-top: 12px;
}
.card-list.is-collapsed {
  display: none;
}

.route-card {
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  background: var(--card-bg);
}
.route-doom .route-card {
  border-color: #4a1f2c;
  background: var(--doom-bg);
}
.route-light .route-card {
  border-color: #16493a;
  background: var(--light-bg);
}

/* 夢ルート: キラキラ演出（グラデーション枠・シマー・スパークル） */
.route-dream .route-card {
  position: relative;
  overflow: hidden;
  padding: 18px 16px;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) + 2px);
  background: linear-gradient(var(--dream-bg), var(--dream-bg)) padding-box, linear-gradient(135deg, #ffd166, #ff8fd6, #a78bfa, #ffd166) border-box;
  background-size:
    100% 100%,
    300% 300%;
  animation: dreamBorderShift 6s ease infinite;
  box-shadow: 0 10px 32px -12px rgba(255, 209, 102, 0.45);
}
.route-dream .route-card::before {
  content: "";
  position: absolute;
  top: -60%;
  left: -60%;
  width: 45%;
  height: 220%;
  background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  transform: rotate(20deg);
  animation: dreamShine 3.4s ease-in-out infinite;
  pointer-events: none;
}
.route-dream .route-card::after {
  content: "✨";
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 1rem;
  animation: dreamTwinkle 2.4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes dreamBorderShift {
  0%,
  100% {
    background-position: 0% 0%, 0% 50%;
  }
  50% {
    background-position: 0% 0%, 100% 50%;
  }
}
@keyframes dreamShine {
  0% {
    left: -60%;
  }
  55% {
    left: 130%;
  }
  100% {
    left: 130%;
  }
}
@keyframes dreamTwinkle {
  0%,
  100% {
    opacity: 0.3;
    transform: scale(0.85) rotate(0deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.2) rotate(15deg);
  }
}
@keyframes dreamBounce {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-3px) rotate(10deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .route-dream .route-card,
  .route-dream .route-card::before,
  .route-dream .route-card::after,
  .route-dream .route-heading::after,
  .route-dream .route-card-title,
  .route-dream .route-card-icon {
    animation: none !important;
  }
}

.route-card.reduced {
  background: var(--card-bg);
  border-color: var(--border);
}

.route-card-title {
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.route-dream .route-card-title {
  position: relative;
  font-weight: 800;
  font-size: 1.02rem;
  background: linear-gradient(90deg, #ffd166, #ff8fd6, #a78bfa, #ffd166);
  background-size: 300% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: dreamTextShine 5s linear infinite;
}
@keyframes dreamTextShine {
  to {
    background-position: 300% center;
  }
}
.route-card-icon {
  font-size: 1rem;
}
.route-dream .route-card-icon {
  display: inline-block;
  animation: dreamBounce 1.8s ease-in-out infinite;
}
.route-dream .stat-value {
  color: var(--dream);
}

.route-action {
  font-weight: 700;
  font-size: 0.92rem;
  padding: 8px 10px;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  border-left: 3px solid var(--border);
}
.route-doom .route-action {
  border-left-color: var(--doom);
}
.route-light .route-action {
  border-left-color: var(--light);
}
.route-dream .route-action {
  border-left-color: var(--dream);
}
.route-plan .route-action {
  border-left-color: var(--accent);
}

.stats-block {
  background: rgba(0, 0, 0, 0.18);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
  padding: 4px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
}
.stat-row:last-child {
  border-bottom: none;
}
.stat-label {
  color: var(--text-dim);
}
.stat-value {
  font-weight: 700;
  text-align: right;
}
.stat-plain {
  display: block;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.narrative {
  font-size: 0.92rem;
  color: var(--text);
}
.narrative-line {
  margin: 0 0 6px;
}
.narrative-line:last-child {
  margin-bottom: 0;
}

/* ---------- リンクチップ（光ルート等・リンク配置方針に基づく） ---------- */
.route-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 12px;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
  border: 1px solid var(--border);
}
.route-link-affiliate {
  color: var(--dream);
  background: rgba(255, 209, 102, 0.1);
  border-color: rgba(255, 209, 102, 0.35);
}
.route-link-affiliate:hover {
  background: rgba(255, 209, 102, 0.2);
}
.route-link-public {
  color: var(--light);
  background: rgba(47, 214, 167, 0.1);
  border-color: rgba(47, 214, 167, 0.35);
}
.route-link-public:hover {
  background: rgba(47, 214, 167, 0.2);
}
.route-link-pending {
  color: var(--text-dim);
  background: transparent;
  cursor: default;
  opacity: 0.7;
}
.pr-tag {
  font-size: 0.6rem;
  font-weight: 800;
  background: var(--dream);
  color: #2c2410;
  border-radius: 4px;
  padding: 1px 4px;
  letter-spacing: 0.5px;
}

/* ---------- コピー・シェア ---------- */
.share-actions {
  text-align: center;
  margin-bottom: 8px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  position: relative;
}
.btn-share-action {
  padding: 10px 16px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
}
.btn-share-action:hover {
  border-color: var(--accent);
  background: var(--card-bg);
}
.copy-toast {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: var(--light);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
}
.copy-toast.show {
  opacity: 1;
}

.result-actions {
  text-align: center;
}

/* Lv3以上: 装飾抑制 */
.screen-result.reduced .route-card {
  border-radius: var(--radius-sm);
}
.screen-result.reduced .stats-block {
  background: rgba(255, 255, 255, 0.03);
}

/* ---------- AI判定中ローディング ---------- */
.loading-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 60px 0;
}
.loading-spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: loadingSpin 0.9s linear infinite;
}
@keyframes loadingSpin {
  to {
    transform: rotate(360deg);
  }
}
.loading-text {
  color: var(--text-dim);
  font-size: 0.95rem;
}
@media (prefers-reduced-motion: reduce) {
  .loading-spinner {
    animation: none;
    border-top-color: var(--border);
  }
}

/* ---------- Crisis / Info screens ---------- */
.screen-crisis,
.screen-info,
.screen-reference {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
}

.crisis-intro p {
  text-align: center;
  margin: 0 0 4px;
  font-size: 1.05rem;
}
.crisis-intro {
  margin-bottom: 24px;
}

.contacts-list {
  display: grid;
  gap: 12px;
  margin-bottom: 20px;
}

.contact-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.contact-name {
  font-weight: 700;
  margin-bottom: 4px;
}
.contact-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--light);
  letter-spacing: 0.5px;
}
.contact-note {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 4px;
  white-space: pre-line;
}

.minor-note {
  margin-bottom: 8px;
}
.minor-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-weight: 700;
}

.reference-link {
  text-align: center;
  margin-top: 8px;
}
.ref-link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.78rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 6px;
}
.ref-link-btn:hover {
  color: var(--accent);
}

/* ---------- Responsive ---------- */
@media (max-width: 420px) {
  .options-grid {
    grid-template-columns: 1fr;
  }
  .hero h1 {
    font-size: 1.35rem;
  }
}
