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

.chat-invite {
  min-height: 126px;
  display: flex;
  align-items: center;
  gap: 26px;
  padding: 18px 38px;
  border: 1px solid rgba(222, 184, 88, .28);
  border-top: 0;
  background: linear-gradient(100deg, #2b1b13, #1b120e 58%, #21170f);
}
.chat-invite-portrait { width: 68px; height: 68px; flex: none; overflow: hidden; border-radius: 50%; border: 1px solid rgba(245, 217, 133, .65); }
.chat-invite-portrait img { width: 100%; height: 100%; object-fit: cover; object-position: 42% 22%; transform: scale(1.65); }
.chat-invite-copy { display: flex; flex-direction: column; gap: 4px; }
.chat-invite-copy strong { font-family: var(--display); font-size: clamp(21px, 2vw, 28px); letter-spacing: -.025em; }
.chat-invite-copy > span { color: var(--muted); font-size: 15px; }
.chat-invite-action { margin-left: auto; flex: none; color: var(--gold-light); border-bottom: 1px solid currentColor; padding-bottom: 4px; font-weight: 600; }
.chat-invite-action span { padding-left: 10px; }
.chat-invite:hover .chat-invite-action { color: #fff; }

.chat-hero { max-width: 1510px; padding-top: 42px; padding-bottom: 44px; }
.chat-hero .back-link { margin-bottom: 45px; }
.chat-hero-head { display: flex; justify-content: space-between; align-items: end; gap: 40px; }
.chat-hero h1 { font-family: var(--display); font-size: clamp(49px, 5vw, 80px); line-height: 1.02; letter-spacing: -.045em; margin: 10px 0 0; }
.chat-hero h1 em { font-family: var(--accent); font-weight: 500; color: var(--gold-light); }
.chat-hero-head > p { max-width: 380px; margin: 0 0 4px; color: var(--muted); font-size: 16px; }
.chat-layout { max-width: 1510px; display: grid; grid-template-columns: 288px minmax(0, 1fr); gap: clamp(24px, 3vw, 46px); padding-bottom: 105px; }
.chat-aside { align-self: start; }
.chat-aside-portrait { height: 198px; overflow: hidden; background: #211710; border: 1px solid rgba(222, 184, 88, .22); }
.chat-aside-portrait img { width: 100%; height: 100%; object-fit: cover; object-position: 41% 18%; }
.chat-aside-caption { margin: 28px 0 11px; color: var(--gold-light); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.chat-prompt-list { display: grid; border-top: 1px solid rgba(222, 184, 88, .2); }
.chat-prompt-list button { min-height: 68px; padding: 13px 6px; border: 0; border-bottom: 1px solid rgba(222, 184, 88, .2); background: transparent; color: var(--ink); text-align: left; line-height: 1.35; }
.chat-prompt-list button::after { content: '↗'; float: right; color: var(--gold); font-size: 19px; line-height: 1; }
.chat-prompt-list button:hover { color: var(--gold-light); }
.chat-aside-note { margin-top: 24px; color: var(--muted); font-size: 13px; line-height: 1.6; }

.chat-panel { min-width: 0; height: min(680px, max(570px, 67vh)); display: flex; flex-direction: column; overflow: hidden; border: 1px solid rgba(222, 184, 88, .34); border-radius: 9px; background: radial-gradient(circle at 50% -30%, rgba(117, 72, 27, .14), transparent 48%), #1b120e; box-shadow: 0 22px 55px rgba(0, 0, 0, .2); }
.chat-panel-head { min-height: 83px; display: flex; align-items: center; gap: 14px; padding: 16px 25px; border-bottom: 1px solid rgba(222, 184, 88, .18); }
.chat-panel-mark { flex: none; display: grid; place-items: center; width: 45px; height: 45px; border: 1px solid rgba(222, 184, 88, .6); border-radius: 50%; color: var(--gold-light); font-family: var(--accent); font-size: 29px; }
.chat-panel-head > div { display: flex; flex-direction: column; gap: 2px; }
.chat-panel-head strong { font-family: var(--display); font-size: 17px; line-height: 1.2; }
.chat-panel-head div span { color: var(--muted); font-size: 12px; }
.chat-clear { min-height: 44px; margin-left: auto; padding: 0 2px; border: 0; background: transparent; color: var(--gold-light); font-size: 13px; }
.chat-clear:hover { color: #fff; }
.chat-transcript { flex: 1; min-height: 0; overflow-y: auto; padding: 28px clamp(22px, 3vw, 47px); scrollbar-color: #73502c transparent; }
.chat-message { max-width: min(78%, 66ch); margin: 0 0 21px; }
.chat-message[data-role="user"] { margin-left: auto; padding: 15px 19px; border: 1px solid rgba(222, 184, 88, .27); border-radius: 13px 13px 2px 13px; background: #322116; }
.chat-message[data-role="assistant"] { padding-left: 20px; border-left: 1px solid var(--gold); }
.chat-message-label { display: block; margin: 0 0 7px; color: var(--gold-light); font-size: 12px; font-weight: 700; }
.chat-message-label[hidden] { display: none; }
.chat-message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.chat-message-actions { display: flex; align-items: center; gap: 17px; margin-top: 10px; }
.chat-message-actions button { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: transparent; color: var(--gold-light); font-size: 12px; }
.chat-message-actions button .ui-icon { width: 15px; height: 15px; }
.chat-message-actions button:hover { color: #fff; }
.chat-message-context { color: var(--muted); font-size: 11px; }
.chat-thinking-stage { display: flex; align-items: center; gap: 22px; min-height: 96px; }
.chat-thinking-cards { display: block; position: relative; flex: none; width: 148px; height: 84px; perspective: 500px; }
.chat-thinking-cards i { position: absolute; top: 9px; left: var(--slot); display: grid; place-items: center; width: 46px; height: 66px; border: 1px solid #c39c4e; border-radius: 4px; background: linear-gradient(150deg, #3b281a, #160e0b 65%, #2d1c13); box-shadow: inset 0 0 0 4px #1c120d, inset 0 0 0 5px rgba(245, 217, 133, .32), 0 8px 16px #0d0806; transform-origin: 50% 82%; animation: chat-card-search 1.8s cubic-bezier(.22, 1, .36, 1) infinite; }
.chat-thinking-cards i:nth-child(1) { --fan: -10deg; --slot: 0px; animation-delay: -.25s; }
.chat-thinking-cards i:nth-child(2) { --fan: -5deg; --slot: 24px; animation-delay: -.1s; }
.chat-thinking-cards i:nth-child(3) { --fan: 0deg; --slot: 48px; animation-delay: .05s; }
.chat-thinking-cards i:nth-child(4) { --fan: 5deg; --slot: 72px; animation-delay: .2s; }
.chat-thinking-cards i:nth-child(5) { --fan: 10deg; --slot: 96px; animation-delay: .35s; }
.chat-thinking-cards svg { width: 21px; height: 21px; fill: none; stroke: #efd281; stroke-width: 1.35; stroke-linejoin: round; }
.chat-thinking-line { display: inline-flex; align-items: baseline; gap: 7px; color: var(--gold-light); font-family: var(--accent); font-size: 18px; font-style: italic; white-space: nowrap; }
.chat-thinking-dots { display: inline-flex; gap: 4px; }
.chat-thinking-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--gold); animation: chat-pulse 1.1s ease-in-out infinite; }
.chat-thinking-dots i:nth-child(2) { animation-delay: .14s; }
.chat-thinking-dots i:nth-child(3) { animation-delay: .28s; }
@keyframes chat-card-search { 0%, 100% { opacity: .75; transform: rotate(var(--fan)) rotateY(0deg); } 46% { opacity: 1; transform: translateY(-12px) rotate(0deg) rotateY(88deg); } 58% { opacity: 1; transform: translateY(-12px) rotate(0deg) rotateY(0deg); } 75% { opacity: .9; transform: rotate(var(--fan)); } }
@keyframes chat-pulse { 50% { opacity: .25; transform: translateY(-3px); } }
.chat-error { color: #efc5a1; }
.chat-composer { padding: 0 clamp(20px, 3vw, 43px) 18px; background: #1b120e; border-top: 1px solid rgba(222, 184, 88, .18); }
.chat-locked { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; padding: 18px 0 4px; }
.chat-locked[hidden] { display: none; }
.chat-locked p { max-width: 420px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
[data-chat-prompt]:disabled { opacity: .5; cursor: not-allowed; }
.chat-status { min-height: 18px; margin: 7px 0 5px; color: var(--gold-light); font-size: 12px; }
#chat-form { display: flex; align-items: end; gap: 9px; padding: 7px; border: 1px solid #856135; border-radius: 6px; background: #120c09; }
#chat-form[hidden] { display: none; }
#chat-form:focus-within { border-color: var(--gold-light); }
#chat-input { flex: 1; min-width: 0; max-height: 150px; resize: none; padding: 9px 10px; border: 0; outline: 0; background: transparent; color: var(--ink); color-scheme: dark; scrollbar-color: #755634 transparent; scrollbar-width: thin; font: inherit; font-size: 16px; line-height: 1.5; }
#chat-input::-webkit-resizer { display: none; }
#chat-input::-webkit-scrollbar { width: 6px; }
#chat-input::-webkit-scrollbar-thumb { border-radius: 6px; background: #755634; }
#chat-input::-webkit-scrollbar-track, #chat-input::-webkit-scrollbar-corner { background: transparent; }
#chat-input::placeholder { color: #9d8b7b; }
#chat-send { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 4px; background: var(--gold); color: #1a110b; }
#chat-send svg { width: 23px; height: 23px; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#chat-send:hover { background: var(--gold-light); }
#chat-send:disabled { opacity: .45; cursor: default; }
#chat-stop { flex: none; min-width: 54px; height: 44px; border: 1px solid var(--gold); border-radius: 4px; background: transparent; color: var(--gold-light); font-size: 13px; }
#chat-stop[hidden] { display: none; }
.mobile-nav { grid-template-columns: repeat(5, minmax(0, 1fr)); }

@media (max-width: 900px) {
  .chat-layout { grid-template-columns: 220px minmax(0, 1fr); gap: 20px; }
  .chat-aside-portrait { height: 160px; }
}
@media (max-width: 980px) {
  .chat-hero { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); }
  .chat-layout { display: block; padding: 0; }
  .chat-aside { display: none; }
  .chat-panel { position: fixed; z-index: 10; inset: 80px 0 calc(72px + env(safe-area-inset-bottom)); width: 100%; height: auto; border-left: 0; border-right: 0; border-radius: 0; }
  body:has(#route-chat:not([hidden])) { overflow: hidden; }
}
@media (max-width: 760px) {
  .chat-invite { min-height: 112px; gap: 15px; padding: 19px; }
  .chat-invite-portrait { width: 48px; height: 48px; }
  .chat-invite-copy strong { font-size: 20px; }
  .chat-invite-copy > span { font-size: 13px; }
  .chat-invite-action { display: none; }
  .chat-panel { inset: 72px 0 calc(70px + env(safe-area-inset-bottom)); }
  .chat-panel-head { padding: 12px 16px; min-height: 70px; }
  .chat-panel-head div span { font-size: 11px; }
  .chat-transcript { padding: 22px 16px; }
  .chat-message { max-width: 89%; font-size: 14px; }
  .chat-thinking-stage { gap: 8px; min-height: 86px; }
  .chat-thinking-cards { transform: scale(.79); transform-origin: left center; width: 115px; }
  .chat-thinking-line { font-size: 16px; }
  .chat-composer { padding: 0 13px 13px; }
  .mobile-nav { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .mobile-nav a { min-width: 0; font-size: 10px; }
}
@media (max-width: 370px) {
  .chat-panel-head div span { max-width: 160px; line-height: 1.2; }
  .chat-invite-copy strong { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) { .chat-thinking-dots i, .chat-thinking-cards i { animation: none; } .chat-thinking-cards i { transform: rotate(var(--fan)); } }

/* Greeting: the first message in the transcript, with answer format and a question library. */
.chat-message.chat-greeting { position: relative; max-width: min(92%, 68ch); margin-bottom: 28px; padding-left: 62px; border-left: 0; }
.chat-greeting-avatar { position: absolute; left: 0; top: 0; display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid rgba(222, 184, 88, .55); border-radius: 50%; background: radial-gradient(circle at 50% 35%, #3a2617, #170f0b 70%); box-shadow: 0 6px 18px rgba(0, 0, 0, .35); }
.chat-greeting-avatar img { width: 30px; height: 30px; }
.chat-greeting > p + p { margin-top: 10px; color: var(--muted); }
.chat-format { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 18px 0 20px; }
.chat-format button { display: grid; gap: 3px; padding: 11px 13px; border: 1px solid rgba(222, 184, 88, .26); border-radius: 8px; background: rgba(40, 27, 19, .6); color: var(--ink); text-align: left; transition: border-color var(--motion-base) var(--ease-out), background var(--motion-base) var(--ease-out), transform var(--motion-fast) var(--ease-out); }
.chat-format strong { font-size: 14px; font-weight: 600; }
.chat-format span { color: var(--muted); font-size: 12px; }
.chat-format button:hover { border-color: rgba(222, 184, 88, .55); }
.chat-format button:active { transform: scale(.98); }
.chat-format button[aria-pressed="true"] { border-color: var(--gold); background: linear-gradient(160deg, rgba(222, 184, 88, .2), rgba(222, 184, 88, .06)); }
.chat-format button[aria-pressed="true"] strong { color: var(--gold-light); }
.chat-library { border-top: 1px solid rgba(222, 184, 88, .18); }
.chat-greeting .chat-library-title { margin: 14px 0 4px; color: var(--gold-light); font-family: var(--accent); font-size: 17px; font-style: italic; }
.chat-library-group { border-bottom: 1px solid rgba(222, 184, 88, .14); }
.chat-library-group summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 8px 2px; color: var(--ink); font-size: 14px; cursor: pointer; list-style: none; transition: color var(--motion-fast) ease; }
.chat-library-group summary::-webkit-details-marker { display: none; }
.chat-library-group summary:hover { color: var(--gold-light); }
.chat-library-group summary .ui-icon { width: 15px; height: 15px; color: var(--gold); transition: transform var(--motion-medium) var(--ease-out); }
.chat-library-group[open] summary .ui-icon { transform: rotate(90deg); }
.chat-library-list { display: grid; gap: 6px; padding: 2px 0 14px; }
.chat-library-group[open] .chat-library-list { animation: chat-library-open var(--motion-medium) var(--ease-out); }
.chat-library-list button { padding: 9px 12px; border: 1px solid rgba(222, 184, 88, .18); border-radius: 7px; background: transparent; color: #e9dccd; font-size: 13.5px; line-height: 1.4; text-align: left; transition: border-color var(--motion-fast) ease, color var(--motion-fast) ease, background var(--motion-fast) ease; }
.chat-library-list button:hover { border-color: rgba(222, 184, 88, .5); background: rgba(222, 184, 88, .07); color: var(--gold-light); }
.chat-disclaimer { margin: 8px 2px 0; color: #9f8f80; font-size: 11px; line-height: 1.45; }
@keyframes chat-library-open { from { opacity: 0; transform: translateY(-4px); } }

/* Messages settle in instead of popping; the thinking fan breathes as one slow wave. */
.chat-message { animation: chat-message-in 420ms var(--ease-out) both; }
@keyframes chat-message-in { from { opacity: 0; transform: translateY(8px); filter: blur(3px); } }
.chat-thinking-cards i { animation: chat-card-wave 2.4s cubic-bezier(.45, 0, .55, 1) infinite; transition: none; }
.chat-thinking-cards i:nth-child(1) { animation-delay: 0s; }
.chat-thinking-cards i:nth-child(2) { animation-delay: .16s; }
.chat-thinking-cards i:nth-child(3) { animation-delay: .32s; }
.chat-thinking-cards i:nth-child(4) { animation-delay: .48s; }
.chat-thinking-cards i:nth-child(5) { animation-delay: .64s; }
.chat-thinking-cards svg { animation: chat-star-glow 2.4s cubic-bezier(.45, 0, .55, 1) infinite; animation-delay: inherit; }
@keyframes chat-card-wave {
  0%, 100% { transform: translateY(0) rotate(var(--fan)); opacity: .82; }
  45% { transform: translateY(-10px) rotate(calc(var(--fan) * .35)); opacity: 1; box-shadow: inset 0 0 0 4px #1c120d, inset 0 0 0 5px rgba(245, 217, 133, .55), 0 14px 22px #0d0806; }
}
@keyframes chat-star-glow { 0%, 100% { opacity: .55; filter: none; } 45% { opacity: 1; filter: drop-shadow(0 0 5px rgba(245, 217, 133, .7)); } }
.chat-thinking-dots i { animation: chat-dot-wave 1.4s cubic-bezier(.45, 0, .55, 1) infinite; }
.chat-thinking-dots i:nth-child(2) { animation-delay: .18s; }
.chat-thinking-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes chat-dot-wave { 0%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

@media (max-width: 760px) {
  .chat-message.chat-greeting { max-width: 100%; padding-left: 0; }
  .chat-greeting-avatar { position: static; width: 38px; height: 38px; margin-bottom: 10px; }
  .chat-greeting-avatar img { width: 25px; height: 25px; }
  .chat-format { gap: 6px; }
  .chat-format button { padding: 9px 10px; }
  .chat-format span { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-message, .chat-library-group[open] .chat-library-list, .chat-thinking-cards svg { animation: none; }
}

/* While a reply streams in, a slim gold caret marks where the text is growing. */
.chat-message.is-streaming p::after { content: ""; display: inline-block; width: 2px; height: 1.05em; margin-left: 3px; vertical-align: -0.15em; background: var(--gold-light); animation: chat-caret 1s steps(2, start) infinite; }
@keyframes chat-caret { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .chat-message.is-streaming p::after { animation: none; } }

@media (min-width: 981px) {
  .chat-layout {
    max-width: 1760px;
    grid-template-columns: minmax(260px, 310px) minmax(0, 1fr);
    gap: clamp(28px, 2.5vw, 54px);
    padding-bottom: clamp(150px, 13vh, 220px);
  }
  .chat-panel { height: clamp(760px, 77vh, 980px); }
  .chat-transcript { padding: 34px clamp(32px, 3.2vw, 66px); }
}
