:root {
  --bg: #0e131d;
  --panel: #151c2b;
  --panel-2: #1c2538;
  --border: #26324a;
  --text: #eef2f9;
  --muted: #8b9bb5;
  --accent: #5e8bff;
  --bubble-me: #3a6df0;
  --bubble-soul: #1d273b;
  --ok: #42d392;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", sans-serif; overflow: hidden; }
.hidden { display: none !important; }

/* Auth Screen */
.auth-shell { height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-box {
  width: 100%; max-width: 390px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 22px; padding: 32px 26px; text-align: center; box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.avatar-hero, .soul-avatar {
  width: 54px; height: 54px; border-radius: 18px; margin: 0 auto 14px;
  background: linear-gradient(135deg, #4ea8de, #7b61ff);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.soul-avatar { width: 42px; height: 42px; border-radius: 14px; margin: 0; font-size: 17px; }
.soul-avatar.lg { width: 56px; height: 56px; font-size: 22px; }
.auth-box h1 { font-size: 20px; margin-bottom: 4px; }
.auth-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.auth-switch { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.auth-switch button {
  flex: 1; background: transparent; border: none; color: var(--muted);
  padding: 8px; border-radius: 9px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.auth-switch button.active { background: var(--panel-2); color: #fff; }
.auth-box form { display: flex; flex-direction: column; gap: 11px; }
.auth-box input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 11px 14px; border-radius: 12px; font-size: 14px; outline: none;
}
.auth-box input:focus { border-color: var(--accent); }
.btn-main {
  background: var(--accent); color: #fff; border: none; padding: 12px;
  border-radius: 12px; font-size: 14.5px; font-weight: 600; cursor: pointer; margin-top: 4px;
}
.err { color: #f26b6b; font-size: 13px; }

/* Main App Layout */
.app-shell { display: flex; height: 100%; width: 100%; }
.nav-rail {
  width: 230px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; flex-shrink: 0;
}
.rail-brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 18px; border-bottom: 1px solid var(--border); }
.rail-soul-meta strong { display: block; font-size: 15.5px; }
.mood-pill {
  display: inline-block; font-size: 11.5px; color: var(--ok);
  background: rgba(66,211,146,0.12); padding: 2px 8px; border-radius: 999px; margin-top: 2px;
}
.nav-items { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; flex: 1; }
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 11px 12px;
  border-radius: 12px; border: none; background: transparent; color: var(--muted);
  font-size: 14.5px; font-weight: 500; cursor: pointer; text-align: left; position: relative;
}
.nav-btn.active { background: rgba(94,139,255,0.16); color: #fff; font-weight: 600; }
.unread {
  width: 8px; height: 8px; border-radius: 50%; background: #ff5c7c; margin-left: auto;
}
.rail-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 12px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted);
}
.btn-icon { background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 8px; padding: 4px 9px; cursor: pointer; }

/* Stage */
.stage { flex: 1; display: flex; flex-direction: column; height: 100%; min-width: 0; }
.stage-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border); background: rgba(21,28,43,0.85);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.stage-header h2 { font-size: 16px; }
.header-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.typing-pill {
  font-size: 12px; color: #9ec1ff; background: rgba(94,139,255,0.15);
  padding: 4px 12px; border-radius: 999px; animation: pulse 1.3s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }

.chat-section { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages-list {
  flex: 1; overflow-y: auto; padding: 18px 20px;
  display: flex; flex-direction: column; gap: 14px;
}

.msg-row { display: flex; gap: 10px; max-width: 82%; align-items: flex-end; }
.msg-row.me { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.other { align-self: flex-start; }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 13.5px; font-weight: 700; color: #fff;
}
.msg-avatar.soul { background: linear-gradient(135deg, #4ea8de, #7b61ff); }
.msg-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg-row.me .msg-body { align-items: flex-end; }
.msg-meta { font-size: 11.5px; color: var(--muted); padding: 0 4px; }
.bubble {
  padding: 10px 14px; border-radius: 16px; font-size: 14.5px; line-height: 1.5;
  word-break: break-word; white-space: pre-wrap;
}
.msg-row.me .bubble { background: var(--bubble-me); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.other .bubble { background: var(--bubble-soul); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.sys-notice {
  align-self: center; font-size: 12px; color: #f5b841;
  background: rgba(245,184,65,0.12); border: 1px solid rgba(245,184,65,0.3);
  padding: 6px 14px; border-radius: 999px; text-align: center;
}

/* Attachments & Rich Link Card inside Chat */
.att-grid { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.att-img { max-width: 260px; max-height: 280px; border-radius: 12px; cursor: pointer; object-fit: cover; }
.att-video { max-width: 290px; border-radius: 12px; }
.att-audio { width: 250px; height: 38px; }

.link-card {
  display: flex; gap: 10px; background: rgba(14,19,29,0.65); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px; margin-top: 4px; text-decoration: none; color: var(--text); max-width: 330px;
}
.link-card img { width: 68px; height: 52px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.link-card .lc-platform { font-size: 11px; color: #8ab4f8; font-weight: 600; }
.link-card .lc-title { font-size: 13px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.link-card .lc-author { font-size: 11.5px; color: var(--muted); }

/* Composer */
.pending-atts {
  display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 18px;
  background: var(--panel); border-top: 1px solid var(--border);
}
.pending-chip {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 10px; font-size: 12.5px; display: flex; align-items: center; gap: 6px;
}
.pending-chip button { background: none; border: none; color: #f26b6b; cursor: pointer; font-size: 14px; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border);
}
.btn-attach, .btn-at {
  height: 40px; padding: 0 11px; border-radius: 11px; background: var(--panel-2);
  border: 1px solid var(--border); color: var(--text); display: inline-flex;
  align-items: center; justify-content: center; cursor: pointer; font-size: 15px; flex-shrink: 0;
}
.btn-at { font-size: 13px; color: #9ec1ff; }
#msg-input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; padding: 10px 13px; font-size: 14.5px; resize: none;
  max-height: 120px; outline: none; font-family: inherit;
}
#msg-input:focus { border-color: var(--accent); }
.btn-send {
  height: 40px; padding: 0 16px; border-radius: 11px; background: var(--accent);
  color: #fff; border: none; font-weight: 600; font-size: 14px; cursor: pointer; flex-shrink: 0;
}

/* Moments Wall */
.moments-section { flex: 1; overflow-y: auto; padding: 20px; }
.moments-banner {
  max-width: 660px; margin: 0 auto 20px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 18px 20px; display: flex; align-items: center; gap: 14px;
}
.moments-banner p { font-size: 13px; color: var(--muted); margin-top: 3px; }
.moments-list { max-width: 660px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.moment-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 16px 18px;
}
.moment-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.moment-content { font-size: 14.5px; line-height: 1.6; white-space: pre-wrap; margin-bottom: 12px; }
.moment-actions { display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.btn-like {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 4px 12px; font-size: 12.5px; cursor: pointer;
}
.moment-comments { margin-top: 10px; display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.moment-comment-form { display: flex; gap: 6px; margin-top: 8px; }
.moment-comment-form input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 6px 10px; border-radius: 8px; font-size: 13px;
}

/* Mobile Responsive Bottom Tab Bar */
@media (max-width: 720px) {
  .app-shell { flex-direction: column-reverse; }
  .nav-rail {
    width: 100%; flex-direction: row; align-items: center; justify-content: space-around;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom)); border-right: none; border-top: 1px solid var(--border);
  }
  .rail-brand, .rail-footer { display: none; }
  .nav-items { flex-direction: row; margin-top: 0; justify-content: space-around; width: 100%; }
  .nav-btn { justify-content: center; padding: 8px 10px; font-size: 13px; }
  .msg-row { max-width: 90%; }
}
