@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;700&family=Noto+Sans+SC:wght@400;500;700&family=Caveat:wght@500;700&display=swap');

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

:root {
  --paper: oklch(97% 0.012 80);
  --paper-warm: oklch(94% 0.018 75);
  --paper-dark: oklch(90% 0.022 70);
  --ink: oklch(22% 0.02 60);
  --ink-light: oklch(45% 0.02 60);
  --ink-faint: oklch(70% 0.015 65);
  --seam: oklch(85% 0.025 70);
  --red-pin: oklch(55% 0.22 25);
  --gold: oklch(72% 0.15 75);
  --board-bg: oklch(35% 0.04 55);
  --board-felt: oklch(30% 0.06 145);

  /* per-character accent (used by JS via inline style) */
  --stardust: oklch(72% 0.18 310);
  --bolt: oklch(62% 0.16 240);
  --sunny: oklch(78% 0.16 75);
  --inker: oklch(68% 0.18 340);
  --flash: oklch(68% 0.18 160);
}

body {
  font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--board-bg);
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
}

/* ===================================
   APP LAYOUT
=================================== */
.app-container {
  display: grid;
  grid-template-columns: 270px 1fr 310px;
  grid-template-rows: 52px 1fr;
  height: 100vh;
  gap: 0;
}

/* ===================================
   HEADER — pinboard top rail
=================================== */
.header {
  grid-column: 1 / -1;
  background: var(--board-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 3px solid oklch(28% 0.04 55);
  position: relative;
}

.header::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 0; right: 0;
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--gold) 0, var(--gold) 6px, transparent 6px, transparent 18px);
  opacity: 0.4;
}

.header h1 {
  font-family: 'Caveat', cursive;
  font-size: 24px;
  font-weight: 700;
  color: var(--paper-warm);
  letter-spacing: 0.5px;
}

.world-mood {
  font-size: 12px;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 10px;
  background: oklch(28% 0.04 55);
  padding: 5px 12px;
  border-radius: 3px;
}

.world-mood strong { color: var(--paper-warm); }

.mood-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: oklch(70% 0.2 145);
  animation: breathe 3s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* ===================================
   PANELS — paper on cork board
=================================== */
.left-panel {
  background: var(--paper-warm);
  overflow-y: auto;
  padding: 16px 14px;
  border-right: 1px solid var(--seam);
  box-shadow: inset -4px 0 12px rgba(0,0,0,0.06);
}

.center-panel {
  background: var(--paper);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* subtle lined paper texture */
  background-image: repeating-linear-gradient(
    transparent,
    transparent 27px,
    oklch(91% 0.018 75) 27px,
    oklch(91% 0.018 75) 28px
  );
  background-size: 100% 28px;
}

#centerTimeline {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

#centerMap {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  min-height: 0;
}

#centerScene {
  flex: 1;
  overflow: hidden;
}

.right-panel {
  background: var(--paper-warm);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--seam);
  box-shadow: inset 4px 0 12px rgba(0,0,0,0.06);
}

/* ===================================
   LEFT PANEL — sections
=================================== */
.panel-section {
  margin-bottom: 22px;
}

.panel-section h3 {
  font-family: 'Noto Serif SC', serif;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--ink-faint);
  margin-bottom: 10px;
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--seam);
}

/* character cards — sticky note style */
.character-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 2px;
  cursor: pointer;
  margin-bottom: 7px;
  background: var(--paper);
  border: 1px solid var(--seam);
  box-shadow: 2px 2px 0 var(--seam);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.character-card::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red-pin);
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
  opacity: 0;
  transition: opacity 0.15s;
}

.character-card:hover {
  transform: translateY(-1px);
  box-shadow: 3px 4px 0 var(--seam);
}

.character-card.active {
  transform: translateY(-1px) rotate(-0.5deg);
  box-shadow: 3px 5px 0 var(--seam);
}

.character-card.active::before { opacity: 1; }

