:root {
  --accent: #e75480;
  --accent-soft: #ffe3ec;
  --accent-softer: #fff0f5;
  --bg: #ffeef4;
  --panel: #fff7fa;
  --text: #4a2b36;
  --text-soft: #8a6572;
  --bubble-ai: #ffe0ea;
  --bubble-user: #e75480;
  --bubble-user-text: #ffffff;
  --radius: 18px;
  --shadow: 0 4px 18px rgba(231, 84, 128, 0.12);
  font-size: 15px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", "Poppins", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, var(--bg), #fff5f8 40%, var(--bg));
  color: var(--text);
  min-height: 100vh;
}

.heart { color: var(--accent); }

/* ---------------- Top bar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--accent-soft);
}
.topbar-brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--accent);
}
.topbar-tagline {
  color: var(--text-soft);
  font-style: italic;
  font-size: 0.9rem;
}
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}
.topbar-link {
  background: none;
  border: none;
  color: var(--text-soft);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.92rem;
}
.topbar-link:hover { color: var(--accent); }
.topbar-heart { color: var(--accent); font-size: 1.1rem; }

/* ---------------- Layout ---------------- */
.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 320px;
  gap: 20px;
  padding: 20px 24px 32px;
  align-items: start;
}
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.profile-card { text-align: center; }
.avatar-blob {
  width: 88px;
  height: 88px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #ffb6c9);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(231, 84, 128, 0.35);
  animation: float 4s ease-in-out infinite;
}
.avatar-initial {
  color: white;
  font-size: 2.1rem;
  font-weight: 700;
}
.avatar-photo {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.profile-name { font-weight: 700; font-size: 1.05rem; }
.profile-sub { color: var(--text-soft); font-size: 0.85rem; margin-top: 2px; }

.side-nav { display: flex; flex-direction: column; gap: 6px; }
.side-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
}
.side-nav-item:hover { background: var(--accent-softer); }
.side-nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.side-nav-item .icon { font-size: 1rem; }

.sticky-note {
  background: #fff2f6;
  border: 1px dashed #f3b6c8;
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  font-style: italic;
  color: var(--accent);
  transform: rotate(-1.5deg);
}

.sidebar-illustration { text-align: center; margin-top: auto; }
.floating-cat { animation: float 3.5s ease-in-out infinite; }
.cat-heart { color: var(--accent); font-size: 1.2rem; }
.cat-face { font-size: 1.3rem; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* ---------------- Center panel ---------------- */
.center-panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 640px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.view { display: none; flex-direction: column; flex: 1; padding: 20px 24px; }
.view.active { display: flex; }
.view-title { margin: 0 0 4px; color: var(--accent); }
.view-sub { color: var(--text-soft); margin-top: 0; font-size: 0.9rem; }

/* Chat view */
#view-chat { padding: 0; }
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--accent-soft);
}
.chat-header-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
}
.chat-header-name { font-weight: 700; }
.chat-header-status {
  font-size: 0.8rem;
  color: var(--text-soft);
  display: flex; align-items: center; gap: 6px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4caf50; display: inline-block;
}
.infinity { color: var(--accent); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 320px;
}
.msg-row { display: flex; gap: 10px; max-width: 80%; }
.msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
  background: var(--accent-soft);
}
.msg-row.user .msg-avatar { background: var(--accent); color: white; }
.msg-bubble {
  background: var(--bubble-ai);
  padding: 10px 14px;
  border-radius: 16px 16px 16px 4px;
  line-height: 1.4;
  font-size: 0.92rem;
}
.msg-row.user .msg-bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-radius: 16px 16px 4px 16px;
}
.msg-time {
  font-size: 0.68rem;
  color: var(--text-soft);
  margin-top: 4px;
  display: block;
}
.msg-row.user .msg-time { color: rgba(255,255,255,0.75); text-align: right; }

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0 26px 8px;
}
.typing-indicator[hidden] { display: none; }
.typing-indicator span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
  animation: blink 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 22px;
  border-top: 1px solid var(--accent-soft);
}
.chip {
  background: var(--accent-softer);
  border: 1px solid var(--accent-soft);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
}
.chip:hover { background: var(--accent-soft); }

.chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--accent-soft);
}
.attach-btn {
  background: none; border: none; font-size: 1.1rem; cursor: default; opacity: 0.5;
}
#chat-input {
  flex: 1;
  padding: 11px 16px;
  border-radius: 22px;
  border: 1px solid var(--accent-soft);
  background: #fff;
  font-size: 0.92rem;
  outline: none;
}
#chat-input:focus { border-color: var(--accent); }
.send-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  cursor: pointer;
}
.send-btn:disabled { opacity: 0.5; cursor: default; }

/* Starter questions grid */
.starter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.starter-chip {
  background: var(--accent-softer);
  border: 1px solid var(--accent-soft);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  text-align: left;
}
.starter-chip:hover { background: var(--accent-soft); }

