:root {
  --bg: #0d0f14;
  --bg-soft: #151922;
  --bg-card: #171c26;
  --line: #262c39;
  --line-soft: #1e2431;
  --ink: #e8ebf1;
  --ink-dim: #98a1b3;
  --ink-faint: #6b7488;
  --accent: #6ea8fe;
  --like: #ff5d7a;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

/* .player, #auth-user 처럼 display 를 지정한 선택자는 브라우저 기본 [hidden] 규칙보다
   우선순위가 높아서 hidden 속성이 무시된다. 오버레이가 화면을 덮은 채로 남는다. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont,
               system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100dvh; display: flex; flex-direction: column; }

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(13, 15, 20, .82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #6ea8fe, #b57bff 55%, #ff5d7a);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .08) inset;
  flex: none;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.brand-text small { font-size: 12px; color: var(--ink-faint); }

.topbar-right { display: flex; align-items: center; }
#auth-user { display: flex; align-items: center; gap: 10px; }

.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg-soft);
  object-fit: cover;
}

.user-name { font-size: 14px; color: var(--ink-dim); max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----------------------------------------------------------------- atoms */

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #0b1220; }
.btn-primary:hover { background: #85b7ff; }

.btn-ghost { border-color: var(--line); color: var(--ink-dim); }
.btn-ghost:hover { border-color: #37405280; background: var(--bg-soft); color: var(--ink); }

/* 이름 첫 글자를 넣는 원형 배지. 익명 로그인이라 프로필 사진이 없다. */
.avatar {
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(135deg, #39415a, #2a3142);
}

/* ---------------------------------------------------------- login dialog */

.login-dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-card);
  color: var(--ink);
  padding: 0;
  width: min(360px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}

.login-dialog::backdrop { background: rgba(6, 8, 12, .68); }

.login-dialog form { padding: 24px; display: flex; flex-direction: column; }

.login-dialog h2 { margin: 0 0 6px; font-size: 18px; letter-spacing: -.01em; }

.login-hint { margin: 0 0 20px; font-size: 13px; color: var(--ink-faint); line-height: 1.5; }

.login-dialog label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-dim);
  margin-bottom: 6px;
}

.login-dialog input {
  padding: 11px 13px;
  margin-bottom: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 14px;
  outline: none;
}
.login-dialog input:focus { border-color: #3d4a63; }

.login-error {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 9px;
  background: rgba(255, 93, 122, .1);
  border: 1px solid rgba(255, 93, 122, .28);
  color: #ff8ea3;
  font-size: 12.5px;
  line-height: 1.5;
}

.login-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* -------------------------------------------------------- upload dialog */

.upload-dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-card);
  color: var(--ink);
  padding: 0;
  width: min(460px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
.upload-dialog::backdrop { background: rgba(6, 8, 12, .68); }
.upload-dialog form { padding: 24px; display: flex; flex-direction: column; }
.upload-dialog h2 { margin: 0 0 4px; font-size: 18px; letter-spacing: -.01em; }
.upload-who { margin: 0 0 18px; font-size: 12.5px; color: var(--ink-faint); }

.upload-dialog label { font-size: 12.5px; font-weight: 600; color: var(--ink-dim); margin-bottom: 6px; }
.upload-dialog label .dim { font-weight: 500; color: var(--ink-faint); }
.upload-dialog input[type="text"] {
  padding: 10px 13px;
  margin-bottom: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 14px;
  outline: none;
}
.upload-dialog input[type="text"]:focus { border-color: #3d4a63; }

.dropzone {
  border: 1.5px dashed #38415a;
  border-radius: 12px;
  padding: 22px 16px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-soft);
  transition: border-color .15s, background .15s;
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); }
.dropzone.drag { border-color: var(--accent); background: rgba(110, 168, 254, .07); }
.dropzone-inner { display: flex; flex-direction: column; gap: 5px; pointer-events: none; }
.dropzone-inner strong { font-size: 13.5px; }
.dropzone-inner span { font-size: 12px; color: var(--ink-faint); line-height: 1.5; }

.up-picked {
  margin: 12px 0 0;
  padding: 9px 12px;
  border-radius: 9px;
  background: #1c2230;
  font-size: 12.5px;
  color: var(--ink-dim);
}
.up-picked.instant { border-left: 3px solid #1f9d55; }
.up-picked.bundle { border-left: 3px solid var(--accent); }

.upload-msg {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 9px;
  background: rgba(255, 93, 122, .1);
  border: 1px solid rgba(255, 93, 122, .28);
  color: #ff8ea3;
  font-size: 12.5px;
  line-height: 1.55;
}
.thumb-row { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.thumb-preview {
  width: 64px; height: 40px;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--line);
}

.upload-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* --------------------------------------------------------------- layout */

.wrap {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.search-box {
  position: relative;
  flex: 1 1 280px;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 13px;
  width: 17px; height: 17px;
  fill: none;
  stroke: var(--ink-faint);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 11px 14px 11px 38px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 14px;
  outline: none;
}
.search-box input:focus { border-color: #3d4a63; }
.search-box input::placeholder { color: var(--ink-faint); }

.sort-group { display: flex; gap: 6px; }

.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-dim);
  font-size: 13px;
  font-weight: 600;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { color: var(--ink); border-color: #37405280; }
.chip.is-on { background: var(--ink); color: #0d0f14; border-color: var(--ink); }

.tagbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 22px; }
.tagbar:empty { display: none; }

/* ---------------------------------------------------------------- grid */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
  gap: 18px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  border: 1px solid var(--line-soft);
  background: var(--bg-card);
  overflow: hidden;
  transition: border-color .18s, transform .18s, box-shadow .18s;
}

.card:not(.skel):hover {
  border-color: #39435a;
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.card-thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--bg-soft);
  cursor: pointer;
  overflow: hidden;
}

.card-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

.card-thumb .fallback {
  width: 100%; height: 100%;
  display: grid;
  place-items: center;
  font-size: 40px;
  font-weight: 800;
  color: rgba(255, 255, 255, .82);
  letter-spacing: -.03em;
}

.card-thumb .play-veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 12, 17, .55);
  opacity: 0;
  transition: opacity .18s;
}
.card:hover .play-veil { opacity: 1; }

