/* ===== CSS Variables (Light/Dark + Color-Vision Friendly) ===== */
:root {
  --bg: #0b0c0f;
  --card: #11131a;
  --muted: #9aa3b2;
  --text: #e6e9ef;
  --surface: #0f1420;
  --border: #222836;
  --accent: #4f8cff;
  --good: #1fbf75;
  --bad: #ff5b5b;
  --warn: #ffb454;
  --chip: #151b26;
  --table-grid: #1e2534;
  --shadow: 0 4px 16px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.03);
  --chip-active-text: #f8fafc; /* dark theme active chip text */
  --eff-0: #111; --eff-25:#1a2f5a; --eff-50:#163d2a; --eff-100:#2b2f3a; --eff-200:#4c1d1f; --eff-400:#5b1a5e;
}
[data-theme="light"] {
  --bg: #f7f8fb; --surface:#fff; --card:#fff; --text:#0d1117; --muted:#6b7280; --border:#e6e8ef;
  --accent:#3b82f6; --good:#10b981; --bad:#ef4444; --warn:#f59e0b; --chip:#f3f4f6; --table-grid:#eef2f7;
  --shadow: 0 10px 30px rgba(17,24,39,.08);
  --chip-active-text: #0b1220; /* light theme active chip text */
}
[data-cvd="1"] {
  --accent:#7e57c2; --eff-0:#1b1b1b; --eff-25:#2b5797; --eff-50:#1d6f42; --eff-100:#404040; --eff-200:#b03030; --eff-400:#7c2a8a;
}

/* ===== Global ===== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body{
  margin:0;
  background:
    radial-gradient(1200px 800px at 20% -10%, rgba(16,185,50,.06), transparent 60%),
    radial-gradient(800px 600px at 100% 0%, rgba(46,114,241,.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color:var(--text);
  font:14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Noto Sans KR, Helvetica, Arial, Apple Color Emoji, Segoe UI Emoji;
}

/* ===== Header ===== */
header{
  position:fixed; top:0; left:0; right:0; z-index:1000;
  backdrop-filter:saturate(180%) blur(8px);
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  border-bottom:1px solid var(--border);
}
#header-spacer{ height:120px; }
.wrap{ max-width:1200px; margin:0 auto; padding:16px 20px; }
.app-title{ display:flex; align-items:center; gap:12px; }
.app-title h1{ margin:0; font-size:18px; }
.sub{ color:var(--muted); font-size:12px; }

/* ===== Layout ===== */
.container{ max-width:1200px; margin:16px auto 64px; padding:0 20px; }
.grid{ display:grid; gap:16px; }
.grid-wide-right{ grid-template-columns: minmax(0, 1fr) 320px; }
@media (max-width:1180px){ .grid-wide-right{ grid-template-columns:1fr; } }
.grid-wide-right > .main,
.grid-wide-right > .side,
.card, .card .body, .table-wrap { min-width:0; }
.main{ display:grid; gap:16px; }

/* ===== Card ===== */
.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:16px;
  box-shadow:var(--shadow);
}
.card .head{
  display:flex; justify-content:space-between; align-items:center;
  padding:16px; border-bottom:1px dashed var(--border);
}
.card h2{ margin:0 0 8px; font-size:16px; }
.card .body{ padding: 16px; }
.card .body.explain{ padding: 4px 16px 4px 0px; }

