:root {
  --ink: #1c1914;
  --muted: #6b6459;
  --paper: #f4efe6;
  --panel: #fffaf2;
  --line: #ddd4c6;
  --accent: #9a4b2e;
  --accent-soft: #f0d7cc;
  --user-bubble: #1c1914;
  --assistant-bubble: #efe6d8;
  --shadow: 0 18px 40px rgba(28, 25, 20, 0.08);
  --radius: 18px;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, #fbe7d6 0%, transparent 36%),
    var(--paper);
  color: var(--ink);
}

body {
  font-size: 15px;
  line-height: 1.5;
}

button,
select,
textarea {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 300px;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 20px 24px 12px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.mark {
  width: 14px;
  height: 42px;
  border-radius: 99px;
  background: linear-gradient(180deg, #c46a45, #7a341d);
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--accent);
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 650;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar-actions,
.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.persona-panel,
.memory-drawer,
.chat-panel {
  margin: 0 16px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.persona-panel,
.memory-drawer {
  padding: 18px;
  overflow: auto;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 16px 0;
}

.field.compact {
  margin: 0;
  min-width: 220px;
}

.field span {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.status-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.badge.mood {
  background: #f0d7cc;
  color: #7a341d;
}

.badge.tier {
  background: #efe6d8;
  color: #1c1914;
}

.badge.mood-cheerful {
  background: #f8e3a8;
  color: #7a5a10;
}

.badge.mood-cozy {
  background: #f0d7cc;
  color: #7a341d;
}

.badge.mood-thoughtful {
  background: #dce4f2;
  color: #31415f;
}

.badge.tier-spark,
.badge.tier-buddy,
.badge.tier-advisee,
.badge.tier-acquaintance,
.badge.tier-family {
  background: #eee6da;
  color: #5c5348;
}

.badge.tier-companion,
.badge.tier-close-buddy,
.badge.tier-colleague,
.badge.tier-friend,
.badge.tier-trusted-family {
  background: #e4f0d8;
  color: #3d5a28;
}

.badge.tier-soulmate,
.badge.tier-bestie,
.badge.tier-trusted-mentor,
.badge.tier-close-confidant,
.badge.tier-confidant {
  background: #f0d7cc;
  color: #7a341d;
}

.badge.tier-life-partner,
.badge.tier-inner-circle,
.badge.tier-sage,
.badge.tier-anchor {
  background: #1c1914;
  color: #f8f1e8;
}

.persona-select-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.persona-select-row .grow {
  flex: 1;
  margin: 8px 0 0;
}

.create-btn {
  margin: 0 0 8px;
  width: 100%;
}

.bond-meter {
  margin: 12px 0 8px;
}

.bond-meter-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.bond-track {
  height: 10px;
  border-radius: 999px;
  background: #eee6da;
  overflow: hidden;
}

.bond-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #c46a45, #7a341d);
  transition: width 0.35s ease;
}

.memory-group {
  margin-bottom: 16px;
}

.memory-group h3 {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.memory-card.consolidated {
  border-color: #d6a85c;
  background: #fff8ec;
}

.memory-card.archived {
  opacity: 0.78;
  background: #f7f2ea;
}

.memory-card.highlighted {
  box-shadow: 0 0 0 2px rgba(154, 75, 46, 0.25);
}

.memory-children {
  margin: 8px 0 0 14px;
  padding-left: 12px;
  border-left: 2px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(28, 25, 20, 0.35);
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(520px, 100%);
  max-height: min(90vh, 760px);
  overflow: auto;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 18px;
}

.modal-card input[type="text"],
.modal-card input[type="range"] {
  font: inherit;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  background: #fff;
}

.modal-card input[type="range"] {
  padding: 0;
}

select,
textarea,
button {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

select,
textarea {
  padding: 10px 12px;
}

button {
  cursor: pointer;
  padding: 10px 14px;
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.persona-card section {
  margin-top: 16px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

dl {
  margin: 8px 0 0;
}

dt {
  font-size: 12px;
  color: var(--muted);
}

dd {
  margin: 0 0 8px;
}

.muted {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.status {
  min-height: 22px;
  padding: 10px 18px 0;
  color: var(--muted);
  font-size: 13px;
}

.status.error {
  color: #9a2e2e;
}

.transcript {
  flex: 1;
  overflow: auto;
  padding: 12px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-stream {
  margin: auto;
  max-width: 28ch;
  text-align: center;
  color: var(--muted);
}

.bubble {
  max-width: 78%;
  padding: 12px 14px;
  border-radius: 16px;
  white-space: pre-wrap;
}

.bubble.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: #f8f1e8;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
}

.persona-identity,
.creator-identity,
.message-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.message-row {
  align-items: flex-end;
  max-width: 92%;
}

.message-row.assistant {
  align-self: flex-start;
}

.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-row .bubble {
  max-width: 100%;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: #efe6d8;
  border: 2px solid #fff;
  box-shadow: 0 4px 10px rgba(28, 25, 20, 0.12);
  flex-shrink: 0;
}

.avatar.lg {
  width: 72px;
  height: 72px;
}

.avatar.sm {
  width: 32px;
  height: 32px;
}

.bubble.pending {
  opacity: 0.7;
}

.bubble.proactive {
  border: 1px solid rgba(214, 168, 92, 0.55);
  box-shadow: 0 0 0 1px rgba(214, 168, 92, 0.12);
}

.proactive-tag {
  display: block;
  margin-bottom: 6px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #c48a2a;
}

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

.persona-panel .panel-actions {
  width: 100%;
}

.persona-panel .panel-actions button {
  flex: 1 1 auto;
  white-space: nowrap;
  padding-left: 10px;
  padding-right: 10px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.composer-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}

.memory-mode {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted, #6b6258);
}

.memory-mode select {
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  text-transform: none;
  letter-spacing: normal;
}

button.danger {
  color: #a33a2b;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tier-badge {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: #ece6dc;
  color: #5c5247;
}

.tier-badge.tier-4 {
  background: #e3ecf7;
  color: #2f5785;
}

.tier-badge.tier-5,
.tier-badge.tier-6 {
  background: #f6e2dc;
  color: #9a3a26;
}

.memory-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.memory-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.memory-card .type {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
  }

  .memory-drawer {
    position: fixed;
    top: 12px;
    right: 12px;
    bottom: 12px;
    width: min(360px, calc(100vw - 24px));
    z-index: 5;
    transform: translateX(110%);
    transition: transform 0.2s ease;
  }

  .memory-drawer.open {
    transform: none;
  }
}

@media (min-width: 981px) {
  #memory-toggle,
  #memory-close {
    display: none;
  }
}

.field .user-label {
  display: inline-block;
  font-size: 14px;
  letter-spacing: normal;
  text-transform: none;
  color: inherit;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}


/* --- V1.3 accounts --------------------------------------------------------- */
[hidden] {
  display: none !important;
}

.account-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.auth-card {
  width: min(440px, calc(100vw - 32px));
}

.auth-card form {
  display: grid;
  gap: 10px;
}

.auth-card .field {
  margin: 0;
}

.auth-card .status {
  margin: 0;
  min-height: 0;
}

.auth-card .status:empty {
  display: none;
}

.auth-card #auth-intro {
  margin: 0 0 2px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 4px 0 14px;
  padding: 4px;
  border-radius: 12px;
  background: #f1ebe2;
}

.auth-tabs .tab {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 8px 10px;
  border-radius: 9px;
  box-shadow: none;
}

.auth-tabs .tab.active {
  background: #fff;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(60, 40, 20, 0.12);
}

.auth-card input[type="email"],
.auth-card input[type="password"],
.auth-card input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit;
}

.auth-card small.muted {
  font-size: 12px;
}

#auth-modal:not(.signup) .signup-only {
  display: none !important;
}

.check {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 14px;
  line-height: 1.4;
}

.check input {
  margin-top: 3px;
}

.check a {
  color: inherit;
  text-decoration: underline;
}

.account-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}

.danger-zone {
  margin-top: 8px;
  padding: 12px;
  border: 1px solid #ecc9bf;
  border-radius: 12px;
  background: #fdf3f0;
}

.danger-zone summary {
  cursor: pointer;
  font-weight: 600;
  color: #a33a2b;
}

.danger-zone[open] {
  display: grid;
  gap: 10px;
}

button.danger-solid {
  background: #a33a2b;
  border-color: #a33a2b;
  color: #fff;
}

/* V1.4 crisis resources card */
.safety-card {
  align-self: stretch;
  max-width: 560px;
  margin: 4px 0 4px 44px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.safety-card p {
  margin: 6px 0;
  color: var(--ink);
}

.safety-title {
  font-size: 1rem;
}

.safety-card ul {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.safety-card li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
}

.safety-name {
  font-weight: 600;
}

.safety-contact {
  font-weight: 700;
  color: var(--accent);
  font-size: 1.05rem;
}

.safety-note,
.safety-emergency {
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 640px) {
  .safety-card {
    margin-left: 0;
  }
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 14px;
  color: var(--accent);
  text-decoration: none;
}

.button-link[hidden] {
  display: none;
}
