:root {
  /* Modernist 디자인 시스템(메인 대시보드와 동일 팔레트) — 좌측 패널/하단 툴바 등
     "크롬"은 전부 라이트 테마로 바뀌었지만, 실제 영상/캔버스가 나오는 무대(스테이지)만은
     목업 자체도 var(--color-neutral-900)로 계속 다크하게 유지하는 패턴을 그대로 따름. */
  --bg: #f3f2f2;
  --surface: #eae9e9;
  --surface-strong: #d7d3d3; /* 헤더바/탭바처럼 패널보다 한 단계 더 구분돼야 하는 곳 */
  --media-dark: #2d2b2b; /* 영상/캔버스 스테이지 전용 — 페이지가 라이트여도 계속 다크 */
  --text-main: #201e1d;
  --text-on-dark: #f8f4f4; /* 다크 스테이지 위에 얹는 텍스트 */
  --text-muted: #7d7979;
  --border-color: #bab6b6;
  /* 메인 대시보드 accent(#ec3013)와 통일 */
  --accent: #ec3013;
  --accent-hover: #dd2b0f;
  --panel-width: 350px;
  --bottom-height: 80px;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Archivo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg);
  color: var(--text-main);
  height: 100vh;
  display: grid;
  /* 좌측 단일 사이드바 구조 — 예전엔 좌(Explorer)/우(Viewer) 2개 패널로 나뉘어 있어서
     "정신없다"는 피드백을 받아 왼쪽 하나로 통합(섹션 전환 탭으로 구분). */
  grid-template-areas:
    "left main"
    "left bottom";
  grid-template-columns: var(--panel-width) minmax(400px, 1fr);
  grid-template-rows: 1fr auto; /* Changed from var(--bottom-height) to auto to support wrapping */
  /* grid-template-columns에 transition을 걸어뒀었는데(예전 코드), minmax()가 섞인 트랙 목록은
     브라우저마다 보간이 안 되거나 멈춰버려서 패널 숨기기 버튼을 눌러도 실제로는 안 접히는
     실제 버그였음(직접 확인함). 애니메이션 없이 즉시 전환되도록 transition 제거 — 더 확실하게
     작동하는 쪽을 택함. */
  overflow-x: hidden;
  overflow-y: hidden;
}

/* Toggle Animations via CSS Grid Changes */
body.hide-left {
  grid-template-columns: 0px minmax(400px, 1fr);
}

/* Base Panel Styles */
.panel {
  background-color: var(--surface);
  border-right: 1px solid var(--border-color);
  border-left: 1px solid var(--border-color);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  /* 그리드 아이템의 기본 min-width:auto가 내부 콘텐츠의 min-content 폭까지 강제로 확보해버려서,
     패널 숨기기(body.hide-left → 0px 트랙)를 눌러도 안쪽 자식들의 min-width:var(--panel-width)
     (panel-header/admin-section/match-list/event-list에 남아있던 값들) 때문에 실제로는 안 접혔던
     버그를 발견해서 고침. 이 min-width:0이 핵심 — 없으면 트랙을 0px로 줄여도 그리드 아이템이
     콘텐츠 폭만큼 다시 밀어냄. */
  min-width: 0;
}

#left-panel { grid-area: left; }

#main-panel { 
  grid-area: main; 
  background-color: var(--bg); 
  display: flex; 
  flex-direction: column; 
}

#bottom-panel { 
  grid-area: bottom; 
  background-color: var(--surface); 
  border-top: 1px solid var(--border-color); 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  flex-wrap: wrap; /* NEW: Allow items to wrap when squeezed */
  gap: 10px;
  padding: 10px 20px;
  z-index: 10;
  min-height: var(--bottom-height);
}

/* Headers */
.panel-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 10px 15px;
  background-color: var(--surface-strong);
  box-sizing: border-box;
  position: sticky;
  top: 0;
  z-index: 5;
  flex-shrink: 0;
}

.panel-header h2 { 
  margin: 0; 
  font-size: 1.2rem; 
  color: var(--text-main);
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
}

.workspace-header h1 { 
  margin: 0; 
  font-size: 1.5rem; 
  text-align: center; 
  flex-grow: 1; 
}

/* Buttons */
.toggle-btn, .show-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  transition: color 0.2s;
  padding: 5px;
}

.toggle-btn:hover, .show-btn:hover { 
  color: var(--accent); 
}

