/* Fixed spoiler editing tools */

.spoiler-tools {
  position: fixed;
  right: 14px;
  top: 40%;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 160px;
  padding: 10px;
  background: #f1faff;
  border: 1px solid #a8d2f5;
  border-radius: 12px;
  box-shadow: 0 4px 18px #243c5d20;
}
.spoiler-tools button {
  font-size: 12px;
  padding: 9px 5px;
  white-space: normal;
}
.spoiler-dialog {
  position: fixed;
  inset: 0;
  background: #00000055;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.spoiler-dialog.selection-step {
  pointer-events: none;
  background: transparent;
  align-items: flex-start;
  justify-content: center;
  padding-top: 85px;
}
.spoiler-dialog-card {
  background: white;
  border: 1px solid #a8d2f5;
  border-radius: 12px;
  padding: 18px;
  width: min(400px,95vw);
  box-shadow: 0 5px 25px #00000022;
  pointer-events: auto;
}
.spoiler-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}
.spoiler-dialog-card input {
  width: 100%;
}
.rich-content {
  min-height: 90px;
  border: 1px solid #a8d2f5;
  border-radius: 7px;
  padding: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: white;
  line-height: 1.6;
  outline-offset: 2px;
}
.rich-content:empty:before {
  content: attr(data-placeholder);
  color: #777777;
}
.editor-spoiler {
  display: inline;
  background: #a8d2f5;
  color: #243c5d;
  border-radius: 4px;
  padding: 1px 3px;
  cursor: pointer;
}
.editor-spoiler.spoiler-selected {
  outline: 2px solid #243c5d;
}
.spoiler-inline {
  display: inline;
  white-space: pre-wrap;
  font-size: inherit;
}
.spoiler-toggle {
  display: inline !important;
  font: inherit !important;
  color: inherit !important;
  padding: 0 3px !important;
  margin: 0 !important;
  min-width: 0 !important;
  border: 1px solid currentColor !important;
  border-radius: 3px !important;
  background: transparent !important;
  vertical-align: baseline !important;
  cursor: pointer;
}
.spoiler-hidden {
  font: inherit;
  white-space: pre-wrap;
}
@media (max-width:700px) {
  .spoiler-tools {
    right: 6px;
    top: auto;
    bottom: 12px;
    width: 135px;
  }
  .spoiler-tools button {
    font-size: 11px;
  }
}

/* Compact, inline wiki-style spoiler display. Editor tools are unchanged. */

.inline-spoiler {
  font: inherit;
  color: inherit;
  text-align: left;
}
.inline-spoiler summary::-webkit-details-marker {
  display: none;
}

/* Expanded spoiler content appears below the toggle, not to its right. */

.inline-spoiler[open] .spoiler-revealed {
  display: block;
  margin-top: 3px;
}
.inline-spoiler[open] .spoiler-revealed::before {
  content: none;
}

/* Spoiler title: subdued gray, with explicit open/close state. */

.inline-spoiler .spoiler-revealed {
  font: inherit;
  white-space: pre-wrap;
  color: inherit;
}

/* Fixed labels for both collapsed and expanded spoiler states. */

.inline-spoiler summary::after {
  content: " 펼치기]" !important;
}
.inline-spoiler[open] summary::after {
  content: " 접기]" !important;
}

/* Restore triangle marker and subtly reduce only the spoiler toggle text. */

.inline-spoiler summary {
  display: inline;
  cursor: pointer;
  font: inherit;
  text-align: left;
  list-style: none;
  text-underline-offset: 2px;
  color: #777777 !important;
  text-decoration: underline;
  font-size: .92em !important;
  line-height: inherit;
}
.inline-spoiler summary::before {
  text-decoration: none;
  display: inline-block;
  content: "▸ [" !important;
}
.inline-spoiler[open] summary::before {
  content: "▾ [" !important;
}

/* Character profile links in editable text and saved profiles */