/* 내가 올린 게임의 수정·삭제 (썸네일 위 오른쪽) */
.card-owner {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.card:hover .card-owner, .card:focus-within .card-owner { opacity: 1; }
.card-owner .linkish {
  padding: 4px 9px;
  border-radius: 7px;
  background: rgba(13, 15, 20, .82);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  backdrop-filter: blur(4px);
}
.card-owner .linkish:hover { background: rgba(13, 15, 20, .95); }
.card-owner [data-del]:hover { color: #ff8ea3; }

.play-veil span {
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #0d0f14;
  font-size: 13px;
  font-weight: 700;
}

.card-body { padding: 13px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }

.card-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.35;
  cursor: pointer;
}

.card-desc {
  font-size: 12.5px;
  color: var(--ink-faint);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags { display: flex; flex-wrap: wrap; gap: 5px; }

.tag {
  padding: 3px 8px;
  border-radius: 6px;
  background: #202634;
  color: var(--ink-dim);
  font-size: 11px;
  font-weight: 600;
}
button.tag { border: 1px solid transparent; }
button.tag.is-on { background: var(--accent); color: #0b1220; }

.card-foot {
  margin-top: auto;
  padding-top: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-author { font-size: 12.5px; color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-cohort { color: var(--ink-faint); }

/* ---------------------------------------------------------------- like */

.btn-like {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-dim);
  font-size: 12.5px;
  font-weight: 700;
  flex: none;
  transition: color .15s, border-color .15s, background .15s;
}
.btn-like:hover { border-color: #4a3040; color: var(--like); }
.btn-like .heart { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; transition: fill .15s; }
.btn-like[aria-pressed="true"] { color: var(--like); border-color: #4a3040; background: rgba(255, 93, 122, .08); }
.btn-like[aria-pressed="true"] .heart { fill: currentColor; }
.btn-like.pulse .heart { animation: pop .32s ease; }
.btn-like[disabled] { opacity: .5; cursor: progress; }

@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.32); }
  100% { transform: scale(1); }
}

/* ------------------------------------------------------------ skeleton */

.skel { aspect-ratio: 16 / 10; height: auto; min-height: 250px; border: 1px solid var(--line-soft); }
.skel::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, .04) 50%, transparent 80%);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

.empty { text-align: center; color: var(--ink-faint); padding: 60px 0; font-size: 14px; }

/* --------------------------------------------------------------- foot */

.foot {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-top: 1px solid var(--line-soft);
  color: var(--ink-faint);
  font-size: 12.5px;
}
.foot a:hover { color: var(--ink-dim); }
.foot-right { display: flex; gap: 16px; align-items: center; }

.linkish {
  border: 0;
  background: none;
  padding: 0;
  color: var(--ink-faint);
  font-size: 12.5px;
}
.linkish:hover { color: var(--ink-dim); }

/* ---------------------------------------------------------------- admin */

.admin {
  margin-bottom: 26px;
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid #3a3350;
  background: linear-gradient(180deg, rgba(140, 110, 220, .09), transparent 70%), var(--bg-card);
}

.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.admin-head h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; }
.admin-actions { display: flex; gap: 8px; }

.admin-empty { margin: 0; padding: 22px 0; color: var(--ink-faint); font-size: 13.5px; text-align: center; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.admin-table th,
.admin-table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); }
.admin-table th { color: var(--ink-faint); font-size: 12px; font-weight: 600; }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table tfoot td { border-bottom: 0; border-top: 1px solid var(--line); font-weight: 700; padding-top: 12px; }

.admin-problems {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 9px;
  background: rgba(255, 180, 80, .07);
  border: 1px solid rgba(255, 180, 80, .24);
  font-size: 12.5px;
  color: #f0c07a;
}
.admin-problems strong { display: block; margin-bottom: 6px; }
.admin-problems ul { margin: 0; padding-left: 18px; line-height: 1.6; }

/* ------------------------------------------------------------- player */

.player {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: #07080b;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
}

.player-meta { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.player-meta strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-meta span { font-size: 12px; color: var(--ink-faint); }

.player-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.player-stage { flex: 1; min-height: 0; background: #000; }

#game-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* -------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 90;
  padding: 11px 18px;
  border-radius: 10px;
  background: #222937;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13.5px;
  box-shadow: var(--shadow);
}

@media (max-width: 560px) {
  .topbar { padding: 12px 16px; }
  .wrap { padding: 20px 16px 48px; }
  .brand-text small { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .user-name { display: none; }
}
