:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #15171a;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #2f6df6;
  --accent-text: #ffffff;
  --mine: #e7efff;
  --danger: #d93025;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1b1e24;
    --text: #eceef1;
    --muted: #9aa1ab;
    --border: #2b3038;
    --accent: #5b8cff;
    --mine: #1f2c4a;
    --danger: #ff6b5e;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

a { color: var(--accent); }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Кнопки и формы ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; font-weight: 500; }
.btn.big { min-height: 56px; padding: 14px 28px; font-size: 18px; width: 100%; }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }

.error { color: var(--danger); margin: 8px 0 0; }

/* ---------- Главная и экран входа ---------- */

.landing, .gate {
  max-width: 460px;
  margin: 0 auto;
  padding: 48px 16px 32px;
  display: grid;
  gap: 20px;
}
.gate { text-align: center; justify-items: center; }
.gate .join-form { width: 100%; text-align: left; }

.logo-big {
  margin: 0;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  text-decoration: none;
}
.lead { margin: 0; font-size: 18px; color: var(--muted); }

.how { margin: 0; padding-left: 20px; color: var(--muted); display: grid; gap: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; }

.join-form { display: grid; gap: 12px; }

.foot { margin: 0; font-size: 13px; color: var(--muted); }
.foot.small { padding: 0 16px 8px; font-size: 12px; text-align: center; }

/* ---------- Комната ---------- */

.room {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 860px;
  margin: 0 auto;
}

.bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.logo { font-weight: 800; font-size: 18px; color: var(--text); text-decoration: none; }
.room-code { font-family: ui-monospace, Menlo, monospace; font-size: 15px; color: var(--muted); }
.expires { font-size: 13px; color: var(--muted); }
.spacer { flex: 1; }

.invite {
  display: flex;
  gap: 20px;
  align-items: center;
  margin: 12px 16px 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.qr {
  width: 200px;
  height: 200px;
  flex: none;
  border-radius: 8px;
  background: #fff;
  image-rendering: pixelated;
}
.invite-text p { margin: 0 0 10px; }
.invite-link { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.invite-link code { font-size: 15px; word-break: break-all; }
.invite-pin { font-size: 18px; }
.invite-pin strong { font-family: ui-monospace, Menlo, monospace; font-size: 28px; letter-spacing: .12em; margin-left: 8px; }

.members {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 10px 16px 0;
  list-style: none;
}
.members li {
  font-size: 13px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  overscroll-behavior: contain;
}
.load-more { display: flex; margin: 0 auto 12px; }
#list { display: flex; flex-direction: column; gap: 10px; }

.msg {
  max-width: min(85%, 640px);
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px 10px;
}
.msg.mine { align-self: flex-end; background: var(--mine); border-color: transparent; }
.msg.system {
  align-self: center;
  background: none;
  border: 0;
  padding: 0;
  font-size: 13px;
  color: var(--muted);
}
.msg-head { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .copy { margin-top: 8px; }

.preview {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 10px;
  margin-bottom: 6px;
}
.file { display: inline-flex; gap: 8px; align-items: baseline; font-weight: 600; overflow-wrap: anywhere; }
.file-size { font-weight: 400; font-size: 13px; color: var(--muted); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.composer textarea { resize: none; min-height: 44px; max-height: 200px; overflow-y: hidden; }
.composer .btn { min-height: 44px; }
.attach, .mic { font-size: 20px; padding: 8px 12px; }
.mic.active { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 15%, transparent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .mic.active { animation: none; } }
.file.gone { font-weight: 400; color: var(--muted); font-style: italic; }

.drop {
  position: fixed;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 3px dashed var(--accent);
  border-radius: 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  font-size: 22px;
  font-weight: 700;
  pointer-events: none;
}

.toast, .conn {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  z-index: 10;
}
.toast { bottom: calc(90px + env(safe-area-inset-bottom)); }
.conn { top: 12px; background: var(--danger); color: #fff; }

@media (max-width: 600px) {
  .bar { padding: 8px 12px; gap: 4px 8px; }
  .bar .room-code { display: none; }
  .bar .btn { min-height: 34px; padding: 4px 10px; font-size: 14px; }
  .expires { order: 10; width: 100%; }
  .invite { flex-direction: column; text-align: center; margin: 10px 12px 0; }
  .invite-link { justify-content: center; }
  .qr { width: 220px; height: 220px; }
  .messages, .members { padding-left: 12px; padding-right: 12px; }
  .composer { padding-left: 12px; padding-right: 12px; }
  .composer #send { padding: 8px 12px; }
  .attach, .mic { padding: 8px 10px; }
  .msg { max-width: 92%; }
}
