/* ===== VARIABLES ===== */
:root {
  --app-bg: #0e0e0e;
  --app-text: #fff;
}

/* ===== RESET & BASE ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  background: var(--app-bg) !important;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--app-bg) !important;
  color: var(--app-text);
  height: 100vh;
  height: 100dvh;
  height: calc(var(--tg-viewport-stable-height, 100vh));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ===== COOKIE BANNER ===== */
.cookie-banner {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1a1a1a;
  border-top: 1px solid #333;
  padding: 16px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 200;
  animation: slideUp 0.3s ease;
}

.cookie-banner.show { display: block; }

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.cookie-content {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cookie-text {
  font-size: 13px;
  color: #999;
  line-height: 1.5;
}

.cookie-text a { color: #8b5cf6; text-decoration: none; }

.cookie-buttons {
  display: flex;
  gap: 12px;
}

.cookie-btn {
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s;
}

.cookie-btn.accept {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
}

.cookie-btn.decline {
  background: #333;
  color: #ccc;
}

/* ===== SCREENS ===== */
.screen {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  gap: 24px;
  position: relative;
}

.screen.active { display: flex; }

.screen h1 {
  font-size: 28px;
  font-weight: 700;
}

.screen p {
  font-size: 15px;
  color: #999;
  max-width: 300px;
  line-height: 1.5;
}

/* ===== APP ICON ===== */
.app-icon {
  font-size: 64px;
  line-height: 1;
  margin-bottom: 8px;
}

.app-icon.large {
  font-size: 80px;
}

.header-icon {
  font-size: 32px;
  line-height: 1;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ===== LANGUAGE SELECTION ===== */
.lang-buttons {
  display: flex;
  gap: 16px;
  margin-top: 20px;
}

.lang-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 32px;
  border: 2px solid #333;
  border-radius: 16px;
  background: #1a1a1a;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
}

.lang-btn:hover {
  border-color: #6366f1;
  background: #222;
}

.lang-btn .flag { font-size: 48px; }
.lang-btn .label { font-size: 16px; font-weight: 500; }

/* ===== CHARACTER SELECTION ===== */
.char-buttons {
  display: flex;
  gap: 20px;
  margin-top: 20px;
}

.char-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 28px;
  border: 2px solid #333;
  border-radius: 16px;
  background: #1a1a1a;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
}

.char-btn:hover {
  border-color: #6366f1;
  background: #222;
}

.char-btn .char-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid #6366f1;
}

.char-btn .char-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.char-btn .char-name {
  font-size: 18px;
  font-weight: 600;
}

/* ===== WELCOME SCREEN ===== */
.welcome-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid #6366f1;
}

.welcome-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.welcome-start {
  margin-top: 12px;
  padding: 14px 48px;
  border: none;
  border-radius: 28px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.welcome-start:active {
  transform: scale(0.96);
  opacity: 0.9;
}

.welcome-links {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 16px;
}

.welcome-links a {
  font-size: 12px;
  color: #666;
  text-decoration: none;
  transition: color 0.2s;
}

.welcome-links a:hover { color: #999; }

/* Screen footer for lang/char screens */
.screen-footer {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.screen-footer a {
  font-size: 12px;
  color: #555;
  text-decoration: none;
  transition: color 0.2s;
}

.screen-footer a:hover { color: #888; }

/* ===== CHAT SCREEN ===== */
.chat-screen {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

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

/* Header */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #1a1a1a;
  border-bottom: 1px solid #2a2a2a;
  flex-shrink: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.header-info h2 {
  font-size: 16px;
  font-weight: 600;
}

.header-info span {
  font-size: 12px;
  color: #4ade80;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.her {
  background: #2a2a2a;
  color: #f0f0f0;
  align-self: flex-start;
  border-bottom-left-radius: 6px;
}

.msg.me {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 6px;
}

.msg.typing {
  background: #2a2a2a;
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  color: #888;
}

.typing-dots span {
  animation: blink 1.4s infinite;
  font-size: 20px;
  letter-spacing: 2px;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 60%, 100% { opacity: 0.2; }
  30% { opacity: 1; }
}

/* Input */
.input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #1a1a1a;
  border-top: 1px solid #2a2a2a;
  flex-shrink: 0;
}

.input-area input {
  flex: 1;
  background: #2a2a2a;
  border: none;
  outline: none;
  color: #fff;
  font-size: 15px;
  padding: 10px 16px;
  border-radius: 24px;
}

.input-area input::placeholder { color: #666; }

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Footer */
.chat-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  padding: 6px 12px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  background: #1a1a1a;
  flex-shrink: 0;
}

.chat-footer a {
  font-size: 11px;
  color: #555;
  text-decoration: none;
}

.chat-footer a:hover { color: #888; }

/* Scrollbar */
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 380px) {
  .screen h1 { font-size: 24px; }
  .screen p { font-size: 14px; max-width: 260px; }

  .lang-buttons { gap: 12px; }
  .lang-btn { padding: 20px 24px; }
  .lang-btn .flag { font-size: 40px; }
  .lang-btn .label { font-size: 14px; }

  .char-buttons { gap: 12px; }
  .char-btn { padding: 16px 20px; }
  .char-btn .char-avatar { width: 64px; height: 64px; }
  .char-btn .char-name { font-size: 16px; }

  .welcome-avatar { width: 100px; height: 100px; }
  .welcome-start { padding: 12px 36px; font-size: 15px; }

  .screen-footer { gap: 12px; }
  .screen-footer a { font-size: 11px; }
}

@media (max-height: 600px) {
  .screen { gap: 16px; padding: 20px 16px; }
  .welcome-avatar { width: 80px; height: 80px; }
  .lang-btn { padding: 16px 24px; }
  .lang-btn .flag { font-size: 36px; }
  .char-btn .char-avatar { width: 60px; height: 60px; }
}

/* ===== TOUCH ===== */
button, a {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

input {
  font-size: 16px; /* Prevents iOS zoom */
}
