html, body {
  min-height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden; /* Prevent horizontal scrolling */
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto; /* Allow vertical scrolling */
  justify-content: center; /* Center vertically */
  background-color: #ffffff;
  color: #333333;
  font-family: "Sour Gummy", sans-serif;
  font-optical-sizing: auto;
  font-variation-settings: "wdth" 100;
  overflow-y: auto; /* Allow vertical scrolling */
  padding: 40px 20px; /* Add more top/bottom padding for breathing room */
  min-height: 100vh; /* Fill viewport height for vertical centering */
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
}

.overlay.hidden { display: none; }

.modal-card {
  width: min(90vw, 540px);
  background: #ffffff;
  border: 3px solid #007BFF;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  overflow: hidden;
  transform-origin: center;
}


.pop-in { animation: popIn 500ms cubic-bezier(.2, .7, .3, 1.2); }
.slide-in-right { animation: slideInRight 450ms cubic-bezier(.2, .7, .3, 1.2); }

/* Inline encouragement card - appears next to code box */
.inline-encouragement {
  position: absolute;
  left: 50%;
  transform: translateX(50px);
  width: 35%;
  max-width: 500px;
  opacity: 0;
  transition: all 0.6s cubic-bezier(.25, .46, .45, .94);
  display: flex;
  flex-direction: column;
}

.inline-encouragement.visible {
  opacity: 1;
  transform: translateX(20%);
}

.inline-encouragement.hidden { 
  display: none; 
}

.inline-encouragement.slide-out-right {
  animation: slideOutRightInline 0.6s cubic-bezier(.25, .46, .45, .94) forwards;
}

/* Ensure the inline encouragement card matches the modal card styling */
#inline-encouragement-card {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}



.slide-out-right { animation: slideOutRight 380ms cubic-bezier(.2, .7, .3, 1.2) forwards; }

@keyframes popIn {
  0% { transform: scale(.85) rotate(-2deg); opacity: 0; }
  60% { transform: scale(1.03) rotate(1deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

@keyframes slideInRight {
  0% { transform: translateX(20px); opacity: 0; }
  100% { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutRight {
  0% { transform: translateX(0); opacity: 1; }
  100% { transform: translateX(20px); opacity: 0; }
}

@keyframes slideOutRightInline {
  0% { transform: translateX(20%); opacity: 1; }
  100% { transform: translateX(100px); opacity: 0; }
}


.modal-hero {
  position: relative;
  height: 120px;
  background: linear-gradient(135deg, #007BFF, #0056B3);
  display: grid;
  place-items: center;
}

.badge {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  color: #007BFF;
  font-size: 28px;
  border: 3px solid #ffffffaa;
  box-shadow: 0 6px 18px rgba(0,0,0,0.2);
}

/* Smaller hero and badge for code box */
#code-box .modal-hero {
  height: 80px;
}

#code-box .badge {
  width: 48px;
  height: 48px;
  font-size: 20px;
  border: 2px solid #ffffffaa;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Match encouragement card header to code box dimensions */
#inline-encouragement-card .modal-hero {
  height: 80px;
}

#inline-encouragement-card .badge {
  width: 48px;
  height: 48px;
  font-size: 20px;
  border: 2px solid #ffffffaa;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  color: #4CAF50;
}


.modal-body { padding: 20px 20px 24px; text-align: center; }
.modal-body h2 { margin: 10px 0 8px; color: #007BFF; }
.modal-body p { color: #333; }

/* More compact modal body for code box */
#code-box .modal-body { 
  padding: 15px 15px 20px; 
  text-align: left; 
}

#code-box .modal-body h2 { 
  margin: 0 0 12px 0; 
  color: #007BFF; 
  font-size: 1.2em;
}

/* Match encouragement card body to code box styling */
#inline-encouragement-card .modal-body { 
  padding: 15px 15px 20px; 
  text-align: center; 
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

#inline-encouragement-card .modal-body h2 { 
  margin: 0 0 12px 0; 
  color: #4CAF50; 
  font-size: 1.2em;
  font-weight: 600;
}

/* Improve encouragement text styling */
#inline-encouragement-card .modal-body p { 
  color: #333; 
  font-weight: 400;
  line-height: 1.5;
}

#inline-encouragement-card .modal-body h3 { 
  color: #333; 
  font-weight: 400;
  font-size: 1.1em;
  margin: 0 0 8px 0;
}

