/* ===== 八卦故事分析 - 全局样式 ===== */

:root {
  --bg-primary: #0f0f1a;
  --bg-card: #1a1a2e;
  --color-primary: #e94560;
  --color-secondary: #16213e;
  --color-accent: #0f3460;
  --color-text: #eeeeee;
  --color-text-muted: #8888aa;
  --color-success: #4ecca3;
  --color-warning: #f0a500;
  --color-danger: #e94560;
  --color-border: #2a2a4a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Navbar ===== */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--color-secondary);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar .logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.navbar .logo span { font-size: 1.6rem; }
.navbar nav { display: flex; gap: 20px; align-items: center; }
.navbar nav a { color: var(--color-text-muted); font-size: 0.95rem; transition: color 0.2s; }
.navbar nav a:hover { color: var(--color-primary); text-decoration: none; }

/* ===== Container ===== */
.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: #d63350; transform: translateY(-1px); }
.btn-secondary { background: var(--color-accent); color: #fff; }
.btn-secondary:hover { background: #1a4a8a; }
.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
}
.btn-outline:hover { background: var(--color-primary); color: #fff; }
.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { color: var(--color-text); background: rgba(255,255,255,0.05); }
.btn-danger { background: #c0392b; color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }

/* ===== Forms ===== */
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  font-weight: 500;
}
.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 1rem;
  font-family: var(--font);
  transition: border-color 0.2s;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none;
  border-color: var(--color-primary);
}
.form-textarea { resize: vertical; min-height: 200px; line-height: 1.7; }
.form-error { color: var(--color-danger); font-size: 0.85rem; margin-top: 4px; }

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card-clickable { cursor: pointer; }

/* ===== Hero (首页) ===== */
.hero {
  text-align: center;
  padding: 80px 20px 60px;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--color-secondary) 50%, #1a0a2e 100%);
}
.hero h1 {
  font-size: 2.8rem;
  margin-bottom: 16px;
  background: linear-gradient(90deg, var(--color-primary), #ff6b8a);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero p { font-size: 1.15rem; color: var(--color-text-muted); max-width: 600px; margin: 0 auto 32px; }
.hero .actions { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }

/* ===== Story Cards Grid ===== */
.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}
.story-card { display: flex; flex-direction: column; }
.story-card .story-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}
.story-card h3 { font-size: 1.1rem; margin-bottom: 8px; }
.story-card .story-preview {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* ===== Status Badge ===== */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-pending { background: rgba(240,165,0,0.15); color: var(--color-warning); }
.badge-analyzing { background: rgba(233,69,96,0.15); color: var(--color-primary); }
.badge-completed { background: rgba(78,204,163,0.15); color: var(--color-success); }

/* ===== Auth Pages ===== */
.auth-container {
  max-width: 420px;
  margin: 80px auto;
  padding: 0 20px;
}
.auth-card { padding: 40px; }
.auth-card h2 { text-align: center; margin-bottom: 8px; font-size: 1.6rem; }
.auth-card .subtitle { text-align: center; color: var(--color-text-muted); margin-bottom: 32px; font-size: 0.9rem; }

/* ===== Story Detail ===== */
.story-header { margin-bottom: 32px; }
.story-header h1 { font-size: 2rem; margin-bottom: 12px; }
.story-content {
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 32px;
  white-space: pre-wrap;
  line-height: 1.8;
  max-height: 300px;
  overflow-y: auto;
}

/* ===== Analysis Section ===== */
.analysis-section { margin-bottom: 32px; }
.analysis-section h2 {
  font-size: 1.3rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.analysis-section h2::before {
  content: '';
  width: 4px;
  height: 20px;
  background: var(--color-primary);
  border-radius: 2px;
  display: inline-block;
}

/* ===== Progress Bar ===== */
.progress-bar-wrapper {
  background: var(--bg-primary);
  border-radius: 20px;
  overflow: hidden;
  height: 8px;
  margin: 16px 0 8px;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), #ff6b8a);
  border-radius: 20px;
  transition: width 0.3s;
  width: 0%;
}
.progress-text { font-size: 0.85rem; color: var(--color-text-muted); }

/* ===== Character Cards ===== */
.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.character-card {
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.character-card .avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
}
.character-card h4 { font-size: 1rem; margin-bottom: 4px; }
.character-card p { font-size: 0.85rem; color: var(--color-text-muted); }

/* ===== Relationship List ===== */
.relation-list { list-style: none; }
.relation-item {
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.relation-item .from, .relation-item .to {
  font-weight: 600;
  color: var(--color-primary);
}
.relation-item .label { color: var(--color-text-muted); flex: 1; }

/* ===== Timeline ===== */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-border);
}
.timeline-item {
  position: relative;
  margin-bottom: 24px;
  padding-left: 20px;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -24px;
  top: 6px;
  width: 12px;
  height: 12px;
  background: var(--color-primary);
  border-radius: 50%;
  border: 2px solid var(--bg-primary);
}
.timeline-item .time { font-size: 0.85rem; color: var(--color-text-muted); margin-bottom: 4px; }
.timeline-item .event { font-size: 0.95rem; }

/* ===== Section Title ===== */
.section-title {
  font-size: 1.8rem;
  text-align: center;
  margin-bottom: 12px;
}
.section-subtitle {
  text-align: center;
  color: var(--color-text-muted);
  margin-bottom: 40px;
}

/* ===== Features ===== */
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; padding: 0 20px 60px; max-width: 1000px; margin: 0 auto; }
.feature-card { text-align: center; padding: 32px 20px; }
.feature-icon { font-size: 2.5rem; margin-bottom: 16px; }
.feature-card h3 { margin-bottom: 8px; font-size: 1.1rem; }
.feature-card p { font-size: 0.9rem; color: var(--color-text-muted); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-muted);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state p { margin-bottom: 20px; }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  animation: slideIn 0.3s;
  max-width: 360px;
}
.toast-success { background: var(--color-success); color: #0f0f1a; }
.toast-error { background: var(--color-danger); color: #fff; }
.toast-info { background: var(--color-accent); color: #fff; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== Public Stories (首页) ===== */
.public-section { padding: 40px 20px; max-width: 1000px; margin: 0 auto; }

/* ===== Story Card Enhancements ===== */
.story-card .story-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}
.story-card .story-author {
  display: flex;
  align-items: center;
  gap: 6px;
}
.story-card .story-author .author-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-accent), var(--color-primary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
}
.story-card .story-stats {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===== Visibility Badge ===== */
.badge-public {
  background: rgba(78,204,163,0.15);
  color: var(--color-success);
}
.badge-private {
  background: rgba(136,136,170,0.15);
  color: var(--color-text-muted);
}

/* ===== Toggle Switch ===== */
.toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.toggle-wrapper label {
  margin-bottom: 0;
  cursor: pointer;
}
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--color-border);
  border-radius: 26px;
  transition: 0.3s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.3s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--color-success);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
}
.toggle-hint {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* ===== Public Story Header ===== */
.public-author-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(78,204,163,0.1);
  border: 1px solid rgba(78,204,163,0.2);
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--color-success);
}
.public-author-info .author-avatar-sm {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-success), var(--color-accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  color: #fff;
}

