/* ============================================
   STUDY BUDDY — Cute Minimalist Blue Theme
   ============================================ */

/* --- Variables --- */
:root {
  --blue-50:  #EEF7FF;
  --blue-100: #DCF0FF;
  --blue-200: #B8E0FF;
  --blue-300: #7EC8F7;
  --blue-400: #4AAEDE;
  --blue-500: #2A8FBF;
  --blue-600: #1A6E99;

  --sky-light: #F0F9FF;
  --sky-soft:  #E0F2FE;
  --sky-mid:   #BAE6FD;

  --white:     #FFFFFF;
  --gray-100:  #F8FAFC;
  --gray-200:  #F1F5F9;
  --gray-400:  #94A3B8;
  --gray-600:  #64748B;
  --gray-800:  #1E293B;

  --accent:    #60C5E8;
  --accent2:   #A8E6CF;
  --warn:      #FBBF24;

  --radius-sm:  10px;
  --radius-md:  18px;
  --radius-lg:  24px;
  --radius-xl:  32px;

  --shadow-sm:  0 2px 8px rgba(74, 174, 222, 0.12);
  --shadow-md:  0 4px 20px rgba(74, 174, 222, 0.18);
  --shadow-lg:  0 8px 40px rgba(74, 174, 222, 0.22);

  --font-main:  'Nunito', sans-serif;
  --font-head:  'Baloo 2', cursive;

  --header-h:  72px;
  --footer-h:  80px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  min-height: 100vh;
  font-family: var(--font-main);
  background: linear-gradient(145deg, #C8E9FF 0%, #E8F6FF 40%, #F5FBFF 70%, #DFF0FF 100%);
  color: var(--gray-800);
  overflow: hidden;
  position: relative;
}

/* --- Floating Decorations --- */
.deco {
  position: fixed;
  pointer-events: none;
  user-select: none;
  z-index: 0;
  opacity: 0.18;
  animation: floatDeco 6s ease-in-out infinite;
  font-size: 1.6rem;
  filter: blur(0.5px);
}

.deco-1 { top: 8%; left: 4%;  animation-delay: 0s;    font-size: 1.4rem; }
.deco-2 { top: 15%; right: 6%; animation-delay: 1s;   font-size: 1.2rem; }
.deco-3 { top: 60%; left: 3%; animation-delay: 2s;    font-size: 1.5rem; }
.deco-4 { top: 75%; right: 4%; animation-delay: 0.5s; font-size: 1.3rem; }
.deco-5 { top: 40%; right: 2%; animation-delay: 1.8s; font-size: 1.1rem; }
.deco-6 { top: 30%; left: 2%; animation-delay: 2.5s;  font-size: 1.2rem; }

@keyframes floatDeco {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  33%       { transform: translateY(-12px) rotate(5deg); }
  66%       { transform: translateY(6px) rotate(-4deg); }
}

/* --- App Wrapper --- */
.app-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 680px;
  height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.70);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-left: 1px solid rgba(255, 255, 255, 0.8);
  border-right: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow-lg);
}

/* --- Header --- */
.header {
  height: var(--header-h);
  min-height: var(--header-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 2px solid var(--sky-mid);
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 12px;
}

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

.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-100), var(--blue-200));
  border: 2.5px solid var(--blue-300);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  box-shadow: 0 2px 10px rgba(74,174,222,0.3);
  animation: avatarBounce 3s ease-in-out infinite;
}

@keyframes avatarBounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-3px); }
}

.status-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 11px;
  height: 11px;
  background: #4ADE80;
  border-radius: 50%;
  border: 2px solid white;
  animation: pulseDot 2s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
  50%       { box-shadow: 0 0 0 5px rgba(74, 222, 128, 0); }
}

.app-name {
  font-family: var(--font-head);
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--blue-600);
  line-height: 1.1;
  letter-spacing: -0.3px;
}

.app-status {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--blue-400);
  margin-top: 1px;
}

.btn-clear {
  background: var(--blue-50);
  border: 1.5px solid var(--blue-200);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1;
  flex-shrink: 0;
}

.btn-clear:hover {
  background: #FEE2E2;
  border-color: #FCA5A5;
  transform: scale(1.05);
}

.btn-clear:active {
  transform: scale(0.95);
}

.btn-home {
  background: var(--blue-50);
  border: 1.5px solid var(--blue-200);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1;
  flex-shrink: 0;
}