.show-btn {
  background-color: var(--surface-strong);
  border: 1px solid var(--border-color);
  border-radius: 0;
  font-size: 0.9rem;
}

.control-btn {
  background-color: var(--surface-strong);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 10px 15px;
  border-radius: 0;
  cursor: pointer;
  transition: all 0.2s;
}

.control-btn:hover { background-color: var(--border-color); }

.primary-btn { 
  background-color: var(--accent); 
  color: white; 
  border: none; 
  padding: 12px; 
  cursor: pointer; 
  border-radius: 0; 
  font-weight: bold; 
  margin-top: 15px; 
  transition: background-color 0.2s;
}

.primary-btn:hover { 
  background-color: var(--accent-hover); 
}

/* Utility */
.hidden { display: none !important; }

/* Video & Workspace */
.video-container {
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border-color);
  margin: 20px;
  border-radius: 0;
  background-color: var(--media-dark);
  color: var(--text-on-dark);
}

/* 영상 위 클릭/탭 오버레이 (player.js의 setupVideoTapControls가 만듦) — 항상 활성(데스크톱
   마우스든 모바일 터치든 전부). 한 번 클릭=재생/정지, 더블클릭/더블탭=5초 탐색. 유튜브
   iframe 위에 항상 이 오버레이가 먼저 있어서, 클릭이 iframe에 직접 닿는 일이 없음 — 유튜브
   자체의 "클릭하면 화면 중앙에 뜨는 재생/정지 아이콘"이 이 iframe 직접 클릭에서만 나오는
   자체 UI라, 클릭을 여기서 가로채면 애초에 뜨지 않음(그리기 방해 문제의 근본 해결). */
#tap-seek-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: auto;
  cursor: pointer;
}
#tap-seek-flash {
  position: absolute;
  top: 50%;
  width: 35%;
  padding: 14px 0;
  text-align: center;
  font-size: 1.1rem;
  font-weight: bold;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 0;
  transform: translateY(-50%) scale(0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 6;
}
#tap-seek-flash.left   { left: 0; }
#tap-seek-flash.right  { right: 0; }
#tap-seek-flash.center { left: 50%; width: 60%; transform: translate(-50%, -50%) scale(0.9); } /* 카메라 미시작 안내용 */
#tap-seek-flash.show   { opacity: 1; }
#tap-seek-flash.show:not(.center) { transform: translateY(-50%) scale(1); }
#tap-seek-flash.show.center { transform: translate(-50%, -50%) scale(1); }

.controls {
  display: flex;
  flex-wrap: wrap; /* NEW: Wrap controls to next line */
  justify-content: center; /* NEW: Center aligned when wrapped */
  gap: 12px;
  align-items: center;
  flex: 1 1 auto;
}

#timeline {
  flex-grow: 1;
  cursor: pointer;
  min-width: 150px;
}
#time-display {
  font-variant-numeric: tabular-nums; /* 숫자 폭이 고정돼서 재생 중에 깜빡거리듯 안 흔들림 */
  font-size: 0.85rem;
  color: var(--text-main);
  white-space: nowrap;
  min-width: 100px;
  text-align: center;
}

/* Admin Form & Lists */
.admin-section {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  box-sizing: border-box;
}

.admin-section h3 { 
  margin-top: 0; 
  color: var(--accent); 
  font-size: 1.1rem;
}

#match-form { display: flex; flex-direction: column; gap: 12px; }

#match-form label { 
  display: flex; 
  flex-direction: column; 
  font-size: 0.85rem; 
  color: var(--text-muted); 
  font-weight: 500;
}

#match-form input { 
  padding: 10px; 
  background-color: var(--bg); 
  border: 1px solid var(--border-color); 
  color: var(--text-main); 
  border-radius: 0; 
  margin-top: 6px; 
  outline: none;
  transition: border-color 0.2s;
}

#match-form input:focus { border-color: var(--accent); }

.match-list, .event-list {
  padding: 20px;
  box-sizing: border-box;
}

.match-list input { 
  width: 100%; 
  padding: 10px; 
  box-sizing: border-box; 
  background-color: var(--bg); 
  border: 1px solid var(--border-color); 
  color: var(--text-main); 
  border-radius: 0; 
  margin-bottom: 15px; 
}

.list-container {
  list-style: none;
  padding: 0;
  margin: 0;
}

