:root {
  color-scheme: light;
  --page: #f3f8ff;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --panel-soft: #f8fbff;
  --ink: #142033;
  --muted: #5f6f86;
  --quiet: #91a0b3;
  --line: #dce8f5;
  --line-strong: #bfd4ea;
  --brand: #5aa7ef;
  --brand-strong: #236ba8;
  --brand-soft: #e6f3ff;
  --brand-tint: #f1f8ff;
  --brand-wash: #edf6ff;
  --blue-tint: #eaf5ff;
  --brand-tint-rgb: 241, 248, 255;
  --brand-rgb: 90, 167, 239;
  --brand-strong-rgb: 35, 107, 168;
  --brand-shadow-rgb: 70, 145, 218;
  --brand-aura-rgb: 214, 235, 255;
  --brand-avatar-rgb: 228, 243, 255;
  --page-top-rgb: 236, 247, 255;
  --brand-gradient-start: #4d9de8;
  --brand-gradient-end: #7cccf7;
  --brand-gradient-soft-end: #79c4f6;
  --danger: #aa5966;
  --shadow-card: 0 1px 2px rgba(29, 68, 110, 0.05);
  --shadow-float: 0 18px 50px rgba(29, 68, 110, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-persona="girlfriend"] {
  --page: #f3f8ff;
  --panel-soft: #f8fbff;
  --line: #dce8f5;
  --line-strong: #bfd4ea;
  --brand: #5aa7ef;
  --brand-strong: #236ba8;
  --brand-soft: #e6f3ff;
  --brand-tint: #f1f8ff;
  --brand-wash: #edf6ff;
  --blue-tint: #eaf5ff;
  --brand-tint-rgb: 241, 248, 255;
  --brand-rgb: 90, 167, 239;
  --brand-strong-rgb: 35, 107, 168;
  --brand-shadow-rgb: 70, 145, 218;
  --brand-aura-rgb: 214, 235, 255;
  --brand-avatar-rgb: 228, 243, 255;
  --page-top-rgb: 236, 247, 255;
  --brand-gradient-start: #4d9de8;
  --brand-gradient-end: #7cccf7;
  --brand-gradient-soft-end: #79c4f6;
}

:root[data-persona="boyfriend"] {
  --page: #fff7fa;
  --panel-soft: #fff9fb;
  --line: #f0dce5;
  --line-strong: #e5b8cb;
  --brand: #f08ab2;
  --brand-strong: #b94773;
  --brand-soft: #ffe8f1;
  --brand-tint: #fff5f9;
  --brand-wash: #fff0f6;
  --blue-tint: #fff1f6;
  --brand-tint-rgb: 255, 245, 249;
  --brand-rgb: 240, 138, 178;
  --brand-strong-rgb: 185, 71, 115;
  --brand-shadow-rgb: 205, 91, 139;
  --brand-aura-rgb: 255, 219, 232;
  --brand-avatar-rgb: 255, 232, 241;
  --page-top-rgb: 255, 242, 248;
  --brand-gradient-start: #e76c9e;
  --brand-gradient-end: #f6a8c6;
  --brand-gradient-soft-end: #f8b7d1;
}

:root[data-persona="friend"] {
  --page: #f5fbf7;
  --panel-soft: #f8fdf9;
  --line: #d8eadf;
  --line-strong: #abd2b8;
  --brand: #7acb87;
  --brand-strong: #2f8f55;
  --brand-soft: #e9f9ed;
  --brand-tint: #f4fcf6;
  --brand-wash: #eef9f1;
  --blue-tint: #edf9ef;
  --brand-tint-rgb: 244, 252, 246;
  --brand-rgb: 122, 203, 135;
  --brand-strong-rgb: 47, 143, 85;
  --brand-shadow-rgb: 71, 165, 93;
  --brand-aura-rgb: 213, 241, 220;
  --brand-avatar-rgb: 232, 249, 236;
  --page-top-rgb: 238, 250, 241;
  --brand-gradient-start: #55b86b;
  --brand-gradient-end: #95d994;
  --brand-gradient-soft-end: #a6e0a4;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(var(--page-top-rgb), 0.92), transparent 260px),
    linear-gradient(110deg, rgba(var(--brand-aura-rgb), 0.72), transparent 38%),
    linear-gradient(290deg, rgba(255, 255, 255, 0.74), transparent 45%),
    var(--page);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
}

button,
input,
textarea {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.memory-rail {
  display: none;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
  min-width: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(var(--page-top-rgb), 0.82) 180px),
    var(--page);
}

.chat-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(230, 232, 238, 0.86);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(22px) saturate(150%);
}

.identity,
.rail-card,
.section-title,
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.identity {
  justify-content: flex-start;
  min-width: 0;
}

.identity > div:last-child {
  min-width: 0;
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(var(--brand-rgb), 0.22);
  border-radius: 50%;
  overflow: hidden;
  color: var(--brand-strong);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(var(--brand-avatar-rgb), 0.95)),
    var(--panel-solid);
  box-shadow: 0 10px 24px rgba(var(--brand-strong-rgb), 0.12);
  font-weight: 800;
}

