* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* 윔블던 컬러 팔레트 */
  --green: #1a5632;
  --green-light: #227a45;
  --green-dark: #0f3d22;
  --purple: #4e2d7f;
  --purple-light: #6b45a6;
  --gold: #c9a84c;
  --gold-light: #f5ecd0;
  --danger: #c0392b;
  --danger-hover: #a33025;
  --success: #27ae60;

  --cream: #faf8f3;
  --cream-100: #f3efe6;
  --cream-200: #e5dfd2;
  --cream-300: #cfc7b5;
  --warm-500: #8a7f6e;
  --warm-700: #4a4237;
  --warm-900: #2c261f;

  --radius: 10px;
}

body {
  font-family: 'Georgia', 'Times New Roman', serif;
  background: var(--cream);
  color: var(--warm-900);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* Nav - 윔블던 다크그린 */
nav {
  background: linear-gradient(to right, var(--green-dark), var(--green));
  color: #fff;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: 50px;
  box-shadow: 0 2px 8px rgba(26,86,50,.25);
  position: sticky;
  top: 0;
  z-index: 50;
}

nav .logo {
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  color: var(--gold);
  margin-right: auto;
  letter-spacing: .02em;
  font-family: 'Georgia', serif;
}

nav a {
  color: rgba(255,255,255,.8);
  text-decoration: none;
  font-size: .85rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  padding: .25rem 0;
  border-bottom: 2px solid transparent;
  transition: all .15s;
}

nav a:hover, nav a.active {
  color: #fff;
  border-bottom-color: var(--gold);
}

/* Layout */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem;
}

h1 {
  font-size: 1.25rem;
  margin-bottom: .75rem;
  color: var(--green-dark);
  font-family: 'Georgia', serif;
}

/* Cards */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(44,38,31,.08);
  border: 1px solid var(--cream-200);
  padding: 1rem;
  margin-bottom: .75rem;
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

th, td {
  text-align: left;
  padding: .5rem .4rem;
  border-bottom: 1px solid var(--cream-200);
}

th {
  font-weight: 600;
  font-size: .75rem;
  color: var(--warm-500);
  text-transform: uppercase;
  letter-spacing: .03em;
}

tr:hover td {
  background: var(--cream);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  cursor: pointer;
  transition: all .15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--green);
  color: #fff;
}
.btn-primary:hover { background: var(--green-light); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-sm {
  padding: .3rem .6rem;
  font-size: .8rem;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--cream-300);
  color: var(--warm-700);
}
.btn-outline:hover {
  background: var(--cream-100);
}

/* Forms */
.form-group {
  margin-bottom: .85rem;
}

label {
  display: block;
  font-size: .85rem;
  font-weight: 500;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin-bottom: .25rem;
  color: var(--warm-700);
}

input, select {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--cream-300);
  border-radius: var(--radius);
  font-size: 16px; /* 모바일 zoom 방지 */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #fff;
  transition: border-color .15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(26,86,50,.12);
}

/* Modal - 모바일에서 풀스크린 */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(44,38,31,.45);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop.show {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 1.25rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 -4px 30px rgba(44,38,31,.18);
  -webkit-overflow-scrolling: touch;
}

.modal h2 {
  font-size: 1.1rem;
  margin-bottom: .85rem;
  color: var(--green-dark);
  font-family: 'Georgia', serif;
}

.modal-actions {
  display: flex;
  gap: .5rem;
  margin-top: 1rem;
}

.modal-actions .btn {
  flex: 1;
  padding: .7rem;
}

/* Badges */
.badge {
  display: inline-block;
  padding: .1rem .4rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  vertical-align: middle;
}

