/* ————————————————————————————————————————————————————————————
   Космо — тёмная тема глубокого космоса.
   Мобильный экран первичен, десктоп вторичен: на широком экране
   приложение просто центрируется колонкой телефонной ширины.
   ———————————————————————————————————————————————————————————— */

:root {
  --void: #05060f;
  --deep: #0a0e24;
  --panel: rgba(18, 24, 54, 0.72);
  --panel-solid: #121836;
  --edge: rgba(126, 148, 255, 0.16);

  --violet: #a06bff;
  --cyan: #4de1ff;
  --gold: #ffcc5c;
  --rose: #ff6b9d;

  --text: #e8ecff;
  --muted: #8b94c4;
  --dim: #5a628f;

  --ok: #4ade80;
  --warn: #ffcc5c;
  --bad: #ff6b7d;

  --radius: 16px;
  --radius-sm: 10px;
  --tap: 44px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  color-scheme: dark;
}

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

/* Атрибут hidden обязан побеждать любой display из правил ниже: шторка,
   баннеры и подсказка набора объявлены как flex и иначе видны всегда. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--void);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  overscroll-behavior: none;
}

/* Звёзды рисуются на canvas за всем остальным. */
#stars {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, #1b1046 0%, transparent 60%),
    radial-gradient(ellipse 90% 60% at 90% 100%, #07223d 0%, transparent 55%),
    var(--void);
}

#app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
}

/* ——————————————————————————————————————————————— верхняя панель */

#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  background: linear-gradient(to bottom, rgba(5, 6, 15, 0.94), rgba(5, 6, 15, 0.6));
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--edge);
  flex: none;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

#screen-title {
  font-weight: 600;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub { font-size: 11px; color: var(--muted); }
.sub:empty { display: none; }

.icon-btn {
  min-width: var(--tap);
  height: var(--tap);
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.icon-btn:active { background: rgba(255, 255, 255, 0.07); }

/* Индикатор связи: полоски как у антенны, плюс фаза луны под режим. */
.net-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.bars { display: flex; align-items: flex-end; gap: 2px; height: 14px; }
.bars i {
  width: 3px;
  background: var(--dim);
  border-radius: 1px;
  transition: background 0.3s, height 0.3s;
}
.bars i:nth-child(1) { height: 5px; }
.bars i:nth-child(2) { height: 9px; }
.bars i:nth-child(3) { height: 14px; }

.net-badge[data-bars="1"] .bars i:nth-child(1) { background: var(--bad); }
.net-badge[data-bars="2"] .bars i:nth-child(-n+2) { background: var(--gold); }
.net-badge[data-bars="3"] .bars i { background: var(--ok); }
.net-badge[data-bars="0"] { border-color: rgba(255, 107, 125, 0.4); }

/* ——————————————————————————————————————————————————— экраны */

#main { flex: 1; position: relative; overflow: hidden; }

.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.screen.active { opacity: 1; pointer-events: auto; transform: none; }

.pad { padding: 18px 16px calc(28px + var(--safe-bottom)); }
.prose { max-width: 40em; }
.prose h3 { margin: 22px 0 6px; color: var(--cyan); font-size: 15px; }
.prose p { margin: 0 0 10px; color: var(--muted); }
.prose .warn-text { color: #d8c48f; border-left: 2px solid var(--gold); padding-left: 12px; }

.center-block {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}

h1, h2, h3 { margin: 0 0 10px; font-weight: 600; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }

.glow {
  background: linear-gradient(100deg, var(--cyan), var(--violet) 55%, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(160, 107, 255, 0.35);
}

.muted { color: var(--muted); }
.tiny { font-size: 12px; line-height: 1.5; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; }

/* ————————————————————————————————————————————————— элементы */

.field { display: block; margin: 0 0 14px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

input[type=text], input[type=password], input[type=file], textarea, select {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  background: rgba(10, 14, 36, 0.8);
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, textarea:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgba(160, 107, 255, 0.18);
}
textarea { resize: vertical; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: transform 0.12s, filter 0.2s, background 0.2s;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: default; }

.primary {
  padding: 13px 20px;
  min-height: var(--tap);
  border: 0;
  color: #0a0620;
  font-weight: 600;
  background: linear-gradient(100deg, var(--cyan), var(--violet));
  box-shadow: 0 6px 22px rgba(120, 90, 255, 0.32);
}

.ghost {
  padding: 12px 18px;
  min-height: var(--tap);
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--edge);
}

.danger {
  padding: 12px 18px;
  min-height: var(--tap);
  color: var(--bad);
  background: rgba(255, 107, 125, 0.08);
  border: 1px solid rgba(255, 107, 125, 0.3);
}

.link {
  border: 0;
  background: none;
  color: var(--cyan);
  padding: 4px 6px;
  text-decoration: underline;
}

.wide { display: block; width: 100%; margin: 10px 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
  backdrop-filter: blur(8px);
}

.notice {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--edge);
  background: rgba(77, 225, 255, 0.07);
  font-size: 13px;
  margin: 12px 0;
}
.notice.warn { background: rgba(255, 204, 92, 0.09); border-color: rgba(255, 204, 92, 0.3); }
.notice.bad { background: rgba(255, 107, 125, 0.1); border-color: rgba(255, 107, 125, 0.35); }
.notice strong { display: block; margin-bottom: 4px; }
.notice p { margin: 0; color: var(--muted); }

.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 13px;
  background: rgba(77, 225, 255, 0.08);
  border-bottom: 1px solid var(--edge);
}
.banner.warn { background: rgba(255, 204, 92, 0.12); }
.banner span { flex: 1; }

.details { margin-top: 18px; }
.details summary { cursor: pointer; color: var(--cyan); padding: 8px 0; }

.check { display: flex; align-items: center; gap: 10px; margin-top: 12px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--violet); }

