:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #697386;
  --accent: #5a67d8;
  --border: #e5e7eb;
}

:root.dark {
  --bg: #12161d;
  --panel: #1b212c;
  --text: #e6e8ee;
  --muted: #a0a7b6;
  --accent: #8da2ff;
  --border: #2c3442;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden; /* ✅ 가로 스크롤 방지 */
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

img,
video,
canvas {
  max-width: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.top-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.top-left {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  overflow: hidden;
}

.top-left h1 {
  margin: 0;
  line-height: 1.2;
  max-width: 100%;
}

/* promo links always 1 row */
.promo-links {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.promo-link-btn {
  width: 100%;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.games-title-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.sort-mini select {
  height: 28px;
  min-width: 84px;
  padding: 2px 6px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}

.layout {
  width: 100%;
  max-width: 100%;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 12px;
  padding: 12px;
  min-width: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  min-height: 72vh;
  min-width: 0; /* ✅ grid item overflow 방지 */
}

.row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  min-width: 0;
}

.panel-actions {
  margin-bottom: 0;
  flex-wrap: wrap;
}

.between {
  justify-content: space-between;
  align-items: center;
}

.list {
  display: grid;
  gap: 8px;
  max-height: 58vh;
  overflow: auto;
  min-width: 0;
}

.recommend-empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.drag-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.card img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 8px;
}

#gamesList .card {
  grid-template-columns: 46px minmax(0, 1fr) auto;
}

#gamesList .card img {
  width: 46px;
  height: 64px;
  aspect-ratio: 10 / 14;
  object-fit: contain;
  background: rgba(15, 23, 42, 0.04);
}

.meta {
  min-width: 0;
}

.meta > div,
.meta small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

.meta small {
  color: var(--muted);
}

.btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 8px;
  padding: 6px 10px;
  min-height: 34px;
  cursor: pointer;
  max-width: 100%;
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

/* ===== Drag affordance (desktop only) ===== */
@media (pointer: fine) {
  #gamesList .card[data-game-id],
  #recommendList .card[data-game-id] {
    cursor: grab;
    user-select: none;
    -webkit-user-drag: element;
  }

  #gamesList .card[data-game-id]:hover,
  #recommendList .card[data-game-id]:hover {
    border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
    box-shadow: 0 2px 10px rgba(90, 103, 216, 0.14);
  }

  #gamesList .card[data-game-id]:active,
  #recommendList .card[data-game-id]:active {
    cursor: grabbing;
    transform: scale(0.995);
  }

  #gamesList .card[data-game-id].is-dragging,
  #recommendList .card[data-game-id].is-dragging {
    cursor: grabbing;
    opacity: 0.86;
    transform: scale(0.985);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.22);
    border-color: var(--accent);
  }

  /* 버튼 위에서는 포인터 유지 */
  #gamesList .card .btn,
  #recommendList .card .btn {
    cursor: pointer;
  }
}

.box-visual {
  position: relative;
  border: 3px solid rgba(71, 85, 105, 0.55);
  border-radius: 14px;
  aspect-ratio: 29 / 14;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(255,255,255,0.52), rgba(148, 163, 184, 0.2));
  box-shadow:
    0 14px 30px rgba(15, 23, 42, 0.16),
    inset 0 1px 0 rgba(255,255,255,0.55),
    inset 0 -2px 6px rgba(15, 23, 42, 0.15);
  transition: box-shadow .22s ease, border-color .22s ease;
}

.box-visual::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,0.26) 0%, rgba(255,255,255,0.04) 40%, rgba(2,6,23,0.1) 100%);
  z-index: 1;
}

.box-visual.box-hit {
  border-color: rgba(90, 103, 216, 0.45);
  box-shadow: 0 0 0 2px rgba(90, 103, 216, 0.12) inset, 0 10px 24px rgba(90, 103, 216, 0.14);
}

.box-visual img {
  position: relative;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.95);
}

.box-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: rgba(255, 255, 255, 0.9);
  background: linear-gradient(135deg, #6ea3cc, #8db3cf);
  z-index: 3;
}