.badge-m { background: #dbeafe; color: #1a5a8a; }
.badge-f { background: #fce7f3; color: #a8306b; }
.badge-level { background: var(--gold-light); color: #8a6d1b; }
.badge-games { background: #e8e0f4; color: var(--purple); }

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .75rem;
  flex-wrap: wrap;
  gap: .5rem;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--warm-500);
  font-size: .9rem;
}

/* Round header - 퍼플 악센트 */
.round-header {
  font-size: .9rem;
  font-weight: 600;
  margin: 1rem 0 .4rem;
  padding-bottom: .3rem;
  border-bottom: 2px solid var(--purple);
  color: var(--purple);
  font-family: 'Georgia', serif;
}

/* Court card - 모바일 최적화 */
.court-card {
  background: #fff;
  border: 1px solid var(--cream-200);
  border-radius: var(--radius);
  padding: .75rem;
  margin-bottom: .5rem;
}

.court-card h4 {
  font-size: .75rem;
  color: var(--warm-500);
  margin-bottom: .5rem;
  text-align: center;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.team-vs {
  display: flex;
  align-items: center;
  gap: .5rem;
  justify-content: center;
}

.team {
  flex: 1;
  min-width: 0;
}

.team-player {
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem 0;
  font-size: .85rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.team-player .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.team-score {
  display: flex;
  justify-content: center;
  margin-top: .4rem;
}

.vs {
  font-weight: 700;
  font-size: .85rem;
  color: var(--cream-300);
  flex-shrink: 0;
  padding: 0 .15rem;
}

.score-input {
  width: 52px;
  text-align: center;
  padding: .45rem .25rem;
  font-size: 1.2rem;
  font-weight: 700;
  border-radius: var(--radius);
  border: 2px solid var(--cream-200);
}

.score-input:focus {
  border-color: var(--green);
}

/* Stats - 골드 악센트 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: .5rem;
}

.stat-item {
  text-align: center;
  padding: .6rem .4rem;
  background: var(--cream);
  border-radius: var(--radius);
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--green);
  font-family: 'Georgia', serif;
}

.stat-label {
  font-size: .7rem;
  color: var(--warm-500);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Checkbox list for member selection */
.member-select-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--cream-200);
  border-radius: var(--radius);
  padding: .25rem;
  -webkit-overflow-scrolling: touch;
}

.member-select-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem;
  border-radius: 6px;
  min-height: 40px; /* 터치 타겟 */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.member-select-item:hover {
  background: var(--cream);
}

.member-select-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--green);
}

/* 참가자별 게임수 요약 */
.game-count-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}

/* Toast - 다크그린 */
.toast {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  background: var(--green-dark);
  color: #fff;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  text-align: center;
  z-index: 200;
  opacity: 0;
  transform: translateY(10px);
  transition: all .3s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* 날짜 그룹 아코디언 */
.date-group {
  margin-bottom: .6rem;
}

.date-group-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem .85rem;
  background: var(--green);
  color: #fff;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background .15s;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.date-group-header:active {
  background: var(--green-light);
}

.date-group-arrow {
  font-size: .65rem;
  transition: transform .2s;
  flex-shrink: 0;
}

.date-group.open .date-group-arrow {
  transform: rotate(90deg);
}

.date-group-label {
  font-weight: 600;
  font-size: .9rem;
}

.date-group-count {
  margin-left: auto;
  font-size: .75rem;
  opacity: .75;
}

.date-group-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .25s ease-out;
}

.date-group.open .date-group-body {
  max-height: 2000px;
  transition: max-height .4s ease-in;
}

.date-group-body .event-card:first-child {
  margin-top: .4rem;
}

/* 이벤트 카드 */
.event-card {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--cream-200);
  box-shadow: 0 1px 4px rgba(44,38,31,.06);
  padding: .85rem 1rem;
  margin-bottom: .5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  transition: all .15s;
  touch-action: manipulation;
}

.event-card:active {
  box-shadow: 0 0 0 2px var(--green);
}

.event-card:hover {
  border-color: var(--cream-300);
  background: var(--cream);
}

.event-card-info h3 {
  font-size: .95rem;
  margin-bottom: .1rem;
  color: var(--warm-900);
  font-family: 'Georgia', serif;
}