.modal-actions { display: flex; justify-content: center; gap: 10px; margin-top: 12px; }
.modal-actions .primary { background: #007BFF; color: #fff; padding: 10px 16px; border-radius: 6px; text-decoration: none; display: inline-flex; align-items: center; }
.modal-actions .primary:hover { background: #0056B3; }
.modal-actions .secondary { background: #eee; color: #333; padding: 10px 16px; border-radius: 6px; border: 1px solid #ddd; display: inline-flex; align-items: center; }
.modal-actions .secondary:hover { background: #e2e2e2; }

.close-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 10px;
  background: #ffffff;
  color: #333;
  border: 2px solid #eee;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  margin: 0;
  line-height: 1;
  font-size: 12px;
}

.close-btn i {
  display: block;
  margin: 0;
  padding: 0;
  line-height: 1;
}
.close-btn:hover { background: #f3f3f3; }

h1 {
  margin-bottom: 36px; /* Increased spacing under title */
  color: #007BFF;
  font-size: 2em;
  display: flex;
  align-items: center;
  justify-content: center;
}

h1 i {
  margin-right: 10px;
}

#image-options {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px; /* space between controls */
  margin-bottom: 28px; /* more air between controls and next section */
}

.camera-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#image-options p {
  margin-right: 15px;
  font-weight: bold;
}

button, .upload-label {
  background-color: #007BFF;
  color: #ffffff;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  margin-left: 12px;
  cursor: pointer;
  font-size: 1em;
  display: flex;
  align-items: center;
}

/* Open Camera Button - Blue */
#open-camera-btn {
  background-color: #007BFF;
  color: #ffffff;
}

#open-camera-btn:hover {
  background-color: #0056B3;
}

/* Take Picture Button - Red */
#take-picture-btn {
  background-color: #D32F2F;
  color: #ffffff;
}

#take-picture-btn:hover {
  background-color: #B71C1C;
}

/* Upload Image Button - Blue */
.upload-label {
  background-color: #007BFF;
  color: #ffffff;
}

.upload-label:hover {
  background-color: #0056B3;
}

/* Target buttons with the class 'generate' */
button.generate {
  margin-top: 40px;
  background-color: #9400D3;
  color: #ffffff;
  border: none;
  padding: 15px 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1em;
  display: flex;
  align-items: center;
  font-weight: 600;
}

/* Additional styling for buttons with icons */
button.generate i {
  margin-right: 5px;
}

/* Hover effect for buttons with the class 'generate' */
button.generate:hover {
  background-color: #7B1FA2;
}

button.generate:disabled {
  background-color: #cccccc;
  color: #666666;
  cursor: not-allowed;
  opacity: 0.6;
}

button.generate:disabled:hover {
  background-color: #cccccc;
}

button i, .upload-label i {
  margin-right: 5px;
}

button:hover, .upload-label:hover {
  background-color: #0056b3;
}

#camera-feed, #uploaded-image {
  max-width: 80%;
  max-height: 300px;
  margin-top: 24px; /* slightly more space from controls */
  border-radius: 5px;
  display: none;
  border: 2px solid #007BFF;
}

.fade-in { animation: fadeIn .8s ease-out; }
.fade-out { animation: fadeOut .7s ease-in forwards; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fadeOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(10px) scale(.98); }
}

.pulse { animation: pulse .6s ease-in-out; }
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.pop-bounce { animation: popBounce .6s cubic-bezier(.2,.7,.3,1.2); }
.pop-out { animation: popOut .5s cubic-bezier(.2,.7,.3,1.2) forwards; }
@keyframes popBounce {
  0% { transform: scale(.90); opacity: 0; }
  60% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes popOut {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(.9); opacity: 0; }
}

/* Container for code box and encouragement side by side */
.code-and-encouragement-container {
  position: relative;
  width: 100%;
  max-width: 1400px;
  margin: 40px auto 0 auto; /* Add top margin to move both popups down */
  min-height: 500px; /* Ensure container has proper height for vertical centering */
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* Ensure both cards start at exactly the same vertical position */
#code-box {
  margin-top: 32px;
}

.inline-encouragement {
  margin-top: 20px;
}

#code-box {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 85%;
  max-width: 900px;
  background-color: #ffffff;
  padding: 0;
  border-radius: 16px;
  text-align: left;
  border: 3px solid #007BFF;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  transition: transform 0.6s cubic-bezier(.25, .46, .45, .94), width 0.6s cubic-bezier(.25, .46, .45, .94), max-width 0.6s cubic-bezier(.25, .46, .45, .94);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform-origin: center;
  z-index: 10;
}

