/* sueta — dark, mobile-first. Safe areas + dvh + 16px inputs throughout. */

:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2129;
  --border: #262c36;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3fb68b;
  --accent-2: #2ea043;
  --mine: #1f3d33;
  --danger: #f85149;
  --vvh: 100dvh;
  --vvt: 0px;
  /* social-kit chrome (chips, invite sheet, homeChip) reads these */
  --soc-bg: var(--panel);
  --soc-fg: var(--text);
  --soc-dim: var(--muted);
  --soc-line: var(--border);
  --soc-accent: var(--accent);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#app,
.app {
  height: var(--vvh, 100dvh);
}

.app {
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  /* iOS standalone: when the keyboard shifts the layout viewport and the
     scrollTo(0,0) pin is refused, follow the visual viewport instead */
  transform: translateY(var(--vvt, 0px));
}

/* header */

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.5px;
  flex: 1;
  /* must be allowed to shrink, or the icon row overflows on narrow phones */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .top { gap: 6px; padding-left: 10px; padding-right: 10px; }
  .brand .ver { display: none; }
}

.brand .lock {
  font-size: 13px;
  opacity: 0.9;
}

.peers-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  cursor: pointer;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot.ok { background: var(--accent-2); }
.dot.idle { background: #d29922; }
.dot.down { background: var(--danger); }

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 19px;
  cursor: pointer;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
}
.icon-btn:active { background: var(--panel-2); }

/* roster dropdown */

.roster {
  position: absolute;
  top: calc(54px + env(safe-area-inset-top));
  right: 10px;
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  min-width: 220px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.5);
}

.roster-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  font-size: 14px;
}
.roster-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-state { color: var(--muted); font-size: 12px; }

/* messages */

.msgs {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-anchor: auto;
}

.msg {
  display: flex;
  gap: 10px;
  position: relative;
  max-width: 100%;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  margin-top: 2px;
  user-select: none;
}

.msg-body { min-width: 0; flex: 1; }

.msg-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 3px;
}
.msg-name { font-weight: 600; font-size: 13.5px; }
.msg-time { color: var(--muted); font-size: 11.5px; }

.msg-bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px 14px 14px 14px;
  padding: 9px 12px;
  width: fit-content;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
}

.msg.mine .msg-bubble {
  background: var(--mine);
  border-color: #2b5546;
}

.msg-bubble a { color: var(--accent); }

/* images */

.img-box {
  max-width: min(70vw, 380px);
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel-2);
}
.img-box img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  cursor: pointer;
}
.img-box.loading {
  display: flex;
  align-items: flex-end;
  min-width: 200px;
}
.img-progress {
  width: 100%;
  height: 5px;
  background: rgb(255 255 255 / 0.08);
}
.img-progress div {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}
.img-box.expired {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 200px;
}
.img-expired {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 12px;
}

/* reactions */

.chips { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }

.chip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  cursor: pointer;
}
.chip.on { border-color: var(--accent); background: rgb(63 182 139 / 0.15); }

.thread-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  margin-top: 5px;
  padding: 4px 2px;
}

/* hover action bar (desktop) */

.hoverbar {
  position: absolute;
  top: -14px;
  right: 6px;
  display: none;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 4px;
  z-index: 5;
}
@media (hover: hover) {
  .msg:hover .hoverbar { display: flex; }
}
.hb {
  background: none;
  border: none;
  font-size: 15px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 999px;
}
.hb:hover { background: var(--panel); }

/* long-press action sheet */

.actions {
  position: absolute;
  top: -46px;
  left: 44px;
  display: flex;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 8px;
  z-index: 20;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.5);
}
.ab {
  background: none;
  border: none;
  font-size: 19px;
  cursor: pointer;
  padding: 6px;
  border-radius: 999px;
  color: var(--text);
}
.ab.reply { font-size: 14px; white-space: nowrap; }
.ab:active { background: var(--panel); }

/* composer */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  flex: none;
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 18px;
  padding: 10px 14px;
  /* explicit properties — a `font:` shorthand with `inherit` inside is invalid
     CSS and gets dropped entirely, leaving the UA's ~13px default, which makes
     iOS Safari zoom in on focus. ≥16px is what prevents that zoom. */
  font-size: 16px;
  line-height: 1.4;
  font-family: inherit;
  max-height: 120px;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }

.icon-btn.send { color: var(--accent); font-size: 21px; }

/* thread panel */

.thread {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  z-index: 40;
  animation: slide-in 0.18s ease-out;
}
@keyframes slide-in {
  from { transform: translateX(30%); opacity: 0.5; }
  to { transform: none; opacity: 1; }
}

.thread-sep {
  border-top: 1px solid var(--border);
  margin: 2px 0 6px;
}

/* modal */

