/* Colors come from the Telegram theme (--tg-theme-*), with fallbacks for a plain browser. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f8cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f8cff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --gold: #f5b301;
  --radius: 16px;
  --safe-top: max(env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17181c;
    --bg2: #22242a;
    --text: #f2f3f5;
    --hint: #8d929c;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none;
}
a { color: var(--link); }
h1 { font-size: 24px; margin: 12px 0 6px; }
h2 { font-size: 20px; margin: 0 0 12px; }
.muted { color: var(--hint); margin: 0 0 16px; }
.hidden { display: none !important; }

.screen { position: fixed; inset: 0; display: none; overflow-y: auto; }
.screen.active { display: block; }
.screen.center.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.center-text { text-align: center; }
.pad { padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); max-width: 520px; margin: 0 auto; }

.logo { font-weight: 800; font-size: 22px; letter-spacing: -0.5px; }
.logo span { color: var(--accent); }
.big-emoji { font-size: 56px; }

/* Controls */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font: inherit; font-weight: 600;
  background: var(--bg2); color: var(--text); cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.block { display: block; width: 100%; margin-top: 12px; }
.btn.big { padding: 16px; font-size: 18px; }
.premium-btn { background: linear-gradient(135deg, #ffcf40, #f59e0b); color: #3b2500; }

.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid transparent;
  background: var(--bg2); color: var(--text); font: inherit; outline: none;
}
.input:focus { border-color: var(--accent); }
.input.small { width: 72px; text-align: center; padding: 8px; }
.field-label { display: block; font-size: 13px; color: var(--hint); margin: 16px 0 8px; text-transform: uppercase; letter-spacing: 0.4px; }

.segmented { display: flex; gap: 6px; background: var(--bg2); padding: 4px; border-radius: 12px; }
.segmented button {
  flex: 1; border: 0; background: transparent; color: var(--text); padding: 10px 6px;
  border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer;
}
.segmented button.on { background: var(--accent); color: var(--accent-text); }
.locked .segmented button:not(.on), .locked .age-inputs { opacity: 0.45; }

.check { display: flex; gap: 10px; align-items: flex-start; margin: 20px 0 8px; font-size: 14px; }
.check input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent); }
.error { color: var(--danger); min-height: 1.4em; margin: 4px 0; font-size: 14px; }

