/* Messages on the web (web/messenger.mjs, letters-1026 W3). The phone's
 * conversation on a desk: your own bubbles in your voice (fiammoVoice, with
 * fiammoOnInk words at any hour), theirs on the card; a list beside the open
 * conversation at 1280 and over, the conversation in its place under it.
 * Shapes as the app has them: a circle for a face or a glyph control, a
 * capsule for a small thing in a row (a word of the four, a reaction), a
 * rounded rectangle for a card, a photo (10), a field (10). Copper marks: the
 * unread dot, a chosen tick, your reaction. Grey waits. */

:root {
  --voice: #120B04;     /* fiammoVoice, day */
  --on-voice: #F9F8F6;  /* fiammoOnInk: the day's ground, at any hour */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --voice: #473E35; --on-voice: #F9F8F6; }
}
:root[data-theme="dark"] { --voice: #473E35; --on-voice: #F9F8F6; }

/* The page: a frame of its own height, so the list and the conversation
 * each scroll in place and the composer stays at the foot. */
body[data-view="messages"] .foot { display: none; }
body[data-view="messages"] .page { max-width: none; width: 100%; margin: 0; padding: 0; gap: 0; }
.msgr { display: grid; grid-template-columns: minmax(0, 1fr); height: calc(100dvh - var(--msgr-top, 0px) - var(--msgr-bottom, 0px)); min-height: 360px; }
@media (min-width: 700px) and (max-width: 1099.98px) { .msgr { --msgr-top: 60px; } }
@media (max-width: 699.98px) {
  .msgr { --msgr-top: 57px; --msgr-bottom: calc(84px + env(safe-area-inset-bottom)); }
  body.in-thread .rail, body.in-thread .write-btn { display: none; }
  body.in-thread .msgr { --msgr-bottom: 0px; }
}
@media (min-width: 1280px) {
  .msgr { grid-template-columns: 360px minmax(0, 1fr); }
  .msg-list { border-right: 1px solid var(--border); }
}
@media (max-width: 1279.98px) {
  .msgr.has-thread .msg-list { display: none; }
  .msgr:not(.has-thread) .msg-thread { display: none; }
  .msgr:not(.has-thread) .msg-list { width: 100%; max-width: 648px; margin: 0 auto; }
}

/* ------------------------------------------------------------ the list */
.msg-list { display: flex; flex-direction: column; min-height: 0; }
.msg-title { padding: 32px 24px 12px; }
.msg-rows { list-style: none; margin: 0; padding: 0 8px 24px; overflow-y: auto; flex: 1; }
.msg-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; text-decoration: none; color: var(--fg); position: relative; }
.msg-row:hover { background: color-mix(in srgb, var(--fg) 5%, transparent); }
.msg-row.on { background: color-mix(in srgb, var(--fg) 7%, transparent); }
.msg-row.on .msg-row-time, .msg-row.on .msg-row-line { color: var(--muted-strong); }
.msg-row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.msg-row-top { display: flex; align-items: baseline; gap: 8px; }
.msg-row-name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.msg-row.unread .msg-row-name { font-weight: 700; }
.msg-row-time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.msg-row-line { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row.unread .msg-row-line { color: var(--fg); }
.msg-row-line.sealed-line { font-style: italic; }
.unread-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); flex-shrink: 0; }
.msg-row.empty { cursor: default; }
.avatar.ghost { background: color-mix(in srgb, var(--fg) 6%, transparent); }
.group-face { position: relative; display: inline-flex; flex-shrink: 0; }
.group-face .avatar { position: absolute; box-shadow: 0 0 0 2px var(--paper); }
.group-face .avatar:first-child { top: 0; left: 0; }
.group-face .avatar:nth-child(2) { bottom: 0; right: 0; }
.place-dot { position: absolute; top: -1px; right: -2px; width: 9px; height: 9px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 2px var(--paper); }
.rail:has(.places) .place-dot { pointer-events: none; }