.avatar.large {
  width: 64px;
  height: 64px;
  font-size: 22px;
}

.avatar-thumb {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  overflow: hidden;
  background: white;
  box-shadow: 0 8px 18px rgba(35, 107, 168, 0.12);
}

.avatar-image {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.08;
}

h2 {
  font-size: 19px;
  line-height: 1.22;
}

.soft-text {
  color: var(--muted);
  line-height: 1.55;
}

.settings-button,
.icon-button,
.primary-action,
.send-button,
.danger-action {
  border: 0;
  border-radius: 999px;
}

.settings-button,
.icon-button {
  color: var(--ink);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.settings-button {
  min-height: 38px;
  padding: 0 16px;
  color: var(--brand-strong);
  font-weight: 800;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  font-size: 18px;
}

.settings-button:hover,
.icon-button:hover,
.forget-button:hover {
  color: var(--brand);
  border-color: rgba(var(--brand-rgb), 0.32);
  background: var(--brand-tint);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow: auto;
  padding: 24px 16px 20px;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  max-width: min(86%, 760px);
}

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

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

.message-avatar {
  width: 34px;
  height: 34px;
  font-size: 13px;
  box-shadow: 0 6px 16px rgba(var(--brand-strong-rgb), 0.12);
}

.message {
  max-width: min(78%, 720px);
  padding: 12px 15px;
  border-radius: 18px;
  line-height: 1.62;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(20, 24, 36, 0.04);
}

.message.user {
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  color: white;
  background: linear-gradient(135deg, var(--brand), var(--brand-gradient-soft-end));
  box-shadow: 0 8px 22px rgba(var(--brand-shadow-rgb), 0.2);
}

.message.assistant {
  align-self: flex-start;
  border: 1px solid rgba(230, 232, 238, 0.9);
  border-bottom-left-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
}

.message.system {
  align-self: center;
  max-width: min(640px, 92%);
  padding: 9px 14px;
  color: var(--muted);
  border: 1px solid rgba(230, 232, 238, 0.88);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: none;
  font-size: 13px;
  text-align: center;
}

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

.composer {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(230, 232, 238, 0.88);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 -10px 34px rgba(20, 24, 36, 0.05);
  backdrop-filter: blur(22px) saturate(150%);
}

.composer textarea {
  width: 100%;
  min-height: 46px;
  max-height: 128px;
  padding: 12px 15px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 23px;
  color: var(--ink);
  background: var(--panel-solid);
  outline: none;
}

.composer textarea::placeholder,
.field input::placeholder {
  color: var(--quiet);
}

.composer textarea:focus,
.field input:focus {
  border-color: rgba(var(--brand-rgb), 0.5);
  box-shadow: 0 0 0 4px rgba(var(--brand-rgb), 0.12);
}

.send-button,
.primary-action {
  min-height: 46px;
  padding: 0 20px;
  color: white;
  background: linear-gradient(135deg, var(--brand-gradient-start), var(--brand-gradient-end));
  box-shadow: 0 10px 24px rgba(var(--brand-shadow-rgb), 0.24);
  font-weight: 800;
}

.send-button:disabled {
  background: #a9c6de;
  box-shadow: none;
}

.rail-card {
  align-items: flex-start;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow-card);
}

.companion-card {
  justify-content: flex-start;
}

.memory-card {
  display: grid;
  gap: 16px;
}

.reflection-card,
.journey-card,
.pending-card,
.diagnostics-card {
  display: grid;
  gap: 14px;
}

.reflection-list {
  display: grid;
  gap: 10px;
}

.reflection-list article {
  display: grid;
  gap: 5px;
  padding: 12px 0 0;
  border: 0;
  border-top: 1px solid rgba(230, 232, 238, 0.86);
  border-radius: 0;
  background: transparent;
}

.reflection-list article:first-child {
  border-top: 0;
  padding-top: 0;
}

.reflection-list article:hover {
  border-color: rgba(230, 232, 238, 0.86);
}

.reflection-list span {
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 800;
}

.reflection-list p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.memory-list {
  display: grid;
  gap: 10px;
  min-height: 120px;
}

.pending-memory-list,
.journey-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.memory-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(230, 232, 238, 0.86);
  border-radius: 8px;
  background: var(--panel-soft);
}

.pending-memory-item {
  border-color: rgba(var(--brand-rgb), 0.26);
  background: rgba(var(--brand-tint-rgb), 0.86);
}

.pending-memory-input {
  width: 100%;
  min-height: 68px;
  resize: vertical;
  padding: 10px;
  border: 1px solid rgba(230, 232, 238, 0.9);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  line-height: 1.5;
  outline: none;
}

.pending-memory-input:focus {
  border-color: var(--line-strong);
}

.memory-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.memory-action {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(230, 232, 238, 0.9);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 800;
}