.btn-home:hover {
  background: var(--blue-100);
  border-color: var(--blue-300);
  transform: scale(1.05);
}

.btn-home:active {
  transform: scale(0.95);
}

/* --- Chat Area --- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar {
  width: 5px;
}
.chat-area::-webkit-scrollbar-track {
  background: transparent;
}
.chat-area::-webkit-scrollbar-thumb {
  background: var(--blue-200);
  border-radius: 10px;
}

/* --- Welcome Card --- */
.welcome-card {
  background: linear-gradient(135deg, rgba(255,255,255,0.95), rgba(240,249,255,0.95));
  border: 2px solid var(--sky-mid);
  border-radius: var(--radius-xl);
  padding: 28px 24px;
  text-align: center;
  margin-bottom: 8px;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.welcome-emoji {
  font-size: 2.8rem;
  margin-bottom: 10px;
  display: block;
  animation: wobble 2.5s ease-in-out infinite;
}

@keyframes wobble {
  0%, 100% { transform: rotate(0deg); }
  20%       { transform: rotate(-8deg); }
  40%       { transform: rotate(8deg); }
  60%       { transform: rotate(-4deg); }
  80%       { transform: rotate(4deg); }
}

.welcome-title {
  font-family: var(--font-head);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--blue-600);
  margin-bottom: 8px;
}

.welcome-desc {
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--gray-600);
  margin-bottom: 20px;
}

.quick-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--blue-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  background: linear-gradient(135deg, var(--blue-100), var(--sky-soft));
  border: 1.5px solid var(--blue-200);
  border-radius: 20px;
  padding: 7px 14px;
  font-family: var(--font-main);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--blue-600);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.chip:hover {
  background: var(--blue-300);
  color: white;
  border-color: var(--blue-300);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(74,174,222,0.3);
}

.chip:active {
  transform: translateY(0);
}

/* --- Messages Container --- */
.messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* --- Message Rows --- */
.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  animation: msgIn 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(14px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.message-row.user {
  flex-direction: row-reverse;
}

.message-row.bot {
  flex-direction: row;
}

/* --- Avatars in Chat --- */
.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  border: 2px solid transparent;
  margin-bottom: 4px;
}

.message-row.bot .msg-avatar {
  background: linear-gradient(135deg, var(--blue-100), var(--blue-200));
  border-color: var(--blue-300);
}

.message-row.user .msg-avatar {
  background: linear-gradient(135deg, #E0F2FE, #BAE6FD);
  border-color: var(--blue-300);
}

/* --- Bubbles --- */
.bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  gap: 4px;
}

.message-row.user .bubble-wrap {
  align-items: flex-end;
}

.message-row.bot .bubble-wrap {
  align-items: flex-start;
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  line-height: 1.7;
  position: relative;
  word-break: break-word;
}

/* Bot bubble */
.message-row.bot .bubble {
  background: rgba(255, 255, 255, 0.95);
  border: 1.5px solid var(--sky-mid);
  border-bottom-left-radius: 6px;
  color: var(--gray-800);
  box-shadow: var(--shadow-sm);
}

/* User bubble */
.message-row.user .bubble {
  background: linear-gradient(135deg, var(--blue-400), var(--blue-500));
  border: 1.5px solid var(--blue-400);
  border-bottom-right-radius: 6px;
  color: white;
  box-shadow: 0 3px 14px rgba(42,143,191,0.35);
}

.bubble-time {
  font-size: 0.68rem;
  color: var(--gray-400);
  font-weight: 600;
  padding: 0 4px;
}

/* Bot bubble markdown-like styling */
.bubble strong { font-weight: 700; color: var(--blue-600); }
.message-row.user .bubble strong { color: rgba(255,255,255,0.9); }

.bubble ul, .bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}

.bubble li {
  margin: 4px 0;
}

.bubble p {
  margin: 0 0 6px;
}
.bubble p:last-child { margin-bottom: 0; }

.bubble code {
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.82rem;
  font-family: 'Courier New', monospace;
  color: var(--blue-600);
}

.bubble pre {
  background: var(--blue-50);
  border: 1.5px solid var(--blue-100);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.8rem;
}

/* --- Typing Indicator --- */
.typing-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  animation: msgIn 0.35s ease;
}

.typing-bubble {
  background: rgba(255,255,255,0.95);
  border: 1.5px solid var(--sky-mid);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 6px;
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 8px;
  height: 8px;
  background: var(--blue-300);
  border-radius: 50%;
  animation: typingDots 1.4s ease-in-out infinite;
}

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

