:root {
  --ink:        #141D1B;
  --ink-2:      #1B2725;
  --ink-3:      #22302D;
  --ink-4:      #2C3B37;
  --paper:      #EDE6D9;
  --paper-dim:  #A2AFAA;
  --paper-faint:#6B7A75;
  --line:       rgba(237, 230, 217, .10);
  --line-soft:  rgba(237, 230, 217, .06);
  --danger:     #C4553F;
  --accept:     #3F8A63;

  /* Assigned per account at sign-in. Two people, two colors. */
  --me:   #C08A3E;
  --them: #7A6FA8;

  --sans:  "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --mono:  "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --r:     10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--me);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Sign in ─────────────────────────────────────────────────────── */

.login {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card { width: min(360px, 100%); }

.wordmark {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 38px;
  letter-spacing: -.02em;
  margin: 0;
}

.login-sub {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .04em;
  color: var(--paper-faint);
  margin: 6px 0 32px;
}

.field { display: block; margin-bottom: 16px; }

.field > span {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--paper-faint);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 13px;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--paper);
  font: 400 15px/1.3 var(--sans);
}

.field input[type="color"] { padding: 4px; height: 42px; }
.field input:focus { border-color: var(--me); outline: none; }

.btn-primary {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: var(--r);
  background: var(--me);
  color: #16110A;
  font-weight: 600;
  letter-spacing: .01em;
}

.btn-primary:disabled { opacity: .5; }

.btn-quiet {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: transparent;
  color: var(--paper-dim);
  font-size: 13px;
}

.btn-quiet.danger { color: var(--danger); border-color: rgba(196, 85, 63, .35); }

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin: 0 0 14px;
}

/* ── Layout ──────────────────────────────────────────────────────── */

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto auto;
  max-width: 820px;
  margin: 0 auto;
  border-inline: 1px solid var(--line-soft);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: var(--ink-2);
  border-bottom: 1px solid var(--line);
}

.peer { display: flex; align-items: center; gap: 11px; min-width: 0; }

.avatar {
  width: 38px; height: 38px;
  flex: none;
  border-radius: 50%;
  background: var(--ink-4) center/cover no-repeat;
  border: 1.5px solid var(--them);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--paper-dim);
}

.avatar.big { width: 96px; height: 96px; font-size: 30px; }

.peer-text { display: flex; flex-direction: column; min-width: 0; }

.peer-name { font-weight: 600; font-size: 15px; }

.peer-status {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--paper-faint);
  letter-spacing: .02em;
}

.peer-status.online { color: var(--accept); }

.topbar-actions { display: flex; gap: 2px; }

.icon-btn {
  width: 40px; height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--paper-dim);
}

.icon-btn:hover { background: var(--ink-3); color: var(--paper); }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn svg { width: 21px; height: 21px; fill: currentColor; }
.icon-btn.send { color: var(--me); }
#btn-mic { touch-action: none; }

.offline-banner {
  padding: 6px;
  text-align: center;
  background: var(--ink-4);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .06em;
  color: var(--paper-dim);
}

/* ── Timeline ────────────────────────────────────────────────────── */

.timeline {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-4) transparent;
}

.timeline::-webkit-scrollbar { width: 8px; }
.timeline::-webkit-scrollbar-thumb { background: var(--ink-4); border-radius: 4px; }

.messages { display: flex; flex-direction: column; gap: 3px; }

.load-older { text-align: center; padding-bottom: 12px; }

.daymark {
  align-self: center;
  margin: 18px 0 10px;
  padding: 3px 12px;
  border-radius: 20px;
  background: var(--ink-2);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--paper-faint);
}

.msg {
  position: relative;
  max-width: min(76%, 520px);
  padding: 9px 13px 7px;
  border-radius: 14px;
  background: var(--ink-2);
  animation: rise .16s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .msg { animation: none; }
}

.msg.mine {
  align-self: flex-end;
  background: var(--ink-3);
  border-right: 2px solid var(--me);
  border-top-right-radius: 5px;
}

.msg.theirs {
  align-self: flex-start;
  border-left: 2px solid var(--them);
  border-top-left-radius: 5px;
}

/* Consecutive messages from one person read as a paragraph, not a list. */
.msg.tail-mine   { border-top-right-radius: 14px; margin-top: -1px; }
.msg.tail-theirs { border-top-left-radius: 14px; margin-top: -1px; }

