/* ==========================================================================
   축구/농구 리모컨 공용 스타일
   야구 리모컨(scoreboard-rt-tp1)의 "컨트롤 영역" 스타일을 그대로 이식했다.
   - 카드: #1e1e1e 배경 + #333 테두리 (야구 .control-group)
   - 액센트: #ffcc00 (야구 리모컨과 동일). 종목 구분은 헤더 이모지로만 한다.
   ========================================================================== */
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  padding: 0;
  background-color: #121212;
  color: #e0e0e0;
  font-family: "Pretendard", "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#sp-app {
  --accent: #ffcc00;
  background-color: #121212;
  color: #e0e0e0;
  max-width: 640px;
  margin: 0 auto;
  padding: 15px;
  padding-bottom: 60px;
  min-height: 100vh;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
#sp-app * {
  box-sizing: border-box;
}
/* 입력 필드는 텍스트 선택 허용 */
#sp-app input,
#sp-app textarea {
  user-select: text;
  -webkit-user-select: text;
}

/* --- [헤더] --- */
.sp-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #333;
}
.sp-header h2 {
  margin: 0;
  font-size: 18px;
  color: #ffcc00;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sp-header-btns {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.status-text {
  font-size: 12px;
  color: #95a5a6;
  margin-right: 4px;
}
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
  vertical-align: middle;
}
.dot.connected {
  background: #00ff00;
  box-shadow: 0 0 6px #00ff00;
}
.dot.loading {
  background: #f1c40f;
}
.dot.error {
  background: #ff0000;
  box-shadow: 0 0 6px #ff0000;
}

/* 버튼 공통 (야구 헤더 버튼 이식) */
.sp-btn {
  background: #2c2c2c;
  color: #fff;
  border: 1px solid #444;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: bold;
}
.sp-btn:hover {
  background: #3a3a3a;
}
.sp-btn.danger {
  background: #fdfdfd;
  border: 1px solid #ff4d4f;
  color: #ff4d4f;
}
.sp-btn.danger:hover {
  background: #fff1f0;
}
/* 새 경기(초기화) 버튼 — 야구 btn-newgame(오렌지) */
.sp-btn.wide {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  background: #e67e22;
  border: none;
  color: #fff;
}
.sp-btn.wide:hover {
  background: #d35400;
}

