/* === RESET & BASE === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-deep: #06060f;
  --bg-card: #0d1117;
  --alien-bg: #0f1923;
  --alien-border: #4ecdc4;
  --alien-glow: rgba(78, 205, 196, 0.15);
  --user-bg: #1a1228;
  --user-border: #9b7ed8;
  --input-bg: #111827;
  --input-border: #2d3748;
  --input-focus: #4ecdc4;
  --accent: #ffd93d;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --success: #4ecdc4;
  --error: #f87171;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* === STARS BACKGROUND === */
#stars, #stars2 {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
}

#stars {
  background:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 30% 70%, rgba(255,255,255,0.6), transparent),
    radial-gradient(1.5px 1.5px at 50% 10%, rgba(255,255,255,0.9), transparent),
    radial-gradient(1px 1px at 70% 40%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 90% 80%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1.5px 1.5px at 15% 90%, rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 85% 15%, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 45% 55%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.5px 1.5px at 65% 95%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 25% 45%, rgba(255,255,255,0.5), transparent);
  animation: twinkle 4s ease-in-out infinite alternate;
}

#stars2 {
  background:
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1.5px 1.5px at 40% 80%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 60% 20%, rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 80% 60%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1.5px 1.5px at 5% 75%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 95% 45%, rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 55% 35%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.5px 1.5px at 35% 5%, rgba(255,255,255,0.7), transparent);
  animation: twinkle 5s ease-in-out infinite alternate-reverse;
}

@keyframes twinkle {
  0% { opacity: 0.5; }
  100% { opacity: 1; }
}

/* === APP LAYOUT === */
#app {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

/* === HEADER === */
#header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 16px 0 12px;
  background: linear-gradient(to bottom, var(--bg-deep) 60%, transparent);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.signal-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.signal-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--alien-border);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--alien-border); }
  50% { opacity: 0.4; box-shadow: none; }
}

.signal-text {
  letter-spacing: 0.5px;
}

.progress-bar {
  width: 100%;
  height: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--alien-border), var(--accent));
  border-radius: 2px;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === CHAT === */
#chat {
  flex: 1;
  padding: 8px 0 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}

/* === MESSAGE BUBBLES === */
.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  animation: message-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.alien {
  align-self: flex-start;
  background: var(--alien-bg);
  border: 1px solid rgba(78, 205, 196, 0.15);
  border-radius: 4px 16px 16px 16px;
  color: var(--text);
}

.message.alien.first-in-group {
  margin-top: 12px;
}

.message.alien.first-in-group::before {
  content: '👽 ЗаГ и Кве';
  display: block;
  font-size: 0.75rem;
  color: var(--alien-border);
  margin-bottom: 4px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bg);
  border: 1px solid rgba(155, 126, 216, 0.2);
  border-radius: 16px 4px 16px 16px;
  color: #d4bfff;
}

.message.user::before {
  content: 'Мария';
  display: block;
  font-size: 0.75rem;
  color: var(--user-border);
  margin-bottom: 4px;
  font-weight: 600;
  text-align: right;
}

.message .cipher {
  font-family: 'Courier New', monospace;
  color: var(--accent);
  text-shadow: 0 0 8px rgba(255, 217, 61, 0.3);
}

.message em {
  color: var(--accent);
  font-style: normal;
  font-weight: 600;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* === IMAGE MESSAGE === */
.alien-image {
  padding: 6px !important;
  background: var(--alien-bg);
  overflow: hidden;
}

.quest-image {
  width: 100%;
  max-width: 400px;
  border-radius: 12px;
  display: block;
}

/* === TYPING INDICATOR === */
.typing-indicator {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--alien-bg);
  border: 1px solid rgba(78, 205, 196, 0.1);
  border-radius: 4px 16px 16px 16px;
  animation: message-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--alien-border);
  animation: typing-bounce 1.4s ease-in-out infinite;
}

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

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* === INPUT AREA === */
#input-area {
  position: sticky;
  bottom: 0;
  padding: 16px 0 24px;
  background: linear-gradient(to top, var(--bg-deep) 70%, transparent);
  z-index: 10;
}