.stats { margin: 8px 0 0; font-size: 12px; }
.stats div { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid rgba(126, 148, 255, 0.07); }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; font-family: ui-monospace, Menlo, Consolas, monospace; }

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 10px;
}
.segmented button {
  flex: 1 1 auto;
  min-width: 84px;
  padding: 9px 10px;
  font-size: 13px;
  color: var(--muted);
  background: rgba(10, 14, 36, 0.7);
  border: 1px solid var(--edge);
}
.segmented button.on {
  color: var(--text);
  border-color: var(--violet);
  background: rgba(160, 107, 255, 0.18);
}

/* ————————————————————————————————————————————— список чатов */

.list { list-style: none; margin: 0; padding: 8px 0 96px; }

.chat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(126, 148, 255, 0.07);
}
.chat-row:active { background: rgba(160, 107, 255, 0.1); }

.avatar {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 17px;
  color: #0a0620;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  position: relative;
}
.avatar.big { width: 76px; height: 76px; font-size: 28px; margin: 0 auto 10px; }
.avatar[data-unverified="1"]::after {
  content: '!';
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--warn);
  color: #241a00;
  font-size: 12px;
  display: grid;
  place-items: center;
  border: 2px solid var(--void);
}

.chat-main { flex: 1; min-width: 0; }
.chat-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.chat-last {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-meta { text-align: right; font-size: 11px; color: var(--dim); flex: none; }

.fab {
  position: absolute;
  right: 18px;
  bottom: calc(22px + var(--safe-bottom));
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  font-size: 30px;
  line-height: 1;
  color: #0a0620;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  box-shadow: 0 8px 28px rgba(120, 90, 255, 0.45);
}

/* ————————————————————————————————————————————————————— чат */

.chat-screen { display: flex; flex-direction: column; }
.chat-screen.active { display: flex; }

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

.bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 15px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  position: relative;
  animation: launch 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Отправленное «стартует» снизу вверх — маленький намёк на полёт. */
@keyframes launch {
  from { opacity: 0; transform: translateY(14px) scale(0.94); }
  to { opacity: 1; transform: none; }
}

.bubble.out {
  align-self: flex-end;
  color: #08061c;
  background: linear-gradient(120deg, var(--cyan), var(--violet));
  border-bottom-right-radius: 5px;
}
.bubble.in {
  align-self: flex-start;
  background: var(--panel-solid);
  border: 1px solid var(--edge);
  border-bottom-left-radius: 5px;
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  font-size: 10px;
  opacity: 0.75;
  justify-content: flex-end;
}
.bubble.in .bubble-meta { justify-content: flex-start; color: var(--dim); }

.bubble.pending { opacity: 0.66; }
.bubble.failed { background: rgba(255, 107, 125, 0.18); border: 1px solid var(--bad); color: var(--text); }
.bubble.failed .retry { color: var(--cyan); text-decoration: underline; cursor: pointer; }

.day-sep { align-self: center; font-size: 11px; color: var(--dim); padding: 6px 0; }

.typing { display: flex; gap: 4px; padding: 0 20px 8px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--violet);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: rgba(5, 6, 15, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--edge);
  flex: none;
}
.composer textarea {
  flex: 1;
  max-height: 120px;
  border-radius: 20px;
  padding: 11px 15px;
  line-height: 1.35;
}

.channel-btn, .send-btn {
  width: var(--tap);
  height: var(--tap);
  flex: none;
  border-radius: 50%;
  font-size: 19px;
  border: 1px solid var(--edge);
  background: var(--panel);
  color: var(--text);
  display: grid;
  place-items: center;
}
.send-btn {
  border: 0;
  color: #08061c;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
}
.channel-btn[data-ch="satellite"] { border-color: var(--gold); background: rgba(255, 204, 92, 0.16); }

.composer-hint {
  padding: 0 16px calc(8px + var(--safe-bottom));
  font-size: 11px;
  color: var(--dim);
  background: rgba(5, 6, 15, 0.92);
  flex: none;
}
.composer-hint:empty { display: none; }

