/* Paper sheet: main chat column. Values from ChatConfig via --chat-* (set at runtime). */
main {
  background-color: var(--chat-bg, #e8e4d8);
  margin: clamp(1rem, 2vw, 3rem);
  max-width: var(--chat-max-width, 120em);
  min-width: 0;
  padding: var(--chat-padding, 1.75em);
  border-radius: var(--chat-radius, 0.35rem);
  color: var(--chat-text, #1a1a1a);
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.35);
}

@media (max-width: 900px) {
  main {
    margin: 1rem 0;
    padding: 1.25rem;
  }
}

@media (max-width: 640px) {
  main {
    margin: 0;
    padding: 1rem;
    border-radius: 0.65rem;
    box-shadow: none;
  }

  main .messages {
    gap: 0.75rem;
  }
}

main .messages-wrap {
  position: relative;
  overflow: visible;
}

main .messages {
  position: relative;
  background: transparent;
  align-items: flex-start;
  overflow: visible;
}

/* Stamps must not be clipped and must not affect scroll height */

/* Closing stamps overlay when user hits chat limit */
.chat-closing-stamps-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

/* Stamp block: zero-height anchor in the flow — stamp is a permanent mark at this point on the paper and does not extend or move the paper */
.chat-closing-stamp-block {
  position: relative;
  height: 0;
  min-height: 0;
  flex: 0 0 0;
  overflow: visible;
  display: block;
  pointer-events: none;
  width: 100%;
}

.chat-closing-stamp-block .chat-closing-stamp {
  position: absolute;
  z-index: 10;
}

.chat-closing-stamp {
  font-size: 1.25rem;
  font-weight: 700;
  display: inline-block;
  padding: 0.25rem 1rem;
  text-transform: uppercase;
  font-family: "Courier", Courier New, monospace;
  white-space: pre-line;
  -webkit-mask-image: url("../assets/imgs/other/grunge.webp");
  -webkit-mask-size: 944px 604px;
  mask-image: url("../assets/imgs/other/grunge.webp");
  mask-size: 944px 604px;
  mix-blend-mode: multiply;
}

/* Stashed: square, thick solid edge; dark top-left, nearly transparent lower right */
.chat-closing-stamp--stashed {
  color: #054c11ca;
  border: 0.5rem solid #054c11ca;
  border-radius: 0;
  -webkit-mask-image: url("../assets/imgs/other/grunge.webp"), linear-gradient(to bottom right, black, rgba(0, 0, 0, 0.5) 90%);
  -webkit-mask-size: 944px 604px, 100% 100%;
  -webkit-mask-position: 13rem 6rem, 0 0;
  -webkit-mask-composite: source-in;
  mask-image: url("../assets/imgs/other/grunge.webp"), linear-gradient(to bottom right, black, rgba(0, 0, 0, 0.5) 90%);
  mask-size: 944px 604px, 100% 100%;
  mask-position: 13rem 6rem, 0 0;
  mask-composite: intersect;
}

/* Tracked: grey, single outline; dark top-right, nearly transparent lower left */
.chat-closing-stamp--tracked {
  color: #6b6b6b;
  border: 0.25rem solid #6b6b6b;
  border-radius: 1rem;
  font-size: 1rem;
  -webkit-mask-image: url("../assets/imgs/other/grunge.webp"), linear-gradient(to bottom left, black, rgba(0, 0, 0, 0.45) 99%);
  -webkit-mask-size: 944px 604px, 100% 100%;
  -webkit-mask-position: 2rem 3rem, 0 0;
  -webkit-mask-composite: source-in;
  mask-image: url("../assets/imgs/other/grunge.webp"), linear-gradient(to bottom left, black, rgba(0, 0, 0, 0.45) 99%);
  mask-size: 944px 604px, 100% 100%;
  mask-position: 2rem 3rem, 0 0;
  mask-composite: intersect;
}

/* Anomaly: red, double outline; dark bottom, nearly transparent top */
.chat-closing-stamp--anomaly {
  font-family: "Verdana", sans-serif;
  text-align: center;
  color: #b20412;
  border: 0.5rem double #b20412;
  border-radius: 2rem;
  font-size: 2rem;
  -webkit-mask-image: url("../assets/imgs/other/grunge.webp"), linear-gradient(to top, black, rgba(0, 0, 0, 0.5) 90%);
  -webkit-mask-size: 944px 604px, 100% 100%;
  -webkit-mask-position: 2rem 3rem, 0 0;
  -webkit-mask-composite: source-in;
  mask-image: url("../assets/imgs/other/grunge.webp"), linear-gradient(to top, black, rgba(0, 0, 0, 0.5) 90%);
  mask-size: 944px 604px, 100% 100%;
  mask-position: 2rem 3rem, 0 0;
  mask-composite: intersect;
}

.chat-closing-stamp-line1,
.chat-closing-stamp-line2 {
  display: block;
}

main .messages .message,
main .messages .chat-editor-wrapper {
  flex: 0 0 auto;
  width: 100%;
  max-width: 70ch;
}

main .message.assistant {
  align-self: flex-start;
}

main .message .label {
  font-weight: bold;
  font-family: var(--chat-editor-font, monospace);
  font-size: 1em;
  line-height: var(--chat-editor-line-height, 1.5);
  text-transform: uppercase;
  direction: ltr;
  text-align: left;
  color: var(--chat-text, #1a1a1a);
}

/* DETECTIVE label: start 10 characters from left so typewriter types in place left-to-right */
main .message.assistant .label {
  padding-left: 10ch;
}

main .message .content {
  display: block;
  min-height: 0;
  max-width: 70ch;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  position: relative;
  overflow-wrap: break-word;
  overflow: visible;
}

main .message.user .content {
  background: transparent;
  border: none;
  color: var(--chat-text, #1a1a1a);
}

main .message.assistant .content {
  background: transparent;
  border: none;
  color: var(--chat-text, #1a1a1a);
}


body[data-dev-mode="true"] main .message.user .content,
body[data-dev-mode="true"] main .message.assistant .content {
  border: 1px solid #000;
}

main .message .content.typewriter {
  font-family: var(--chat-editor-font, monospace);
  line-height: var(--chat-editor-line-height, 1.5);
}

main .status {
  font-family: var(--chat-editor-font, monospace);
  line-height: var(--chat-editor-line-height, 1.5);
  color: var(--chat-status, #555);
}

main .status.error {
  color: var(--chat-status-error, #c53030);
}

/* Hidden chat bar: editor at top like start of a letter */
main .form--hidden {
  display: block;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

main .form--hidden .chat-editor-wrapper {
  margin-bottom: 0.5em;
}

main .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;
}

/* Editor wrapper and contenteditable: document measure, like a shared letter */
main .chat-editor-wrapper {
  position: relative;
  min-height: 6em;
  width: 100%;
  max-width: 70ch;
  cursor: text;
}

/* Hidden until QUERENT has finished typing (blank-chat intro) */
main .chat-editor-wrapper.chat-editor-wrapper--hidden {
  visibility: hidden;
}

/* Dev/debug: highlight the clickable text entry region so it's easy to see
   where clicks will focus the editor and move the custom cursor. */
body[data-dev-mode="true"] main .chat-editor-wrapper {
  outline: 2px solid #00ff66;
  outline-offset: 4px;
}

@media (max-width: 640px) {
  main .chat-editor-wrapper {
    max-width: none;
  }
}

main .chat-editor {
  font-family: var(--chat-editor-font, monospace);
  line-height: var(--chat-editor-line-height, 1.5);
  min-height: 2em;
  padding: 0 0 0.25em 0;
  outline: none;
  caret-color: currentColor;
}

main .chat-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--chat-placeholder, #888);
}

/* User block: frozen text in place, no bubble, no shift; document-like width */
main .chat-user-block {
  font-family: var(--chat-editor-font, monospace);
  line-height: var(--chat-editor-line-height, 1.5);
  padding: 0 0 0.25em 0;
  margin-bottom: 0.25em;
  max-width: 70ch;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-wrap: break-word;
}

/* Sketchy black box cursor */
main .chat-cursor {
  position: absolute;
  pointer-events: none;
  background: var(--chat-cursor-bg, #1a1a1a);
  border: var(--chat-cursor-border, 2px solid #1a1a1a);
  border-radius: 1px;
  box-shadow: var(--chat-cursor-shadow, 1px 1px 0 #1a1a1a, -0.5px 0 0 #1a1a1a);
  min-width: var(--chat-cursor-min-width, 2px);
  min-height: var(--chat-cursor-min-height, 1em);
  z-index: 2;
  animation: chatCursorBreath 3.2s ease-in-out infinite;
  transform-origin: center bottom;
  will-change: opacity, transform;
}

@keyframes chatCursorBreath {
  0% {
    opacity: 0.35;
    transform: scaleY(0.9);
  }
  50% {
    opacity: 1;
    transform: scaleY(1.08);
  }
  100% {
    opacity: 0.35;
    transform: scaleY(0.9);
  }
}

@media (prefers-reduced-motion: reduce) {
  main .chat-cursor {
    animation: none;
  }
}

/* Typewriter: monospace everywhere in chat */
main .typewriter,
main .message .content.typewriter {
  font-family: var(--chat-editor-font, monospace);
  line-height: var(--chat-editor-line-height, 1.5);
}