.editor-character-link {
  display: inline;
  background: #d2edff;
  color: #243c5d;
  border-radius: 4px;
  padding: 1px 3px;
  cursor: pointer;
}
.editor-character-link.link-selected {
  outline: 2px solid #243c5d;
}
.character-inline-link {
  color: #243c5d;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  font: inherit;
}
.character-inline-link:hover {
  color: #243c5d;
}
#linkCharacterLabel {
  display: block;
  margin-top: 10px;
}
#linkCharacterSelect {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 8px;
  border: 1px solid #a8d2f5;
  border-radius: 6px;
  background: white;
}

/* Detail navigation: previous on the left, edit/export on the right. */

#detailView .page-actions {
  justify-content: space-between;
  align-items: center;
}
#detailView #previousBtn {
  flex-shrink: 0;
}

/* Collapsible body sections: expanded initially to preserve the existing reading view. */

.body-section > .body-section-heading::-webkit-details-marker {
  display: none;
}
.body-section > .body-section-heading::before {
  content: "▾";
  display: inline-block;
  width: 19px;
  color: #6983a6;
  font-size: 13px;
  vertical-align: 1px;
}
.body-section:not([open]) > .body-section-heading::before {
  content: "▸";
}

/* Clean editor cards: no drag-and-drop controls. */

.body-section > .body-section-heading {
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  list-style: none;
  display: block;
  position: relative;
  padding-bottom: 10px;
  margin-bottom: 0;
}
.body-section[open] > .body-section-heading {
  border-bottom: 1px solid var(--line);
}
.format-toolbar {
  display: flex;
  gap: 5px;
}
.format-toolbar button {
  min-width: 34px;
  padding: 7px;
  background: #ffffff;
  border: 1px solid #a8d2f5;
  border-radius: 6px;
  cursor: pointer;
}
.format-toolbar button:hover {
  background: #d2edff;
}
.spoiler-tools .format-toolbar {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 8px;
  width: 100%;
}
.spoiler-tools .format-toolbar button {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  font-size: 14px;
  padding: 9px 5px;
}
.field-row {
  display: grid;
  grid-template-columns: 220px minmax(0,1fr) 46px;
  gap: 9px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px;
  background: #ffffff;
  box-sizing: border-box;
}
.field-row > .field-name {
  grid-column: 1;
  grid-row: 1;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.field-row > .rich-content {
  grid-column: 2;
  grid-row: 1;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.field-row > .remove-field {
  grid-column: 3;
  grid-row: 1;
  min-width: 0;
}
.section-row {
  display: block;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px;
  background: #ffffff;
}
.section-row-top {
  display: grid;
  grid-template-columns: minmax(0,1fr) 46px;
  gap: 9px;
  margin-bottom: 8px;
}
.section-row-top > .section-title-input {
  min-width: 0;
  grid-column: 1;
}
.section-row-top > .remove-section {
  grid-column: 2;
}
.section-row > .section-content-input {
  width: 100%;
  box-sizing: border-box;
}

/* Rich-text editing surfaces can be manually resized from the bottom-right corner. */

.section-row > .section-content-input.rich-content {
  resize: vertical;
  overflow: auto;
  min-height: 110px;
  height: 110px;
  max-height: 85vh;
}
@media (max-width:700px) {
}

/* Card-only PNG: export just the profile card at its normal desktop width. */

.png-export.png-export-card {
  width: 394px;
  box-sizing: border-box;
}
.png-export.png-export-card > .profile-card {
  width: 330px;
  max-width: 330px;
}

/* PNG export scope chooser */

.png-choice-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}
.png-choice-options button {
  min-width: 0;
  padding: 13px 8px;
  white-space: normal;
}
@media (max-width: 400px) {
  .png-choice-options {
    grid-template-columns: 1fr;
  }
}

/* Stable spoiler label for PNG capture; hidden text is not exported. */

.png-export .png-spoiler-label {
  display: inline;
  color: #777777;
  font-size: .92em;
  text-decoration: underline;
  white-space: nowrap;
}

/* Both exports button spans the full row of the chooser. */

.png-choice-options #pngSaveBoth {
  grid-column: 1 / -1;
  width: 100%;
}

/* Mobile/tablet editor layout: consistent title/content widths and buttons. */

