* {
  box-sizing: border-box;
}
:root {
  --bg: #f1faff;
  --card: #ffffff;
  --text: #243c5d;
  --muted: #6983a6;
  --line: #a8d2f5;
  --accent: #71afe8;
  --danger: #a82d36;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
}
button, input, textarea {
  font: inherit;
}
button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  border-radius: 8px;
  padding: 9px 13px;
  cursor: pointer;
}
button:hover {
  filter: brightness(.97);
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
button.danger {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}
button.small {
  font-size: 12px;
  padding: 6px 8px;
}
.site-header {
  max-width: 1050px;
  margin: auto;
  padding: 28px 20px 18px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  border-bottom: 1px solid var(--line);
}
.site-header nav {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
main {
  max-width: 1050px;
  margin: auto;
  padding: 22px 20px 40px;
}
.view {
  min-height: 55vh;
}
.hidden {
  display: none !important;
}
.toolbar input {
  flex: 1;
}
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 8px;
  padding: 10px;
  color: var(--text);
  outline: none;
}
input:focus, textarea:focus {
  border-color: var(--accent);
}
.character-list {
  display: grid;
  gap: 14px;
}
.character-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
}
.card-image {
  width: 105px;
  min-width: 105px;
  aspect-ratio: 3 / 4;
  background: #d2edff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.no-image {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 10px;
}
.card-info {
  padding: 15px 14px;
  min-width: 0;
}
.card-info p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}
.empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}
.page-actions {
  display: flex;
  justify-content: space-between;
  margin: 8px 0 15px;
}
.editor {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
}
.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.main-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
}
label input, label textarea {
  margin-top: 6px;
  font-weight: 400;
}
.color-picker-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}
.color-picker-row input[type="color"] {
  width: 58px;
  height: 42px;
  padding: 3px;
  cursor: pointer;
  flex: 0 0 58px;
  margin-top: 0;
}
.color-picker-row .color-hex-input {
  width: 150px;
  max-width: 100%;
  margin-top: 0;
  text-transform: uppercase;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.color-help {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}
.editor-section {
  border-top: 1px solid var(--line);
  margin-top: 28px;
  padding-top: 22px;
}
.editor-section-title {
  margin-bottom: 15px;
}
.editor-section-title h3 {
  margin: 0 0 4px;
  font-size: 17px;
}
.editor-section-title span {
  color: var(--muted);
  font-size: 12px;
}
.fields, .sections {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.field-row textarea {
  min-height: 75px;
  resize: vertical;
}
.remove-field, .remove-section {
  padding: 9px 0;
}
.add-field {
  margin-top: 14px;
  border-style: dashed;
  width: 100%;
}
.profile-name {
  background: var(--profile-color, #a8d2f5);
  color: #ffffff;
  text-align: center;
  padding: 13px 10px 11px;
}
.profile-name h2 {
  margin: 0;
  font-size: 21px;
  overflow-wrap: anywhere;
}
.profile-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.profile-photo-empty {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}
.detail-summary {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.6;
}
.detail-buttons {
  display: flex;
  gap: 7px;
}
.png-export {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1050px;
  background: #ffffff;
  padding: 32px;
}
@media (max-width: 700px) {
  .site-header {
    display: block;
    padding-top: 20px;
  }
  .site-header nav {
    justify-content: flex-start;
    margin-top: 15px;
  }
  .image-preview {
    width: 170px;
  }
  .section-row-top {
    grid-template-columns: 1fr 38px;
  }
  .form-actions {
    grid-template-columns: 1fr 1fr;
  }
  .form-actions span {
    display: none;
  }
  .form-actions .danger {
    grid-column: 1 / 3;
  }
  footer span {
    display: block;
    margin: 3px 0;
  }
}

/* Sky-blue theme and responsive profile arrangement */

.site-header h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: .08em;
  color: #71afe8;
}
.character-card:hover {
  border-color: #a8d2f5;
}
#detail, #categoryDetailBody {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  background: #ffffff;
}
#detail, #detail * {
  text-indent: 0;
}
#detail ul, #detail ol {
  padding-left: 0;
  margin-left: 0;
  list-style-position: inside;
}
@media (min-width: 701px) {
  .profile-content {
    grid-template-columns: minmax(220px, 38%) minmax(0, 1fr);
  }
  .profile-photo {
    height: auto;
    aspect-ratio: 3 / 4;
  }
  .profile-table {
    align-self: start;
  }
  .profile-table tr:first-child th, .profile-table tr:first-child td {
    border-top: 0;
  }
}
@media (max-width: 700px) {
  #detail {
    padding: 14px;
  }
  .profile-content {
    grid-template-columns: 1fr;
  }
}

/* Reference sky blue: #a8d2f5, heading blue: #71afe8 */

/* Final layout: original side-by-side card and body */