.drop-zone {
  position: absolute;
  inset: 0;
  padding: 0;
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0;
  overflow: hidden;
  z-index: 2;
}

.plug-item {
  position: relative;
  margin: 0;
  height: 100%;
  border-radius: 0;
  overflow: hidden;
  transform-origin: left center;
  animation: plugIn 280ms cubic-bezier(0.22, 1, 0.36, 1);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: transparent;
}

.plug-item::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 1px;
  height: 100%;
  background: rgba(15, 23, 42, 0.25);
  z-index: 3;
}

.plug-item:last-child::before { display: none; }

.plug-item::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(255,255,255,.08), rgba(0,0,0,.08));
}

.empty-slot {
  height: 100%;
  border-radius: 0;
  background: rgba(107, 114, 128, 0.45);
}

@keyframes plugIn {
  from { transform: translateX(10px) scale(0.98); opacity: 0; }
  to { transform: translateX(0) scale(1); opacity: 1; }
}

.progress {
  background: var(--border);
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
}

#progressBar {
  background: linear-gradient(90deg, #5a67d8, #6aa6ff);
  width: 0%;
  height: 100%;
  transition: width .3s ease;
}

.stats {
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
  font-size: 14px;
  gap: 8px;
  flex-wrap: wrap;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

dialog {
  width: min(980px, 92vw);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
}

.compact .card {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.fly {
  position: fixed;
  width: 52px;
  height: 52px;
  border-radius: 10px;
  pointer-events: none;
  z-index: 999;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.24);
  will-change: transform, opacity, filter;
  transition:
    transform .32s cubic-bezier(0.22, 1, 0.36, 1),
    opacity .32s cubic-bezier(0.22, 1, 0.36, 1),
    filter .32s cubic-bezier(0.22, 1, 0.36, 1);
}

#exportBoxArea.export-static .plug-item,
#exportBoxArea.export-static .plug-item::after {
  animation: none !important;
  transform: none !important;
}

#exportBoxArea.export-static #boxPlaceholder {
  display: none !important;
}

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "right"
      "center"
      "left";
  }

  .right { grid-area: right; }
  .center { grid-area: center; }
  .left { grid-area: left; }

  .panel { min-height: auto; }
}

@media (max-width: 768px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 10px;
  }

  .top-controls {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  .top-left {
    width: 100%;
    gap: 8px;
    overflow: hidden;
  }

  .top-left h1 {
    font-size: 42px;
    max-width: 100%;
  }

  /* ✅ promo buttons always 1 row on mobile */
  .promo-links {
    width: 100%;
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 4px !important;
  }

  .promo-link-btn {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 28px;
    padding: 4px 2px !important;
    font-size: 9px !important;
    letter-spacing: -0.2px;
    line-height: 1.1;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .layout {
    padding: 8px;
    gap: 8px;
  }

  .panel {
    padding: 10px;
    border-radius: 10px;
  }

  .row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .row label {
    min-width: 0;
    flex: 1 1 140px;
  }

  .card {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    padding: 8px;
    gap: 6px;
  }

  .card img {
    width: 44px;
    height: 44px;
  }

  #gamesList .card {
    grid-template-columns: 40px minmax(0, 1fr) auto;
  }

  #gamesList .card img {
    width: 40px;
    height: 56px;
  }

  .btn {
    padding: 5px 8px;
    min-height: 30px;
    font-size: 12px;
  }

  /* ✅ 추천 카드 Add 버튼 잘림 방지 */
  #recommendList .card .btn {
    min-width: 40px;
    padding: 4px 6px;
    font-size: 11px;
  }

  input, select, button {
    font-size: 14px;
    max-width: 100%;
  }

  .box-placeholder {
    font-size: 18px;
  }
}

@media (max-width: 480px) {
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .top-left h1 {
    font-size: 28px;
  }

  .promo-link-btn {
    font-size: 8px !important;
    padding: 3px 1px !important;
  }

  .layout {
    padding: 6px;
    gap: 6px;
  }

  .panel {
    padding: 8px;
    border-radius: 10px;
  }

  .chips { gap: 4px; }
  .chip { font-size: 11px; }
}
