:root {
  --background-color: #121212;
  --surface-color: #1e1e1e;
  --primary-color: #bb86fc;
  --primary-variant-color: #3700b3;
  --secondary-color: #03dac6;
  --text-color: #ffffff;
  --border-color: #333333;
}

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

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--background-color);
  color: var(--text-color);
  padding: 2rem;
}

body.viewport-lock {
    /* Robust scroll locking for mobile */
    position: fixed;
    width: 100%;
    overflow: hidden;
}

body.no-scroll {
  /* This class is now mostly for semantic purposes, as main scrolling is disabled */
}

#root {
  width: 100%;
  max-width: 1200px;
  min-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.container {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  width: 100%;
  flex: 1;
  min-height: 0;
}

header {
  text-align: center;
  flex-shrink: 0;
}

header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary-color);
}

header p {
  font-size: 1.1rem;
  color: var(--text-color);
  opacity: 0.8;
  margin-top: 0.5rem;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

main {
  width: 100%;
  max-width: 700px;
  margin: 0 auto;
  background-color: var(--surface-color);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  flex-shrink: 0; /* Prevents main from growing unnecessarily */
}

.upload-zone {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  border: 2px dashed var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  text-align: center;
  padding: 1rem;
  min-height: 300px; /* Ensure a decent size for the dropzone */
}

.upload-zone.drag-over {
  background-color: var(--primary-variant-color);
  border-color: var(--primary-color);
}

.upload-zone:hover {
  background-color: #2a2a2a;
  border-color: var(--primary-color);
}

.upload-zone svg {
  width: 60px;
  height: 60px;
  color: var(--primary-color);
  margin-bottom: 1rem;
}

.upload-zone p {
  font-size: 1.2rem;
  font-weight: 600;
}

.upload-zone span {
  font-size: 0.9rem;
  opacity: 0.7;
  margin-top: 0.5rem;
}

.meme-creator-container {
  display: flex;
  flex-direction: column;
}

.meme-preview-area {
  display: flex;
  align-items: center;
  justify-content: flex-start; /* Aligns tall images to the top */
  flex-direction: column;
  padding: 1rem;
}

.meme-display-area {
  position: relative;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 8px;
  background-color: #121212;
  flex-shrink: 0;
}

.image-content-wrapper {
  position: relative;
  line-height: 0; /* remove bottom space from image */
}

.meme-display-area img {
    display: block;
    max-width: 100%; /* Use max-width to be responsive */
    height: auto;
    max-height: 75vh;
    object-fit: contain;
    pointer-events: none;
    margin: 0 auto; /* Center image if container is wider */
}


.meme-text {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 90%; /* Bounded width relative to wrapper */
  word-break: break-word; /* Force wrapping */
  padding: 0.2rem 0;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  z-index: 10;
  touch-action: none;
}


@media (max-width: 1023px) {
  body {
    padding: 1rem 0 0 0;
    overflow-x: hidden; /* Prevent horizontal scroll */
  }
  .container {
    gap: 1rem;
  }
  header h1 {
    font-size: 2rem;
  }
  header p {
    font-size: 1rem;
  }
  main {
    border-left: none;
    border-right: none;
    width: 100%;
    overflow-x: hidden; /* Prevent horizontal scroll */
  }

  .desktop-controls-container {
      width: 100%;
  }
  
  .meme-display-area img {
      max-height: none; /* No height limit on mobile */
  }

  /* This class activates the fullscreen, interactive layout for customization on mobile */
  main.is-customizing {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 500;
    border-radius: 0;
    margin: 0;
    overflow-x: hidden;
  }
  
  main.is-customizing .meme-creator-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  
  main.is-customizing .meme-preview-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }
}

@media (min-width: 1024px) {
    /* This class activates the two-column layout on desktop AFTER an image is uploaded */
    main.has-content {
        display: flex;
        flex-direction: row;
        gap: 0;
        max-width: 1200px;
        align-items: flex-start;
        padding: 0;
        flex: 1; /* Allow main to grow and fill vertical space */
        flex-shrink: 1;
    }

    main.has-content .meme-creator-container {
        flex: 1;
        min-width: 0;
    }
    main.has-content .desktop-controls-container {
        width: 380px;
        flex-shrink: 0;
        position: sticky;
        top: 2rem;
        height: calc(100vh - 4rem);
        overflow-y: auto;
    }
    main.has-content .controls-panel {
        border-top: none;
        border-left: 1px solid var(--border-color);
        height: 100%;
    }
}


.placeholder-container {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  height: 100%;
  width: 100%;
  text-align: center;
  background-color: rgba(0,0,0,0.5);
  border-radius: 8px;
  padding: 1rem;
}

.spinner {
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top: 4px solid var(--secondary-color);
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

.loading-message {
  font-weight: 600;
  color: var(--text-color);
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.controls-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.5rem;
  background-color: #181818;
  flex-shrink: 0;
  position: relative; /* Ensure stacking context */
  z-index: 20;      /* Ensure it's above meme text */
  border-radius: 12px; /* For standalone appearance */
}

.prompt-container,
.creativity-slider-container,
.language-selector-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-radius: 8px;
  padding: 0.5rem;
}

.prompt-container label {
  font-weight: 600;
  opacity: 0.9;
  text-align: left;
}

.prompt-container textarea {
  width: 100%;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--background-color);
  color: var(--text-color);
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  resize: vertical;
  min-height: 60px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.prompt-container textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(187, 134, 252, 0.25);
}

.creativity-slider-container label {
  font-weight: 600;
  opacity: 0.9;
  text-align: left;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: var(--border-color);
  border-radius: 5px;
  outline: none;
  opacity: 0.7;
  transition: opacity .2s;
  cursor: pointer;
}

