:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --card-soft: #f8fafc;
  --line: #e3e8ee;
  --text: #0f1720;
  --muted: #7b8794;
  --accent: #1d7fc2;
  --accent-dark: #16679f;
  --accent-soft: rgba(29, 127, 194, 0.1);
  --shadow: 0 12px 30px rgba(15, 23, 32, 0.08);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --phone-width: 430px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  justify-content: center;
}

body.modal-open {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

img {
  display: block;
}

.app-shell {
  width: 100%;
  max-width: var(--phone-width);
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(18px + env(safe-area-inset-top)) 16px 12px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.top-publish {
  min-width: 132px;
  min-height: 44px;
  border-radius: 14px;
}

.feed-screen {
  padding: 8px 14px 20px;
}

.feed-block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  padding: 12px;
}

.feed-list {
  display: grid;
  gap: 12px;
}

.status-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
}

.status-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-author {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #edf2f7;
  border: 1px solid #d7e0e8;
  color: var(--accent-dark);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.status-meta {
  min-width: 0;
}

.status-name {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.1;
}

.status-time {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 4px;
}

.status-text {
  margin: 14px 0 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 1rem;
}

.reactions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.reaction-chip,
.action-chip,
.send-btn,
.icon-btn,
.primary-btn,
.emoji-btn {
  transition: 0.15s ease;
}

.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
}

.reaction-chip.active {
  background: var(--accent-soft);
  border-color: rgba(29, 127, 194, 0.25);
}

.status-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.action-chip {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: #f5f7fa;
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 600;
}

.action-chip.secondary {
  background: #fff;
  border: 2px solid #111;
}

.emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.emoji-btn {
  min-width: 44px;
  height: 40px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  box-shadow: 0 10px 24px rgba(29, 127, 194, 0.24);
  min-height: 46px;
  padding: 0 18px;
  border-radius: 16px;
  font-weight: 700;
}

.full-btn {
  width: 100%;
}

.text-input,
.text-area {
  width: 100%;
  border: 1px solid #d9dee5;
  background: #fff;
  border-radius: 18px;
  color: var(--text);
  outline: none;
}

.text-input {
  min-height: 50px;
  padding: 0 16px;
}

.text-area {
  min-height: 150px;
  resize: none;
  padding: 14px 16px;
  line-height: 1.5;
}

.text-input:focus,
.text-area:focus {
  border-color: rgba(29, 127, 194, 0.38);
  box-shadow: 0 0 0 4px rgba(29, 127, 194, 0.08);
}

.modal-backdrop,
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 32, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.hidden,
.sheet-backdrop.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 18px 36px rgba(15, 23, 32, 0.12);
}

.auth-card {
  padding: 24px;
  text-align: left;
}

.auth-logo {
  width: 66px;
  height: 66px;
  object-fit: contain;
  margin: 0 auto 10px;
}

.auth-card h2 {
  margin: 0 0 18px;
  text-align: center;
  font-size: 1.8rem;
  font-weight: 900;
}

.field-label {
  display: block;
  margin-bottom: 10px;
  font-size: 1rem;
  color: #222;
}

.composer-card {
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.composer-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--accent);
}

.sheet-head,
.sheet-footer,
.comment-composer,
.comments-page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.comments-page-head {
  padding-bottom: 4px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: #f6f8fa;
  border: 1px solid var(--line);
  color: var(--accent-dark);
  font-size: 1.15rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.counter {
  color: var(--muted);
  font-size: 0.88rem;
}

.sheet-backdrop {
  padding: 0;
  background: var(--bg);
  align-items: stretch;
}

.sheet-card {
  width: 100%;
  max-width: var(--phone-width);
  margin: 0 auto;
  background: var(--bg);
}

.comments-page {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(12px + env(safe-area-inset-bottom));
}

.status-preview {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  line-height: 1.5;
  box-shadow: var(--shadow);
}

.comments-list {
  overflow: auto;
  display: grid;
  gap: 10px;
  align-content: start;
  padding-right: 2px;
}

.comment-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
}

.comment-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.comment-name {
  font-weight: 800;
}

.comment-time {
  color: var(--muted);
  font-size: 0.78rem;
}