.char-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  border: 2.5px solid;
  overflow: hidden;
  background: var(--paper-dark);
  position: relative;
}

.char-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.char-avatar-fallback {
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.chat-header-avatar {
  width: 44px;
  height: 44px;
  font-size: 20px;
}

.char-info { flex: 1; min-width: 0; }

.char-name {
  font-size: 13px;
  font-weight: 700;
  font-family: 'Noto Serif SC', serif;
}

.char-personality {
  font-size: 10px;
  color: var(--ink-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: oklch(65% 0.22 145);
  flex-shrink: 0;
}

/* ===================================
   RELATIONSHIPS
=================================== */
.relationship-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
  font-size: 11px;
  color: var(--ink-light);
}

.heat-bar {
  width: 56px;
  height: 5px;
  background: var(--seam);
  border-radius: 2px;
  overflow: hidden;
}

.heat-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s ease;
}

/* ===================================
   STATS
=================================== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-box {
  background: var(--paper-dark);
  padding: 10px 8px;
  border-radius: 2px;
  text-align: center;
  border: 1px solid var(--seam);
  box-shadow: 1px 1px 0 var(--seam);
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  font-family: 'Noto Serif SC', serif;
  color: var(--ink);
  line-height: 1;
}

.stat-label {
  font-size: 9px;
  color: var(--ink-faint);
  margin-top: 3px;
  letter-spacing: 0.5px;
}

/* ===================================
   CENTER PANEL — timeline
=================================== */
.timeline-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-left: 48px; /* align with margin line */
}

.timeline-header h2 {
  font-family: 'Noto Serif SC', serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

/* margin line — like a real ruled notebook */
.center-panel::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: calc(270px + 44px);
  width: 1px;
  background: oklch(78% 0.1 10);
  opacity: 0.35;
  pointer-events: none;
}

.square-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.square-input-row input {
  flex: 1;
  background: white;
  border: 1px solid var(--seam);
  border-bottom: 2px solid var(--ink-light);
  color: var(--ink);
  padding: 9px 12px;
  border-radius: 2px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  box-shadow: 1px 1px 0 var(--seam);
}

.square-input-row input:focus {
  border-bottom-color: var(--ink);
}

.square-input-row input::placeholder { color: var(--ink-faint); }

.square-input-row button {
  background: var(--ink);
  color: var(--paper);
  border: none;
  padding: 9px 16px;
  border-radius: 2px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  box-shadow: 2px 2px 0 var(--ink-light);
}

.square-input-row button:hover { opacity: 0.85; }
.square-input-row button:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink-light); }

/* timeline events */
.timeline-event {
  padding: 11px 13px;
  background: white;
  border-radius: 2px;
  margin-bottom: 7px;
  border: 1px solid var(--seam);
  border-left: 3px solid var(--seam);
  box-shadow: 2px 2px 0 var(--seam);
  animation: noteIn 0.25s ease;
  transition: transform 0.15s, box-shadow 0.15s;
}

.timeline-event:hover {
  transform: translateX(2px);
  box-shadow: 3px 3px 0 var(--seam);
}

.timeline-event.user-event {
  border-left-color: var(--ink);
  background: oklch(97% 0.01 270);
}

.timeline-event.task-event {
  border-left-color: var(--gold);
}

.timeline-event.task-complete {
  border-left-color: oklch(60% 0.22 145);
}

@keyframes noteIn {
  from { opacity: 0; transform: translateY(-6px) rotate(-0.5deg); }
  to { opacity: 1; transform: translateY(0) rotate(0deg); }
}

.event-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.event-type {
  font-size: 9px;
  padding: 2px 7px;
  border-radius: 1px;
  background: var(--paper-dark);
  color: var(--ink-light);
  letter-spacing: 0.5px;
  font-weight: 600;
  border: 1px solid var(--seam);
}

.event-time {
  font-size: 10px;
  color: var(--ink-faint);
  font-family: 'Caveat', cursive;
}

