.secondary-panel-popover[x-cloak] {
  display: none !important;
}

.secondary-panel-popover {
  position: fixed;
  left: calc(var(--primary-sidebar-collapsed-width, 8.25dvh) + 2.2dvh);
  right: 1rem;
  top: 1rem !important;
  bottom: auto !important;
  z-index: 80;
  width: auto;
  max-width: 68rem;
  max-height: calc(100vh - 2rem);
  pointer-events: auto;
  border: 1px solid rgb(45 41 36 / 18%);
  border-radius: .9rem;
  background: #fbf8f4;
  box-shadow: 0 12px 30px rgb(45 41 36 / 16%), 0 0 0 1px rgb(45 41 36 / 8%);
  box-sizing: border-box;
  padding: .875rem;
}

@media (min-width: 1024px) {
  body[data-primary-sidebar-open="true"] .secondary-panel-popover {
    left: calc(var(--primary-sidebar-expanded-width, 30.8dvh) + 2.2dvh);
  }
}

.secondary-panel-group + .secondary-panel-group {
  margin-top: .45rem;
}

.secondary-panel-group-title {
  margin: 0 0 .25rem;
  color: rgb(45 41 36 / 62%);
  font-size: 1.4rem;
  font-weight: 750;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.secondary-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .35rem;
  padding: 0 .1rem;
}

.secondary-panel-heading h2 {
  color: rgb(45 41 36 / 62%);
  font-size: 1.36rem;
  letter-spacing: .18em;
}

