:root {
  color-scheme: light;
  --app-height: 100dvh;
  --app-top: 0px;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-soft: #f1f3f5;
  --border: #e2e5e9;
  --text: #17191d;
  --muted: #747a84;
  --primary: #111827;
  --primary-hover: #273244;
  --danger: #d64555;
  --warning-bg: #fff8e8;
  --warning-text: #705400;
  --success: #1e9c66;
  --searching: #d18a00;
  --shadow: 0 10px 30px rgba(17, 24, 39, .055);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html { background: var(--bg); }
body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Tahoma, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.chat-mode { overflow: hidden; }
button, input, textarea { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: .45; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(17, 24, 39, .16); outline-offset: 2px; }

.app-shell {
  width: min(100% - 28px, 560px);
  min-height: 100dvh;
  margin: auto;
  padding: max(16px, env(safe-area-inset-top)) 0 max(20px, env(safe-area-inset-bottom));
}
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 42px; }
.brand { padding: 0; border: 0; background: none; color: var(--text); font-size: 1.2rem; font-weight: 900; letter-spacing: -.02em; }
.online-indicator { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .72rem; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.online-indicator[data-state="searching"] .status-dot,
.online-indicator[data-state="found"] .status-dot,
.online-indicator[data-state="empty"] .status-dot,
.online-indicator[data-state="reconnecting"] .status-dot { background: var(--searching); }
.online-indicator[data-state="peer-left"] .status-dot { background: var(--danger); }
.screen { display: none; }
.screen.active { display: block; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }

.welcome-screen { padding-top: clamp(44px, 10vh, 90px); }
.hero { text-align: center; }
.brand-icon { width: 54px; height: 54px; margin: 0 auto 18px; display: grid; place-items: center; border-radius: 15px; background: var(--primary); color: #fff; font-size: 1.6rem; font-weight: 900; }
.hero h1 { margin: 0; font-size: clamp(2rem, 7vw, 2.8rem); line-height: 1.28; letter-spacing: -.035em; }
.hero p { max-width: 410px; margin: 15px auto 0; color: var(--muted); font-size: .92rem; line-height: 1.8; }
.hero .coming-soon { width: fit-content; margin-top: 10px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: #555d68; font-size: .7rem; font-weight: 700; }
.setup-panel { margin-top: 30px; padding: 18px; }
.field-label { display: block; margin-bottom: 8px; font-size: .82rem; font-weight: 700; }
.interest-input { width: 100%; height: 48px; padding: 0 13px; border: 1px solid var(--border); border-radius: 11px; background: #fff; color: var(--text); outline: none; }
.interest-input:focus { border-color: #aeb4bd; box-shadow: 0 0 0 3px rgba(17,24,39,.05); }
.interest-input.is-selected { border-color: var(--success); background: #f3fbf7; box-shadow: 0 0 0 3px rgba(30,156,102,.10); }
.selected-interest { width: fit-content; max-width: 100%; margin-top: 9px; display: inline-flex; align-items: center; gap: 7px; padding: 7px 9px; border: 1px solid #bfe8d4; border-radius: 999px; background: #eefaf4; color: #146b49; font-size: .76rem; font-weight: 700; }
.selected-interest[hidden] { display: none; }
.selected-interest-check { width: 17px; height: 17px; display: inline-grid; place-items: center; border-radius: 50%; background: var(--success); color: #fff; font-size: .65rem; line-height: 1; }
#selectedInterestText { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clear-interest-button { width: 24px; height: 24px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: #47816a; font-size: .72rem; }
.clear-interest-button:hover { background: rgba(30,156,102,.10); color: #124d38; }
.field-hint { margin: 7px 2px 16px; color: var(--muted); font-size: .67rem; line-height: 1.6; }
.consents { display: grid; gap: 12px; padding: 14px; border-radius: 12px; background: var(--surface-soft); }
.check-row { display: flex; align-items: flex-start; gap: 9px; color: #4e545e; font-size: .78rem; line-height: 1.7; }
.check-row input { flex: 0 0 auto; width: 17px; height: 17px; margin-top: 3px; accent-color: var(--primary); }
.text-button { padding: 0; border: 0; background: none; color: var(--text); text-decoration: underline; }
.primary-button, .secondary-button, .danger-button, .next-button, .send-button { min-height: 46px; border-radius: 11px; border: 0; font-weight: 700; }
.primary-button { width: 100%; margin-top: 14px; background: var(--primary); color: #fff; }
.install-app-button { width: 100%; margin-top: 14px; }
.install-app-button[hidden] { display: none; }
.primary-button:hover { background: var(--primary-hover); }
.secondary-button { padding: 0 17px; border: 1px solid var(--border); background: var(--surface-soft); color: var(--text); }
.danger-button { padding: 0 17px; background: var(--danger); color: #fff; }

.waiting-screen { padding-top: min(27vh, 200px); text-align: center; }
.loader { width: 42px; height: 42px; margin: 0 auto 20px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .65s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.waiting-screen h2 { margin: 0; font-size: 1.45rem; }
.waiting-screen p { max-width: 340px; color: var(--muted); margin: 9px auto 22px; font-size: .82rem; line-height: 1.7; }
.waiting-screen .secondary-button { min-width: 120px; }

.chat-screen.active {
  position: fixed;
  top: var(--app-top, 0px);
  right: 0;
  bottom: auto;
  left: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  width: 100%;
  height: var(--app-height, 100dvh);
  padding: 0;
  background: var(--bg);
}
.chat-card {
  width: min(100%, 560px);
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template:
    "header" auto
    "safety" auto
    "connection" auto
    "messages" minmax(0, 1fr)
    "typing" auto
    "country" auto
    "composer" auto
    / 100%;
  overflow: hidden;
  border-top: 0;
  border-bottom: 0;
  border-radius: 0;
}
.chat-header { grid-area: header; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: max(9px, env(safe-area-inset-top)) 12px 9px; border-bottom: 1px solid var(--border); }
.peer-summary { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 40px; height: 40px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 900; }
.peer-text { min-width: 0; }
.peer-summary strong { display: block; font-size: .91rem; }
.peer-status { color: var(--muted); font-size: .67rem; margin-top: 3px; }
.peer-status span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--success); margin-left: 4px; }
.peer-status.offline span { background: var(--danger); }
.peer-interest { max-width: 230px; margin-top: 3px; color: #535a64; font-size: .65rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; align-items: center; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 10px; background: transparent; color: #6d727b; font-size: 1.05rem; }
.icon-button:hover { background: var(--surface-soft); color: var(--text); }
.safety-strip { grid-area: safety; padding: 7px 12px; background: var(--warning-bg); color: var(--warning-text); border-bottom: 1px solid #f2e6c2; font-size: .66rem; text-align: center; }
.connection-banner { grid-area: connection; padding: 8px 12px; border-bottom: 1px solid #f0d9a1; background: #fff5d9; color: #745000; text-align: center; font-size: .7rem; font-weight: 700; line-height: 1.5; }
.connection-banner[hidden] { display: none; }
.messages { grid-area: messages; min-height: 0; overflow-y: auto; padding: 13px; scroll-behavior: smooth; overscroll-behavior: contain; }
.message-row { display: flex; align-items: flex-end; gap: 5px; margin-bottom: 8px; }
.message-row.mine { justify-content: flex-start; }
.message-row.peer { justify-content: flex-end; }
.message-bubble { max-width: 84%; padding: 9px 11px 7px; border-radius: 15px; line-height: 1.6; overflow-wrap: anywhere; white-space: pre-wrap; font-size: .9rem; }
.message-text { white-space: pre-wrap; }
.message-reply-quote { display: block; max-width: 100%; margin-bottom: 6px; padding: 6px 8px; border-radius: 8px; border-right: 3px solid currentColor; background: rgba(255,255,255,.12); opacity: .82; font-size: .7rem; line-height: 1.45; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer .message-reply-quote { background: rgba(17,24,39,.06); }
.reply-message-button { flex: 0 0 auto; width: 30px; height: 30px; display: grid; place-items: center; padding: 0; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--muted); font-size: .77rem; opacity: .72; }
.reply-message-button:hover, .reply-message-button:focus-visible { opacity: 1; color: var(--text); background: var(--surface-soft); }
.mine .message-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 5px; }
.peer .message-bubble { background: var(--surface-soft); color: var(--text); border-bottom-left-radius: 5px; }
.message-time { display: block; margin-top: 3px; opacity: .58; font-size: .56rem; }
.system-message { width: fit-content; max-width: 90%; margin: 9px auto; padding: 6px 10px; text-align: center; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: .65rem; }
.typing-indicator { grid-area: typing; min-height: 20px; padding: 2px 13px 5px; color: var(--muted); font-size: .67rem; }
.peer-country { grid-area: country; min-height: 25px; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 3px 10px; border-top: 1px solid var(--border); color: var(--muted); background: #fcfcfd; font-size: .62rem; font-weight: 700; line-height: 1.2; }
.country-flag-wrap { width: 18px; height: 13px; display: inline-grid; place-items: center; flex: 0 0 auto; overflow: hidden; border-radius: 2px; box-shadow: 0 0 0 1px rgba(17,24,39,.08); }
.country-flag-image { grid-area: 1 / 1; display: block; width: 18px; height: 13px; object-fit: cover; }
.country-flag-emoji { grid-area: 1 / 1; display: block; font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; font-size: 14px; line-height: 1; }
.composer {
  grid-area: composer;
  direction: ltr;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 6px;
  padding-top: 8px;
  padding-right: max(8px, env(safe-area-inset-right));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  padding-left: max(8px, env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.message-field { direction: rtl; min-width: 0; }
.reply-preview { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; padding: 7px 9px; border: 1px solid var(--border); border-right: 3px solid var(--primary); border-radius: 9px; background: var(--surface-soft); }
.reply-preview[hidden] { display: none; }
.reply-preview-content { min-width: 0; display: grid; gap: 2px; }
.reply-preview-content strong { font-size: .65rem; }
.reply-preview-content span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .65rem; }
.cancel-reply-button { width: 26px; height: 26px; flex: 0 0 auto; display: grid; place-items: center; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); }
.cancel-reply-button:hover { background: rgba(17,24,39,.07); color: var(--text); }
.message-field textarea { width: 100%; min-height: 46px; max-height: 108px; padding: 11px; resize: none; border: 1px solid var(--border); border-radius: 11px; background: #fff; color: var(--text); outline: none; }
.message-field textarea:focus { border-color: #aeb4bd; box-shadow: 0 0 0 3px rgba(17,24,39,.05); }
.composer-meta { display: flex; justify-content: flex-end; padding: 2px 3px 0; color: #959aa2; font-size: .56rem; }
.next-button { min-width: 69px; padding: 0 10px; border: 1px solid var(--border); background: var(--surface-soft); color: var(--text); }
.send-button { min-width: 46px; padding: 0; background: var(--primary); color: #fff; font-size: 1rem; }

.rules-screen { padding-top: 26px; }
.back-button { border: 0; background: none; color: var(--muted); padding: 8px 0 15px; }
.rules-panel { padding: 20px; line-height: 1.9; }
.rules-panel h2 { margin: 0 0 14px; font-size: 1.45rem; }
.rules-panel ul { margin: 0; padding-right: 19px; }
.rules-panel li { color: #555b65; margin-bottom: 7px; font-size: .84rem; }

.report-dialog, .captcha-dialog { width: min(92vw, 420px); border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(17,24,39,.18); }
.report-dialog::backdrop, .captcha-dialog::backdrop { background: rgba(17,24,39,.52); backdrop-filter: blur(2px); }
.captcha-dialog form { display: grid; gap: 12px; }
.captcha-dialog h3 { margin: 0; font-size: 1.25rem; }
.captcha-dialog p { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.75; }
.captcha-question { position: relative; isolation: isolate; min-height: 72px; display: flex; align-items: center; justify-content: center; gap: 2px; overflow: hidden; padding: 18px 14px; border: 1px solid var(--border); border-radius: 12px; background: repeating-linear-gradient(11deg, #edf0f3 0 3px, #f8f9fa 3px 7px); text-align: center; font-size: 1.45rem; font-weight: 900; direction: ltr; user-select: none; }
.captcha-question::before, .captcha-question::after { content: ""; position: absolute; z-index: -1; inset: -30%; pointer-events: none; }
.captcha-question::before { background: repeating-linear-gradient(var(--captcha-line-angle, 23deg), transparent 0 13px, rgba(17,24,39,.12) 13px 14px, transparent 14px 24px); transform: rotate(var(--captcha-bg-rotate, 0deg)); }
.captcha-question::after { background-image: radial-gradient(circle, rgba(17,24,39,.22) 0 1px, transparent 1.5px); background-size: 11px 9px; opacity: .24; filter: blur(.25px); transform: translate(var(--captcha-noise-x, 0), var(--captcha-noise-y, 0)); }
.captcha-char { position: relative; z-index: 1; display: inline-block; min-width: .62em; color: #1b2028; text-shadow: 1px 0 rgba(17,24,39,.28), -1px 1px rgba(255,255,255,.85); filter: blur(.28px) contrast(1.13); transform: translateY(var(--captcha-y, 0)) rotate(var(--captcha-rotate, 0deg)) skewX(var(--captcha-skew, 0deg)); }
.captcha-label { font-size: .78rem; font-weight: 700; }
.captcha-answer { width: 100%; height: 48px; padding: 0 12px; border: 1px solid var(--border); border-radius: 11px; text-align: center; font-size: 1.05rem; outline: none; }
.captcha-answer:focus { border-color: #aeb4bd; box-shadow: 0 0 0 3px rgba(17,24,39,.06); }
.captcha-error { color: var(--danger); font-size: .75rem; line-height: 1.6; }
.captcha-honeypot { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip: rect(0 0 0 0) !important; opacity: 0 !important; pointer-events: none !important; }
.captcha-actions { justify-content: stretch; }
.captcha-actions > button { flex: 1; }
.captcha-submit { width: auto; margin-top: 0; padding: 0 17px; }
.report-dialog form { display: grid; gap: 12px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h3 { margin: 0; }
.report-dialog p { color: var(--muted); margin: 0 0 4px; font-size: .78rem; line-height: 1.7; }
.report-dialog label { display: flex; gap: 8px; align-items: center; color: #4f5560; font-size: .86rem; }
.report-dialog input { width: 17px; height: 17px; accent-color: var(--primary); }
.report-dialog textarea { min-height: 76px; padding: 11px; border: 1px solid var(--border); border-radius: 10px; resize: none; outline: none; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toast { position: fixed; right: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(50%, 14px); opacity: 0; pointer-events: none; z-index: 40; background: var(--primary); color: white; border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); transition: .2s; font-size: .8rem; }
.toast.show { transform: translate(50%, 0); opacity: 1; }

@media (max-width: 560px) {
  .app-shell { width: 100%; padding-right: 10px; padding-left: 10px; }
  .topbar { padding: 0 2px; }
  .welcome-screen { padding-top: 48px; }
  .hero h1 { font-size: 2.05rem; }
  .hero p { font-size: .85rem; padding: 0 8px; }
  .setup-panel { margin-top: 25px; padding: 14px; border-radius: 14px; box-shadow: none; }
  .online-indicator { max-width: 58%; }
  .chat-card { width: 100%; border: 0; box-shadow: none; }
  .chat-header { padding-right: 9px; padding-left: 9px; }
  .avatar { width: 37px; height: 37px; }
  .icon-button { width: 35px; height: 35px; }
  .messages { padding: 10px; }
  .message-bubble { max-width: 88%; }
  .composer { gap: 5px; padding-right: 6px; padding-left: 6px; }
  .next-button { min-width: 61px; padding: 0 8px; font-size: .75rem; }
  .send-button { min-width: 43px; }
}

@media (max-width: 370px) {
  .app-shell { padding-right: 7px; padding-left: 7px; }
  .hero h1 { font-size: 1.86rem; }
  .composer { grid-template-columns: 56px minmax(0, 1fr) 40px; }
  .next-button { min-width: 0; padding: 0 5px; }
  .send-button { min-width: 40px; }
}

.blocked-screen {
  width: min(100% - 32px, 420px);
  min-height: 100dvh;
  margin: 0 auto;
  display: grid;
  align-content: center;
  text-align: center;
  padding: 24px;
}
.blocked-screen h1 { margin: 0 0 10px; font-size: 1.45rem; }
.blocked-screen p { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.8; }
