.mde-toolbar {
  position: fixed;
  left: 16px;
  right: 16px;
  top: 14px;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(60, 42, 38, 0.14);
  border-radius: 999px;
  color: #2f2520;
  background: rgba(255, 252, 244, 0.9);
  box-shadow: 0 18px 48px rgba(54, 36, 24, 0.16);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

html,
body[data-editor-template] {
  max-width: 100%;
  overflow-x: hidden;
}

.mde-toolbar-title {
  min-width: 0;
  display: grid;
  gap: 2px;
  padding-left: 6px;
  line-height: 1.25;
}

.mde-toolbar-title strong {
  overflow: hidden;
  font-size: 14px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mde-toolbar-title span {
  color: rgba(47, 37, 32, 0.62);
  font-size: 12px;
}

.mde-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mde-toolbar button,
.mde-view-cta button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(60, 42, 38, 0.14);
  border-radius: 999px;
  color: #2f2520;
  background: rgba(255, 255, 255, 0.74);
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}

.mde-toolbar button[data-mde-action="share"],
.mde-view-cta button {
  color: #fffaf0;
  border-color: transparent;
  background: #8f5f38;
  box-shadow: 0 10px 24px rgba(143, 95, 56, 0.24);
}

.mde-toolbar button:hover,
.mde-view-cta button:hover {
  transform: translateY(-1px);
}

.mde-link-row {
  display: none;
  min-width: min(420px, 42vw);
}

.mde-toolbar.has-link .mde-link-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mde-link-row input {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid rgba(60, 42, 38, 0.14);
  border-radius: 999px;
  color: #2f2520;
  background: rgba(255, 255, 255, 0.76);
  font: inherit;
}

body.mde-view-mode .mde-toolbar {
  display: none;
}

body.mde-edit-mode [contenteditable="true"] {
  min-height: 1em;
  border-radius: 4px;
  cursor: text;
  white-space: pre-wrap;
}

body.mde-edit-mode [contenteditable="true"]:hover {
  outline: 1px dashed rgba(143, 95, 56, 0.42);
  outline-offset: 4px;
}

body.mde-edit-mode [contenteditable="true"]:focus {
  outline: 2px solid rgba(143, 95, 56, 0.46);
  outline-offset: 4px;
  background: rgba(255, 250, 240, 0.32);
}

body.mde-edit-mode [data-mde-image-id] {
  cursor: pointer;
}

body.mde-edit-mode [data-mde-image-id]:hover {
  outline: 2px dashed rgba(143, 95, 56, 0.52);
  outline-offset: 5px;
}

.mde-bg-has-image {
  background-position: center !important;
  background-size: cover !important;
  background-repeat: no-repeat !important;
}

.mde-bg-has-image > * {
  opacity: 0 !important;
  pointer-events: none !important;
}

img.mde-image-target:not([src]),
img.mde-image-target[src=""] {
  min-height: min(420px, 70vw);
  border: 1px dashed rgba(143, 95, 56, 0.3);
  background:
    linear-gradient(135deg, rgba(255, 250, 240, 0.62), rgba(232, 210, 205, 0.38)),
    repeating-linear-gradient(45deg, rgba(143, 95, 56, 0.08) 0 12px, transparent 12px 24px);
  object-fit: cover;
}

body.mde-edit-mode img.mde-image-target:not([src]),
body.mde-edit-mode img.mde-image-target[src=""] {
  display: block;
}

.mde-toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 320;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 999px;
  color: #fffaf0;
  background: rgba(43, 37, 31, 0.9);
  box-shadow: 0 16px 36px rgba(43, 37, 31, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity 180ms ease, transform 180ms ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

.mde-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.mde-view-cta {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 260;
  display: none;
  transform: translateX(-50%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body.mde-view-mode .mde-view-cta {
  display: block;
}

.mde-image-dialog {
  position: fixed;
  inset: 0;
  z-index: 340;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: #2f2520;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.mde-image-dialog.is-open {
  display: flex;
}

.mde-image-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 22, 18, 0.38);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.mde-image-panel {
  position: relative;
  z-index: 1;
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 18px;
  border: 1px solid rgba(60, 42, 38, 0.14);
  border-radius: 18px;
  background: rgba(255, 252, 244, 0.96);
  box-shadow: 0 24px 80px rgba(32, 24, 18, 0.28);
}

.mde-image-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.mde-image-panel-head strong,
.mde-image-panel-head span {
  display: block;
}

.mde-image-panel-head strong {
  font-size: 17px;
}

.mde-image-panel-head span,
.mde-image-help {
  color: rgba(47, 37, 32, 0.62);
  font-size: 12px;
  line-height: 1.6;
}

.mde-image-close {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(60, 42, 38, 0.14);
  border-radius: 999px;
  color: #2f2520;
  background: rgba(255, 255, 255, 0.74);
  cursor: pointer;
  font: inherit;
}

.mde-image-preview {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px dashed rgba(143, 95, 56, 0.34);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(255, 250, 240, 0.82), rgba(232, 210, 205, 0.46)),
    repeating-linear-gradient(45deg, rgba(143, 95, 56, 0.08) 0 12px, transparent 12px 24px);
}

.mde-image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mde-image-preview.is-empty img {
  display: none;
}

.mde-image-preview span {
  color: rgba(47, 37, 32, 0.58);
  font-size: 14px;
}

.mde-image-upload {
  display: grid;
  place-items: center;
  min-height: 42px;
  margin-bottom: 10px;
  border-radius: 999px;
  color: #fffaf0;
  background: #8f5f38;
  box-shadow: 0 10px 24px rgba(143, 95, 56, 0.24);
  cursor: pointer;
}

.mde-image-upload input {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mde-image-url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.mde-image-url-row input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(60, 42, 38, 0.16);
  border-radius: 999px;
  color: #2f2520;
  background: rgba(255, 255, 255, 0.82);
  font: inherit;
}

.mde-image-url-row button,
.mde-image-panel-actions button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid rgba(60, 42, 38, 0.14);
  border-radius: 999px;
  color: #2f2520;
  background: rgba(255, 255, 255, 0.76);
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}

.mde-image-help {
  margin: 10px 2px 12px;
}

.mde-image-panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.mde-image-panel-actions button:last-child {
  color: #fffaf0;
  border-color: transparent;
  background: #8f5f38;
}

@media (max-width: 760px) {
  body[data-editor-template="movingLetter"] .cursor,
  body[data-editor-template="movingLetter"] .cursor-ring {
    display: none !important;
  }

  .mde-toolbar {
    left: 10px;
    right: 10px;
    top: 10px;
    align-items: stretch;
    flex-direction: column;
    border-radius: 18px;
  }

  .mde-toolbar-actions,
  .mde-toolbar.has-link .mde-link-row {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .mde-toolbar.has-link .mde-link-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .mde-toolbar button {
    width: 100%;
    padding: 0 10px;
  }

  .mde-link-row {
    min-width: 0;
  }

  body.mde-edit-mode {
    padding-top: 118px;
  }

  .mde-image-dialog {
    align-items: flex-end;
    padding: 12px;
  }

  .mde-image-panel {
    width: 100%;
    max-height: calc(100vh - 24px);
    border-radius: 20px;
  }

  .mde-image-url-row,
  .mde-image-panel-actions {
    grid-template-columns: 1fr;
  }

  .mde-image-panel-actions {
    display: grid;
  }
}