/* ——————————————————————————————————————————————————— QR */

.qr-wrap {
  display: grid;
  place-items: center;
  padding: 16px;
  margin: 12px 0;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 0 40px rgba(77, 225, 255, 0.2);
}
.qr-wrap canvas { display: block; width: 100%; max-width: 300px; height: auto; image-rendering: pixelated; }

.copy-row { display: flex; gap: 8px; margin-bottom: 12px; }
.copy-row input { flex: 1; font-size: 12px; font-family: ui-monospace, Menlo, monospace; }

.scan-wrap { margin-bottom: 12px; }
.scan-wrap video {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
  aspect-ratio: 1;
  object-fit: cover;
}

/* Код безопасности — крупно и моноширинно, чтобы удобно диктовать. */
.sas {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 19px;
  letter-spacing: 1px;
  text-align: center;
}
.sas span {
  padding: 9px 4px;
  background: rgba(10, 14, 36, 0.85);
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  color: var(--cyan);
}
.sas-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 13px;
  color: var(--gold);
  margin-bottom: 6px;
}
.sas-words span { padding: 4px 9px; border: 1px solid rgba(255, 204, 92, 0.28); border-radius: 999px; }

.contact-head { text-align: center; margin-bottom: 18px; }

/* ————————————————————————————————————————————— украшения */

.hero { text-align: center; margin-bottom: 26px; }

.planet {
  width: 96px;
  height: 96px;
  margin: 10px auto 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #7d5cff, #2b1b6b 55%, #0a0a24);
  box-shadow: 0 0 60px rgba(125, 92, 255, 0.45), inset -10px -10px 26px rgba(0, 0, 0, 0.55);
  position: relative;
}
.planet::after {
  content: '';
  position: absolute;
  inset: -20% -34%;
  border: 2px solid rgba(77, 225, 255, 0.4);
  border-radius: 50%;
  transform: rotate(-18deg) scaleY(0.28);
}

.satellite-icon { font-size: 52px; filter: drop-shadow(0 0 18px rgba(77, 225, 255, 0.5)); }

.orbit-loader { position: relative; width: 60px; height: 60px; }
.orbit-loader i {
  position: absolute;
  inset: 0;
  border: 2px solid transparent;
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 1.1s linear infinite;
}
.orbit-loader i:nth-child(2) { inset: 9px; border-top-color: var(--violet); animation-duration: 0.85s; }
.orbit-loader i:nth-child(3) { inset: 18px; border-top-color: var(--gold); animation-duration: 1.5s; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ————————————————————————————————————————— всплывашки */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 50;
  max-width: 88vw;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13px;
  background: rgba(18, 24, 54, 0.96);
  border: 1px solid var(--edge);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: rise 0.24s ease;
}
.toast.bad { border-color: rgba(255, 107, 125, 0.5); color: #ffc9d1; }
.toast.ok { border-color: rgba(74, 222, 128, 0.45); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 12px); } }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(2, 3, 10, 0.66);
  backdrop-filter: blur(3px);
}
.sheet-body {
  width: 100%;
  max-width: 560px;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  background: var(--panel-solid);
  border-top: 1px solid var(--edge);
  border-radius: var(--radius) var(--radius) 0 0;
  animation: sheetUp 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes sheetUp { from { transform: translateY(100%); } }

.sheet-opt {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  padding: 13px;
  margin-bottom: 8px;
  color: var(--text);
  background: rgba(10, 14, 36, 0.7);
  border: 1px solid var(--edge);
}
.sheet-opt.on { border-color: var(--violet); background: rgba(160, 107, 255, 0.15); }
.sheet-opt .ic { font-size: 20px; }
.sheet-opt b { display: block; }
.sheet-opt small { color: var(--muted); font-size: 12px; }
.sheet-opt:disabled { opacity: 0.45; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ————————————————————————————— передача по кускам (спутник, радио) */

.row-2 { display: flex; gap: 10px; }
.row-2 > * { flex: 1; min-width: 0; }

select {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  background: rgba(10, 14, 36, 0.8);
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
}

.frag-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: 11px;
  color: var(--gold);
  background: rgba(255, 204, 92, 0.08);
  border-top: 1px solid rgba(255, 204, 92, 0.22);
  flex: none;
}
.frag-bar {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 204, 92, 0.18);
  overflow: hidden;
}
.frag-bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--gold), var(--cyan));
  transition: width 0.3s ease;
}

.modem-line { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.signal-dots { display: inline-flex; gap: 3px; }
.signal-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); }
.signal-dots i.on { background: var(--ok); }

.sub-head { margin: 14px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
input[type=tel] {
  width: 100%; padding: 12px 14px; font: inherit; color: var(--text);
  background: rgba(10, 14, 36, 0.8); border: 1px solid var(--edge);
  border-radius: var(--radius-sm); outline: none;
}
input[type=tel]:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(160, 107, 255, 0.18); }
