/* Moments: the Story moments section: the heading, the cards and their ⋯ menu, folding, the editor, the chapter's job, the add row and Reorder mode */

.moments-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-top: 7px;
  margin: 2px 0 14px;
  border-top: 1px solid var(--line-soft);
}

.moments-heading h2 {
  margin: 18px 0 2px;
  font-size: 1.3rem;
}

.moments-heading-copy {
  min-width: 0;
}

.moments-heading-tools {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
}

/* A heading tool: its icon and word, the icon alone on phones. */
.moments-tool {
  gap: 6px;
}

.moments-tool:disabled {
  opacity: 0.45;
  cursor: default;
}

.moments-tool .book-icon {
  width: 17px;
  height: 17px;
}

.stuck-button {
  min-height: 54px;
  flex: 0 0 auto;
  padding: 10px 17px;
  border-color: #e1bd58;
  color: var(--stuck-ink);
  background: var(--gold-pale);
  box-shadow: 0 5px 12px rgba(165, 115, 17, 0.1);
}

.stuck-button:hover:not(:disabled) {
  border-color: var(--gold);
  background: var(--stuck-hover);
}

.stuck-button span {
  color: var(--spark);
}

.moments-heading p {
  margin-bottom: 0;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.moments-list {
  display: grid;
  gap: 13px;
}

.moment-card {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 40px;
  align-items: start;
  gap: 10px;
  padding: 10px 10px 10px 14px;
  border: 1px solid var(--moment-line);
  border-radius: 14px;
  background: var(--moment);
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease,
    opacity 150ms ease,
    transform 150ms ease;
}

/* Over the cards after it. */
.moment-card.has-menu {
  z-index: 6;
}

.moment-card.is-help-target {
  border-color: #d9a62d;
  background: var(--moment-target);
  box-shadow:
    0 0 0 3px rgba(230, 169, 43, 0.18),
    0 9px 22px rgba(83, 60, 18, 0.1);
}

.moment-number {
  display: grid;
  width: 32px;
  height: 32px;
  margin-top: 12px;
  place-items: center;
  border-radius: 10px;
  color: var(--violet-dark);
  background: var(--moment-number);
  font-size: 0.8rem;
  font-weight: 900;
}

.moment-body {
  min-width: 0;
  padding: 16px 0 14px;
}

/* A moment's state (css/components.css) over its words: its mount, empty
   without one, takes no room. */
.moment-state-mount {
  display: flex;
}

/* A moment's words, and the chapter's job, as they are written. */
.moment-text {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.moment-text.is-empty {
  color: var(--placeholder);
  font-style: italic;
}

/* A card's words fold after 4 lines (MOMENT_FOLD_LINES) until unfolded. */
.moment-card:not(.is-unfolded) .moment-text {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
}

/* Read more / Show less, under words that fold. */
.moment-fold-button {
  min-height: 32px;
  padding: 2px 0;
  border: 0;
  color: var(--violet-dark);
  background: none;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
}

.moment-fold-button:hover {
  text-decoration: underline;
}

.moment-fold-button:focus-visible {
  outline: 3px solid var(--violet);
  outline-offset: 1px;
}

/* A moment's words, and those written for it, under its text. */
.moment-words {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.3;
}

/* The ⋯ and its dropdown, placed from it. */
.moment-menu-anchor {
  position: relative;
  margin-top: 8px;
}

.moment-menu-button {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--ink-soft);
  background: none;
}

.moment-menu-button:hover,
.moment-menu-button[aria-expanded="true"] {
  color: var(--ink);
  background: var(--violet-pale);
}

.moment-menu-button:focus-visible {
  outline: 3px solid var(--violet);
  outline-offset: 1px;
}

.moment-menu-button .book-icon {
  width: 20px;
  height: 20px;
}

/* Phones: the moment's book sheet (css/reader.css). */
.moment-sheet-excerpt {
  display: -webkit-box;
  margin: -2px 8px 12px;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.moment-sheet .book-sheet-row[data-action="delete-moment"] {
  color: var(--delete-ink);
}

.moment-sheet .book-sheet-row[data-action="delete-moment"] .book-sheet-tile {
  color: var(--delete-ink);
  background: var(--delete-tile);
}

/* The chapter's job, as text with its ✎ in a card like a moment's. */
.chapter-change-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  align-items: start;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--moment-line);
  border-radius: 14px;
  background: var(--moment);
}

.chapter-change-card .moment-text {
  padding: 8px 0;
}

/* The editor in place: a card, or the chapter's job, with "Editing",
   Ideas, Cancel and Done over its text box. The phone dialog lays the
   same markup out full screen. */
