/**
 * Agenty v2 Styles
 * Mobile-first, clean, responsive
 */

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  height: 100vh;
  height: 100dvh;
  color: #fff;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ========== SCREENS ========== */
.screen {
  display: none;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ========== LANGUAGE SCREEN ========== */
#languageScreen.active {
  justify-content: center;
  align-items: center;
}

.language-box {
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 40px;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.1);
  max-width: 480px;
  width: 90%;
}

.language-box h1 { font-size: 28px; margin-bottom: 8px; }
.language-box .subtitle { opacity: 0.7; margin-bottom: 24px; }

.language-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}

.lang-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 12px;
  background: rgba(255,255,255,0.05);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
}

.lang-btn:hover {
  background: rgba(102,126,234,0.2);
  border-color: #667eea;
}

.lang-btn .flag { font-size: 32px; }
.lang-btn .name { font-size: 14px; }

.lang-switch {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.6);
  padding: 8px 16px;
  border-radius: 16px;
  cursor: pointer;
  margin-top: 16px;
  font-size: 13px;
}

.lang-switch:hover { background: rgba(255,255,255,0.1); color: white; }

/* ========== LOGIN SCREEN ========== */
#loginScreen.active {
  justify-content: center;
  align-items: center;
}

.login-box {
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 40px;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.1);
  max-width: 420px;
  width: 90%;
}

.login-box h1 { font-size: 48px; margin-bottom: 4px; }
.subtitle { opacity: 0.7; margin-bottom: 24px; }

.form-group { margin-bottom: 12px; }

.form-group input {
  width: 100%;
  padding: 14px 20px;
  border-radius: 20px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: white;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus { border-color: #667eea; }
.form-group input::placeholder { color: rgba(255,255,255,0.5); }

.buttons {
  display: flex;
  gap: 12px;
  margin: 16px 0;
}

.btn-primary, .btn-secondary {
  flex: 1;
  padding: 14px 20px;
  border-radius: 20px;
  border: none;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: white;
  border: 2px solid rgba(255,255,255,0.2);
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(102,126,234,0.4); }
.btn-secondary:hover { background: rgba(255,255,255,0.15); }

.error { color: #ff6b6b; font-size: 13px; min-height: 20px; margin-top: 8px; }

.info-box {
  margin-top: 20px;
  padding: 12px;
  background: rgba(102,126,234,0.15);
  border-radius: 12px;
  text-align: left;
  font-size: 13px;
  line-height: 1.5;
}

.info-box p { margin: 4px 0; opacity: 0.8; }

/* ========== DEVICE SCREEN ========== */
#deviceScreen.active {
  justify-content: center;
  align-items: center;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 20px;
}

.device-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
  background: rgba(255,255,255,0.05);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 16px;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
}

.device-btn:hover {
  background: rgba(102,126,234,0.2);
  border-color: #667eea;
}

.device-icon { font-size: 40px; margin-bottom: 8px; }
.device-name { font-size: 14px; }

/* ========== DESKTOP SCREEN ========== */
#desktopScreen.active {
  display: flex;
  flex-direction: column;
}

.desktop-header {
  background: rgba(0,0,0,0.3);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.logo { font-size: 18px; font-weight: 600; }

.header-right { display: flex; align-items: center; gap: 12px; }

.user-badge {
  background: rgba(102,126,234,0.3);
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 13px;
}

.btn-logout {
  padding: 8px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255,107,107,0.5);
  background: rgba(255,107,107,0.15);
  color: #ff6b6b;
  cursor: pointer;
  font-size: 13px;
}

