/* Meme generator page. */
.mg { max-width: 1040px; margin: 0 auto 50px; padding: 0 16px; }
.mg h1 {
  font-family: 'Nunito', Arial, sans-serif; font-size: 32px; margin: 10px 0 6px;
}
.mg-lede { color: #555; margin: 0 0 22px; line-height: 1.55; max-width: 68ch; }

.mg-grid { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
@media (max-width: 820px) { .mg-grid { grid-template-columns: 1fr; } }

.mg-stage {
  background: #f4f4f4; border: 2px solid #000; border-radius: 10px;
  padding: 12px; text-align: center;
}
#mg-canvas {
  max-width: 100%; height: auto; display: block; margin: 0 auto;
  background: #fff; border-radius: 6px;
}
.mg-credit { font-size: 13px; color: #666; margin: 10px 0 0; }
.mg-status { font-size: 13px; color: #666; margin: 6px 0 0; min-height: 1.2em; }
.mg-status--error { color: #c0392b; }

.mg-controls { display: flex; flex-direction: column; gap: 6px; }
.mg-controls label { font-size: 13px; font-weight: 700; margin-top: 8px; }
.mg-controls input[type=text] {
  padding: 9px 10px; border: 1px solid #ccc; border-radius: 7px; font-size: 15px;
}
.mg-controls input[type=range] { width: 100%; }
.mg-check { display: flex; align-items: center; gap: 8px; font-weight: 400 !important; }
.mg-filelabel { margin-top: 14px !important; }
.mg-btn {
  margin-top: 16px; padding: 12px 16px; border: none; border-radius: 8px;
  background: linear-gradient(90deg, #D4FC79, #96E6A1);
  color: #000;
  font-family: 'Nunito', sans-serif; font-weight: 800; text-transform: uppercase;
  font-size: 15px; cursor: pointer; box-shadow: 3px 3px 0 rgba(0,0,0,.8);
}
.mg-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 5px 5px 0 rgba(0,0,0,.8); }
.mg-btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

.mg-starters-heading { font-size: 22px; margin: 34px 0 12px; }
.mg-starters { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.mg-starter { display: block; border: 2px solid #000; border-radius: 8px; overflow: hidden; }
.mg-starter img { width: 100%; height: 140px; object-fit: cover; display: block; }
.mg-starter:hover { transform: translateY(-2px); }

.mg-faq { margin-top: 40px; line-height: 1.7; }
.mg-faq h2 { font-size: 22px; margin: 0 0 10px; }
.mg-faq ol { margin: 0 0 14px 22px; }

/* The link that sends a meme detail page into the editor. */
.meme-remix {
  display: inline-block; margin: 14px 0 4px; padding: 10px 16px;
  background: linear-gradient(90deg, #A1C4FD, #C2E9FB); color: #000;
  font-family: 'Nunito', sans-serif; font-weight: 800; text-transform: uppercase;
  font-size: 14px; border-radius: 8px; text-decoration: none;
  box-shadow: 3px 3px 0 rgba(0,0,0,.8);
}
.meme-remix:hover { transform: translateY(-2px); box-shadow: 5px 5px 0 rgba(0,0,0,.8); text-decoration: none; }

.mg-controls select {
  padding: 8px 10px; border: 1px solid #ccc; border-radius: 7px; font-size: 15px; background: #fff;
}
.mg-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
/* Each cell stacks its own label above its swatch. <label> is inline by
   default, so without this the label and the colour input compete for one line
   and the swatch wraps under it at odd widths. */
.mg-row > div { display: flex; flex-direction: column; min-width: 0; }
.mg-row label { display: block; margin: 8px 0 4px; }
.mg-row input[type=color] {
  width: 100%; height: 38px; padding: 2px;
  border: 1px solid #ccc; border-radius: 7px; background: #fff;
  -webkit-appearance: none; appearance: none; cursor: pointer;
}
/* Safari/Chrome draw the swatch in a padded well; strip it so the colour fills
   the control and the rounded corner is not doubled. */
.mg-row input[type=color]::-webkit-color-swatch-wrapper { padding: 2px; }
.mg-row input[type=color]::-webkit-color-swatch { border: none; border-radius: 5px; }
.mg-row input[type=color]::-moz-color-swatch { border: none; border-radius: 5px; }
.mg-btn--alt {
  background: linear-gradient(90deg, #A1C4FD, #C2E9FB);
  color: #000;
  margin-top: 8px;
}
.mg-note { font-size: 12px; color: #777; line-height: 1.5; margin: 10px 0 0; }
.mg-savedlink { font-weight: 700; }
#mg-canvas { touch-action: none; }          /* let pointermove drag, not scroll */
#mg-canvas.mg-dragging { cursor: grabbing; }
.mg-hint { font-weight: 400; color: #888; font-size: 11px; }
.mg-others { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.mg-others a {
  display: inline-block; padding: 8px 14px; background: #f2f2f2;
  border: 1px solid #ddd; border-radius: 20px; color: #222; text-decoration: none;
}
.mg-others a:hover { background: #e6e6e6; text-decoration: none; }
.mg-starters-note { color: #666; font-size: 13px; margin: -4px 0 12px; }
.mg-browse { margin: 14px 0 0; }

/* --- Mobile ---------------------------------------------------------------
   The desktop layout is a two-column grid with the controls in a sidebar. On a
   phone that collapses to one column, which left the canvas pushed around by a
   long stack of full-width inputs. This makes the canvas the fixed reference
   point and packs the controls into a compact grid underneath it. */
@media (max-width: 820px) {
  .mg { padding: 0 12px; }
  .mg h1 { font-size: 25px; line-height: 1.2; }
  .mg-lede { font-size: 15px; }

  .mg-grid { gap: 14px; }

  .mg-stage {
    padding: 8px;
    margin: 0 -12px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }
  #mg-canvas { max-height: 46vh; width: auto; max-width: 100%; }

  /* Two columns for the short controls, full width for the text inputs. */
  .mg-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
    /* end, not center: rows here are label-above-input pairs of differing
       heights, and centring them left the colour swatches floating out of line
       with the sliders beside them. */
    align-items: end;
  }
  .mg-controls > label { margin-top: 10px; font-size: 12px; }
  .mg-row label { font-size: 12px; margin: 10px 0 4px; }
  .mg-controls label[for="mg-top"],
  .mg-controls label[for="mg-bottom"],
  .mg-controls input[type=text],
  .mg-controls .mg-filelabel,
  .mg-controls input[type=file],
  .mg-controls .mg-btn,
  .mg-controls .mg-note,
  .mg-row { grid-column: 1 / -1; }

  /* Comfortable touch targets. 16px stops iOS zooming the page on focus. */
  .mg-controls input[type=text],
  .mg-controls select { font-size: 16px; padding: 11px 12px; }
  .mg-controls input[type=range] { height: 30px; }
  .mg-check { grid-column: 1 / -1; margin-top: 8px; }

  .mg-btn { width: 100%; padding: 14px 16px; font-size: 16px; }

  .mg-starters { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .mg-starter img { height: 104px; }

  .mg-faq { font-size: 15px; }
  .mg-faq h2 { font-size: 19px; }
  .mg-others a { padding: 9px 13px; }
}

@media (max-width: 420px) {
  #mg-canvas { max-height: 40vh; }
  .mg-controls { grid-template-columns: 1fr; }
  .mg-row { grid-template-columns: 1fr 1fr; }
}

/* --- Shrink-to-corner preview --------------------------------------------
   Sticking the preview to the top pushed the page down and covered the
   controls. Instead, once the stage has scrolled out of view it becomes a small
   card in the bottom-right corner: the preview stays visible while you type,
   without occupying the top of the screen. Tapping it scrolls back up. */
.mg-stage.mg-mini {
  position: fixed;
  right: 12px;
  bottom: 12px;
  left: auto;
  top: auto;
  width: 168px;
  max-width: 45vw;
  margin: 0;
  padding: 6px;
  z-index: 60;
  border: 2px solid #000;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
  cursor: pointer;
}
.mg-stage.mg-mini #mg-canvas { max-height: 150px; width: auto; max-width: 100%; }
.mg-stage.mg-mini .mg-credit,
.mg-stage.mg-mini .mg-status { display: none; }
.mg-stage.mg-mini::after {
  content: "tap to edit";
  display: block; text-align: center;
  font-size: 10px; color: #666; padding-top: 3px;
}
/* Placeholder keeps the page from jumping when the stage goes fixed. */
.mg-stage-spacer { display: none; }
.mg-stage-spacer.mg-active { display: block; }
