/* ===== CSS Variables ===== */
:root {
  --bg: #0d1117;
  --card: #161b22;
  --border: #30363d;
  --text: #c9d1d9;
  --text-muted: #8b949e;
  --gold: #d29922;
  --gold-hover: #e3b341;
  --green: #7ee787;
  --red: #f85149;
  --radius: 12px;
  --font-serif: "Noto Serif SC", "Songti SC", "SimSun", "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

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

/* ===== Page System ===== */
.page { display: none; min-height: 100vh; }
.page.active { display: block; }

.hidden { display: none !important; }

/* ===== Scene Select Page ===== */
.select-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px;
}

.select-header { text-align: center; margin-bottom: 48px; }

.main-title {
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 2px;
  text-shadow: 0 0 30px rgba(210, 153, 34, 0.3);
}

.subtitle {
  margin-top: 12px;
  font-size: 1.05rem;
  color: var(--text-muted);
}

.scene-category {
  font-size: 0.9rem;
  color: var(--gold);
  margin: 24px 0 12px;
  padding-left: 12px;
  border-left: 3px solid var(--gold);
  font-weight: 600;
}

.scene-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.scene-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.scene-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.scene-card:hover {
  border-color: var(--gold);
  transform: translateY(-4px);
  box-shadow: 0 8px 32px rgba(210, 153, 34, 0.12);
}

.scene-card:hover::before { opacity: 1; }

.scene-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  display: block;
}

.scene-card-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 8px;
}

.scene-card-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ===== Saves Section ===== */
.saves-section { margin-top: 48px; }

.section-title {
  font-size: 1.2rem;
  color: var(--text);
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.saves-list { display: flex; flex-direction: column; gap: 12px; }

.save-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 20px;
  transition: border-color 0.2s;
}

.save-item:hover { border-color: var(--green); }

.save-info { flex: 1; }

.save-item-title {
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
}

.save-item-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.btn-load-save {
  background: transparent;
  border: 1px solid var(--green);
  color: var(--green);
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.btn-load-save:hover {
  background: var(--green);
  color: var(--bg);
}

/* ===== Game Page ===== */
.game-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 24px 48px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.game-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.story-title {
  flex: 1;
  font-size: 1.4rem;
  color: var(--gold);
  font-weight: 600;
}

.header-actions { display: flex; gap: 8px; }

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-icon:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.btn-action {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-action:hover {
  border-color: var(--gold);
  color: var(--gold);
}

/* ===== Story History ===== */
.story-history {
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 20px;
  padding-right: 8px;
}

.story-history::-webkit-scrollbar { width: 4px; }
.story-history::-webkit-scrollbar-track { background: transparent; }
.story-history::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.history-passage {
  font-family: var(--font-serif);
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.8;
  padding: 12px 16px;
  border-left: 2px solid var(--border);
  margin-bottom: 12px;
  white-space: pre-wrap;
}

/* ===== Current Passage ===== */
.current-passage {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 24px;
  flex: 1;
}

.passage-text {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 2;
  color: var(--text);
  white-space: pre-wrap;
  min-height: 60px;
}

.passage-text .cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--gold);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s infinite;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* ===== Choices ===== */
.choices-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.choice-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 16px 24px;
  font-size: 1rem;
  font-family: var(--font-sans);
  text-align: left;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  padding-left: 48px;
}

.choice-btn::before {
  content: '▶';
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gold);
  font-size: 0.75rem;
  opacity: 0.6;
  transition: all 0.25s;
}

.choice-btn:hover {
  border-color: var(--gold);
  background: rgba(210, 153, 34, 0.06);
  transform: translateX(4px);
}

.choice-btn:hover::before {
  opacity: 1;
  left: 24px;
}

.choice-btn:active { transform: translateX(2px); }

.choice-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ===== Loading Indicator ===== */
.loading-indicator {
  text-align: center;
  padding: 24px;
  color: var(--gold);
  font-size: 1rem;
  letter-spacing: 1px;
}

.loading-dots { font-weight: 600; }

.dots-anim::after {
  content: '';
  animation: dots 1.5s infinite;
}

@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ===== Loading Text ===== */
.loading-text {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
  font-size: 1rem;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 460px;
  max-height: 70vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  color: var(--gold);
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.modal-close:hover {
  color: var(--red);
  background: rgba(248, 81, 73, 0.1);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

/* ===== Save Slot ===== */
.save-slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.save-slot:hover {
  border-color: var(--gold);
  background: rgba(210, 153, 34, 0.04);
}

.save-slot-info { flex: 1; }

.save-slot-label {
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
}

.save-slot-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.save-slot-empty {
  color: var(--text-muted);
  font-style: italic;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--green);
  color: var(--green);
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 2000;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.3s ease;
}

.toast.error {
  border-color: var(--red);
  color: var(--red);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .main-title { font-size: 2rem; }
  .select-container { padding: 32px 16px; }
  .scene-grid { grid-template-columns: 1fr; }
  .game-container { padding: 16px; }
  .current-passage { padding: 20px; }
  .passage-text { font-size: 0.95rem; }
  .game-header { flex-wrap: wrap; gap: 8px; }
  .story-title { font-size: 1.1rem; order: -1; flex-basis: 100%; }
}