.btn-logout:hover { background: #ff6b6b; color: white; }

.btn-lang {
  padding: 8px 12px;
  border-radius: 16px;
  border: 1px solid rgba(102,126,234,0.5);
  background: rgba(102,126,234,0.15);
  color: #667eea;
  cursor: pointer;
  font-size: 18px;
}

.btn-lang:hover { background: #667eea; color: white; }

.btn-gallery {
  padding: 8px 14px;
  border-radius: 16px;
  border: 1px solid rgba(102,126,234,0.5);
  background: rgba(102,126,234,0.15);
  color: #667eea;
  text-decoration: none;
  font-size: 13px;
}

.btn-gallery:hover { background: #667eea; color: white; }

.desktop {
  flex: 1;
  padding: 24px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 16px;
  overflow-y: auto;
}

.game-grid { display: flex; flex-wrap: wrap; gap: 16px; }

.game-icon {
  width: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 8px;
  border-radius: 12px;
  transition: background 0.2s;
}

.game-icon:hover { background: rgba(255,255,255,0.1); }

.icon-wrapper {
  width: 60px;
  height: 60px;
  border-radius: 14px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 6px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  position: relative;
}

.icon { font-size: 28px; }

.icon-label {
  font-size: 12px;
  text-align: center;
  opacity: 0.9;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.new-game .icon-wrapper {
  background: transparent;
  border: 2px dashed rgba(255,255,255,0.3);
}

.delete-btn {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255,107,107,0.9);
  color: white;
  border: none;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

.game-icon:hover .delete-btn { opacity: 1; }

.taskbar {
  background: rgba(0,0,0,0.4);
  padding: 8px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

/* ========== EDITOR SCREEN ========== */
#editorScreen.active {
  display: flex;
  flex-direction: column;
}

.editor-header {
  background: rgba(0,0,0,0.3);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.btn-back {
  padding: 8px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.1);
  color: white;
  cursor: pointer;
  font-size: 13px;
}

.btn-back:hover { background: rgba(255,255,255,0.2); }

.game-name-input {
  flex: 1;
  max-width: 280px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 14px;
  font-weight: 600;
}

.game-name-input:focus { border-color: #667eea; outline: none; }

.header-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.public-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
}

.public-toggle input { width: 16px; height: 16px; accent-color: #667eea; }
.toggle-label { font-size: 12px; opacity: 0.8; white-space: nowrap; }

.btn-versions, .btn-share {
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: white;
  cursor: pointer;
  font-size: 13px;
}

.btn-versions:hover { background: rgba(255,165,0,0.3); }
.btn-share:hover { background: rgba(0,184,148,0.3); }

.auto-save { font-size: 11px; opacity: 0.6; }

/* ========== EDITOR BODY ========== */
.editor-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ========== CHAT PANEL ========== */
.chat-panel {
  width: 45%;
  display: flex;
  flex-direction: column;
  background: rgba(0,0,0,0.2);
  border-right: 1px solid rgba(255,255,255,0.1);
  overflow: hidden;
  height: 100%;
}

.chat-header {
  padding: 12px 16px;
  background: rgba(0,0,0,0.3);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chat-header h3 { font-size: 15px; }

.btn-close-chat {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  background: rgba(255,100,100,0.2);
  color: white;
  font-size: 18px;
  cursor: pointer;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease;
}

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

.message.user {
  background: linear-gradient(135deg, #667eea, #764ba2);
  align-self: flex-end;
}

.message.assistant {
  background: rgba(255,255,255,0.1);
  align-self: flex-start;
}

.message pre {
  background: rgba(0,0,0,0.3);
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 12px;
  margin: 8px 0;
}

.retry-btn {
  display: inline-flex;
  gap: 6px;
  margin-top: 10px;
  padding: 8px 14px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border: none;
  border-radius: 16px;
  color: white;
  font-size: 13px;
  cursor: pointer;
}

.chat-input-area {
  display: flex;
  padding: 12px;
  gap: 8px;
  background: rgba(0,0,0,0.2);
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

#chatInput {
  flex: 1;
  padding: 10px 14px;
  border-radius: 16px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: white;
  font-size: 14px;
  outline: none;
}

#chatInput:focus { border-color: #667eea; }

.btn-send {
  padding: 10px 16px;
  border-radius: 16px;
  border: none;
  background: linear-gradient(135deg, #00b894, #00a085);
  color: white;
  font-size: 16px;
  cursor: pointer;
}

.quick-actions {
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: rgba(0,0,0,0.1);
  flex-shrink: 0;
}

.quick-actions span { font-size: 11px; opacity: 0.6; }

.quick-actions button {
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: white;
  font-size: 12px;
  cursor: pointer;
}

.quick-actions button:hover { background: rgba(102,126,234,0.3); }

/* ========== PREVIEW PANEL ========== */
.preview-panel {
  width: 55%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.preview-header {
  padding: 12px 16px;
  background: rgba(0,0,0,0.3);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-header h3 { font-size: 14px; }

.preview-actions { display: flex; gap: 8px; align-items: center; }

.btn-preview-action {
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: white;
  font-size: 12px;
  cursor: pointer;
}

.btn-preview-action:hover { background: rgba(102,126,234,0.4); }

.btn-refresh {
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: white;
  font-size: 12px;
  cursor: pointer;
}

.preview-container {
  flex: 1;
  padding: 12px;
  overflow: hidden;
  min-height: 0;
}

#preview {
  width: 100%;
  height: 100%;
  min-height: 300px;
  border: none;
  border-radius: 12px;
  background: white;
}

/* ========== CHAT TOGGLE (Mobile FAB) ========== */
.chat-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(102,126,234,0.4);
  z-index: 999;
  align-items: center;
  justify-content: center;
}

/* ========== MODALS ========== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: linear-gradient(135deg, #1e1e2e, #2d2d44);
  border-radius: 20px;
  padding: 28px;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  text-align: center;
}

.modal-content h2 { margin-bottom: 12px; }
.modal-desc { opacity: 0.7; margin-bottom: 16px; font-size: 14px; }

.modal-content input {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 15px;
  margin-bottom: 16px;
}

.modal-content input:focus { border-color: #667eea; outline: none; }

.modal-buttons { display: flex; gap: 12px; justify-content: center; }
.modal-buttons button { flex: 1; }

.btn-danger {
  padding: 12px 24px;
  border-radius: 20px;
  border: none;
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.warning { color: #ff6b6b; font-size: 13px; margin-bottom: 12px; }

/* Share Modal */
.share-info { opacity: 0.7; margin-bottom: 16px; }

.share-link-box { display: flex; gap: 8px; margin-bottom: 16px; }

.share-link-box input {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 13px;
}

.btn-copy {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.copy-status { margin-top: 8px; font-size: 13px; color: #00b894; }

.share-buttons { display: flex; gap: 8px; }
.btn-preview { background: linear-gradient(135deg, #00b894, #00a085); }
.btn-close { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); }

/* Version Modal */
.modal-versions { max-width: 480px; max-height: 80vh; display: flex; flex-direction: column; }

.version-list {
  max-height: 300px;
  overflow-y: auto;
  margin: 12px 0;
  border-radius: 10px;
  background: rgba(0,0,0,0.2);
}

.version-item {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.version-item:hover { background: rgba(255,255,255,0.05); }
.version-item:last-child { border-bottom: none; }

.version-label { font-size: 13px; margin-bottom: 2px; }
.version-time { font-size: 11px; opacity: 0.5; }

.btn-revert {
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid rgba(102,126,234,0.5);
  background: rgba(102,126,234,0.2);
  color: white;
  font-size: 12px;
  cursor: pointer;
}

.version-empty { text-align: center; padding: 24px; opacity: 0.5; }

/* ========== LOADING ========== */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#loadingText { margin-top: 12px; font-size: 14px; }

.stop-btn {
  margin-top: 12px;
  padding: 8px 24px;
  background: #e74c3c;
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.stop-btn:hover { background: #c0392b; transform: scale(1.05); }

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }

/* ========== RESPONSIVE ========== */

/* Tablet */
@media (max-width: 1024px) {
  .chat-panel { width: 50%; }
  .preview-panel { width: 50%; }
}

/* Mobile */
@media (max-width: 768px) {
  .login-box { padding: 28px 20px; width: 95%; }
  .login-box h1 { font-size: 36px; }
  
  .language-box { padding: 28px 20px; }
  .language-grid { grid-template-columns: repeat(2, 1fr); }
  
  .device-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .device-btn { padding: 16px 10px; }
  .device-icon { font-size: 32px; }
  
  .desktop-header { padding: 8px 12px; flex-wrap: wrap; gap: 8px; }
  .header-actions { display: none; }
  .desktop { padding: 12px; gap: 10px; }
  
  .game-icon { width: 70px; }
  .icon-wrapper { width: 48px; height: 48px; }
  .icon { font-size: 22px; }
  .icon-label { font-size: 10px; }
  
  .editor-header { padding: 8px 12px; gap: 8px; }
  .game-name-input { max-width: 140px; font-size: 13px; }
  .public-toggle { padding: 4px 8px; }
  .toggle-label { display: none; }
  .btn-versions, .btn-share { padding: 5px 10px; font-size: 12px; }
  
  /* Editor: Preview fills screen, chat as overlay */
  .editor-body { 
    flex-direction: column-reverse;
    height: calc(100vh - 50px);
  }
  .chat-panel, .preview-panel { width: 100%; }
  
  /* Chat: Hidden by default, FAB to open */
  .chat-panel {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    background: #1a1a2e;
  }
  
  .chat-panel.active { display: flex; }
  
  .btn-close-chat { display: flex; }
  
  /* Preview: Full screen on mobile */
  .preview-panel { 
    height: auto;
    flex: 1;
    min-height: 0;
  }
  .preview-container { 
    padding: 8px; 
    flex: 1;
    display: flex;
    flex-direction: column;
  }
  #preview { 
    flex: 1;
    min-height: 0;
    height: 100%;
  }
  
  .chat-toggle { display: flex; }
  
  /* Modal */
  .modal-content { padding: 20px; width: 95%; max-width: none; border-radius: 16px; }
  .modal-buttons { flex-direction: column; }
  .share-link-box { flex-direction: column; }
}

/* Small mobile */
@media (max-width: 480px) {
  .login-box { padding: 20px 16px; }
  .login-box h1 { font-size: 28px; }
  .language-box h1 { font-size: 24px; }
  
  .buttons { flex-direction: column; }
  
  .game-icon { width: 60px; }
  .icon-wrapper { width: 42px; height: 42px; }
  .icon { font-size: 18px; }
  
  /* Preview still fills available space */
  .preview-panel { flex: 1; }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .login-box { padding: 16px; width: 95%; }
  .login-box h1 { font-size: 24px; margin-bottom: 0; }
  .subtitle { display: none; }
  .info-box { display: none; }
  
  .editor-body { flex-direction: row; }
  .chat-panel, .preview-panel { width: 50%; height: calc(100vh - 50px); }
  .chat-messages { max-height: calc(100vh - 120px); }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Print */
@media print {
  .btn-logout, .btn-share, .btn-refresh, .quick-actions, .chat-input-area { display: none !important; }
}