.event-item {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background-color 0.2s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.event-item:hover { 
  background-color: rgba(32, 30, 29, 0.06); 
}

.event-item.active { 
  background-color: var(--accent); 
  color: white; 
  border-left: 4px solid var(--bg); 
}

.event-label {
  font-weight: bold;
  font-size: 0.95rem;
}

.event-team {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.event-time { 
  font-size: 0.8rem; 
  color: var(--text-muted); 
}

.event-item.active .event-time, .event-item.active .event-team { 
  color: var(--text-on-dark); 
}

/* --- Step 5 CSS: Code Viewer Grouping UI --- */
.code-tools {
  padding: 15px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border-color);
}
#event-search {
  width: 100%;
  padding: 10px;
  background-color: var(--bg);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 0;
  box-sizing: border-box;
  font-size: 0.9rem;
}
#event-search:focus {
  border-color: var(--accent);
  outline: none;
}
.group-header {
  background-color: var(--surface-strong);
  padding: 12px 15px;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.2s;
  user-select: none;
}
.group-header:hover {
  background-color: var(--border-color);
}
.group-badge {
  background-color: var(--accent);
  color: white;
  padding: 2px 8px;
  border-radius: 0;
  font-size: 0.75rem;
  font-family: monospace;
}
.group-content {
  display: none;
  flex-direction: column;
}
.group-content.open {
  display: flex;
}

/* Bottom Panel Ext */
.controls.drawing-controls {
  margin-left: auto;
}