.event-content {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink);
}

.conversation-round {
  margin-top: 8px;
  padding: 8px;
  background: oklch(98% 0.01 260);
  border: 1px solid var(--seam);
  border-radius: 4px;
}

.conv-meta-row {
  font-size: 11px;
  color: var(--ink-light);
  margin-bottom: 3px;
}

.conv-turns {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv-turn {
  font-size: 12px;
  line-height: 1.5;
  background: white;
  border: 1px solid var(--seam);
  border-radius: 3px;
  padding: 5px 7px;
}

.conv-speaker {
  font-weight: 700;
  margin-right: 4px;
}

.conv-text {
  color: var(--ink);
}

/* ===================================
   RIGHT PANEL — chat
=================================== */
#chatArea {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
  font-size: 13px;
  text-align: center;
  padding: 24px;
  font-family: 'Caveat', cursive;
  font-size: 16px;
}

.chat-header {
  padding: 12px 14px;
  border-bottom: 1px dashed var(--seam);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper-dark);
}

.chat-header .char-avatar { width: 30px; height: 30px; font-size: 15px; }

.clear-history-btn {
  background: none;
  border: 1px solid var(--seam);
  border-radius: 6px;
  cursor: pointer;
  padding: 4px 8px;
  font-size: 13px;
  opacity: 0.5;
  transition: opacity 0.2s, background 0.2s;
}
.clear-history-btn:hover {
  opacity: 1;
  background: rgba(244, 114, 182, 0.12);
}

.chat-title {
  font-size: 14px;
  font-weight: 700;
  font-family: 'Noto Serif SC', serif;
}

.chat-subtitle {
  font-size: 10px;
  color: var(--ink-light);
  margin-top: 1px;
}

/* tabs */
.chat-tabs {
  display: flex;
  border-bottom: 1px solid var(--seam);
  background: var(--paper-dark);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 9px 0;
  background: none;
  border: none;
  color: var(--ink-faint);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--ink); background: rgba(0,0,0,0.03); }
.tab-btn.active { color: var(--ink); border-bottom: 2px solid var(--ink); }

.tab-panel {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#tabMemory {
  overflow-y: auto;
  padding: 12px;
}

/* chat messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.chat-msg {
  margin-bottom: 10px;
  animation: msgIn 0.2s ease;
}

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

.chat-msg .sender {
  font-size: 10px;
  color: var(--ink-faint);
  margin-bottom: 3px;
  font-family: 'Caveat', cursive;
  font-size: 12px;
}

.chat-msg .bubble {
  padding: 8px 12px;
  border-radius: 2px;
  font-size: 13px;
  line-height: 1.55;
  max-width: 90%;
  border: 1px solid var(--seam);
  box-shadow: 1px 2px 0 var(--seam);
}

.chat-msg.from-user .bubble {
  background: var(--ink);
  color: var(--paper);
  margin-left: auto;
  border-color: var(--ink);
  box-shadow: 2px 2px 0 oklch(15% 0.02 60);
}

.chat-msg.from-char .bubble {
  background: white;
}

/* inputs */
.chat-input-area {
  padding: 10px 12px;
  border-top: 1px dashed var(--seam);
  background: var(--paper-dark);
}

.chat-input-row {
  display: flex;
  gap: 6px;
}

.chat-input-row input {
  flex: 1;
  background: white;
  border: 1px solid var(--seam);
  border-bottom: 2px solid var(--ink-light);
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 2px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input-row input:focus {
  border-bottom-color: var(--ink);
}

.chat-input-row input::placeholder { color: var(--ink-faint); }

.chat-input-row button {
  background: var(--ink);
  color: var(--paper);
  border: none;
  padding: 8px 13px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  transition: opacity 0.15s;
  box-shadow: 1px 1px 0 oklch(15% 0.02 60);
}

.chat-input-row button:hover { opacity: 0.8; }



/* ===================================
   MEMORY PANEL
=================================== */
.memory-loading {
  text-align: center;
  padding: 32px;
  color: var(--ink-faint);
  font-size: 13px;
  font-family: 'Caveat', cursive;
  font-size: 16px;
}

.memory-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mem-section {
  background: white;
  border-radius: 2px;
  border: 1px solid var(--seam);
  box-shadow: 1px 2px 0 var(--seam);
  overflow: hidden;
}

.mem-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 7px 11px;
  border-left: 3px solid;
  background: var(--paper-dark);
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  border-bottom: 1px solid var(--seam);
}

