/* Peakxy — mobile-first, scales up to desktop.
   Tokens: paper #F5F6F4 · surface #FFFFFF · ink #101418 · muted #5C6570
   accent (cobalt) #2743E8 · youtube #E5484D · instagram #D6409F */

:root {
  --paper: #f5f6f4;
  --paper-2: #eef0ec;
  --surface: #ffffff;
  --ink: #101418;
  --muted: #5c6570;
  --line: #e3e6e2;
  --accent: #2743e8;
  --accent-ink: #ffffff;
  --yt: #e5484d;
  --ig: #d6409f;
  --radius: 16px;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --paper: #14161a;
  --paper-2: #0d0f12;
  --surface: #1c1f24;
  --ink: #f1f2f4;
  --muted: #9aa1ab;
  --line: #2c3038;
  --accent: #5b7cff;
  --accent-ink: #ffffff;
  --yt: #ff6b70;
  --ig: #ec6bc2;
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  position: fixed;
  inset: 0;
  width: 100%;
  margin: 0;
  font-family: var(--body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- layout ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 720px;
  margin: 0 auto;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: calc(22px + env(safe-area-inset-top)) 18px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  flex-shrink: 0;
}
.back {
  align-self: center;
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  margin: -2px 2px -2px -6px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
}
.back:hover { border-color: var(--accent); color: var(--accent); }
.back[hidden] { display: none; }
.wordmark {
  font-family: var(--display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.02em;
}
.wordmark .caret { color: var(--accent); margin-left: 1px; }
.tagline {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.clear-btn {
  align-self: center;
  margin-left: auto;
  flex-shrink: 0;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.clear-btn:hover { border-color: var(--yt); color: var(--yt); }
.clear-btn[hidden] { display: none; }

/* ---------- DM-style chat header (who you're messaging) ---------- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-shrink: 0;
}
.chat-header[hidden] { display: none; }
.chat-header .avatar {
  position: relative;
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--display);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.02em;
}
.chat-header .avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-header-info { min-width: 0; }
.chat-header-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.chat-header-sub {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.new-chat-btn {
  margin-left: auto;
  flex-shrink: 0;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.new-chat-btn:hover { border-color: var(--accent); color: var(--accent); }

.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px 24px;
  scroll-behavior: smooth;
}
.chat[hidden] { display: none; }

/* ---------- picker (choose an influencer) ---------- */
.picker {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px 28px;
}
.picker[hidden] { display: none; }
.picker-head { padding: 8px 6px 4px; }
.picker-head p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
  margin: 0 0 22px;
}
.agent-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.agent-card {
  font: inherit;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.agent-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.agent-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.agent-card .avatar {
  flex-shrink: 0;
  width: 52px; height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--display);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.agent-card .avatar img { width: 100%; height: 100%; object-fit: cover; }
.agent-info { min-width: 0; }
.agent-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}
.agent-tag {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.4;
  margin-top: 2px;
}
.picker-empty {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}

/* custom-agent cards + the create card */
.agent-card-wrap { position: relative; display: flex; }
.agent-card-wrap .agent-card { flex: 1; }
.agent-del {
  position: absolute;
  top: 8px; right: 8px;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.agent-del:hover { border-color: var(--yt); color: var(--yt); }
.agent-name .badge {
  margin-left: 8px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 5px;
  padding: 1px 5px;
  vertical-align: middle;
}
.agent-card.create { border-style: dashed; }
.agent-card.create:hover { border-style: solid; }
.agent-card .avatar.plus {
  background: var(--paper);
  color: var(--accent);
  border: 1px dashed var(--accent);
  font-size: 26px;
  font-weight: 400;
}

/* ---------- builder (create a custom agent) ---------- */
.builder {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px 28px;
}
.builder[hidden] { display: none; }
.build-form { display: flex; flex-direction: column; gap: 18px; max-width: 560px; }
.b-head h2 {
  font-family: var(--display);
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -0.02em;
  margin: 4px 0 4px;
}
.b-head p { color: var(--muted); font-size: 14px; margin: 0; }
.b-field { display: flex; flex-direction: column; gap: 7px; }
.b-label {
  font-family: var(--display);
  font-weight: 700;
  font-size: 14.5px;
}
.b-field input[type="text"],
.b-field textarea {
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  resize: vertical;
}
.b-field input:focus-visible,
.b-field textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
.b-hint { color: var(--muted); font-size: 12.5px; line-height: 1.4; margin: 0; }
.b-sources { display: flex; flex-direction: column; gap: 8px; }
.b-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  font-size: 15px;
}
.b-check:hover { border-color: var(--accent); }
.b-check input { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.b-error { color: var(--yt); font-size: 13.5px; margin: 0; }
.b-error[hidden] { display: none; }
.b-actions { display: flex; gap: 10px; margin-top: 2px; }
.b-btn {
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  padding: 12px 20px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  flex: 1;
}
.b-btn.ghost {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.b-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- empty state ---------- */
.empty { padding: 12vh 6px 0; }
.empty h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(34px, 9vw, 52px);
  letter-spacing: -0.03em;
  line-height: 1.02;
  margin: 0 0 12px;
}
.empty p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
  max-width: 46ch;
  margin: 0 0 22px;
}
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit;
  font-size: 14px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- messages ---------- */
.msg {
  max-width: 88%;
  margin-bottom: 14px;
  animation: rise 0.25s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .msg { animation: none; }
  .chat { scroll-behavior: auto; }
}

.msg.user {
  margin-left: auto;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 11px 15px;
  border-radius: var(--radius);
  border-bottom-right-radius: 6px;
  font-size: 15px;
  line-height: 1.5;
}
.msg.bot {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 13px 15px;
  border-radius: var(--radius);
  border-bottom-left-radius: 6px;
  font-size: 15px;
  line-height: 1.6;
}
.msg.bot.error { border-color: var(--yt); color: var(--yt); }

/* typing indicator */
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); opacity: 0.4;
  animation: blink 1.1s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 40% { opacity: 1; } }

/* ---------- source receipts (signature element) ---------- */
.sources { margin-top: 12px; display: grid; gap: 8px; }
.receipt {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 10px;
  padding: 10px 12px;
}
.receipt:hover { border-color: var(--accent); border-left-width: 4px; }
.receipt.youtube  { border-left-color: var(--yt); }
.receipt.instagram { border-left-color: var(--ig); }
.receipt .meta { min-width: 0; }
.receipt .title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.receipt .sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
  display: flex;
  gap: 8px;
}
.receipt .stamp {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 7px;
  white-space: nowrap;
  background: var(--surface);
}

