/* 모바일 우선, 기본 폰트/색상 */
:root {
  --bg: #f5f5f0;
  --card: #fff;
  --text: #1a1a1a;
  --text-muted: #666;
  --primary: #2d5a27;
  --primary-light: #e8f0e6;
  --accent: #c4a747;
  --border: #ddd;
  --danger: #c0392b;
  --safe: #27ae60;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --header-h: 52px;
  --nav-h: 56px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + 16px);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
}

/* 화면 전환 */
.screen {
  display: none;
  padding: 12px;
  padding-top: calc(var(--header-h) + 12px);
}

.screen.active {
  display: block;
}

/* 헤더 */
.app-header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--header-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  z-index: 100;
}

.app-header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  flex: 1;
  text-align: center;
}

/* 버튼 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--border);
  color: var(--text);
}

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

.btn.secondary {
  background: var(--primary-light);
  color: var(--primary);
}

.btn.icon {
  padding: 8px 12px;
  background: transparent;
  font-size: 1.2rem;
}

/* 로드 화면 */
.load-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.load-card .hint,
.hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 8px 0 16px;
}

.load-status {
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--primary);
}

.load-status.error {
  color: var(--danger);
}

/* 달력 */
.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
}

#current-month-label {
  font-weight: 600;
  font-size: 1.05rem;
}

.start-time-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 8px 0;
}

.start-time-row label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.start-time-row select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 1rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.calendar-grid .weekday {
  background: var(--primary-light);
  padding: 8px 4px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
}

.calendar-grid .weekday.sunday {
  background: #fde8e8;
  color: #d94f4f;
}

.calendar-grid .day-cell {
  background: var(--card);
  min-height: 44px;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  cursor: pointer;
}

.calendar-grid .day-cell.other-month {
  color: #aaa;
}

.calendar-grid .day-cell.sunday {
  background: #fff5f5;
  color: #d94f4f;
}

.calendar-grid .day-cell.sunday.other-month {
  background: #fff5f5;
  color: #edadad;
}

.calendar-grid .day-cell.today {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.calendar-grid .day-cell.has-event {
  background: var(--primary-light);
  color: var(--primary);
}

.calendar-grid .day-cell.sunday.has-event {
  background: #fde8e8;
  color: #d94f4f;
}

.calendar-grid .day-cell .day-num {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.calendar-grid .day-cell.today .day-num {
  background: rgba(0,0,0,.15);
}

/* 참여자 리스트 */
.participants-section h2,
.waiting-section h3 {
  font-size: 1rem;
  margin: 0 0 8px;
  color: var(--text-muted);
}

.participant-list {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.participant-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.participant-list li:last-child {
  border-bottom: none;
}

.participant-list .name-grade {
  font-weight: 500;
}

.participant-list .grade-tag {
  font-size: 0.75rem;
  color: var(--primary);
  margin-left: 6px;
}

.participant-list .check-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}

.participant-list .check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.participant-list input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.participant-list select {
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  min-width: 64px;
}

.day-actions {
  margin-top: 16px;
}

.day-actions .btn {
  width: 100%;
}

/* 대진표 */
.bracket-games {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bracket-actions {
  margin-top: 16px;
}

.bracket-actions .btn {
  width: 100%;
}

.bracket-actions .btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.bracket-notice {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.9rem;
  color: #856404;
  margin-bottom: 8px;
}

.bracket-empty-msg {
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 8px;
}

.bracket-toast {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.game-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.game-card h3 {
  margin: 0;
  padding: 10px 16px;
  background: var(--primary-light);
  font-size: 0.95rem;
  color: var(--primary);
}

.teams-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  padding: 12px;
}

.team-box {
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  text-align: center;
  position: relative;
}

.team-box.winner {
  border-color: var(--safe);
  background: #e8f8f0;
}

.team-box.draw {
  border-color: var(--accent);
  background: #fdf5e0;
}

.team-box .team-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.team-box .member {
  font-size: 0.9rem;
  margin: 2px 0;
}

.team-box[data-team-group]::before {
  content: attr(data-team-group);
  display: block;
  font-size: 0.65rem;
  color: var(--primary);
  margin-bottom: 6px;
}

.team-box::after {
  content: '합산 ' attr(data-team-score) '점';
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.team-box .dup-tag {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.62rem;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 6px;
  border: 1px solid #f2bcbc;
  background: #ffeaea;
  color: var(--danger);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.result-input {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.result-input label {
  font-size: 0.9rem;
}

.result-input select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 1rem;
}

.waiting-section {
  margin-top: 16px;
  padding: 12px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.waiting-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.9rem;
}

.waiting-section li {
  padding: 4px 0;
}

/* 순위/승률 */
.stats-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.stats-tabs .tab {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--card);
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-muted);
}

.stats-tabs .tab.active {
  background: var(--primary);
  color: #fff;
}

.stats-panel {
  display: none;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.stats-panel.active {
  display: block;
}

.rank-list, .vs-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.rank-list li, .vs-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.rank-list li:last-child, .vs-list li:last-child {
  border-bottom: none;
}

.rank-list li .name,
.vs-list li .name {
  font-weight: 500;
}

.rank-list li .score,
.vs-list li .rate {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.vs-select {
  margin-bottom: 16px;
}

.vs-select label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.vs-select select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 1rem;
}

/* 하단 네비 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 99;
}

.bottom-nav .nav-item {
  flex: 1;
  border: none;
  background: none;
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 12px;
}

.bottom-nav .nav-item.active {
  color: var(--primary);
  font-weight: 600;
}

/* 회원관리 화면 */
.member-password {
  padding: 20px;
}

.password-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  margin-top: 12px;
}

.error-message {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 8px;
}

.member-list {
  padding: 0;
}

.member-detail {
  padding: 20px;
}

.member-detail h2 {
  margin-bottom: 16px;
  color: var(--text);
}

.member-detail p {
  margin: 12px 0;
  font-size: 1rem;
  color: var(--text);
}

.member-detail p strong {
  color: var(--text);
  margin-right: 8px;
}

/* 모바일 터치 영역 확보 */
@media (max-width: 480px) {
  .calendar-grid .day-cell {
    min-height: 48px;
  }

  .participant-list li {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
  }

  .participant-list .name-grade {
    grid-column: 1;
  }

  .participant-list .check-group {
    grid-column: 1 / -1;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
}

/* 태블릿/데스크톱에서도 가독성 유지 */
@media (min-width: 481px) {
  #app {
    box-shadow: 0 0 0 1px var(--border);
  }
}

/* 대진표 편집 모드 */
.bracket-edit-btn-row {
  margin-bottom: 10px;
  display: flex;
  gap: 8px;
}

.bracket-edit-btn-row .btn {
  flex: 1;
}

.edit-mode-banner {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 0.82rem;
  color: #856404;
  margin-bottom: 10px;
  line-height: 1.5;
}

.player-chip {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 14px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 500;
  margin: 3px;
  cursor: pointer;
  border: 2px solid transparent;
  user-select: none;
  transition: background 0.13s, border-color 0.13s, color 0.13s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.player-chip:hover {
  border-color: var(--primary);
}

.player-chip.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45,90,39,0.18);
}

.player-chip.drag-over {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.player-chip.dragging {
  opacity: 0.45;
}

.player-chip.locked {
  background: #f0f0f0;
  color: #aaa;
  border-color: transparent;
  cursor: not-allowed;
  opacity: 0.75;
}

.team-members-edit {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  margin: 4px 0 2px;
}
