* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --line: #dde3ec;
  --text: #1c2430;
  --muted: #68758a;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --sel: #fef3c7;
}

body {
  font-family: 'Segoe UI', 'Malgun Gothic', Apple SD Gothic Neo, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

button { font: inherit; cursor: pointer; border: none; border-radius: 8px; }
input, select { font: inherit; }

.btn { padding: 10px 16px; background: var(--primary); color: #fff; border-radius: 8px; }
.btn:hover { background: var(--primary-dark); }
.btn.ghost { background: #eef2f9; color: var(--text); }
.btn.ghost:hover { background: #e2e8f4; }
.btn.danger { background: var(--red); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }

.badge {
  display: inline-block; min-width: 20px; text-align: center;
  font-size: 11px; font-weight: 700; padding: 2px 5px; border-radius: 5px; margin-left: 4px;
}
.badge.g-M { background: #dbeafe; color: #1d4ed8; }
.badge.g-F { background: #fce7f3; color: #be185d; }
.badge.grade { background: #ecfdf5; color: #047857; }

#bm-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: #1c2430; color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 1000;
  max-width: 90vw;
}
#bm-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#bm-toast.error { background: var(--red); }
#bm-toast.error.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 홈 ---------- */
.home-wrap {
  max-width: 460px; margin: 0 auto; padding: 48px 20px;
}
.home-wrap h1 { font-size: 26px; margin-bottom: 6px; text-align: center; }
.home-wrap .sub { color: var(--muted); text-align: center; margin-bottom: 32px; font-size: 14px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px; margin-bottom: 18px; box-shadow: 0 1px 3px rgba(20,30,60,.05);
}
.card h2 { font-size: 17px; margin-bottom: 14px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.field input:focus, .field select:focus { outline: 2px solid #bfd3fb; border-color: var(--primary); }
.radio-row { display: flex; gap: 8px; }
.radio-row label {
  flex: 1; text-align: center; padding: 10px 0; border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--text); background: #fff;
}
.radio-row input { display: none; }
.radio-row input:checked + span { font-weight: 700; }
.radio-row label:has(input:checked) { border-color: var(--primary); background: #eff4ff; color: var(--primary-dark); }

/* ---------- 관리자 보드 ---------- */
header.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 18px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
header.topbar h1 { font-size: 18px; }
header.topbar .code { color: var(--muted); font-size: 13px; }
header.topbar .spacer { flex: 1; }

main.board { padding: 16px 18px 60px; max-width: 1500px; margin: 0 auto; }
.section-title { font-size: 14px; font-weight: 700; color: var(--muted); margin: 14px 0 8px; }

.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 1000px) { .grid4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 540px) { .grid4 { grid-template-columns: 1fr; } }

.court, .team {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; min-height: 170px; display: flex; flex-direction: column;
}
.court .head, .team .head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.court .head b, .team .head b { font-size: 14px; }
.court .timer { font-size: 12px; color: var(--amber); font-weight: 700; }
.court-label { cursor: pointer; }
.court-label .edit-ic { font-size: 11px; color: var(--muted); opacity: .6; }
.court-label:hover .edit-ic { opacity: 1; color: var(--primary); }
.court-del {
  font-size: 11px; font-weight: 700; line-height: 1; padding: 3px 7px;
  border-radius: 6px; background: #fee2e2; color: var(--red);
}
.court-del:hover { background: #fecaca; }
.court.empty { border-style: dashed; background: #f8fafd; }
.court.playing { border-color: #86b5f8; }
.court.assignable { outline: 3px solid var(--green); cursor: pointer; }
.court .players { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; flex: 1; }
.court .empty-msg { color: var(--muted); font-size: 13px; display: flex; align-items: center; justify-content: center; flex: 1; }

.pcell {
  background: #f4f7fc; border-radius: 8px; padding: 8px; font-size: 13px;
  display: flex; align-items: center; justify-content: center; text-align: center;
}

.team .slots { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; flex: 1; }
.slot {
  border: 1px dashed var(--line); border-radius: 8px; min-height: 40px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--muted); background: #fbfcfe; padding: 4px;
}
.slot.filled {
  border-style: solid; background: #f4f7fc; color: var(--text); cursor: grab;
  flex-direction: column; gap: 3px; padding: 6px 4px;
}
.slot-sub { display: flex; align-items: center; gap: 4px; }
.slot-sub .linkbadge { margin-left: 0; }
.slot-qr {
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  background: #e2e8f4; color: var(--primary-dark);
}
.slot-qr:hover { background: #cfd9ee; }
.slot-x {
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  background: #fee2e2; color: var(--red);
}
.slot-x:hover { background: #fecaca; }
.slot.target { border-color: var(--green); background: #f0fdf4; color: var(--green); cursor: pointer; }
.slot.dragover { outline: 2px solid var(--primary); }
.team.dragover { outline: 3px solid var(--primary); }
.team { cursor: grab; }
.court.playing { cursor: grab; }
.court.dragover { outline: 3px solid var(--primary); }
.team .foot { display: flex; gap: 5px; margin-top: 8px; }
.team .foot .btn { flex: 1; padding: 6px 4px; font-size: 12px; white-space: nowrap; }
.team .foot .btn[data-assign] { flex: 1.4; }
.wlist td.games { font-weight: 700; color: var(--primary-dark); }
.linkbadge {
  margin-left: 6px; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 9px; cursor: default; white-space: nowrap;
}
.linkbadge.on { background: #ecfdf5; color: #047857; }
.linkbadge.off { background: #f1f5f9; color: #94a3b8; }

.bottom { display: grid; grid-template-columns: 1fr 320px; gap: 14px; align-items: start; }
@media (max-width: 900px) { .bottom { grid-template-columns: 1fr; } }

.wlist { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.wlist table { width: 100%; border-collapse: collapse; font-size: 14px; }
.wlist th { text-align: left; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.wlist td { padding: 7px 8px; border-bottom: 1px solid #eef1f6; }
.wlist tr.selectable { cursor: pointer; }
.wlist tr.selected { background: var(--sel); }
.wlist tr.resting td, .wlist tr.playing td { color: var(--muted); }
.wlist .st { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 10px; }
.wlist .st.WAITING { background: #eff4ff; color: var(--primary-dark); }
.wlist .st.TEAMED { background: #f0fdf4; color: var(--green); }
.wlist .st.PLAYING { background: #fff7ed; color: var(--amber); }
.wlist .st.RESTING { background: #f1f5f9; color: var(--muted); }
.wlist .st.LEFT { background: #f1f5f9; color: #94a3b8; text-decoration: line-through; }
.wlist tr.left td { color: #b9c2cf; }
.wlist tr.left .badge, .wlist tr.left .linkbadge { opacity: .45; }
.wlist .ops { white-space: nowrap; text-align: right; }
.wlist .ops button {
  background: #eef2f9; border-radius: 6px; padding: 3px 8px; font-size: 12px; margin-left: 3px;
}
.wlist .ops button:hover { background: #dfe6f2; }
.wlist .ops button.del { color: var(--red); }

.hint {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  border-radius: 10px; padding: 10px 14px; font-size: 13px; margin: 10px 0;
  display: none;
}
.hint.show { display: block; }

/* 모달 */
.modal-back {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-back.show { display: flex; }
.modal {
  background: #fff; border-radius: 16px; padding: 26px; max-width: 420px; width: 100%;
  text-align: center;
}
.modal h2 { font-size: 18px; margin-bottom: 14px; }
.qr-box svg { width: 100%; max-width: 300px; height: auto; }
.modal .link { font-size: 13px; color: var(--muted); word-break: break-all; margin: 10px 0; }
.modal .close-row { margin-top: 14px; display: flex; gap: 8px; justify-content: center; }
.modal .modal-msg { font-size: 14px; color: var(--text); line-height: 1.5; }
.modal .modal-input-row { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.modal .modal-input {
  flex: 1; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 16px; text-align: center;
}
.modal .modal-input:focus { outline: 2px solid #bfd3fb; border-color: var(--primary); }
.modal .modal-suffix { font-size: 15px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.modal .close-row .btn { min-width: 88px; }

/* ---------- 회원 페이지 ---------- */
.member-wrap { max-width: 520px; margin: 0 auto; padding: 24px 16px 60px; }
.member-wrap h1 { font-size: 20px; text-align: center; margin-bottom: 4px; }
.member-wrap .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.mystatus { text-align: center; padding: 26px 16px; }
.mystatus .order { font-size: 42px; font-weight: 800; color: var(--primary); }
.mystatus .desc { color: var(--muted); font-size: 14px; margin-top: 6px; }
.mystatus .state-line { margin-top: 10px; font-size: 15px; font-weight: 600; }
.roster { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.roster button {
  display: flex; width: 100%; align-items: center; justify-content: space-between;
  padding: 11px 14px; background: #fff; border-bottom: 1px solid #eef1f6; font-size: 15px;
}
.roster button:hover { background: #f4f7fc; }
.mini-courts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mini-court { border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 12px; }
/* 카드 제목(직계 b)만 블록 처리 — 인원 목록 안의 강조(b)는 줄바꿈되지 않아야 함 */
.mini-court > b { display: block; font-size: 13px; margin-bottom: 5px; }
.mini-court.empty { border-style: dashed; color: var(--muted); }
.mini-court.me { border: 2px solid var(--primary); background: #eff4ff; }
.wrow {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-bottom: 1px solid #eef1f6; font-size: 14px;
}
.wrow:last-child { border-bottom: none; }
.wrow .no { min-width: 26px; text-align: right; color: var(--muted); font-weight: 700; }
.wrow .nm { flex: 1; }
.wrow .nm .gm { font-size: 12px; color: var(--muted); margin-left: 4px; }
.wrow .mk { font-size: 12px; }
.wrow.me { background: #eff4ff; border-radius: 8px; font-weight: 700; }
.wrow.me .nm { color: var(--primary); }
.mini-court div { line-height: 1.6; }