input[type="range"]:hover {
  opacity: 1;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--primary-color);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--surface-color);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--primary-color);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--surface-color);
}

input[type="range"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  opacity: 0.7;
  padding: 0 5px;
}

.language-selector-container label, .font-selector label {
  font-weight: 600;
  opacity: 0.9;
  text-align: left;
}

select {
  width: 100%;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--background-color);
  color: var(--text-color);
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23BB86FC%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 0.65em auto;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(187, 134, 252, 0.25);
}

.resizable-panel {
  flex-shrink: 0;
  width: 100%;
  background-color: var(--surface-color);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -5px 20px rgba(0,0,0,0.3);
  z-index: 1000;
  transition: height 0.3s ease-out;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-header {
    padding: 24px 0;
    cursor: ns-resize;
    flex-shrink: 0;
}

.grab-handle {
  width: 40px;
  height: 5px;
  background-color: var(--border-color);
  border-radius: 2.5px;
  margin: 0 auto; /* Center handle within header */
}

.resizable-panel-content {
  padding: 0 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow-y: auto;
  flex: 1; /* Allow content to take available space */
}

.controls-panel h3,
.resizable-panel-content h3 {
    text-align: center;
    font-size: 1.3rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.custom-control-group {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.color-picker {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.color-picker label {
    font-weight: 600;
}

.colors {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.colors button, .colors .custom-color-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    padding: 0;
    display: inline-block;
}

.colors button:hover, .colors .custom-color-btn:hover {
    transform: scale(1.1);
}

.colors button.active {
    border-color: var(--secondary-color);
    transform: scale(1.15);
    box-shadow: 0 0 8px var(--secondary-color);
}

.custom-color-btn {
  background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
}

.font-selector {
    flex: 1;
    min-width: 150px;
}

.text-size-slider {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.text-size-slider label {
    font-weight: 600;
}


.controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  width: 100%;
  margin-top: 1rem;
}

.button {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
  background-color: var(--primary-color);
  color: #000;
}

.button:hover:not(:disabled) {
  background-color: var(--secondary-color);
  transform: translateY(-2px);
}

.button:disabled {
  background-color: var(--border-color);
  color: #888;
  cursor: not-allowed;
}

.button.secondary {
  background-color: var(--surface-color);
  color: var(--primary-color);
  border: 2px solid var(--primary-color);
}

.button.secondary:hover:not(:disabled) {
  background-color: var(--primary-variant-color);
  color: var(--text-color);
}

.error-message {
  color: #ff8a80;
  background-color: rgba(255, 0, 0, 0.1);
  border: 1px solid #ff8a80;
  padding: 1rem;
  border-radius: 8px;
  text-align: center;
  margin: 1rem;
  width: calc(100% - 2rem);
}

.diagnostic-info {
  font-family: monospace;
  font-size: 0.8rem;
  color: #aaa;
  text-align: center;
  margin: 0 1rem 1rem 1rem;
  padding: 0.5rem;
  background-color: #2a2a2a;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  word-break: break-all;
}

.meme-gallery {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  flex-shrink: 0;
}

.meme-gallery h2 {
  text-align: center;
  font-size: 1.8rem;
  color: var(--primary-color);
  margin-bottom: 1.5rem;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.5rem;
  align-items: start;
}

.gallery-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.gallery-item img {
  width: 100%;
  height: auto;
  display: block;
}

.gallery-item-actions {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    background-color: rgba(0,0,0,0.6);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.gallery-item:hover .gallery-item-actions,
.gallery-item:focus-within .gallery-item-actions {
    opacity: 1;
}

.gallery-item-actions button {
    background-color: rgba(30, 30, 30, 0.8);
    border: 1px solid var(--border-color);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.2s;
}

.gallery-item-actions button:hover {
    background-color: var(--primary-color);
    color: black;
    transform: scale(1.1);
}

.gallery-item-actions button svg {
    width: 24px;
    height: 24px;
}


@keyframes highlight-pulse {
  0% { box-shadow: 0 0 0 2px rgba(187, 134, 252, 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(187, 134, 252, 0); }
  100% { box-shadow: 0 0 0 0 rgba(187, 134, 252, 0); }
}

.prompt-container.highlight-pulse,
.creativity-slider-container.highlight-pulse,
.language-selector-container.highlight-pulse {
  animation: highlight-pulse 1.5s 1;
}

@keyframes highlight-header-pulse {
  0%, 100% {
    color: var(--primary-color);
    transform: scale(1);
  }
  50% {
    color: var(--secondary-color);
    transform: scale(1.05);
  }
}

.controls-panel h3.highlight-pulse-header,
.resizable-panel-content h3.highlight-pulse-header {
  animation: highlight-header-pulse 1s 3;
}


.remove-image-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 15;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
}

.remove-image-btn:hover {
  background-color: rgba(255, 59, 48, 0.8);
  transform: scale(1.1);
}

.remove-image-btn svg {
  width: 20px;
  height: 20px;
}

/* --- Toast Notification Styles --- */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none; /* Allow clicks to pass through the container */
}

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

.toast-notification {
  pointer-events: all; /* Re-enable clicks on the toast itself */
  background-color: #2a2a2a;
  color: var(--text-color);
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: max-content;
  max-width: 90vw;
  animation: toast-in 0.3s ease-out forwards;
  border: 1px solid var(--border-color);
}

.toast-notification p {
  font-weight: 500;
}

.toast-actions {
  display: flex;
  gap: 0.5rem;
}

.toast-actions button {
  background: none;
  border: none;
  color: var(--secondary-color);
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.toast-actions button:hover {
  background-color: rgba(3, 218, 198, 0.1);
}