.mem-section-toggle { cursor: pointer; user-select: none; }
.mem-section-toggle:hover { background: var(--paper); }
.mem-toggle-icon { margin-left: auto; font-size: 11px; color: var(--ink-faint); }

.mem-count {
  background: var(--seam);
  border-radius: 8px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  margin-left: auto;
  color: var(--ink-light);
}

.mem-summary {
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.75;
  color: var(--ink-light);
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--seam) transparent;
}

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

.mem-empty {
  padding: 10px 12px;
  font-size: 11px;
  color: var(--ink-faint);
  text-align: center;
  font-family: 'Caveat', cursive;
  font-size: 14px;
}

.mem-items { display: flex; flex-direction: column; }

.mem-item {
  padding: 7px 11px;
  border-bottom: 1px solid var(--paper-dark);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mem-item:last-child { border-bottom: none; }

.mem-time {
  font-size: 9px;
  color: var(--ink-faint);
  font-family: 'Caveat', cursive;
  font-size: 11px;
}

.mem-content {
  font-size: 12px;
  color: var(--ink);
  line-height: 1.5;
}

.mem-interest-line {
  font-size: 11px;
  color: #2d7a2d;
  margin-bottom: 3px;
  line-height: 1.5;
}

.mem-disinterest-line {
  font-size: 11px;
  color: #8a3a3a;
  margin-bottom: 3px;
  line-height: 1.5;
}

/* ===================================
   SCROLLBAR
=================================== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--seam); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

/* ===================================
   MOBILE NAV
=================================== */
.mobile-nav {
  display: none;
}

/* ===================================
   RESPONSIVE
=================================== */
@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  .app-container {
    grid-template-columns: 1fr;
    grid-template-rows: 48px 1fr;
    height: calc(100vh - 56px); /* leave room for bottom nav */
  }

  .header {
    padding: 0 14px;
  }

  .header h1 {
    font-size: 20px;
  }

  .world-mood {
    font-size: 11px;
    padding: 4px 8px;
  }

  /* all panels fill full area, show/hide via JS */
  .left-panel,
  .center-panel,
  .right-panel {
    grid-column: 1;
    grid-row: 2;
    display: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .left-panel.mobile-active,
  .center-panel.mobile-active,
  .right-panel.mobile-active {
    display: block;
  }

  .right-panel.mobile-active {
    display: flex;
  }

  .center-panel {
    background-image: none; /* remove lined paper on mobile for perf */
    padding: 12px;
  }

  .left-panel {
    padding: 14px 12px;
  }

  .character-card {
    padding: 10px;
  }

  /* chat right panel needs flex column */
  #chatArea {
    height: 100%;
  }

  /* mobile bottom nav */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0; right: 0;
    height: 56px;
    background: var(--paper-dark);
    border-top: 1px solid var(--seam);
    z-index: 100;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  }

  .mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ink-faint);
    font-family: inherit;
    transition: color 0.15s, background 0.15s;
    padding: 6px 0;
  }

  .mobile-nav-btn:hover,
  .mobile-nav-btn.active {
    color: var(--ink);
    background: rgba(0,0,0,0.04);
  }

  .mobile-nav-btn.active .mobile-nav-icon {
    transform: scale(1.15);
  }

  .mobile-nav-icon {
    font-size: 20px;
    line-height: 1;
    transition: transform 0.15s;
  }

  .mobile-nav-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
  }

  /* chat input should not get covered by nav */
  .chat-input-area,
  .task-input-area {
    padding-bottom: 8px;
  }

  /* timeline header on mobile */
  .timeline-header {
    padding-left: 0;
  }
}