.profile-layout {
  justify-content: flex-start;
  width: 100%;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
.profile-card {
  background: #ffffff;
  border: 1.5px solid var(--profile-color, #a8d2f5);
  border-radius: 10px;
  overflow: hidden;
  width: 330px;
  max-width: 100%;
}
.profile-content {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  display: block;
}
.profile-photo {
  background: #d2edff;
  overflow: hidden;
  min-width: 0;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
}
.profile-name, .profile-table th {
  color: var(--profile-contrast, #000000);
}
.profile-name p {
  margin: 4px 0 0;
  font-size: 12px;
  opacity: .9;
  color: inherit;
}
.profile-table, .body-content {
  font-size: 13px;
}
.profile-body {
  min-width: 0;
}
.body-section {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 15px;
  background: #ffffff;
}
.body-section h3 {
  font-size: 16px;
  margin: 0 0 10px;
}
.body-content {
  white-space: pre-wrap;
  line-height: 1.55;
  overflow-wrap: anywhere;
  color: #000000;
}
.section-content-input {
  min-height: 110px;
  resize: vertical;
}
footer {
  max-width: 1050px;
  margin: auto;
  padding: 0 20px 25px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  text-align: right;
}
@media (max-width: 700px) {
  .profile-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }
  .profile-card {
    width: 330px;
    max-width: 100%;
  }
  .profile-content {
    display: block;
  }
  footer {
    display: flex;
    justify-content: flex-end;
    text-align: right;
  }
}

/* Compact profile information rows */

.profile-table tr {
  height: auto;
}

/* Profile rows: compact, no HTML-template indentation */

.profile-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 0;
  table-layout: fixed;
  border-spacing: 0;
}
.profile-table th, .profile-table td {
  border-top: 1px solid var(--profile-color, #a8d2f5);
  overflow-wrap: anywhere;
  padding: 5px 8px;
  height: auto;
  vertical-align: top;
  line-height: 1.45;
  text-indent: 0;
}
.profile-table td {
  background: #ffffff;
  line-height: 1.55;
  color: #000000;
  padding-left: 8px;
  text-align: left;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

/* 편집 화면: 사진과 파일 선택 너비 일치 */

.image-editor {
  width: 220px;
  max-width: 100%;
}
.image-preview {
  aspect-ratio: 3 / 4;
  background: #d2edff;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  overflow: hidden;
  margin-bottom: 8px;
  width: 100%;
}
.image-editor input[type="file"] {
  font-size: 12px;
  margin-bottom: 5px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.editor-top {
  display: grid;
  gap: 22px;
  margin-bottom: 30px;
  grid-template-columns: 220px minmax(0, 1fr);
}

/* 저장 버튼을 한 줄 전체 너비로 */

.form-actions button[type="submit"] {
  width: 100%;
}

/* 프로필 항목명 가운데 정렬 */

/* 목록에서는 이름만 표시 */

.card-info h3 {
  margin: 0 0 7px;
  font-size: 17px;
  margin-bottom: 0;
}
@media (max-width: 700px) {
  .editor-top {
    grid-template-columns: minmax(0, 1fr);
  }
  .image-editor {
    width: 220px;
  }
  .form-actions {
    display: flex;
    flex-direction: column;
  }
  .form-actions .danger {
    align-self: flex-start;
  }
}

/* 수정 시 삭제/저장 1:1, 새 캐릭터는 저장 전체 너비 */

.form-actions {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  flex-direction: column;
  display: grid ;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.form-actions button {
  width: 100% !important;
  min-width: 0;
}
.form-actions .danger {
  align-self: stretch;
}
.form-actions .danger.hidden + button[type="submit"] {
  grid-column: 1 / -1;
}

/* 항목 이름은 두 줄 이상에서도 수직·수평 중앙 */

.profile-table th {
  background: var(--profile-color, #a8d2f5);
  color: #ffffff;
  font-weight: 600;
  letter-spacing: .01em;
  width: 29%;
  padding-left: 5px;
  padding-right: 5px;
  vertical-align: middle !important;
  text-align: center !important;
}

/* 검색 및 정렬 */

.toolbar {
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}
#sortSelect {
  min-width: 120px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #ffffff;
  color: inherit;
  font: inherit;
}
#countText {
  white-space: nowrap;
  margin-left: auto;
}
.profile-modified-date {
  margin-top: 12px;
  text-align: right;
  font-size: 11px;
  color: #6983a6;
  line-height: 1.5;
}

/* 편집 화면의 항목 이름 칸을 사진 입력 영역 너비에 맞춤 */

@media (max-width: 700px) {
}

/* 프로필 편집: 항목 이름 입력칸을 사진 선택 영역(220px)과 동일하게 */

.field-row .field-name {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
@media (max-width: 700px) {
  .field-row {
    grid-template-columns: minmax(0, 1fr) 38px;
  }
  .field-row .field-name {
    grid-column: 1 / -1;
    width: min(220px, 100%);
  }
}

/* 상세 프로필의 수정 및 PNG 저장 버튼을 항상 우측 정렬 */

#detailView .page-actions {
  display: flex;
  width: 100%;
}
#detailView .detail-buttons {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* 제목과 부제의 시각적 시작 위치를 미세 조정 */

.site-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  padding-left: 2px;
}