.comment-text {
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.sticky-comment-composer {
  background: var(--bg);
  padding-top: 4px;
}

.send-btn {
  min-width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  box-shadow: 0 10px 24px rgba(29, 127, 194, 0.24);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  min-width: 220px;
  max-width: calc(100% - 24px);
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(15, 23, 32, 0.92);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 80;
  text-align: center;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.empty-state {
  padding: 28px 16px;
  border-radius: 18px;
  text-align: center;
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

@media (min-width: 760px) {
  body {
    padding: 18px 0;
  }

  .app-shell {
    min-height: calc(100vh - 36px);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(15, 23, 32, 0.08);
  }

  .comments-page {
    border-radius: 28px;
    overflow: hidden;
  }
}

.login-page {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-page-shell {
  width: 100%;
  max-width: var(--phone-width);
  display: flex;
  justify-content: center;
}

.auth-page-card {
  width: 100%;
  max-width: 360px;
  padding: 24px;
}

.auth-page-card h2 {
  margin: 0 0 18px;
  text-align: center;
  font-size: 1.8rem;
  font-weight: 900;
}

.auth-page-card .auth-logo {
  width: 66px;
  height: 66px;
  object-fit: contain;
  margin: 0 auto 10px;
}

.auth-page-card .field-label {
  display: block;
  margin-bottom: 10px;
  font-size: 1rem;
  color: #222;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-btn {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(15, 23, 32, 0.05);
}

.ghost-btn:hover {
  transform: translateY(-1px);
}

.auth-page-card .text-input {
  margin-bottom: 22px;
}

.auth-page-card .full-btn {
  margin-top: 10px;
}

.status-preview {
  background: linear-gradient(180deg, #f3f9fe 0%, #eef6fc 100%);
  border: 1px solid #d7e7f3;
  border-left: 4px solid var(--accent);
  border-radius: 20px;
  padding: 14px;
  line-height: 1.5;
  box-shadow: none;
}

.comments-list {
  overflow: auto;
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 10px;
  border-radius: 20px;
  background: #eef2f6;
  border: 1px solid #dde5ec;
}

.comment-item {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  box-shadow: 0 4px 14px rgba(15, 23, 32, 0.04);
}

.comment-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.comment-text {
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.comments-page {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 14px;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(12px + env(safe-area-inset-bottom));
}

/* ===== FIX: верхняя панель, кружок профиля, модалка имени ===== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(18px + env(safe-area-inset-top)) 16px 12px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.profile-btn {
  width: 46px;
  height: 46px;
  min-width: 46px;
  min-height: 46px;
  padding: 0;
  border: 2px solid #cfe0ec;
  border-radius: 50%;
  background: #ffffff;
  color: #111111;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(15, 23, 32, 0.06);
  overflow: hidden;
}

.profile-btn:hover {
  transform: translateY(-1px);
  border-color: #b7d3e6;
}

.profile-btn:active {
  transform: translateY(0);
}

.profile-letter {
  display: block;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  color: #111111;
  text-transform: uppercase;
}

.top-publish {
  min-width: 156px;
  height: 46px;
  padding: 0 18px;
  border-radius: 16px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ===== FIX: модалка смены имени ===== */

.rename-card {
  width: min(360px, calc(100vw - 24px));
  padding: 18px;
  border-radius: 24px;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: 0 18px 36px rgba(15, 23, 32, 0.14);
}

.rename-card .sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.rename-card .field-label {
  display: block;
  margin-bottom: 10px;
  font-size: 1rem;
  font-weight: 600;
  color: #20262d;
}

.rename-card .text-input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid #cfd8e3;
  border-radius: 18px;
  margin-bottom: 16px;
  box-shadow: none;
}

.rename-card .text-input:focus {
  border-color: rgba(29, 127, 194, 0.45);
  box-shadow: 0 0 0 4px rgba(29, 127, 194, 0.08);
}

.rename-actions {
  margin-top: 0;
}

.rename-card .full-btn {
  width: 100%;
  min-height: 56px;
  border-radius: 18px;
  font-size: 1rem;
  font-weight: 800;
}

/* ===== FIX: чтобы статус и комментарии не слипались ===== */

.status-preview {
  background: linear-gradient(180deg, #f3f9fe 0%, #edf6fd 100%);
  border: 1px solid #d9e7f2;
  border-left: 4px solid #1d7fc2;
  border-radius: 20px;
  padding: 14px;
  box-shadow: none;
}

.comments-list {
  overflow: auto;
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 10px;
  border-radius: 20px;
  background: #eef3f7;
  border: 1px solid #dde5ec;
}

.comment-item {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  box-shadow: 0 4px 14px rgba(15, 23, 32, 0.04);
}

/* ===== FIX: мобильная шапка ===== */

@media (max-width: 560px) {
  .topbar {
    align-items: center;
    flex-direction: row;
  }

  .topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
  }

  .profile-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .top-publish {
    min-width: 148px;
    height: 44px;
    padding: 0 16px;
  }

  .rename-card {
    width: calc(100vw - 20px);
    padding: 16px;
  }
}