.secondary-btn {
  background-color: var(--surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 0;
  cursor: pointer;
  transition: all 0.2s;
  padding: 5px 10px;
}

.secondary-btn:hover {
  background-color: var(--border-color);
  color: var(--text-main);
}

.draw-tools {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin-left: 15px;
  padding-left: 15px;
  border-left: 1px solid var(--border-color);
  opacity: 0.3;
  pointer-events: none;
  transition: opacity 0.3s;
}

.draw-tools.active {
  opacity: 1;
  pointer-events: auto;
}

/* Property controls styling for sliders in footer */
.draw-tools input[type="range"] {
  height: 4px;
  background: var(--border-color);
  border-radius: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.draw-tools input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

input[type="color"] {
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 0;
  cursor: pointer;
  background-color: transparent;
}

/* 하단 그리기 툴바 정리 — .separator는 원래 정의가 아예 없어서 안 보이는 빈 div였음(버그).
   실제 구분선으로 그리고, 도구 묶음마다 옅은 배경의 tool-group으로 묶어서 한눈에 구역이
   보이게 함. 기능은 그대로, 시각적 정리만. */
.separator {
  width: 1px;
  align-self: stretch;
  margin: 4px 2px;
  background-color: var(--border-color);
  flex-shrink: 0;
}

.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 0;
  background-color: rgba(32, 30, 29, 0.04);
  flex-shrink: 0;
}

/* 아이콘만 있는 도구 버튼은 텍스트 버튼과 같은 좌우 패딩을 쓰면 불필요하게 넓어져서
   따로 정사각형에 가깝게 맞춤 — 기능/클릭 핸들러는 그대로, 크기만 다름. */
.control-btn.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Highlighted state for active tools */
.control-btn.highlight {
  background-color: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Fabric.js Canvas Container Overrides */
.canvas-container {
  position: absolute !important;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
  pointer-events: none; /* View Mode Default */
  z-index: 10;
}
.canvas-container.draw-mode {
  pointer-events: auto !important; /* Draw Mode Active */
  z-index: 1000 !important; /* 분석 시 유튜브 UI 간섭 방지 */
  /* #tap-seek-overlay가 클릭을 먼저 가로채서(player.js) 유튜브 iframe이 "직접 클릭"을 받는
     일은 없어졌지만, 그리기 모드는 항상 영상을 정지시키고 시작하고(drawModeBtn 클릭 →
     pausePlayer()), 정지 상태가 되면 유튜브가 클릭 여부와 무관하게 자체 UI(제목바/추천영상
     등)를 띄움 — 그건 클릭 차단으로는 못 막음. 재생 중엔 원본 밝기 그대로 두고(배경 없음),
     "그리기 모드 + 정지 상태"일 때만(.yt-ui-masked, player.js의 updateDrawModeMask가 토글)
     어둡게 가려서 유튜브 UI를 감춤. */
}
.canvas-container.draw-mode.yt-ui-masked {
  background-color: rgba(0, 0, 0, 0.55);
}

/* 전체화면 버튼 — video-container 우상단에 항상 떠 있는 오버레이. 페이지 전체(document.documentElement)를
   전체화면으로 전환해서(video-container만이 아니라) 하단 재생/그리기 컨트롤이 계속 보이고 눌리게 함 —
   브라우저 Fullscreen API는 전체화면 대상 요소의 자손만 보여주므로, video-container만 전체화면하면
   그 바깥에 있는 #bottom-panel(재생바·그리기 툴바)이 통째로 안 보이게 되는 문제를 피하기 위함. */
.video-fullscreen-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 20;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: background-color 0.2s;
}
.video-fullscreen-btn:hover {
  background: rgba(0, 0, 0, 0.75);
}

/* 드로잉 모드 활성화 시 하단 컨트롤바 간섭 최소화 */
body.drawing-active .playback-controls {
  opacity: 0.3;
  pointer-events: none;
  transition: opacity 0.3s;
}
body.drawing-active .playback-controls:hover {
  opacity: 1;
  pointer-events: auto;
}

/* --- Step 9 CSS: Advanced Clip Library & Playlist Modal --- */
.tab-headers {
  display: flex;
  background-color: var(--surface-strong);
  border-bottom: 2px solid var(--border-color);
}
.tab-btn {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: bold;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px; /* overlap border */
}
.tab-btn:hover {
  color: var(--text-main);
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* 좌측 패널 상단 섹션 전환(Explorer ↔ Viewer) — tab-btn보다 한 단계 위 레벨이라
   눈에 더 잘 띄게 배경을 채우는 pill 스타일로 구분. */
.section-tabs {
  display: flex;
  gap: 4px;
  background-color: var(--bg);
  border-bottom: 1px solid var(--border-color);
  padding: 6px;
  flex-shrink: 0;
}
.section-tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px;
  background: none;
  border: none;
  border-radius: 0;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: bold;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.section-tab-btn:hover { background-color: rgba(32, 30, 29, 0.06); color: var(--text-main); }
.section-tab-btn.active { background-color: var(--accent); color: white; }

/* 선수단 배포 링크(?lock=1)용 — Explorer(다른 경기 탐색·연결 해제 등 관리 기능)를 완전히
   숨기고 이 경기의 Viewer(장면/이벤트) 화면에만 갇히게 함. app.js의 handleUrlParams가
   body에 이 클래스를 붙임. */
body.locked-viewer-mode .section-tabs,
body.locked-viewer-mode #section-explorer {
  display: none !important;
}

.section-content {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.section-content.active { display: flex; }

.library-filters select {
  padding: 10px;
  background-color: var(--bg);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 0;
  outline: none;
  transition: border-color 0.2s;
}
.library-filters select:focus {
  border-color: var(--accent);
}
.filter-code-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  font-size: 0.9rem;
  color: var(--text-main);
  cursor: pointer;
  border-radius: 0;
}
.filter-code-label:hover {
  background-color: rgba(32, 30, 29, 0.05);
}

/* Card Grid for Library Results */
#library-results-ul {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 0;
}
.clip-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: var(--surface);
  border: 1px solid var(--border-color);
  padding: 12px;
  border-radius: 0;
  transition: transform 0.2s, box-shadow 0.2s, background-color 0.2s;
}
.clip-item:hover {
  background-color: var(--surface-strong);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.clip-item.selected {
  border-color: var(--accent);
  background-color: rgba(236, 48, 19, 0.08);
}

.clip-checkbox-container {
  display: block;
  position: relative;
  padding-left: 24px;
  cursor: pointer;
  user-select: none;
  height: 20px;
}
.clip-checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}
.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 20px;
  width: 20px;
  background-color: var(--bg);
  border: 1px solid var(--border-color);
  border-radius: 0;
  transition: background-color 0.2s, border-color 0.2s;
}
.clip-checkbox-container:hover input ~ .checkmark {
  border-color: #888;
}
.clip-checkbox-container input:checked ~ .checkmark {
  background-color: var(--accent);
  border-color: var(--accent);
}
.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}
.clip-checkbox-container input:checked ~ .checkmark:after {
  display: block;
}
.clip-checkbox-container .checkmark:after {
  left: 6px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.clip-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.clip-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.clip-code {
  font-size: 0.95rem;
  font-weight: bold;
  color: var(--text-main);
}
.clip-team {
  font-size: 0.8rem;
  color: #ff9800;
  background-color: rgba(255, 152, 0, 0.15);
  padding: 2px 6px;
  border-radius: 0;
}
.clip-match {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.clip-time {
  font-size: 0.8rem;
  color: var(--text-muted);
}

#btn-create-playlist {
  width: 100%;
  box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
  animation: slideUp 0.3s ease-out;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
#btn-create-playlist:hover {
  background-color: #439a46;
}

/* Playlist Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.modal-content {
  background-color: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 0;
  padding: 25px;
  width: 400px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-overlay.active .modal-content {
  transform: translateY(0);
}
.modal-content h3 {
  margin-top: 0;
  color: var(--text-main);
}
#playlist-title {
  width: 100%;
  padding: 12px;
  background-color: var(--bg);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 0;
  margin: 15px 0;
  box-sizing: border-box;
}
#playlist-title:focus {
  border-color: var(--accent);
  outline: none;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.btn-cancel, .btn-confirm {
  padding: 10px 15px;
  border-radius: 0;
  border: none;
  cursor: pointer;
  font-weight: bold;
}
.btn-cancel {
  background-color: transparent;
  color: var(--text-muted);
}
.btn-cancel:hover {
  color: var(--text-main);
  background-color: rgba(32,30,29,0.06);
}
.btn-confirm {
  background-color: var(--accent);
  color: white;
}
.btn-confirm:hover {
  background-color: var(--accent-hover);
}

/* --- Match Item Styles --- */
.match-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(32,30,29,0.03);
    border-radius: 0;
    padding: 12px;
    margin-bottom: 8px;
    transition: all 0.2s;
    border: 1px solid transparent;
}
.match-item:hover {
    background: rgba(32,30,29,0.06);
    border-color: var(--border-color);
}
.match-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.match-info strong {
    color: var(--text-main);
    font-size: 0.95rem;
}
.match-info span {
    color: var(--text-muted);
    font-size: 0.8rem;
}
.match-actions {
    display: flex;
    gap: 6px;
}
.small-btn {
    width: 32px;
    height: 32px;
    border-radius: 0;
    border: 1px solid var(--border-color);
    background: var(--bg);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    font-size: 1rem;
    transition: all 0.2s;
}
.small-btn:hover {
    background: var(--accent);
    color: white;
    transform: translateY(-2px);
}
.stats-btn:hover {
    background: #2196f3;
}
.analyze-btn:hover {
    background: #ff9800;
}

