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

:root {
  --bg-deep: #0d0d1a;
  --bg-surface: #12122a;
  --bg-card: #1a1a2e;
  --bg-hover: #222244;
  --gold: #c4a86a;
  --gold-dim: #c4a86a44;
  --gold-text: #e8d8a0;
  --text-primary: #e8e0d0;
  --text-secondary: #b4b2a9;
  --text-muted: #5f5e5a;
  --border-color: #2a2a4e;
  --teal: #5dcaa5;
  --blue: #85b7eb;
  --coral: #f0997b;
  --danger: #e24b4a;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Noto Serif CJK SC', 'Source Han Serif SC', 'Songti SC', Georgia, serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; justify-content: center; }

#app {
  width: 100%;
  max-width: 800px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-left: 0.5px solid var(--border-color);
  border-right: 0.5px solid var(--border-color);
}

/* ===== Top Bar ===== */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 0.5px solid var(--border-color);
  flex-wrap: wrap;
  gap: 8px;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }

.epoch-badge {
  font-size: 12px;
  font-weight: 500;
  color: var(--gold);
  border: 0.5px solid var(--gold-dim);
  padding: 2px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.year-display {
  font-size: 22px;
  font-weight: 500;
  color: var(--gold-text);
  font-family: 'Noto Serif CJK SC', 'Songti SC', Georgia, serif;
  letter-spacing: 2px;
}

.topbar-right { display: flex; gap: 14px; align-items: center; }

.stat {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 3px;
}
.stat strong { color: var(--text-secondary); font-weight: 500; }
.stat-icon { font-size: 10px; }
.stat.online strong { color: var(--teal); }

/* ===== Mobile Tabs ===== */
#mobileTabs {
  display: none;
  border-bottom: 0.5px solid var(--border-color);
  background: #16162a;
}

.tab {
  flex: 1;
  text-align: center;
  padding: 10px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.2s, border-color 0.2s;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }
.tab:active { opacity: 0.7; }

/* ===== Main Content ===== */
#mainContent { flex: 1; overflow-y: auto; }

.panel { display: none; padding: 16px 20px; }
.panel.active { display: block; }

.panel-header {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.panel-subheader {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin: 12px 0 8px;
}

/* ===== Timeline ===== */
#timeline { margin-bottom: 12px; }

.timeline-entry {
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
  animation: fadeIn 0.4s ease;
}

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

@keyframes highlightPulse {
  0% { background: var(--gold-dim); }
  100% { background: transparent; }
}

.timeline-entry.new {
  animation: fadeIn 0.4s ease, highlightPulse 2s ease 0.4s;
}

.timeline-dot {
  width: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}
.timeline-dot::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  margin-top: 5px;
}
.timeline-dot::after {
  content: '';
  width: 1px;
  flex: 1;
  background: var(--border-color);
  min-height: 24px;
}

.timeline-entry:last-child .timeline-dot::after { display: none; }
.timeline-entry.future .timeline-dot::before { background: var(--text-muted); }
.timeline-entry.npc .timeline-dot::before { background: var(--blue); }
.timeline-entry.player .timeline-dot::before { background: var(--gold); }
.timeline-entry.event .timeline-dot::before { background: var(--coral); }
.timeline-entry.milestone .timeline-dot::before { background: var(--teal); width: 9px; height: 9px; }

.timeline-body { padding-bottom: 10px; flex: 1; min-width: 0; }

.timeline-year {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 1px;
}

.timeline-text {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
  word-break: break-word;
}
.timeline-text.muted { color: var(--text-muted); font-style: italic; }
.timeline-text .creator-tag {
  font-size: 11px;
  color: var(--gold);
  margin-left: 4px;
}
.timeline-text .epoch-transition-highlight {
  color: var(--gold-text);
  font-weight: 500;
}

/* ===== Suggestion Box ===== */
.suggestion-box {
  margin: 8px 0 4px;
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 0.5px solid var(--gold-dim);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: fadeIn 0.4s ease;
}

.suggestion-icon { font-size: 14px; color: var(--gold); flex-shrink: 0; margin-top: 1px; }
.suggestion-label { font-size: 11px; color: var(--gold); margin-bottom: 2px; font-weight: 500; }
.suggestion-text { font-size: 12px; color: var(--text-secondary); line-height: 1.5; }

