/* =====================================================
   CY | conversation-first home, matches studio styling
   ===================================================== */

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

/* ----------- App shell -----------
   The home page IS the chat: it fills the viewport and never scrolls itself.
   Only the message list scrolls, so the composer is always where you left it.
   Scoped to .cy-page — every other page keeps the normal document flow.

   iOS Safari ignores `overflow:hidden` on the body for touch scrolling and
   rubber-bands the whole page, so a plain overflow lock drifts (vertically and,
   because the closed nav menu overhangs a few px, horizontally too). The
   bulletproof lock is a fixed body pinned to the viewport with rubber-banding
   switched off — then nothing behind it can scroll. */
html:has(.cy-page){ height: 100%; overflow: hidden; }

.cy-page{
  position: fixed;
  /* --app-height / --vv-offset are set from the visual viewport by main.js, so
     the shell shrinks to sit above the on-screen keyboard and tracks iOS's
     viewport offset. Both fall back to a full-height, top-anchored shell. */
  top: var(--vv-offset, 0px); left: 0; right: 0;
  height: var(--app-height, 100dvh);
  /* .cy-page is the <body>, which base styles give min-height:100vh — that would
     pin the shell at full height and stop it shrinking for the keyboard. */
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
  display: flex;
  flex-direction: column;
  transition: height .16s ease-out;
}

.cy-page main{
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.cy{
  flex: 1;
  min-height: 0;
  display: flex; flex-direction: column;
  padding-top: calc(80px + var(--safe-top));
  padding-bottom: 10px;
  width: 100%;
}

.cy__head{ flex: none; text-align: center; padding: 4px 0 14px; }

.cy__title{
  font-family: var(--display);
  font-size: clamp(23px, 1.6vw + 15px, 34px);
  line-height: 1.05;
  letter-spacing: -.03em;
  font-weight: 600;
}

.cy__sub{
  margin-top: 7px;
  font-size: var(--t-sm);
  color: var(--ink-3);
  font-weight: 400;
}

/* ----------- Thread ----------- */
.cy__thread{
  flex: 1;
  min-height: 0;
  display:flex; flex-direction:column;
  border-radius: var(--radius-lg);
  overflow:hidden;
}

.cy__messages{
  flex: 1;
  min-height: 0;
  overflow-y:auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 22px 20px 8px;
  display:flex; flex-direction:column; gap: 14px;
  scroll-behavior:smooth;
}

/* Conversation grows upward from the composer, the way a messaging app reads.
   margin-top:auto rather than justify-content:flex-end — the flex-end version
   makes the earliest messages unreachable once the list overflows. */
/* :first-child would match the <noscript> element that sits here for no-JS
   visitors — invisible, but still the first child. */
.cy__messages > .cy-msg:first-of-type{ margin-top: auto; }

.cy__noscript{ font-size: var(--t-sm); color: var(--ink-2); }
.cy__noscript a{ color: var(--ink); }

/* ----------- Bubbles ----------- */
.cy-msg{ display:flex; gap:10px; align-items:flex-start; max-width: 86%; }
.cy-msg--user{ margin-left:auto; flex-direction:row-reverse; max-width: 72%; }

.cy-msg__avatar{
  width:30px; height:30px; border-radius:50%;
  background: var(--ink); color: var(--linen);
  display:flex; align-items:center; justify-content:center;
  font-size: 11px; font-weight: 540; flex-shrink:0;
  user-select:none;
}

.cy-msg__body{ min-width:0; display:flex; flex-direction:column; gap:8px; }

.cy-msg__bubble{
  background: rgba(255,255,255,.85);
  border: 1px solid var(--hairline);
  border-radius: 6px 16px 16px 16px;
  padding: 11px 15px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  overflow-wrap: break-word;
}

.cy-msg--user .cy-msg__bubble{
  background: var(--ink);
  color: var(--linen);
  border-color: transparent;
  border-radius: 16px 6px 16px 16px;
}

/* Typing dots */
.cy-typing{ display:inline-flex; gap:4px; padding: 4px 2px; }
.cy-typing i{
  width:6px; height:6px; border-radius:50%;
  background: var(--ink-4);
  animation: cy-blink 1.2s infinite ease-in-out;
}
.cy-typing i:nth-child(2){ animation-delay:.18s; }
.cy-typing i:nth-child(3){ animation-delay:.36s; }
@keyframes cy-blink{ 0%,70%,100%{ opacity:.25 } 35%{ opacity:1 } }

/* Escalating line under the dots while the model wakes up on a cold start. */
.cy-typing-note{
  display:block;
  margin-top:7px;
  font-size:12.5px;
  line-height:1.4;
  color: var(--ink-3);
  animation: cy-fade .3s ease;
}
@keyframes cy-fade{ from{ opacity:0 } to{ opacity:1 } }

/* ----------- Chips ----------- */
.cy-chips{ display:flex; flex-wrap:wrap; gap:7px; }

.cy-chip{
  font-family: var(--text);
  font-size: 13px;
  font-weight: 460;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--hairline-2);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease;
}
.cy-chip:hover{ background: rgba(10,10,10,.05); border-color: rgba(10,10,10,.3); }

.cy-chip--primary{ background: var(--ink); color: var(--linen); border-color: var(--ink); }
.cy-chip--primary:hover{ background: var(--ink-2); }