/* When encouragement is shown, code box moves left */
#code-box.with-encouragement {
  width: 45%;
  max-width: 700px;
  transform: translateX(-95%);
}

pre {
  background-color: #f8f8f8;
  color: #333333;
  padding: 15px;
  border-radius: 8px;
  overflow-x: auto;
  border: 1px solid #dddddd;
  white-space: pre-wrap; /* Allow code to wrap */
  word-wrap: break-word; /* Ensure words break correctly */
  margin: 0;
}

/* More compact pre element for code box */
#code-box pre {
  padding: 12px;
  font-size: 0.9em;
  line-height: 1.4;
}

pre code {
  font-size: 1em;
  color: #333333 !important;
}

/* Force all code text to be black, overriding syntax highlighting */
#content, #content * {
  color: #333333 !important;
}

.button-group {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px; /* extra space from code */
}

/* More compact button group for code box */
#code-box .button-group {
  margin-top: 12px;
}

#code-box .button-group button {
  padding: 8px 16px;
  font-size: 0.9em;
}

/* Style encouragement button to match code box buttons but in green */
#inline-encouragement-card .modal-actions {
  justify-content: flex-end;
  margin-top: auto; /* Push button to bottom */
  padding-top: 12px;
}

#inline-encouragement-card .modal-actions .secondary {
  background-color: #4CAF50;
  color: #ffffff;
  border: none;
  padding: 8px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.9em;
  display: flex;
  align-items: center;
  margin-left: 0;
  transition: background-color 0.3s ease;
}

#inline-encouragement-card .modal-actions .secondary:hover {
  background-color: #007BFF;
}

#inline-encouragement-card .modal-actions .secondary i {
  margin-right: 5px;
}

.button-group button {
  margin-left: 10px;
  background-color: #007BFF;
  color: #ffffff;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1em;
  display: flex;
  align-items: center;
  transition: background-color 0.3s ease;
}

.button-group button i {
  margin-right: 5px;
}

/* Generated Code buttons - Purple hover */
#code-box .button-group button:hover {
  background-color: #9400D3;
}


