/* ============================
   GLOBAL SAFETY (prevents mobile overflow)
   ============================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden; /* safety */
}

/* ============================
   Page container
   ============================ */
main.meme-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
  width: 100%;
  min-width: 0;
}

/* Desktop: 2-column layout */
.meme-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 1.5rem;
  align-items: flex-start;

  width: 100%;
  min-width: 0; /* IMPORTANT */
}

/* ============================
   Canvas area
   ============================ */
.meme-canvas-wrap {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  padding: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);

  width: 100%;
  min-width: 0; /* IMPORTANT */
}

.meme-canvas-inner {
  background: #111;
  border-radius: 8px;
  padding: 8px;

  display: flex;
  align-items: center;
  justify-content: center;

  min-height: 260px;

  width: 100%;
  min-width: 0; /* IMPORTANT */
  overflow: hidden; /* prevents canvas bleed */
}

/* ✅ Force responsive canvas sizing (visual) */
#memeCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  border-radius: 6px;
  background: #000;
}

.meme-note {
  font-size: 0.8rem;
  color: #666;
  margin-top: 6px;
}

/* ============================
   Controls shell (right column)
   ============================ */
.meme-controls-shell {
  align-self: stretch;
  width: 100%;
  min-width: 0; /* IMPORTANT */
}

.meme-controls-details {
  border: none;
  padding: 0;
}

/* On desktop we hide the summary bar and just show the panel */
.meme-controls-summary {
  display: none;
}

.meme-controls {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  padding: 12px 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  font-size: 0.9rem;

  width: 100%;
  min-width: 0;
}

.meme-controls h2 {
  margin-top: 0;
  margin-bottom: 0.5rem;
  font-size: 1.15rem;
  color: #d8143c;
}

.meme-controls-group {
  margin-bottom: 0.75rem;
}

.meme-controls-group label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.meme-controls-group input[type="text"],
.meme-controls-group select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  font-size: 0.9rem;
}

.meme-controls-inline {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.meme-controls-inline label {
  margin-bottom: 0;
  font-weight: 500;
}

.meme-range {
  width: 100%;
}

.meme-color-input {
  width: 42px;
  height: 26px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid #d1d5db;
}

.meme-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.meme-preset-btn {
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.meme-preset-btn:hover {
  background: #fff;
  border-color: #d8143c33;
}

.meme-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.meme-btn-primary,
.meme-btn-secondary {
  border-radius: 999px;
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.meme-btn-primary {
  background: #d8143c;
  color: #fff;
  border-color: #d8143c;
}

.meme-btn-primary:hover {
  background: #b10e32;
  border-color: #b10e32;
}

.meme-btn-secondary {
  background: #fff;
  color: #111;
  border-color: #d1d5db;
}

.meme-btn-secondary:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

/* Extra actions row under image (mobile only by default) */
.meme-primary-actions {
  display: none; /* shown on mobile */
  margin-top: 0.75rem;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.meme-source-pill {
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

.meme-source-pill a {
  color: inherit;
  text-decoration: underline;
}

.meme-help {
  font-size: 0.8rem;
  color: #555;
  margin-top: 0.4rem;
}

/* Simple ad spot under canvas */
.meme-ad {
  margin-top: 0.75rem;
  text-align: center;
}

/* ============================
   Copy overlay
   ============================ */
.meme-copy-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.meme-copy-inner {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  text-align: center;
  color: #f9fafb;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.meme-copy-instructions {
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.meme-copy-inner img {
  max-width: 100%;
  max-height: 75vh;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

.meme-copy-close {
  position: absolute;
  top: -0.5rem;
  right: -0.5rem;
  border: none;
  background: #111827;
  color: #f9fafb;
  border-radius: 999px;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  cursor: pointer;
}

.meme-copy-overlay[hidden] {
  display: none !important;
}

body.no-scroll {
  overflow: hidden;
}

/* ============================
   Suggestions (grid) — legacy (safe)
   ============================ */
.meme-suggestions {
  margin-top: 1rem;
  width: 100%;
  min-width: 0;
}

.meme-suggestions-title {
  font-size: 0.95rem;
  margin: 0 0 0.25rem;
}

.meme-suggestions-note {
  font-size: 0.8rem;
  color: #6b7280;
  margin: 0 0 0.5rem;
}

.meme-suggestions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}

.meme-suggestion-thumb {
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

.meme-suggestion-thumb img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  display: block;
}

.meme-suggestion-thumb:hover {
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}

/* ============================
   Suggestions row + Trending row (hot-row) — FIXED
   ============================ */

/* ✅ Key: clamp to viewport width (100vw) AND avoid padding overflow */
#homeTrendingRow.hot-row,
#memeSuggestionsRow.hot-row {
  display: flex;
  gap: 12px;

  width: 100%;
  max-width: 100vw;     /* clamp */
  min-width: 0;

  overflow-x: auto;
  overflow-y: hidden;

  padding: 6px 12px 10px; /* add real padding so cards don't touch edge */
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;

  /* ensure scroll container doesn't expand page */
  box-sizing: border-box;
}

/* make sure children don’t force container wider than itself */
#homeTrendingRow.hot-row > *,
#memeSuggestionsRow.hot-row > * {
  flex: 0 0 auto;
}

/* cards */
.mm-suggest-card {
  flex: 0 0 auto;
  width: 160px;
  max-width: 70vw; /* prevents huge cards on very small screens */
  scroll-snap-align: start;
}

.mm-suggest-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}

.mm-suggest-thumbbtn {
  border: 0;
  background: transparent;
  padding: 0;
  width: 100%;
  cursor: pointer;
}

.mm-suggest-meta {
  margin-top: 6px;
}

.mm-suggest-pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  opacity: .8;
}

/* ============================
   Mobile layout
   ============================ */
@media (max-width: 860px) {
  /* 1-column layout */
  .meme-layout {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  /* Controls shell comes first; canvas second */
  .meme-controls-shell { order: 1; }
  .meme-canvas-wrap { order: 2; padding: 0; }

  main.meme-wrap { padding: 0; }

  .meme-canvas-inner {
    min-height: 220px;
    padding: 0;          /* removes the “frame” on mobile */
    border-radius: 0;
  }

  #memeCanvas {
    width: 100% !important;
    height: auto !important;
    border-radius: 0;
  }

  .meme-note,
  .meme-note-secondary {
    text-align: center;
    font-size: 0.85rem;
  }

  /* Show the summary bar as a “filter” */
  .meme-controls-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;

    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    font-size: 0.95rem;
    font-weight: 600;
    color: #222;
    cursor: pointer;

    list-style: none;
  }

  .meme-controls-summary::-webkit-details-marker {
    display: none;
  }

  .meme-controls-summary::after {
    content: "▾";
    font-size: 0.9rem;
    margin-left: auto;
    transform-origin: center;
    transition: transform 0.2s ease;
  }

  .meme-controls-details[open] > .meme-controls-summary::after {
    transform: rotate(180deg);
  }

  /* Panel content when open */
  .meme-controls {
    margin-top: 0.6rem;
    padding: 0.9rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
  }

  /* Buttons under the image (mobile only) */
  .meme-primary-actions { display: flex; }

  /* Hide desktop actions on mobile */
  .meme-actions { display: none; }

  aside {
    padding: 0;
    padding-top: 0.5rem;
    padding-right: .5rem;
    padding-left: .2rem;
  }
}