@keyframes typingDots {
  0%, 60%, 100% { transform: translateY(0); background: var(--blue-300); }
  30%            { transform: translateY(-8px); background: var(--blue-500); }
}

/* --- Input Area --- */
.input-area {
  padding: 12px 16px 16px;
  background: rgba(255,255,255,0.92);
  border-top: 2px solid var(--sky-mid);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--white);
  border: 2px solid var(--blue-200);
  border-radius: var(--radius-xl);
  padding: 8px 8px 8px 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.input-wrap:focus-within {
  border-color: var(--blue-400);
  box-shadow: 0 0 0 4px rgba(74,174,222,0.15), var(--shadow-sm);
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-main);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--gray-800);
  resize: none;
  max-height: 120px;
  line-height: 1.6;
  padding: 4px 0;
}

.chat-input::placeholder {
  color: var(--gray-400);
}

.chat-input::-webkit-scrollbar {
  width: 4px;
}

.send-btn {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-400), var(--blue-500));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: white;
  transition: all 0.2s ease;
  box-shadow: 0 3px 12px rgba(42,143,191,0.4);
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.08);
  box-shadow: 0 5px 18px rgba(42,143,191,0.5);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.93);
}

.send-btn:disabled {
  background: linear-gradient(135deg, var(--gray-200), var(--gray-400));
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.6;
}

.send-icon {
  display: inline-block;
  transform: translateX(1px);
  font-style: normal;
  font-size: 0.9rem;
}

.input-hint {
  font-size: 0.68rem;
  color: var(--gray-400);
  text-align: center;
  font-weight: 500;
}

/* --- API Key Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 40, 80, 0.45);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: white;
  border-radius: var(--radius-xl);
  padding: 32px 28px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
  border: 2px solid var(--sky-mid);
  animation: modalIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(30px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  display: block;
  animation: wobble 2s ease-in-out infinite;
}

.modal-title {
  font-family: var(--font-head);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--blue-600);
  margin-bottom: 12px;
}

.modal-desc {
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--gray-600);
  margin-bottom: 20px;
}

.modal-desc a {
  color: var(--blue-500);
  font-weight: 700;
  text-decoration: none;
}
.modal-desc a:hover { text-decoration: underline; }

.api-input {
  width: 100%;
  padding: 13px 16px;
  border: 2px solid var(--blue-200);
  border-radius: var(--radius-md);
  font-family: var(--font-main);
  font-size: 0.87rem;
  color: var(--gray-800);
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.api-input:focus {
  border-color: var(--blue-400);
  box-shadow: 0 0 0 3px rgba(74,174,222,0.15);
}

.api-input::placeholder {
  color: var(--gray-400);
}

.modal-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--blue-400), var(--blue-500));
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 12px;
  box-shadow: 0 4px 16px rgba(42,143,191,0.4);
}

.modal-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(42,143,191,0.5);
}

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

.modal-note {
  font-size: 0.72rem;
  color: var(--gray-400);
  font-weight: 600;
}

/* --- Error State --- */
.error-bubble {
  background: #FEF2F2;
  border-color: #FECACA;
  color: #DC2626;
}

/* --- Responsive --- */
@media (max-width: 480px) {
  .app-wrapper {
    border-left: none;
    border-right: none;
    border-radius: 0;
  }

  .welcome-card {
    padding: 20px 16px;
  }

  .welcome-title {
    font-size: 1.2rem;
  }

  .welcome-emoji {
    font-size: 2.2rem;
  }

  .bubble-wrap {
    max-width: 85%;
  }

  .chip {
    font-size: 0.76rem;
    padding: 6px 12px;
  }

  .app-name {
    font-size: 1.15rem;
  }

  .header {
    padding: 0 14px;
  }

  .chat-area {
    padding: 16px 12px 12px;
  }

  .input-area {
    padding: 10px 12px 14px;
  }

  .deco {
    opacity: 0.1;
    font-size: 1.1rem;
  }
}

@media (min-width: 681px) {
  .app-wrapper {
    border-radius: 0;
    max-width: 680px;
    height: 100vh;
  }
}

@media (min-width: 1024px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .app-wrapper {
    height: 90vh;
    max-height: 820px;
    border-radius: var(--radius-xl);
    border: 1.5px solid rgba(255,255,255,0.9);
  }

  .header {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }

  .input-area {
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  }
}

/* --- Utility --- */
.hidden { display: none !important; }