/* ===================================
   DAILY SUMMARY CARD
=================================== */
.daily-summary-card {
  background: oklch(96% 0.03 75);
  border: 1px solid var(--seam);
  border-left: 4px solid var(--gold);
  border-radius: 3px;
  padding: 12px 14px 10px;
  margin-bottom: 14px;
  box-shadow: 2px 3px 0 var(--seam);
  position: relative;
}

/* Pinned note aesthetic */
.daily-summary-card::before {
  content: '';
  position: absolute;
  top: -5px;
  left: 20px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.summary-header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
}

.summary-icon {
  font-size: 15px;
}

.summary-date {
  font-family: 'Noto Serif SC', serif;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-faint);
  flex: 1;
}

.summary-refresh {
  background: none;
  border: 1px solid var(--seam);
  border-radius: 2px;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, transform 0.2s;
  padding: 0;
  line-height: 1;
}

.summary-refresh:hover {
  color: var(--ink);
  border-color: var(--ink-light);
}

.summary-refresh.spinning {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.summary-text {
  font-family: 'Noto Serif SC', serif;
  font-size: 13px;
  line-height: 1.75;
  color: var(--ink);
  min-height: 40px;
}

.summary-loading {
  color: var(--ink-faint);
  font-style: italic;
  font-size: 12px;
}

.summary-meta {
  margin-top: 8px;
  font-size: 11px;
  color: var(--ink-faint);
  display: flex;
  gap: 12px;
}

.summary-meta span {
  display: flex;
  align-items: center;
  gap: 3px;
}

@media (max-width: 768px) {
  .daily-summary-card {
    margin-bottom: 10px;
    padding: 10px 12px 8px;
  }

  .summary-text {
    font-size: 12px;
    line-height: 1.65;
  }
}

/* ===================================
   PHASE 1 & 2 ADDITIONS
=================================== */

/* Mood badge on avatar */
.char-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.mood-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  font-size: 12px;
  line-height: 1;
  background: white;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}

.mood-badge.mood-pulse {
  animation: moodPop 0.5s ease forwards;
}

@keyframes moodPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.5); }
  70%  { transform: scale(0.9); }
  100% { transform: scale(1); }
}

/* Relationship SVG graph */
#relationshipGraph {
  background: var(--paper-dark);
  border-radius: 3px;
  border: 1px solid var(--seam);
  overflow: hidden;
  display: flex;
  justify-content: center;
  padding: 4px 0 2px;
}

#relSvg {
  display: block;
}

/* Timeline event actions (rating + join) */
.event-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.rate-btn {
  background: none;
  border: 1px solid var(--seam);
  border-radius: 3px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s, transform 0.1s;
  color: var(--ink-light);
}

.rate-btn:hover {
  background: var(--paper-dark);
  transform: scale(1.1);
}

.rate-btn:active {
  transform: scale(0.95);
}

.join-btn {
  background: none;
  border: 1px solid var(--seam);
  border-radius: 3px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 11px;
  color: var(--ink-light);
  font-family: inherit;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  margin-left: 2px;
}

.join-btn:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.rate-thanks {
  font-size: 11px;
  color: var(--ink-faint);
  font-family: 'Caveat', cursive;
  font-size: 13px;
}

/* World events (Phase 2) */
.timeline-event.world-event {
  border-left-color: var(--stardust);
  background: oklch(97% 0.02 280);
}

/* ===================================
   CENTER TABS (Timeline / Scene)
=================================== */
.center-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--seam);
  padding-bottom: 0;
}

.center-tab {
  padding: 7px 14px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-faint);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
  letter-spacing: 0.3px;
}

.center-tab:hover { color: var(--ink); }
.center-tab.active { color: var(--ink); border-bottom-color: var(--ink); }