.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--bg2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
.spinner.light { border-color: rgba(255,255,255,0.2); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Home */
.home { display: flex; flex-direction: column; min-height: 100%; }
.home-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.online { font-size: 14px; color: var(--hint); display: flex; align-items: center; gap: 6px; }
.online i { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; display: inline-block; }
.preview { position: relative; aspect-ratio: 3 / 4; max-height: 46vh; width: 100%; border-radius: var(--radius); overflow: hidden; background: #000; }
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; text-align: center; padding: 16px; }
.profile-chip { position: absolute; left: 10px; bottom: 10px; }
.chip { border: 0; border-radius: 999px; padding: 6px 12px; background: rgba(0,0,0,0.55); color: #fff; font: inherit; font-size: 14px; backdrop-filter: blur(6px); }
.card { background: var(--bg2); border-radius: var(--radius); padding: 4px 12px 12px; margin-top: 12px; }
.card .segmented { background: var(--bg); }
.card .input { background: var(--bg); }
.card-row { display: flex; align-items: center; justify-content: space-between; }
.age-row .field-label { margin: 12px 0 0; }
.age-inputs { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.badge { font-size: 12px; font-weight: 700; color: #3b2500; background: var(--gold); padding: 2px 8px; border-radius: 999px; margin-top: 8px; }
.badge.ok { background: #22c55e; color: #fff; }
.filter-hint { margin: 10px 0 0; font-size: 13px; color: var(--hint); }
.filter-hint b { color: var(--text); }
.girl-block { margin-top: 16px; padding: 12px; border-radius: var(--radius); background: var(--bg2); }
.girl-block h3 { margin: 0 0 6px; font-size: 17px; }
.girl-block .muted { margin-bottom: 4px; }
.girl-block .btn { background: var(--bg); }
.sheet-list button .save { font-size: 12px; font-weight: 700; color: #fff; background: #22c55e; border-radius: 999px; padding: 1px 7px; margin-left: 6px; }
.invite-link { padding: 12px; border-radius: 12px; background: var(--bg2); font-size: 14px; word-break: break-all; user-select: text; }
.invite-stats { margin: 12px 0 0; text-align: center; }

/* Call */
.call { background: #000; color: #fff; overflow: hidden; }
#remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
#local-video {
  position: absolute; top: calc(12px + var(--safe-top)); right: 12px; width: 28vw; max-width: 140px; aspect-ratio: 3 / 4;
  object-fit: cover; border-radius: 12px; transform: scaleX(-1); background: #222; border: 2px solid rgba(255,255,255,0.25); z-index: 3;
}
#local-video.cam-off { visibility: hidden; }
.call-status {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: radial-gradient(circle at 50% 40%, #2a2d36, #0b0c0f); z-index: 1; text-align: center; padding: 24px;
}
.call-status p { margin: 0; color: #d6d8de; }
.tap-sound { position: absolute; top: 45%; left: 50%; transform: translateX(-50%); z-index: 4; }
.tap-sound { border: 0; border-radius: 999px; padding: 12px 18px; background: rgba(0,0,0,0.65); color: #fff; font: inherit; }
.partner-badge { position: absolute; top: calc(12px + var(--safe-top)); left: 12px; z-index: 3; }
.partner-badge { border-radius: 999px; padding: 6px 12px; background: rgba(0,0,0,0.5); font-weight: 600; backdrop-filter: blur(6px); }

.chat { position: absolute; left: 12px; right: 12px; bottom: calc(84px + var(--safe-bottom)); z-index: 3; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.chat-log { display: flex; flex-direction: column; gap: 4px; max-height: 32vh; overflow-y: auto; align-items: flex-start; }
.chat-log .msg { max-width: 80%; padding: 6px 10px; border-radius: 12px; background: rgba(0,0,0,0.55); backdrop-filter: blur(6px); font-size: 15px; user-select: text; word-break: break-word; }
.chat-log .msg.me { align-self: flex-end; background: color-mix(in srgb, var(--accent) 80%, transparent); }
.chat-log .msg.sys { align-self: center; background: transparent; color: #c9ccd3; font-size: 13px; }
.chat-form { display: flex; gap: 8px; pointer-events: auto; }
.chat-form .input { background: rgba(0,0,0,0.6); color: #fff; }

.controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; align-items: center; gap: 8px;
  padding: 12px 12px calc(12px + var(--safe-bottom)); background: linear-gradient(transparent, rgba(0,0,0,0.65));
}
.round { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; background: rgba(255,255,255,0.16); color: #fff; font-size: 18px; backdrop-filter: blur(6px); cursor: pointer; }
.round.off { background: var(--danger); }
.round.warn { color: #ffd24d; }
.round.active { background: rgba(255,255,255,0.35); }
.controls .next { flex: 1; min-width: 0; height: 46px; padding: 0 10px; font-size: 17px; white-space: nowrap; }

/* Sheets */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 10; }
.backdrop.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; background: var(--bg); color: var(--text);
  border-radius: 20px 20px 0 0; padding: 20px 16px calc(16px + var(--safe-bottom)); transform: translateY(105%);
  transition: transform 0.25s ease; max-width: 520px; margin: 0 auto; max-height: 85vh; overflow-y: auto;
}
.sheet.show { transform: none; }
.sheet-list { display: flex; flex-direction: column; gap: 8px; }
.sheet-list button { text-align: left; border: 0; border-radius: 12px; padding: 14px; background: var(--bg2); color: var(--text); font: inherit; cursor: pointer; }
.sheet-list button b { float: right; }
.perks, .rules { padding-left: 20px; margin: 0 0 12px; }
.perks li, .rules li { margin: 6px 0; }

.toast {
  position: fixed; left: 50%; top: calc(16px + var(--safe-top)); transform: translate(-50%, -150%); z-index: 20;
  background: rgba(20,20,24,0.9); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  transition: transform 0.25s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); }
