:root {
  --bg: #121826; --surface: #1B2335; --elev: #243049; --border: #2E3A56;
  --text: #C8D0E4; --text-hi: #E4E8F0; --muted: #7E89A6;
  --primary: #4DA3FF; --success: #34C77B; --warning: #E0A23C; --danger: #E5645D; --teal: #34D3C2;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, "Malgun Gothic", sans-serif; background: var(--bg); color: var(--text); }
header { display: flex; align-items: center; gap: 24px; padding: calc(14px + env(safe-area-inset-top)) 24px 14px; background: var(--surface); border-bottom: 1px solid var(--border); }
header h1 { font-size: 18px; margin: 0; color: var(--text-hi); }
nav { display: flex; gap: 8px; }
nav button { background: transparent; color: var(--muted); border: 1px solid transparent; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 14px; }
nav button.active { background: var(--elev); color: var(--text-hi); }
main { padding: 20px 24px calc(20px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.tab { display: none; } .tab.active { display: block; }
h2 { font-size: 15px; color: var(--text-hi); margin: 24px 0 10px; }
small.muted, .muted { color: var(--muted); font-weight: normal; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
button, select, input { font-size: 14px; }
button { background: var(--elev); color: var(--text); border: 1px solid var(--border); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
button:hover { border-color: var(--primary); }
button.primary { background: var(--primary); color: #06121f; border: none; font-weight: 600; }
button.success { background: var(--success); color: #06210f; border: none; font-weight: 600; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); padding: 4px 10px; }
input, select { background: var(--bg); color: var(--text); border: 1px solid var(--border); padding: 8px 10px; border-radius: 8px; }
label.file { background: var(--elev); border: 1px solid var(--border); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
table { width: 100%; border-collapse: collapse; margin-top: 8px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 500; }
.courts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
/* 코트 카드: 크기 고정(세로 균일) + 액션 버튼 하단 고정 */
.court { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px;
  display: flex; flex-direction: column; min-height: 240px; }
.court.empty { opacity: .5; border-style: dashed; }
.court.empty.staged { opacity: 1; } /* 회원 배치 중인 코트는 선명하게 */
.court-actions { margin-top: auto; display: flex; gap: 6px; padding-top: 10px; }
.court-actions > button { flex: 1; }
.court-actions > button:disabled { opacity: .4; cursor: not-allowed; }
.court h3 { margin: 0 0 8px; font-size: 14px; color: var(--text-hi); }
.team { background: var(--elev); border-radius: 8px; padding: 8px; margin: 6px 0; }
.team.a { border-left: 3px solid var(--primary); } .team.b { border-left: 3px solid var(--teal); }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--elev); color: var(--muted); }
.badge.playing { background: #2a3a2f; color: var(--success); }
.badge.resting { background: #3a2f2a; color: var(--warning); }
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 20px; min-width: 320px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.fb-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.fb-row .stars button { padding: 2px 6px; }
.spacer { flex: 1; }
.live { color: var(--muted); font-size: 12px; transition: color .3s; }
.live.on { color: var(--success); }
#who { font-size: 13px; }
#qrDlg { text-align: center; }
#qrDlg img { width: 280px; height: 280px; border-radius: 12px; background: var(--surface); }
#qrDlg .qr-url { font-size: 12px; color: var(--muted); word-break: break-all; margin: 10px 0; }
#qrDlg h2 { margin-top: 0; }

/* ── 드래그 앤 드롭 ── */
[draggable=true] { cursor: grab; user-select: none; }
[draggable=true]:active { cursor: grabbing; }
.dragging { opacity: .3; }
.drag-over { outline: 2px dashed var(--primary) !important; background: rgba(77,163,255,.08) !important; border-radius: 8px; }
.player-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--elev); border: 1px solid var(--border); border-radius: 6px; padding: 3px 7px; font-size: 13px; margin: 2px; cursor: grab; }
.player-chip:hover { border-color: var(--primary); }
/* 성별 구분: 남=파랑, 여=분홍 (테두리 + 이름 색) */
.player-chip.male   { border: 2px solid #4DA3FF; }
.player-chip.female { border: 2px solid #FF69B4; }
.player-chip.male:hover   { border-color: #4DA3FF; }
.player-chip.female:hover { border-color: #FF69B4; }
.player-chip.male   .pname { color: #9CC9FF; }
.player-chip.female .pname { color: #FFA8D2; }
.pname { font-weight: 700; }
.pmeta { font-size: 11px; color: var(--muted); font-weight: 400; }
/* 빈 슬롯(터치하여 출석 회원 수동 배치) */
.slot-empty { font-size: 12px; padding: 4px 9px; border: 1px dashed var(--border); border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; margin: 2px; min-height: unset; }
.slot-empty:hover { border-color: var(--primary); color: var(--text-hi); }
/* 회원 선택 다이얼로그 */
.pick-list { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; min-width: 240px; }
.pick-item { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 13px; border: 2px solid var(--border); border-radius: 8px; background: var(--elev);
  color: var(--text-hi); cursor: pointer; font-size: 14px; text-align: left; }
.pick-item:hover { border-color: var(--primary); }
.pick-item.male   { border-color: #4DA3FF; } .pick-item.male   .pick-name { color: #9CC9FF; }
.pick-item.female { border-color: #FF69B4; } .pick-item.female .pick-name { color: #FFA8D2; }
.pick-name { font-weight: 700; }
.rm-btn { background: none; border: none; color: var(--danger); cursor: pointer; padding: 0 2px; font-size: 11px; min-height: unset; line-height: 1.2; }
.court-slot { display: flex; flex-wrap: wrap; gap: 3px; min-height: 32px; align-items: center; padding: 3px 0; }
.team-drop { padding: 5px 6px; border-radius: 6px; transition: outline .1s, background .1s; }
.court.disabled-court { opacity: .45; filter: grayscale(.65); }
.court-status-btn { font-size: 11px; padding: 2px 7px; min-height: unset; border-radius: 4px; float: right; }
#queueWrap { border: 2px dashed transparent; border-radius: 10px; padding: 2px; transition: border .15s, background .15s; }
#queueWrap.drag-over { border-color: var(--danger); background: rgba(229,100,93,.06); }
.wait-pos { font-size: 11px; color: var(--muted); background: var(--elev); border-radius: 4px; padding: 1px 5px; margin-left: 3px; }
#queue tbody tr[data-uid] { cursor: grab; }
#queue tbody tr[data-uid]:hover td:first-child { color: var(--primary); }

/* ── 모바일 최적화 ── */
@media (max-width: 640px) {
  header { flex-wrap: wrap; gap: 10px 14px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
  header h1 { font-size: 16px; width: 100%; }
  nav { width: 100%; }
  nav button { flex: 1; padding: 10px 8px; }
  .spacer { display: none; }
  #who { font-size: 12px; }
  main { padding: 14px; }
  .row { gap: 6px; }
  .row > button, .row > input, .row > select { flex: 1 1 auto; min-height: 42px; } /* 터치 타깃 */
  h2 { margin: 18px 0 8px; }
  /* 표는 가로 스크롤 */
  table { display: block; overflow-x: auto; white-space: nowrap; }
  .courts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  dialog { min-width: auto; width: calc(100vw - 28px); margin: auto; }
  dialog input[type="number"] { min-height: 40px; }
  .fb-row { flex-wrap: wrap; }
  .fb-row .stars button { padding: 8px 12px; } /* 별점 터치 키우기 */
  #qrDlg img { width: min(78vw, 280px); height: min(78vw, 280px); }
}
/* 터치 기기 공통: 더 큰 탭 영역 */
@media (pointer: coarse) {
  button { min-height: 40px; }
}

/* ── KDK 오더지 인쇄 (A5 가로 1장 = 1경기) ───────────────────── */
.print-only { display: none; }
.kdk-entry-print { font-size: 11px; padding: 2px 6px; min-height: unset; }
@media print {
  @page orderPage { size: A5 landscape; margin: 8mm; }
  body { background: #fff; color: #000; }
  header, main, dialog, .toast { display: none !important; }
  .print-only { display: block !important; }
  .order-sheet {
    page: orderPage;
    break-after: page; page-break-after: always;
    break-inside: avoid; page-break-inside: avoid;
    box-sizing: border-box; width: 100%; min-height: 128mm;
    display: flex; flex-direction: column;
    border: 2px solid #000; padding: 7mm 9mm; margin: 0;
    font-family: system-ui, "Malgun Gothic", sans-serif; color: #000;
  }
  .order-sheet:last-child { break-after: auto; page-break-after: auto; }
  .os-title { text-align: center; font-size: 19px; font-weight: 800; margin-bottom: 10px; }
  .os-meta { display: flex; border: 1px solid #000; margin-bottom: 14px; }
  .os-meta-item { flex: 1; padding: 8px 10px; border-right: 1px solid #000; font-size: 18px; font-weight: 700; text-align: center; }
  .os-meta-item:last-child { border-right: none; }
  .os-meta-label { font-weight: 700; font-size: 12px; margin-bottom: 3px; }
  .os-teams { display: flex; align-items: stretch; gap: 14px; flex: 1; margin-bottom: 12px; }
  .os-team { flex: 1; border: 2px solid #000; padding: 12px; text-align: center;
             display: flex; flex-direction: column; justify-content: center; }
  .os-team-label { font-size: 14px; font-weight: 700; margin-bottom: 10px; }
  .os-team-players { font-size: 23px; font-weight: 800; margin-bottom: 14px; }
  .os-score-box { width: 74px; height: 74px; border: 2px solid #000; margin: 0 auto; }
  .os-vs { display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 800; }
  .os-footer { display: flex; justify-content: space-between; border-top: 1px solid #999; padding-top: 8px; font-size: 12px; }
  .os-footer-line { border-bottom: 1px solid #000; display: inline-block; width: 130px; }
  .os-note { font-size: 10px; color: #444; text-align: center; margin-top: 5px; }
}