.moment-card.is-editing {
  grid-template-columns: 34px minmax(0, 1fr);
  border-color: var(--violet-line);
}

.moment-editor {
  display: grid;
  min-width: 0;
  gap: 8px;
}

.moment-editor-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.moment-card .moment-editor-bar {
  padding-top: 6px;
}

.moment-editor-heading,
.moment-editor-before {
  display: none;
}

.moment-editor-label {
  margin-right: auto;
  color: var(--violet-dark);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Over .editor-textarea (css/workshop.css) by specificity, not file order. */
.moment-card .moment-textarea {
  min-height: 56px;
  padding: 9px 11px;
  overflow-y: hidden;
  line-height: 1.4;
  resize: none;
}

.moment-ideas-button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 5px;
  padding: 0 12px;
  border: 1px solid var(--moment-tool-line);
  border-radius: 999px;
  color: var(--violet-dark);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 900;
  line-height: 1;
}

.moment-ideas-button span {
  color: var(--spark);
}

.moment-ideas-button:hover,
.moment-ideas-button:focus-visible {
  border-color: var(--violet);
  background: var(--violet-pale);
}

/* Phones: the editor fills the screen, its height kept to what the
   keyboard leaves (fitMomentEditorToViewport). Cancel, the title, Ideas
   and Done in the bar; the line before the words; the text box takes the
   rest and scrolls inside itself. */
.moment-editor-dialog {
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  background: var(--map-page);
}

.moment-editor-dialog::backdrop {
  background: var(--map-page);
}

.moment-editor-dialog .moment-editor {
  display: flex;
  height: 100%;
  flex-direction: column;
  gap: 0;
}

.moment-editor-dialog .moment-editor-bar {
  display: grid;
  grid-template-areas: "cancel heading ideas done";
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px 10px;
  border-bottom: 1px solid var(--map-header-line);
  background: var(--map-header);
}

.moment-editor-dialog .moment-editor-heading {
  display: block;
  grid-area: heading;
  min-width: 0;
  text-align: center;
}

.moment-editor-dialog .moment-editor-heading h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

.moment-editor-dialog .moment-editor-heading p {
  margin: 1px 0 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 0.76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.moment-editor-dialog .moment-editor-label {
  display: none;
}

.moment-editor-dialog .moment-editor-cancel {
  grid-area: cancel;
  padding-inline: 8px;
  color: var(--violet-dark);
  font-size: 0.95rem;
}

.moment-editor-dialog .moment-ideas-button {
  grid-area: ideas;
  min-height: 44px;
  padding: 0 14px;
  font-size: 0.9rem;
}

.moment-editor-dialog .moment-editor-done {
  grid-area: done;
}

.moment-editor-dialog .moment-editor-before {
  display: -webkit-box;
  flex: none;
  margin: 14px 16px 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-style: italic;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.moment-editor-before span {
  display: block;
  color: var(--violet-dark);
  font-size: 0.7rem;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* 1.125rem: over 16px, so iOS does not zoom into it. */
.moment-editor-text {
  display: block;
  min-height: 0;
  flex: 1;
  margin: 12px 16px 16px;
  padding: 14px 16px;
  overflow-y: auto;
  border: 1px solid var(--editor-line);
  border-radius: 14px;
  color: var(--ink);
  background: var(--field);
  font-size: 1.125rem;
  line-height: 1.5;
  resize: none;
}

.moment-editor-text:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 4px var(--focus-glow);
  outline: 0;
}

.moments-empty-state {
  display: flex;
  min-height: 76px;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px dashed var(--moments-empty-line);
  border-radius: 14px;
  color: var(--ink-soft);
  background: var(--violet-faint);
  font-size: 0.82rem;
}

.moments-empty-state strong {
  display: block;
  margin-bottom: 2px;
  color: var(--ink);
  font-size: 0.88rem;
}

.moments-empty-spark {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 12px;
  color: var(--moments-empty-spark);
  background: var(--gold-pale);
  font-size: 1.05rem;
}

/* Reorder mode: one line per moment. Unqualified, so the drag ghost, a
   clone on <body>, keeps the layout. */
.moments-list.is-reordering {
  gap: 8px;
}

.moment-row {
  position: relative;
  display: grid;
  grid-template-columns: 30px 28px minmax(0, 1fr) 44px 44px;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 4px;
  border: 1px solid var(--moment-line);
  border-radius: 12px;
  background: var(--moment);
  transition:
    border-color 150ms ease,
    opacity 150ms ease;
}

.moment-row.is-dragging {
  border-color: #b8ade7;
  opacity: 0.35;
}

.moment-row.is-drop-before::before,
.moment-row.is-drop-after::after {
  position: absolute;
  right: 10px;
  left: 10px;
  z-index: 2;
  height: 3px;
  border-radius: 999px;
  background: var(--violet);
  box-shadow: 0 0 0 3px rgba(102, 87, 199, 0.12);
  content: "";
}

.moment-row.is-drop-before::before {
  top: -6px;
}

.moment-row.is-drop-after::after {
  bottom: -6px;
}

/* Only here may a touch drag: the page scrolls from anywhere else. */
.moment-drag-handle {
  display: grid;
  width: 30px;
  min-height: 44px;
  padding: 0;
  place-items: center;
  border-radius: 9px;
  color: #8b82b5;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.moment-drag-handle:hover {
  color: var(--violet-dark);
  background: var(--violet-pale);
}

.moment-drag-handle:focus-visible {
  color: var(--violet-dark);
  background: var(--violet-pale);
  outline: 3px solid rgba(102, 87, 199, 0.28);
  outline-offset: 2px;
}

.moment-drag-handle:active {
  cursor: grabbing;
}

.moment-drag-handle span {
  font-size: 1.35rem;
  line-height: 1;
}

.moment-row .moment-number {
  width: 28px;
  height: 28px;
  margin: 0;
  border-radius: 8px;
  font-size: 0.78rem;
}

.moment-row-text {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.95rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.moment-row-text.is-empty {
  color: var(--ink-soft);
  font-style: italic;
}

.moment-move-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--moment-tool-line);
  border-radius: 10px;
  color: var(--violet-dark);
  background: var(--surface);
}

.moment-move-button .book-icon {
  width: 18px;
  height: 18px;
}

.moment-move-button:hover:not(:disabled),
.moment-move-button:focus-visible {
  border-color: var(--violet);
  background: var(--violet-pale);
}

.moment-move-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.moment-drag-ghost {
  position: fixed !important;
  z-index: 1000;
  margin: 0 !important;
  pointer-events: none;
  opacity: 0.94;
  box-shadow: 0 18px 45px rgba(39, 34, 78, 0.24);
}

.moment-drag-ghost .moment-drag-handle {
  cursor: grabbing;
}

body.is-reordering-moment {
  cursor: grabbing;
  user-select: none;
}

.moment-action-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  min-height: 54px;
  margin-top: 13px;
}