/* ── 모바일 공통(세로/가로 둘 다) 오버플로 정리 ──
   상단 헤더(제목+대시보드 홈+카메라 전환 버튼)와 하단 툴바(재생/배속/타임라인 + 그리기 도구
   20개 가까이)가 좁은 화면에 한 줄로 다 안 들어가 카메라3/4번·뒤쪽 그리기 도구가 화면 밖으로
   밀려나가 아예 안 보이고 안 눌리던 문제 — 줄바꿈 대신 가로 스크롤 한 줄로 바꿔서 스와이프로
   전부 접근 가능하게 함(실측: 카메라 버튼 그룹 폭 450px vs 화면 375px, 그리기 툴바 1352px).
   가로 모드(랜드스케이프)에서도 폭이 좁은 폰(예: 667px)에선 여전히 필요해서 방향 무관하게
   적용 — 폭 기준만 봄(940px는 큰 폰 가로 폭까지 커버). */
@media (max-width: 940px) {
  .workspace-header {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px 12px;
  }
  .workspace-header h1 {
    flex-shrink: 0;
    font-size: 1.05rem;
  }
  .workspace-header a.primary-btn {
    flex-shrink: 0;
    font-size: 0 !important;
    padding: 8px !important;
  }
  .workspace-header a.primary-btn i {
    font-size: 1rem;
  }
  .camera-toggles {
    flex-shrink: 0;
    margin-left: 8px !important;
  }
  .camera-toggles button {
    flex-shrink: 0;
  }

  #bottom-panel {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    padding: 8px 12px;
  }
  #bottom-panel > * {
    flex-shrink: 0;
  }
  .controls.drawing-controls {
    flex-wrap: nowrap;
    margin-left: 12px !important;
  }
  .tool-group {
    flex-shrink: 0;
  }
}

