/* In-place Edit / Save — one Edit per box, phone-first */

.msj-edit-box,
.msj-edit-box-pos {
  position: relative;
}

.msj-edit-box-intro {
  margin-bottom: 0.25rem;
}

.msj-edit-trigger {
  appearance: none;
  border: 1px solid rgba(196, 120, 90, 0.45);
  background: rgba(255, 252, 248, 0.95);
  color: #8a4f38;
  font: 600 0.75rem/1 "Source Sans 3", system-ui, sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.45rem 0.75rem;
  min-height: 36px;
  min-width: 44px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 2px 8px rgba(44, 42, 40, 0.08);
  z-index: 4;
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  opacity: 0.78;
}

.msj-edit-box:hover > .msj-edit-trigger,
.msj-edit-box:focus-within > .msj-edit-trigger,
.msj-edit-trigger:focus {
  opacity: 1;
}

.msj-edit-box.is-editing {
  outline: 2px solid #c4785a;
  outline-offset: 6px;
  border-radius: 12px;
}

.msj-editing {
  outline: 1px dashed rgba(196, 120, 90, 0.55);
  outline-offset: 3px;
  border-radius: 6px;
  background: rgba(255, 252, 248, 0.55);
  caret-color: #c4785a;
}

.msj-edit-bar {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0.65rem 0.85rem;
  background: rgba(44, 42, 40, 0.92);
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  z-index: 10000;
  max-width: calc(100vw - 1.5rem);
}

.msj-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font: 600 0.95rem/1 "Source Sans 3", system-ui, sans-serif;
  min-height: 44px;
  padding: 0.65rem 1.15rem;
  border-radius: 999px;
  touch-action: manipulation;
}

.msj-btn-save {
  background: #c4785a;
  color: #fffaf6;
}

.msj-btn-cancel {
  background: rgba(255, 252, 248, 0.15);
  color: #fffaf6;
}

.msj-btn-reset {
  background: transparent;
  color: rgba(255, 250, 246, 0.75);
  text-decoration: underline;
  text-underline-offset: 3px;
  min-width: auto;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

.msj-edit-toast {
  position: fixed;
  left: 50%;
  top: max(1rem, env(safe-area-inset-top));
  transform: translateX(-50%) translateY(-12px);
  background: #2c2a28;
  color: #fffaf6;
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  font: 600 0.95rem/1.2 "Source Sans 3", system-ui, sans-serif;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 10001;
  pointer-events: none;
}

.msj-edit-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.msj-edit-toast.is-error {
  background: #8a3030;
}

.msj-edit-hint {
  margin: 0 0 1.25rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(168, 181, 160, 0.28);
  border: 1px solid rgba(168, 181, 160, 0.55);
  color: #2c2a28;
  font-size: 0.95rem;
  line-height: 1.45;
}

.msj-alt-host {
  position: relative;
}

.msj-alt-panel {
  position: absolute;
  left: 0.5rem;
  right: 0.5rem;
  bottom: 0.5rem;
  z-index: 6;
  background: rgba(255, 252, 248, 0.97);
  border: 1px solid rgba(196, 120, 90, 0.4);
  border-radius: 12px;
  padding: 0.75rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.msj-alt-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8a4f38;
  margin-bottom: 0.35rem;
}

.msj-alt-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(44, 42, 40, 0.18);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font: 400 1rem/1.4 "Source Sans 3", system-ui, sans-serif;
  min-height: 44px;
  resize: vertical;
  background: #fff;
  color: #2c2a28;
}

/* Section cards are <a> — keep Edit outside navigation */
a.section-card.msj-edit-box {
  display: block;
}

a.section-card .msj-edit-trigger {
  pointer-events: auto;
}

/* Breathing room so Edit doesn’t cover titles on tight cards */
.msj-edit-box.section-card,
a.section-card.msj-edit-box {
  padding-right: 4.25rem;
}

.msj-edit-box.chapter-intro,
.msj-edit-box-intro {
  padding-top: 0.15rem;
  padding-right: 4.25rem;
}

.msj-edit-box.entry,
article.entry.msj-edit-box {
  padding-right: 4.25rem;
}

figure.msj-edit-box {
  padding-top: 0.15rem;
}

@media (max-width: 700px) {
  .msj-edit-trigger {
    opacity: 0.92;
  }
}