/* ----------- Inline cards ----------- */
.cy-cards{ display:grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap:8px; }

.cy-card{
  display:block;
  background: rgba(255,255,255,.85);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 12px 14px;
  text-decoration:none;
  color: var(--ink);
  transition: border-color .18s ease, transform .18s ease;
}
.cy-card:hover{ border-color: rgba(10,10,10,.3); transform: translateY(-1px); }

.cy-card strong{ display:block; font-size:14px; font-weight:540; margin-bottom:3px; }
.cy-card span{ display:block; font-size:12.5px; color: var(--ink-3); line-height:1.45; margin-bottom:8px; }
.cy-card em{ font-style:normal; font-size:12px; font-weight:480; }
.cy-card em::after{ content:" →"; }

/* ----------- Brief / lead card ----------- */
.cy-brief{
  background: rgba(255,255,255,.9);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 14px;
}

.cy-brief h4{
  font-family: var(--text);
  font-size: 12px; font-weight: 540;
  letter-spacing: .02em;
  margin: 0 0 8px;
}

.cy-brief ul{ margin: 0 0 12px; padding-left: 18px; font-size: 13px; color: var(--ink-2); line-height: 1.6; }

.cy-brief__fields{ display:flex; gap:8px; margin-bottom:8px; }

.cy-brief input{
  flex:1; min-width:0;
  font-family: var(--text);
  /* 16px min, or iOS Safari zooms the page in on focus. */
  font-size: 16px;
  color: var(--ink);
  background: rgba(250,244,228,.6);
  border: 1px solid var(--hairline-2);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
}
.cy-brief input:focus{ border-color: rgba(10,10,10,.4); }

.cy-brief__send{
  font-family: var(--text);
  font-size: 13px; font-weight: 480;
  background: var(--ink); color: var(--linen);
  border: none; border-radius: 999px;
  padding: 9px 18px;
  cursor: pointer;
  transition: background .18s ease;
}
.cy-brief__send:hover{ background: var(--ink-2); }
.cy-brief__send:disabled{ opacity:.55; cursor: default; }

.cy-brief small{ display:block; margin-top:8px; font-size:11px; color: var(--ink-4); }

/* ----------- Composer ----------- */
.cy__composer{
  flex: none;
  display:flex; align-items:center; gap:10px;
  margin: 10px 16px 0;
  background: rgba(255,255,255,.9);
  border: 1px solid var(--hairline-2);
  border-radius: 999px;
  padding: 6px 6px 6px 18px;
}

.cy__input{
  flex:1; min-width:0;
  font-family: var(--text);
  /* 16px min, or iOS Safari zooms the page in on focus. */
  font-size: 16px;
  color: var(--ink);
  background: transparent;
  border: none; outline: none;
}
.cy__input::placeholder{ color: var(--ink-4); }

.cy__send{
  width: 38px; height: 38px; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  background: var(--ink); color: var(--linen);
  border: none; border-radius: 50%;
  cursor: pointer;
  transition: background .18s ease, transform .12s ease;
}
.cy__send svg{ width:16px; height:16px; }
.cy__send:hover{ background: var(--ink-2); }
.cy__send:active{ transform: scale(.94); }

.cy__note{
  flex: none;
  text-align:center;
  font-size: 11.5px;
  color: var(--ink-4);
  padding: 8px 16px 12px;
}
.cy__note a{ color: var(--ink-3); }

.cy__mode{ color: var(--ink-4); }
.cy__mode.is-live{ color: #2f7d4f; }

/* ----------- Footer, trimmed to a single line on the chat page ----------- */
.cy-page .foot{
  flex: none;
  margin-top: 0;
  padding: 0 0 calc(8px + var(--safe-bottom));
  border-top: none;
}

.cy-page .foot__bottom{
  padding-top: 10px;
  gap: 16px;
}

/* ----------- Small screens ----------- */
@media (max-width: 640px){
  .cy{ padding-top: calc(74px + var(--safe-top)); }
  .cy__head{ padding: 2px 0 12px; }
  .cy__messages{ padding: 16px 12px 8px; }
  .cy-msg{ max-width: 94%; }
  .cy-msg--user{ max-width: 84%; }
  .cy__composer{ margin: 8px 10px 0; }
  .cy-brief__fields{ flex-direction: column; }

  /* Tighter chips fit two to a row instead of one, which is worth ~80px of
     conversation on a phone. */
  .cy-chips{ gap: 6px; }
  .cy-chip{ font-size: 12.5px; padding: 6px 11px; }

  /* No footer on phones — the screen belongs to the conversation. The classic
     site is still one tap away in the note under the composer; the other pages
     carry the full footer. */
  .cy-page .foot{ display: none; }
}

/* ----------- Short viewports (landscape phones, zoomed-in browsers) -----------
   Give the conversation the room instead of the chrome. */
@media (max-height: 620px){
  .cy{ padding-top: calc(72px + var(--safe-top)); }
  .cy__head{ padding: 0 0 8px; }
  .cy__title{ font-size: 20px; }
  .cy__sub{ display: none; }
  .cy__note{ padding: 6px 16px 8px; }
  .cy-page .foot__bottom{ padding-top: 6px; }
}