@media (max-width: 900px) {
  .site-header nav {
    justify-content: flex-end;
    width: 100%;
    margin-top: 14px;
  }
  .site-header {
    flex-wrap: wrap;
  }
  .site-header nav button {
    flex: 0 0 auto;
  }
  .section-row > .section-content-input {
    width: 100%;
    max-width: 100%;
  }
}
@media (max-width:700px) {
  .site-header nav {
    justify-content: flex-end;
  }
  .field-row {
    grid-template-columns: minmax(0,1fr) 46px;
  }
  .field-row > .field-name {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    max-width: 220px;
  }
  .field-row > .remove-field {
    grid-column: 2;
    grid-row: 1;
  }
  .field-row > .rich-content {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }
  .section-row > .section-content-input {
    width: calc(100% - 55px);
  }
}
footer span {
  line-height: 1.8;
}

/* 중첩된 링크·스포일러·서식의 편집 표시 */

.editor-character-link,.editor-spoiler {
  cursor: text;
  white-space: pre-wrap;
}
#templateDialog select {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid #a8d2f5;
  border-radius: 8px;
  background: #ffffff;
}

/* Display body content without the previous indentation. */

.body-section > .body-content {
  padding-left: 0 !important;
  margin-left: 0 !important;
}

/* Mobile and iPad: profile-field and section content align with title inputs. */

@media (max-width: 900px) {
  .field-row {
    display: grid;
    grid-template-columns: minmax(0,1fr) 46px;
    gap: 9px;
    align-items: start;
  }
  .field-row > .field-name {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    max-width: none;
    min-width: 0;
  }
  .field-row > .remove-field {
    grid-column: 2;
    grid-row: 1;
  }
  .field-row > .rich-content {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .section-row-top {
    grid-template-columns: minmax(0,1fr) 46px;
    gap: 9px;
  }
  .section-row > .section-content-input,
  .section-row > .section-content-input.rich-content {
    width: calc(100% - 55px);
    max-width: calc(100% - 55px);
    min-width: 0;
  }
}
.help-dialog-card {
  max-width: 540px;
  width: min(540px,calc(100vw - 32px));
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.help-dialog-card h2 {
  margin: 0 0 12px;
  font-size: 20px;
}
.help-dialog-content {
  overflow-y: auto;
  line-height: 1.6;
}
.help-dialog-content p {
  margin: 0 0 16px;
}

/* 조합 추가 화면: 기존 캐릭터 편집 및 목록 스타일은 그대로 유지 */

.combo-choice-buttons {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 10px;
  margin: 18px 0;
}
.combo-choice-buttons button {
  min-height: 58px;
}
.combo-member-editor {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.combo-member-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) 42px;
  gap: 9px;
}
.combo-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.combo-section-head {
  display: grid;
  grid-template-columns: minmax(0,1fr) 42px;
  gap: 9px;
  margin-bottom: 9px;
}
.combo-section-head input {
  min-width: 0;
}
.combo-section textarea {
  display: block;
  width: 100%;
  min-height: 125px;
  resize: vertical;
  box-sizing: border-box;
}
#comboDetail {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
}
.combo-title {
  margin: 0 0 20px;
}
.combo-layout {
  display: grid;
  grid-template-columns: 330px minmax(0,1fr);
  gap: 22px;
  align-items: start;
}
.combo-members {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 8px;
  min-width: 0;
}
.combo-mini-card {
  border-radius: 9px;
  overflow: hidden;
  min-width: 0;
}
.combo-mini-name {
  padding: 10px 5px;
  text-align: center;
  font-weight: 700;
  background: var(--profile-color,#d2edff);
  overflow-wrap: anywhere;
}
.combo-mini-photo {
  aspect-ratio: 3/4;
  background: #d2edff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #6983a6;
}
.combo-mini-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
@media (max-width:700px) {
  .combo-layout {
    grid-template-columns: minmax(0,1fr);
  }
  .combo-members {
    max-width: 360px;
    width: 100%;
  }
  #comboDetail {
    padding: 14px;
  }
}

/* 목록 종류 필터 */