/* Memories / Notes */
.memory-form, .note-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 16px;
  max-width: 420px;
}
.note-form { flex-direction: row; max-width: none; }
.memory-form input, .memory-form textarea,
.note-form input {
  border: 1px solid var(--accent-soft);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.88rem;
  font-family: inherit;
}
.note-form input { flex: 1; }
.memory-form button, .note-form button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 0.85rem;
}
.memory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.memory-item {
  background: var(--accent-softer);
  border-radius: 14px;
  padding: 14px;
  position: relative;
}
.memory-item h4 { margin: 0 0 6px; color: var(--accent); font-size: 0.95rem; }
.memory-item p { margin: 0; font-size: 0.82rem; color: var(--text); }
.memory-item .del-btn, .note-item .del-btn {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; cursor: pointer; color: var(--text-soft);
}

.notes-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.note-item {
  background: #fff8e7;
  border-radius: 4px 16px 16px 16px;
  padding: 14px;
  font-size: 0.85rem;
  box-shadow: 0 3px 8px rgba(0,0,0,0.06);
  position: relative;
  transform: rotate(-1deg);
}
.note-item:nth-child(even) { transform: rotate(1deg); background: #eefaf0; }

/* Settings */
.settings-block { margin-bottom: 22px; }
.settings-label { font-weight: 600; display: block; margin-bottom: 8px; }
.theme-swatches { display: flex; gap: 10px; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid white;
  outline: 1px solid var(--accent-soft);
  background: var(--sw);
  cursor: pointer;
}
.danger-btn {
  background: var(--accent-softer);
  border: 1px solid var(--accent-soft);
  color: var(--accent);
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  margin-right: 10px;
  font-size: 0.85rem;
}

/* ---------------- Right column ---------------- */
.right-col { display: flex; flex-direction: column; gap: 18px; }

.hero-card {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
  height: 220px;
  background: linear-gradient(160deg, #ffd3e0, #ffb6c9 45%, #f78fb3);
}
.hero-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.hero-photo-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(231, 84, 128, 0.05), rgba(120, 20, 55, 0.55));
}
.hero-animation { position: absolute; inset: 0; overflow: hidden; }
.hero-caption {
  position: absolute;
  left: 18px; bottom: 16px;
  color: white;
  font-weight: 600;
  font-size: 1.1rem;
  text-shadow: 0 2px 6px rgba(0,0,0,0.25);
  line-height: 1.3;
}
.floating-heart {
  position: absolute;
  bottom: -20px;
  color: rgba(255,255,255,0.85);
  font-size: 1.1rem;
  animation: rise linear forwards;
}
@keyframes rise {
  0% { transform: translateY(0) translateX(0) scale(0.8); opacity: 0; }
  10% { opacity: 1; }
  100% { transform: translateY(-260px) translateX(var(--drift, 20px)) scale(1.1); opacity: 0; }
}