/* ===== Visibility Toggle in Dashboard ===== */
.visibility-toggle {
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.visibility-toggle:hover {
  border-color: var(--color-success);
  color: var(--color-success);
}
.visibility-toggle.is-public {
  border-color: var(--color-success);
  color: var(--color-success);
  background: rgba(78,204,163,0.08);
}

/* ===== Page Header ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 16px;
}
.page-header h1 { font-size: 1.8rem; }


/* ===== Visualization Tabs ===== */
.visualization-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 4px;
  width: fit-content;
  border: 1px solid var(--color-border);
}
.viz-tab {
  padding: 8px 20px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}
.viz-tab:hover {
  color: var(--color-text);
  background: rgba(255,255,255,0.05);
}
.viz-tab.active {
  background: var(--color-primary);
  color: #fff;
}

/* ===== Graph Detail Card ===== */
.graph-detail-card {
  position: absolute;
  z-index: 50;
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 240px;
  max-width: 320px;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  animation: fadeIn 0.2s ease;
}
.graph-detail-card h4 {
  font-size: 1rem;
  margin-bottom: 4px;
}
.graph-detail-card h5 {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.detail-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.detail-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.15s;
}
.detail-close:hover {
  color: var(--color-text);
  background: rgba(255,255,255,0.1);
}
.detail-desc {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}
.detail-meta span {
  background: rgba(255,255,255,0.05);
  padding: 2px 8px;
  border-radius: 4px;
}
.detail-rels {
  max-height: 160px;
  overflow-y: auto;
}
.detail-rel {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.8rem;
}
.rel-direction {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}
.rel-name {
  color: var(--color-text);
  font-weight: 600;
}
.rel-type {
  font-weight: 600;
  font-size: 0.75rem;
}
.rel-conf {
  margin-left: auto;
  color: var(--color-text-muted);
  font-size: 0.75rem;
}
.detail-no-rel {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}
.detail-evidence {
  margin-top: 8px;
}
.detail-evidence p {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  line-height: 1.5;
  background: rgba(255,255,255,0.03);
  padding: 8px;
  border-radius: 6px;
  max-height: 100px;
  overflow-y: auto;
}

/* ===== Graph Link Tooltip ===== */
.graph-link-tooltip {
  position: absolute;
  z-index: 40;
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.8rem;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}

/* ===== Graph Empty State ===== */
.graph-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

/* ===== Graph SVG Interactions ===== */
.graph-node {
  cursor: grab;
  transition: opacity 0.2s;
}
.graph-node:active {
  cursor: grabbing;
}
.graph-link {
  cursor: pointer;
  transition: stroke-opacity 0.2s, stroke-width 0.2s;
}

/* ===== World Tree ===== */
.tree-node { cursor: pointer; }
.tree-link { transition: stroke-opacity 0.2s; }
.tree-tooltip {
  position: absolute;
  z-index: 60;
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  max-width: 280px;
  line-height: 1.5;
  animation: fadeIn 0.15s ease;
}

/* ===== D3 Timeline ===== */
.timeline-event { transition: opacity 0.2s; }
.timeline-event:hover { opacity: 0.85; }

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

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .navbar { padding: 12px 16px; }
  .navbar .logo { font-size: 1.1rem; }
  .hero h1 { font-size: 2rem; }
  .hero p { font-size: 1rem; }
  .container { padding: 16px 12px; }
  .story-grid { grid-template-columns: 1fr; }
  .character-grid { grid-template-columns: 1fr 1fr; }
  .auth-container { margin: 40px auto; }
  .auth-card { padding: 24px; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 480px) {
  .character-grid { grid-template-columns: 1fr; }
  .hero .actions { flex-direction: column; align-items: center; }
}