.list-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.list-filters button {
  border: 1px solid var(--line,#a8d2f5);
  border-radius: 10px;
  background: white;
  padding: 6px 12px;
  font-size: 13px;
  color: inherit;
  cursor: pointer;
}
.list-filters button.active {
  background: #d2edff;
  border-color: #a8d2f5;
  font-weight: 700;
}
.combo-list-card {
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.combo-list-card .card-info {
  padding: 14px;
  min-width: 0;
}
.combo-list-label {
  font-size: 12px;
  color: #6983a6;
}

/* Shared editor tools: a vertical tab attached to the panel's left edge. */
.tools-toggle {
  position: fixed;
  z-index: 41;
  right: 0;
  top: 35%;
  width: 42px;
  min-width: 42px;
  height: 62px;
  padding: 7px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1px solid #a8d2f5;
  border-radius: 10px 0 0 10px;
  background: #f1faff;
  color: #243c5d;
  box-shadow: none;
  isolation: isolate;
  cursor: pointer;
  line-height: 1;
  box-sizing: border-box;
}
/* Shadow is clipped at the panel seam so it cannot shade the panel. */
.tools-toggle::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: -4px 2px 10px #243c5d1a;
  clip-path: inset(-14px 0 -14px -14px);
  pointer-events: none;
  z-index: -1;
}
.tools-toggle:hover { background: #d2edff; }
.tools-toggle:focus-visible { outline: 2px solid #71afe8; outline-offset: 2px; }
.tools-toggle-icon {
  display: block;
  width: 100%;
  font-size: 25px;
  font-weight: 600;
  line-height: 25px;
  text-align: center;
  font-family: Arial, sans-serif;
}
.tools-toggle-label { display: block; font-size: 11px; font-weight: 700; line-height: 14px; white-space: nowrap; text-align: center; }
@media (max-width: 700px) {
  .tools-toggle { width: 40px; min-width: 40px; height: 58px; }
}

.combo-rich-content {
  min-height: 125px;
  max-height: none;
  resize: vertical;
  overflow: auto;
  box-sizing: border-box;
  width: 100%;
  border: 1px solid var(--line,#a8d2f5);
  border-radius: 9px;
  padding: 12px;
  background: #ffffff;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline-offset: 2px;
}
.combo-rich-content:empty::before {
  content: attr(data-placeholder);
  color: #777777;
  pointer-events: none;
}
@media (max-width:700px) {
}

/* Combo profile and list adjustments */

.character-list {
  grid-template-columns: repeat(2,minmax(0,1fr));
}
.character-card {
  min-height: 96px;
  height: 110px;
  align-items: stretch;
}
.character-card .card-image {
  width: 92px;
  min-width: 92px;
  aspect-ratio: auto;
}
.character-card .card-info {
  flex: 1;
  justify-content: space-between;
  padding: 12px;
}
.list-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.list-card-top h3 {
  margin: 0;
  overflow-wrap: anywhere;
}
.list-type-label {
  font-size: 12px;
  color: #6983a6;
  flex-shrink: 0;
}
.list-modified {
  line-height: 1.45;
  overflow-wrap: anywhere;
  font-size: 12px;
  color: #777777;
  margin-top: auto;
}
.combo-profile-card .profile-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.combo-members-bottom {
  display: grid;
  grid-template-columns: repeat(8,minmax(0,1fr));
  gap: 9px;
  margin-top: 22px;
}
.combo-members-bottom .combo-mini-card {
  display: block;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  background: white;
}
.combo-members-bottom .combo-mini-photo {
  aspect-ratio: 3/4;
}
.combo-members-bottom .combo-mini-name {
  padding: 6px 3px;
  font-size: 12px;
  background: #d2edff;
}
@media (max-width:700px) {
  .character-list {
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 9px;
  }
  .character-card {
    height: 100px;
    min-height: 100px;
  }
  .character-card .card-image {
    width: 64px;
    min-width: 64px;
  }
  .character-card .card-info {
    padding: 8px;
  }
  .list-card-top {
    flex-wrap: wrap;
    gap: 2px;
  }
  .list-card-top h3 {
    font-size: 13px;
  }
  .list-type-label,.list-modified {
    font-size: 10px;
  }
  .combo-members-bottom {
    grid-template-columns: repeat(4,minmax(0,1fr));
  }
}

/* Match character selector with template selector styling */

.combo-member-row select {
  min-width: 0;
  width: 100%;
  appearance: auto;
  background: #ffffff;
  border: 1px solid #a8d2f5;
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 48px;
  font-size: 15px;
  color: #243c5d;
}
.combo-member-row button {
  border: 1px solid #a8d2f5;
  border-radius: 10px;
  background: #ffffff;
}
.combo-profile-card .profile-photo {
  aspect-ratio: 3/4;
  height: auto !important;
}
.combo-editor-top .combo-image-preview {
  aspect-ratio: 4/3 ;
}

/* Requested mobile header alignment */

@media (max-width:900px) {
  .site-header nav {
    justify-content: flex-start ;
  }
}

/* Combo member names beneath list title */

.list-title-group {
  min-width: 0;
  flex: 1;
}
.list-combo-members {
  font-size: 12px;
  color: #6983a6;
  margin-top: 4px;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
}
@media (max-width:700px) {
  .list-combo-members {
    font-size: 10px;
  }
}

/* Detail history navigation */

.page-actions > button + button {
  margin-left: 5px;
}

/* 이전/다음 이동 버튼은 한 그룹으로 묶어 왼쪽에 정렬 */

.page-actions .history-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
#detailView .page-actions, #comboDetailView .page-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
#detailView .page-actions .detail-buttons,#comboDetailView .page-actions .detail-buttons {
  margin-left: auto;
}
.setting-profile-card .profile-content {
  padding-top: 0;
}

/* 두 명 이하 조합의 구성원은 왼쪽 설정표 바로 아래에 표시 */

.combo-profile-card .combo-members-inline {
  grid-template-columns: repeat(2,minmax(0,1fr));
  margin: 12px 0 0;
  gap: 9px;
}
.combo-profile-card .combo-members-inline .combo-mini-card {
  min-width: 0;
}

/* 1~2인 조합 카드: 프로필 표의 그리드에서 분리하여 표 열 너비 유지 */

.combo-profile-card > .combo-members-inline {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 9px;
  margin: 12px 10px 12px;
  min-width: 0;
}
.combo-profile-card > .combo-members-inline .combo-mini-card {
  min-width: 0;
}

/* 1~2인 조합: 프로필 카드 바깥, 왼쪽 열 바로 아래에 별도 카드 배치 */

.combo-left-column {
  min-width: 0;
  width: 330px;
  max-width: 100%;
}
.combo-left-column > .combo-profile-card {
  width: 100%;
  max-width: 100%;
}
.combo-left-column > .combo-members-inline {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 12px;
  margin: 18px 0 0;
  min-width: 0;
}
.combo-left-column > .combo-members-inline .combo-mini-card {
  min-width: 0;
}
@media (max-width:700px) {
  .combo-left-column {
    width: 330px;
    max-width: 100%;
  }
}
.welcome-dialog-card {
  width: min(430px,95vw);
  line-height: 1.65;
}
.welcome-dialog-card h2 {
  margin-top: 0;
}

/* Mobile detail actions: retain normal button sizing, move only the row. */

@media (max-width:700px) {
  #detailView .page-actions,
  #comboDetailView .page-actions,
  #relationshipDetailView .page-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  #detailView .page-actions .history-controls,
  #comboDetailView .page-actions .history-controls,
  #relationshipDetailView .page-actions .history-controls {
    align-self: flex-start;
  }
  #detailView .page-actions .detail-buttons,
  #comboDetailView .page-actions .detail-buttons,
  #relationshipDetailView .page-actions .detail-buttons {
    margin: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }
  #detailView .page-actions .detail-buttons > button,
  #comboDetailView .page-actions .detail-buttons > button,
  #relationshipDetailView .page-actions .detail-buttons > button {
    font-size: 14px;
    padding: 10px 14px;
    min-height: 40px;
    flex: 0 0 auto;
  }
}

