.thinking-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: var(--snow);
  z-index: 4000;
  display: none !important;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 12rem 1.5rem 8rem; /* Increased top padding to avoid top bar overlap */
  text-align: center;
  overflow-x: hidden;
  overflow-y: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.thinking-screen.visible {
  display: flex !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

.thinking-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 2rem;
}

.thinking-title {
  font-family: "Instrument Serif", serif;
  font-size: 3.5rem;
  line-height: 0.85;
  color: var(--text);
  margin-bottom: 1.5rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.thinking-title .italic {
  display: block;
  margin-top: 1.5rem;
}

.magical-instruction {
  width: 100%;
  max-width: 600px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1.5rem;
}

.magic-text {
  font-family: "Instrument Serif", serif;
  font-size: 2rem;
  line-height: 1.1;
  color: var(--text);
  font-weight: 400;
  text-align: center;
  opacity: 0.8;
}

.thinking-input-pill {
  width: 100% !important;
  max-width: 500px !important;
  background: #ffffff !important;
  border: 1px solid rgba(0, 0, 0, 0.05) !important;
  border-radius: 24px !important; /* Less rounded for textarea */
  padding: 1rem 8px 1rem 1.5rem !important; 
  display: flex !important;
  align-items: flex-end !important; /* Button at bottom right */
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02) !important;
  margin: 3rem 0 !important;
  gap: 10px;
  justify-content: space-between;
  position: relative;
}

.char-count {
  position: absolute;
  top: -25px;
  right: 1rem;
  font-size: 0.75rem;
  color: var(--sub);
  font-weight: 500;
  opacity: 0.6;
}

.thinking-input-pill textarea {
  flex: 1;
  border: none !important;
  background: transparent !important;
  font-size: 1.2rem !important;
  font-weight: 500 !important;
  text-align: left;
  min-height: 100px; /* Space for ~4 rows */
  padding: 0;
  resize: none;
  font-family: inherit;
  color: var(--text);
}

.thinking-input-pill textarea:focus {
  outline: none;
}

.start-mixing-btn-pill {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #000;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.start-mixing-btn-pill:hover {
  transform: scale(1.05);
  background: #222;
}

.start-mixing-btn-pill:active {
  transform: scale(0.95);
}

.start-mixing-btn-pill .material-symbols-rounded {
  font-size: 1.5rem;
}

.settings-toggle-pill {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  padding: 10px 20px;
  border-radius: 100px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
  z-index: 4500;
  margin-top: 2rem;
  margin-bottom: 2rem;
}

.settings-toggle-pill:hover {
  background: #f8f8f8;
  transform: translateY(-2px);
}

.settings-toggle-pill .material-symbols-rounded {
  font-size: 1.2rem;
}

.ingredients-overlay {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-w);
  max-height: 85vh; /* Limit height so it doesn't cover whole screen */
  background: #ffffff;
  padding: 0; /* Padding moved to scroll container */
  border-radius: 32px 32px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.1);
  z-index: 4600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.4s cubic-bezier(0.2, 1, 0.2, 1);
  transform: translateX(-50%) translateY(100%);
  display: none;
  overflow: hidden; /* Hide outer overflow */
}

.ingredients-scroll-container {
  width: 100%;
  height: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 4rem 2rem 3rem; /* Space for close button and bottom padding */
  -webkit-overflow-scrolling: touch;
}

.close-overlay-btn {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--snow);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: all 0.2s ease;
  z-index: 10; /* Ensure it stays above scroll content */
}

.close-overlay-btn:hover {
  background: #eeeeee;
  transform: scale(1.1);
}

.close-overlay-btn .material-symbols-rounded {
  font-size: 1.2rem;
}

.ingredients-overlay.visible {
  display: block;
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.ingredients-container {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  width: 100%;
}

.ingredient-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.ingredient-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--sub);
  opacity: 0.8;
}

@media (max-width: 768px) {
  .thinking-screen {
    padding: 8rem 1.5rem 6rem; /* Increased top padding for mobile top bar */
  }
  .thinking-title {
    font-size: 2.5rem;
  }
  .magic-text {
    font-size: 1.8rem;
  }
  .thinking-input-pill {
    margin: 2rem 0 !important;
  }
  .thinking-input-pill textarea {
    font-size: 1.1rem !important;
  }
  .start-mixing-btn-pill {
    width: 40px;
    height: 40px;
  }
}

/* Animations and Helpers */
.start-mixing-btn-pill.loading {
  pointer-events: none;
  background: #333;
}
.start-mixing-btn-pill.loading span { display: none; }
.start-mixing-btn-pill.loading::after {
  content: "";
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  display: block;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.writing-desc { font-size: 0.9rem; color: var(--sub); font-style: italic; text-align: center; }
.writing-text { font-size: 1.1rem; font-weight: 500; text-align: center; }

.thinking-error {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #ffffff;
  padding: 3rem 2rem;
  border-radius: 40px;
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.1);
  z-index: 5000;
}
.thinking-error.visible { display: flex; }
.error-icon-circle { width: 64px; height: 64px; background: #fff5f5; color: #ff4d4d; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-bottom: 1.5rem; }
.error-icon-circle span { font-size: 32px; }
.thinking-error h3 { font-size: 1.4rem; margin-bottom: 0.5rem; color: var(--text); }
.thinking-error p { color: var(--sub); margin-bottom: 2rem; }
.error-actions { display: flex; gap: 1rem; width: 100%; }
.retry-btn, .cancel-btn { flex: 1; padding: 1rem; border-radius: 100px; border: none; font-weight: 700; cursor: pointer; font-size: 0.95rem; transition: all 0.2s ease; }
.retry-btn { background: #000; color: #fff; }
.cancel-btn { background: var(--snow); color: var(--text); }

.thinking-input-pill input:disabled {
  opacity: 0.6;
  cursor: default;
}

.settings-toggle-pill.disabled {
  opacity: 0.5;
  pointer-events: none;
}