/* ── 모바일 세로(포트레이트) 레이아웃 ──
   기존 좌(Explorer/Viewer 350px 고정폭) + 우(영상, 최소 400px) 2열 그리드는 좁은 화면에서
   그대로 쓰면 영상이 찌그러지게 눌리거나(혹은 좌우로 잘려나감). "화면이 위로 가고(영상이
   위) 뷰어/익스플로어는 아래로 내려가야" 한다는 피드백대로, 세로 1열 스택으로 재구성:
   영상(위) → Explorer/Viewer(가운데) → 하단 재생/그리기 컨트롤(아래) 순으로 쌓고 페이지
   전체가 세로 스크롤되게 함. 세로에서만 적용 — 가로(랜드스케이프)는 세로 스택하면 영상이
   가로로 긴 화면에서 얇게 눌려버려서 아래 별도 규칙으로 원래 좌우 그리드를 유지함. */
@media (max-width: 768px) and (orientation: portrait) {
  body {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
  }
  #main-panel {
    order: 1;
    min-height: 42vh; /* 영상이 너무 작아지지 않을 정도의 최소 높이 */
  }
  #left-panel {
    order: 2;
    max-height: 65vh; /* Explorer/Viewer 목록은 이 안에서 자체 스크롤(.panel이 이미 overflow-y:auto) */
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
  }
  #bottom-panel {
    order: 3;
  }
  /* 데스크톱 전용 사이드바 접기(hide-left)는 그리드 트랙 기반이라 모바일 flex 레이아웃에선
     의미가 없어짐 — 버튼 자체를 숨겨서 눌러도 아무 반응 없어 보이는 걸 방지 */
  #toggle-left-btn, #show-left-btn { display: none; }
}

/* ── 모바일 가로(랜드스케이프) 레이아웃 ──
   세로 스택 레이아웃을 가로에도 그대로 쓰면(예전 버그) 화면 높이가 짧아서(폰 가로 400px
   안팎) 영상 영역이 min-height:42vh(≈160px) 정도로 눌리고, 그 안에서 유튜브 iframe이
   width/height 100%로 꽉 채우다 보니 가로로 아주 넓고 얇게 찌그러진 채 나오던 문제
   ("유튜브 화면이 제대로 안나옴") — 가로에서는 위 포트레이트 전용 세로 스택 규칙을 아예
   안 걸어서 원래 데스크톱 좌우 그리드(영상 | 패널, body 기본 규칙)가 그대로 살아나게 하고,
   패널 폭만 좁혀서 영상이 화면 높이 전체를 그대로 쓰게 함. grid-template-areas/columns 구조
   자체는 body 기본값과 동일하게 유지 — body.hide-left(패널 접기)가 "첫 컬럼=left" 가정으로
   0px를 주는 기존 규칙과도 그대로 호환됨. */
@media (max-width: 940px) and (orientation: landscape) {
  :root {
    /* 260px는 폭이 좁은 실기기 가로 화면(예: 667px)에서 영상 영역을 407px까지 눌러버려서
       "화면이 너무 작다"는 피드백으로 축소 — 목록 텍스트는 여전히 읽을 수 있는 선. */
    --panel-width: 200px;
  }
  body {
    height: 100vh;
    overflow: hidden;
  }
  #left-panel {
    max-height: none;
  }
  #bottom-panel {
    min-height: 56px;
    padding: 6px 12px;
  }
  /* 터치 타깃 확대 — 기존 29x32px(패널 토글)/38x38px(전체화면)는 실기기 터치로 정확히
     누르기 어려워서(사용자 신고: "옆에 익스플로어 접는 게 잘 안 됨") Apple/Google 권장
     최소 터치 영역(44px)에 맞춤. 아이콘 자체 크기는 유지하고 클릭 가능 영역만 넓힘. */
  #toggle-left-btn, #show-left-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 1.4rem;
  }
  .video-fullscreen-btn {
    width: 44px;
    height: 44px;
    font-size: 1.3rem;
  }
  /* 카메라 전환 버튼 줄(전술캠1~3·중계캠)이 좁은 화면에선 가로 스크롤 밖으로 밀려나는데
     (기존 overflow-x:auto 자체는 정상 동작 — 위 940px 공통 규칙), 스크롤 가능하다는
     시각적 힌트가 없어 "화면 밖에 있는 버튼을 놓쳤다"는 인상을 줌. 오른쪽 끝에 옅은
     그라디언트 페이드로 "더 있음"을 암시. */
  .workspace-header {
    position: relative;
  }
  .workspace-header::after {
    content: '';
    position: sticky;
    right: 0;
    top: 0;
    height: 100%;
    width: 24px;
    margin-left: -24px;
    flex-shrink: 0;
    background: linear-gradient(to right, transparent, var(--bg));
    pointer-events: none;
  }
}