/* Gallery: same card rhythm as the existing document editor. */

.wiki-gallery-editor-items {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}
.wiki-gallery-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px;
  border: 1px solid #a8d2f5;
  border-radius: 10px;
}
.wiki-gallery-item img {
  width: 90px;
  height: 90px;
  object-fit: contain;
}
.wiki-gallery-item button {
  min-width: 30px;
}
.wiki-gallery-upload {
  display: inline-block;
  padding: 10px 16px;
  background: #d2edff;
  border-radius: 8px;
  cursor: pointer;
}
.wiki-gallery-upload input {
  display: none;
}
.wiki-gallery {
  margin-top: 24px;
  padding: 16px;
  border: 1px solid #a8d2f5;
  border-radius: 12px;
}
.wiki-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill,minmax(140px,1fr));
  gap: 12px;
}
.wiki-gallery-grid figure {
  margin: 0;
}
.wiki-gallery-grid img {
  width: 100%;
  height: auto;
  max-height: 400px;
  object-fit: contain;
}

/* Gallery matches the document section border color and weight. */

#detailView .wiki-gallery,#comboDetailView .wiki-gallery,.wiki-png-export .wiki-gallery {
  border: 1.5px solid var(--section-border-color,#a8d2f5);
  border-radius: 12px;
  background: transparent;
}
.wiki-gallery-grid [data-gallery-preview] {
  cursor: zoom-in;
}
.wiki-gallery-lightbox,.wiki-png-choice-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  background: rgba(0, 0, 0, .85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
}
.wiki-gallery-lightbox img {
  max-width: 95vw;
  max-height: 90vh;
  width: auto;
  height: auto;
  object-fit: contain;
}
.wiki-gallery-lightbox button {
  position: absolute;
  top: 16px;
  right: 16px;
}
.wiki-png-choice-panel {
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: white;
  color: #243c5d;
  border-radius: 14px;
  padding: 22px;
  min-width: min(320px,90vw);
  max-height: 90vh;
  overflow: auto;
}
.wiki-png-choice-panel button {
  padding: 11px;
  border-radius: 8px;
}