.secondary-panel-list {
  display: grid;
  gap: .25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.secondary-panel-list--elements {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: .15rem;
}

.secondary-panel-lock {
  position: absolute;
  right: .2rem;
  bottom: .2rem;
  display: grid;
  width: 1.45rem;
  height: 1.45rem;
  place-items: center;
  border-radius: 999px;
  background: #111;
  color: #d4a72c;
  box-shadow: 0 1px 3px rgb(0 0 0 / 35%);
}

.secondary-panel-lock svg {
  width: .82rem;
  height: .82rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.secondary-panel-add {
  flex: 0 0 auto;
  border: 1px solid rgb(45 41 36 / 24%);
  border-radius: .55rem;
  background: rgb(251 248 244 / 84%);
  color: #2d2924;
  cursor: pointer;
  font-size: 1.56rem;
  font-weight: 700;
  line-height: 1.3;
  padding: .4rem .55rem;
}

.secondary-panel-add:hover,
.secondary-panel-add:focus-visible {
  background: rgb(45 41 36 / 10%);
}

.secondary-panel-create-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  margin: 0;
  width: min(32rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  transform: translate(-50%, -50%);
  border: 1px solid rgb(45 41 36 / 18%);
  border-radius: .9rem;
  background: #fbf8f4;
  color: #2d2924;
  padding: 1.25rem;
  box-shadow: 0 18px 45px rgb(45 41 36 / 22%);
}

.secondary-panel-create-dialog::backdrop {
  background: rgb(45 41 36 / 46%);
}

.secondary-panel-create-dialog label {
  color: #2d2924;
  font-size: .78rem;
  font-weight: 700;
}

.secondary-panel-create-dialog input,
.secondary-panel-create-dialog textarea {
  display: block;
  width: 100%;
  border: 1px solid rgb(45 41 36 / 22%);
  border-radius: .5rem;
  background: rgb(251 248 244 / 80%);
  color: #2d2924;
  font-size: .9rem;
  margin-top: .35rem;
  padding: .6rem .7rem;
}

.secondary-panel-create-dialog input:focus,
.secondary-panel-create-dialog textarea:focus {
  border-color: rgb(45 41 36 / 48%);
  box-shadow: 0 0 0 3px rgb(45 41 36 / 10%);
  outline: none;
}

.secondary-panel-create-actions {
  display: flex;
  justify-content: flex-end;
  gap: .6rem;
  margin-top: 1rem;
}

.secondary-panel-create-actions button {
  border: 1px solid rgb(45 41 36 / 22%);
  border-radius: .5rem;
  background: transparent;
  color: #2d2924;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 700;
  padding: .55rem .75rem;
}

.secondary-panel-create-actions button[type="submit"] {
  background: rgb(45 41 36 / 10%);
}

.secondary-panel-list--reorderable {
  min-height: 8rem;
  border-radius: .75rem;
  outline: 1px dashed transparent;
  outline-offset: .25rem;
  transition: background .12s ease, outline-color .12s ease;
}

.secondary-panel-list--elements.secondary-panel-list--reorderable {
  min-height: 0;
}

.secondary-panel-list--reorderable.is-drag-over {
  background: rgb(255 255 255 / 38%);
  outline-color: rgb(45 41 36 / 25%);
}

.secondary-panel-list--reorderable [data-reorder-item] {
  cursor: grab;
}

.secondary-panel-list--reorderable [data-reorder-item]:active,
.secondary-panel-list--reorderable [data-reorder-item].is-dragging {
  cursor: grabbing;
  opacity: .45;
}

.secondary-panel-drop-hint {
  display: grid;
  min-height: 6rem;
  place-items: center;
  border: 1px dashed rgb(45 41 36 / 18%);
  border-radius: .6rem;
  color: rgb(45 41 36 / 55%);
  font-size: .75rem;
  font-weight: 650;
}

.secondary-panel-reorder-status {
  min-height: 1.25rem;
  margin: .75rem 0 0;
  color: rgb(45 41 36 / 62%);
  font-size: .75rem;
  text-align: right;
}

.secondary-panel-reorder-status[data-state="error"] {
  color: #b42318;
}

.secondary-panel-item {
  display: flex;
  align-items: center;
  gap: .525rem;
  min-width: 0;
  padding: .35rem;
  border: 1px solid transparent;
  border-radius: .6rem;
  color: #2d2924;
  text-decoration: none;
}

.secondary-panel-item:hover,
.secondary-panel-item:focus-visible {
  border-color: rgb(45 41 36 / 14%);
  background: rgb(45 41 36 / 8%);
}

.secondary-panel-thumb {
  width: 3.5rem;
  height: 3.5rem;
  flex: 0 0 3.5rem;
  border: 1px solid rgb(45 41 36 / 12%);
  border-radius: .5rem;
}

.secondary-panel-thumb--empty {
  background: rgb(251 248 244 / 45%);
}

.secondary-panel-thumb--empty .generated-image-placeholder,
.narrative-element-card-image-empty .generated-image-placeholder {
  border: 0;
  background: transparent;
}

.secondary-panel-thumb--empty .ai-orb-loader,
.narrative-element-card-image-empty .ai-orb-loader {
  opacity: .5;
}

.secondary-panel-item-title {
  min-height: 2.6em;
  overflow-wrap: anywhere;
  color: #2d2924;
  font-family: "Atkinson Hyperlegible", sans-serif;
  font-size: 1.7rem;
  font-weight: 650;
  line-height: 1.3;
  text-align: left;
}

.secondary-panel-item-summary {
  display: -webkit-box;
  overflow: hidden;
  color: rgb(45 41 36 / 62%);
  font-size: 1.4rem;
  line-height: 1.35;
  -webkit-box-orient: vertical;
}

.secondary-panel-element-tile {
  flex-direction: column;
  min-height: 100%;
  align-items: center;
  justify-content: flex-start;
}

.secondary-panel-list--elements > li {
  min-width: 0;
}

.secondary-panel-list--elements .secondary-panel-item {
  height: 100%;
  padding: .15rem;
}

.secondary-panel-list--elements .secondary-panel-item-title {
  min-height: 0;
  width: 100%;
  max-width: 100%;
  /* Keep a hyphenated name intact; move it to the next line instead. */
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
  text-wrap: pretty;
  font-size: clamp(1.2rem, 1.38vw, 1.5rem);
  line-height: 1.2;
  text-align: center;
}

.secondary-panel-list--elements .secondary-panel-item-title--long {
  font-size: clamp(1.05rem, 1.15vw, 1.25rem);
  letter-spacing: -.01em;
}

.secondary-panel-list--elements .secondary-panel-item-title.mt-2 {
  margin-top: .35rem;
}

.secondary-panel-list--elements .secondary-panel-thumb {
  width: 85%;
  margin-inline: auto;
  height: auto;
  aspect-ratio: 1;
  flex-basis: auto;
}

.secondary-panel-list--elements .secondary-panel-chapter-tile {
  width: 85%;
  margin-inline: auto;
  height: auto;
  aspect-ratio: 1;
  flex-basis: auto;
}

.secondary-panel-chapter-tile {
  width: 3.5rem;
  height: 3.5rem;
  flex: 0 0 3.5rem;
  background: rgb(45 41 36 / 8%);
  container-type: inline-size;
}

.secondary-panel-chapter-number {
  position: absolute;
  right: .5rem;
  bottom: .5rem;
  z-index: 1;
  display: block;
  pointer-events: none;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 28cqw;
  font-weight: 700;
  line-height: 1;
  -webkit-text-stroke: 1.5px #000;
  paint-order: stroke fill;
}

.secondary-panel-chapter-tile .secondary-panel-thumb {
  width: 100%;
  height: 100%;
  margin: 0;
  aspect-ratio: auto;
  border: 0;
  border-radius: inherit;
}

@media (max-width: 1023px) {
  :root {
    --mobile-narrative-tray-height: calc(52px + .9rem + env(safe-area-inset-bottom));
  }

  .secondary-panel-popover {
    top: 0 !important;
    right: 0;
    bottom: var(--mobile-narrative-tray-height) !important;
    left: 0;
    width: auto;
    max-width: none;
    max-height: none;
    margin: 0;
    overscroll-behavior: contain;
    touch-action: pan-y;
    border: 0;
    border-radius: 0;
    background: #fbf8f4;
    box-shadow: none;
  }

  .secondary-panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .secondary-panel-list--elements {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* The chapter connection grid reuses the secondary-navigation tile component,
   but stays three columns wide so its images have useful reading size. */
.chapter-connected-elements-grid.secondary-panel-list--elements {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .25rem;
}

.chapter-connected-elements-grid .secondary-panel-thumb {
  width: 100%;
}

.chapter-connected-elements-grid .chapter-connected-element-title {
  font-size: clamp(.72rem, .8vw, .82rem);
  font-weight: 650;
  line-height: 1.15;
}

@media (min-width: 40rem) {
  .chapter-connected-elements-grid.secondary-panel-list--elements {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