.msg-body {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-body a { color: var(--me); }
.msg.theirs .msg-body a { color: var(--them); }

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--paper-faint);
  letter-spacing: .03em;
}

.msg-edited { font-style: italic; }

.ticks { letter-spacing: -2px; }
.ticks.seen { color: var(--accept); letter-spacing: -3px; }

.quote {
  display: block;
  margin-bottom: 6px;
  padding: 5px 9px;
  border-left: 2px solid var(--paper-faint);
  border-radius: 4px;
  background: rgba(0, 0, 0, .18);
  font-size: 12.5px;
  color: var(--paper-dim);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quote-who { display: block; font-weight: 600; font-size: 11px; }

/* Attachments */

.att { margin: 2px 0 4px; }
.att img.photo, .att video {
  display: block;
  max-width: 100%;
  max-height: 380px;
  border-radius: 8px;
  background: var(--ink);
  cursor: pointer;
}

.att img.sticker {
  width: 132px; height: 132px;
  object-fit: contain;
}

.msg.sticker-only { background: transparent; border: 0; padding: 2px 0; }

.file-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, .18);
  color: inherit;
  text-decoration: none;
}

.file-chip .fname { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .fsize { font-family: var(--mono); font-size: 10.5px; color: var(--paper-faint); }

.voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 190px;
  padding: 4px 0;
}

.voice button {
  width: 34px; height: 34px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--me);
  color: #16110A;
  display: grid;
  place-items: center;
}

.msg.theirs .voice button { background: var(--them); color: #100D18; }
.voice svg { width: 15px; height: 15px; fill: currentColor; }

.voice-track {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--ink-4);
  position: relative;
}

.voice-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: 2px;
  background: var(--paper-dim);
}

.voice-time { font-family: var(--mono); font-size: 10.5px; color: var(--paper-faint); }

/* Reactions */

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }

.reaction {
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(0, 0, 0, .22);
  font-size: 13px;
  line-height: 1.5;
}

.reaction.by-me { border-color: var(--me); }

.typing-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px 2px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--paper-faint);
}

.typing-dots { display: inline-flex; gap: 3px; }

.typing-dots i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--them);
  animation: blink 1.2s infinite;
}

.typing-dots i:nth-child(2) { animation-delay: .2s; }
.typing-dots i:nth-child(3) { animation-delay: .4s; }

@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ── Composer ────────────────────────────────────────────────────── */

.reply-bar, .staging {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--ink-2);
  border-top: 1px solid var(--line);
}

.reply-bar-body { flex: 1; min-width: 0; border-left: 2px solid var(--me); padding-left: 9px; }

.reply-bar-label {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--paper-faint);
}

.reply-bar-text { font-size: 13px; color: var(--paper-dim); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.staging { flex-wrap: wrap; }

.stage-item {
  position: relative;
  width: 62px; height: 62px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--ink-4) center/cover no-repeat;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 9px;
  text-align: center;
  padding: 4px;
  color: var(--paper-dim);
}

.stage-item .x {
  position: absolute;
  top: 2px; right: 2px;
  width: 18px; height: 18px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .7);
  color: var(--paper);
  font-size: 12px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.stage-item .bar {
  position: absolute;
  left: 0; bottom: 0;
  height: 3px;
  background: var(--me);
  width: 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 8px 8px calc(8px + var(--safe-b));
  background: var(--ink-2);
  border-top: 1px solid var(--line);
}

.input-wrap { flex: 1; padding: 0 4px; }

#input {
  width: 100%;
  max-height: 148px;
  padding: 9px 12px;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--paper);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.45;
  resize: none;
}

#input:focus { outline: none; border-color: var(--ink-4); }
#input::placeholder { color: var(--paper-faint); font-family: var(--sans); font-size: 14px; }

.recording {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px calc(10px + var(--safe-b));
  background: var(--ink-3);
  border-top: 1px solid var(--line);
}

.rec-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1s infinite;
}

@keyframes pulse { 50% { opacity: .3; } }

.rec-time { font-family: var(--mono); font-size: 13px; }
.rec-hint { font-size: 11.5px; color: var(--paper-faint); }

/* ── Picker ──────────────────────────────────────────────────────── */