.event-card-meta {
  color: var(--warm-500);
  font-size: .75rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ============ Admin Toggle ============ */
.admin-toggle {
  background: none;
  border: none;
  font-size: 1.15rem;
  cursor: pointer;
  padding: .2rem .35rem;
  line-height: 1;
  border-radius: 6px;
  transition: background .15s, transform .15s;
  -webkit-tap-highlight-color: transparent;
}
.admin-toggle:hover {
  background: rgba(255,255,255,.15);
  transform: scale(1.1);
}

/* PIN Modal */
.pin-modal {
  text-align: center;
}
.pin-input-group {
  display: flex;
  justify-content: center;
}
.pin-input {
  width: 140px !important;
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: .5em;
  font-weight: 700;
}

/* Admin-only 표시/숨김 */
.admin-only {
  display: none !important;
}
body.is-admin .admin-only {
  display: revert !important;
}
body.is-admin .admin-only.btn {
  display: inline-flex !important;
}
body.is-admin td.admin-only {
  display: table-cell !important;
}
body.is-admin th.admin-only {
  display: table-cell !important;
}

/* 스코어 입력: 기본 비활성, .score-editable 이면 활성 */
.score-input {
  pointer-events: none;
  opacity: .6;
  background: var(--cream-100) !important;
}
.score-editable .score-input {
  pointer-events: auto;
  opacity: 1;
  background: #fff !important;
}

/* 선수 이름 클릭 (관리자 전용) */
.player-name-click {
  cursor: default;
}
body.is-admin .player-name-click {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  text-decoration-color: var(--warm-400);
  transition: color .15s;
}
body.is-admin .player-name-click:hover {
  color: var(--green);
  text-decoration-color: var(--green);
}
body.is-admin .player-name-click:active {
  opacity: .7;
}

/* 선수 교체 모달 */
.swap-member-list {
  max-height: 50vh;
}
.swap-member-option {
  cursor: pointer;
  transition: background .15s;
  border-radius: var(--radius);
}
.swap-member-option:hover {
  background: var(--cream-100);
}
.swap-member-option:active {
  background: var(--cream-200);
}

/* 전적 기록 아코디언 (페어/상대) */
.record-group {
  margin-bottom: .6rem;
}
.record-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .85rem;
  background: var(--purple);
  color: #fff;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font-weight: 600;
  font-size: .9rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.record-group-header:active {
  opacity: .85;
}
.record-group-arrow {
  font-size: .65rem;
  transition: transform .2s;
  flex-shrink: 0;
}
.record-group.open .record-group-arrow {
  transform: rotate(90deg);
}
.record-group-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .25s ease-out;
}
.record-group.open .record-group-body {
  max-height: 2000px;
  transition: max-height .4s ease-in;
}
.record-group-body table {
  margin-top: .4rem;
}
.record-group-body tr[data-event-id]:hover {
  background: var(--cream-200, #f0ede6);
}

/* 특별 포인트 수정 버튼 */
.special-points-edit {
  opacity: 0;
  transition: opacity .15s;
}
tr:hover .special-points-edit,
.special-points-edit:focus {
  opacity: 1;
}

/* 포인트 설정 카드 */
#pointSettingsCard {
  border-left: 3px solid var(--purple);
}
#pointSettingsCard .toolbar {
  align-items: center;
}

/* 회원 상세 - 총점수 행 */
.stat-item-full {
  grid-column: 1 / -1;
}

/* 데스크톱 */
@media (min-width: 769px) {
  .container { max-width: 700px; padding: 1.5rem; }
  nav { height: 54px; gap: 2rem; padding: 0 1.5rem; }
  .modal {
    border-radius: var(--radius);
    max-height: 80vh;
  }
  .modal-backdrop {
    align-items: center;
  }
  .toast {
    left: auto;
    right: 1.5rem;
    bottom: 1.5rem;
    max-width: 360px;
  }
}
