:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --line: #e3e6eb;
  --text: #191c21;
  --sub: #5b6270;
  --brand: #1d4ed8;
  --brand-weak: #e8eefc;
  --ok: #15803d;
  --ok-weak: #e7f6ec;
  --bad: #b42318;
  --bad-weak: #fdecea;
  --warn: #a15c07;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand); }

/* ---- 상단 ---- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.top-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 24px; height: 60px;
}
.logo { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo img { width: 24px; height: 24px; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  padding: 8px 14px; border-radius: 8px; text-decoration: none; color: var(--sub); font-weight: 600; white-space: nowrap;
}
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--brand-weak); color: var(--brand); }
.me { color: var(--sub); font-size: 14px; white-space: nowrap; }

main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 80px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; flex: 1; }
.page-head .back { text-decoration: none; color: var(--sub); font-weight: 600; }

/* ---- 버튼·입력 ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 9px 16px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f8f9fb; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1a44be; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 14px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
.input, select.input {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; width: 100%;
}
.input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.code-input { font-size: 28px; letter-spacing: .3em; text-transform: uppercase; text-align: center; font-weight: 700; }
.hint { color: var(--sub); font-size: 13px; }
.error { color: var(--bad); font-size: 14px; min-height: 20px; }

/* ---- 카드 ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}
.card.link { cursor: pointer; }
.card.link:hover { border-color: #c5ccd8; }
.thumb {
  aspect-ratio: 16 / 9; background: #20242c center / cover no-repeat; position: relative;
  display: flex; align-items: center; justify-content: center; color: #8a93a3; font-size: 14px;
}
.thumb .badge-type {
  position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, .65); color: #fff;
  border-radius: 6px; padding: 1px 7px; font-size: 13px;
}
.card-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-title { font-weight: 700; font-size: 16px; word-break: break-all; }
.card-sub { color: var(--sub); font-size: 14px; }
.card-actions { display: flex; gap: 6px; padding: 0 16px 14px; flex-wrap: wrap; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; border-radius: 999px; padding: 2px 10px; width: fit-content; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-weak); color: var(--ok); }
.pill.bad { background: var(--bad-weak); color: var(--bad); }

.empty {
  background: var(--surface); border: 1px dashed #c9cfd9; border-radius: var(--radius);
  padding: 48px 20px; text-align: center; color: var(--sub);
}
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }

/* ---- 표 ---- */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 14px; color: var(--sub); background: #fafbfc; font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }

/* ---- 재생목록 편집 ---- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 16px; margin: 0; flex: 1; }
.panel-body { padding: 16px; }
.items { list-style: none; margin: 0; padding: 0; }
.item {
  display: grid; grid-template-columns: 28px 96px minmax(0, 1fr) auto auto; gap: 12px; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.item:last-child { border-bottom: 0; }
.item.dragging { opacity: .4; }
.item.drop-before { box-shadow: inset 0 3px 0 var(--brand); }
.item .grip { cursor: grab; color: #9aa3b2; text-align: center; font-size: 18px; user-select: none; }
.item .mini { width: 96px; aspect-ratio: 16 / 9; border-radius: 6px; background: #20242c center / cover no-repeat; }
.item .name { font-weight: 600; word-break: break-all; }
.item .meta { color: var(--sub); font-size: 14px; }
.item .sec { display: flex; align-items: center; gap: 6px; color: var(--sub); font-size: 14px; }
.item .sec input { width: 64px; padding: 6px 8px; text-align: right; }
.item .moves { display: flex; gap: 2px; }
.savebar {
  position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line);
  padding: 12px 16px; display: flex; gap: 10px; align-items: center; border-radius: 0 0 var(--radius) var(--radius);
}
.savebar .status { flex: 1; color: var(--sub); font-size: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--sub); }
.kv dd { margin: 0; font-weight: 600; }

/* ---- 업로드 ---- */
.drop {
  border: 2px dashed #c3cad6; border-radius: var(--radius); background: var(--surface);
  padding: 28px; text-align: center; color: var(--sub); margin-bottom: 20px;
}
.drop.over { border-color: var(--brand); background: var(--brand-weak); }
.drop strong { color: var(--text); display: block; font-size: 17px; margin-bottom: 4px; }
.uploads { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.upload { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.upload-row { display: flex; gap: 10px; align-items: center; }
.upload-row .n { flex: 1; font-weight: 600; word-break: break-all; }
.upload-row .p { color: var(--sub); font-size: 14px; white-space: nowrap; }
.bar { height: 6px; background: var(--bg); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .3s; }
.upload.done .bar > i { background: var(--ok); }
.upload.failed .bar > i { background: var(--bad); }

/* ---- 모달 ---- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15, 20, 30, .45); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 460px; max-height: calc(100vh - 32px);
  display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.modal.wide { max-width: 860px; }
.modal-head { padding: 18px 20px 6px; font-size: 18px; font-weight: 700; }
.modal-body { padding: 12px 20px; overflow: auto; }
.modal-foot { padding: 14px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.pick { border: 2px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; background: #fff; text-align: left; padding: 0; }
.pick.on { border-color: var(--brand); }
.pick .thumb { border-radius: 0; }
.pick .pn { padding: 6px 8px; font-size: 14px; font-weight: 600; word-break: break-all; }
.pick .check {
  position: absolute; right: 6px; top: 6px; width: 24px; height: 24px; border-radius: 50%;
  background: rgba(255, 255, 255, .9); border: 2px solid #c3cad6;
}
.pick.on .check { background: var(--brand); border-color: var(--brand); }
.pick.on .check::after { content: "✓"; color: #fff; font-size: 14px; font-weight: 700; display: block; text-align: center; line-height: 20px; }

/* ---- 로그인 ---- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 32px 28px; width: 100%; max-width: 380px; }
.auth h1 { margin: 0 0 20px; font-size: 22px; display: flex; gap: 8px; align-items: center; }
.auth h1 img { width: 28px; }
.auth .btn { width: 100%; margin-top: 6px; padding: 12px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #1f2430; color: #fff; padding: 11px 18px; border-radius: 10px; opacity: 0;
  transition: all .2s; pointer-events: none; z-index: 100; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); }

.section-title { font-size: 17px; margin: 28px 0 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; }
  .item { grid-template-columns: 24px 72px minmax(0, 1fr); }
  .item .mini { width: 72px; }
  .item .sec, .item .moves { grid-column: 3; }
  .top-inner { gap: 12px; }
  .me { display: none; }
}
[data-preview] { cursor: pointer; }
