/* CONNECT — mobile first. No framework, no build: the file you edit is the file
   that runs.

   Khaki, and dark. The palette is one hue family — olive drab from near-black
   through to a dusty yellow-green — because a messenger is read for hours and a
   second competing hue is what makes an interface tiring. Colour is spent on
   three things only: what is yours, what needs attention, and what is dangerous.

   The shape borrows from the messenger everyone already knows how to use: an
   identity in the header rather than a hex string, one bubble per message with
   the time inside it, a composer whose right-hand button changes with what you
   are doing. Where it differs, it differs on purpose — the key of the person
   you are talking to stays visible, because here it is the only thing that
   actually identifies them. */

:root {
  color-scheme: dark;

  --bg: #12140e;
  --bg-2: #191c13;
  --panel: #1f2318;
  --panel-2: #262b1c;
  --line: #2c3222;
  --line-2: #3d4530;

  --text: #eceadb;
  --muted: #a5a68f;
  --dim: #71735e;

  --accent: #c2b264;
  --accent-dim: #8f8447;
  /* Your own words, in the one place the palette allows a filled shape. */
  --mine: #3b4426;
  --mine-line: #4f5b34;

  --ok: #9fc07a;
  --warn: #d8b26a;
  --danger: #e08a7a;

  --radius: 14px;
  --bubble: 16px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  --bar-h: 54px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
/* A class selector beats the browser's own [hidden] rule, so any element given
   a display here would ignore the attribute entirely. That is how the back
   arrow ended up permanently visible on a screen with nothing to go back to. */
[hidden] { display: none !important; }
.screen { height: 100svh; display: flex; flex-direction: column; }
.small { font-size: .85rem; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; }
.warn { color: var(--warn); }

/* ------------------------------------------------------------------ lock */

#lock { align-items: center; justify-content: center; padding: 24px; }
.lock-inner { width: min(420px, 100%); text-align: center; }

.wordmark {
  margin: 0;
  font-weight: 200;
  font-size: clamp(2.6rem, 14vw, 4rem);
  letter-spacing: .14em;
  text-indent: .14em;
  background: linear-gradient(180deg, #f2efdd 0%, var(--accent-dim) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { margin: 8px 0 32px; color: var(--muted); font-weight: 300; }

.stack { display: flex; flex-direction: column; gap: 12px; text-align: left; }

.phrase {
  margin: 0;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  font: 400 1rem/1.7 var(--mono);
  white-space: pre-wrap;
  word-spacing: .3em;
  text-align: left;
}

.check { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: .92rem; }
.check input { width: auto; }

/* --------------------------------------------------------------- controls */

button {
  font: inherit;
  padding: .78em 1.1em;
  border-radius: 11px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
button:disabled { opacity: .45; cursor: default; }

.primary { background: var(--accent); border-color: var(--accent); color: #17190f; font-weight: 600; }
.primary:hover:not(:disabled) { background: #cfbe6f; }
.ghost { background: var(--panel); border-color: var(--line-2); color: var(--text); }
.ghost:hover { border-color: #4d5740; background: var(--panel-2); }
.ghost.danger { color: var(--danger); }
.ghost.small { flex: none; padding: .45em .8em; font-size: .82rem; }

input, textarea, select {
  font: inherit;
  width: 100%;
  padding: .72em .9em;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 11px;
  color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent-dim); }
textarea { resize: vertical; font-family: var(--mono); }
::placeholder { color: var(--dim); }

/* -------------------------------------------------------------- app chrome */

.bar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: var(--bar-h);
  padding: max(env(safe-area-inset-top), 8px) 8px 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 20, 14, .92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.bar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.bar-title #title {
  font-weight: 600;
  font-size: 1.02rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* The key of whoever you are talking to. Small, permanent, and the only thing
   in the header that cannot be chosen by someone else. */
.bar-sub {
  font-family: var(--mono);
  font-size: .68rem;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
}
.icon:hover { color: var(--text); background: var(--panel); }
.icon svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.big { width: 44px; height: 44px; }
.icon.big svg { width: 24px; height: 24px; }

#views { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view { padding: 12px; display: flex; flex-direction: column; gap: 12px; min-height: 100%; }
.view[data-view="chat"] { padding: 8px 10px 10px; gap: 0; }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--dim);
  font-size: .8rem;
  padding: .85em 0;
}
.tabs button.on { color: var(--accent); }

/* ------------------------------------------------------------- avatars */

/* An initial in a coloured disc, with the colour derived from the key rather
   than chosen — so the same person is the same colour on every device, and two
   people are rarely the same. */
.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-weight: 600;
  font-size: 1.05rem;
  color: #13150e;
  user-select: none;
}
.avatar.sm { width: 34px; height: 34px; font-size: .85rem; }

/* ---------------------------------------------------------------- content */

.list { display: flex; flex-direction: column; }

.row-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "face who when" "face preview meta";
  column-gap: 12px;
  row-gap: 2px;
  align-items: center;
  padding: 10px 8px;
  background: none;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.row-item:hover { background: var(--panel); }
.row-item .avatar { grid-area: face; }
.row-item .who {
  grid-area: who;
  font-weight: 600;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-item .who.mono { font-family: var(--mono); font-size: .82rem; font-weight: 400; color: var(--accent); }
.row-item .preview {
  grid-area: preview;
  color: var(--muted);
  font-size: .9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-item .when { grid-area: when; color: var(--dim); font-size: .74rem; }
.row-item .meta { grid-area: meta; color: var(--dim); font-size: .74rem; text-align: right; }

.empty { color: var(--dim); text-align: center; padding: 40px 12px; margin: 0; }

/* --------------------------------------------------------------- messages */

/* Grows to fill, so the composer sits at the bottom of the screen in an empty
   conversation instead of halfway up it. */
.messages { flex: 1 0 auto; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; padding: 6px 0 10px; }

/* A date, once, where the day changes — rather than a date inside every
   bubble, which is what the timestamps used to be. */
.day {
  align-self: center;
  margin: 14px 0 8px;
  padding: 3px 12px;
  background: var(--panel);
  border-radius: 999px;
  color: var(--muted);
  font-size: .74rem;
}

.msg {
  position: relative;
  max-width: 78%;
  padding: 7px 11px 6px;
  border-radius: var(--bubble);
  font-size: .96rem;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.msg.in { align-self: flex-start; background: var(--panel); border-bottom-left-radius: 5px; }
.msg.out { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 5px; }

/* Consecutive messages from the same side belong together: the tight corner
   appears only on the last of a run, which is what makes a burst read as one
   turn rather than as five interruptions. */
.msg.grouped.in { border-bottom-left-radius: var(--bubble); }
.msg.grouped.out { border-bottom-right-radius: var(--bubble); }
.msg.grouped { margin-bottom: 0; }
.msg + .msg { margin-top: 2px; }
.msg.starts { margin-top: 10px; }

.msg .stamp {
  float: right;
  margin: 6px 0 0 10px;
  font-size: .68rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.msg.out .stamp { color: #9aa383; }
.msg.elsewhere .stamp::after { content: " · с другого устройства"; }

.composer {
  display: flex;
  gap: 6px;
  align-items: center;
  padding-top: 8px;
}
.composer input { flex: 1; border-radius: 20px; }
.composer button { flex: none; }
.view[data-view="chat"] .composer {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(18, 20, 14, 0) 0%, var(--bg) 28%);
  padding-bottom: 4px;
}

.send, .icon.send { background: var(--accent); border-color: var(--accent); color: #17190f; }
.send:hover, .icon.send:hover { background: #cfbe6f; color: #17190f; }
#record.recording { color: var(--danger); background: var(--panel); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }
@media (prefers-reduced-motion: reduce) { #record.recording { animation: none; } }

/* ----------------------------------------------------------------- panels */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel .small { margin: 0; }

.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.kv span:first-child { color: var(--muted); font-size: .88rem; flex: none; }
.kv code, .kv span:last-child {
  font-family: var(--mono);
  font-size: .74rem;
  color: var(--text);
  overflow-wrap: anywhere;
  text-align: right;
}

.row { display: flex; gap: 10px; align-items: center; }
.row label { color: var(--muted); font-size: .9rem; flex: none; }

.trust-line { display: flex; gap: 10px; align-items: flex-start; font-size: .88rem; color: var(--muted); }
.dot { flex: none; width: 9px; height: 9px; margin-top: .45em; border-radius: 50%; }
.dot.yes { background: var(--ok); }
.dot.no { background: var(--danger); }

.sharing {
  padding: 12px 14px;
  background: #2a2a16;
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  color: var(--warn);
  font-size: .88rem;
}

.invite .qr { display: grid; place-items: center; padding: 14px; background: var(--bg-2); border-radius: var(--radius); }
.qr { color: var(--text); }
.qr svg { display: block; width: min(240px, 70vw); height: auto; }
.invite .phrase { font-size: .9rem; }

.alarm {
  padding: 12px 14px;
  background: #2e1a16;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: #f3c9c0;
  font-size: .9rem;
}
.alarm strong { color: var(--danger); }

/* ------------------------------------------------------------------ files */

.msg.has-media { padding: 4px 4px 5px; max-width: 74%; }
.msg.has-media .stamp { margin-right: 7px; }

.media img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 58vh;
  object-fit: cover;
  border-radius: 12px;
  cursor: zoom-in;
  background: var(--bg-2);
}
.media audio { display: block; width: min(250px, 58vw); margin: 2px; }
.media.loading { opacity: .55; }

.media-open {
  display: block;
  width: 100%;
  padding: .7em .9em;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 11px;
  color: var(--text);
  font: inherit;
  font-size: .88rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.media-open.bad { color: var(--danger); border-color: var(--danger); }

/* ------------------------------------------------------------ sheet menu */

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg-2);
  border-top: 1px solid var(--line-2);
  border-radius: var(--radius) var(--radius) 0 0;
  transform: translateY(100%);
  transition: transform .16s ease-out;
}
.sheet.open { transform: none; }
@media (prefers-reduced-motion: reduce) { .sheet { transition: none; transform: none; } }

.sheet-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  font: inherit;
  text-align: left;
}
.sheet-item.danger { color: var(--danger); }
.sheet-item:hover { background: var(--panel-2); border-color: var(--line-2); }

/* ------------------------------------------------------------------- call */

.call {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #2a301c 0%, var(--bg) 72%);
}
.call-inner { width: min(340px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.call-inner .avatar { width: 96px; height: 96px; font-size: 2.2rem; margin-bottom: 6px; }
.call-who { margin: 0; font-size: 1.45rem; font-weight: 600; }
.call-status {
  margin: 0;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}
.call .stack { width: 100%; margin-top: 14px; }
#call-mute.on { color: var(--warn); border-color: var(--warn); }
#call-audio { display: none; }

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  z-index: 40;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 16px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  color: var(--text);
  font-size: .9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s, transform .16s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: var(--danger); color: #f3c9c0; }

/* --------------------------------------------------------------- settings */

/* A person at the top of their own settings, the way every phone does it —
   because the first question anyone has here is "who am I on this device". */
.profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 12px 6px;
  text-align: center;
}
.profile .composer { width: 100%; max-width: 380px; }
.profile p { margin: 0; max-width: 420px; }

.avatar.huge {
  width: 104px;
  height: 104px;
  padding: 0;
  border: 1px solid var(--line-2);
  font-size: 2.4rem;
  cursor: pointer;
}
.avatar.huge:hover { border-color: var(--accent-dim); }

/* Section headings, so a settings screen reads as a list of subjects rather
   than a stack of identical boxes. */
.section {
  margin: 14px 4px -4px;
  color: var(--accent-dim);
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* Одна галочка — письмо забрали, две — открыли. Точка, пока ни того ни другого:
   отправлено и лежит в ящике. */
.tick { margin-left: 6px; letter-spacing: -2px; }
.tick.read { color: var(--accent); }

/* ----------------------------------------------------------------- replies */

/* A quoted line, in the bubble and above the composer: the same shape in both
   places, because it is the same thing — what is being answered. */
.quote {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 5px;
  padding: 4px 8px;
  border-left: 2px solid var(--accent);
  border-radius: 5px;
  background: rgba(194, 178, 100, .09);
  cursor: pointer;
}
.quote-who { color: var(--accent); font-size: .78rem; font-weight: 600; }
.quote-text {
  color: var(--muted);
  font-size: .82rem;
  max-height: 2.6em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 8px;
}
.reply-bar .quote { flex: 1; min-width: 0; margin: 0; cursor: default; }

/* Where a quoted line points. Brief, and only as a nudge. */
.msg.found { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ search */

.search {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 20px;
}
.search svg {
  flex: none;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--dim);
  stroke-width: 1.8;
  stroke-linecap: round;
}
.search input { border: 0; background: none; padding: .62em 0; }
.search input:focus { outline: none; }
.search .icon { width: 28px; height: 28px; }
.search .icon svg { width: 15px; height: 15px; stroke: currentColor; }

/* ------------------------------------------------------------- video call */

/* The other person fills the screen; everything else floats over them. */
.call-remote {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0b0d08;
}

/* Yourself, small, in the corner a thumb does not cover, and mirrored — a
   camera pointed at your face should behave like a mirror. */
.call-local {
  position: absolute;
  top: max(env(safe-area-inset-top), 12px);
  right: 12px;
  width: min(30vw, 132px);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: #0b0d08;
  transform: scaleX(-1);
  z-index: 2;
}
.call-local.off { opacity: .25; }

/* With a picture on screen the name stops being the main event and moves out
   of the way, still legible against whatever is behind it. */
.call-inner.over {
  position: absolute;
  top: max(env(safe-area-inset-top), 16px);
  left: 16px;
  right: 160px;
  align-items: flex-start;
  text-align: left;
  gap: 2px;
  z-index: 2;
  text-shadow: 0 1px 12px rgba(0, 0, 0, .85);
}
.call-inner.over .avatar,
.call-inner.over #call-note { display: none; }
.call-inner.over .call-who { font-size: 1.1rem; }

.call-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 26px);
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.call-bar .icon {
  background: rgba(31, 35, 24, .82);
  border: 1px solid var(--line-2);
  color: var(--text);
  backdrop-filter: blur(8px);
}
.call-bar .icon:hover { background: var(--panel-2); }
.call-bar .icon.on { color: var(--warn); border-color: var(--warn); }
.call-bar .danger-round { background: var(--danger); border-color: var(--danger); color: #1a0f0d; }
.call-bar .danger-round:hover { background: #eb9b8c; color: #1a0f0d; }

/* Непрочитанные и живая подпись под именем. */
.badge {
  grid-area: meta;
  justify-self: end;
  min-width: 20px;
  padding: 1px 6px;
  background: var(--accent);
  border-radius: 999px;
  color: #17190f;
  font-size: .72rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.bar-sub.live { color: var(--accent); font-family: var(--font); font-size: .74rem; }


/* --------------------------------------------------------------- reactions */

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.reaction {
  padding: 1px 7px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  color: var(--text);
  font-size: .8rem;
  line-height: 1.5;
}
.reaction.mine { border-color: var(--accent); background: rgba(194, 178, 100, .16); }

/* Ряд эмодзи в меню: то, ради чего его чаще всего и открывают, поэтому сверху
   и крупно — попасть пальцем важнее, чем сэкономить место. */
.quick { display: flex; justify-content: space-between; gap: 4px; padding: 2px 2px 6px; }
.quick-pick {
  flex: 1;
  padding: 8px 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  font-size: 1.35rem;
  line-height: 1;
}
.quick-pick:hover { background: var(--panel-2); border-color: var(--line-2); }
