* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #fff; color: #222;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; font-size: 16px; } /* 16px stops iPhone zooming in */

/* ================= STOPWATCH & TIMER (cover) ================= */
#calc { height: 100vh; height: 100dvh; background: #fff; overflow-y: auto; }
#timerApp {
  max-width: 460px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  font-variant-numeric: tabular-nums;
}
.tm-head { display: flex; align-items: center; gap: 8px; padding: 4px 0 10px; }
.tm-logo { position: relative; font-size: 20px; }
.tm-title { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.tm-tabs { display: flex; background: #f0f1f3; border-radius: 10px; padding: 3px; margin-bottom: 8px; }
.tm-tab { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; color: #666; font-weight: 600; font-size: 15px; }
.tm-tab.active { background: #fff; color: #111; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tm-pane { flex: 1; display: flex; flex-direction: column; align-items: stretch; }
.tm-big { font-size: clamp(48px, 17vw, 76px); font-weight: 300; text-align: center; letter-spacing: -.02em; color: #111; }
#swPane .tm-big { margin: 9vh 0 6vh; }
.tm-btns { display: flex; justify-content: space-between; gap: 16px; margin: 8px 0 16px; }
.tm-btns:has(> :only-child) { justify-content: center; }
.tm-round {
  width: 84px; height: 84px; border-radius: 50%; border: 0; font-size: 16px; font-weight: 600;
  background: #eceef1; color: #222; box-shadow: 0 0 0 3px #fff, 0 0 0 4.5px #e1e3e7;
}
.tm-round:disabled { color: #aaa; }
.tm-round.go { background: #dff3e4; color: #1f8f3e; box-shadow: 0 0 0 3px #fff, 0 0 0 4.5px #c9ead2; }
.tm-round.stop { background: #fde4e3; color: #d6332e; box-shadow: 0 0 0 3px #fff, 0 0 0 4.5px #f7cfcd; }
.tm-round:active { filter: brightness(.94); }
.tm-laps { list-style: none; margin: 0; padding: 0; border-top: 1px solid #eee; overflow-y: auto; }
.tm-laps li { display: flex; justify-content: space-between; padding: 12px 4px; border-bottom: 1px solid #eee; font-size: 16px; }
.tm-laps li.best { color: #1f8f3e; }
.tm-laps li.worst { color: #d6332e; }
#tmSet { display: flex; flex-direction: column; padding-top: 6vh; }
.tm-label { font-size: 13px; color: #888; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; text-align: center; }
.tm-input {
  margin: 10px auto 0; width: 100%; max-width: 320px; text-align: center; font-size: 44px !important; font-weight: 300;
  border: 0; border-bottom: 2px solid #e1e3e7; outline: none; padding: 6px 0; color: #111; background: transparent;
}
.tm-input:focus { border-bottom-color: #1f8f3e; }
.tm-input::placeholder { color: #c8cbd0; }
.tm-msg { min-height: 18px; margin: 8px 0 0; text-align: center; font-size: 13px; color: #d6332e; }
.tm-presets { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 14px 0 26px; }
.tm-preset { border: 1px solid #e1e3e7; background: #fff; border-radius: 999px; padding: 8px 14px; font-size: 14px; color: #333; }
.tm-preset:active { background: #f0f1f3; }
#tmRun { display: flex; flex-direction: column; padding-top: 3vh; }
.tm-ring { position: relative; width: min(78vw, 300px); aspect-ratio: 1; margin: 0 auto 18px; }
.tm-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.tm-ring circle { fill: none; stroke-width: 8; }
.tm-ring .bg { stroke: #eceef1; }
.tm-ring .fg { stroke: #f29d38; stroke-linecap: round; transition: stroke-dashoffset .25s linear; }
.tm-ring-in { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.tm-ring .tm-big { font-size: clamp(40px, 13vw, 60px); }
.tm-ends { color: #999; font-size: 15px; margin-top: 4px; }
.tm-done {
  margin: 10px auto 0; border: 0; border-radius: 14px; padding: 14px 20px; font-size: 17px; font-weight: 700;
  background: #f29d38; color: #fff; animation: tmPulse 1s ease-in-out infinite;
}
@keyframes tmPulse { 50% { transform: scale(1.04); } }
@media (max-height: 560px) { #swPane .tm-big { margin: 4vh 0 3vh; } #tmSet { padding-top: 2vh; } .tm-round { width: 70px; height: 70px; } }

/* ================= CHAT ================= */
#chat {
  --bg: #f5f6f8; --panel: #fff; --text: #1d1d1f; --muted: #8a8f98; --line: #e4e6ea;
  --me: #3b82f6; --me-text: #fff; --them: #e9ebef; --them-text: #1d1d1f; --accent: #3b82f6; --danger: #e5484d;
  position: fixed; inset: 0; background: var(--bg); color: var(--text); display: flex; flex-direction: column;
}
#chat { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  #chat:not([data-theme=light]) { --bg: #0f1115; --panel: #171a1f; --text: #ecedee; --muted: #8b9098; --line: #2a2e35; --them: #262a31; --them-text: #ecedee; --accent: #4c8df6; --me: #3b7ef0; color-scheme: dark; }
}
#chat[data-theme=dark] { --bg: #0f1115; --panel: #171a1f; --text: #ecedee; --muted: #8b9098; --line: #2a2e35; --them: #262a31; --them-text: #ecedee; --accent: #4c8df6; --me: #3b7ef0; color-scheme: dark; }
#chat input:not([type=file]) {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; min-width: 0;
}
#chat input:focus { border-color: var(--accent); }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 600; }
.primary:disabled { opacity: .5; }
.icon { background: none; border: 0; color: var(--text); font-size: 20px; padding: 6px 8px; border-radius: 8px; line-height: 1; }
.icon:hover { background: var(--line); }
.icon.small { font-size: 13px; color: var(--muted); }
.link { background: none; border: 0; color: var(--muted); margin-top: 14px; }
.msg { font-size: 13px; color: var(--muted); margin: 6px 0 0; min-height: 1em; }
.msg.err { color: var(--danger); }
.msg.ok { color: #22a35a; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 20px; }
.empty.big { margin: auto; font-size: 16px; }

.auth { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { background: var(--panel); border-radius: 16px; padding: 24px; width: 100%; max-width: 360px; box-shadow: 0 4px 24px rgba(0,0,0,.08); text-align: center; }
.auth-card h1 { margin: 0 0 16px; font-size: 22px; }
.tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; color: var(--muted); }
.tabs button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
#authForm { display: flex; flex-direction: column; gap: 10px; }

#appView { flex: 1; display: flex; min-height: 0; }
.bar {
  display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--panel);
  padding-top: max(10px, env(safe-area-inset-top));
}
#sidebar { width: 320px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.me { flex: 1; font-weight: 700; font-size: 17px; user-select: none; -webkit-user-select: none; cursor: default; }
.me.quiet::after { content: '.'; color: var(--muted); margin-left: 1px; }
.receipt { font-weight: 600; }
.receipt.seen { color: var(--accent); }
.add-friend { display: flex; gap: 6px; padding: 12px 12px 0; }
.add-friend input { flex: 1; }
#addFriendMsg { padding: 0 12px; }
#requests { padding: 0 12px; }
.req { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--bg); border-radius: 10px; margin-top: 8px; font-size: 14px; }
.req span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.req button { border: 0; border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.req .accept { background: var(--accent); color: #fff; }
.req .decline { background: var(--line); color: var(--text); }
#friendList { list-style: none; margin: 8px 0 0; padding: 0; overflow-y: auto; flex: 1; }
.friend { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; }
.friend:hover { background: var(--bg); }
.friend.active { background: var(--bg); }
.avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; text-transform: uppercase; }
.friend-info { flex: 1; min-width: 0; }
.friend-name { font-weight: 600; }
.friend-last { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; font-size: 12px; font-weight: 700; padding: 2px 7px; }

#convo { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.convo-name { flex: 1; font-weight: 700; font-size: 17px; }
#backBtn { font-size: 28px; padding: 0 8px; }
#messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 4px; -webkit-overflow-scrolling: touch; }
.day { text-align: center; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.bubble-row { display: flex; flex-direction: column; align-items: flex-start; max-width: 100%; }
.bubble-row.mine { align-items: flex-end; }
.bubble { max-width: min(75%, 480px); padding: 8px 12px; border-radius: 18px; background: var(--them); color: var(--them-text); word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; cursor: default; }
.mine .bubble { background: var(--me); color: var(--me-text); }
.bubble.media { padding: 4px; background: transparent; }
.bubble.media img, .bubble.media video { display: block; max-width: 100%; max-height: 320px; border-radius: 14px; cursor: pointer; background: var(--them); min-width: 80px; min-height: 60px; }
.bubble a { color: inherit; }
.file-link { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.file-link .fi { font-size: 22px; }
.file-link small { opacity: .75; display: block; }
.snap-btn { border: 2px solid #e5484d; color: #e5484d; background: var(--panel); border-radius: 18px; padding: 8px 14px; font-weight: 700; }
.snap-done { color: var(--muted); font-style: italic; }
.mine .snap-done { color: rgba(255,255,255,.85); }
.meta { font-size: 11px; color: var(--muted); margin: 2px 6px 4px; display: flex; gap: 8px; align-items: center; }
.meta .del { background: none; border: 0; color: var(--danger); font-size: 12px; padding: 0; }
#uploadStatus { font-size: 13px; color: var(--muted); padding: 0 14px; }
#uploadStatus:empty { display: none; }
#composer { display: flex; gap: 6px; align-items: center; padding: 10px; border-top: 1px solid var(--line); background: var(--panel); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
#msgInput { flex: 1; border-radius: 20px !important; }
#sendBtn { border-radius: 20px; }

@media (max-width: 720px) {
  #sidebar { width: 100%; border-right: 0; }
  #convo { display: none; }
  #appView.in-convo #sidebar { display: none; }
  #appView.in-convo #convo { display: flex; }
  .bubble { max-width: 82%; }
}

/* camera */
#camera { position: fixed; inset: 0; background: #000; z-index: 20; display: flex; align-items: center; justify-content: center; }
#camVideo, #camPreview { width: 100%; height: 100%; object-fit: cover; }
#camVideo.mirror { transform: scaleX(-1); }
#camPreview { object-fit: contain; }
.cam-top { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 14px; right: 14px; display: flex; justify-content: space-between; }
.cam-round { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(0,0,0,.45); color: #fff; font-size: 20px; }
.cam-bottom { position: absolute; left: 0; right: 0; bottom: max(24px, env(safe-area-inset-bottom)); display: flex; justify-content: center; }
#camShootRow, #camSendRow { display: flex; gap: 10px; align-items: center; }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: rgba(255,255,255,.25); }
.shutter:active { background: #fff; }
.cam-pill { border: 0; border-radius: 22px; padding: 12px 16px; background: rgba(0,0,0,.6); color: #fff; font-size: 15px; }
.cam-pill.send { background: #3b82f6; font-weight: 700; }

/* viewer */
#viewer { position: fixed; inset: 0; background: rgba(0,0,0,.95); z-index: 30; display: flex; align-items: center; justify-content: center; flex-direction: column; }
#viewerImg { max-width: 100%; max-height: 90%; object-fit: contain; }
#viewerTimer { position: absolute; top: max(16px, env(safe-area-inset-top)); right: 18px; color: #fff; font-size: 22px; font-weight: 700; }
#viewerTimer:empty { display: none; }
.viewer-hint { color: #aaa; font-size: 13px; position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); margin: 0; }

/* ================= update 2 ================= */
#calcDot { position: absolute; top: 1px; right: -7px; width: 5px; height: 5px; border-radius: 50%; background: #6aa9e9; }
.receipt.delivered { color: var(--muted); }
.bubble.deleted { background: transparent !important; color: var(--muted) !important; border: 1px dashed var(--line); font-style: italic; font-size: 14px; }
.save-btn { margin-left: 8px; border: 0; border-radius: 12px; padding: 3px 10px; font-size: 12px; font-weight: 600; background: rgba(255,255,255,.25); color: inherit; }
.friend.unread .friend-name { font-weight: 800; }
.friend.unread .friend-last { color: var(--accent); font-weight: 600; }
.plain { background: var(--line); color: var(--text); border: 0; border-radius: 10px; padding: 10px 14px; }
.offscreen-video { position: fixed; left: -10000px; top: 0; width: 4px; height: 4px; }

/* chat backgrounds */
#convo.has-bg #messages { background: transparent; }
#convo.has-bg .day, #convo.has-bg .meta { align-self: center; background: rgba(0,0,0,.38); color: #fff; padding: 2px 8px; border-radius: 10px; }
#convo.has-bg .bubble-row .meta { align-self: auto; }
#convo.has-bg .receipt.seen { color: #9cc7ff; }
#convo.has-bg .receipt.delivered { color: #fff; }
#convo.has-bg .meta .del { color: #ffb4b4; }
#convo.has-bg .bubble:not(.media):not(.deleted) { box-shadow: 0 1px 2px rgba(0,0,0,.18); }
#convo.has-bg .bubble-row:not(.mine) .bubble:not(.media):not(.deleted) { background: rgba(255,255,255,.92); color: #1d1d1f; }
#convo.has-bg .bubble.deleted { background: rgba(0,0,0,.35) !important; color: #eee !important; border-color: transparent; }
#convo.has-bg #emptyConvo { color: #fff; }

/* new message popup */
#toast { position: fixed; z-index: 15; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(420px, calc(100% - 20px));
  display: flex; align-items: center; background: var(--panel); color: var(--text); border-radius: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.22); border: 1px solid var(--line); animation: toastIn .2s ease-out; }
@keyframes toastIn { from { transform: translate(-50%, -12px); opacity: 0; } }
.toast-body { flex: 1; min-width: 0; text-align: left; background: none; border: 0; color: inherit; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.toast-body span { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast-x { background: none; border: 0; color: var(--muted); font-size: 16px; padding: 12px 14px; }

/* pop-ups */
#sheet, #bgPicker { position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet-card { background: var(--panel); color: var(--text); border-radius: 16px; padding: 18px; width: 100%; max-width: 380px; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
#sheetText { margin: 0 0 14px; line-height: 1.4; }
#sheetBtns { display: flex; gap: 8px; justify-content: flex-end; }
.bg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
#bgGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.bg-swatch { aspect-ratio: 3 / 4; border-radius: 10px; border: 2px solid var(--line); font-size: 12px; color: var(--muted); padding: 0; overflow: hidden; }
.bg-swatch.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.bg-only { display: flex; align-items: center; gap: 8px; margin: 14px 0 10px; font-size: 14px; }
#bgUpload { width: 100%; }
@media (max-width: 720px) {
  #sheet, #bgPicker { align-items: flex-end; padding: 0; }
  #sheet .sheet-card, #bgPicker .sheet-card { max-width: none; border-radius: 16px 16px 0 0; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
}

/* ================= update 3: replies + hearts ================= */
.bubble-wrap { position: relative; display: flex; max-width: 100%; }
.mine .bubble-wrap { justify-content: flex-end; }
.bubble-wrap .bubble { max-width: min(75vw, 480px); }
.hearts { position: absolute; bottom: -10px; right: -4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; font-size: 12px; padding: 1px 5px; line-height: 1.3; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.mine .hearts { right: auto; left: -4px; }
.bubble-wrap:has(.hearts) + .meta { margin-top: 12px; }
.bubble-wrap:has(.hearts) { margin-bottom: 2px; }
.quote { max-width: min(70vw, 440px); border: 0; border-left: 3px solid var(--accent); background: var(--bg); color: var(--muted); font-size: 13px; text-align: left;
  padding: 4px 10px; border-radius: 3px 10px 10px 3px; margin: 4px 4px 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#convo.has-bg .quote { background: rgba(255,255,255,.85); color: #444; }
.actions { display: flex; gap: 6px; margin: 2px 4px 6px; }
.actions button { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 14px; padding: 5px 11px; font-size: 13px; }
.actions button.danger { color: var(--danger); }
.meta { cursor: pointer; }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 3px #f5c542; } 100% { box-shadow: none; } }
.bubble.flash { animation: flash 1.4s ease-out; }
#replyBar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--line); }
.reply-info { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 8px; display: flex; flex-direction: column; }
.reply-info b { font-size: 13px; color: var(--accent); }
.reply-info span { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ================= update 4: photo replies + typing ================= */
.quote { display: flex; align-items: center; gap: 6px; }
.quote .thumb { width: 28px; height: 28px; border-radius: 5px; object-fit: cover; flex: none; background: var(--line); }
#replyThumb:empty { display: none; }
#replyThumb .thumb { width: 38px; height: 38px; border-radius: 6px; object-fit: cover; display: block; background: var(--line); }
.quick-reply { background: none; border: 0; padding: 0; font-size: 11px; color: var(--accent); font-weight: 600; }
#convo.has-bg .quick-reply { color: #cfe3ff; }
#viewerActions { position: absolute; bottom: max(44px, calc(env(safe-area-inset-bottom) + 34px)); display: flex; gap: 10px; }
#typingRow { padding: 0 12px 8px; }
#convo.has-bg #typingRow { background: transparent; }
.typing-bubble { display: inline-flex; gap: 4px; align-items: center; background: var(--them); border-radius: 18px; padding: 11px 14px; }
#convo.has-bg .typing-bubble { background: rgba(255,255,255,.92); }
.typing-bubble span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: typingDot 1.2s infinite ease-in-out; }
.typing-bubble span:nth-child(2) { animation-delay: .15s; }
.typing-bubble span:nth-child(3) { animation-delay: .3s; }
@keyframes typingDot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }
.friend.typing .friend-last { color: var(--accent); font-style: italic; }

/* ================= update 5: dark mode + shared backgrounds ================= */
#bgNote { align-self: center; margin: 8px auto 0; background: rgba(0,0,0,.6); color: #fff; font-size: 13px; padding: 5px 12px; border-radius: 12px; animation: toastIn .2s ease-out; position: relative; z-index: 1; }
#bgFor { color: var(--muted); font-size: 13px; }
.auth-card { box-shadow: 0 4px 24px rgba(0,0,0,.08); }
/* dark versions of the see-through bubbles used on top of backgrounds */
@media (prefers-color-scheme: dark) {
  #chat:not([data-theme=light]) #convo.has-bg .bubble-row:not(.mine) .bubble:not(.media):not(.deleted),
  #chat:not([data-theme=light]) #convo.has-bg .typing-bubble { background: rgba(32,36,43,.92); color: #ecedee; }
  #chat:not([data-theme=light]) #convo.has-bg .quote { background: rgba(32,36,43,.88); color: #c9ccd1; }
  #chat:not([data-theme=light]) .snap-btn { background: transparent; }
}
#chat[data-theme=dark] #convo.has-bg .bubble-row:not(.mine) .bubble:not(.media):not(.deleted),
#chat[data-theme=dark] #convo.has-bg .typing-bubble { background: rgba(32,36,43,.92); color: #ecedee; }
#chat[data-theme=dark] #convo.has-bg .quote { background: rgba(32,36,43,.88); color: #c9ccd1; }
#chat[data-theme=dark] .snap-btn { background: transparent; }
#chat[data-theme=dark] .auth-card { box-shadow: 0 4px 24px rgba(0,0,0,.5); }

/* ================= update 6 ================= */
.convo-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.convo-name { cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#convoStatus { font-size: 12px; color: var(--muted); font-weight: 400; }
#convoStatus:empty { display: none; }
#convoStatus.on { color: #22a35a; }
.friend .avatar { position: relative; }
.friend.online .avatar::after { content: ''; position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%; background: #31c75a; border: 2px solid var(--panel); }
.real-name { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.meta .edited { font-style: italic; }
/* swipe to reply */
.bubble-row { position: relative; touch-action: pan-y; }
.swipe-icon { position: absolute; left: 2px; top: 50%; transform: translateY(-50%); opacity: 0; font-size: 18px; color: var(--accent); pointer-events: none; }
.bubble-row.swipe-ready .swipe-icon { transform: translateY(-50%) scale(1.25); }
/* edit bar */
#editBar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--line); }
/* voice messages */
#composer { position: relative; }
#micBtn { font-size: 22px; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#recBar { position: absolute; left: 10px; right: 56px; top: 8px; bottom: max(8px, env(safe-area-inset-bottom)); background: var(--panel); display: flex; align-items: center; gap: 10px; font-size: 15px; z-index: 2; }
#recBar .rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: recBlink 1s infinite; }
@keyframes recBlink { 50% { opacity: .25; } }
#recTime { font-variant-numeric: tabular-nums; font-weight: 600; }
#recHint { color: var(--muted); font-size: 13px; flex: 1; text-align: center; }
#recBar.cancel #recHint { color: var(--danger); font-weight: 600; }
.bubble.voice { padding: 6px; }
.bubble.voice audio { display: block; width: min(260px, 62vw); height: 40px; }
/* settings + nickname sheets */
#settings, #nickSheet { position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 15px; }
.set-row small { color: var(--muted); margin-left: 4px; }
.set-row input[type=checkbox] { width: 20px; height: 20px; }
.set-note { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.set-note:empty { display: none; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; color: var(--muted); padding: 6px 9px; border-radius: 8px; font-size: 13px; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.nick-for { margin: 0 0 10px; font-weight: 600; }
#nickInput { width: 100%; }
.nick-btns { display: flex; gap: 8px; margin-top: 12px; }
@media (max-width: 720px) {
  #settings, #nickSheet { align-items: flex-end; padding: 0; }
  #settings .sheet-card, #nickSheet .sheet-card { max-width: none; border-radius: 16px 16px 0 0; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
}
/* snap drawing */
#drawLayer { position: absolute; overflow: hidden; touch-action: none; }
#drawCanvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; touch-action: none; }
#drawItems { position: absolute; inset: 0; pointer-events: none; }
.d-item { position: absolute; pointer-events: auto; touch-action: none; cursor: grab; -webkit-user-select: none; user-select: none; line-height: 1; }
.d-item.sticker { transform: translate(-50%, -50%); }
.d-item.caption { left: 0; right: 0; transform: translateY(-50%); background: rgba(0,0,0,.55); color: #fff; text-align: center; font-weight: 600; padding: .35em .5em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-item.leaving { opacity: .35; }
#drawTools { position: absolute; right: 14px; top: calc(max(14px, env(safe-area-inset-top)) + 54px); display: flex; flex-direction: column; gap: 10px; z-index: 2; }
#drawTools .cam-round { font-size: 18px; font-weight: 700; }
#drawTools .cam-round.on { background: #fff; color: #000; }
#penColors { position: absolute; right: 66px; top: calc(max(14px, env(safe-area-inset-top)) + 54px); display: flex; flex-direction: column; gap: 8px; z-index: 2; }
#penColors button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255,255,255,.8); padding: 0; }
#penColors button.on { transform: scale(1.25); border-color: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.4); }
#stickerTray { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(max(24px, env(safe-area-inset-bottom)) + 70px); width: min(340px, calc(100% - 28px)); display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; background: rgba(0,0,0,.65); border-radius: 16px; padding: 8px; z-index: 3; }
#stickerTray button { background: none; border: 0; font-size: 26px; padding: 4px 0; }
#chat #capInput { position: absolute; left: 14px; right: 14px; top: 40%; z-index: 4; font-size: 18px; padding: 12px 14px; border-radius: 12px; border: 0; background: rgba(0,0,0,.75); color: #fff; text-align: center; outline: none; }

/* ===== update 7: grouped messages (time only under the last one in a run) ===== */
.bubble-row.cont .meta > .t, .bubble-row.cont .meta > [data-exp] { display: none; }
.bubble-row.cont .meta:not(:has(.edited, .quick-reply, .receipt)) { display: none; }

/* ===== update 8: hover buttons next to a message (mouse/trackpad only) ===== */
.hover-acts { display: none; }
@media (hover: hover) and (pointer: fine) {
  .hover-acts { display: flex; position: absolute; top: 50%; left: 100%; transform: translateY(-50%); gap: 2px; padding: 0 6px;
    opacity: 0; pointer-events: none; transition: opacity .12s; white-space: nowrap; z-index: 2; }
  .mine .hover-acts { left: auto; right: 100%; flex-direction: row-reverse; }
  .bubble-row:hover .hover-acts, .hover-acts:focus-within { opacity: 1; pointer-events: auto; }
  .hover-acts button { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--text);
    font-size: 14px; line-height: 1; padding: 0; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
  .hover-acts button:hover { background: var(--me); color: var(--me-text); border-color: transparent; }
}

/* ===== update 9: camera filters, save snaps in chat, double-tap heart ===== */
#camera { touch-action: manipulation; }
#camCanvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#camera #camShootRow { flex-direction: column; gap: 14px; max-width: 100vw; }
#filterRow { display: flex; gap: 10px; overflow-x: auto; padding: 4px 16px; max-width: 100vw; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
#filterRow::-webkit-scrollbar { display: none; }
#filterRow button { flex: 0 0 auto; width: 46px; height: 46px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); background: rgba(0,0,0,.45); font-size: 22px; padding: 0; line-height: 1; }
#filterRow button.on { border-color: #fff; background: rgba(255,255,255,.3); transform: scale(1.12); }
#camHint { position: absolute; top: 40%; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.55); color: #fff; padding: 8px 14px; border-radius: 16px; font-size: 15px; font-weight: 600; pointer-events: none; white-space: nowrap; }
#snapActions { position: absolute; bottom: max(44px, calc(env(safe-area-inset-bottom) + 34px)); display: flex; gap: 10px; }
.saved-label { font-size: 11px; color: var(--muted); padding: 3px 4px 0; }
.mine .saved-label { text-align: right; }
#messages { touch-action: manipulation; }
.bubble { position: relative; }
.heart-burst { position: absolute; left: 50%; top: 50%; font-size: 34px; pointer-events: none; transform: translate(-50%, -50%) scale(.3); animation: heartBurst .7s ease-out forwards; z-index: 3; }
@keyframes heartBurst { 30% { transform: translate(-50%, -50%) scale(1.25); opacity: 1; } 100% { transform: translate(-50%, -110%) scale(1); opacity: 0; } }

/* ===== update 10: tap-to-load videos, video thumbs ===== */
.video-tile { display: flex; align-items: center; gap: 10px; min-width: 180px; padding: 22px 18px; border: 0; border-radius: 14px; background: #1f1f24; color: #fff; font-size: 14px; cursor: pointer; }
.video-tile .vt-play { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.18); display: grid; place-items: center; font-size: 16px; }
.thumb-video { display: inline-grid; place-items: center; font-size: 20px; background: #1f1f24; }