/* ---------- composer ---------- */
.composer {
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--paper);
  flex-shrink: 0;
}
.composer form { display: flex; gap: 8px; }
#input {
  flex: 1;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
}
#input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
#send {
  width: 46px; height: 46px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
#send:disabled { opacity: 0.5; cursor: default; }
#send:focus-visible, .chip:focus-visible, .receipt:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- desktop ---------- */
@media (min-width: 760px) {
  body { background: linear-gradient(var(--paper), var(--paper-2)); }
  .app {
    height: calc(100dvh - 48px);
    margin: 24px auto;
    border: 1px solid var(--line);
    border-radius: 20px;
    overflow: hidden;
    background: var(--paper);
    box-shadow: 0 12px 40px rgba(16, 20, 24, 0.07);
  }
  .chat { padding: 24px 28px; }
  .msg { max-width: 76%; }
  .picker { padding: 24px 28px 32px; }
  .agent-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- password gate ---------- */
.gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  background: var(--paper);
}
.gate[hidden] { display: none; }
.gate-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 40px rgba(16, 20, 24, 0.07);
  text-align: center;
}
.gate-sub {
  margin: -6px 0 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}
.gate-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
}
.gate-input:focus {
  outline: none;
  border-color: var(--accent);
}
.gate-error {
  margin: -6px 0 0;
  color: var(--yt);
  font-size: 12px;
}
.gate-btn {
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.gate-btn:hover { opacity: 0.92; }
.theme-toggle {
  display: flex;
  width: 100%;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
}
.theme-opt {
  flex: 1;
  padding: 8px 10px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.theme-opt[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(16, 20, 24, 0.08);
}