/* ===================================
   SCENE SELECTOR BAR
=================================== */
.scene-selector-bar {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  background: rgba(0,0,0,0.35);
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.scene-tab {
  padding: 6px 14px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  color: rgba(255,255,255,0.65);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.scene-tab:hover { background: rgba(255,255,255,0.14); color: #fff; }
.scene-tab.active { background: rgba(180,140,255,0.25); border-color: rgba(180,140,255,0.5); color: #fff; }

/* ===================================
   SCENE POPUP (群聊气泡面板)
=================================== */
.scene-popup {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 300px;
  max-height: 340px;
  background: rgba(14, 10, 28, 0.93);
  border: 1px solid rgba(180,140,255,0.3);
  border-radius: 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: popupIn 0.22s ease;
  z-index: 20;
}

@keyframes popupIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.scene-popup-header {
  display: flex;
  align-items: center;
  padding: 10px 12px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.scene-popup-title {
  flex: 1;
  font-size: 12px;
  font-weight: 700;
  color: rgba(220,210,255,0.9);
  font-family: 'Noto Serif SC', serif;
  letter-spacing: 0.3px;
}

.scene-popup-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px 4px;
  transition: color 0.15s;
}
.scene-popup-close:hover { color: #fff; }

.scene-popup-topic {
  padding: 5px 12px;
  font-size: 10px;
  color: rgba(180,140,255,0.8);
  letter-spacing: 0.3px;
  background: rgba(180,140,255,0.06);
  flex-shrink: 0;
}

.scene-popup-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.scene-chat-loading, .scene-chat-error {
  text-align: center;
  padding: 20px;
  color: rgba(255,255,255,0.35);
  font-size: 12px;
  font-family: 'Caveat', cursive;
  font-size: 14px;
}

.scene-chat-bubble {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.scene-chat-avatar {
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 1px;
}

.scene-chat-body {
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,0.07);
  max-width: 220px;
}

.scene-chat-name {
  font-size: 10px;
  font-weight: 700;
  margin-bottom: 3px;
  font-family: 'Noto Serif SC', serif;
}

.scene-chat-text {
  font-size: 12px;
  color: rgba(240,235,255,0.88);
  line-height: 1.5;
}

/* ===================================
   AFFINITY BAR (in character cards)
=================================== */
.char-affinity {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
}

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

.affinity-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s ease;
}

.affinity-val {
  font-size: 9px;
  font-weight: 700;
  min-width: 20px;
  text-align: right;
  line-height: 1;
}

/* ===================================
   BIG FIVE BARS (persona panel)
=================================== */
.bigfive-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.bf-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bf-label {
  font-size: 10px;
  color: var(--ink-faint);
  width: 34px;
  flex-shrink: 0;
  text-align: right;
}

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

.bf-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}

.bf-val {
  font-size: 10px;
  font-weight: 600;
  min-width: 26px;
  text-align: right;
  color: var(--ink-light);
}

.persona-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-faint);
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--seam);
  margin-bottom: 7px;
}

/* canvas wrap needs proper height - uses flex:1 from parent, no fixed height needed */

.scene-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

#sceneCanvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}

@media (max-width: 900px) {
  .scene-popup {
    width: calc(100vw - 24px);
    right: 12px;
    left: 12px;
    bottom: 8px;
  }

  #centerScene {
    flex: 1;
    min-height: 300px;
  }
}

/* ===================================
   PHASE 3: MILESTONE EVENTS
=================================== */
.milestone-event {
  border-left: 3px solid gold !important;
  background: linear-gradient(135deg, rgba(251,191,36,0.12), rgba(251,191,36,0.04)) !important;
  position: relative;
  overflow: hidden;
}

.milestone-event::before {
  content: '🏆';
  position: absolute;
  right: 10px;
  top: 8px;
  font-size: 20px;
  opacity: 0.4;
}

