:root {
  --bg: #0e0f12;
  --panel: #16181d;
  --panel-2: #1d2027;
  --line: #2a2e37;
  --text: #e8eaee;
  --muted: #9aa0ad;
  --accent: #4f7cff;
  --accent-soft: rgba(79, 124, 255, 0.16);
  --gold: #ffc844;
  --danger: #ff5f56;
  --radius: 12px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Pretendard', 'Apple SD Gothic Neo', 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

/* ───────────── 공통 컴포넌트 ───────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #262a33; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #6389ff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #492a2a; }
.btn.danger:hover { background: #2a1a1a; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 64px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ───────────── 로그인 화면 ───────────── */

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
}
.gate-card h1 { font-size: 20px; margin: 0 0 4px; }
.gate-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

/* ───────────── 헤더 ───────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(14, 15, 18, .88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1500px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 17px; margin: 0; }
.count-pill {
  background: var(--accent-soft);
  color: #a9c0ff;
  border: 1px solid rgba(79,124,255,.35);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.wrap { max-width: 1500px; margin: 0 auto; padding: 20px; }

/* ───────────── 그리드 ───────────── */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.grid.lg { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid.sm { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
.card .thumb {
  position: relative;
  aspect-ratio: 1;
  background: #0a0b0d;
  cursor: zoom-in;
  display: block;
}
.card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .3s;
}
.card .thumb img.loaded { opacity: 1; }
.card.picked { border-color: var(--gold); }
.card.picked .thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 3px var(--gold);
  pointer-events: none;
}

.pick {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 16px;
  line-height: 1;
  transition: transform .12s, background .15s;
}
.pick:hover { transform: scale(1.12); }
.card.picked .pick { background: var(--gold); color: #2a1f00; }

.meta {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.fname {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.fname:hover { color: var(--text); }

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* ───────────── 라이트박스 ───────────── */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #08090b;
  display: none;
  flex-direction: column;
}
.lightbox.open { display: flex; }
.lb-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #1c1e24;
}
.lb-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--muted);
}
.lb-stage {
  flex: 1;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 0;
}
.lb-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 76px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,.07);
  color: #fff;
  font-size: 22px;
}
.lb-nav:hover { background: rgba(255,255,255,.16); }
.lb-nav.prev { left: 16px; }
.lb-nav.next { right: 16px; }
.lb-bottom {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid #1c1e24;
}
.lb-pick.on { background: var(--gold); border-color: var(--gold); color: #2a1f00; }

/* ───────────── 토스트 ───────────── */

#toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: #22252d;
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  font-size: 14px;
  max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ───────────── 관리자 전용 ───────────── */

.album-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.album-card:hover { border-color: #3b4150; transform: translateY(-2px); }
.album-card .cover {
  aspect-ratio: 3/2;
  background: #0a0b0d center/cover no-repeat;
  display: grid;
  place-items: center;
  color: #3a3f4a;
  font-size: 13px;
}
.album-card .body { padding: 12px 14px; }
.album-card h3 { margin: 0 0 4px; font-size: 15px; }

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: none;
  place-items: center;
  z-index: 90;
  padding: 20px;
}
.modal-back.open { display: grid; }
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 460px;
  max-height: 86dvh;
  overflow: auto;
}
.modal h2 { margin: 0 0 18px; font-size: 18px; }

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  color: var(--muted);
  transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }

.bar {
  height: 6px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
  display: none;
}
.bar.show { display: block; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.share-box {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  word-break: break-all;
  color: var(--muted);
}

@media (max-width: 600px) {
  .wrap { padding: 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .topbar-inner { padding: 10px 14px; gap: 8px; }
  .lb-nav { width: 38px; height: 60px; }
}