/* ===== Controls ===== */
.controls{ display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.btn{
  border:1px solid var(--border);
  background:var(--surface);
  color:var(--text);
  padding:8px 12px;
  border-radius:10px;
  cursor:pointer;
  font-weight:600;
}
.btn:hover{
  background: color-mix(in oklab, var(--surface) 80%, var(--accent));
  border-color: color-mix(in oklab, var(--border) 60%, var(--accent));
}
/* 키보드 포커스 가시성 */
.btn:focus-visible,
.chip:focus-visible {
  outline:2px solid var(--accent);
  outline-offset:2px;
}
.right{ margin-left:auto; }
.muted{ color:var(--muted); }

/* ===== Team board ===== */
.team-board{ display:grid; grid-template-rows:repeat(6,auto); gap:12px; }
.slot{
  padding:12px; border-radius:12px; border:1px dashed var(--border);
  background:var(--surface);
  display:flex; flex-direction:column; gap:10px;
}

/* 헤더: 좌측 제목, 우측 버튼 */
.slot .top{ display:flex; align-items:center; justify-content:space-between; gap:8px; }
.slot h3{ margin:0; font-size:13px; color:var(--muted); }
.slot .actions{ display:flex; gap:6px; }

/* === 기본: 2 : 1 : 6 (선택/별명 : 스프라이트 : 타입) === */
.slot-grid{
  display:grid;
  grid-template-columns: 2fr 1fr minmax(560px, 6fr);
  gap:12px;
  align-items:start;
}

/* === 스프라이트가 없을 때: 가운데 칸 제거, 좌측을 3fr로 확장 === */
.slot.no-sprite .slot-grid{ grid-template-columns: 3fr minmax(560px, 6fr); }
.slot.no-sprite .slot-sprite{ display:none; }

/* --- 스프라이트 썸네일 --- */
.slot-left{ display:flex; flex-direction:column; gap:8px; }
.slot-sprite{ display:flex; align-items:center; justify-content:center; padding-top:4px; }
.slot .sprite{
  width:72px; height:72px; object-fit:contain;
  image-rendering: pixelated;
  background: var(--surface); border:1px solid var(--border);
  border-radius:12px; padding:6px; display:none; cursor: zoom-in;
}

.slot input.name,
.slot input.search{
  width:100%;
  padding:6px 10px;
  border:1px solid var(--border);
  border-radius:10px;
  background:var(--card);
  color:var(--text);
}

@media (max-width:1180px){
  .slot-grid{ grid-template-columns:1fr; }
  .slot-sprite{ justify-content:flex-start; }
}

/* 타입칩 그리드 */
.slot-right{ min-width:0; } /* 오버플로 방지 */
.chip-row{ display:grid; gap:4px; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.chip{
  display:flex; align-items:center; justify-content:center; gap:8px;
  padding:8px 10px; border-radius:12px; border:1px solid var(--border);
  background:var(--chip); cursor:pointer; user-select:none; font-weight:700; letter-spacing:.2px; color:var(--text);
}
.chip .dot{
  width:9px; height:9px; border-radius:999px;
  border:1px solid rgba(0,0,0,.08);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.chip.active{
  outline:2px solid var(--accent);
  background: color-mix(in oklab, var(--chip) 70%, var(--accent));
  color:var(--chip-active-text) !important;
}

/* 하단 요약 */
.mini{ display:flex; flex-direction:column; gap:8px; padding-top:10px; border-top:1px dashed var(--border); }
.meta-row,
.weak-row{ display:flex; flex-wrap:wrap; gap:6px; align-items:center; }
.stat-pill{ font-variant-numeric:tabular-nums; }

/* 공통 pill */
.pill{
  display:inline-flex; align-items:center; gap:6px;
  padding:4px 10px; border:1px solid var(--border);
  border-radius:999px; background:var(--surface);
}
.pill .dot{
  width:9px; height:9px; border-radius:999px;
  border:1px solid rgba(0,0,0,.08);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}

/* ===== Tables ===== */
.table-wrap{ overflow:auto; border:1px solid var(--border); border-radius:12px; scrollbar-gutter: stable both-edges;}
table{
  border-collapse:separate; border-spacing:0;
  width:100%; table-layout:fixed;
  font-variant-numeric:tabular-nums;
}
th, td{
  padding:8px 10px; border-bottom:1px solid var(--table-grid);
  white-space:nowrap; text-align:center;
}
thead th{ position:sticky; top:0; background:var(--surface); z-index:2; }
tbody tr:last-child td{ border-bottom:0; }
tbody tr:hover td{ background: color-mix(in oklab, var(--surface) 85%, var(--accent)); }
.sticky-col{
  position:sticky; left:0; background:var(--surface);
  border-right:1px solid var(--table-grid); z-index:3; text-align:left;
}
thead th.sticky-col{ z-index:4; }
#attackTable{ min-width:1100px; }
#defenseTable{ min-width:800px; }
#attackTable th:first-child,#attackTable td:first-child,
#defenseTable th:first-child,#defenseTable td:first-child{ width:120px; }

/* Eff chips */
.eff{ border-radius:6px; padding:2px 4px; font-weight:500; display:inline-block; min-width:35px; }
.eff-0{ background:var(--eff-0); color:#ddd; }
.eff-25{ background:var(--eff-25); color:#cfe3ff; }
.eff-50{ background:var(--eff-50); color:#c9ffe6; }
.eff-100{ background:var(--eff-100); color:#d7deea; }
.eff-200{ background:var(--eff-200); color:#ffcdcd; }
.eff-400{ background:var(--eff-400); color:#ffd9ff; }
.hole-col{ background: color-mix(in oklab, var(--warn) 20%, var(--surface)) !important; }
thead th.hole-col{ background: color-mix(in oklab, var(--warn) 28%, var(--surface)) !important; }

/* KPIs / Recommendation */
.kpis{
  display:grid; grid-template-columns:repeat(3,1fr);
  gap:10px; margin-bottom:10px;
}
.kpi{
  background:var(--surface); border:1px solid var(--border);
  padding:10px; border-radius:12px;
  display:flex; align-items:center; gap:8px;
}
.kpi strong{ font-size:18px; }

.side{ display:flex; flex-direction:column; gap:16px; }
.list{ display:flex; flex-wrap:wrap; gap:6px; }
.footer{ color:var(--muted); font-size:12px; margin-top:10px; }
.hole-block{ display:flex; flex-wrap:wrap; gap:6px; margin-top:6px; }

/* 추천 패널 */
.reco-controls{
  display:grid; gap:10px 12px;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "count count"
    "dedup speed"
    "roles roles";
  align-items:center;
}
.reco-controls .reco-count{ grid-area:count; }
.reco-controls .reco-dedup{ grid-area:dedup; }
.reco-controls .reco-speed{ grid-area:speed; }
.reco-controls .reco-roles{ grid-area:roles; display:flex; flex-wrap:wrap; gap:12px; align-items:center; }
.reco-controls select{
  padding:6px 8px; border:1px solid var(--border);
  border-radius:8px; background:var(--surface); color:var(--text);
}
.reco-controls label{ display:flex; gap:6px; align-items:center; font-weight:600; white-space:nowrap; }

@media (max-width:520px){
  .reco-controls{
    grid-template-columns:1fr;
    grid-template-areas:"count" "dedup" "speed" "roles";
  }
}

.count-field input#recoCount{
  width: 72px;
  padding: 6px 8px;
  border:1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius:10px;
  font-weight:600;
}

.reco-filters{ display:grid; gap:8px; margin-top:8px; padding-bottom:10px; border-bottom:1px dashed var(--border); margin-bottom:12px; }
#recoReasons{ margin:0; padding:0; min-height:0; }
.reco-filters .chip-group{ display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.chipline{ display:flex; flex-wrap:wrap; gap:6px; }

/* 추천 카드: 전체 카드/바디를 분리해서 바디만 스크롤 */
#recoCard{
  display: flex;
  flex-direction: column;
  /* JS가 계산해 주는 최대 높이. 미지원/초기엔 대략값 */
  --reco-max: 70vh;
  max-height: var(--reco-max);
}

#recoCard .head{
  align-items: flex-start;              /* 제목 블록이 위에 딱 붙도록 */
  gap: 8px;
}
#recoCard .head .title{
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#recoCard .head .hint{
  font-size: 12px;
  color: var(--muted);
  line-height: 1.2;
}
#recoCard .head .controls{ display:flex; gap:4px; flex-wrap:wrap; }
#recoCard .head .hint::before{ content: "↓ "; opacity:.7; }


#recoCard .body{
  flex: 1 1 auto;
  overflow: auto;                 /* 바디 영역만 스크롤 */
  /* JS가 계산해 주는 바디 최대 높이. 초기엔 카드 높이에서 헤더값 대략 차감 */
  --reco-body-max: calc(var(--reco-max) - 64px);
  max-height: var(--reco-body-max);
}

@media (max-width: 1180px){
  #recoCard{
    max-height: none !important;
    --reco-max: auto !important;
  }
  #recoCard .body{
    max-height: none !important;
    --reco-body-max: auto !important;
    overflow: visible !important;
  }
  /* 좁은 화면에서는 스크롤 힌트 숨김 */
  #recoCard .head .hint{ display:none !important; }
}

/* 우측 칼럼은 항상 상단 정렬 */
.side{ align-self: start; }


.reco-list{ display:grid; grid-template-columns:repeat(auto-fill,minmax(260px,1fr)); gap:16px; }
.pkm-card{
  background:var(--surface); border:1px solid var(--border);
  border-radius:12px; padding:12px; display:flex; flex-direction:column; gap:10px;
}
.pkm-card:not(:last-child){ margin-bottom:4px; }
.pkm-title{ display:flex; align-items:center; justify-content:space-between; }
.pkm-title h3{ margin:0; font-size:14px; }
.pkm-types,.pkm-badges{ display:flex; flex-wrap:wrap; gap:6px; align-items:center; }
.pkm-actions{ display:flex; gap:8px; }
.pkm-actions .btn{ padding:6px 8px; font-weight:700; }

/* 반응형 축소 */
@media (max-width:1180px){
  .chip{ padding:4px 6px; font-size:12px; }
  th,td{ padding:6px 6px; font-size:12px; }
}

/* ========= 라이트박스(확대 보기) ========= */
.lightbox{
  position:fixed; inset:0;
  background: rgba(0,0,0,.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display:none; align-items:center; justify-content:center;
  z-index:4000;
}
.lightbox.open{ display:flex; }
.lightbox .lb-img{
  max-width:min(90vw, 560px);
  max-height:90vh;
  image-rendering: pixelated;
  background:var(--card);
  border:1px solid var(--border);
  border-radius:16px; padding:12px;
  box-shadow:var(--shadow);
}
.lightbox .lb-close{
  position:absolute; top:16px; right:16px;
  border:1px solid var(--border);
  background: var(--card); color: var(--text);
  border-radius:10px; padding:6px 10px;
  cursor:pointer; font-weight:700;
}
.lightbox .lb-close:hover{
  background: color-mix(in oklab, var(--surface) 80%, var(--accent));
  border-color: color-mix(in oklab, var(--border) 60%, var(--accent));
}

/* ====================================================== */
/* ====================== 모바일 ========================= */
/* ====================================================== */

/* 공통: 데스크톱/모바일 가시성 */
.desktop-only { display:flex; gap:8px; }
.mobile-only  { display:none; }
@media (max-width: 1180px){
  .desktop-only { display:none; }
  .mobile-only  { display:inline-flex; }
  .icon-btn { padding:8px 10px; font-weight:700; }
}

/* 모바일 시트 */
.sheet[hidden]{ display:none !important; }
.sheet{ position:fixed; inset:0; z-index:2000; }
.sheet-backdrop{ position:absolute; inset:0; background:rgba(0,0,0,.45); }
.sheet-panel{
  position:absolute; left:0; right:0; bottom:0;
  background:var(--card); border-top-left-radius:16px; border-top-right-radius:16px;
  border:1px solid var(--border); box-shadow:var(--shadow);
  max-height:70vh; display:flex; flex-direction:column;
}
.sheet-head{ display:flex; justify-content:space-between; align-items:center; padding:12px 16px; border-bottom:1px solid var(--border); }
.sheet-body{ padding:12px 16px; display:grid; gap:8px; }
.sheet-body .block{ width:100%; }

/* 모바일 헤더: 좌측(h1+pill) · 우측(MENU 버튼) 정렬 */
@media (max-width:1180px){
  header .app-title{
    display:flex;           /* 이미 flex라면 유지 */
    align-items:center;
    gap:8px;
    width:100%;             /* 버튼을 우측 끝까지 밀 수 있도록 */
  }
  /* MENU 버튼을 오른쪽으로 밀기 */
  #menuBtn.mobile-only{
    margin-left:auto;       /* 핵심 */
    display:inline-flex;    /* 높이/수직정렬 안정화 */
    align-items:center;
  }
  /* 보조: 타이틀/배지 사이즈 살짝 컴팩트 */
  .app-title h1.mobile-only{ font-size:18px; }
  .app-title .pill.mobile-only{ font-size:12px; }
}

/* ===== 모바일(≤1180px) — 상단: 좌(입력)/우(스프라이트), 중앙: 타입 4열 ===== */
@media (max-width:1180px){
  /* 그리드를 풀고 일반 흐름으로 */
  .slot .slot-grid{ display:block; }

  /* 카드 안에서 스프라이트만 우측 상단에 고정 */
  .slot{ position: relative; }
  .slot .slot-sprite{
    position:absolute; right:12px; top:12px;
    width:96px; height:96px;
    display:flex; align-items:center; justify-content:center;
  }
  .slot .slot-sprite img{
    width:96px; height:96px; object-fit:contain; image-rendering:pixelated;
  }
  /* 스프라이트가 없으면 자리 제거 + 좌측 여백 복원 */
  .slot .slot-sprite:empty,
  .slot .slot-sprite img[src=""],
  .slot .slot-sprite img:not([src]){ display:none; }
  .slot.no-sprite .slot-left{ padding-right:0; }

  /* 입력(검색/별명) 영역을 왼쪽, 스프라이트 자리만큼 우측 여백 확보 */
  .slot .slot-left{
    min-width:0;
    padding-right:112px; /* 스프라이트 폭(96) + 여백 */
  }

  /* 타입 표는 중앙 전체 폭(스프라이트 영역 포함)으로 */
  .slot .slot-types,
  .slot .chip-row{
    margin-top:10px;
    display:grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important; /* 6×3 → 4열 */
    gap:6px !important;
    width:100%;
  }

  /* 칩 사이즈 컴팩트 */
  .chip, .chip.sm{ padding:6px 8px !important; font-size:13px !important; border-radius:10px; }
  .chip .dot{ width:8px; height:8px; }

  /* 종족값 라인 줄바꿈 허용 — 카드 밖으로 넘침 방지 */
  .statline{ font-size:13px !important; line-height:1.25; white-space:normal; overflow-wrap:anywhere; }

  /* 아래쪽 칩/태그들도 살짝 축소 */
  .pill{ padding:4px 8px; font-size:12px; }
}

/* ===== 모바일: 슬롯 헤더(제목+초기화) ===== */
@media (max-width:1180px){
  /* 스프라이트가 있을 때: 스프라이트 폭만큼 우측 패딩 확보(겹침 방지) */
  .slot .top{
    display:flex;
    align-items:center;
    gap:8px;
    padding-right:112px;   /* 96px + 여백 */
    margin-bottom:8px;
  }
  /* 기본은 제목 옆에 버튼(좌측 정렬) */
  .slot .top .actions{
    margin-left:0 !important;
    order:2;
  }

  /* ── 스프라이트가 '없는' 슬롯일 때만 규칙 변경 ── */
  .slot.no-sprite .top{
    padding-right:0;               /* 우측 패딩 제거 */
  }
  .slot.no-sprite .top .actions{
    margin-left:auto !important;   /* 초기화 버튼을 맨 우측으로 밀기 */
  }

  /* 스프라이트 영역 감추기(없을 때) */
  .slot.no-sprite .slot-sprite{ display:none !important; }
}

/* 아주 작은 폭(≤420px)에서 스프라이트와 칩 더 축소 */
@media (max-width:420px){
  .slot .slot-sprite{ right:10px; top:10px; }
  .slot .slot-sprite img{ width:84px; height:84px; }
  .slot .slot-left{ padding-right:100px; }
  .chip, .chip.sm{ font-size:12.5px; padding:5px 7px; }
}

/* ===== 중앙 모달 ===== */
.modal[hidden]{ display:none !important; }
.modal{ position:fixed; inset:0; z-index:2200; }
.modal-backdrop{ position:absolute; inset:0; background:rgba(0,0,0,.5); }

.modal-panel{
  position:absolute; left:50%; top:50%; transform:translate(-50%,-50%);
  background:var(--card); border:1px solid var(--border); border-radius:16px; box-shadow:var(--shadow);
  max-width:calc(100vw - 48px); max-height:calc(100vh - 48px);
  overflow:auto; padding:16px;
}

/* 스프라이트 확대용 패널 */
.modal-panel.image{ background:transparent; border:0; box-shadow:none; padding:0; }
.modal-panel.image img{
  width:min(76vw, 360px); height:min(76vw, 360px);
  max-height:80vh; object-fit:contain; image-rendering:pixelated;
  background:#fff; border-radius:18px; box-shadow:var(--shadow); padding:12px;
}

/* 햄버거 메뉴용 패널 */
.modal-panel.menu{ width:min(420px, 92vw); }
.modal-panel.menu .menu-list{ display:grid; gap:10px; }
.modal-panel.menu .btn.block{ width:100%; justify-content:center; }

