:root {
  --black: #0d0d0d;
  --cream: #fff8de;
  --purple: #c98bff;
  --purple-deep: #b56df5;
  --orange: #ff8a5b;
  --yellow: #ffdf3d;
  --peach: #f6b69c;
  --ink: #111;
  --radius: 22px;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "DM Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
button, .btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 0% 0%, #c9c2c4 0%, transparent 45%),
    radial-gradient(100% 90% at 100% 100%, #efd0ff 0%, transparent 55%),
    linear-gradient(115deg, #e6a58c 0%, #f7b9a0 45%, #f4c3d0 75%, #ecd2f7 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); letter-spacing: -0.02em; margin: 0; line-height: 1.02; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- doodles ---------- */
.doodles { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.d { position: absolute; filter: drop-shadow(2px 3px 0 rgba(0,0,0,.08)); animation: bob 6s ease-in-out infinite; }
.d-bird   { width: 86px;  top: 2%;   left: 6%; }
.d-spark1 { width: 38px;  top: 6%;   left: 30%; animation-delay: -2s; }
.d-star   { width: 84px;  top: 40%;  left: 1.5%; animation-delay: -1s; }
.d-heart  { width: 54px;  top: 44%;  left: 32%; animation-delay: -3s; }
.d-bolt   { width: 34px;  top: 60%;  right: 30%; animation-delay: -4s; }
.d-cloud  { width: 100px; top: 1%;   left: 38%; animation-delay: -2.5s; }
.d-moon   { width: 54px;  top: 48%;  right: 2%; animation-delay: -1.5s; }
.d-cherry { width: 90px;  top: 3%;   right: 3%; animation-delay: -3.5s; }
.d-planet { width: 110px; bottom: 2%; left: 46%; animation-delay: -.5s; }
.d-ast1   { width: 24px;  bottom: 8%; left: 4%; }
.d-ast2   { width: 22px;  top: 20%;  right: 34%; }
.d-ast3   { width: 26px;  bottom: 4%; right: 8%; }
.d-star2  { width: 34px;  bottom: 6%; left: 22%; animation-delay: -2s; }
.d-zig    { width: 110px; top: 30%;  right: 31%; animation-delay: -4.5s; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-8px) rotate(4deg); } }
@media (prefers-reduced-motion: reduce) { .d { animation: none; } }

/* ---------- cards ---------- */
.card-black  { background: var(--black); color: #fff; }
.card-cream  { background: var(--cream); }
.card-purple { background: var(--purple); }
.logo { font-family: var(--display); font-weight: 800; font-size: 1.6rem; margin: 0; }
.logo span { color: var(--yellow); margin-left: 4px; -webkit-text-stroke: 1.5px var(--ink); }
.card-black .logo span { -webkit-text-stroke: 0; }
.logo.small { font-size: 1.25rem; }
.logo { display: flex; align-items: center; gap: 10px; }
.logo { letter-spacing: -0.035em; }
.logo-mark { width: 2.1em; height: 2.1em; flex: none; filter: drop-shadow(0 3px 0 rgba(0,0,0,.28)); } /* the mark has its own ink outline */
.logo span { display: none; } /* the mark carries the spark now */
.logo.small .logo-mark { width: 1.9em; height: 1.9em; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 2.5px solid var(--ink); border-radius: 999px; padding: 12px 22px;
  font-weight: 700; cursor: pointer; text-decoration: none;
  box-shadow: 3px 3px 0 var(--ink); transition: transform .12s, box-shadow .12s;
}
.btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; }
.btn-black { background: var(--black); color: #fff; }
.btn-yellow { background: var(--yellow); }
.btn.wide { width: 100%; }
.chip { border-radius: 999px; padding: 6px 14px; cursor: pointer; font-weight: 600; font-size: .85rem; }
.chip-ghost { background: transparent; border: 1.5px solid rgba(255,255,255,.5); color: #fff; }
.chip-ghost-dark { background: transparent; border: 1.5px solid var(--ink); }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ---------- landing ---------- */
.landing {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 40px;
  max-width: 1180px; margin: 0 auto; padding: 90px 32px 70px; align-items: start;
}
.hero-card { border-radius: var(--radius); padding: 28px; min-height: 560px; display: flex; flex-direction: column; }
.hero-card:nth-child(2) { margin-top: 36px; }
.hero-card h1 { font-size: clamp(1.9rem, 2.6vw, 2.4rem); margin-top: auto; padding-top: 24px; }
.hero-card h2 { font-size: clamp(1.6rem, 2.3vw, 2.1rem); }
.arch {
  border-radius: 999px 999px 0 0; overflow: hidden; position: relative;
}
.arch-hero { background: #cfc5c3; height: 300px; margin: 0 6px; display: flex; align-items: flex-end; padding: 22px 16px; }
.bubble-stack { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.b { padding: 9px 13px; border-radius: 18px; font-size: .9rem; max-width: 85%; color: var(--ink); border: 2px solid var(--ink); }
.b-them { background: #fff; align-self: flex-start; border-bottom-left-radius: 4px; }
.b-me { background: var(--yellow); align-self: flex-end; border-bottom-right-radius: 4px; }
.how { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 14px; }
.how li { display: flex; gap: 12px; align-items: flex-start; font-size: 1.02rem; line-height: 1.4; }
.how b {
  flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--orange); border: 2px solid var(--ink); font-family: var(--display);
}
.card-purple .btn { margin-top: 14px; }
.card-purple h2 { margin: 18px 0 18px; }

/* Instagram-branded connect button */
.btn-ig {
  background: linear-gradient(95deg, #feda75, #fa7e1e 28%, #d62976 58%, #962fbf 80%, #4f5bd5);
  color: #fff; position: relative; overflow: hidden;
}
.ig-glyph { width: 22px; height: 22px; flex: none; }
.ig-spinner {
  display: none; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin .7s linear infinite;
}
.btn-ig.connecting { pointer-events: none; }
.btn-ig.connecting .ig-spinner { display: inline-block; }
.btn-ig.connecting .ig-glyph { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ig-spinner { animation: none; } }
.secured { font-size: .82rem; margin: 12px 2px 0; line-height: 1.4; opacity: .9; }
.secured .lock { margin-right: 4px; }
.or { text-align: center; font-size: .85rem; opacity: .7; margin: 14px 0 0; font-weight: 700; }
.note { font-size: .9rem; background: rgba(255,255,255,.55); padding: 10px 12px; border-radius: 12px; margin: 16px 0 0; }
.note.error { background: #ffe1d6; border: 1.5px solid var(--ink); }
.fine { font-size: .8rem; margin-top: auto; padding-top: 20px; opacity: .8; }
.fine a { color: inherit; font-weight: 700; }
.side-links { margin: auto 0 0; padding-top: 14px; font-size: .78rem; opacity: .65; }
.side-links a { color: inherit; }

/* ---------- app ---------- */
.app {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: 300px minmax(0, 1fr) 360px; gap: 28px;
  max-width: 1320px; margin: 0 auto; padding: 60px 28px 40px; height: 100vh; min-height: 640px;
}
.panel { border-radius: var(--radius); padding: 22px; display: flex; flex-direction: column; min-height: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-title { font-size: 1.7rem; margin: 18px 0 14px; }
.who { font-size: .85rem; opacity: .8; margin: 10px 0 0; }
.tag { background: var(--yellow); color: var(--ink); border-radius: 999px; padding: 1px 8px; font-size: .72rem; font-weight: 700; margin-left: 4px; }

/* inbox */
.thread-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; overflow-x: hidden; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; align-content: start; }
.thread {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left;
  background: transparent; border: 1.5px solid transparent; border-radius: 16px; padding: 10px; cursor: pointer; color: #fff;
}
.thread:hover { background: #1f1f1f; }
.thread[aria-current="true"] { background: #232323; border-color: var(--purple); }
.thread-meta { min-width: 0; flex: 1; }
.thread-name { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.thread-name time { font-weight: 400; font-size: .75rem; opacity: .6; }
.thread-preview { font-size: .85rem; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar {
  flex: none; width: 46px; height: 52px; display: grid; place-items: center;
  font-family: var(--display); font-weight: 800; font-size: 1.2rem; color: var(--ink);
  border: 2px solid var(--ink);
}
.arch-avatar { border-radius: 999px 999px 8px 8px; }
.card-black .avatar { border-color: #fff; }

/* chat */
.chat { padding: 0; overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 14px; padding: 20px 22px 16px; border-bottom: 2px dashed rgba(0,0,0,.15); }
.chat-head h2 { font-size: 1.6rem; }
.chat-head .avatar { background: var(--peach); }
.handle { margin: 2px 0 0; font-size: .85rem; opacity: .65; }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 75%; padding: 11px 15px; border-radius: 20px; border: 2px solid var(--ink); line-height: 1.4; word-wrap: break-word; animation: pop .25s ease-out; }
.msg.them { align-self: flex-start; background: #fff; border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--purple); border-bottom-right-radius: 6px; }
.msg time { display: block; font-size: .7rem; opacity: .55; margin-top: 4px; }
@keyframes pop { from { transform: scale(.95); opacity: 0; } to { transform: none; opacity: 1; } }
.empty { margin: auto; text-align: center; opacity: .6; }
.composer { display: flex; gap: 10px; padding: 14px 18px 18px; border-top: 2px dashed rgba(0,0,0,.15); align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 2px solid var(--ink); border-radius: 18px; padding: 11px 14px; background: #fff; min-height: 48px;
}

/* coach */
.coach { overflow-y: auto; }
.panel-title.dark { margin-top: 0; }
.coach-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.coach-head .panel-title { margin-bottom: 14px; }
.coach-close, #btn-coach { display: none; } /* phones only, see the responsive block */
.tones { display: flex; flex-wrap: wrap; gap: 8px; }
.tone {
  border: 2px solid var(--ink); background: #fff; border-radius: 999px; padding: 7px 13px;
  cursor: pointer; font-weight: 600; font-size: .9rem; transition: transform .1s;
}
.tone:hover { transform: rotate(-2deg) scale(1.04); }
.tone[aria-checked="true"] { background: var(--ink); color: #fff; box-shadow: 2px 2px 0 var(--yellow); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.coach label { display: grid; gap: 5px; font-weight: 700; font-size: .85rem; }
.coach select, .coach input {
  border: 2px solid var(--ink); border-radius: 12px; padding: 9px 10px; background: #fff; font-weight: 500; width: 100%;
}
.notes { margin: 12px 0 16px; }
.results { margin-top: 18px; display: grid; gap: 12px; }
.vibe { background: var(--black); color: #fff; border-radius: 16px; padding: 12px 14px; font-size: .9rem; }
.vibe b { color: var(--yellow); }
.reply {
  background: var(--cream); border: 2px solid var(--ink); border-radius: 18px; padding: 13px 14px;
  box-shadow: 3px 3px 0 var(--ink); animation: pop .3s ease-out both;
}
.reply:nth-child(4) { animation-delay: .06s; } .reply:nth-child(5) { animation-delay: .12s; }
.results-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -2px; z-index: 2; background: var(--purple); padding: 2px 0 6px; font-family: var(--display); font-size: 1.05rem; }
.refresh {
  display: inline-flex; align-items: center; gap: 6px; border: 2px solid var(--ink); background: var(--yellow); border-radius: 999px;
  padding: 7px 14px; font: 700 .85rem var(--body); cursor: pointer; box-shadow: 2px 2px 0 var(--ink);
}
.refresh:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
.refresh-icon { display: inline-block; font-size: 1.05rem; line-height: 1; }
.results.busy { pointer-events: none; }
.results.busy .reply, .results.busy .vibe, .results.busy .tip { opacity: .45; transition: opacity .15s; }
.results.busy .refresh-icon { animation: spin .8s linear infinite; }
@media (prefers-reduced-motion: reduce) { .results.busy .refresh-icon { animation: none; } }
.reply p { margin: 0; font-weight: 600; line-height: 1.4; }
.reply small { display: block; margin-top: 6px; opacity: .7; line-height: 1.35; }
.reply-actions { display: flex; gap: 8px; margin-top: 10px; }
.reply-actions button { border: 1.5px solid var(--ink); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: .8rem; font-weight: 700; cursor: pointer; }
.reply-actions button.primary { background: var(--yellow); }
.tip { background: var(--orange); border: 2px solid var(--ink); border-radius: 18px; padding: 12px 14px; font-size: .9rem; }
.tip b { font-family: var(--display); }
.loading { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 18px; font-weight: 700; }
.loading span { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); animation: dot 1s infinite; }
.loading span:nth-child(2) { animation-delay: .15s; background: var(--yellow); }
.loading span:nth-child(3) { animation-delay: .3s; background: var(--orange); }
@keyframes dot { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.err { background: #ffe1d6; border: 2px solid var(--ink); border-radius: 14px; padding: 10px 12px; font-size: .9rem; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 600;
  box-shadow: 3px 3px 0 var(--yellow); width: max-content; max-width: calc(100vw - 32px); text-align: center;
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .app { grid-template-columns: 260px minmax(0, 1fr); height: auto; }
  .app .coach { grid-column: 1 / -1; }
  .app .chat { height: 70vh; }
  .app .inbox { max-height: 70vh; }
}
@media (max-width: 900px) {
  .landing { grid-template-columns: 1fr; gap: 24px; padding: 70px 16px 40px; }
  .landing .card-purple { order: -1; } /* sign-in card first, so it's on screen without scrolling */
  .hero-card { min-height: 0; }
  .hero-card:nth-child(2) { margin-top: 0; }
  .arch-hero { height: 240px; }
  .d-cloud, .d-zig, .d-heart, .d-planet { display: none; }
}
@media (max-width: 760px) {
  body { background-attachment: scroll; } /* fixed backgrounds stutter on iOS */
  .d { animation: none; }
  .landing { padding: 52px 14px 28px; gap: 18px; }
  .hero-card { padding: 22px 18px; }
  .hero-card h1 { padding-top: 14px; }
  .arch-hero { height: 240px; margin: 0; border-radius: 150px 150px 0 0; } /* a flatter arch so the bubbles aren't clipped */
  .btn { min-height: 48px; }

  .app { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 0; gap: 14px; padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); }
  .inbox, .coach { padding: 18px 16px; }
  .panel-title { font-size: 1.5rem; margin: 12px 0 10px; }
  .chip { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; padding: 6px 16px; }
  .thread { padding: 12px 8px; min-height: 64px; }
  .app .inbox { max-height: none; }
  .app.viewing .inbox { display: none; }
  .app:not(.viewing) .chat, .app:not(.viewing) .coach { display: none; }

  /* a chat fills the screen: header on top, messages scroll, composer at the bottom */
  .app.viewing .chat { height: calc(100vh - 28px); height: calc(100dvh - 28px - env(safe-area-inset-bottom)); }
  .chat-head { padding: 12px 14px; gap: 10px; }
  .chat-head h2 { font-size: 1.25rem; }
  .back { display: inline-flex; flex: none; }
  .messages { padding: 14px; }
  .msg { max-width: 88%; overflow-wrap: anywhere; }
  .composer { flex-wrap: wrap; padding: 10px 12px 12px; }
  .composer textarea { flex: 1 1 100%; font-size: 16px; } /* 16px stops iOS zooming in on focus */
  .composer .btn { flex: 1; padding: 10px 14px; }
  #btn-coach { display: inline-flex; }

  /* the reply coach becomes a full-screen sheet over the chat */
  .app.viewing .coach { display: none; }
  .app.viewing.coach-open .coach {
    display: flex; position: fixed; inset: 0; z-index: 30; border-radius: 0; overflow-y: auto; overscroll-behavior: contain;
    padding: calc(14px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  }
  .coach-close { display: inline-flex; }
  .coach select, .coach input { font-size: 16px; min-height: 44px; }
  .tone { padding: 10px 14px; }
  .reply-actions button { padding: 9px 16px; font-size: .85rem; min-height: 40px; }

  .toast { bottom: auto; top: calc(12px + env(safe-area-inset-top)); }
}