.picker {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(820px, 100%);
  max-height: 46vh;
  background: var(--ink-2);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 40;
  padding-bottom: var(--safe-b);
}

.picker-tabs { display: flex; gap: 4px; padding: 8px 12px 0; }

.tab {
  padding: 6px 12px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: var(--paper-faint);
  font-size: 12.5px;
}

.tab.active { background: var(--ink-4); color: var(--paper); }

.picker-body {
  overflow-y: auto;
  padding: 10px 12px 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 2px;
}

.picker-body.stickers { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }

.picker-body button {
  border: 0;
  background: transparent;
  font-size: 24px;
  padding: 4px;
  border-radius: 8px;
  line-height: 1.2;
}

.picker-body button:hover { background: var(--ink-4); }
.picker-body img { width: 100%; aspect-ratio: 1; object-fit: contain; }

.picker-group {
  grid-column: 1 / -1;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--paper-faint);
  padding: 8px 2px 2px;
}

/* ── Menus, sheets, toast ───────────────────────────────────────── */

.menu {
  position: fixed;
  z-index: 60;
  min-width: 168px;
  padding: 5px;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}

.menu button {
  display: block;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: 13.5px;
}

.menu button:hover { background: var(--ink-4); }
.menu button.danger { color: var(--danger); }

.menu-react {
  display: flex;
  gap: 2px;
  padding: 4px 3px 7px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.menu-react button { width: 34px; padding: 4px; font-size: 20px; text-align: center; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(10, 15, 14, .72);
  display: grid;
  place-items: center;
  padding: 20px;
}

.sheet-card {
  width: min(400px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.sheet-card h2 { font-family: var(--serif); font-size: 22px; margin: 0 0 18px; font-weight: 600; }

.sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.hint { font-size: 12px; color: var(--paper-faint); margin: 4px 0 0; line-height: 1.5; }

.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions .btn-primary { flex: 1; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(8, 12, 11, .95);
  display: grid;
  place-items: center;
}

.lightbox img, .lightbox video { max-width: 96vw; max-height: 90vh; }
.lightbox-close { position: absolute; top: calc(12px + var(--safe-t)); right: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 90;
  padding: 9px 16px;
  border-radius: 20px;
  background: var(--ink-4);
  font-size: 13px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
}

/* ── Call ────────────────────────────────────────────────────────── */

.call, .incoming {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--ink);
}

.remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0B100F;
}

.call.audio-only .remote-video { display: none; }

.call-audio-face {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.call.audio-only .call-audio-face { display: flex; }
.call-peer-name { font-family: var(--serif); font-size: 24px; }

.local-video {
  position: absolute;
  right: 14px;
  top: calc(76px + var(--safe-t));
  width: 104px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0B100F;
}

.call.audio-only .local-video { display: none; }

.call-header {
  position: absolute;
  top: calc(16px + var(--safe-t));
  left: 0; right: 0;
  text-align: center;
}

.call-state { font-size: 14px; color: var(--paper-dim); }
.call-timer { font-family: var(--mono); font-size: 20px; margin-top: 3px; }

.call-quality {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 9px;
  border-radius: 20px;
  background: rgba(0, 0, 0, .45);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--paper-dim);
}

.call-controls, .incoming-actions {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(38px + var(--safe-b));
  display: flex;
  justify-content: center;
  gap: 16px;
}

.round-btn {
  width: 58px; height: 58px;
  border: 0;
  border-radius: 50%;
  background: rgba(237, 230, 217, .12);
  color: var(--paper);
  display: grid;
  place-items: center;
  backdrop-filter: blur(6px);
}

.round-btn svg { width: 24px; height: 24px; fill: currentColor; }
.round-btn.off { background: var(--paper); color: var(--ink); }
.round-btn.hangup { background: var(--danger); }
.round-btn.accept { background: var(--accept); }

.incoming { background: var(--ink); display: grid; place-items: center; }
.incoming-card { text-align: center; }
.incoming-name { font-family: var(--serif); font-size: 26px; margin-top: 18px; }

.incoming-kind {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--paper-faint);
  margin-top: 6px;
  animation: pulse 1.6s infinite;
}

.incoming-actions { bottom: calc(60px + var(--safe-b)); }

@media (max-width: 520px) {
  .msg { max-width: 84%; }
  .app { border-inline: 0; }
}