@keyframes popInBounce {
  0% {
    opacity: 0;
    transform: scale(1.3) translateY(-20px);
  }
  50% {
    opacity: 1;
    transform: scale(1.1) translateY(-5px);
  }
  70% {
    transform: scale(0.95) translateY(2px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

#image-options .or-text {
  margin: 0 15px; /* Equal margin on both sides of "OR" */
  font-weight: bold;
}

@keyframes typing {
  from { width: 0; }
  to { width: 100%; }
}

@keyframes blink-caret {
  from, to { border-color: transparent; }
  50% { border-color: #000; }
}

#content.typing {
  overflow: hidden; /* Ensures the content is hidden until it's revealed by the animation */
  border-right: .15em solid #333; /* Adds a caret at the end */
  white-space: nowrap; /* Prevents wrapping */
  animation: typing 3.5s steps(10, end), blink-caret .75s step-end infinite;
  width: 0; /* Start with no width */
}

/* Loading dots animation for AI responses */
.loading-dots {
  display: inline-block;
  margin-left: 8px;
}

.loading-dots span {
  animation: loadingDots 1.4s infinite ease-in-out both;
  display: inline-block;
  font-size: 1.2em;
  color: #4CAF50; /* Green for chat */
}

/* Loading dots for code box - use default text color */
#content .loading-dots span {
  color: inherit; /* Use the same color as the text in #content */
}

/* When showing loading messages, use site font instead of monospace */
#content.loading,
#content:has(.loading-dots),
#content.loading .loading-dots {
  font-family: "Sour Gummy", sans-serif !important;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
.loading-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes loadingDots {
  0%, 80%, 100% { 
    transform: scale(0);
    opacity: 0.5;
  } 
  40% { 
    transform: scale(1);
    opacity: 1;
  }
}

/* Streaming character animation - characters bounce in sequentially */
.streaming-char {
  display: inline-block;
  animation: streamChar 0.5s ease-out forwards;
  opacity: 0;
  transform: translateY(-8px) scale(0.7);
}

@keyframes streamChar {
  0% {
    opacity: 0;
    transform: translateY(-8px) scale(0.7);
  }
  50% {
    transform: translateY(2px) scale(1.1);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Ensure loading text uses site font, not monospace */
#content.loading .streaming-char {
  font-family: "Sour Gummy", sans-serif !important;
}

/* Apply Sour Gummy font to specific elements, excluding icons */
h1, h2, h3, h4, h5, h6, p, span, div, button, input, label, .modal-body, .modal-actions, .button-group {
  font-family: "Sour Gummy", sans-serif !important;
  font-optical-sizing: auto;
  font-variation-settings: "wdth" 100;
}

/* Ensure icons keep their Font Awesome fonts */
i, .fas, .fa, .fa-solid, .fa-brands, .fa-regular, [class*="fa-"], [class*="fas"], [class*="far"], [class*="fab"] {
  font-family: "Font Awesome 6 Free", "Font Awesome 6 Pro", "Font Awesome 6 Brands" !important;
}

/* Code elements should use monospace font for readability */
.hljs, .hljs *, pre code, #content, #content *, pre, code {
  font-family: "Courier New", "Monaco", "Menlo", "Ubuntu Mono", monospace !important;
}

/* ==========================
   Left Chat Drawer (Mockup)
   ========================== */
.chat-drawer {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 420px;
  max-width: 90vw;
  z-index: 1100;
  display: flex;
  align-items: stretch;
  pointer-events: none; /* container doesn't capture clicks, inner card/tab will */
}

.chat-drawer.collapsed .chat-drawer-card {
  transform: translateX(-100%);
  box-shadow: none;
}


.chat-drawer .chat-drawer-card {
  pointer-events: auto;
  background: #ffffff;
  border: 3px solid #007BFF;
  border-radius: 16px;
  height: calc(100vh - 40px);
  margin: 20px 0 20px 16px;
  width: 380px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 40px rgba(0,0,0,0.25);
  overflow: hidden;
  transition: transform 420ms cubic-bezier(.2, .7, .3, 1.2), box-shadow 320ms ease;
  position: relative; /* Enable relative positioning for the tab */
}

.chat-drawer-tab {
  pointer-events: auto;
  position: absolute;
  top: 140px;
  left: 3px;
  background: #007BFF;
  color: #fff;
  border: none;
  width: 44px;
  height: 120px;
  border-top-right-radius: 12px;
  border-bottom-right-radius: 12px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0,0,0,0.25);
  z-index: 1101;
  transition: left 420ms cubic-bezier(.2, .7, .3, 1.2);
}

.chat-drawer:not(.collapsed) .chat-drawer-tab {
  left: 388px; /* position at the right edge of the card, no gap (16px margin + 380px width - 44px tab width) */
}

.chat-drawer-tab i { font-size: 18px; }
.chat-drawer-tab .tab-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.chat-header {
  position: relative;
  height: 72px;
  background: linear-gradient(135deg, #007BFF, #0056B3);
  display: flex;
  align-items: center;
  padding: 0 16px 0 18px;
  gap: 12px;
}

.chat-title {
  color: #fff;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

/* New Chat button - positioned to the left of close button with proper spacing */
.new-chat-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 60px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  height: 32px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  padding: 0 12px;
  margin: 0;
  line-height: 1;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.new-chat-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-50%) scale(1.02);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.new-chat-btn:active {
  transform: translateY(-50%) scale(0.98);
}

.new-chat-btn i {
  display: block;
  margin: 0;
  padding: 0;
  line-height: 1;
  font-size: 12px;
}

.new-chat-btn span {
  display: block;
  margin: 0;
  padding: 0;
  line-height: 1;
}

/* Animation for clearing chat messages */
@keyframes fadeOutUp {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-msg.fade-out {
  animation: fadeOutUp 0.3s ease forwards;
}

.chat-msg.fade-in {
  animation: fadeInDown 0.4s ease;
}

.chat-messages {
  flex: 1;
  padding: 16px;
  background: #f7faff;
  overflow-y: auto;
}

.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}

.chat-msg .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #ffffff;
  border: 2px solid #007BFF22;
  color: #007BFF;
}

.chat-msg.ai .bubble {
  background: #ffffff;
  color: #333;
  border: 1px solid #E3F0FF;
}

.chat-msg.user {
  justify-content: flex-end;
}

.chat-msg.user .bubble {
  background: #007BFF;
  color: #fff;
  border: 1px solid #0056B3;
}

