:root {
  --bg: #0e0c10;
  --bg-soft: #18141c;
  --fg: #ece8e1;
  --fg-soft: #b8b0a4;
  --sakura: #f5b7c5;
  --sakura-dim: #c98797;
  --accent: #f0a3b1;
  --error: #ff7e84;
  --border: #2a242f;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Source Han Sans CN", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

/* —— 通用动画 —— */
@keyframes inkIn {
  from { opacity: 0; filter: blur(2px); }
  to   { opacity: 1; filter: blur(0); }
}
@keyframes choiceIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.fade-in { animation: fadeIn 320ms ease both; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(20, 17, 24, 0.85);
  backdrop-filter: blur(8px);
}

.chapter {
  font-size: 14px;
  color: var(--sakura);
  letter-spacing: 0.08em;
  min-width: 120px;
  transition: color 0.4s;
}
.chapter.fade-in { animation: fadeIn 420ms ease both; }
.speaker.fade-in { animation: fadeIn 320ms ease both; }

.progress-track {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--sakura-dim), var(--sakura));
  transition: width 0.6s ease;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 28px clamp(20px, 8vw, 120px);
  overflow-y: auto;
  gap: 14px;
}

.speaker {
  align-self: flex-start;
  font-size: 13px;
  color: var(--sakura);
  background: rgba(245, 183, 197, 0.08);
  border: 1px solid rgba(245, 183, 197, 0.25);
  padding: 2px 12px;
  border-radius: 12px;
  min-height: 22px;
}
.speaker:empty { display: none; }

.narration {
  font-size: 17px;
  line-height: 1.95;
  letter-spacing: 0.02em;
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 26px;
  white-space: pre-wrap;
  min-height: 240px;
  box-shadow: var(--shadow);
}

.narration .ink {
  animation: inkIn 260ms ease-out both;
  display: inline;
}

.narration.is-streaming::after {
  content: "▎";
  color: var(--sakura);
  margin-left: 4px;
  animation: blink 1s infinite;
}
@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

.choice-btn {
  text-align: left;
  font-size: 15px;
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
  font-family: inherit;
  animation: choiceIn 380ms cubic-bezier(.2,.7,.3,1) both;
  animation-delay: var(--stagger, 0ms);
}
.choice-btn:hover:not(:disabled) {
  background: #221c28;
  border-color: var(--sakura-dim);
}
.choice-btn:active:not(:disabled) { transform: translateY(1px); }
.choice-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.choice-btn.is-pivot {
  border-color: var(--sakura);
  box-shadow: 0 0 0 1px rgba(245, 183, 197, 0.18) inset;
}
.choice-btn.is-ending {
  border-color: var(--accent);
  color: var(--accent);
  text-align: center;
}

.error {
  background: rgba(255, 126, 132, 0.1);
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.retry-btn {
  background: var(--error);
  color: #1d0e0f;
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
}

.ending-banner {
  position: fixed;
  inset: auto 0 0 0;
  background: linear-gradient(180deg, rgba(14,12,16,0), rgba(14,12,16,0.95) 40%);
  padding: 48px 20px 32px;
  text-align: center;
  z-index: 10;
}
.ending-banner.fade-in { animation: fadeIn 500ms ease both; }
.ending-title {
  font-size: 22px;
  color: var(--sakura);
  letter-spacing: 0.12em;
  margin-bottom: 16px;
}
.restart {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--sakura);
  border-radius: 24px;
  padding: 10px 28px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.restart:hover { background: rgba(245, 183, 197, 0.12); }

.start-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 7, 10, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
  animation: fadeIn 400ms ease both;
}
.start-card {
  max-width: 560px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  text-align: center;
  animation: choiceIn 480ms cubic-bezier(.2,.7,.3,1) both;
  animation-delay: 80ms;
}
.start-card h1 {
  font-size: 22px;
  color: var(--sakura);
  margin: 0 0 8px;
  line-height: 1.4;
}
.start-card .subtitle {
  color: var(--fg-soft);
  font-size: 14px;
  margin: 0 0 24px;
}
.start-card .tip {
  color: var(--fg-soft);
  font-size: 13px;
  line-height: 1.7;
  margin: 0 0 24px;
}
.start-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.start-actions button {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 22px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
}
.start-actions button.primary {
  background: var(--sakura);
  color: #1d0e13;
  border-color: var(--sakura);
}
.start-actions button:hover { border-color: var(--sakura); }

.profile-panel {
  text-align: left;
  animation: fadeIn 260ms ease both;
}
.profile-progress {
  color: var(--sakura);
  font-size: 12px;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}
.profile-question {
  color: var(--fg);
  font-size: 18px;
  line-height: 1.6;
  margin-bottom: 16px;
}
.profile-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.profile-choice {
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 15px;
  color: var(--fg);
  background: rgba(14, 12, 16, 0.55);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
  animation: choiceIn 340ms cubic-bezier(.2,.7,.3,1) both;
  animation-delay: var(--stagger, 0ms);
}
.profile-choice:hover {
  border-color: var(--sakura-dim);
  background: #221c28;
}

.epilogue {
  max-width: min(860px, calc(100vw - 40px));
  margin: 18px auto 0;
  background: rgba(24, 20, 28, 0.96);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  text-align: left;
  box-shadow: var(--shadow);
}
.epilogue h2 {
  margin: 0 0 10px;
  color: var(--sakura);
  font-size: 15px;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.epilogue-text {
  color: var(--fg);
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
}
.epilogue-actions {
  margin-top: 12px;
}

@media (max-width: 640px) {
  .stage { padding: 16px; }
  .narration { font-size: 16px; padding: 18px; }
  .top-bar { padding: 8px 14px; gap: 10px; }
  .chapter { min-width: auto; }
  .ending-banner {
    max-height: 70vh;
    overflow-y: auto;
  }
  .start-actions { flex-direction: column; }
}