.add-moment-button,
.finish-reorder-button {
  min-width: 0;
  flex: 1 1 auto;
  border-radius: 16px;
  font-weight: 900;
}

.add-moment-button:hover:not(:disabled),
.finish-reorder-button:hover:not(:disabled) {
  background: var(--violet-fill-hover);
}

.add-moment-button:disabled,
.stuck-button:disabled {
  opacity: 0.5;
}

/* Under the disabled add row: why a chapter takes no more moments. */
.moment-limit-note {
  margin: 8px 2px 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.35;
}

@media (max-width: 780px) {
  .moments-tool {
    width: 44px;
    padding: 0;
  }

  .moments-tool-label {
    display: none;
  }

  .moments-tool .book-icon {
    width: 20px;
    height: 20px;
  }

  /* One row: the number, the words and the ⋯ at 44px. */
  .moment-card {
    grid-template-areas: "number text menu";
    grid-template-columns: 28px minmax(0, 1fr) 44px;
    gap: 10px;
    padding: 12px 6px 12px 12px;
  }

  .moment-card.is-editing {
    grid-template-areas: "number text";
    grid-template-columns: 28px minmax(0, 1fr);
  }

  .moment-card .moment-number {
    grid-area: number;
    width: 28px;
    height: 28px;
    margin: 0;
    font-size: 0.78rem;
  }

  .moment-body,
  .moment-card .moment-editor {
    grid-area: text;
    padding: 2px 0 0;
  }

  .moment-menu-anchor {
    grid-area: menu;
    margin-top: -8px;
  }

  .moment-menu-button {
    width: 44px;
    height: 44px;
  }

  .chapter-change-card {
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .chapter-change-card .moment-text {
    padding: 10px 0;
  }

  .moment-textarea {
    font-size: 1rem;
  }
}

@media (max-width: 500px) {
  .moments-heading {
    gap: 12px;
  }

  .moment-action-row {
    gap: 8px;
  }

  .add-moment-button,
  .finish-reorder-button {
    padding-inline: 10px;
    font-size: 0.86rem;
  }

  .stuck-button {
    min-width: 76px;
    padding-inline: 11px;
    font-size: 0.86rem;
  }
}
