@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-y: auto;
  padding: 16px;
  /* 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;
}

.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);
}

/* ===================================
   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; }

.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,
.task-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,
.task-input-row input:focus {
  border-bottom-color: var(--ink);
}

.chat-input-row input::placeholder,
.task-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; }

.task-input-area {
  padding: 8px 12px 10px;
  border-top: 1px dashed var(--seam);
  background: var(--paper-dark);
}

.task-input-area label {
  font-size: 10px;
  color: var(--ink-faint);
  display: block;
  margin-bottom: 5px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 600;
}

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

.task-input-row button {
  background: var(--gold);
  color: var(--ink);
  border: none;
  padding: 8px 11px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  font-weight: 700;
  box-shadow: 1px 1px 0 oklch(60% 0.12 70);
}

.task-input-row button:hover { opacity: 0.85; }

/* ===================================
   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;
}

/* ===================================
   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); }

/* ===================================
   RESPONSIVE
=================================== */
@media (max-width: 900px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-rows: 52px 1fr;
  }
  .left-panel, .right-panel { display: none; }
}