/* Choice buttons */
.choice-container {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  animation: fade-up 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.choice-btn {
  padding: 10px 24px;
  background: var(--user-bg);
  border: 1.5px solid var(--user-border);
  border-radius: 20px;
  color: #d4bfff;
  font-size: 1rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.choice-btn:hover {
  background: rgba(155, 126, 216, 0.2);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(155, 126, 216, 0.2);
}

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

/* Text input */
.input-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fade-up 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.input-hint {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-field {
  flex: 1;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 1.5px solid var(--input-border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  transition: all 0.3s ease;
}

.input-field::placeholder {
  color: rgba(148, 163, 184, 0.5);
}

.input-field:focus {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.1), 0 0 20px rgba(78, 205, 196, 0.05);
}

.date-field {
  color-scheme: dark;
  min-width: 180px;
}

.input-field.error {
  border-color: var(--error);
  animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.submit-btn {
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--alien-border), #38b2ac);
  border: none;
  border-radius: 12px;
  color: var(--bg-deep);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.submit-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(78, 205, 196, 0.3);
}

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

.submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.error-text {
  color: var(--error);
  font-size: 0.8rem;
  text-align: center;
  animation: fade-in 0.3s ease;
}

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-3px); }
  40%, 60% { transform: translateX(3px); }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Dual input */
.dual-input-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.dual-input-row .input-field {
  text-align: center;
  max-width: 120px;
}

.dual-input-separator {
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* === AUDIO INDICATOR === */
.audio-indicator {
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 32px;
  background: rgba(78, 205, 196, 0.05);
  border: 1px solid rgba(78, 205, 196, 0.15);
  border-radius: 16px;
  margin: 12px 0;
  animation: message-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.audio-waves {
  display: flex;
  gap: 4px;
  align-items: center;
  height: 32px;
}

.audio-wave-bar {
  width: 4px;
  border-radius: 2px;
  background: var(--alien-border);
  animation: wave 1.2s ease-in-out infinite;
}

.audio-wave-bar:nth-child(1) { height: 8px; animation-delay: 0s; }
.audio-wave-bar:nth-child(2) { height: 16px; animation-delay: 0.1s; }
.audio-wave-bar:nth-child(3) { height: 24px; animation-delay: 0.2s; }
.audio-wave-bar:nth-child(4) { height: 32px; animation-delay: 0.3s; }
.audio-wave-bar:nth-child(5) { height: 24px; animation-delay: 0.4s; }
.audio-wave-bar:nth-child(6) { height: 16px; animation-delay: 0.5s; }
.audio-wave-bar:nth-child(7) { height: 8px; animation-delay: 0.6s; }

@keyframes wave {
  0%, 100% { transform: scaleY(1); opacity: 0.5; }
  50% { transform: scaleY(1.8); opacity: 1; }
}

.audio-label {
  font-size: 0.8rem;
  color: var(--alien-border);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.replay-btn {
  padding: 8px 18px;
  background: transparent;
  border: 1px solid rgba(78, 205, 196, 0.3);
  border-radius: 16px;
  color: var(--alien-border);
  font-size: 0.85rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s ease;
}

.replay-btn:hover {
  background: rgba(78, 205, 196, 0.1);
  border-color: var(--alien-border);
}

.replay-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === SCREEN EFFECTS === */
.screen-flash {
  position: fixed;
  inset: 0;
  background: rgba(78, 205, 196, 0.15);
  z-index: 100;
  animation: flash 0.6s ease-out forwards;
  pointer-events: none;
}

@keyframes flash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

.screen-shake {
  animation: screen-shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes screen-shake {
  10%, 90% { transform: translateX(-1px) translateY(1px); }
  20%, 80% { transform: translateX(2px) translateY(-1px); }
  30%, 50%, 70% { transform: translateX(-2px) translateY(2px); }
  40%, 60% { transform: translateX(2px) translateY(-2px); }
}

/* === CONFETTI === */
#confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  top: -10px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* === FINALE === */
.finale-message {
  text-align: center;
  padding: 32px 24px;
  margin: 24px 0;
  background: linear-gradient(135deg, rgba(78, 205, 196, 0.08), rgba(155, 126, 216, 0.08));
  border: 1px solid rgba(78, 205, 196, 0.2);
  border-radius: 20px;
  animation: finale-in 1s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.finale-message h2 {
  font-size: 1.5rem;
  background: linear-gradient(135deg, var(--alien-border), var(--accent), var(--user-border));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

@keyframes finale-in {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* === SEPARATOR === */
.scene-separator {
  text-align: center;
  padding: 24px 0;
  color: var(--text-dim);
  font-size: 0.8rem;
  letter-spacing: 2px;
  opacity: 0.5;
}

/* === SCROLLBAR === */
#chat::-webkit-scrollbar {
  width: 4px;
}

#chat::-webkit-scrollbar-track {
  background: transparent;
}

#chat::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}

/* === RESPONSIVE === */
@media (max-width: 480px) {
  #app {
    padding: 0 12px;
  }

  .message {
    max-width: 90%;
    padding: 10px 14px;
    font-size: 0.95rem;
  }

  .choice-btn {
    padding: 10px 20px;
    font-size: 0.95rem;
  }

  .input-field {
    padding: 11px 14px;
    font-size: 0.95rem;
  }

  .dual-input-row .input-field {
    max-width: 100px;
  }
}

/* === START SCREEN === */
.start-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80dvh;
  gap: 24px;
  animation: fade-in 1s ease both;
}

.start-screen .signal-icon {
  font-size: 3rem;
  animation: pulse-icon 2s ease-in-out infinite;
}

@keyframes pulse-icon {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.1); filter: brightness(1.3); }
}

.start-screen h1 {
  font-size: 1.4rem;
  color: var(--alien-border);
  text-align: center;
  font-weight: 400;
  letter-spacing: 1px;
}

.start-screen .start-btn {
  padding: 14px 40px;
  background: transparent;
  border: 1.5px solid var(--alien-border);
  border-radius: 24px;
  color: var(--alien-border);
  font-size: 1rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 0.5px;
}

.start-screen .start-btn:hover {
  background: rgba(78, 205, 196, 0.1);
  box-shadow: 0 0 24px rgba(78, 205, 196, 0.15);
  transform: translateY(-2px);
}

/* Reset button (hidden, bottom corner) */
.reset-btn {
  position: fixed;
  bottom: 8px;
  right: 8px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.08);
  font-size: 0.7rem;
  cursor: pointer;
  z-index: 50;
  padding: 4px 8px;
  font-family: var(--font);
}

.reset-btn:hover {
  color: rgba(255,255,255,0.3);
}