.mcq-card, .quote-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.mcq-header { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.mcq-icon {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.mcq-title { font-weight: 700; font-size: 0.95rem; }
.mcq-sub { font-size: 0.78rem; color: var(--text-soft); }

.mcq-progress-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 14px;
}
.mcq-progress-bar {
  flex: 1; height: 6px; border-radius: 4px; background: var(--accent-soft); overflow: hidden;
}
.mcq-progress-fill {
  height: 100%; width: 0%; background: var(--accent); transition: width 0.4s ease;
}
#mcq-progress-label { font-size: 0.75rem; color: var(--text-soft); }

.mcq-question { font-weight: 600; margin-bottom: 12px; font-size: 0.92rem; }
.mcq-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid var(--accent-soft);
  border-radius: 12px;
  padding: 9px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 0.85rem;
}
.mcq-option:hover { background: var(--accent-softer); }
.mcq-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.mcq-option.correct { border-color: #4caf50; background: #e8f8ec; }
.mcq-option.incorrect { border-color: #e05252; background: #fdeaea; }
.mcq-option-letter {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700; flex-shrink: 0;
}
.mcq-submit-btn {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 10px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.mcq-submit-btn:disabled { opacity: 0.5; cursor: default; }
.mcq-reaction {
  margin-top: 12px;
  font-size: 0.85rem;
  background: var(--accent-softer);
  border-radius: 10px;
  padding: 10px 12px;
}
.mcq-next-btn {
  margin-top: 10px;
  width: 100%;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 12px;
  padding: 9px;
  cursor: pointer;
  font-weight: 600;
}
.mcq-loading { color: var(--text-soft); font-size: 0.85rem; }

.quote-card { text-align: center; font-style: italic; color: var(--accent); }

/* ==========================================================================
   MOBILE APP LAYOUT
   Below 860px the 3-column desktop layout is replaced by a single
   full-screen-at-a-time mobile flow, controlled by body[data-screen].
   Screens: home | chat | questions | mcq | world | notes | settings | menu
   ========================================================================== */

.mobile-topbar,
.mobile-screen,
.mobile-menu-fab {
  display: none; /* hidden on desktop, and hidden by default even below 860px
                     until JS + the media query below turn on the active one */
}

@media (max-width: 860px) {
  html, body { height: 100%; }
  body {
    overflow-x: hidden;
  }

  .topbar { display: none; }

  /* ---- Mobile top app bar ---- */
  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--accent-soft);
  }
  body[data-screen]:not([data-screen="home"]) .mobile-topbar { display: flex; }
  body[data-screen="menu"] .mobile-topbar .mobile-menu-btn { visibility: hidden; }
  .mobile-back-btn, .mobile-menu-btn {
    width: 34px; height: 34px;
    border-radius: 50%;
    border: none;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
  }
  .mobile-topbar-title { font-weight: 700; color: var(--accent); font-size: 1rem; }

  /* ---- Generic mobile screen container ---- */
  .mobile-screen {
    flex-direction: column;
    min-height: calc(100vh - 0px);
    min-height: 100dvh;
    padding: 20px 20px 32px;
  }
  body[data-screen="home"] .mobile-home { display: flex; }
  body[data-screen="menu"] .mobile-menu { display: flex; }

  /* ---- Mobile Home screen ---- */
  .mobile-home { position: relative; text-align: center; align-items: center; }
  .mobile-menu-fab {
    position: absolute;
    top: 18px; right: 18px;
    width: 38px; height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 1.2rem;
    cursor: pointer;
  }
  body[data-screen="home"] .mobile-menu-fab { display: flex; align-items: center; justify-content: center; }

  .mobile-home-hero { margin-top: 28px; }
  .mobile-heart-frame {
    position: relative;
    width: 190px; height: 170px;
    margin: 0 auto 14px;
  }
  .mobile-heart-outline {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
  }
  .mobile-heart-outline path {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2.5;
    opacity: 0.55;
  }
  .mobile-avatar-wrap {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -46%);
    width: 108px; height: 108px;
  }
  .mobile-avatar-wrap .hero-animation {
    position: absolute;
    inset: -40px;
    overflow: visible;
    pointer-events: none;
  }
  .mobile-avatar-blob { width: 108px; height: 108px; margin: 0; position: relative; z-index: 1; }
  .mobile-avatar-blob .avatar-initial { font-size: 2.6rem; }

  .mobile-home-title { margin: 4px 0 2px; font-size: 1.4rem; color: var(--text); }
  .mobile-home-subtitle { margin: 0; color: var(--accent); font-weight: 600; font-size: 0.95rem; }
  .mobile-home-caption { margin: 4px 0 0; color: var(--text-soft); font-size: 0.82rem; }

  .mobile-home-actions {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 30px;
  }
  .mobile-home-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 15px 18px;
    border-radius: 16px;
    border: 1px solid var(--accent-soft);
    background: var(--accent-softer);
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
  }
  .mobile-home-btn .chevron { margin-left: auto; color: var(--text-soft); }
  .mobile-home-btn.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
  }
  .mobile-home-btn.primary .chevron { color: rgba(255,255,255,0.8); }

  .mobile-sticky-note { width: 100%; max-width: 360px; margin-top: 28px; }

  /* ---- Mobile Menu screen ---- */
  .mobile-menu-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 10px;
  }
  .mobile-menu-avatar { width: 64px; height: 64px; margin: 0; flex-shrink: 0; }
  .mobile-menu-avatar .avatar-initial { font-size: 1.6rem; }
  .mobile-menu-hero-mini {
    flex: 1;
    background: linear-gradient(160deg, #ffd3e0, #f78fb3);
    color: #fff;
    border-radius: 14px;
    padding: 12px 14px;
    font-weight: 600;
    font-size: 0.88rem;
    line-height: 1.3;
  }
  .mobile-menu-name { font-weight: 700; margin-bottom: 18px; }

  .mobile-menu-list { display: flex; flex-direction: column; gap: 8px; }
  .mobile-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid var(--accent-soft);
    background: var(--panel);
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
  }
  .mobile-menu-item .chevron { margin-left: auto; color: var(--text-soft); }
  .mobile-menu-item:active { background: var(--accent-softer); }

  .mobile-signoff-note { margin-top: auto; padding-top: 24px; }

  /* ---- Layout container becomes single-screen ---- */
  .layout {
    display: block;
    padding: 0;
    gap: 0;
  }
  .sidebar { display: none; }

  .center-panel {
    display: none;
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .view { padding: 16px; }
  body[data-screen="chat"] .center-panel,
  body[data-screen="questions"] .center-panel,
  body[data-screen="world"] .center-panel,
  body[data-screen="notes"] .center-panel,
  body[data-screen="settings"] .center-panel {
    display: flex;
  }
  #view-chat { min-height: calc(100vh - 63px); min-height: calc(100dvh - 63px); }

  .quick-actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .quick-actions::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; }

  .msg-row { max-width: 88%; }

  /* ---- Right column becomes the MCQ full screen ---- */
  .right-col {
    display: none;
    flex-direction: column;
    padding: 16px;
    gap: 16px;
    min-height: 100vh;
    min-height: 100dvh;
  }
  body[data-screen="mcq"] .right-col { display: flex; }
  body[data-screen="mcq"] .hero-card,
  body[data-screen="mcq"] .quote-card {
    display: none;
  }
  body[data-screen="mcq"] .mcq-card {
    flex: 1;
    box-shadow: none;
    border-radius: 16px;
  }
}
