* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  scroll-behavior: smooth;
  background: #0f0f0f;
  color: #fff;
  transition: background 0.6s cubic-bezier(0.22, 1, 0.36, 1),
              color 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  -webkit-font-smoothing: antialiased;
  -webkit-overflow-scrolling: touch;
  overflow-x: hidden;
}

body.light-mode {
  background: #ffffff;
  color: #000;
}

#top-box {
  position: sticky;
  top: 0;
  z-index: 1000;
  padding: 15px 20px;
  background: rgba(20, 20, 20, 0.85);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

body.light-mode #top-box {
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid rgba(0,0,0,0.08);
}

#top-box h1 {
  font-size: 28px;
  font-weight: 610;
  transition: transform 0.3s ease;
}

#top-box h1:hover {
  transform: translateX(2px);
}

.top-buttons {
  display: flex;
  align-items: center;
  gap: 18px;
}

#settings-btn {
  background: none;
  color: #fff;
  padding: 4px 10px;
  font-size: 27px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

#settings-btn:hover {
  transform: translateY(-2px);
}

#theme-switch {
  font-size: 27px;
  background: none;
  border: none;
  color: gold;
  cursor: pointer;
  transition: transform 0.4s cubic-bezier(0.68, -0.6, 0.32, 1.6),
              color 0.3s ease;
}

#theme-switch:hover {
  transform: rotate(15deg) scale(1.1);
}

body.light-mode #theme-switch {
  color: #333;
}

#app-container {
  max-width: 1000px;
  margin: auto;
  padding: 80px 15px 100px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.6s ease;
}

#chat-box {
  flex: 1;
  overflow-y: auto;
  background: #111;
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 690px;
  margin: auto;
  width: 100%;
  border: 1px solid rgba(255,255,255,0.03);
}

body.light-mode #chat-box {
  background: rgba(255,255,255,0.95);
  border: 1px solid rgba(0,0,0,0.03);
}

/* Scrollbar styling */
#chat-box::-webkit-scrollbar {
  width: 8px;
}

#chat-box::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.05);
}

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

/* Bot message styling */
.bot-message {
  width: 100%;
  padding: 0;
  font-size: 1rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: inherit;
  align-self: flex-start;
}

.bot-message strong:first-child {
  display: block;
  font-size: 1.3rem;
  font-weight: 650;
  color: #0d6efd;
  margin-bottom: 12px;
  letter-spacing: -0.2px;
}

body.light-mode .bot-message strong:first-child {
  color: #084298;
}

/* User message styling */
.user-message {
  max-width: 85%;
  padding: 14px 20px;
  font-size: 1rem;
  border-radius: 18px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  background: linear-gradient(145deg, #0d6efd, #0056d2);
  color: #ffffff;
  align-self: flex-end;
  border: 1px solid rgba(255, 255, 255, 0.15);
  animation: fadeInUp 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

body.light-mode .user-message {
  background: linear-gradient(145deg, #cce5ff, #b3d9ff);
  color: #333;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate3d(0, 10px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

/* Typing indicator */
.bot-message.typing {
  color: rgba(255, 255, 255, 0.7);
  font-style: italic;
}

body.light-mode .bot-message.typing {
  color: rgba(0, 0, 0, 0.6);
}

/* Tables in messages */
.bot-message table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  background: rgba(30, 30, 30, 0.05);
  border-radius: 8px;
  overflow: hidden;
}

body.light-mode .bot-message table {
  background: rgba(0, 0, 0, 0.03);
}

.bot-message th,
.bot-message td {
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

body.light-mode .bot-message th,
body.light-mode .bot-message td {
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.bot-message th {
  background: rgba(13, 110, 253, 0.1);
  font-weight: 600;
}

/* Code blocks */
.bot-message pre {
  background: rgba(30, 30, 30, 0.2);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 12px 0;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.9rem;
}

body.light-mode .bot-message pre {
  background: rgba(0, 0, 0, 0.05);
}

/* Lists */
.bot-message ul,
.bot-message ol {
  padding-left: 24px;
  margin: 12px 0;
}

.bot-message li {
  margin-bottom: 6px;
}

/* Final thought section */
.final-thought {
  padding-left: 16px;
  border-left: 3px solid #0d6efd;
  margin: 16px 0;
}

body.light-mode .final-thought {
  border-left: 3px solid #084298;
}

.final-thought-title {
  font-weight: 600;
  margin-bottom: 8px;
  color: #0d6efd;
}

body.light-mode .final-thought-title {
  color: #084298;
}

/* Input area */
#input-form {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 12px;
  padding: 18px 20px;
  background: rgba(20,20,20,0.92);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  border-top: 1px solid rgba(255,255,255,0.1);
  z-index: 999;
}

body.light-mode #input-form {
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid rgba(0,0,0,0.08);
}

#user-input {
  flex: 1;
  padding: 14px 18px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  background: #222;
  color: #fff;
  transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

body.light-mode #user-input {
  background: #f5f5f5;
  color: #333;
}

#user-input:focus {
  outline: none;
}

#send-btn {
  background: linear-gradient(145deg, #0d6efd, #084298);
  color: #fff;
  padding: 14px 20px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

#send-btn:hover {
  transform: translateY(-2px);
}

/* Scroll to bottom button */
#scroll-to-bottom {
  position: fixed;
  bottom: 80px;
  right: 20px;
  background: #333;
  color: #fff;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: none;
  border-radius: 50%;
  display: none;
  z-index: 999;
  cursor: pointer;
  transition: all 0.3s ease;
}

#scroll-to-bottom:hover {
  background: #0d6efd;
  transform: scale(1.1);
}

body.light-mode #scroll-to-bottom {
  background: #aaa;
}

/* Loading screen */
#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid rgba(255,255,255,0.1);
  border-top: 5px solid #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

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

/* Responsive adjustments */
@media (max-width: 768px) {
  #chat-box {
    padding: 16px;
    border-radius: 12px;
  }
  #top-box h1 {
    font-size: 24px;
  }
  .bot-message strong:first-child {
    font-size: 1.2rem;
  }
  #user-input, #send-btn {
    padding: 12px 16px;
  }
}

@media (max-width: 480px) {
  #app-container {
    padding: 60px 12px 90px;
  }
  .user-message {
    max-width: 90%;
    padding: 12px 16px;
  }
  #input-form {
    padding: 14px 16px;
  }
  }