/* ------------------------------------------------------------ a conversation */
.msg-thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.msg-thread.none { align-items: center; justify-content: center; }
.msg-none { color: var(--muted); font-size: 14px; text-align: center; margin: 24px auto; }
.msg-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); min-height: 60px; }
@media (min-width: 1100px) { .msg-head { padding-right: 76px; } }
.msg-head-title { margin: 0; font-size: 16px; font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-head-name { color: var(--fg); text-decoration: none; }
a.msg-head-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.msg-back { width: 44px; height: 44px; margin-left: -10px; border: 0; border-radius: 50%; background: transparent; color: var(--fg); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.msg-back:hover { background: color-mix(in srgb, var(--fg) 6%, transparent); }
.msg-back .ic, .msg-back svg { width: 18px; height: 18px; }
@media (min-width: 1280px) { .msg-back { display: none; } }
.msg-scroll { flex: 1; overflow-y: auto; overflow-anchor: none; padding: 16px max(16px, calc((100% - 760px) / 2)); outline-offset: -3px; }
.msg-inner { display: flex; flex-direction: column; gap: 6px; }
.msg-earlier { align-self: center; margin-bottom: 8px; }
.day-line { align-self: center; font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
.sealed-note, .key-line, .event-line { align-self: center; max-width: 420px; text-align: center; font-size: 13px; color: var(--muted); margin: 6px 0; }
.key-line { display: inline-flex; align-items: center; gap: 6px; }
.key-line .ic, .bubble.sealed .ic { width: 14px; height: 14px; flex-shrink: 0; }

.msg { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; position: relative; }
.msg.mine { flex-direction: row-reverse; }
.msg-sender { flex-basis: 100%; margin: 6px 0 0 4px; font-size: 12px; font-weight: 600; color: var(--muted-strong); }
.msg-col { display: flex; flex-direction: column; gap: 4px; max-width: min(78%, 540px); align-items: flex-start; }
.msg.mine .msg-col { align-items: flex-end; }
.bubble { background: var(--card); box-shadow: var(--lift); border-radius: 18px; padding: 9px 14px; max-width: 100%; }
.msg.mine .bubble { background: var(--voice); color: var(--on-voice); box-shadow: none; }
.msg.mine .bubble a { color: var(--on-voice); }
.bubble-text { margin: 0; font-family: var(--serif); font-size: 15px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-text a { color: var(--gold-text); text-underline-offset: 3px; }
.bubble.sealed { display: inline-flex; gap: 8px; align-items: center; background: transparent; box-shadow: inset 0 0 0 1px var(--border); color: var(--muted); font-size: 14px; font-style: italic; }
.msg.mine .bubble.sealed { background: transparent; color: var(--muted); }
/* Waiting and not gone are said in words under the bubble (Sending…,
 * Didn't send. Retry), and a ring in the error colour round one that
 * didn't go: never a faded bubble, whose words would drop below 4.5:1. */
.msg.failed .bubble { box-shadow: 0 0 0 1.5px var(--error); }
.unsent-line { margin: 2px 4px; font-size: 13px; font-style: italic; color: var(--muted); }
.msg-meta { margin: 0 6px; font-size: 12px; color: var(--muted); }
.failed-line { display: inline-flex; gap: 10px; align-items: center; color: var(--error); }
.failed-line .text-btn { font-size: 12px; }
.receipt { flex-basis: 100%; text-align: right; margin: 0 6px; font-size: 12px; color: var(--muted); }
.msg.theirs .receipt { text-align: left; }
.quoted-line { display: flex; flex-direction: column; gap: 1px; border-left: 2px solid var(--gold); padding: 2px 0 2px 10px; font-size: 13px; color: var(--muted-strong); max-width: 100%; }
.quoted-who { font-weight: 600; font-size: 12px; }
.quoted-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.echo-quote { margin: 0; display: flex; flex-direction: column; gap: 4px; border-left: 2px solid var(--gold); padding: 4px 0 4px 12px; max-width: 100%; }
.echo-kind { font-size: 12px; font-weight: 600; color: var(--muted-strong); font-family: var(--sans); }
.echo-text { font-family: var(--serif); font-style: italic; font-size: 15px; line-height: 1.45; }
.msg-photos { display: grid; gap: 4px; grid-template-columns: minmax(0, 1fr); width: min(300px, 100%); }
.msg-photos.n2, .msg-photos.n3, .msg-photos.n4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.msg-photo { padding: 0; border: 0; background: none; cursor: zoom-in; border-radius: 10px; overflow: hidden; display: block; }
.pic { display: block; border-radius: 10px; overflow: hidden; background: color-mix(in srgb, var(--fg) 6%, transparent); min-height: 80px; }
.pic img { display: block; width: 100%; height: auto; }
.pic.sticker-frame { background: none; min-height: 0; width: 120px; }
.pic-missing { font-size: 13px; color: var(--muted); padding: 6px 4px; }
.msg-video { position: relative; }
.video-mark { position: absolute; top: 12px; left: 12px; width: 32px; height: 32px; border-radius: 50%; background: rgba(18, 11, 4, .6); color: #F9F8F6; display: inline-flex; align-items: center; justify-content: center; }
.video-mark svg { width: 14px; height: 14px; }
.video-line { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.stickers { display: flex; gap: 6px; flex-wrap: wrap; }
.bubble.voice { display: flex; align-items: center; gap: 10px; min-width: 200px; padding: 8px 14px 8px 8px; }
.voice-play { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--ink); color: var(--on-ink); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.msg.mine .voice-play { background: var(--on-voice); color: var(--voice); }
.voice-play svg { width: 14px; height: 14px; }
.voice-bar { flex: 1; height: 4px; border-radius: 2px; background: color-mix(in srgb, currentColor 22%, transparent); overflow: hidden; }
.voice-fill { display: block; height: 100%; width: 0; background: currentColor; }
.voice-len { font-size: 12px; font-variant-numeric: tabular-nums; }
.voice-wrap { display: flex; flex-direction: column; gap: 4px; }
.link-card-msg { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border-radius: 12px; background: var(--card); box-shadow: 0 0 0 1px var(--border); text-decoration: none; color: var(--fg); max-width: 100%; }
.link-card-title { font-size: 14px; font-weight: 600; }
.link-card-site { font-size: 12px; color: var(--muted); }
.reactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: -2px; }
.reaction { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; padding: 2px 8px; border-radius: 999px; background: var(--card); box-shadow: 0 0 0 1px var(--border); }
.reaction.mine { box-shadow: 0 0 0 1.5px var(--gold); }
.msg-more-wrap { position: relative; opacity: 0; transition: opacity .12s var(--arrive); }
.msg:hover .msg-more-wrap, .msg:focus-within .msg-more-wrap, .msg-more[aria-expanded="true"] { opacity: 1; }
@media (hover: none) { .msg-more-wrap { opacity: .7; } }
.msg-more { width: 32px; height: 32px; border-radius: 50%; border: 0; background: transparent; color: var(--muted-strong); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.msg-more:hover, .msg-more:focus-visible { background: color-mix(in srgb, var(--fg) 6%, transparent); }
.msg-more svg { width: 18px; height: 18px; }
.msg.mine .msg-more-wrap .menu { right: 0; left: auto; }
.msg.theirs .msg-more-wrap .menu { left: 0; right: auto; }
.typing-line { margin: 0; padding: 0 max(20px, calc((100% - 752px) / 2)); min-height: 18px; font-size: 13px; font-style: italic; color: var(--muted); }

/* ------------------------------------------------------------ the composer (the composer's glass) */
.msg-composer-wrap { padding: 6px max(16px, calc((100% - 760px) / 2)) max(12px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; }
.msg-composer-wrap.drop .msg-composer { box-shadow: 0 0 0 2px var(--gold); }
.msg-composer { padding: 5px 5px 5px 5px; align-items: flex-end; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.msg-field { field-sizing: content; max-height: 40vh; flex: 1; border: 0; background: transparent; resize: none; font-family: var(--serif); font-size: 15px; line-height: 1.4; padding: 8px 4px; min-height: 22px; outline: none; color: var(--fg); }
.composer-btn, .send-arrow { width: 36px; height: 36px; border-radius: 50%; border: 0; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.composer-btn { background: transparent; color: var(--muted-strong); }
.composer-btn:hover { background: color-mix(in srgb, var(--fg) 6%, transparent); }
.composer-btn svg, .send-arrow svg { width: 20px; height: 20px; }
.send-arrow { background: var(--ink); color: var(--on-ink); padding: 0; box-shadow: none; outline: 0; background-image: none; overflow: hidden; transform: translateZ(0); -webkit-appearance: none; appearance: none; }
.send-arrow[disabled] { opacity: .3; cursor: default; }
.attach-wrap .menu { top: auto; bottom: 44px; left: 0; right: auto; }
.msg-attachments { display: flex; gap: 6px; flex-wrap: wrap; }
.msg-attachment { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; box-shadow: 0 0 0 1px var(--border); }
.msg-attachment img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment-x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; padding: 4px; background: var(--card); color: var(--fg); box-shadow: var(--lift); cursor: pointer; display: inline-flex; }
.attachment-x svg { width: 14px; height: 14px; }
.msg-quote { display: flex; align-items: center; gap: 8px; }
.msg-quote .quoted-line { flex: 1; min-width: 0; }
.msg-quote .attachment-x { position: static; }
.composer-line { margin: 0 4px; font-size: 12px; color: var(--muted); min-height: 0; }
.composer-line:empty { display: none; }

/* ------------------------------------------------------------ linking */
.link-page { width: 100%; max-width: 600px; margin: 0 auto; padding: 48px 24px 64px; display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 699.98px) { .link-page { padding: 24px 16px 120px; } }
.link-lede { max-width: 520px; }
.link-why { margin: 0; padding: 12px 16px; border-radius: 12px; background: color-mix(in srgb, var(--gold) 12%, var(--card)); font-size: 14px; }
.link-card { display: flex; flex-direction: column; gap: 16px; align-items: flex-start; }
.link-code { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.link-qr { border-radius: 12px; box-shadow: 0 0 0 1px var(--border); background: #ffffff; flex-shrink: 0; transition: opacity .2s var(--arrive); }
.link-qr.spent { opacity: .18; }
.link-code-text { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 220px; }
.link-words { display: flex; gap: 6px; flex-wrap: wrap; margin: 0; }
.link-word { font-size: 17px; font-weight: 650; padding: 6px 12px; border-radius: 999px; background: var(--paper); box-shadow: 0 0 0 1px var(--border); letter-spacing: .01em; }
.link-how { margin: 0; font-size: 15px; }
.link-check { margin: 0; }
.link-clock { margin: 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
/* What the page knows of the phone while the code waits (fiammo 870). */
.link-phone { margin: 0; font-size: 14px; line-height: 1.4; padding-left: 10px; box-shadow: inset 2px 0 0 var(--gold); }
.link-phone.warn { box-shadow: inset 2px 0 0 var(--muted); }
.link-code-btn { align-self: flex-start; font-size: 14px; }
.keep-row { width: 100%; margin: -8px; }
.code-boxes { display: flex; gap: 8px; }
.code-box { width: 44px; height: 52px; text-align: center; font-size: 22px; font-weight: 600; border-radius: 10px; border: 0; box-shadow: inset 0 0 0 1px var(--border); background: var(--paper); color: var(--fg); font-variant-numeric: tabular-nums; }
.code-box:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
@media (max-width: 380px) { .code-boxes { gap: 5px; } .code-box { width: 40px; } }

/* Echo this, from a letter (letters.mjs). */
.echo-sheet { display: flex; flex-direction: column; gap: 12px; }
.echo-sheet .echo-quote { font-family: var(--serif); font-style: italic; font-size: 15px; line-height: 1.45; }
.echo-note { width: 100%; }
.photo-view-wrap { max-height: 70vh; overflow: auto; }
.photo-view { display: block; max-width: 100%; height: auto; border-radius: 10px; margin: 0 auto; }
.set-strong { margin: 0; font-weight: 600; }
.inline-link { color: var(--gold-text); font-weight: 600; }

/* Phone width: the composer floats over the list on its glass, and the list
 * scrolls underneath it, padded by the composer's measured height (--cmp-h,
 * which includes the safe area) so the last message clears it. The frame
 * follows the visual viewport (--vvh) so Safari's toolbar and keyboard
 * never leave a solid band. */
@media (max-width: 699.98px) {
  .msgr { height: calc(var(--vvh, 100dvh) - var(--msgr-top, 0px) - var(--msgr-bottom, 0px)); }
  /* In a conversation the frame is fixed to the visible viewport: no page scroll, no dead gap under the composer, and it rides above Safari's floating bar and the keyboard. */
  body.in-thread { overflow: hidden; }
  body.in-thread .msgr { position: fixed; left: 0; right: 0; top: var(--msgr-top, 0px); width: 100%; overscroll-behavior: contain; }
  .msg-scroll { overscroll-behavior: contain; }
  .msg-thread { position: relative; overflow: hidden; }
  .msg-scroll { padding-top: calc(var(--hd-h, 60px) + 12px); padding-bottom: calc(var(--cmp-h, 76px) + 12px); }
  .msg-head { position: absolute; top: 0; left: 0; right: 0; z-index: 2; padding-top: calc(10px + env(safe-area-inset-top)); background: color-mix(in srgb, var(--paper) 78%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
  .msg-composer-wrap { position: absolute; left: 0; right: 0; bottom: 0; background: transparent; z-index: 2; pointer-events: none; }
  .msg-composer-wrap > * { pointer-events: auto; }
  .msg-composer { border-radius: 24px; box-shadow: var(--lift); }
  .typing-line { position: absolute; left: 0; right: 0; bottom: var(--cmp-h, 76px); z-index: 2; pointer-events: none; }
}
@media (max-width: 699.98px) {
  /* Keyboard up: the safe area is under the keys, so the composer sits right on the viewport's foot. */
  html.msg-kb .msg-composer-wrap { padding-bottom: 8px; }
}