/* Selected PNG subsets must not reserve the original two-column layout. */

.wiki-png-export .profile-layout:has(> .profile-body:only-child) {
  grid-template-columns: minmax(0,1fr);
}
.wiki-png-export .profile-layout:has(> .profile-card:only-child) {
  grid-template-columns: minmax(0,1fr);
}
.wiki-png-export .profile-layout:has(> .combo-left-column:only-child) {
  grid-template-columns: minmax(0,1fr);
}
#comboEditorView .wiki-gallery-upload.add-field,
#editorView .wiki-gallery-upload.add-field {
  display: flex;
  width: 100%;
  min-height: 56px;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-sizing: border-box;
  font: inherit;
  font-size: 16px;
  color: #243c5d;
  background: #d2edff;
  border: 1px solid #a8d2f5;
  border-radius: 12px;
  cursor: pointer;
}

/* The setting photo editor uses the exact same layout as the character photo editor.
   Only its Remove Image button differs: it fills the photo column. */

#comboEditorView.setting-mode .combo-editor-top {
  display: grid;
  grid-template-columns: 220px minmax(0,1fr);
  gap: 22px;
  margin-bottom: 30px;
  align-items: start;
}
#comboEditorView.setting-mode .combo-editor-top > .image-editor {
  width: 220px;
  max-width: 100%;
  min-width: 0;
}
#comboEditorView.setting-mode .combo-editor-top .image-preview {
  aspect-ratio: 3/4;
  width: 100%;
}
#comboEditorView.setting-mode .combo-editor-top .photo-adjust-controls {
  display: grid;
  gap: 9px;
  align-content: start;
}
#comboEditorView.setting-mode .combo-editor-top .photo-adjust-controls label {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 8px;
  row-gap: 4px;
  margin: 0;
  padding: 0;
  font-size: 13px;
  line-height: 1.35;
}
#comboEditorView.setting-mode .combo-editor-top .photo-adjust-controls label input[type="range"] {
  grid-column: 1/-1;
  grid-row: 2;
  display: block;
  width: 100%;
  height: 20px;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
}
#comboEditorView.setting-mode #comboRemoveImage {
  display: block;
  width: 100%;
  box-sizing: border-box;
}
@media(max-width:700px) {
  #comboEditorView.setting-mode .combo-editor-top {
    grid-template-columns: minmax(0,1fr);
  }
}