/* Quick-start options mimic user messages but are clickable */
.bubble.chat-option {
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.2s ease;
}
.bubble.chat-option:hover {
  background-color: #0056B3;
}
.bubble.chat-option:active {
  transform: translateY(1px) scale(0.995);
}

/* Grouped option bubbles inside one user message */
.options-bubbles {
  display: inline-flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end; /* keep bubbles hugging the right like user messages */
  flex: 0 0 auto; /* prevent stretching across the row */
  max-width: 85%; /* allow wider grouped options */
}

/* Let option bubbles use the container's wider max width */
.options-bubbles .bubble {
  max-width: 100%;
}

.bubble {
  max-width: 70%;
  padding: 10px 12px;
  border-radius: 12px;
  line-height: 1.3;
  box-shadow: 0 4px 10px rgba(0,0,0,0.06);
  overflow-wrap: break-word;    /* Break long words */
  word-break: break-word;       /* Fallback for word breaking */
  overflow: hidden;             /* Prevent overflow */
}

.chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #E8EEF7;
  background: #ffffff;
}

.chat-input input[type="text"] {
  flex: 1;
  height: 40px;
  border-radius: 10px;
  border: 1px solid #cfe2ff;
  padding: 0 12px;
  font-size: 14px;
}

.chat-input .send {
  background: #9400D3;
  color: #fff;
  border: none;
  height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.chat-input .send:hover { background: #7B1FA2; }

/* Disabled state for chat input when button options are shown */
.chat-input input[type="text"]:disabled {
  background: #f5f5f5;
  color: #999;
  cursor: not-allowed;
  border-color: #ddd;
}

.chat-input .send:disabled {
  background: #ccc;
  cursor: not-allowed;
  opacity: 0.6;
}

.chat-input .send:disabled:hover {
  background: #ccc;
}

/* Block Learning System Styles - Uses existing chat option styling */
.block-learning-category-options .options-bubbles {
    max-width: 95%; /* Make category options wider than default 85% */
    align-items: flex-end !important; /* Force right alignment */
}

.block-learning-category-options .bubble {
    min-width: 120px; /* Ensure buttons have minimum width */
    text-align: center; /* Center text within the wider buttons */
}

/* Ensure user messages in block learning are right-aligned */
.block-learning-category-options {
    justify-content: flex-end !important;
    display: flex !important;
    align-items: flex-end !important;
}

/* Streaming animation for block learning responses */
.streaming-response {
    position: relative;
}

/* Removed cursor to prevent extra spacing issues */

/* Enhanced animations for block learning buttons */
.bubble.chat-option {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bubble.chat-option:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.bubble.chat-option:active {
    transform: translateY(0) scale(0.98);
    transition: all 0.1s ease;
}

/* Selected/stagnant state for chat option buttons after being clicked */
.bubble.chat-option.selected {
    cursor: default !important;
    pointer-events: none !important;
    transform: none !important;
    box-shadow: none !important;
}

.bubble.chat-option.selected:hover {
    transform: none !important;
    box-shadow: none !important;
}

/* Code in chat messages */
.chat-msg .bubble pre {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 8px;
    margin: 8px 0;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    white-space: pre-wrap;       /* Wrap while preserving whitespace */
    word-break: break-all;       /* Break words at any character */
    overflow-wrap: break-word;   /* Additional fallback for word breaking */
    overflow-x: hidden;          /* Prevent horizontal scroll */
}

.chat-msg .bubble pre code {
    background: transparent;
    padding: 0;
    color: #333;
    white-space: pre-wrap;       /* Inherit wrapping behavior */
    word-break: break-all;       /* Break words at any character */
}

/* Inline code styling */
.chat-msg .bubble code.inline-code,
.chat-msg .bubble code:not(pre code) {
    background: #e8e8e8;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #c7254e;
}

.chat-msg .bubble strong {
    font-weight: bold;
    color: #333;
}

.chat-msg .bubble em {
    font-style: italic;
}

.chat-msg .bubble h1 {
    font-size: 18px;
    font-weight: bold;
    margin: 8px 0 4px 0;
    color: #333;
}

.chat-msg .bubble h2 {
    font-size: 16px;
    font-weight: bold;
    margin: 6px 0 3px 0;
    color: #333;
}

/* Small screens: slightly narrower drawer */
@media (max-width: 480px) {
  .chat-drawer .chat-drawer-card { width: 320px; }
}

/* Save Chat Log Button */
#save-chat-log-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #007BFF;
  color: white;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
  transition: all 0.3s ease;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "Sour Gummy", sans-serif;
}

#save-chat-log-btn:hover {
  background: #0056b3;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4);
}

#save-chat-log-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
}

