:root {
  --bg: #0f1115;
  --panel: #161a22;
  --panel2: #1d222c;
  --text: #e6e8ee;
  --muted: #7a8294;
  --accent: #6aa2ff;
  --me: #2b6cb0;
  --them: #2d3340;
  --border: #262c38;
}
* { box-sizing: border-box; }
/* The document itself must never scroll — #app is a fixed-height flex column
   and .scroll is the only scrollable region. Without this the soft keyboard
   scrolls the whole page and takes the header off the top of the screen. */
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text);
  overflow: hidden; overscroll-behavior: none;
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

/* svh = small viewport (address bar visible). dvh = dynamic (progressive). never clips. */
#app { height: 100svh; height: 100dvh; display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom); }

/* discreet gate */
.gate { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 24px; }
.gate h1 { font-weight: 400; color: var(--muted); font-size: 14px; margin: 0 0 12px; letter-spacing: 1px; text-transform: uppercase; }
.gate input[type=password] {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: 10px 14px; border-radius: 8px; font-size: 16px; width: 240px; outline: none;
  text-align: center;
}
.gate input:focus { border-color: var(--accent); }
.gate .err { color: #ff7373; font-size: 13px; margin-top: 10px; min-height: 16px; }

/* SSO login */
.sso-section { margin-bottom: 16px; }
.sso-btn { background: var(--accent); color: #fff; border: 0; padding: 12px 24px; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; min-width: 240px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.sso-btn:hover { opacity: 0.9; }
.login-divider { color: var(--muted); font-size: 12px; text-align: center; margin: 16px 0; text-transform: uppercase; letter-spacing: 1px; }

/* pin keypad */
.pin-dots { display: flex; gap: 16px; margin-bottom: 28px; }
.pin-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); transition: background .1s, border-color .1s; }
.pin-dot.filled { background: var(--accent); border-color: var(--accent); }
.pin-dot.err { background: #f87171; border-color: #f87171; }
.pin-keypad { display: grid; grid-template-columns: repeat(3, 72px); grid-template-rows: repeat(4, 64px); gap: 10px; }
.pin-keypad button { background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 12px; font-size: 22px; font-weight: 500; cursor: pointer; display: flex; align-items: center; justify-content: center; -webkit-tap-highlight-color: transparent; transition: background .1s; }
.pin-keypad button:active { background: var(--panel2); }
.pin-keypad button.pin-back { font-size: 20px; color: var(--muted); }
.pin-keypad button.pin-empty { background: transparent; border-color: transparent; cursor: default; pointer-events: none; }

/* chat */
.bar { display: flex; align-items: center; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--border); gap: 8px; flex-shrink: 0; min-height: 44px; }
.bar-left { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.bar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.me-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.bar button { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 5px 9px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.bar button:hover { color: var(--text); border-color: var(--accent); }
.hamburger { font-size: 18px !important; padding: 4px 8px !important; }

/* hamburger dropdown */
.hamburger-menu { position: fixed; z-index: 200; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 6px; min-width: 180px; box-shadow: 0 4px 24px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 2px; }
.hamburger-menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.hamburger-menu .version { font-size: 11px; color: var(--muted); padding: 4px 10px; }
.hamburger-menu button { background: transparent; border: 0; color: var(--text); padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; text-align: left; }
.hamburger-menu button:hover { background: var(--panel2); }
.hamburger-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; font-size: 13px; color: var(--muted); gap: 12px; }
.hamburger-select { background: var(--panel2); border: 1px solid var(--border); color: var(--text); padding: 4px 8px; border-radius: 6px; font-size: 13px; cursor: pointer; outline: none; }
.hamburger-select:focus { border-color: var(--accent); }

/* chat switcher */
.chat-switcher-btn { background: transparent; border: 1px solid var(--border); color: var(--text); padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 4px; }
.chat-switcher-btn:hover { color: var(--text); border-color: var(--accent); }
.chat-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.chat-switcher-arrow { font-size: 10px; color: var(--muted); }
.chat-switcher-menu { position: fixed; z-index: 200; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 6px; min-width: 200px; max-width: 280px; box-shadow: 0 4px 24px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 2px; max-height: 70vh; }
.chat-switcher-header { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; padding: 6px 10px; font-weight: 600; }
.chat-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; min-height: 0; }
.chat-item { background: transparent; border: 0; color: var(--text); padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item:hover { background: var(--panel2); }
.chat-item.active { background: rgba(106,162,255,.15); color: var(--accent); font-weight: 600; }
.chat-switcher-menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.new-chat-btn { background: transparent; border: 0; color: var(--accent); padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; text-align: left; font-weight: 500; }
.new-chat-btn:hover { background: var(--panel2); }

/* pins panel */
.pins-panel { position: fixed; left: 0; right: 0; z-index: 190; background: var(--panel); border-bottom: 1px solid var(--border); box-shadow: 0 4px 20px rgba(0,0,0,.5); max-height: 50vh; overflow-y: auto; }
.pin-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.pin-item:hover { background: var(--panel2); }
.pin-item:last-child { border-bottom: 0; }
.pin-icon { font-size: 16px; flex-shrink: 0; color: var(--accent); }
.pin-content { flex: 1; min-width: 0; }
.pin-who { font-size: 11px; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.pin-body { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-remove { background: transparent; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; flex-shrink: 0; padding: 4px 6px; line-height: 1; }
.pin-remove:hover { color: #f87171; }
.pins-empty { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }
.pin-btn-wrap { position: relative; display: flex; align-items: center; }
.pin-badge { position: absolute; top: -4px; right: -5px; background: var(--accent); color: #fff; font-size: 9px; min-width: 14px; height: 14px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-weight: 700; padding: 0 3px; pointer-events: none; }

/* connection dot */
.conn-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.conn-dot.connected { background: #4ade80; }
.conn-dot.connecting { background: #facc15; animation: pulse 1s infinite; }
.conn-dot.disconnected, .conn-dot.slow { background: #f87171; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* presence */
.presence-row { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); flex: 2; justify-content: center; min-width: 0; overflow: hidden; }
.presence-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.presence-dot.active { background: #4ade80; }
.presence-dot.away { background: #facc15; }
.presence-dot.offline { background: #6b7280; }
.presence-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.scroll { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 14px; word-wrap: break-word; white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--me); border-bottom-right-radius: 4px; }
.msg.me.sending { opacity: 0.55; }
.msg.them { align-self: flex-start; background: var(--them); border-bottom-left-radius: 4px; }
.msg img, .msg video { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; }
.msg a { color: #93c5fd; text-decoration: underline; word-break: break-all; }
.msg a:hover { opacity: 0.8; }
.meta { font-size: 11px; color: var(--muted); margin: 2px 4px 4px; display: flex; align-items: center; gap: 4px; }
.meta.me { align-self: flex-end; }
.meta.them { align-self: flex-start; }
.meta .seen { color: var(--accent); font-size: 11px; }
.day { align-self: center; color: var(--muted); font-size: 11px; padding: 8px 0; }
.load-more { align-self: center; color: var(--muted); font-size: 13px; padding: 12px 0; }
.update-toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 10px 20px; border-radius: 20px; font-size: 13px; cursor: pointer; z-index: 300; box-shadow: 0 4px 16px rgba(0,0,0,.4); white-space: nowrap; }
.typing { color: var(--muted); font-size: 12px; padding: 0 12px 4px; min-height: 16px; flex-shrink: 0; }

.composer { display: flex; gap: 8px; padding: 8px; background: var(--panel); border-top: 1px solid var(--border); flex-shrink: 0; }
.composer-input-wrap {
  flex: 1; min-width: 0; background: var(--panel2); border: 1px solid var(--border); border-radius: 18px;
  overflow-y: auto; max-height: 120px; cursor: text; -webkit-user-select: text; user-select: text;
}
.composer-input-wrap:focus-within { border-color: var(--accent); }
.composer-input {
  color: var(--text); padding: 10px 12px; font: inherit; min-height: 40px; outline: none;
  white-space: pre-wrap; word-break: break-word; line-height: 1.4;
  -webkit-user-select: text; user-select: text;
}
.composer-input:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.composer button { background: var(--accent); color: white; border: 0; padding: 0 16px; border-radius: 18px; cursor: pointer; font: inherit; font-weight: 600; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.composer .icon { background: transparent; color: var(--muted); padding: 0 8px; font-size: 22px; line-height: 1; flex-shrink: 0; }
.composer .icon:hover { color: var(--text); }

/* emoji picker — small popup above composer */
.picker { position: absolute; bottom: calc(100% + 4px); left: 0; right: 0; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; padding: 8px; box-shadow: 0 -4px 24px rgba(0,0,0,.5); z-index: 10; }
.picker .tabs { display: flex; gap: 4px; margin-bottom: 6px; align-items: center; }
.picker .tabs button { flex: 1; background: transparent; border: 0; color: var(--muted); padding: 6px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.picker .tabs button.on { background: var(--panel2); color: var(--text); }
.picker-close { flex: 0 !important; color: var(--muted); font-size: 14px !important; padding: 4px 8px !important; }
.picker .grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; max-height: 200px; overflow-y: auto; }
.picker .grid button { background: transparent; border: 0; color: var(--text); font-size: 22px; padding: 4px; cursor: pointer; border-radius: 6px; }
.picker .grid button:hover { background: var(--panel2); }
.picker .loading { color: var(--muted); font-size: 13px; text-align: center; padding: 16px; }

/* gif picker — fullscreen overlay */
.gif-overlay { position: fixed; inset: 0; background: var(--bg); z-index: 100;
  display: flex; flex-direction: column; }
.gif-overlay .gif-header { display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--panel); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.gif-overlay .gif-search { flex: 1; background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: 20px; font: inherit; font-size: 15px; outline: none; }
.gif-overlay .gif-search:focus { border-color: var(--accent); }
.gif-overlay .gif-close { background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 8px 14px; border-radius: 20px; cursor: pointer; font-size: 13px; flex-shrink: 0; }
.gif-overlay .gif-close:hover { color: var(--text); border-color: var(--accent); }
.gif-overlay .gif-grid { flex: 1; overflow-y: auto; padding: 8px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; align-content: start; }
.gif-overlay .gif-grid button { background: transparent; border: 0; padding: 0; cursor: pointer;
  border-radius: 8px; overflow: hidden; aspect-ratio: 1; }
.gif-overlay .gif-grid button:hover { opacity: .85; }
.gif-overlay .gif-grid img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 8px; }
.gif-overlay .gif-loading { color: var(--muted); font-size: 13px; text-align: center; padding: 48px 0;
  grid-column: 1/-1; }

#composer-wrap { position: relative; flex-shrink: 0; }

/* reply quote inside message bubble */
.reply-quote { background: rgba(0,0,0,.25); border-left: 3px solid var(--accent); padding: 4px 8px; border-radius: 4px; margin-bottom: 6px; cursor: pointer; }
.reply-quote:hover { background: rgba(0,0,0,.38); }
@keyframes msg-flash { 0% { box-shadow: 0 0 0 3px rgba(106,162,255,0); } 35% { box-shadow: 0 0 0 3px rgba(106,162,255,.7); } 100% { box-shadow: 0 0 0 3px rgba(106,162,255,0); } }
.msg.flash { animation: msg-flash 1s ease; }
.reply-user { color: var(--accent); font-size: 11px; font-weight: 600; display: block; }
.reply-body { color: rgba(255,255,255,.6); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; max-width: 220px; }

/* reaction pills below message */
.msg-reactions { display: inline-flex; gap: 4px; flex-wrap: wrap; vertical-align: middle; }
.react-pill { background: var(--panel); border: 1px solid var(--border); color: var(--text); padding: 2px 8px; border-radius: 12px; cursor: pointer; font-size: 14px; line-height: 1.4; }
.react-pill.mine { border-color: var(--accent); background: rgba(106,162,255,.12); }
.react-pill:hover { border-color: var(--accent); }

/* floating action bar */
.action-bar { position: fixed; z-index: 150; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 6px 8px; display: flex; gap: 2px; box-shadow: 0 4px 24px rgba(0,0,0,.6); }
.action-bar button { background: transparent; border: 0; font-size: 24px; padding: 5px 8px; border-radius: 10px; cursor: pointer; line-height: 1; }
.action-bar button:hover { background: var(--panel2); }
.action-reply { font-size: 18px !important; color: var(--muted); }
.action-close { font-size: 14px !important; color: var(--muted); border-left: 1px solid var(--border) !important; margin-left: 2px; padding-left: 10px !important; }

/* draft attachment preview bar */
.draft-attach { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--panel); border-top: 1px solid var(--border); }
.draft-attach-thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex-shrink: 0; display: block; }
.draft-attach-icon { font-size: 26px; flex-shrink: 0; width: 56px; text-align: center; line-height: 56px; }
.draft-attach-name { flex: 1; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.draft-attach > button { background: transparent; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; flex-shrink: 0; padding: 0 4px; line-height: 1; }
.draft-attach > button:hover { color: var(--text); }

/* reply bar in composer */
.reply-bar { display: flex; align-items: center; padding: 6px 10px; background: var(--panel); border-top: 1px solid var(--border); gap: 8px; }
.reply-bar-content { flex: 1; font-size: 12px; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar-user { color: var(--accent); font-weight: 600; }
.reply-bar > button { background: transparent; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; flex-shrink: 0; line-height: 1; padding: 0 2px; }
.reply-bar > button:hover { color: var(--text); }

/* reaction editor overlay */
.react-editor { position: fixed; inset: 0; z-index: 200; background: var(--bg); display: flex; flex-direction: column; }
.react-editor-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--panel); border-bottom: 1px solid var(--border); font-size: 15px; font-weight: 600; flex-shrink: 0; }
.react-editor-header button { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 6px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.react-editor-section { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; padding: 12px 14px 6px; flex-shrink: 0; }
.react-editor-picks { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 14px 14px; flex-shrink: 0; min-height: 48px; }
.react-editor-pick { background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 5px 10px; cursor: pointer; font-size: 20px; display: flex; align-items: center; gap: 5px; }
.react-editor-pick:hover { border-color: #f87171; }
.react-editor-rm { font-size: 11px; color: var(--muted); line-height: 1; }
.react-editor-empty { font-size: 13px; color: var(--muted); padding: 8px 0; align-self: center; }
.react-editor-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; padding: 4px 14px 14px; overflow-y: auto; flex: 1; align-content: start; }
.react-editor-grid button { background: transparent; border: 1px solid transparent; font-size: 24px; padding: 6px 2px; cursor: pointer; border-radius: 8px; }
.react-editor-grid button:hover { background: var(--panel2); }
.react-editor-grid button.on { background: rgba(106,162,255,.15); border-color: var(--accent); }

/* image modal */
.img-modal { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.93); display: flex; flex-direction: column; }
.img-modal-toolbar { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 12px; flex-shrink: 0; }
.img-modal-toolbar button { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); color: #fff; padding: 8px 16px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.img-modal-toolbar button:hover { background: rgba(255,255,255,.22); }
.img-modal-stage { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; cursor: grab; }
.img-modal-stage.dragging { cursor: grabbing; }
.img-modal-stage img { max-width: 95vw; max-height: 85vh; object-fit: contain; transform-origin: center center; user-select: none; -webkit-user-select: none; pointer-events: none; }

/* clickable images in chat */
.msg img { cursor: zoom-in; }

/* video call */
.call-overlay { position: fixed; inset: 0; z-index: 300; background: #000; display: flex; flex-direction: column; }
.call-remote { flex: 1; width: 100%; object-fit: cover; background: #111; }
.call-local { position: absolute; top: 60px; right: 12px; width: 90px; height: 130px; object-fit: cover; border-radius: 12px; border: 2px solid rgba(255,255,255,.25); background: #222; cursor: pointer; z-index: 1; }
.call-status { position: absolute; top: 0; left: 0; right: 0; padding: 20px; text-align: center; color: rgba(255,255,255,.75); font-size: 15px; pointer-events: none; }
.call-controls { display: flex; justify-content: center; gap: 20px; padding: 20px 0 44px; background: linear-gradient(transparent, rgba(0,0,0,.75)); flex-shrink: 0; }
.call-controls button { width: 62px; height: 62px; border-radius: 50%; border: 0; font-size: 24px; cursor: pointer; display: flex; align-items: center; justify-content: center; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.call-btn-end { background: #ef4444; color: #fff; }
.call-btn-toggle { background: rgba(255,255,255,.2); color: #fff; }
.call-btn-toggle.off { background: rgba(255,255,255,.5); }
.call-incoming { position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 10px; }
.call-incoming-who { color: #fff; font-size: 26px; font-weight: 600; }
.call-incoming-sub { color: rgba(255,255,255,.5); font-size: 13px; letter-spacing: .5px; text-transform: uppercase; }
.call-incoming-btns { display: flex; gap: 36px; margin-top: 28px; }
.call-incoming-btns button { width: 72px; height: 72px; border-radius: 50%; border: 0; font-size: 28px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.call-accept-btn { background: #22c55e; }
.call-reject-btn { background: #ef4444; }

/* attach submenu button — the "+" left of the composer.
   Scoped to .composer so it beats `.composer button`, which would otherwise
   win on specificity and silently decide this button's colours. */
.composer .attach-btn {
  background: var(--accent); color: #fff; border: 0;
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  flex-shrink: 0; align-self: center;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1; font-weight: 400; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.composer .attach-btn:hover { filter: brightness(1.12); }
.composer .attach-btn:active { transform: scale(0.92); }

/* attach submenu popup */
.attach-menu { position: absolute; bottom: calc(100% + 4px); left: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 6px; box-shadow: 0 -4px 24px rgba(0,0,0,.5); z-index: 10; display: flex; flex-direction: row; gap: 2px; flex-wrap: wrap; max-width: calc(100vw - 24px); }
.attach-menu button { background: transparent; border: 0; color: var(--muted); padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 20px; line-height: 1; }
.attach-menu button:hover { background: var(--panel2); color: var(--text); }

@media (min-width: 600px) {
  .gif-overlay .gif-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 900px) {
  .gif-overlay .gif-grid { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 480px) {
  .picker .grid { grid-template-columns: repeat(7, 1fr); }
}

/* history PIN modal */
.pin-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 200; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.pin-modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 28px 24px; display: flex; flex-direction: column; align-items: center; min-width: 280px; }
.pin-modal-title { color: var(--muted); font-size: 13px; margin-bottom: 20px; text-align: center; }
.pin-modal-cancel { margin-top: 16px; background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 8px; padding: 6px 20px; font-size: 14px; cursor: pointer; }
.pin-modal-cancel:hover { color: var(--text); }

/* duress screen — see renderDuress() in app.js */
.duress {
  position: fixed; inset: 0; z-index: 500;
  background: #000; color: #33ff66;
  font-family: "SF Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  display: flex; flex-direction: column;
  user-select: none; -webkit-user-select: none;
}
.duress-head {
  flex-shrink: 0; padding: 8px 10px;
  border-bottom: 1px solid #0b4d1f;
  color: #7dffa4; font-size: 11px; letter-spacing: 1.5px;
  text-shadow: 0 0 6px rgba(51,255,102,.55);
}
.duress-feed {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 8px 10px 20px;
  font-size: 11px; line-height: 1.45;
  text-shadow: 0 0 5px rgba(51,255,102,.35);
  overflow-wrap: anywhere;
}
.duress-line { white-space: pre-wrap; opacity: .88; }
.duress-line.crit { color: #ff5f5f; text-shadow: 0 0 6px rgba(255,95,95,.45); opacity: 1; }
.duress-ts { color: #1f8f45; }
.duress-sev { color: #b9ffcf; }

/* askText / askConfirm — in-app replacements for window.prompt/confirm, which
   an installed PWA suppresses (see the prompts section in app.js) */
.ask-overlay { position: fixed; inset: 0; z-index: 250; background: rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.ask-modal { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; min-width: 300px; max-width: 90vw; display: flex; flex-direction: column; box-shadow: 0 8px 32px rgba(0,0,0,.6); }
.ask-header { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.ask-header h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--text); }
.ask-body { padding: 16px 20px 4px; }
.ask-input {
  width: 100%; background: var(--panel2); border: 1px solid var(--border);
  color: var(--text); padding: 11px 13px; border-radius: 10px;
  font: inherit; font-size: 16px; outline: none;   /* 16px stops iOS zoom-on-focus */
}
.ask-input:focus { border-color: var(--accent); }
.ask-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px 18px; }
.ask-actions button {
  border: 0; border-radius: 10px; padding: 9px 18px;
  font: inherit; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ask-ok { background: var(--accent); color: #fff; }
.ask-ok:hover { filter: brightness(1.1); }
.ask-ok.danger { background: #ef4444; }
.ask-cancel { background: transparent; color: var(--muted); border: 1px solid var(--border) !important; }
.ask-cancel:hover { color: var(--text); }

/* chat background — an uploaded image set as the room's wallpaper.
   Sits behind everything in #app; .bar and #composer-wrap are opaque panels, so
   it reads as the message area's backdrop. The scrim keeps text legible over a
   bright photo without needing to know anything about the image. */
#app { position: relative; }
.chat-bg {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background-position: center; background-size: cover; background-repeat: no-repeat;
  opacity: 0; transition: opacity .25s ease;
}
.chat-bg.on { opacity: 1; }
.chat-bg.on::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(rgba(15,17,21,.62), rgba(15,17,21,.72));
}
/* everything else has to sit above the wallpaper */
.bar, .scroll, .typing, #composer-wrap { position: relative; z-index: 1; }
.chat-bg.on ~ .scroll .msg.them { background: rgba(45,51,64,.92); }
.chat-bg.on ~ .scroll .msg.me { background: rgba(43,108,176,.92); }
.chat-bg.on ~ .typing { text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.chat-bg.on ~ .scroll .day { text-shadow: 0 1px 3px rgba(0,0,0,.8); }

/* shown when a chat's messages fail to load — an empty room and a failed load
   look identical otherwise */
.chat-load-error {
  margin: auto; text-align: center; color: var(--muted); font-size: 13px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.chat-load-error button {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 18px; font: inherit; cursor: pointer;
}
.chat-load-error button:hover { border-color: var(--accent); }

/* a message the server refused — previously these just sat pending forever */
.msg.failed { opacity: .55; border: 1px dashed #f87171; }
.meta.failed { color: #f87171; }
