/* Compact creative studio: keep the preview, editing controls and actions in one viewport. */
.meme-creator-dialog {
  box-sizing: border-box;
  width: min(94vw, 1080px);
  height: min(760px, calc(100dvh - 28px));
  max-height: calc(100dvh - 28px);
  overflow: hidden;
  border: 1px solid #f0d7dc;
  border-radius: 24px;
  background: #fffaf9;
  box-shadow: 0 28px 90px #210d1c66;
}
.meme-creator-form {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 16px 20px 14px;
}
.meme-creator-heading {
  position: relative;
  z-index: 2;
  align-items: center;
  min-height: 46px;
  padding-right: 4px;
}
.meme-creator-heading h2 {
  font-size: clamp(25px, 2.4vw, 31px);
}
.meme-creator-help {
  margin-top: 3px;
  font-size: 11px;
  line-height: 1.35;
}
.meme-icon-button {
  position: sticky;
  top: 0;
  z-index: 5;
  width: 42px;
  height: 42px;
  border: 1px solid #d7a9b2;
  background: #fff;
  color: #7d1735;
  box-shadow: 0 3px 12px #260d1d18;
  font-size: 24px;
}
.meme-icon-button:hover {
  border-color: #b72245;
  background: #fff0f3;
}
.meme-workspace {
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 410px);
  gap: 18px;
  align-items: stretch;
}
.meme-stage {
  position: relative;
  display: grid;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 5px;
}
.meme-canvas-wrap {
  min-height: 0;
  max-height: none;
  height: 100%;
  border-color: #f0d7dc;
  border-radius: 18px;
  background: radial-gradient(ellipse at 50% 0%, #ffe2e8 0, transparent 64%), linear-gradient(145deg, #fff5ef, #f7e6f0 56%, #eee8ff);
}
.meme-stage-canvas {
  max-width: 94%;
  max-height: 94%;
  border-radius: 8px;
  box-shadow: 0 14px 34px #37162a26;
}
.meme-stage-note {
  margin: 2px 3px 0;
  font-size: 10px;
}
.meme-controls {
  box-sizing: border-box;
  min-height: 0;
  max-height: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 7px 9px;
  overflow: auto;
  padding: 1px 3px 2px;
  scrollbar-width: thin;
  scrollbar-color: #d7a2b0 transparent;
}
.meme-controls > .meme-upload-field,
.meme-controls > .meme-template-field,
.meme-controls > .meme-caption-heading,
.meme-controls > .meme-ai-panel,
.meme-controls > .meme-more-settings {
  grid-column: 1 / -1;
}
.meme-field {
  gap: 4px;
  font-size: 10px;
}
.meme-field-hint {
  overflow: hidden;
  font-size: 9px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meme-controls :is(input[type=text], input[type=file], select, textarea) {
  min-height: 34px;
  padding: 6px 9px;
  border-radius: 10px;
  font-size: 11px;
}
.meme-controls textarea {
  min-height: 43px;
  max-height: 52px;
  resize: none;
}
.meme-controls input[type=file] {
  min-height: 38px;
  padding: 5px;
}
.meme-template-field {
  gap: 5px;
}
.meme-template-grid {
  gap: 5px;
}
.meme-template-chip {
  min-height: 34px;
  padding: 5px 4px;
  font-size: 9px;
}
.meme-caption-heading {
  align-items: baseline;
  margin: 1px 0 -3px;
}
.meme-caption-heading h3 {
  font-size: 12px;
}
.meme-ai-panel {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 8px;
  padding: 8px;
  border-radius: 13px;
  background: linear-gradient(125deg, #fff0f3, #fffaf5 70%, #f3efff);
}
.meme-ai-intro {
  grid-column: 1 / -1;
  gap: 6px;
}
.meme-ai-spark {
  width: 25px;
  height: 25px;
  border-radius: 9px;
  font-size: 14px;
}
.meme-ai-intro strong {
  font-size: 10px;
}
.meme-ai-intro small,
.meme-ai-privacy {
  display: none;
}
.meme-ai-row {
  grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 6px;
}
.meme-ai-row :is(input, select) {
  min-height: 32px !important;
}
.meme-ai-button {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 10px;
}
.meme-ai-ideas {
  grid-column: 1 / -1;
  max-height: 72px;
  overflow: auto;
}
.meme-ai-choice {
  padding: 5px 7px;
  font-size: 10px;
}
.meme-more-settings {
  padding-top: 6px;
}
.meme-more-settings summary {
  font-size: 10px;
}
.meme-settings-grid {
  gap: 6px;
  margin-top: 7px;
}
.meme-settings-grid .meme-field {
  gap: 3px;
}
.meme-settings-grid input[type=color] {
  height: 30px;
  min-height: 30px;
}
.meme-creator-status {
  min-height: 14px;
  overflow: hidden;
  font-size: 10px;
  line-height: 1.3;
  text-overflow: ellipsis;
}
.meme-creator-actions {
  position: relative;
  z-index: 3;
  min-height: 46px;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 0 0;
  background: #fffaf9;
}
.meme-creator-actions button {
  min-height: 38px;
  padding: 7px 13px;
  font-size: 11px;
}

@media (max-width: 850px) {
  .meme-creator-dialog {
    width: min(96vw, 700px);
    height: min(760px, calc(100dvh - 16px));
    max-height: calc(100dvh - 16px);
    border-radius: 22px;
  }
  .meme-creator-form {
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: 8px;
    padding: 12px 14px 10px;
  }
  .meme-workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(140px, 25dvh) minmax(0, 1fr);
    gap: 8px;
  }
  .meme-stage {
    grid-template-rows: minmax(0, 1fr);
  }
  .meme-stage-note {
    display: none;
  }
  .meme-stage-canvas {
    max-height: 100%;
  }
  .meme-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 8px;
  }
  .meme-icon-button {
    position: sticky;
  }
}

@media (max-width: 520px) {
  .meme-creator-dialog {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .meme-creator-form {
    padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
  }
  .meme-creator-heading {
    min-height: 42px;
    gap: 8px;
  }
  .meme-creator-heading h2 {
    font-size: 23px;
  }
  .meme-creator-help {
    max-width: 36ch;
    font-size: 9px;
  }
  .meme-icon-button {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
  }
  .meme-workspace {
    grid-template-rows: minmax(118px, 20dvh) minmax(0, 1fr);
  }
  .meme-controls {
    gap: 5px 7px;
    padding-inline: 1px;
  }
  .meme-field {
    font-size: 9px;
  }
  .meme-controls :is(input[type=text], input[type=file], select, textarea) {
    min-height: 31px;
    padding: 5px 7px;
    font-size: 10px;
  }
  .meme-controls textarea {
    min-height: 37px;
    max-height: 42px;
  }
  .meme-template-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .meme-template-chip {
    min-height: 31px;
    font-size: 8px;
  }
  .meme-ai-panel {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .meme-ai-row {
    grid-template-columns: minmax(0, 1fr) 96px;
  }
  .meme-creator-actions {
    min-height: 42px;
    gap: 6px;
    padding-top: 5px;
  }
  .meme-creator-actions button {
    min-height: 36px;
    padding: 6px 9px;
    font-size: 10px;
  }
}

@media (max-height: 700px) {
  .meme-creator-dialog {
    height: calc(100dvh - 12px);
    max-height: calc(100dvh - 12px);
  }
  .meme-creator-form {
    gap: 6px;
    padding-block: 8px;
  }
  .meme-workspace {
    grid-template-rows: minmax(100px, 19dvh) minmax(0, 1fr);
  }
}

/* Keep compact navigation labels horizontal on narrow phone screens. */
@media (max-width: 700px) {
  .sidebar nav > .nav-item {
    writing-mode: horizontal-tb !important;
    word-break: keep-all !important;
    overflow-wrap: normal !important;
    white-space: nowrap !important;
  }
  .sidebar nav > .mobile-create {
    white-space: nowrap !important;
    word-break: keep-all !important;
  }
}