#save-chat-log-btn i {
  font-size: 16px;
}

#save-chat-log-btn span {
  font-size: 14px;
}

/* Hide text on very small screens */
@media (max-width: 480px) {
  #save-chat-log-btn span {
    display: none;
  }
  
  #save-chat-log-btn {
    padding: 12px;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    justify-content: center;
  }
}


/* ==========================================================
   Kid-friendly 3-step layout (photo -> read -> send)
   ========================================================== */
:root {
  --tmc-blue: #1E6FFF;
  --tmc-blue-dark: #1556c7;
  --tmc-purple: #8A3FFC;
  --tmc-green: #1FA463;
  --tmc-green-dark: #178651;
  --tmc-sun: #FFC93C;
  --tmc-bg: #F4F8FF;
  --tmc-card: #ffffff;
  --tmc-ink: #24324a;
  --tmc-muted: #5b6b85;
}

body {
  background: var(--tmc-bg);
  color: var(--tmc-ink);
  justify-content: flex-start;
  padding: 28px 16px 60px;
}

.page-header { text-align: center; margin-bottom: 8px; max-width: 760px; }
.page-header h1 {
  margin: 0 0 6px;
  font-size: 2.4em;
  color: var(--tmc-blue);
  letter-spacing: 0.5px;
}
.page-header .subtitle { margin: 0; font-size: 1.15em; color: var(--tmc-muted); }

.step-card {
  width: 100%;
  max-width: 900px;
  box-sizing: border-box;
  background: var(--tmc-card);
  border-radius: 22px;
  border: 3px solid #dbe6ff;
  box-shadow: 0 6px 0 #dbe6ff;
  padding: 22px 26px;
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.step-title {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.35em;
  font-weight: 700;
  margin-bottom: 16px;
}
.step-num {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--tmc-sun);
  color: var(--tmc-ink);
  font-size: 1.1em;
  font-weight: 800;
  flex: 0 0 auto;
}

/* Step 1 */
#image-options { margin-bottom: 8px; flex-wrap: wrap; }
#image-options .or-text { color: var(--tmc-muted); font-weight: 600; margin: 0; }
#open-camera-btn, .upload-label {
  font-size: 1.15em;
  padding: 14px 26px;
  border-radius: 14px;
  margin-left: 0;
  box-shadow: 0 4px 0 var(--tmc-blue-dark);
  background-color: var(--tmc-blue);
}
#open-camera-btn:hover, .upload-label:hover { background-color: var(--tmc-blue-dark); }
.tip { color: var(--tmc-muted); font-size: 0.95em; margin: 10px 0 0; text-align: center; }
.tip i { color: var(--tmc-sun); margin-right: 4px; }
#uploaded-image { border-radius: 14px; margin-top: 14px; }

/* Step 2 */
#step-read button.generate {
  margin: 0;
  font-size: 1.35em;
  padding: 16px 36px;
  border-radius: 16px;
  background-color: var(--tmc-purple);
  box-shadow: 0 5px 0 #6526c4;
}
#step-read button.generate:hover { background-color: #7430e0; }
#step-read button.generate:disabled { box-shadow: none; }
.program-status-line { min-height: 1.6em; margin: 14px 0 0; font-size: 1.1em; color: var(--tmc-ink); text-align: center; }
#program-status .loading-dots span { color: var(--tmc-purple); }