.memory-action.primary {
  border-color: transparent;
  color: white;
  background: var(--brand-strong);
}

.journey-item {
  position: relative;
  display: grid;
  gap: 5px;
  padding: 0 0 0 18px;
  color: var(--muted);
  list-style: none;
}

.journey-item::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand-strong);
  box-shadow: 0 0 0 4px rgba(var(--brand-rgb), 0.14);
}

.journey-item.stage::before {
  background: var(--ink);
}

.journey-item strong {
  color: var(--ink);
  font-size: 13px;
}

.journey-item p {
  font-size: 12px;
  line-height: 1.5;
}

.diagnostics-grid {
  display: grid;
  gap: 9px;
}

.diagnostics-grid article {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid rgba(230, 232, 238, 0.82);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.diagnostics-grid span {
  color: var(--brand-strong);
  font-size: 11px;
  font-weight: 800;
}

.diagnostics-grid p {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.memory-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--quiet);
  font-size: 12px;
}

.memory-content {
  color: var(--ink);
  line-height: 1.55;
}

.forget-button {
  border: 0;
  color: var(--brand-strong);
  background: transparent;
  font-size: 12px;
}

.empty {
  color: var(--muted);
  line-height: 1.6;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(23, 24, 28, 0.24);
  backdrop-filter: blur(4px);
}

.settings-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 21;
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: min(420px, 100vw);
  padding: 20px;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: -18px 0 60px rgba(20, 24, 36, 0.16);
  transform: translateX(100%);
  transition: transform 180ms ease;
  backdrop-filter: blur(24px) saturate(145%);
}

.settings-drawer.open {
  transform: translateX(0);
}

.field,
.field-group {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.field span,
.field-group > span {
  color: var(--ink);
  font-weight: 800;
}

.field input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel-solid);
  outline: none;
}

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  max-height: 298px;
  overflow: auto;
  padding: 2px;
}

.avatar-choice {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 86px;
  padding: 8px 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel-solid);
}

.avatar-choice small {
  max-width: 100%;
  overflow: hidden;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-choice.active {
  color: var(--brand-strong);
  border-color: rgba(90, 167, 239, 0.44);
  background: var(--brand-tint);
  box-shadow: 0 0 0 3px rgba(90, 167, 239, 0.1);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--brand-wash);
}

.segment {
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.segment.active {
  color: white;
  background: linear-gradient(135deg, var(--brand-gradient-start), var(--brand-gradient-soft-end));
  box-shadow: 0 8px 18px rgba(var(--brand-shadow-rgb), 0.18);
}

.style-grid {
  display: grid;
  gap: 10px;
}

.style-option {
  display: grid;
  gap: 4px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel-solid);
  text-align: left;
}

.style-option span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.style-option.active {
  border-color: rgba(var(--brand-rgb), 0.38);
  background: var(--brand-tint);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.1);
}

.privacy-box {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  line-height: 1.6;
}

.danger-action {
  min-height: 46px;
  color: var(--danger);
  background: #fff0f2;
  font-weight: 800;
}

.autosave-note {
  color: var(--quiet);
  font-size: 13px;
}

.onboarding {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: start center;
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(var(--page-top-rgb), 0.94), transparent 260px),
    linear-gradient(110deg, rgba(var(--brand-aura-rgb), 0.86), transparent 42%),
    var(--page);
}

.onboarding-card {
  display: grid;
  gap: 16px;
  width: min(520px, 100%);
  margin: 24px 0;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-float);
}

@media (hover: hover) {
  .send-button:hover,
  .primary-action:hover {
    filter: brightness(1.03);
  }

  .style-option:hover,
  .avatar-choice:hover,
  .memory-item:hover,
  .reflection-list article:hover,
  .rail-card:hover {
    border-color: var(--line-strong);
  }
}

@media (min-width: 920px) {
  .app-shell {
    grid-template-columns: 360px minmax(0, 1fr);
  }

  .memory-rail {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    overflow: auto;
    padding: 16px;
    border-right: 1px solid var(--line);
    background: rgba(249, 250, 252, 0.84);
    backdrop-filter: blur(18px) saturate(145%);
  }

  .chat-header {
    padding-left: 28px;
    padding-right: 28px;
  }

  .composer {
    padding-left: 28px;
    padding-right: 28px;
  }

  .messages {
    padding: 30px 28px;
  }

  .message {
    max-width: min(62%, 720px);
  }

  .message-row {
    max-width: min(68%, 760px);
  }

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

@media (max-width: 520px) {
  .chat-header {
    gap: 10px;
    min-height: 64px;
    padding: 10px 12px;
  }

  .settings-button {
    min-width: 0;
    padding: 0 13px;
  }

  .messages {
    padding-left: 12px;
    padding-right: 12px;
  }

  .message {
    max-width: 86%;
  }

  .message-row {
    max-width: 92%;
  }

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

  .avatar-picker {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .composer {
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  }

  .send-button {
    padding: 0 16px;
  }
}
