/* ═══════════ БАЗА ═══════════ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
               "Segoe UI", Roboto, sans-serif;
  background: #fff; color: #111;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
.screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ═══════════ TOPBAR ═══════════ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #111;
  background: #fff;
  position: sticky; top: 0; z-index: 10;
  flex-shrink: 0;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff;
  border: 1px solid #111;
  border-radius: 10px;
  color: #111;
  padding: 0;
}
.icon-btn:active { background: #f2f2f2; }

.user-block { display: flex; align-items: center; gap: 10px; }
.level-info { display: flex; align-items: center; gap: 8px; }
.level-num {
  font-weight: 700; font-size: 15px;
  border: 1px solid #111; border-radius: 8px;
  padding: 3px 9px;
  background: #fff;
  min-width: 34px; text-align: center;
}
.progress-track {
  width: 68px; height: 8px;
  border: 1px solid #111;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.progress-fill {
  height: 100%;
  background: #111;
  width: 0%;
  transition: width .35s ease;
}
.progress-text {
  font-size: 11px; color: #555; min-width: 40px;
  font-variant-numeric: tabular-nums;
}
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid #111;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.topbar-title {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}
.topbar-spacer { width: 40px; }

/* ═══════════ DRAWER ═══════════ */
.drawer {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: 78%; max-width: 320px;
  background: #fff;
  border-right: 1px solid #111;
  transform: translateX(-100%);
  transition: transform .25s ease;
  z-index: 30;
  padding: 22px 16px;
  padding-top: calc(22px + env(safe-area-inset-top));
  display: flex; flex-direction: column; gap: 12px;
}
.drawer.open { transform: translateX(0); }
.drawer-close {
  align-self: flex-end;
  width: 36px; height: 36px;
  border: 1px solid #111; border-radius: 10px;
  background: #fff;
  font-size: 16px;
  line-height: 1;
}
.drawer-nav { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.drawer-item {
  text-align: left;
  padding: 14px 16px;
  border: 1px solid #111;
  border-radius: 12px;
  background: #fff;
  font-size: 15px;
}
.drawer-item:active { background: #f2f2f2; }

.backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.25);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  z-index: 25;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

/* ═══════════ CHAT ═══════════ */
.chat {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 8px;
  display: flex; flex-direction: column; gap: 10px;
  background: #fff;
}
.msg {
  max-width: 82%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.35;
  word-wrap: break-word;
  white-space: pre-wrap;
  border: 1px solid #111;
  animation: msgIn .18s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg.user {
  align-self: flex-end;
  background: #111; color: #fff;
  border-color: #111;
}
.msg.bot {
  align-self: flex-start;
  background: #fff; color: #111;
}
.msg.system {
  align-self: center;
  background: #f4f4f4;
  border: 1px dashed #999;
  font-size: 13px;
  color: #555;
  max-width: 92%;
  text-align: center;
}
.msg img {
  display: block;
  max-width: 100%;
  border-radius: 10px;
  margin-top: 4px;
}

.typing-dot {
  display: inline-block;
  width: 6px; height: 6px;
  margin: 0 1px;
  border-radius: 50%;
  background: #888;
  animation: blink 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes blink {
  0%, 80%, 100% { opacity: .25; }
  40% { opacity: 1; }
}

/* ═══════════ PAYWALL CARD ═══════════ */
.paywall-card {
  align-self: stretch;
  border: 1px solid #111;
  border-radius: 14px;
  padding: 16px 14px;
  background: #fffdf5;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 4px 0;
  animation: msgIn .18s ease;
}
.paywall-title {
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}
.paywall-desc {
  font-size: 13px;
  line-height: 1.4;
  color: #333;
  text-align: center;
}
.paywall-btn {
  margin-top: 4px;
  padding: 12px 16px;
  border: 1px solid #111;
  border-radius: 12px;
  background: #111;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}
.paywall-btn:active { background: #333; }
.paywall-btn:disabled { background: #666; }

/* ═══════════ COMPOSER ═══════════ */
.composer {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid #111;
  background: #fff;
  flex-shrink: 0;
}
.text-input {
  flex: 1;
  height: 42px;
  padding: 0 14px;
  border: 1px solid #111;
  border-radius: 12px;
  background: #fff;
  outline: none;
  font-size: 15px;
  min-width: 0;
}
.text-input:disabled { background: #f7f7f7; }
.send-btn { background: #111; color: #fff; border-color: #111; }
.send-btn:active { background: #333; }
.send-btn:disabled { background: #555; opacity: .6; }

/* ═══════════ PREVIEW BAR ═══════════ */
.preview-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid #111;
  background: #fafafa;
  flex-shrink: 0;
}
.preview-bar img {
  width: 56px; height: 56px;
  object-fit: cover;
  border: 1px solid #111;
  border-radius: 10px;
}
.preview-remove {
  width: 32px; height: 32px;
  border: 1px solid #111;
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  margin-left: auto;
}

/* ═══════════ LEADERBOARD ═══════════ */
.lb-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 24px;
  display: flex; flex-direction: column; gap: 12px;
}
.lb-timer {
  align-self: center;
  font-size: 12px;
  color: #666;
  padding: 7px 14px;
  border: 1px solid #111;
  border-radius: 10px;
  background: #fff;
}
.lb-card {
  border: 1px solid #111;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}
.lb-head {
  display: grid;
  grid-template-columns: 40px 1fr 100px;
  padding: 10px 14px;
  border-bottom: 1px solid #111;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #666;
  background: #fafafa;
}
.lb-head-rank { text-align: center; }
.lb-head-name { text-align: left; }
.lb-head-count { text-align: right; }
.lb-line {
  display: grid;
  grid-template-columns: 40px 1fr 100px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid #eee;
  font-size: 15px;
}
.lb-line:last-child { border-bottom: none; }
.lb-line-top { background: #fdfaf2; }
.lb-c-rank {
  text-align: center;
  font-weight: 700;
  font-size: 15px;
}
.lb-line-top .lb-c-rank { font-size: 19px; }
.lb-c-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.lb-c-count {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.lb-empty {
  text-align: center;
  padding: 30px 20px;
  color: #666;
  font-size: 14px;
}

/* ═══════════ TOAST ═══════════ */
.toast {
  position: fixed;
  bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #111; color: #fff;
  padding: 10px 16px; border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all .25s;
  z-index: 50;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
