/* The chat stage. #chatModal is a .stage-panel (see layout.css) laid out as a
   row: the picture of who you're talking to, then the conversation (head,
   a centred reading column, composer). Below 900px the picture goes away and
   the avatar in the head opens it instead. */

#chatModal { background: var(--bg); flex-direction: row; }
.chat-main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* --- The picture --- */
.chat-visual {
  flex: none; width: clamp(300px, 32vw, 460px); display: flex; flex-direction: column; gap: 10px;
  padding: var(--sp-4) 0 var(--sp-5) var(--sp-4);
}
.visual-frame {
  position: relative; flex: 1; min-height: 0; padding: 0; overflow: hidden; cursor: zoom-in;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.visual-frame:hover:not(:disabled) { background: var(--panel); border-color: var(--border); }
.visual-frame img { width: 100%; height: 100%; object-fit: cover; object-position: center 10%; display: block; }
.visual-frame .initial {
  position: absolute; inset: 0; display: grid; place-items: center; font-size: 96px; color: var(--faint);
  font-family: var(--font-display); font-weight: var(--display-weight);
}
.visual-tabs { display: flex; gap: 6px; justify-content: center; min-height: 0; }
.visual-tabs:empty { display: none; }
.visual-tabs button { background: transparent; color: var(--muted); border-color: var(--border); font-weight: 500; font-size: 13px; padding: 5px 14px; border-radius: 999px; }
.visual-tabs button.on { background: var(--panel2); color: var(--text); border-color: color-mix(in srgb, var(--text) 25%, var(--border)); }
.visual-tabs button:hover:not(:disabled) { background: var(--panel2); color: var(--text); border-color: var(--border); }

.msg-image img, .cp-gallery img { cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 56px 72px; cursor: zoom-out;
  background: rgb(var(--veil) / .92); animation: lb-in .15s ease;
}
@keyframes lb-in { from { opacity: 0; } to { opacity: 1; } }
.lb-img { max-width: calc(100vw - 144px); max-height: calc(100vh - 112px); max-height: calc(100dvh - 112px); object-fit: contain; border-radius: var(--radius-md); box-shadow: 0 30px 80px rgba(0, 0, 0, .55); cursor: default; }
.lb-bar { position: absolute; top: 14px; right: 16px; display: flex; align-items: center; gap: 10px; }
.lb-save { color: #fff; font-size: 14px; font-weight: 500; text-decoration: none; padding: 6px 14px; border-radius: 999px; background: rgba(255, 255, 255, .14); cursor: pointer; }
.lb-save:hover { background: rgba(255, 255, 255, .24); }
.lightbox button { color: #fff; background: rgba(255, 255, 255, .14); border: none; }
.lightbox button:hover:not(:disabled) { background: rgba(255, 255, 255, .26); }
.lb-close { width: 40px; height: 40px; padding: 0 0 3px; border-radius: 50%; font-size: 28px; line-height: 1; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; padding: 0 0 4px; border-radius: 50%; font-size: 34px; line-height: 1; }
.lb-nav.prev { left: 14px; }
.lb-nav.next { right: 14px; }
.lb-count { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); color: rgba(255, 255, 255, .8); font-size: 13px; }
@media (max-width: 640px) { .lightbox { padding: 56px 12px; } .lb-img { max-width: calc(100vw - 24px); } .lb-nav { display: none; } }

/* --- Head --- */
.chat-head {
  display: flex; align-items: center; gap: 8px; flex: none; height: 64px;
  padding: 0 var(--sp-4) 0 var(--sp-3);
}
.chat-who {
  display: flex; align-items: center; gap: 12px; min-width: 0; padding: 4px 12px 4px 4px;
  background: transparent; border: none; border-radius: 999px; color: var(--text); text-align: left; font-weight: 400;
}
.chat-who:hover:not(:disabled) { background: var(--panel2); }
.chat-who .avatar { width: 40px; height: 40px; flex: none; }
.chat-who b { font-family: var(--font-display); font-weight: var(--display-weight); letter-spacing: var(--display-track); font-size: 18px; line-height: 1.1; display: block; }
.chat-who .sub { font-size: 12.5px; color: var(--muted); display: block; line-height: 1.2; }
#chatSceneBtn { font-size: 14px; padding: 7px 14px; border-radius: 999px; }

/* Mode menu: one button in the head, a small list under it. */
.mode-menu { position: relative; flex: none; }
.mode-menu[hidden] { display: none; }
.mode-btn { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; padding: 7px 12px 7px 14px; border-radius: 999px; }
.mode-pop {
  display: none; position: absolute; top: calc(100% + 8px); right: 0; z-index: 30; width: 300px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: 0 16px 40px rgb(var(--veil) / .45);
}
.mode-menu.open .mode-pop { display: block; }
.mode-pop hr { border: none; border-top: 1px solid var(--border); margin: 6px 4px; }
.mode-opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; text-align: left;
  background: none; border: none; border-radius: 10px; padding: 9px 12px; color: var(--text); font-weight: 400;
}
.mode-opt:hover:not(:disabled) { background: var(--panel2); border: none; }
.mode-opt .mode-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mode-opt .mode-desc { font-size: 12.5px; color: var(--muted); font-weight: 400; line-height: 1.35; }
.mode-opt.on .mode-name::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.mode-opt:disabled { opacity: .5; cursor: not-allowed; }
.mode-note { align-self: center; text-align: center; font-size: 13px; color: var(--muted); padding: 4px 14px; border: 1px solid var(--border); border-radius: 999px; }

/* Round portrait, or the first letter when there is none. Used all over. */
.avatar {
  position: relative; border-radius: 50%; overflow: hidden; background: var(--panel2);
  border: 1px solid var(--border); display: inline-block;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar .initial[hidden] { display: none; }
.avatar .initial {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--font-display); font-size: 1.1em; color: var(--muted);
}

/* --- Messages --- */
#chatMessages {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 18px;
  padding: var(--sp-4) max(var(--sp-4), calc((100% - var(--read-w)) / 2)) var(--sp-5);
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

.msg { position: relative; display: flex; gap: 12px; max-width: 100%; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Her words: no bubble to read around, set like a page. */
.msg.assistant { align-self: flex-start; align-items: flex-start; max-width: 94%; }
.msg.assistant .msg-avatar { width: 32px; height: 32px; flex: none; margin-top: 4px; }
.msg.assistant .msg-main {
  background: var(--bubble); border: 1px solid var(--bubble-border);
  border-radius: 6px var(--radius-lg) var(--radius-lg) var(--radius-lg); padding: 12px 16px;
  font-family: var(--font-chat); font-size: var(--chat-size); line-height: var(--chat-leading); font-optical-sizing: auto;
  min-width: 0;
}
/* *actions* — set apart from speech by colour and slant, not a label. */
.msg em { color: var(--em); font-style: italic; }
.msg.user em { color: inherit; opacity: .85; }

/* Yours: a plain warm bubble on the right. */
.msg.user { align-self: flex-end; max-width: 80%; }
.msg.user .msg-main {
  background: var(--user-bg); color: var(--user-ink); border-radius: var(--radius-lg) var(--radius-lg) 6px var(--radius-lg);
  padding: 10px 16px; font-size: var(--chat-size); line-height: 1.5; min-width: 0;
}

.chat-empty { margin: auto; color: var(--muted); font-size: 16px; text-align: center; padding: 0 24px; }

/* The "picture of this moment" button: only on hover or focus. */
.msg-imagine {
  position: absolute; top: -10px; right: 10px; z-index: 1; display: none; width: 30px; height: 30px; padding: 0;
  border-radius: 50%; place-items: center; background: var(--panel); color: var(--muted); border: 1px solid var(--border);
}
.msg-imagine svg { width: 16px; height: 16px; display: block; }
.msg:hover .msg-imagine, .msg:focus-within .msg-imagine { display: grid; }
.msg-imagine:hover:not(:disabled) { color: var(--text); background: var(--panel2); border-color: var(--border); }
.msg.assistant .msg-imagine { right: 10px; }

.msg-image:empty { display: none; }
.msg-image { margin-top: 12px; }
.msg-image img { display: block; max-width: min(100%, 420px); border-radius: var(--radius-md); border: 1px solid var(--border); }
.msg-image .hint { font-family: var(--font-ui); font-style: normal; }

/* --- Composer: one rounded box --- */
#chatComposer { flex: none; padding: var(--sp-2) max(var(--sp-4), calc((100% - var(--read-w)) / 2)) var(--sp-5); }
.composer-box {
  display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 18px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 26px;
  transition: border-color .15s;
}
.composer-box:focus-within { border-color: color-mix(in srgb, var(--accent) 65%, var(--border)); }
#prompt {
  flex: 1; resize: none; height: 44px; max-height: 160px; padding: 11px 0; line-height: 1.45;
  background: transparent; border: none; border-radius: 0; font-size: 15.5px;
}
#prompt:focus { border: none; }
#sendBtn {
  flex: none; width: 44px; height: 44px; padding: 0; border-radius: 50%; display: grid; place-items: center;
}
#sendBtn svg { width: 20px; height: 20px; display: block; }

