* { box-sizing: border-box; }

:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2330;
  --muted: #6b7686;
  --line: #e3e7ee;
  --accent: #2f6fed;
  --accent-soft: #e8effd;
  --badge: #1f8a5b;
  --badge-soft: #e6f5ee;
}

body {
  margin: 0;
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 10px;
  padding: 14px 22px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { margin: 0; font-size: 19px; white-space: nowrap; line-height: 1.3; }
.topbar h1 a { color: var(--text); text-decoration: none; }

@media (max-width: 480px) {
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 13px; flex: 1 1 100%; white-space: normal; }
  /* 새로고침은 왼쪽 끝, 나머지 버튼은 오른쪽 끝 — 제목·본문의 좌우 여백과 열을 맞춤 */
  .topbar-actions { flex: 1 1 100%; justify-content: space-between; }
  .topbar-actions .link-group { display: flex; gap: 8px; }
  .admin-link { padding: 7px 10px; font-size: 13px; }
}
.admin-link {
  font-size: 14px;
  color: var(--accent);
  text-decoration: none;
  padding: 7px 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  white-space: nowrap;
}
.admin-link:hover { background: var(--accent-soft); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  position: relative;
  font-size: 17px;
  line-height: 1;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
  color: var(--text);
}
.icon-btn:hover { background: var(--bg); }
.icon-btn .icon { display: inline-block; vertical-align: middle; }

/* 새 데이터가 있으면 테두리를 강조 색으로 바꾸고, 반짝이는 점을 표시 */
.icon-btn.has-update { border-color: var(--accent); color: var(--accent); }
.icon-btn .update-dot { display: none; }
.icon-btn.has-update .update-dot {
  display: block;
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: sparkle 1.4s ease-out infinite;
}
@keyframes sparkle {
  0% { box-shadow: 0 0 0 0 rgba(47, 111, 237, .55); }
  70% { box-shadow: 0 0 0 8px rgba(47, 111, 237, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 111, 237, 0); }
}

/* 로딩 중에는 아이콘을 감추고 색이 맞춰진 원형 스피너로 교체함 */
.icon-btn .spinner { display: none; }
.icon-btn.spinning .icon { display: none; }
.icon-btn.spinning .spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  vertical-align: middle;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

main { max-width: 1100px; margin: 0 auto; padding: 22px; }

.controls { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
#searchInput {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
#searchInput:focus { outline: 2px solid var(--accent); border-color: transparent; }

.key-filter { display: flex; flex-wrap: wrap; gap: 6px; }
.key-filter button {
  padding: 6px 12px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
.key-filter button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.song-count { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.card {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow .15s, transform .15s;
}
.card:hover { box-shadow: 0 6px 18px rgba(20, 40, 90, .12); transform: translateY(-2px); }
.thumb {
  height: 180px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.no-img { color: var(--muted); font-size: 13px; }
.card-body { padding: 12px 14px; }
.card-title { font-weight: 600; font-size: 15px; margin-bottom: 8px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }

.key-badge {
  background: var(--badge-soft);
  color: var(--badge);
  font-weight: 700;
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 999px;
}
.tag {
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
}

.empty { color: var(--muted); text-align: center; padding: 50px 0; grid-column: 1 / -1; }

/* ---- 상세 화면 ---- */
.back-link { display: inline-block; margin-bottom: 14px; color: var(--accent); text-decoration: none; font-size: 14px; }
.detail-head { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.detail-head h2 { margin: 0 0 10px; font-size: 24px; }
.detail-head-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 10px; }
.detail-head-actions { display: flex; gap: 8px; flex-shrink: 0; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 6px; }

.detail-section { margin-bottom: 20px; }
.detail-section h3 { font-size: 15px; color: var(--muted); margin: 0 0 10px; }

.yt-wrap { position: relative; padding-top: 56.25%; border-radius: 12px; overflow: hidden; background: #000; }
.yt-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.related-list { display: flex; flex-wrap: wrap; gap: 8px; }
.related-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
}
.related-chip:hover { border-color: var(--accent); }

.sheet {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 14px;
}
.sheet img { display: block; width: 100%; }
.sheet-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.dl-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}
.dl-btn:hover { opacity: .9; }

/* ---- 관리 페이지 ---- */
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab-btn {
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.empty-hint { color: var(--muted); text-align: center; padding: 40px 16px; }

.admin-layout { display: grid; grid-template-columns: 320px 1fr; gap: 18px; align-items: start; }
.admin-layout[hidden] { display: none; }
@media (max-width: 800px) { .admin-layout { grid-template-columns: 1fr; } }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.panel h2 { margin: 0 0 14px; font-size: 17px; }
.panel h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); }

details.settings { margin-bottom: 18px; }
details.settings summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.password-status { font-weight: 400; font-size: 13px; margin-left: 8px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  font-size: 14px;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
.btn.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: #d64545; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 6px 12px; font-size: 13px; text-decoration: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

#adminSongList { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
#adminSongList li {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
}
#adminSongList li:hover { background: var(--accent-soft); }
#adminSongList li.selected { background: var(--accent-soft); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 13px;
}
.chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 14px; padding: 0; }

.img-previews { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.img-previews figure {
  margin: 0;
  width: 110px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}
.img-previews img { width: 100%; height: 140px; object-fit: cover; object-position: top; display: block; }
.img-previews figcaption { font-size: 11px; padding: 4px 6px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.img-previews .remove-img {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,.55); color: #fff;
  border: 0; border-radius: 999px; width: 22px; height: 22px; cursor: pointer;
}

#statusLog {
  margin-top: 16px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  min-height: 40px;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-family: -apple-system, "Malgun Gothic", sans-serif;
  line-height: 1.6;
}
#statusLog:empty::before { content: "작업 로그가 여기에 표시됩니다."; color: #5d6b85; }

/* ---- 드래그 앤 드롭 ---- */
.dropzone {
  position: relative;
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  background: #fff;
  transition: border-color .15s, background .15s;
}
.dropzone p { margin: 0 0 6px; font-size: 14px; }
.dropzone p span { color: var(--accent); text-decoration: underline; }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }

/* 파일 입력을 숨기지 않고 드롭존 전체를 덮는 투명 레이어로 둠 —
   숨긴 input에 click()을 위임하는 방식은 일부 모바일 브라우저(iOS Safari 등)에서
   파일 선택창이 열리지 않는 경우가 있어, 탭이 input에 직접 전달되도록 함 */
.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