/* --- [컨트롤 카드] 야구 .control-group 이식 --- */
.sp-group,
.sp-ctrl {
  background: #1e1e1e;
  padding: 15px;
  border-radius: 10px;
  margin-bottom: 6px;
  border: 1px solid #333;
}
.sp-label {
  display: block;
  font-size: 11px;
  color: #888;
  margin-bottom: 8px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
#sp-app input[type="text"] {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  text-align: center;
  background: #2c2c2c;
  border: 1px solid #444;
  border-radius: 6px;
  color: #fff;
}
#sp-app input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* --- [라이브 프리뷰] 야구 미니 스코어보드(preview-box) 이식 --- */
.sp-preview {
  position: sticky;
  top: 0;
  z-index: 100;
  margin-bottom: 6px;
  background: linear-gradient(145deg, #1e1e1e, #000);
  border: 1px solid #333;
  border-radius: 12px;
  padding: 18px 14px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
}
.sp-period-badge {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #000;
  font-size: 13px;
  font-weight: 700;
  padding: 3px 14px;
  border-radius: 20px;
}
.sp-teams {
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin-top: 14px;
}
.sp-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.sp-logo {
  width: 70px;
  height: 70px;
  object-fit: contain;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid #444;
}
.sp-tname {
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sp-score {
  font-size: 48px;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.sp-vs {
  font-size: 34px;
  font-weight: 800;
  color: #55627a;
  padding: 0 6px;
}

/* ==========================================================================
   컨트롤 그룹 드래그 정렬 (야구 리모컨과 동일 UX)
   ========================================================================== */
.sp-draggable {
  position: relative;
}
/* 드래그 핸들: 섹션 오른쪽 위 작은 아이콘. 이 아이콘에서만 드래그 시작. */
.sp-drag-handle {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 5;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  color: #666;
  background: rgba(58, 58, 58, 0.55);
  font-size: 16px;
  line-height: 1;
  padding: 5px 7px;
  border-radius: 6px;
}
.sp-drag-handle:active {
  cursor: grabbing;
  color: var(--accent);
}
/* 헤더 있는 섹션은 토글 아이콘과 겹치지 않도록 우측 여백 확보 */
.sp-draggable .sp-layout-header {
  padding-right: 44px;
}
.sp-dragging {
  opacity: 0.5;
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
  border-radius: 10px;
}

/* --- [테마 선택] 드롭다운 + 적용 버튼 --- */
.sp-theme-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.sp-theme-row .sp-layout-select {
  flex: 1;
  margin: 0;
}
.sp-apply-btn {
  flex: 0 0 68px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.sp-apply-btn:hover {
  filter: brightness(1.08);
}
.sp-apply-btn:active {
  transform: scale(0.96);
}

/* --- [전/후반, 쿼터 버튼] 야구 버튼(#3a3a3a) 이식 --- */
.sp-period-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.sp-period {
  flex: 1;
  min-width: 64px;
  padding: 14px 6px;
  font-size: 16px;
  font-weight: bold;
  background: #3a3a3a;
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 6px;
  cursor: pointer;
}
.sp-period.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}

/* --- [팀 컨트롤] --- */
.sp-ctrl.away {
  border-left: 5px solid #3498db;
}
.sp-ctrl.home {
  border-left: 5px solid #e74c3c;
}
.sp-ctrl input[type="text"] {
  margin-bottom: 10px;
}
.sp-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sp-logo-btn {
  background: #3a3a3a;
  color: #fff;
  border: none;
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
}
.sp-score-btns {
  display: flex;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.sp-score-btns button {
  min-width: 56px;
  padding: 14px 10px;
  font-size: 20px;
  font-weight: 800;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: #fff;
}
.sp-plus {
  background: #27ae60;
}
.sp-plus:hover {
  background: #219150;
}
.sp-minus {
  background: #c0392b;
}
.sp-minus:hover {
  background: #a93226;
}
.sp-plus:active,
.sp-minus:active,
.sp-period:active,
.sp-btn:active,
.sp-logo-btn:active {
  transform: scale(0.96);
}

/* ==========================================================================
   화면 배치조절 / 위치·크기 미세조절 (야구 리모컨과 동일 기능)
   접이식 헤더/본문은 별도 카드가 아니라 .sp-group 카드 안에 배치된다.
   ========================================================================== */
.sp-layout-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  color: #ffcc00;
  font-weight: bold;
  font-size: 14px;
}
.sp-toggle-icon {
  font-size: 12px;
  background: #3a3a3a;
  padding: 3px 10px;
  border-radius: 6px;
  color: #cfd8e3;
  font-weight: 600;
}
.sp-layout-content {
  margin-top: 10px;
}
.sp-layout-select {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  background: #222;
  color: #fff;
  border: 1px solid #555;
  border-radius: 6px;
}
.sp-layout-select:focus {
  outline: none;
  border-color: var(--accent);
}
.sp-layout-hint {
  font-size: 12px;
  color: #888;
  margin: 12px 0 4px 2px;
}
.sp-layout-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.sp-layout-btn {
  padding: 14px 6px;
  font-size: 18px;
  background: #3a3a3a;
  color: #fff;
  border: 1px solid #444;
  border-radius: 6px;
  cursor: pointer;
}
.sp-layout-btn:hover {
  border-color: var(--accent);
}
.sp-layout-btn.reset {
  font-size: 13px;
  font-weight: bold;
  background: #2c2c2c;
}
.sp-layout-scale {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.sp-layout-scale .sp-layout-btn {
  flex: 1;
  font-size: 15px;
  font-weight: bold;
}
.sp-layout-btn:active {
  transform: scale(0.96);
}

/* ==========================================================================
   [NEW] 팀 로고 라이브러리 모달 (축구·농구 공용) — 야구 리모컨 기능 이식
   ========================================================================== */
.sp-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.sp-modal-overlay.open {
  display: flex;
}
.sp-modal-content {
  background: #1f2733;
  color: #e8edf3;
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.sp-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 800;
  background: #16a085;
  color: #fff;
}
.sp-modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  flex: 1;
}
.sp-modal-footer {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.logo-lib-count {
  font-size: 13px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.25);
  padding: 3px 10px;
  border-radius: 10px;
}
/* [추가] 로고 미리보기 모달 (야구 리모컨과 동일 구성) */
.logo-preview-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.logo-preview-img {
  max-width: 100%;
  max-height: 40vh;
  object-fit: contain;
  background: #10161e;
  border-radius: 8px;
  padding: 8px;
}
.logo-preview-zoom {
  display: flex;
  gap: 8px;
}
.logo-preview-actions {
  flex-wrap: wrap;
}
.logo-preview-actions .sp-btn {
  flex: 1;
  min-width: 90px;
}
.logo-lib-info {
  font-size: 12px;
  color: #9aa7b4;
  margin-bottom: 10px;
  line-height: 1.4;
}
.logo-lib-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.logo-lib-msg {
  grid-column: 1 / -1;
  text-align: center;
  color: #9aa7b4;
  padding: 20px;
}
.logo-lib-msg.error {
  color: #e74c3c;
}
.logo-lib-item {
  border: 1px solid #3a4553;
  border-radius: 6px;
  padding: 6px;
  background: #283442;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.logo-lib-thumb {
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #10161e;
  border-radius: 4px;
  overflow: hidden;
}
.logo-lib-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.logo-lib-name {
  font-size: 11px;
  color: #c7d0da;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logo-lib-item-actions {
  display: flex;
  gap: 4px;
}
.logo-lib-select {
  flex: 1;
  background: #27ae60;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 0;
  font-size: 12px;
  cursor: pointer;
}
.logo-lib-del {
  background: #c0392b;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
}
.logo-lib-add-btn {
  flex: 1;
  background: #3498db;
  padding: 10px;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
}

/* --- [테마 썸네일 그리드] 테마(방송 스타일) 패널의 테마 선택 UI (야구 리모컨과 동일 룩) --- */
.theme-thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 10px;
  padding-right: 2px; /* 스크롤바와 카드 간격 */
}
.theme-thumb-card {
  position: relative; /* 선택 체크 배지 기준점 */
  background: #1e1e1e;
  border: 2px solid #333;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.theme-thumb-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #14181d; /* 썸네일 여백색과 동일 */
}
.theme-thumb-label {
  padding: 4px 5px;
  font-size: 10px;
  color: #ccc;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.theme-thumb-card.selected {
  border-color: #ff9f43;
  box-shadow: 0 0 0 1px #ff9f43, 0 0 10px rgba(255, 159, 67, 0.55);
}
.theme-thumb-card.selected .theme-thumb-label {
  color: #111;
  background: #ff9f43;
  font-weight: 700;
}
/* 선택 체크 배지 (썸네일 우상단) */
.theme-thumb-card.selected::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ff9f43;
  color: #111;
  font-size: 12px;
  font-weight: 900;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
/* 썸네일 이미지가 없는 테마(캡처 전) — 라벨만 크게 보여주는 플레이스홀더 */
.theme-thumb-card.no-thumb img {
  display: none;
}
.theme-thumb-card.no-thumb .theme-thumb-label {
  aspect-ratio: 16 / 6;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: normal;
  font-size: 12px;
}

/* === [GUIDE] 단계별 사용 안내 (SB.startGuide / SB.maybeAutoGuide) ===
   야구 리모컨(scoreboard-rt-tp1.css)과 동일한 모양을 유지한다. */
.guide-overlay-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: transparent;
  z-index: 9998;
  display: none;
}
.guide-highlight {
  position: relative;
  z-index: 9999 !important;
  box-shadow:
    0 0 0 4px #e67e22,
    0 0 0 9999px rgba(0, 0, 0, 0.7);
  border-radius: 6px;
  pointer-events: none; /* 가이드 중 오조작 방지 */
}
.guide-tooltip {
  position: absolute;
  z-index: 10000;
  background: #fff;
  color: #333;
  padding: 15px;
  border-radius: 8px;
  width: 300px;
  max-width: calc(100vw - 20px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  line-height: 1.5;
  display: none;
  word-break: keep-all;
}
.guide-tooltip h4 {
  margin: 0 0 8px 0;
  color: #e67e22;
  font-size: 16px;
  border-bottom: 1px solid #eee;
  padding-bottom: 5px;
}
.guide-tooltip .guide-content {
  margin-bottom: 15px;
  color: #555;
}
.guide-tooltip .guide-nav {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}
.guide-tooltip button {
  padding: 10px 14px; /* 터치 타겟 확보 */
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  pointer-events: auto;
}
.guide-tooltip button:hover {
  background: #2980b9;
}
.guide-tooltip button.close {
  background: #95a5a6;
}
.guide-tooltip button.close:hover {
  background: #7f8c8d;
}