/* --- The experimental game-master card --- */
.msg.gm {
  align-self: center; max-width: 520px; width: 100%; display: block;
  background: var(--panel); border: 1px dashed color-mix(in srgb, var(--warn) 45%, var(--border));
  border-radius: var(--radius-md); padding: 14px 16px; font-size: 14.5px;
}
.msg.gm p { margin: 4px 0; }
.msg.gm .who { font-weight: 600; margin-bottom: 4px; }
.gm-dice { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.die {
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; border-radius: 6px; background: var(--panel2); border: 1px solid var(--border);
}
.gm-outcome.fail { color: var(--dislike); }
.gm-outcome.tie { color: var(--warn); }
.gm-outcome.success, .gm-outcome.success_with_style { color: var(--accent2); }

@media (max-width: 899px) {
  .chat-visual { display: none; }
  .chat-who .avatar { width: 44px; height: 44px; }
}
@media (max-width: 640px) {
  .msg.assistant .msg-avatar { display: none; }
  .msg.assistant, .msg.user { max-width: 94%; }
  #chatSceneBtn { display: none; }
  .chat-head { gap: 4px; padding-right: var(--sp-2); }
  .mode-pop { position: fixed; top: calc(var(--header-h) + 64px); left: 12px; right: 12px; width: auto; }
  .mode-btn { padding: 6px 10px 6px 12px; }
  .chat-who .sub { display: none; }
}

/* --- Starter lines for the chosen scene, above the composer (views/scenes.js) --- */
.scene-starters {
  flex: none; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: var(--sp-2) max(var(--sp-4), calc((100% - var(--read-w)) / 2)) 0;
}
.scene-starters[hidden] { display: none; }
.scene-starters::-webkit-scrollbar { display: none; }
.scene-starters .scene-chip { flex: none; max-width: 78%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