.milestone-event .event-type {
  color: gold !important;
  font-weight: 700;
}

.milestone-event .event-content {
  color: #fbbf24 !important;
  font-style: italic;
}

/* ===================================
   PHASE 3: DIARY TAB
=================================== */
.diary-view {
  padding: 8px 0;
}

.diary-header {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--seam);
}

.diary-entry {
  background: var(--paper-warm);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-left: 3px solid var(--seam);
  font-size: 12px;
  line-height: 1.7;
}

.diary-date {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
  opacity: 0.8;
}

.diary-content {
  color: var(--ink-light);
}

.diary-entry.locked {
  opacity: 0.6;
  border-left-color: var(--ink-faint);
}

.diary-locked-msg {
  color: var(--ink-faint);
  font-size: 11px;
  font-style: italic;
}

/* ===================================
   PHASE 3: WORLD EVENT (LLM)
=================================== */
.world-event.llm-event {
  border-left-color: #c084fc;
  background: linear-gradient(135deg, rgba(192,132,252,0.08), rgba(192,132,252,0.02));
}

/* ===================================
   PHASE 3: AFFINITY FLOATER
=================================== */
.affinity-floater {
  font-family: 'Noto Sans SC', sans-serif;
  letter-spacing: 0.3px;
}

/* ===================================
   PHASE 3: WORLD EVENT DISCUSS TURN
=================================== */
.conv-turn.world-event-discuss {
  background: rgba(192,132,252,0.07);
  border-radius: 4px;
  padding: 2px 4px;
}

/* ===================================
   PHASE 3+4: 渚汐镇 ADDITIONS
=================================== */

/* Title English subtitle */
.title-en {
  font-size: 13px;
  font-weight: 400;
  color: var(--ink-faint);
  letter-spacing: 0;
}

/* Header right group */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Weather display */
.weather-display {
  font-size: 12px;
  color: var(--paper-warm);
  display: flex;
  align-items: center;
  gap: 4px;
  background: oklch(28% 0.04 55);
  padding: 5px 10px;
  border-radius: 3px;
}

/* Villager status live */
.char-status-live {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--ink-faint);
  margin-top: 2px;
}

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

.status-dot.active {
  background: oklch(65% 0.22 145);
  animation: pulse 2s infinite;
}

.status-dot.sleeping {
  background: var(--ink-faint);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.mbti-tag {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 8px;
  background: var(--paper-dark);
  color: var(--ink-faint);
  font-weight: 600;
  letter-spacing: 0.5px;
  border: 1px solid var(--seam);
}

/* Map related */
.map-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.map-header h3 {
  font-family: 'Noto Serif SC', serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.map-hint {
  font-size: 11px;
  color: var(--ink-faint);
}

.town-map-wrap {
  position: relative;
  display: inline-block;
}

.map-location-info {
  margin-top: 12px;
  padding: 12px;
  background: var(--paper-dark);
  border-radius: 4px;
  border: 1px solid var(--seam);
  min-height: 60px;
}

.map-location-info h4 {
  font-size: 13px;
  color: var(--gold);
  margin-bottom: 8px;
  font-family: 'Noto Serif SC', serif;
}

.map-residents {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.map-resident-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--paper);
  border: 1px solid var(--seam);
  border-radius: 12px;
  font-size: 11px;
  color: var(--ink);
  box-shadow: 1px 1px 0 var(--seam);
}

/* World news event style */
.event-world-news {
  border-left-color: var(--gold) !important;
  background: oklch(96% 0.03 75) !important;
}

.event-label-news {
  background: oklch(85% 0.08 75);
  color: var(--ink);
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 2px;
  font-weight: 600;
  border: 1px solid var(--seam);
}

/* Proactive message badge */
.proactive-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: var(--red-pin);
  border-radius: 50%;
  animation: pulse 1s infinite;
}

/* Character list scrollable for 16 villagers */
#characterList {
  max-height: calc(100vh - 280px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--seam) transparent;
}