/* Step 3 (overrides the old floating code box) */
#code-box {
  position: static;
  transform: none;
  left: auto;
  width: 100%;
  max-width: 900px;
  border: 3px solid #dbe6ff;
  box-shadow: 0 6px 0 #dbe6ff;
  padding: 22px 26px;
  overflow: visible;
  align-items: stretch;
  z-index: auto;
}
.makecode-wrap {
  position: relative;
  width: 100%;
  height: 520px;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid #dbe6ff;
  background: #f7f9fc;
}
#makecode-editor { width: 100%; height: 100%; border: 0; display: block; }
.program-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #f7f9fc;
  color: var(--tmc-muted);
  font-size: 1.15em;
  text-align: center;
  padding: 20px;
}
.program-placeholder i { font-size: 2.6em; color: #b9c9ea; margin-bottom: 8px; }
.program-placeholder.hidden { display: none; }

.send-status { min-height: 1.4em; margin: 12px 0 0; font-size: 1.05em; text-align: center; color: var(--tmc-muted); }
.send-status.ok { color: var(--tmc-green-dark); }
.send-status.error { color: #c62828; }

#code-box .send-buttons { justify-content: center; gap: 14px; margin-top: 12px; flex-wrap: wrap; }
#code-box .send-buttons button { margin-left: 0; font-size: 1.2em; padding: 14px 28px; border-radius: 14px; }
#code-box .send-buttons .send-primary { background-color: var(--tmc-green); box-shadow: 0 4px 0 var(--tmc-green-dark); }
#code-box .send-buttons .send-primary:hover { background-color: var(--tmc-green-dark); }
#code-box .send-buttons .send-secondary { background-color: #ffffff; color: var(--tmc-blue); border: 2px solid var(--tmc-blue); }
#code-box .send-buttons .send-secondary:hover { background-color: #eef4ff; }
#code-box .send-buttons button:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

.peek-code { margin-top: 18px; }
.peek-code summary { cursor: pointer; color: var(--tmc-muted); font-size: 1em; }
.peek-code summary i { margin-right: 6px; }
.peek-code pre { margin-top: 10px; }

@media (max-width: 640px) {
  .page-header h1 { font-size: 1.8em; }
  .step-card, #code-box { padding: 18px 16px; }
  .makecode-wrap { height: 420px; }
}

/* Waiting state for "Read My Blocks!": readable, clearly not ready yet */
#step-read button.generate:disabled,
#step-read button.generate:disabled:hover {
  background-color: #EFE7FF;
  color: #6A44C9;
  border: 2px dashed #C3A6F8;
  box-shadow: none;
  opacity: 1;
  cursor: not-allowed;
}

/* Make full-width buttons center their label */
button, .upload-label { justify-content: center; box-sizing: border-box; }

/* Hide the collapsed chat card fully (it peeked out on narrow screens) */
.chat-drawer.collapsed .chat-drawer-card { transform: translateX(calc(-100% - 24px)); }

/* ---------- Phones ---------- */
@media (max-width: 640px) {
  body { padding: 18px 14px 90px; }
  .page-header h1 { font-size: 1.75em; }
  .page-header .subtitle { font-size: 1em; line-height: 1.4; }

  .step-card, #code-box { padding: 16px 14px; margin-top: 16px; border-radius: 18px; }
  .step-title { font-size: 1.08em; gap: 10px; margin-bottom: 12px; line-height: 1.25; }
  .step-num { width: 32px; height: 32px; font-size: 1em; }

  #image-options { flex-direction: column; align-items: stretch; width: 100%; gap: 8px; }
  #image-options .or-text { text-align: center; font-size: .95em; }
  #open-camera-btn, .upload-label { width: 100%; font-size: 1.1em; padding: 14px 16px; }
  .camera-stack { width: 100%; }
  #camera-feed, #uploaded-image { max-width: 100%; max-height: 50vh; }
  #take-picture-btn { width: 100%; }
  .tip { font-size: .9em; }

  #step-read button.generate { width: 100%; font-size: 1.2em; padding: 15px 16px; }
  .program-status-line { font-size: 1em; }

  .makecode-wrap { height: 62vh; min-height: 360px; border-radius: 12px; }
  .send-status { font-size: .95em; }
  #code-box .send-buttons { flex-direction: column; gap: 10px; }
  #code-box .send-buttons button { width: 100%; font-size: 1.1em; padding: 14px 16px; }
  .peek-code summary { font-size: .95em; }
  #code-box pre { font-size: .8em; }

  /* Chat: round floating button bottom-left; panel nearly full width when open */
  .chat-drawer { width: 100vw; max-width: 100vw; }
  .chat-drawer .chat-drawer-card { width: calc(100vw - 24px); margin: 12px; height: calc(100dvh - 24px); }
  .chat-drawer-tab {
    top: auto; bottom: 18px; left: 14px;
    width: 58px; height: 58px; border-radius: 50%;
    position: fixed;
  }
  .chat-drawer-tab .tab-label { display: none; }
  .chat-drawer-tab i { font-size: 22px; }
  .chat-drawer:not(.collapsed) .chat-drawer-tab { display: none; }
}