.overlay {
  position: fixed;
  inset: 0;
  /* keyboard-aware: cover the VISIBLE viewport, not the layout viewport, so
     centered modals stay above the iOS keyboard */
  top: var(--vvt, 0px);
  bottom: auto;
  height: var(--vvh, 100dvh);
  background: rgb(0 0 0 / 0.6);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
  overflow-y: auto;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px 22px;
  width: min(100%, 360px);
  /* grid items default to min-width:auto — without this the box refuses to
     shrink below its content and drifts off-center on narrow screens */
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.modal h2 { font-size: 22px; letter-spacing: 1px; }
.modal p { color: var(--muted); font-size: 13px; }
.modal input {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
  text-align: center;
}
.modal input:focus { border-color: var(--accent); }

button.primary {
  background: var(--accent-2);
  border: none;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
}

/* image viewer */

.viewer {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.92);
  display: grid;
  place-items: center;
  z-index: 90;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.viewer img { max-width: 100vw; max-height: 100%; object-fit: contain; }

/* toast */

.toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13.5px;
  z-index: 110;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in {
  from { transform: translate(-50%, 8px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* empty-room hint */

.empty {
  margin: auto;
  max-width: 340px;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px 12px;
  font-size: 14px;
}
.empty strong { color: var(--text); }
.empty-lock { font-size: 34px; }
.empty code {
  background: var(--panel-2);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12.5px;
}

/* lobby */

.lobby { background: var(--bg); align-items: start; padding-top: max(8vh, env(safe-area-inset-top)); }
.lobby-box { text-align: center; width: min(100%, 400px); }

.room-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 46vh;
  overflow-y: auto;
  text-align: left;
}

.room-row { display: flex; align-items: center; gap: 4px; }

.room-open {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 15px;
  cursor: pointer;
  min-width: 0;
}
.room-open:active { border-color: var(--accent); }
.room-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-ago { color: var(--muted); font-size: 12px; flex: none; }

.icon-btn.small { min-width: 38px; min-height: 38px; font-size: 15px; color: var(--muted); }
.icon-btn.small.armed {
  color: #fff;
  background: var(--danger);
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}

.new-room-form { display: flex; gap: 8px; }
.new-room-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 16px;
  outline: none;
}
.new-room-form input:focus { border-color: var(--accent); }
.new-room-form .primary { padding: 11px 16px; white-space: nowrap; }

.rename-in {
  flex: 1;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
}

button.ghost.armed { border-color: var(--danger); color: var(--danger); }

.copy-out {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 16px;
  outline: none;
  text-align: center;
}

.hint { color: var(--muted); font-size: 12.5px; }

/* identity */

.roster-badge { font-size: 12px; letter-spacing: 1px; }
.roster-row.clickable { cursor: pointer; border-radius: 8px; }
.roster-row.clickable:active { background: var(--panel-2); }

.msg-id { font-size: 10.5px; letter-spacing: 1px; opacity: 0.85; }

.id-sheet { gap: 12px; }
.fp-emoji { font-size: 34px; letter-spacing: 6px; }
.fp-hex {
  font: 10.5px/1.5 ui-monospace, monospace;
  color: var(--muted);
  word-break: break-all;
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 10px;
  user-select: all;
}
.warn { color: #d29922; font-size: 13px; }

.id-sheet form { display: flex; flex-direction: column; gap: 8px; }
.id-sheet input[readonly] { color: var(--muted); }
.id-row { display: flex; gap: 8px; justify-content: center; }

button.ghost {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

/* calls */

.callbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  border-top: 2px solid var(--accent);
  flex: none;
}
.call-info { font-size: 13.5px; color: var(--text); flex: 1; }
.cb {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 14px;
  font-size: 15px;
  cursor: pointer;
}
.cb.join { background: var(--accent-2); border: none; color: #fff; font-weight: 600; }
.cb.danger { color: var(--danger); border-color: var(--danger); }
.cb.off { opacity: 0.55; background: var(--bg); }

.tiles {
  flex: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 6px;
  padding: 6px 10px;
  max-height: 42vh;
  overflow-y: auto;
  background: var(--bg);
}
.tile {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel);
  cursor: pointer;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile video.mirror { transform: scaleX(-1); }
.tile.big { grid-column: 1 / -1; aspect-ratio: 16 / 10; }
.tile.novideo video { display: none; }
.tile-avatar {
  display: none;
  position: absolute;
  inset: 0;
  margin: auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 22px;
  text-align: center;
  line-height: 52px;
}
.tile.novideo .tile-avatar { display: block; }
.tile-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 3px 8px;
  font-size: 11.5px;
  color: #fff;
  background: linear-gradient(transparent, rgb(0 0 0 / 0.65));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* versioning */

.ver { color: var(--muted); font-size: 11px; font-weight: 400; letter-spacing: 0; }

.update-banner {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--accent-2);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.45);
  max-width: 92vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: toast-in 0.25s ease-out;
}

.hidden { display: none !important; }

/* scrollbars (desktop) */
.msgs::-webkit-scrollbar { width: 8px; }
.msgs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