/* ===== Notification ===== */
#notificationArea {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.notification-toast {
  background: var(--bg-card);
  border: 0.5px solid var(--gold-dim);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-primary);
  pointer-events: auto;
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 4.7s;
  max-width: 260px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

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

/* ===== NPC List ===== */
.npc-list { display: flex; flex-direction: column; gap: 8px; }

.npc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-color);
}

.npc-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.npc-info { flex: 1; min-width: 0; }
.npc-name { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.npc-detail { font-size: 11px; color: var(--text-muted); }

.npc-empty {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  padding: 8px 0;
}

/* ===== Inspiration ===== */
.inspiration-section { margin-bottom: 14px; }

.inspiration-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.inspiration-bar-container {
  height: 8px;
  background: var(--bg-card);
  border-radius: 4px;
  overflow: hidden;
  border: 0.5px solid var(--border-color);
}

.inspiration-bar {
  height: 100%;
  background: var(--gold);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.inspiration-info {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.inspiration-recovery { color: var(--gold-dim); }

/* ===== Action Buttons ===== */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.action-btn {
  padding: 12px 0;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.action-btn.enabled {
  color: var(--gold);
  border-color: var(--gold-dim);
  background: var(--bg-hover);
}

.action-btn.enabled:active {
  transform: scale(0.97);
  opacity: 0.8;
}

.action-btn:active { opacity: 0.6; }

/* ===== Create Form ===== */
.create-form {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 12px;
  border: 0.5px solid var(--gold-dim);
  margin-bottom: 12px;
  animation: fadeIn 0.3s ease;
}

.create-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  margin-bottom: 8px;
  outline: none;
}
.create-input:focus { border-color: var(--gold-dim); }

.create-textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
  outline: none;
  margin-bottom: 8px;
}
.create-textarea:focus { border-color: var(--gold-dim); }

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

.submit-btn {
  flex: 1;
  padding: 8px;
  background: var(--gold);
  border: none;
  border-radius: var(--radius-sm);
  color: #0d0d1a;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}
.submit-btn:active { opacity: 0.8; }

.cancel-btn {
  padding: 8px 16px;
  background: transparent;
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.cancel-btn:active { opacity: 0.6; }

/* ===== Player Invention Log ===== */
.invention-list { display: flex; flex-direction: column; gap: 6px; }

.invention-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 6px 0;
  border-bottom: 0.5px solid var(--border-color);
}
.invention-item:last-child { border-bottom: none; }

.invention-icon { font-size: 12px; color: var(--gold); flex-shrink: 0; margin-top: 2px; }
.invention-title { font-size: 12px; color: var(--text-primary); font-weight: 500; }
.invention-desc { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

/* ===== Footer ===== */
#footer {
  padding: 8px 20px;
  background: var(--bg-deep);
  border-top: 0.5px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

/* ===== Notification Overlay ===== */
.notification-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 99;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

/* ===== Responsive: Desktop ===== */
@media (min-width: 768px) {
  #mobileTabs { display: none !important; }

  #mainContent {
    display: grid;
    grid-template-columns: 1fr 240px;
    gap: 0;
  }

  .panel { display: block !important; padding: 16px 20px; }
  .panel#panelChronicle { border-right: 0.5px solid var(--border-color); }
  .panel#panelWorld { }
  .panel#panelCreate { display: none !important; }

  /* On desktop, create is inline on the right panel */
  #panelWorld .action-grid {
    margin-top: 12px;
  }
  #panelWorld .inspiration-section { display: block; }
}

/* ===== Responsive: Mobile ===== */
@media (max-width: 767px) {
  #mobileTabs { display: flex; }

  #mainContent { display: block; }
  .panel { display: none; padding: 12px 16px; }
  .panel.active { display: block; }

  #topbar { padding: 10px 14px; }
  .year-display { font-size: 18px; }
  .topbar-right { gap: 10px; }
  .stat { font-size: 11px; }

  .action-btn { padding: 14px 0; font-size: 15px; }

  .timeline-entry { margin-bottom: 4px; }
  .timeline-text { font-size: 13px; }

  #panelWorld .inspiration-section { display: none; }
  #panelWorld .action-grid { display: none; }
  #panelWorld .create-log { display: none; }
}

/* ===== Loading State ===== */
.loading-dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}

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