/* Both document editors use the same image removal width and ratio selector. */

#editorView #removeImage,
#comboEditorView.setting-mode #comboRemoveImage {
  display: block;
  width: 100%;
  box-sizing: border-box;
}
#editorView .photo-ratio-label,
#comboEditorView.setting-mode .photo-ratio-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0 12px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  white-space: normal;
}
#editorView .photo-ratio,
#comboEditorView.setting-mode .photo-ratio {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  box-sizing: border-box;
  border: 1px solid #a8d2f5;
  border-radius: 9px;
  background: #ffffff;
  color: inherit;
  font: inherit;
}

/* Match gallery upload exactly to the document add buttons. */

#editorView .wiki-gallery-upload.add-field,#comboEditorView .wiki-gallery-upload.add-field {
  display: block;
  width: 100%;
  height: auto;
  min-height: 0;
  margin-top: 14px;
  padding: 12px 15px;
  line-height: normal;
  font: inherit;
  text-align: center;
  background: #d2edff;
  color: #243c5d;
  border: 1px solid #a8d2f5;
  border-radius: 12px;
  box-sizing: border-box;
}

/* List thumbnail uses the saved photo crop, clipped by the thumbnail frame. */

.character-card .card-image {
  overflow: hidden;
  position: relative;
}
.character-card .card-image img:not(.rel-list-thumbnail) {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center center;
}

/* List photos fill the thumbnail without empty bars; saved offsets remain applied. */

.character-card .card-image img:not(.rel-list-thumbnail) {
  object-fit: cover;
}

/* Document thumbnail: crop the editor's virtual frame, without cover re-zoom. */

.character-card .card-image > img:not(.rel-list-thumbnail) {
  max-width: none;
  max-height: none;
  object-fit: contain;
}

/* Link picker uses the same document-choice cards as the folder editor. */
#linkCharacterLabel .link-document-controls{display:flex;gap:8px;align-items:end;margin:10px 0;}
#linkCharacterLabel .link-document-controls input{min-width:0;flex:1;}
#linkDocumentChoices{max-height:320px;overflow-y:auto;}
#linkDocumentChoices .folder-choice-kind{font-size:12px;color:#6983a6;}
#linkCharacterSelect.hidden{display:none;}

/* Relationship add picker reuses the folder document choice UI. */
#relActionDialog .link-document-controls{display:flex;gap:8px;align-items:end;margin:10px 0;}
#relActionDialog .link-document-controls input{min-width:0;flex:1;}
#relActionDialog #relAddDocumentChoices{max-height:280px;overflow:auto;}

/* Restore folder-picker card layout inside the relationship action dialog.
   The dialog's generic form rules otherwise stretch each radio to full width. */
#relActionDialog #relAddDocumentChoices .folder-document-choice{
  display:flex;
  flex-direction:row;
  align-items:center;
  gap:12px;
  min-height:54px;
  padding:12px 14px;
  margin:0;
}
#relActionDialog #relAddDocumentChoices .folder-document-choice input[type="radio"]{
  display:block;
  width:17px;
  min-width:17px;
  height:17px;
  min-height:17px;
  flex:0 0 17px;
  padding:0;
  margin:0;
  accent-color:var(--accent);
}
#relActionDialog #relAddDocumentChoices .folder-choice-name{flex:1;min-width:0;}
#relActionDialog #relPopupCharacter.hidden{display:none;}
#relActionDialog .link-document-controls{min-width:0;}
#relActionDialog .link-document-controls .wiki-filter-field{min-width:0;flex:1;}
#relActionDialog .link-document-controls #relAddDocumentSearch{min-width:0;flex:1;}
