/* Per-goal chat thread (index.html + chat.js). */

.thread { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.cm-list { flex: 1; overflow-y: auto; padding: 0 0 16px; overscroll-behavior: contain; }

/* thread starter: the goal itself */
.cm-start { padding: 28px 16px 8px; }
.cm-start .ic { width: 64px; height: 64px; border-radius: 50%; background: var(--field); display: grid; place-items: center; font-size: 30px; }
.cm-start h2 { font-size: 28px; line-height: 1.2; margin: 10px 0 4px; color: var(--head); word-break: break-word; }
.cm-start p { color: var(--muted); margin: 0; }
.cm-start .embed { margin-top: 12px; }

/* messages */
.cm { position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 16px; padding: 2px 16px 2px 16px; margin-top: 16px; }
.cm.grouped { margin-top: 0; }
.cm:hover, .cm.sel { background: var(--msg-hover); }
.cm.hl { background: rgba(240, 178, 50, .08); box-shadow: inset 2px 0 0 var(--gold); }
.cm.hl:hover { background: rgba(240, 178, 50, .13); }
.cm.flash { animation: cmflash 1.6s ease-out; }
@keyframes cmflash { 0%, 40% { background: rgba(88, 101, 242, .28); } 100% { background: transparent; } }
.cm-ref { grid-column: 1 / -1; position: relative; display: flex; align-items: center; gap: 4px; min-width: 0; padding: 0 0 2px 56px; font-size: 13px; color: var(--muted); cursor: pointer; }
.cm-ref::before { content: ''; position: absolute; left: 19px; top: 8px; width: 30px; height: 8px; border: 2px solid #4e5058; border-right: 0; border-bottom: 0; border-top-left-radius: 6px; }
.cm-ref b { color: var(--head); font-weight: 600; white-space: nowrap; }
.cm-ref .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.cm-ref:hover .txt { color: var(--head); }
.cm-gut { padding-top: 2px; }
.cm-av { background: none; border: 0; padding: 0; cursor: pointer; border-radius: 50%; display: block; }
.cm-hover-time { display: block; font-size: 11px; color: var(--faint); text-align: right; visibility: hidden; padding-top: 4px; white-space: nowrap; }
.cm:hover .cm-hover-time { visibility: visible; }
.cm-main { min-width: 0; }
.cm-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.cm-name { background: none; border: 0; padding: 0; font-weight: 600; cursor: pointer; font-size: 16px; }
.cm-name:hover { text-decoration: underline; }
.cm-head time { font-size: 12px; color: var(--faint); }
.cm .md { color: var(--text); }
.edited { font-size: 10px; color: var(--faint); white-space: nowrap; }

/* attachments */
.atts { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 4px; }
.att-img { display: block; max-width: 100%; height: auto; border-radius: 8px; cursor: zoom-in; background: var(--field); }
.att-vid { max-width: min(400px, 100%); max-height: 320px; border-radius: 8px; background: #000; }
.att-aud { width: min(400px, 100%); }
.att-file { display: flex; align-items: center; gap: 10px; background: var(--side); border: 1px solid var(--rail); border-radius: 8px; padding: 10px 12px; width: min(400px, 100%); }
.att-file .ic { font-size: 28px; flex: none; }
.att-file a { font-weight: 600; word-break: break-all; }
.att-file small { display: block; color: var(--muted); font-size: 12px; }

/* reactions */
.rxs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.rx { display: flex; align-items: center; gap: 6px; background: var(--side); border: 1px solid transparent; border-radius: 8px; padding: 2px 6px; font-size: 15px; line-height: 20px; cursor: pointer; color: var(--muted); }
.rx b { font-size: 13px; font-weight: 600; }
.rx:hover { border-color: var(--line); }
.rx.mine { background: rgba(88, 101, 242, .18); border-color: var(--accent); color: #c9cdfb; }
.rx.add { opacity: 0; font-size: 14px; }
.cm:hover .rx.add, .cm.sel .rx.add { opacity: 1; }

/* hover toolbar */
.cm-tools { position: absolute; right: 16px; top: -16px; display: none; background: var(--pop-2); border: 1px solid var(--rail); border-radius: 6px; padding: 2px; box-shadow: 0 2px 8px rgba(0, 0, 0, .3); z-index: 2; }
.cm:hover .cm-tools, .cm.sel .cm-tools { display: flex; }
.cm-tools button { width: 32px; height: 32px; border: 0; background: none; border-radius: 4px; cursor: pointer; font-size: 17px; color: var(--muted); display: grid; place-items: center; padding: 0; }
.cm-tools button:hover { background: #3f4147; color: var(--head); }
.cm-tools .danger:hover { color: var(--red); }
.cm-tools .sep { width: 1px; background: var(--line); margin: 4px 2px; }
@media (hover: none) { .cm:hover .cm-tools { display: none; } .cm.sel .cm-tools { display: flex; } .cm:hover { background: none; } }

.cm-edit textarea { background: var(--field); border-radius: 8px; min-height: 44px; resize: none; margin-top: 4px; }
.cm-edit .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.cm-edit .hint button { background: none; border: 0; padding: 0; color: var(--link); cursor: pointer; font-size: 12px; }
.cm-edit .hint button:hover { text-decoration: underline; }

.newline { display: flex; align-items: center; margin: 14px 16px 0; height: 0; border-top: 1px solid var(--red); position: relative; }
.newline span { position: absolute; right: 0; top: -9px; background: var(--badge); color: #fff; font-size: 11px; font-weight: 800; line-height: 16px; padding: 0 5px; border-radius: 3px 0 0 3px; }

/* composer */
.composer { position: relative; padding: 0 16px 2px; flex: none; }
.stack { background: var(--field); border-radius: 8px; }
.cbar { background: rgba(0, 0, 0, .22); border-radius: 8px 8px 0 0; padding: 8px 8px 8px 14px; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.cbar b { color: var(--head); }
.cbar .icon { margin-left: auto; width: 24px; height: 24px; font-size: 13px; }
.tray { display: flex; gap: 10px; overflow-x: auto; padding: 18px 12px 10px; border-bottom: 1px solid var(--line); }
.tray-item { position: relative; width: 168px; flex: none; background: var(--side); border-radius: 6px; padding: 8px; }
.tray-item .thumb { height: 108px; display: grid; place-items: center; overflow: hidden; border-radius: 4px; background: var(--rail); font-size: 40px; }
.tray-item .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tray-item .nm { font-size: 12px; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray-item .x { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 6px; border: 0; background: var(--pop-2); color: var(--red); cursor: pointer; box-shadow: 0 2px 6px rgba(0, 0, 0, .4); }
.tray-item.loading .thumb { opacity: .45; }
.tray-item.loading .nm::after { content: ' · uploading'; color: var(--muted); }
.tray-item.err { box-shadow: inset 0 0 0 1px var(--red); }
.tray-item.err .nm { color: var(--red-text); white-space: normal; }
.cbox { display: flex; align-items: flex-end; gap: 2px; padding: 2px 6px; position: relative; }
.cbox textarea { background: none; border: 0; resize: none; min-height: 0; max-height: 40vh; padding: 11px 4px; line-height: 1.375; border-radius: 0; }
.cbox textarea:focus-visible { outline: none; }
.stack:focus-within { box-shadow: 0 0 0 1px rgba(88, 101, 242, .5); }
.cbox .icon { width: 40px; height: 44px; }
.cbox .plus svg { width: 24px; height: 24px; }
.cbox .send { color: var(--accent); }
.cbox .send:disabled { color: var(--faint); cursor: default; background: none; }

.fmt { position: absolute; bottom: calc(100% + 8px); left: 48px; display: flex; background: var(--pop); border-radius: 6px; padding: 3px; gap: 2px; box-shadow: 0 4px 12px rgba(0, 0, 0, .45); z-index: 3; }
.fmt button { min-width: 32px; height: 30px; border: 0; background: none; color: var(--text); border-radius: 4px; cursor: pointer; font-size: 15px; padding: 0 6px; }
.fmt button:hover { background: #3f4147; }

.ac { position: absolute; left: 16px; right: 16px; bottom: calc(100% + 4px); background: var(--pop-2); border-radius: 8px; padding: 8px; box-shadow: 0 -4px 16px rgba(0, 0, 0, .35); z-index: 4; max-height: 320px; overflow-y: auto; }
.ac h6 { margin: 0 0 6px 6px; font-size: 12px; color: var(--muted); font-weight: 700; }
.ac button { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; padding: 6px 8px; border-radius: 4px; cursor: pointer; color: var(--text); text-align: left; font-size: 15px; }
.ac button.on { background: #404249; color: var(--head); }
.ac .h { color: var(--muted); margin-left: auto; font-size: 13px; }
.ac .em { font-size: 20px; width: 24px; text-align: center; }

.typing { height: 24px; font-size: 13px; color: var(--text); padding: 2px 4px; display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; }
.typing b { font-weight: 700; color: var(--head); }
.typing .dots { display: inline-flex; gap: 3px; }
.typing .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--text); animation: tdot 1.2s infinite; }
.typing .dots i:nth-child(2) { animation-delay: .15s; } .typing .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes tdot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-2px); } }

.drop { position: absolute; inset: 0; background: rgba(30, 31, 34, .78); display: grid; place-items: center; z-index: 10; }
.drop > div { background: var(--accent); border-radius: 12px; padding: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); }
.drop > div > * { display: block; text-align: center; color: #fff; }
.drop b { font-size: 22px; border: 2px dashed rgba(255, 255, 255, .7); border-bottom: 0; border-radius: 8px 8px 0 0; padding: 28px 40px 6px; }
.drop span { font-size: 14px; border: 2px dashed rgba(255, 255, 255, .7); border-top: 0; border-radius: 0 0 8px 8px; padding: 0 40px 28px; }

.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .86); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; z-index: 70; padding: 16px; }
.lightbox img { max-width: 100%; max-height: calc(100dvh - 80px); border-radius: 4px; }
.lightbox a { color: var(--muted); font-size: 14px; }

/* meme maker */
.modal.meme { max-width: 860px; }
.meme .mbody { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; }
.meme-pick input { margin-bottom: 8px; }
.meme-list { max-height: 440px; overflow-y: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; align-content: start; }
.meme-list button { display: block; padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; background: var(--rail); cursor: pointer; min-width: 0; } /* the square image sets the size; Safari squashes aspect-ratio on buttons */
.meme-list button img { width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; display: block; } 
.meme-list button.on { border-color: var(--accent); }
.meme-list .own { min-height: 64px; color: var(--muted); font-size: 13px; font-weight: 600; border: 2px dashed var(--line); background: none; }
.meme-stage canvas { max-width: 100%; max-height: 360px; border-radius: 6px; background: #000; display: block; margin: 0 auto; }
.meme-stage .two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.meme-stage .blank { height: 240px; display: grid; place-items: center; color: var(--muted); background: var(--rail); border-radius: 6px; text-align: center; padding: 16px; }

@media (max-width: 760px) {
  .cm { padding: 2px 12px; column-gap: 12px; }
  .cm-ref { padding-left: 52px; }
  .composer { padding: 0 8px 2px; }
  .cm-start { padding: 20px 12px 8px; }
  .meme .mbody { grid-template-columns: minmax(0, 1fr); }
  .meme-list { grid-template-columns: repeat(4, minmax(0, 1fr)); max-height: 170px; }
  .meme-stage .two { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .cm.flash, .typing .dots i { animation: none; } }
