/* CSS 變數 - 用於動態調整縮放 */
:root {
  --chat-min-width: 300px; /* 基礎最小寬度，會根據縮放動態調整 */
  --chat-min-height: 200px; /* 基礎最小高度 */
  --fixed-chat-min-width: 300px; /* 固定布局聊天室最小寬度 */
  --separated-chat-min-width: 300px; /* 分離聊天室最小寬度 */
  --base-font-size: 16px; /* 基礎字體大小 */
  --zoom-factor: 1; /* 縮放因子，由 JavaScript 動態設置 */
  
  /* 主題變數 - 暗色主題（預設） */
  --bg-primary: #0a0a0a;
  --bg-secondary: #000;
  --bg-tertiary: #111;
  --bg-quaternary: #0e0e0e;
  --bg-panel: rgba(0, 0, 0, 0.95);
  --bg-panel-hover: rgba(0, 0, 0, 0.85);
  --bg-input: #1a1a1a;
  --bg-button: #1a1a1a;
  --bg-button-hover: #333;
  --bg-button-active: #9147ff;
  --border-color: #333;
  --border-color-hover: #444;
  --border-color-active: #9147ff;
  --text-primary: #fff;
  --text-secondary: #aaa;
  --text-accent: #9147ff;
  --shadow-color: rgba(0, 0, 0, 0.9);
  --shadow-accent: rgba(145, 71, 255, 0.5);
}

/* 亮色主題 */
[data-theme="light"] {
  --bg-primary: #f5f5f5;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f0f0;
  --bg-quaternary: #fafafa;
  --bg-panel: rgba(255, 255, 255, 0.95);
  --bg-panel-hover: rgba(255, 255, 255, 0.85);
  --bg-input: #ffffff;
  --bg-button: #ffffff;
  --bg-button-hover: #e0e0e0;
  --bg-button-active: #9147ff;
  --border-color: #ddd;
  --border-color-hover: #ccc;
  --border-color-active: #9147ff;
  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --text-accent: #9147ff;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --shadow-accent: rgba(145, 71, 255, 0.3);
}

* { box-sizing: border-box; }

/* Select 元素樣式 */
select {
  background: var(--bg-input);
  border: 1px solid var(--border-color-hover);
  color: var(--text-primary);
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

select:focus {
  outline: none;
  border-color: var(--border-color-active);
}
html {
  overflow-x: hidden; /* 防止水平滾動 */
  width: 100%;
  max-width: 100vw; /* 確保不超過視窗寬度 */
}
body { 
  margin: 0; 
  background: var(--bg-primary); 
  color: var(--text-primary); 
  font-family: 'Segoe UI', Arial, sans-serif; 
  overflow-x: hidden; /* 防止水平滾動 */
  overflow-y: auto; /* 允許垂直滾動 */
  width: 100%;
  max-width: 100vw; /* 確保不超過視窗寬度 */
  font-size: var(--base-font-size); /* 使用相對單位 */
  transition: background-color 0.3s ease, color 0.3s ease;
}

#container { 
  position: relative; 
  width: 100%; 
  max-width: 100vw; /* 確保不超過視窗寬度 */
  height: 100vh; 
  background: var(--bg-secondary);
  transition: height 0.5s ease-in-out, padding-bottom 0.5s ease-in-out, padding-right 0.3s ease, background-color 0.3s ease;
  padding-bottom: 0;
  padding-right: 0;
  overflow-x: hidden; /* 防止水平滾動 */
}

body:has(.control-panel:not(.collapsed)) #container {
  padding-right: 550px;
}

/* 響應式調整：根據視窗大小動態調整 padding */
@media (max-width: 1024px) {
  body:has(.control-panel:not(.collapsed)) #container {
    padding-right: 450px;
  }
}

@media (max-width: 768px) {
  body:has(.control-panel:not(.collapsed)) #container {
    padding-right: 0;
  }
}

.stream-box {
  position: absolute; 
  background: var(--bg-tertiary); 
  border: 2px solid var(--border-color); 
  box-shadow: 0 0 30px var(--shadow-color);
  overflow: hidden; 
  border-radius: 8px; 
  -webkit-user-select: none;
  user-select: none;
  display: flex;
  flex-direction: column;
  min-width: 300px;
  min-height: 200px;
  transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.stream-box.active {
  border-color: var(--border-color-active);
  box-shadow: 0 0 40px var(--shadow-accent);
}


.content-wrapper {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
  min-height: 200px;
}

.content-wrapper.layout-horizontal {
  flex-direction: row;
}

.content-wrapper.layout-vertical {
  flex-direction: column;
}

.player-container {
  flex: 1;
  position: relative;
  min-height: 200px;
  min-width: 200px;
}

.player-container iframe { 
  width: 100%; 
  height: 100%; 
  border: none; 
  display: block;
}

.chat-container {
  background: var(--bg-quaternary);
  transition: all 0.3s ease, background-color 0.3s ease;
  overflow: hidden;
  position: relative;
  min-height: 100px;
  min-width: var(--chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
}

.content-wrapper.layout-horizontal .chat-container {
  width: max(300px, var(--chat-min-width, 300px)); /* 確保不小於最小寬度 */
  min-width: var(--chat-min-width, 300px); /* 確保最小寬度 */
  height: 100%;
  border-left: 1px solid var(--border-color);
}

.content-wrapper.layout-vertical .chat-container {
  width: 100%;
  min-width: var(--chat-min-width, 300px); /* 垂直布局時也確保最小寬度 */
  height: max(250px, var(--chat-min-height, 200px) * 1.25); /* 根據縮放調整高度 */
  min-height: max(250px, var(--chat-min-height, 200px) * 1.25); /* 確保最小高度 */
  border-top: 1px solid var(--border-color);
}

.chat-container.hidden {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow: hidden !important;
}

.chat-container.hidden .chat-resizer {
  display: none !important;
}

.chat-container iframe {
  width: 100%;
  height: 100%;
  border: none;
  min-width: var(--chat-min-width, 300px); /* YouTube 聊天室 iframe 最小寬度，根據縮放動態調整 */
  min-height: var(--chat-min-height, 200px); /* 確保最小高度，根據縮放動態調整 */
}

.chat-resizer {
  position: absolute;
  background: transparent;
  z-index: 10;
  transition: background 0.2s;
}

/* 水平排列時的調整器（在左側） */
.content-wrapper.layout-horizontal .chat-resizer {
  top: 0;
  left: 0;
  right: auto;
  bottom: auto;
  width: 4px;
  height: 100%;
  cursor: ew-resize;
}

/* 垂直排列時的調整器（在頂部） */
.content-wrapper.layout-vertical .chat-resizer {
  top: 0;
  left: 0;
  right: 0;
  bottom: auto;
  width: 100%;
  height: 4px;
  cursor: ns-resize;
}

.chat-resizer:hover {
  background: rgba(145, 71, 255, 0.5);
}

/* 水平排列時的指示線 */
.content-wrapper.layout-horizontal .chat-resizer::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 40px;
  background: #9147ff;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s;
}

/* 垂直排列時的指示線 */
.content-wrapper.layout-vertical .chat-resizer::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 2px;
  background: #9147ff;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s;
}

.chat-resizer:hover::before {
  opacity: 1;
}

.separated-chat {
  position: fixed;
  background: var(--bg-tertiary);
  border: 2px solid var(--border-color-active);
  box-shadow: 0 0 30px var(--shadow-accent);
  border-radius: 8px;
  z-index: 2000;
  min-width: var(--separated-chat-min-width, 300px); /* 根據縮放動態調整 */
  min-height: max(400px, var(--chat-min-height, 200px) * 2); /* 根據縮放調整高度 */
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.separated-chat-header {
  height: 35px;
  background: rgba(145, 71, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  cursor: move;
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
  font-weight: bold;
  color: var(--text-accent);
  transition: border-color 0.3s ease;
}

.separated-chat-content {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.separated-chat-content iframe {
  width: 100%;
  height: 100%;
  border: none;
  min-width: var(--separated-chat-min-width, 300px); /* YouTube 聊天室 iframe 最小寬度，根據縮放動態調整 */
  min-height: var(--chat-min-height, 200px); /* 確保最小高度，根據縮放動態調整 */
}

.controls {
  height: 45px; 
  background: var(--bg-panel-hover); 
  display: flex; 
  align-items: center; 
  padding: 0 12px;
  gap: 12px; 
  font-size: 13px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.controls .stream-label {
  font-weight: bold;
  color: var(--text-accent);
  min-width: 50px;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 200px;
}

.volume {
  flex: 1;
  height: 6px;
  cursor: pointer;
}

.vol-value {
  min-width: 40px;
  text-align: right;
  font-size: 12px;
  color: var(--text-secondary);
}

.control-btn {
  background: transparent;
  border: 1px solid var(--border-color-hover);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.2s, background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

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

.close { 
  cursor: pointer; 
  color: #ff4444; 
  font-weight: bold; 
  font-size: 18px;
  padding: 0 8px;
  transition: transform 0.2s;
}

.close:hover {
  transform: scale(1.2);
}

.control-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  width: 550px;
  height: 100vh;
  z-index: 1000;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-color);
  box-shadow: -4px 0 20px var(--shadow-color);
  transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.control-panel.collapsed {
  transform: translateX(100%);
}

.control-panel-toggle-collapsed {
  display: none;
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 1002;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid #333;
  border-right: none;
  border-radius: 4px 0 0 4px;
  padding: 12px 8px;
  color: #9147ff;
  font-size: 16px;
  transition: all 0.3s ease;
  box-shadow: -2px 0 10px rgba(0,0,0,0.5);
}

.control-panel-toggle-collapsed:hover {
  background: rgba(145, 71, 255, 0.2);
  padding-right: 12px;
}

body:has(.control-panel.collapsed) .control-panel-toggle-collapsed {
  display: block;
}

/* 控制面板滑鼠懸停檢測區域 */
#control-panel-hover-zone {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 30px;
  z-index: 1001;
  pointer-events: auto;
  background: transparent;
}

.control-panel:not(.collapsed) ~ .control-panel-toggle-collapsed,
body:has(.control-panel:not(.collapsed)) .control-panel-toggle-collapsed {
  display: none;
}

.control-panel-header {
  padding: 12px 15px;
  padding-top: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  -webkit-user-select: none;
  user-select: none;
  border-bottom: 1px solid var(--border-color);
  position: relative;
  flex-shrink: 0;
  transition: border-color 0.3s ease;
}

.control-panel-title {
  cursor: pointer;
  flex: 1;
  font-weight: bold;
  color: var(--text-accent);
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  transition: color 0.3s ease;
}

.control-panel-title:hover {
  opacity: 0.8;
}

.control-panel-toggle {
  color: var(--text-secondary);
  font-size: 18px;
  transition: transform 0.3s ease, color 0.3s ease, background-color 0.3s ease;
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1001;
  cursor: pointer;
  background: var(--bg-panel-hover);
  border-radius: 4px;
  padding: 4px 8px;
  line-height: 1;
}

.control-panel.collapsed .control-panel-toggle {
  transform: rotate(180deg);
}

/* 主題切換 Switch 樣式 */
.theme-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 26px;
  cursor: pointer;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color-hover);
  transition: 0.3s;
  border-radius: 26px;
}

.theme-switch-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-primary);
  transition: 0.3s;
  border-radius: 50%;
}

.theme-switch input:checked + .theme-switch-slider {
  background-color: var(--text-accent);
  border-color: var(--text-accent);
}

.theme-switch input:checked + .theme-switch-slider:before {
  transform: translateX(24px);
  background-color: #fff;
}

.theme-switch:hover .theme-switch-slider {
  border-color: var(--border-color-active);
}

.control-panel-content {
  padding: 15px;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.control-section {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid var(--border-color);
  transition: border-color 0.3s ease;
}

.control-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.control-section button {
  white-space: nowrap;
  flex-shrink: 0;
  word-break: keep-all;
}

.section-title {
  font-size: 12px;
  font-weight: bold;
  color: var(--text-accent);
  margin-bottom: 10px;
  transition: color 0.3s ease;
}

/* 意見回饋按鈕樣式 */
.control-section a[href*="forms.gle"],
.control-section a[onclick*="showVersionHistory"] {
  padding: 6px 12px;
  font-size: 12px;
  background: #9147ff;
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  display: inline-block;
  transition: background 0.2s;
  border: none;
  cursor: pointer;
}

.control-section a[href*="forms.gle"]:hover,
.control-section a[onclick*="showVersionHistory"]:hover {
  background: #7c3aed;
}

.control-section a[href*="forms.gle"]:active {
  background: #6d28d9;
}

.master-volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: rgba(145, 71, 255, 0.1);
  border-radius: 4px;
}

/* 收藏串流管理界面 */
.favorite-streams-manager {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  max-width: 90vw;
  max-height: 80vh;
  background: var(--bg-panel);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  z-index: 10000;
  display: none;
  flex-direction: column;
  box-shadow: 0 8px 32px var(--shadow-color);
  pointer-events: auto;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* 移動設備上的收藏管理界面優化 */
@media (max-width: 768px) {
  .favorite-streams-manager {
    width: 95vw;
    max-width: 95vw;
    max-height: 90vh;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  
  .favorite-manager-header {
    padding: 15px;
  }
  
  .favorite-manager-header h3 {
    font-size: 18px;
  }
  
  .close-btn {
    font-size: 28px;
    width: 44px;
    height: 44px;
    line-height: 44px;
  }
  
  .favorite-manager-content {
    padding: 15px;
    font-size: 14px;
  }
  
  .favorite-tabs {
    gap: 8px;
  }
  
  .tab-btn {
    font-size: 13px;
    padding: 10px 16px;
    min-height: 44px;
  }
  
  .favorite-add-section input,
  .favorite-add-section select {
    font-size: 16px;
    padding: 12px;
    min-height: 44px;
  }
  
  .favorite-add-section button {
    font-size: 14px;
    padding: 12px 20px;
    min-height: 44px;
  }
  
  .favorite-item,
  .category-item {
    padding: 12px;
    font-size: 14px;
  }
  
  .favorite-item button,
  .category-item button {
    font-size: 12px;
    padding: 8px 12px;
    min-height: 36px;
    min-width: 36px;
  }
}

.favorite-streams-manager.show {
  display: flex;
}

/* 背景遮罩 */
.favorite-streams-manager::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: -1;
  pointer-events: auto;
}

.favorite-manager-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  border-radius: 8px 8px 0 0;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.favorite-manager-header h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 16px;
  transition: color 0.3s ease;
}

.favorite-manager-header .close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s, background-color 0.3s ease, color 0.3s ease;
}

.favorite-manager-header .close-btn:hover {
  background: var(--bg-button-hover);
  color: var(--text-primary);
}

.favorite-manager-content {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  background: var(--bg-secondary);
  transition: background-color 0.3s ease;
}

.favorite-add-section {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.favorite-add-section input {
  background: var(--bg-input);
  border: 1px solid var(--border-color-hover);
  color: var(--text-primary);
  border-radius: 4px;
  font-size: 12px;
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.favorite-add-section input:focus {
  outline: none;
  border-color: var(--border-color-active);
}

.favorite-add-section button {
  background: var(--bg-button-active);
  color: var(--text-primary);
  border: none;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
  transition: background-color 0.2s, background-color 0.3s ease;
}

.favorite-add-section button:hover {
  background: #7c3aed;
}

.favorite-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.favorite-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color-hover);
  border-radius: 6px;
  transition: all 0.2s, background-color 0.3s ease, border-color 0.3s ease;
}

.favorite-item:hover {
  background: var(--bg-button-hover);
  border-color: var(--border-color-hover);
}

.favorite-item-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.favorite-platform-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.favorite-item-name {
  color: var(--text-primary);
  font-weight: bold;
  font-size: 13px;
  flex-shrink: 0;
  min-width: 100px;
  transition: color 0.3s ease;
}

.favorite-item-url {
  color: var(--text-secondary);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  transition: color 0.3s ease;
}

.favorite-item-edit {
  display: none;
  flex: 1;
  align-items: center;
  gap: 8px;
  margin-right: 10px;
}

.favorite-item-edit input[type="text"] {
  flex: 1;
  min-width: 150px;
  background: var(--bg-input);
  border: 1px solid var(--border-color-hover);
  color: var(--text-primary);
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.favorite-item-edit select {
  min-width: 120px;
  background: var(--bg-input);
  border: 1px solid var(--border-color-hover);
  color: var(--text-primary);
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.favorite-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.favorite-item-actions button {
  background: var(--bg-button);
  color: var(--text-primary);
  border: none;
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s, background-color 0.3s ease, color 0.3s ease;
  min-width: 32px;
}

.favorite-item-actions button:hover {
  background: var(--bg-button-hover);
}

.favorite-item-actions button:first-child:hover {
  background: var(--bg-button-active);
}

.favorite-item-actions button:last-child:hover {
  background: #ff4444;
}

/* 收藏管理標籤頁 */
.favorite-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 15px;
  border-bottom: 1px solid var(--border-color);
  transition: border-color 0.3s ease;
}

.tab-btn {
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s, color 0.3s ease, border-color 0.3s ease;
  position: relative;
  z-index: 1;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(145, 71, 255, 0.1);
}

.tab-btn.active {
  color: var(--text-accent);
  border-bottom-color: var(--border-color-active);
  background: rgba(145, 71, 255, 0.15);
  font-weight: 600;
  z-index: 2;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* 收藏控制區域 */
.favorite-controls {
  margin-bottom: 15px;
}

.favorite-filter-section {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.favorite-filter-section select {
  background: var(--bg-input);
  border: 1px solid var(--border-color-hover);
  color: var(--text-primary);
  border-radius: 4px;
  font-size: 12px;
  padding: 6px;
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.favorite-filter-section select:focus {
  outline: none;
  border-color: var(--border-color-active);
}

.favorite-item-checkbox {
  margin-right: 10px;
  flex-shrink: 0;
}

.favorite-item-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.favorite-item-category {
  color: var(--text-secondary);
  font-size: 11px;
  transition: color 0.3s ease;
  flex-shrink: 0;
  margin-left: 8px;
}

/* 分類管理 */
.category-add-section {
  display: flex;
  gap: 8px;
  margin-bottom: 15px;
}

.category-add-section input {
  flex: 1;
  padding: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-color-hover);
  color: var(--text-primary);
  border-radius: 4px;
  font-size: 12px;
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.category-add-section input:focus {
  outline: none;
  border-color: var(--border-color-active);
}

.category-add-section button {
  padding: 6px 12px;
  background: var(--bg-button-active);
  color: var(--text-primary);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.2s, background-color 0.3s ease, color 0.3s ease;
}

.category-add-section button:hover {
  background: #7c3aed;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.category-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color-hover);
  border-radius: 6px;
  transition: all 0.2s, background-color 0.3s ease, border-color 0.3s ease;
}

.category-item:hover {
  background: var(--bg-button-hover);
  border-color: var(--border-color-hover);
}

.category-item-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.category-item-name {
  color: var(--text-primary);
  font-weight: bold;
  font-size: 14px;
  transition: color 0.3s ease;
}

.category-item-count {
  color: var(--text-secondary);
  font-size: 12px;
  transition: color 0.3s ease;
}

.category-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.category-item-actions button {
  background: var(--bg-button);
  color: var(--text-primary);
  border: none;
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s, background-color 0.3s ease, color 0.3s ease;
  min-width: 60px;
}

.category-item-actions button:hover {
  background: var(--bg-button-hover);
}

.category-item-actions .load-category-btn:hover {
  background: #9147ff;
}

.category-item-actions .edit-category-btn:hover {
  background: #ffa500;
}

.category-item-actions .remove-category-btn:hover {
  background: #ff4444;
}

.master-volume-control input[type="range"] {
  height: 6px;
  cursor: pointer;
}

.stream-order-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--bg-input);
  border-radius: 4px;
  margin-bottom: 8px;
  transition: background 0.2s, background-color 0.3s ease;
}

.stream-order-item:hover {
  background: var(--bg-button-hover);
}

.stream-order-item.dragging {
  opacity: 0.5;
}

.stream-order-header {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: move;
}

.stream-order-volume {
  cursor: default;
  pointer-events: auto;
}

.stream-order-volume * {
  pointer-events: auto;
}

.stream-order-handle {
  cursor: move;
  color: var(--text-accent);
  font-size: 14px;
  transition: color 0.3s ease;
}

.stream-order-label {
  flex: 1;
  font-size: 16px;
  color: var(--text-primary);
  transition: color 0.3s ease;
}

.stream-order-buttons {
  display: flex;
  gap: 4px;
}

.stream-order-buttons button {
  padding: 4px 8px;
  font-size: 16px;
  min-width: 30px;
}

.stream-order-volume {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}

.stream-order-volume label {
  font-size: 16px;
  color: var(--text-secondary);
  min-width: 50px;
  transition: color 0.3s ease;
}

.stream-order-volume input[type="range"] {
  flex: 1;
  height: 4px;
  cursor: pointer;
}

.stream-order-volume-value {
  min-width: 35px;
  text-align: right;
  font-size: 16px;
  color: var(--text-secondary);
  transition: color 0.3s ease;
}

#add-panel { 
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 15px;
  width: 100%;
  box-sizing: border-box;
}

#url-input {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-color-hover);
  color: var(--text-primary);
  border-radius: 4px;
  font-size: 14px;
  box-sizing: border-box;
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

#add-panel button {
  flex-shrink: 0;
  white-space: nowrap;
}

#url-input:focus {
  outline: none;
  border-color: var(--border-color-active);
}

#presets { 
  display: flex; 
  gap: 8px; 
  flex-wrap: wrap;
}

button { 
  padding: 8px 14px; 
  background: var(--bg-button); 
  color: var(--text-primary); 
  border: 1px solid var(--border-color-hover); 
  border-radius: 4px; 
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s, background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

button:hover { 
  background: var(--bg-button-hover); 
  border-color: var(--border-color-active);
}

button.active {
  background: var(--bg-button-active);
  border-color: var(--border-color-active);
}

.resizer {
  position: absolute;
  width: 20px;
  height: 20px;
  background: var(--border-color-hover);
  right: 0;
  bottom: 0;
  cursor: se-resize;
  border-radius: 4px 0 8px 0;
  transition: background-color 0.3s ease;
}

.resizer:hover {
  background: var(--border-color-active);
}

.layout-selector {
  position: fixed;
  top: 150px;
  left: 10px;
  z-index: 1000;
  background: var(--bg-panel);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  display: none;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.layout-selector.show {
  display: block;
}

.layout-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.layout-preview {
  width: 60px;
  height: 40px;
  border: 2px solid var(--border-color-hover);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  transition: all 0.2s, border-color 0.3s ease;
}

.layout-preview:hover {
  border-color: var(--border-color-active);
}

.layout-preview.active {
  border-color: var(--border-color-active);
  background: rgba(145, 71, 255, 0.2);
}

.layout-preview div {
  background: #9147ff;
  border: 1px solid #000;
}

/* 控制面板内的布局预览 */
.layout-grid-inline {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.layout-preview-inline {
  width: 100%;
  height: 45px;
  min-height: 45px;
  border: 2px solid #444;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  transition: all 0.2s;
  background: #1a1a1a;
}

.layout-preview-inline:hover {
  border-color: #9147ff;
  background: rgba(145, 71, 255, 0.1);
}

.layout-preview-inline.active {
  border-color: #9147ff;
  background: rgba(145, 71, 255, 0.2);
}

.layout-preview-inline {
  position: relative;
}

.layout-preview-inline div {
  background: #9147ff;
  border: 1px solid rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
  pointer-events: none; /* 防止子元素阻止點擊事件 */
}

/* 初始發布商內容樣式 */
.initial-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 800px;
  padding: 40px;
  background: var(--bg-panel);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  text-align: center;
  z-index: 100;
  transition: opacity 0.3s ease, visibility 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
}

.initial-content-language-selector {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.initial-content-language-selector label {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: color 0.3s ease;
}

.initial-content-language-selector select {
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-color-hover);
  color: var(--text-primary);
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s, background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.initial-content-language-selector select:hover {
  border-color: var(--border-color-active);
  background: var(--bg-button-hover);
}

.initial-content-language-selector select:focus {
  outline: none;
  border-color: var(--border-color-active);
  box-shadow: 0 0 0 2px rgba(145, 71, 255, 0.2);
}

.initial-content.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.initial-content-wrapper {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.initial-content-title {
  font-size: 32px;
  font-weight: bold;
  color: var(--text-accent);
  margin: 0;
  line-height: 1.2;
  transition: color 0.3s ease;
}

.initial-content-description {
  font-size: 18px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.6;
  transition: color 0.3s ease;
}

.initial-content-features {
  text-align: left;
  background: rgba(145, 71, 255, 0.1);
  padding: 20px;
  border-radius: 8px;
  border: 1px solid rgba(145, 71, 255, 0.3);
}

.initial-content-subtitle {
  font-size: 20px;
  font-weight: bold;
  color: var(--text-accent);
  margin: 0 0 16px 0;
  text-align: center;
  transition: color 0.3s ease;
}

.initial-content-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.initial-content-list li {
  font-size: 16px;
  color: var(--text-primary);
  padding-left: 24px;
  position: relative;
  line-height: 1.6;
  transition: color 0.3s ease;
}

.initial-content-list li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--text-accent);
  font-weight: bold;
  font-size: 18px;
  transition: color 0.3s ease;
}

.initial-content-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  align-items: center;
}

.initial-content-button {
  padding: 12px 24px;
  background: var(--bg-button-active);
  color: var(--text-primary);
  border: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s, background-color 0.3s ease, color 0.3s ease;
}

.initial-content-button:hover {
  background: #7c3aed;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(145, 71, 255, 0.4);
}

.initial-content-link {
  color: var(--text-accent);
  text-decoration: none;
  font-size: 16px;
  padding: 8px 16px;
  border: 1px solid var(--border-color-active);
  border-radius: 6px;
  transition: all 0.2s, color 0.3s ease, border-color 0.3s ease, background-color 0.3s ease;
}

.initial-content-link:hover {
  background: rgba(145, 71, 255, 0.1);
  border-color: #7c3aed;
}

.initial-content-note {
  font-size: 14px;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 8px;
  line-height: 1.5;
  transition: color 0.3s ease;
}

/* 當有串流時隱藏初始內容 */
#container:has(.stream-box) .initial-content {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* 響應式優化 */
@media (max-width: 768px) {
  .initial-content {
    width: 95%;
    padding: 24px;
  }
  
  .initial-content-language-selector {
    top: 10px;
    right: 10px;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
  }
  
  .initial-content-language-selector label {
    font-size: 12px;
  }
  
  .initial-content-language-selector select {
    font-size: 12px;
    padding: 4px 8px;
  }
  
  .initial-content-title {
    font-size: 24px;
    margin-top: 40px;
  }
  
  .initial-content-description {
    font-size: 16px;
  }
  
  .initial-content-subtitle {
    font-size: 18px;
  }
  
  .initial-content-list li {
    font-size: 14px;
  }
  
  .initial-content-button {
    font-size: 14px;
    padding: 10px 20px;
  }
  
  .initial-content-link {
    font-size: 14px;
    padding: 6px 12px;
  }
}

/* 廣告橫幅 */
.ad-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
  border-top: 2px solid #9147ff;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  z-index: 9999;
  transform: translateY(100%);
  transition: transform 0.5s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: 200px;
}

.ad-banner.show {
  transform: translateY(0);
}

/* 當廣告顯示時，調整容器高度 */
body:has(.ad-banner.show) #container,
#container.has-ad {
  padding-bottom: 200px;
  height: calc(100vh - 200px);
}

/* 兼容不支持 :has() 的瀏覽器 */
#container.has-ad {
  padding-bottom: 200px;
  height: calc(100vh - 200px);
}

.ad-content {
  position: relative;
  width: 100%;
  max-width: 1200px;
  padding: 15px 50px 15px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-close-btn {
  position: absolute;
  top: 10px;
  right: 15px;
  width: 30px;
  height: 30px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: #fff;
  font-size: 20px;
  line-height: 28px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  z-index: 10;
}

.ad-close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
  transform: scale(1.1);
}

.ad-body {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-placeholder {
  text-align: center;
  padding: 20px;
  color: #fff;
}

.ad-label {
  display: inline-block;
  background: #9147ff;
  color: #fff;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.ad-message {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 8px;
  color: #fff;
}

.ad-note {
  font-size: 11px;
  color: #888;
  font-style: italic;
}

/* 響應式設計 - 平板和手機優化 */

/* 平板設備 (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
  .control-panel {
    width: 450px;
  }
  
  body:has(.control-panel:not(.collapsed)) #container {
    padding-right: 450px;
  }
  
  .stream-box {
    min-width: 250px;
    min-height: 180px;
  }
}

/* 手機設備 (最大 768px) */
@media (max-width: 768px) {
  /* 控制面板在手機上全屏顯示 */
  .control-panel {
    width: 100vw;
    left: 0;
    right: 0;
    z-index: 2000;
  }
  
  body:has(.control-panel:not(.collapsed)) #container {
    padding-right: 0;
    padding-bottom: 0;
  }
  
  /* 聊天室容器在手機上優化 */
  .chat-container {
    min-width: max(100%, var(--chat-min-width, 300px)); /* 手機上使用全寬，但不小於最小寬度 */
  }
  
  .content-wrapper.layout-horizontal .chat-container {
    width: 100%;
    min-width: max(100%, var(--chat-min-width, 300px)); /* 確保不小於最小寬度 */
  }
  
  .content-wrapper.layout-vertical .chat-container {
    width: 100%;
    min-width: max(100%, var(--chat-min-width, 300px)); /* 確保不小於最小寬度 */
  }
  
  .chat-container iframe {
    min-width: max(100%, var(--chat-min-width, 300px)); /* 手機上使用全寬，但不小於最小寬度 */
  }
  
  /* 控制面板標題調整 */
  .control-panel-header {
    padding: 15px;
    padding-top: 50px;
  }
  
  .control-panel-title {
    font-size: 16px;
  }
  
  .control-panel-toggle {
    font-size: 20px;
    padding: 8px 12px;
    top: 15px;
    right: 15px;
  }
  
  /* 控制面板內容調整 */
  .control-panel-content {
    padding: 15px;
  }
  
  /* 輸入框和按鈕優化（觸摸友好） */
  #add-panel input {
    font-size: 16px; /* 防止 iOS 自動縮放 */
    padding: 12px;
    min-height: 44px; /* 觸摸目標最小尺寸 */
  }
  
  #add-panel button {
    font-size: 16px;
    padding: 12px 20px;
    min-height: 44px;
  }
  
  /* 所有按鈕優化 */
  .control-section button {
    font-size: 14px;
    padding: 10px 16px;
    min-height: 44px;
    min-width: 44px;
  }
  
  /* 布局預覽按鈕調整 */
  .layout-grid-inline {
    gap: 8px;
  }
  
  .layout-preview-inline {
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
  }
  
  /* 串流視窗最小尺寸調整 */
  .stream-box {
    min-width: 200px;
    min-height: 150px;
  }
  
  /* 音量控制滑桿優化 */
  .volume,
  #master-volume {
    min-height: 44px;
    padding: 10px 0;
  }
  
  /* 收藏列表和串流順序列表調整 */
  #favorite-list-display,
  #stream-order-list {
    max-height: 200px;
  }
  
  /* 選擇框優化 */
  select {
    font-size: 16px; /* 防止 iOS 自動縮放 */
    padding: 12px;
    min-height: 44px;
  }
  
  /* 收起按鈕調整 */
  .control-panel-toggle-collapsed {
    width: 50px;
    padding: 15px 10px;
    font-size: 20px;
    right: 0;
  }
  
  /* 滑鼠懸停檢測區域在移動設備上禁用 */
  #control-panel-hover-zone {
    display: none;
  }
  
  /* 廣告優化 */
  .ad-content {
    padding: 12px 40px 12px 15px;
    max-width: 95vw;
  }
  
  .ad-message {
    font-size: 14px;
  }
  
  .ad-note {
    font-size: 10px;
  }
  
  .ad-close-btn {
    font-size: 24px;
    width: 44px;
    height: 44px;
    line-height: 44px;
  }
  
  /* 串流視窗控制按鈕優化 */
  .controls {
    height: 50px;
    padding: 0 10px;
    gap: 8px;
  }
  
  .control-btn {
    padding: 8px 12px;
    font-size: 12px;
    min-height: 36px;
  }
  
  .close {
    font-size: 20px;
    padding: 0 12px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* 標題字體調整 */
  .section-title {
    font-size: 14px;
    margin-bottom: 12px;
  }
  
  /* 意見回饋和版本紀錄按鈕 */
  .control-section a[href*="forms.gle"],
  .control-section a[onclick*="showVersionHistory"] {
    font-size: 14px;
    padding: 10px 16px;
    min-height: 44px;
  }
}

/* 小屏幕手機 (最大 480px) */
@media (max-width: 480px) {
  .control-panel-header {
    padding: 12px;
    padding-top: 45px;
  }
  
  .control-panel-content {
    padding: 12px;
  }
  
  .control-section {
    margin-top: 12px;
    padding-top: 12px;
  }
  
  /* 布局預覽更小 */
  .layout-grid-inline {
    gap: 6px;
  }
  
  .layout-preview-inline {
    width: 45px;
    height: 45px;
    min-width: 45px;
    min-height: 45px;
  }
  
  /* 串流視窗進一步縮小 */
  .stream-box {
    min-width: 180px;
    min-height: 120px;
  }
  
  /* 收藏列表高度調整 */
  #favorite-list-display,
  #stream-order-list {
    max-height: 150px;
  }
  
  /* 按鈕文字可能換行 */
  .control-section button {
    white-space: normal;
    word-break: break-word;
    padding: 8px 12px;
    font-size: 12px;
  }
}

/* 橫向模式優化 */
@media (max-width: 768px) and (orientation: landscape) {
  .control-panel {
    width: 60vw;
    max-width: 400px;
  }
  
  body:has(.control-panel:not(.collapsed)) #container {
    padding-right: 0;
  }
  
  .stream-box {
    min-width: 220px;
    min-height: 140px;
  }
  
  #favorite-list-display,
  #stream-order-list {
    max-height: 120px;
  }
}

/* 觸摸設備優化 */
@media (hover: none) and (pointer: coarse) {
  /* 禁用懸停效果 */
  .control-panel-toggle:hover,
  .control-panel-title:hover,
  .control-panel-toggle-collapsed:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.8);
    padding-right: 8px;
  }
  
  /* 增加觸摸目標 */
  button, a, .control-btn, .close {
    -webkit-tap-highlight-color: rgba(145, 71, 255, 0.3);
    tap-highlight-color: rgba(145, 71, 255, 0.3);
  }
  
  /* 滑鼠懸停檢測區域禁用 */
  #control-panel-hover-zone {
    display: none !important;
  }
  
  /* 防止意外縮放 */
  body {
    touch-action: pan-x pan-y;
  }
  
  /* 優化滾動 */
  .control-panel-content,
  #favorite-list-display,
  #stream-order-list {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  
  /* 防止文本選擇（拖曳時） */
  .stream-box {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
}

/* ============================================
   全面響應式設計優化 - 所有解析度
   ============================================ */

/* 超大屏幕 (2560px 及以上) */
@media (min-width: 2560px) {
  .control-panel {
    width: 650px;
  }
  
  body:has(.control-panel:not(.collapsed)) #container {
    padding-right: 650px;
  }
  
  .control-panel-content {
    padding: 20px;
  }
  
  .section-title {
    font-size: 14px;
  }
  
  button {
    font-size: 14px;
    padding: 10px 16px;
  }
  
  #url-input {
    font-size: 16px;
    padding: 12px;
  }
  
  .stream-box {
    min-width: 350px;
    min-height: 250px;
  }
  
  .favorite-streams-manager {
    width: 800px;
    max-width: 80vw;
  }
  
  .layout-preview-inline {
    height: 50px;
    min-height: 50px;
  }
}

/* 大屏幕 (1920px - 2559px) */
@media (min-width: 1920px) and (max-width: 2559px) {
  .control-panel {
    width: 600px;
  }
  
  body:has(.control-panel:not(.collapsed)) #container {
    padding-right: 600px;
  }
  
  .stream-box {
    min-width: 320px;
    min-height: 220px;
  }
  
  .favorite-streams-manager {
    width: 700px;
    max-width: 85vw;
  }
}

/* 中等屏幕桌面 (1440px - 1919px) - 標準桌面 */
@media (min-width: 1440px) and (max-width: 1919px) {
  .control-panel {
    width: 550px;
  }
  
  body:has(.control-panel:not(.collapsed)) #container {
    padding-right: 550px;
  }
  
  .stream-box {
    min-width: 300px;
    min-height: 200px;
  }
}

/* 小屏幕桌面 (1024px - 1439px) - 筆記本電腦 */
@media (min-width: 1024px) and (max-width: 1439px) {
  .control-panel {
    width: 500px;
  }
  
  body:has(.control-panel:not(.collapsed)) #container {
    padding-right: 500px;
  }
  
  .stream-box {
    min-width: 280px;
    min-height: 180px;
  }
  
  .favorite-streams-manager {
    width: 550px;
    max-width: 90vw;
  }
  
  .layout-preview-inline {
    height: 40px;
    min-height: 40px;
  }
  
  .control-panel-content {
    padding: 12px;
  }
  
  .section-title {
    font-size: 11px;
  }
  
  button {
    font-size: 12px;
    padding: 7px 12px;
  }
}

/* 平板橫向 (1024px - 1366px) */
@media (min-width: 1024px) and (max-width: 1366px) and (orientation: landscape) {
  .control-panel {
    width: 450px;
  }
  
  body:has(.control-panel:not(.collapsed)) #container {
    padding-right: 450px;
  }
  
  .stream-box {
    min-width: 250px;
    min-height: 170px;
  }
  
  .layout-preview-inline {
    height: 38px;
    min-height: 38px;
  }
}

/* 固定布局聊天室面板基礎樣式 */
.chat-sidebar-panel,
.fixed-chat-panel {
  position: relative;
  background: #0a0a0a;
  border: 1px solid #333;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0; /* 允許 flexbox 縮小面板 */
  max-width: 100%; /* 確保不超出父容器 */
  box-sizing: border-box; /* 確保 border 包含在寬度內 */
  flex-shrink: 1; /* 允許縮小 */
}

.chat-sidebar-content,
.chat-content-fixed {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: var(--fixed-chat-min-width, 300px); /* 確保內容區域有足夠寬度，根據縮放動態調整 */
  min-height: var(--chat-min-height, 200px); /* 確保最小高度，根據縮放動態調整 */
}

.chat-sidebar-content iframe,
.chat-content-fixed iframe {
  width: 100%;
  height: 100%;
  border: none;
  min-width: var(--fixed-chat-min-width, 300px); /* YouTube 聊天室 iframe 最小寬度，根據縮放動態調整 */
  min-height: var(--chat-min-height, 200px); /* 確保最小高度，根據縮放動態調整 */
}

#fixed-chat-sidebar,
.chat-sidebar-fixed {
  position: absolute;
  background: #0a0a0a;
  border-left: 2px solid #333;
  display: flex;
  box-sizing: border-box;
  min-width: var(--fixed-chat-min-width, 300px); /* 確保側邊欄有足夠寬度，根據縮放動態調整 */
  height: 100vh; /* 使用視窗高度，確保在高縮放下正確顯示 */
  top: 0; /* 確保從頂部開始 */
  overflow: hidden; /* 防止內容溢出 */
  max-width: 100vw; /* 確保不會超出視窗寬度 */
  /* 注意：left 和 width 由 JavaScript 動態設置，確保右邊界不超出視窗 */
}

/* 固定布局響應式優化 - Layout 13, 14, 15 */
@media (max-width: 1440px) {
  /* 固定聊天側邊欄在小屏幕上調整 */
  #fixed-chat-sidebar,
  .chat-sidebar-fixed {
    max-width: 100%;
  }
  
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: var(--fixed-chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
  }
  
  .chat-sidebar-content iframe,
  .chat-content-fixed iframe,
  .fixed-chat-panel iframe {
    min-width: var(--fixed-chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
  }
}

@media (max-width: 1024px) {
  /* 固定布局在平板上的優化 */
  #fixed-chat-sidebar,
  .chat-sidebar-fixed {
    width: 100% !important;
    max-width: 100% !important;
    min-width: var(--fixed-chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
  }
  
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: var(--fixed-chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
  }
  
  .chat-sidebar-content iframe,
  .chat-content-fixed iframe,
  .fixed-chat-panel iframe {
    min-width: var(--fixed-chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
  }
  
  /* 視頻區域在小屏幕上可能需要調整 */
  #container:has(#fixed-chat-sidebar) {
    flex-direction: column;
  }
}

@media (max-width: 768px) {
  /* 固定布局在手機上改為垂直堆疊 */
  #fixed-chat-sidebar,
  .chat-sidebar-fixed {
    position: relative !important;
    width: 100% !important;
    height: auto !important;
    max-height: 40vh !important;
    flex-direction: row !important;
    overflow-x: auto;
    overflow-y: hidden;
    border-top: 2px solid #9147ff;
    border-left: none;
    border-right: none;
    min-width: 100%; /* 手機上全寬 */
  }
  
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: var(--fixed-chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
    max-width: 80vw;
    height: 100% !important;
    flex-shrink: 0;
  }
  
  .chat-sidebar-content iframe,
  .chat-content-fixed iframe,
  .fixed-chat-panel iframe {
    min-width: var(--fixed-chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
  }
  
  /* 視頻區域在手機上佔滿寬度 */
  #container:has(#fixed-chat-sidebar) {
    flex-direction: column;
    padding-bottom: 0;
  }
}

/* 分離聊天室響應式優化 */
@media (max-width: 1440px) {
  .separated-chat {
    min-width: var(--separated-chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
    min-height: max(350px, var(--chat-min-height, 200px) * 1.75);
    max-width: 90vw;
    max-height: 85vh;
  }
  
  .separated-chat-content iframe {
    min-width: var(--separated-chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
  }
}

@media (max-width: 1024px) {
  .separated-chat {
    min-width: var(--separated-chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
    min-height: max(300px, var(--chat-min-height, 200px) * 1.5);
    max-width: 95vw;
    max-height: 80vh;
  }
  
  .separated-chat-content iframe {
    min-width: var(--separated-chat-min-width, 300px); /* 使用 CSS 變數，根據縮放動態調整 */
  }
  
  .separated-chat-header {
    height: 40px;
    font-size: 13px;
    padding: 0 12px;
  }
}

@media (max-width: 768px) {
  .separated-chat {
    min-width: 90vw;
    min-height: 50vh;
    max-width: 95vw;
    max-height: 70vh;
  }
  
  .separated-chat-content iframe {
    min-width: max(90vw, var(--separated-chat-min-width, 300px)); /* 手機上使用視窗寬度，但不小於最小寬度 */
  }
  
  .separated-chat-header {
    height: 44px;
    font-size: 14px;
    padding: 0 15px;
  }
  
  .separated-chat-header .close {
    font-size: 24px;
    min-width: 44px;
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  .separated-chat {
    min-width: 95vw;
    min-height: 45vh;
    max-width: 98vw;
    max-height: 65vh;
  }
}

/* 模態框（版本歷史、使用教學）響應式優化 */
@media (min-width: 1920px) {
  .favorite-streams-manager {
    width: 750px;
    max-width: 75vw;
  }
  
  .favorite-manager-content {
    font-size: 15px;
  }
  
  .favorite-manager-header h3 {
    font-size: 20px;
  }
}

@media (min-width: 1440px) and (max-width: 1919px) {
  .favorite-streams-manager {
    width: 650px;
    max-width: 80vw;
  }
}

@media (min-width: 1024px) and (max-width: 1439px) {
  .favorite-streams-manager {
    width: 550px;
    max-width: 85vw;
  }
  
  .favorite-manager-content {
    font-size: 13px;
    padding: 18px;
  }
  
  .favorite-manager-header h3 {
    font-size: 17px;
  }
}

@media (max-width: 768px) {
  .favorite-streams-manager {
    width: 95vw;
    max-width: 95vw;
    max-height: 90vh;
  }
  
  .favorite-manager-content {
    padding: 15px;
    font-size: 14px;
    max-height: calc(90vh - 60px);
  }
  
  .favorite-manager-header {
    padding: 12px 15px;
  }
  
  .favorite-manager-header h3 {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .favorite-streams-manager {
    width: 98vw;
    max-width: 98vw;
    max-height: 95vh;
  }
  
  .favorite-manager-content {
    padding: 12px;
    font-size: 13px;
    max-height: calc(95vh - 55px);
  }
  
  .favorite-manager-header {
    padding: 10px 12px;
  }
  
  .favorite-manager-header h3 {
    font-size: 15px;
  }
}

/* 布局預覽按鈕響應式優化 */
@media (min-width: 1920px) {
  .layout-grid-inline {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
  }
  
  .layout-preview-inline {
    height: 55px;
    min-height: 55px;
  }
}

@media (min-width: 1440px) and (max-width: 1919px) {
  .layout-grid-inline {
    grid-template-columns: repeat(3, 1fr);
    gap: 9px;
  }
  
  .layout-preview-inline {
    height: 48px;
    min-height: 48px;
  }
}

@media (min-width: 1024px) and (max-width: 1439px) {
  .layout-grid-inline {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  
  .layout-preview-inline {
    height: 42px;
    min-height: 42px;
  }
}

@media (max-width: 768px) {
  .layout-grid-inline {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }
  
  .layout-preview-inline {
    height: 50px;
    min-height: 50px;
  }
}

@media (max-width: 480px) {
  .layout-grid-inline {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  
  .layout-preview-inline {
    height: 45px;
    min-height: 45px;
  }
}

/* 串流順序列表響應式優化 */
@media (min-width: 1920px) {
  #stream-order-list {
    max-height: 400px;
  }
  
  .stream-order-item {
    padding: 12px;
  }
  
  .stream-order-label {
    font-size: 13px;
  }
}

@media (min-width: 1440px) and (max-width: 1919px) {
  #stream-order-list {
    max-height: 350px;
  }
}

@media (min-width: 1024px) and (max-width: 1439px) {
  #stream-order-list {
    max-height: 280px;
  }
  
  .stream-order-item {
    padding: 9px;
  }
  
  .stream-order-label {
    font-size: 11px;
  }
}

/* 收藏列表響應式優化 */
@media (min-width: 1920px) {
  #favorite-list-display {
    max-height: 400px;
  }
}

@media (min-width: 1440px) and (max-width: 1919px) {
  #favorite-list-display {
    max-height: 350px;
  }
}

@media (min-width: 1024px) and (max-width: 1439px) {
  #favorite-list-display {
    max-height: 280px;
  }
}

/* 廣告橫幅響應式優化 */
@media (min-width: 1920px) {
  .ad-banner {
    max-height: 250px;
  }
  
  body:has(.ad-banner.show) #container,
  #container.has-ad {
    padding-bottom: 250px;
    height: calc(100vh - 250px);
  }
  
  .ad-content {
    max-width: 1400px;
    padding: 20px 60px 20px 25px;
  }
  
  .ad-message {
    font-size: 18px;
  }
}

@media (min-width: 1440px) and (max-width: 1919px) {
  .ad-banner {
    max-height: 220px;
  }
  
  body:has(.ad-banner.show) #container,
  #container.has-ad {
    padding-bottom: 220px;
    height: calc(100vh - 220px);
  }
  
  .ad-content {
    max-width: 1200px;
  }
}

@media (min-width: 1024px) and (max-width: 1439px) {
  .ad-banner {
    max-height: 180px;
  }
  
  body:has(.ad-banner.show) #container,
  #container.has-ad {
    padding-bottom: 180px;
    height: calc(100vh - 180px);
  }
  
  .ad-content {
    max-width: 1000px;
    padding: 15px 50px 15px 20px;
  }
  
  .ad-message {
    font-size: 15px;
  }
}

@media (max-width: 768px) {
  .ad-banner {
    max-height: 150px;
  }
  
  body:has(.ad-banner.show) #container,
  #container.has-ad {
    padding-bottom: 150px;
    height: calc(100vh - 150px);
  }
  
  .ad-content {
    padding: 10px 35px 10px 12px;
  }
  
  .ad-message {
    font-size: 13px;
  }
  
  .ad-close-btn {
    width: 40px;
    height: 40px;
    font-size: 22px;
    line-height: 40px;
  }
}

@media (max-width: 480px) {
  .ad-banner {
    max-height: 120px;
  }
  
  body:has(.ad-banner.show) #container,
  #container.has-ad {
    padding-bottom: 120px;
    height: calc(100vh - 120px);
  }
  
  .ad-message {
    font-size: 12px;
  }
  
  .ad-note {
    font-size: 9px;
  }
}

/* 控制面板內容區域響應式優化 */
@media (min-width: 1920px) {
  .control-panel-content {
    padding: 20px;
  }
  
  .control-section {
    margin-top: 20px;
    padding-top: 20px;
  }
  
  .section-title {
    font-size: 14px;
    margin-bottom: 12px;
  }
}

@media (min-width: 1440px) and (max-width: 1919px) {
  .control-panel-content {
    padding: 18px;
  }
  
  .control-section {
    margin-top: 18px;
    padding-top: 18px;
  }
}

@media (min-width: 1024px) and (max-width: 1439px) {
  .control-panel-content {
    padding: 12px;
  }
  
  .control-section {
    margin-top: 12px;
    padding-top: 12px;
  }
  
  .section-title {
    font-size: 11px;
    margin-bottom: 8px;
  }
}

/* 輸入框和按鈕響應式優化 */
@media (min-width: 1920px) {
  #url-input {
    font-size: 16px;
    padding: 12px;
  }
  
  #add-panel button {
    font-size: 15px;
    padding: 12px 24px;
  }
  
  .control-section button {
    font-size: 14px;
    padding: 10px 16px;
  }
}

@media (min-width: 1440px) and (max-width: 1919px) {
  #url-input {
    font-size: 15px;
    padding: 11px;
  }
  
  #add-panel button {
    font-size: 14px;
    padding: 11px 22px;
  }
}

@media (min-width: 1024px) and (max-width: 1439px) {
  #url-input {
    font-size: 14px;
    padding: 10px;
  }
  
  #add-panel button {
    font-size: 13px;
    padding: 10px 18px;
  }
  
  .control-section button {
    font-size: 12px;
    padding: 7px 12px;
  }
}

/* 音量控制響應式優化 */
@media (min-width: 1920px) {
  .master-volume-control {
    padding: 10px;
  }
  
  .master-volume-control label {
    font-size: 13px;
  }
  
  #master-volume {
    height: 8px;
  }
  
  #master-volume-value {
    font-size: 13px;
    min-width: 45px;
  }
}

@media (min-width: 1024px) and (max-width: 1439px) {
  .master-volume-control {
    padding: 7px;
  }
  
  .master-volume-control label {
    font-size: 11px;
  }
  
  #master-volume-value {
    font-size: 11px;
    min-width: 35px;
  }
}

/* 高 DPI 屏幕優化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .stream-box {
    border-width: 1.5px;
  }
  
  .control-panel {
    border-left-width: 1.5px;
  }
  
  .separated-chat {
    border-width: 1.5px;
  }
  
  .favorite-streams-manager {
    border-width: 1.5px;
  }
}

/* 超寬屏優化 (21:9 等) */
@media (min-width: 2560px) and (min-aspect-ratio: 21/9) {
  .control-panel {
    width: 700px;
  }
  
  body:has(.control-panel:not(.collapsed)) #container {
    padding-right: 700px;
  }
  
  .stream-box {
    min-width: 400px;
    min-height: 280px;
  }
}

/* ============================================
   超小解析度優化 (360px 及以下)
   ============================================ */

/* 小手機 (360px - 480px) */
@media (max-width: 480px) and (min-width: 361px) {
  .control-panel-header {
    padding: 10px;
    padding-top: 40px;
  }
  
  .control-panel-content {
    padding: 10px;
  }
  
  .control-section {
    margin-top: 10px;
    padding-top: 10px;
  }
  
  .control-panel-title {
    font-size: 15px;
  }
  
  .control-panel-toggle {
    font-size: 18px;
    padding: 6px 10px;
    top: 12px;
    right: 12px;
  }
  
  #add-panel {
    flex-direction: column;
    gap: 8px;
  }
  
  #add-panel input {
    width: 100%;
    font-size: 16px;
    padding: 10px;
    min-height: 44px;
  }
  
  #add-panel button {
    width: 100%;
    font-size: 15px;
    padding: 12px;
    min-height: 44px;
  }
  
  .layout-grid-inline {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  
  .layout-preview-inline {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
  }
  
  .stream-box {
    min-width: 160px;
    min-height: 100px;
  }
  
  .section-title {
    font-size: 13px;
    margin-bottom: 10px;
  }
  
  .control-section button {
    font-size: 12px;
    padding: 8px 10px;
    min-height: 40px;
    min-width: 40px;
  }
  
  #favorite-list-display,
  #stream-order-list {
    max-height: 140px;
  }
  
  .master-volume-control {
    flex-direction: column;
    gap: 6px;
    padding: 8px;
  }
  
  .master-volume-control label {
    font-size: 12px;
  }
  
  #master-volume {
    width: 100%;
  }
  
  .favorite-streams-manager {
    width: 98vw;
    max-width: 98vw;
    max-height: 92vh;
  }
  
  .favorite-manager-content {
    padding: 10px;
    font-size: 13px;
    max-height: calc(92vh - 50px);
  }
  
  .favorite-manager-header {
    padding: 10px 12px;
  }
  
  .favorite-manager-header h3 {
    font-size: 15px;
  }
  
  .close-btn {
    font-size: 26px;
    width: 40px;
    height: 40px;
    line-height: 40px;
  }
  
  .favorite-tabs {
    gap: 6px;
    flex-wrap: wrap;
  }
  
  .tab-btn {
    font-size: 12px;
    padding: 8px 12px;
    min-height: 40px;
    flex: 1;
    min-width: 0;
  }
  
  .favorite-add-section {
    flex-direction: column;
    gap: 8px;
  }
  
  .favorite-add-section input,
  .favorite-add-section select {
    width: 100%;
    font-size: 16px;
    padding: 10px;
    min-height: 44px;
  }
  
  .favorite-add-section button {
    width: 100%;
    font-size: 14px;
    padding: 12px;
    min-height: 44px;
  }
  
  .favorite-item,
  .category-item {
    padding: 10px;
    font-size: 13px;
    flex-wrap: wrap;
  }
  
  .favorite-item-info {
    width: 100%;
    margin-bottom: 8px;
  }
  
  .favorite-item-actions {
    width: 100%;
    justify-content: flex-end;
  }
  
  .favorite-item button,
  .category-item button {
    font-size: 11px;
    padding: 6px 10px;
    min-height: 36px;
    min-width: 36px;
  }
  
  .separated-chat {
    min-width: 98vw;
    min-height: 40vh;
    max-width: 98vw;
    max-height: 60vh;
  }
  
  .separated-chat-header {
    height: 40px;
    font-size: 13px;
    padding: 0 10px;
  }
  
  .controls {
    height: 48px;
    padding: 0 8px;
    gap: 6px;
    flex-wrap: wrap;
  }
  
  .control-btn {
    padding: 6px 10px;
    font-size: 11px;
    min-height: 32px;
  }
  
  .close {
    font-size: 18px;
    padding: 0 10px;
    min-width: 40px;
    min-height: 40px;
  }
  
  .ad-content {
    padding: 8px 30px 8px 10px;
  }
  
  .ad-message {
    font-size: 12px;
  }
  
  .ad-note {
    font-size: 9px;
  }
  
  .ad-close-btn {
    width: 36px;
    height: 36px;
    font-size: 20px;
    line-height: 36px;
    top: 8px;
    right: 10px;
  }
  
  .control-panel-toggle-collapsed {
    width: 44px;
    padding: 12px 8px;
    font-size: 18px;
  }
  
  .control-section a[href*="forms.gle"],
  .control-section a[onclick*="showVersionHistory"] {
    font-size: 13px;
    padding: 10px 14px;
    min-height: 40px;
    width: 100%;
    text-align: center;
    margin-bottom: 6px;
  }
}

/* 超小手機 (320px - 360px) */
@media (max-width: 360px) {
  .control-panel-header {
    padding: 8px;
    padding-top: 38px;
  }
  
  .control-panel-content {
    padding: 8px;
  }
  
  .control-section {
    margin-top: 8px;
    padding-top: 8px;
  }
  
  .control-panel-title {
    font-size: 14px;
  }
  
  .control-panel-toggle {
    font-size: 16px;
    padding: 5px 8px;
    top: 10px;
    right: 10px;
  }
  
  #add-panel {
    gap: 6px;
  }
  
  #add-panel input {
    font-size: 16px;
    padding: 8px;
    min-height: 42px;
  }
  
  #add-panel button {
    font-size: 14px;
    padding: 10px;
    min-height: 42px;
  }
  
  .layout-grid-inline {
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
  }
  
  .layout-preview-inline {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
  }
  
  .stream-box {
    min-width: 140px;
    min-height: 90px;
    border-radius: 6px;
  }
  
  .section-title {
    font-size: 12px;
    margin-bottom: 8px;
  }
  
  .control-section button {
    font-size: 11px;
    padding: 6px 8px;
    min-height: 38px;
    min-width: 38px;
  }
  
  #favorite-list-display,
  #stream-order-list {
    max-height: 120px;
  }
  
  .master-volume-control {
    padding: 6px;
    gap: 5px;
  }
  
  .master-volume-control label {
    font-size: 11px;
  }
  
  #master-volume {
    height: 4px;
  }
  
  #master-volume-value {
    font-size: 11px;
    min-width: 30px;
  }
  
  .master-volume-control button {
    font-size: 11px;
    padding: 6px 10px;
    min-height: 38px;
  }
  
  .favorite-streams-manager {
    width: 100vw;
    max-width: 100vw;
    max-height: 95vh;
    border-radius: 0;
  }
  
  .favorite-manager-content {
    padding: 8px;
    font-size: 12px;
    max-height: calc(95vh - 45px);
  }
  
  .favorite-manager-header {
    padding: 8px 10px;
    border-radius: 0;
  }
  
  .favorite-manager-header h3 {
    font-size: 14px;
  }
  
  .close-btn {
    font-size: 24px;
    width: 36px;
    height: 36px;
    line-height: 36px;
  }
  
  .favorite-tabs {
    gap: 4px;
  }
  
  .tab-btn {
    font-size: 11px;
    padding: 6px 10px;
    min-height: 38px;
  }
  
  .favorite-add-section {
    gap: 6px;
  }
  
  .favorite-add-section input,
  .favorite-add-section select {
    font-size: 16px;
    padding: 8px;
    min-height: 42px;
  }
  
  .favorite-add-section button {
    font-size: 13px;
    padding: 10px;
    min-height: 42px;
  }
  
  .favorite-item,
  .category-item {
    padding: 8px;
    font-size: 12px;
  }
  
  .favorite-item-name {
    font-size: 12px;
    min-width: 80px;
  }
  
  .favorite-item-url {
    font-size: 10px;
  }
  
  .favorite-item button,
  .category-item button {
    font-size: 10px;
    padding: 5px 8px;
    min-height: 32px;
    min-width: 32px;
  }
  
  .category-item-name {
    font-size: 13px;
  }
  
  .category-item-count {
    font-size: 11px;
  }
  
  .separated-chat {
    min-width: 100vw;
    min-height: 35vh;
    max-width: 100vw;
    max-height: 55vh;
    border-radius: 0;
  }
  
  .separated-chat-header {
    height: 36px;
    font-size: 12px;
    padding: 0 8px;
  }
  
  .separated-chat-header .close {
    font-size: 20px;
    min-width: 36px;
    min-height: 36px;
  }
  
  .controls {
    height: 44px;
    padding: 0 6px;
    gap: 4px;
  }
  
  .stream-label {
    font-size: 11px;
    min-width: 40px;
  }
  
  .control-btn {
    padding: 5px 8px;
    font-size: 10px;
    min-height: 30px;
  }
  
  .close {
    font-size: 16px;
    padding: 0 8px;
    min-width: 36px;
    min-height: 36px;
  }
  
  .volume-control {
    max-width: 150px;
  }
  
  .volume {
    height: 4px;
  }
  
  .vol-value {
    font-size: 10px;
    min-width: 30px;
  }
  
  .ad-banner {
    max-height: 100px;
  }
  
  body:has(.ad-banner.show) #container,
  #container.has-ad {
    padding-bottom: 100px;
    height: calc(100vh - 100px);
  }
  
  .ad-content {
    padding: 6px 25px 6px 8px;
  }
  
  .ad-label {
    font-size: 9px;
    padding: 3px 8px;
    margin-bottom: 6px;
  }
  
  .ad-message {
    font-size: 11px;
    margin-bottom: 4px;
  }
  
  .ad-note {
    font-size: 8px;
  }
  
  .ad-close-btn {
    width: 32px;
    height: 32px;
    font-size: 18px;
    line-height: 32px;
    top: 6px;
    right: 8px;
  }
  
  .control-panel-toggle-collapsed {
    width: 40px;
    padding: 10px 6px;
    font-size: 16px;
  }
  
  .control-section a[href*="forms.gle"],
  .control-section a[onclick*="showVersionHistory"] {
    font-size: 12px;
    padding: 8px 12px;
    min-height: 38px;
  }
  
  .stream-order-item {
    padding: 6px;
    gap: 6px;
  }
  
  .stream-order-label {
    font-size: 10px;
  }
  
  .stream-order-buttons button {
    padding: 3px 6px;
    font-size: 10px;
    min-width: 28px;
    min-height: 28px;
  }
  
  .stream-order-volume label {
    font-size: 10px;
    min-width: 40px;
  }
  
  .stream-order-volume input[type="range"] {
    height: 3px;
  }
  
  .stream-order-volume-value {
    font-size: 10px;
    min-width: 30px;
  }
}

/* 極小屏幕 (最大 320px) - 非常舊的手機 */
@media (max-width: 320px) {
  .control-panel-header {
    padding: 6px;
    padding-top: 35px;
  }
  
  .control-panel-content {
    padding: 6px;
  }
  
  .control-section {
    margin-top: 6px;
    padding-top: 6px;
  }
  
  .control-panel-title {
    font-size: 13px;
  }
  
  .control-panel-toggle {
    font-size: 14px;
    padding: 4px 6px;
    top: 8px;
    right: 8px;
  }
  
  #add-panel input {
    padding: 6px;
    min-height: 40px;
  }
  
  #add-panel button {
    padding: 8px;
    min-height: 40px;
  }
  
  .layout-preview-inline {
    width: 35px;
    height: 35px;
    min-width: 35px;
    min-height: 35px;
  }
  
  .stream-box {
    min-width: 120px;
    min-height: 80px;
  }
  
  .section-title {
    font-size: 11px;
  }
  
  .control-section button {
    font-size: 10px;
    padding: 5px 6px;
    min-height: 36px;
    min-width: 36px;
  }
  
  #favorite-list-display,
  #stream-order-list {
    max-height: 100px;
  }
  
  .favorite-manager-content {
    padding: 6px;
    font-size: 11px;
  }
  
  .favorite-manager-header {
    padding: 6px 8px;
  }
  
  .favorite-manager-header h3 {
    font-size: 13px;
  }
  
  .close-btn {
    font-size: 22px;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
  
  .tab-btn {
    font-size: 10px;
    padding: 5px 8px;
    min-height: 36px;
  }
  
  .favorite-item,
  .category-item {
    padding: 6px;
    font-size: 11px;
  }
  
  .separated-chat {
    min-height: 30vh;
    max-height: 50vh;
  }
  
  .separated-chat-header {
    height: 32px;
    font-size: 11px;
  }
  
  .controls {
    height: 40px;
    padding: 0 4px;
  }
  
  .control-btn {
    padding: 4px 6px;
    font-size: 9px;
    min-height: 28px;
  }
  
  .ad-content {
    padding: 4px 20px 4px 6px;
  }
  
  .ad-message {
    font-size: 10px;
  }
  
  .ad-note {
    font-size: 7px;
  }
  
  .ad-close-btn {
    width: 28px;
    height: 28px;
    font-size: 16px;
    line-height: 28px;
  }
}

/* 橫向模式 - 小屏幕優化 */
@media (max-width: 480px) and (orientation: landscape) {
  .control-panel {
    width: 70vw;
    max-width: 350px;
  }
  
  .control-panel-header {
    padding-top: 35px;
  }
  
  .stream-box {
    min-width: 180px;
    min-height: 100px;
  }
  
  #favorite-list-display,
  #stream-order-list {
    max-height: 100px;
  }
  
  .favorite-streams-manager {
    max-height: 85vh;
  }
  
  .favorite-manager-content {
    max-height: calc(85vh - 45px);
  }
  
  .separated-chat {
    min-height: 50vh;
    max-height: 70vh;
  }
}

@media (max-width: 360px) and (orientation: landscape) {
  .control-panel {
    width: 75vw;
    max-width: 320px;
  }
  
  .stream-box {
    min-width: 150px;
    min-height: 80px;
  }
  
  #favorite-list-display,
  #stream-order-list {
    max-height: 80px;
  }
  
  .separated-chat {
    min-height: 45vh;
    max-height: 65vh;
  }
}

/* ============================================
   縮放優化 - 作業系統和瀏覽器縮放
   ============================================ */

/* 高 DPI 屏幕（系統縮放 125%, 150%, 175%, 200% 等） */
/* 注意：這些是備用值，JavaScript 會動態覆蓋這些值 */

@media (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi) {
  :root {
    --chat-min-width: 394px; /* 300px * 1.25 * 1.05 (增加緩衝) */
    --chat-min-height: 250px; /* 200px * 1.25 */
    --fixed-chat-min-width: 394px;
    --separated-chat-min-width: 394px;
  }
}

@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi) {
  :root {
    --chat-min-width: 473px; /* 300px * 1.5 * 1.05 (增加緩衝) */
    --chat-min-height: 300px; /* 200px * 1.5 */
    --fixed-chat-min-width: 473px;
    --separated-chat-min-width: 473px;
  }
}

/* 175% 縮放優化 */
@media (-webkit-min-device-pixel-ratio: 1.75), (min-resolution: 168dpi) {
  :root {
    --chat-min-width: 550px; /* 300px * 1.75 * 1.05 (增加緩衝) */
    --chat-min-height: 350px; /* 200px * 1.75 */
    --fixed-chat-min-width: 550px;
    --separated-chat-min-width: 550px;
  }
}

/* 200% 縮放優化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  :root {
    --chat-min-width: 690px; /* 300px * 2 * 1.15 (增加緩衝) */
    --chat-min-height: 400px; /* 200px * 2 */
    --fixed-chat-min-width: 690px;
    --separated-chat-min-width: 690px;
  }
}

/* 瀏覽器縮放檢測（使用視窗寬度比例） */
@media (min-width: 1200px) and (max-width: 1439px) {
  /* 可能是 125% 縮放 */
  .chat-container,
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: max(375px, var(--chat-min-width, 300px));
  }
}

@media (min-width: 960px) and (max-width: 1199px) {
  /* 可能是 150% 縮放 */
  .chat-container,
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: max(450px, var(--chat-min-width, 300px));
  }
}

@media (min-width: 800px) and (max-width: 959px) {
  /* 可能是 200% 縮放 */
  .chat-container,
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: max(600px, var(--chat-min-width, 300px));
  }
}

/* 確保聊天室在縮放時文字可讀 */
.chat-container,
.chat-sidebar-content,
.chat-content-fixed,
.separated-chat-content {
  /* 使用相對單位確保文字隨縮放調整 */
  font-size: 1rem;
  line-height: 1.5;
}

/* 聊天室 iframe 縮放優化 */
.chat-container iframe,
.chat-sidebar-content iframe,
.chat-content-fixed iframe,
.separated-chat-content iframe {
  /* 確保 iframe 內容可以正確縮放 */
  transform-origin: top left;
  /* 防止文字被裁剪 */
  overflow: visible;
}

/* 針對不同縮放比例的額外優化 */
@media (min-resolution: 120dpi) {
  /* 125% 縮放 */
  .chat-container {
    min-width: max(394px, var(--chat-min-width, 300px));
  }
  
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: max(394px, var(--fixed-chat-min-width, 300px));
  }
  
  .separated-chat {
    min-width: max(394px, var(--separated-chat-min-width, 300px));
  }
}

@media (min-resolution: 144dpi) {
  /* 150% 縮放 */
  .chat-container {
    min-width: max(473px, var(--chat-min-width, 300px));
  }
  
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: max(473px, var(--fixed-chat-min-width, 300px));
  }
  
  .separated-chat {
    min-width: max(473px, var(--separated-chat-min-width, 300px));
  }
}

/* 175% 縮放優化（針對 1920x1080 @ 175% 的情況） */
@media (min-resolution: 168dpi) {
  .chat-container {
    min-width: max(550px, var(--chat-min-width, 300px));
  }
  
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: max(550px, var(--fixed-chat-min-width, 300px));
  }
  
  .separated-chat {
    min-width: max(550px, var(--separated-chat-min-width, 300px));
  }
}

/* 200% 縮放優化（針對 3840x2160 @ 200% 的情況） */
@media (min-resolution: 192dpi) {
  .chat-container {
    min-width: max(690px, var(--chat-min-width, 300px));
  }
  
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: max(690px, var(--fixed-chat-min-width, 300px));
  }
  
  .separated-chat {
    min-width: max(690px, var(--separated-chat-min-width, 300px));
  }
}

/* 確保在極高縮放下聊天室仍然可用 */
@media (min-resolution: 240dpi) {
  /* 250% 縮放 */
  .chat-container {
    min-width: max(900px, var(--chat-min-width, 300px));
  }
  
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: max(900px, var(--fixed-chat-min-width, 300px));
  }
  
  .separated-chat {
    min-width: max(900px, var(--separated-chat-min-width, 300px));
  }
}

/* 針對特定解析度和縮放組合的優化 */
/* 3840x2160 @ 200% 縮放 */
@media (min-width: 1920px) and (min-height: 1080px) and (-webkit-min-device-pixel-ratio: 2) {
  .chat-container,
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: max(690px, var(--chat-min-width, 300px));
  }
  
  .separated-chat {
    min-width: max(690px, var(--separated-chat-min-width, 300px));
  }
  
  /* 固定布局聊天室側邊欄優化 */
  #fixed-chat-sidebar,
  .chat-sidebar-fixed {
    height: 100vh !important; /* 確保高度正確 */
    top: 0 !important;
    overflow: hidden !important;
  }
  
  /* 確保聊天室面板正確分配高度 */
  .chat-sidebar-panel,
  .fixed-chat-panel {
    height: 100% !important;
    min-height: 0 !important;
  }
  
  /* 確保容器高度正確 */
  #container {
    height: 100vh !important;
    overflow: hidden;
  }
}

/* 1920x1080 @ 175% 縮放 */
@media (min-width: 1097px) and (max-width: 1920px) and (min-height: 617px) and (max-height: 1080px) and (-webkit-min-device-pixel-ratio: 1.75) {
  .chat-container,
  .chat-sidebar-panel,
  .fixed-chat-panel {
    min-width: max(550px, var(--chat-min-width, 300px));
  }
  
  .separated-chat {
    min-width: max(550px, var(--separated-chat-min-width, 300px));
  }
}

/* 打印樣式優化 */
@media print {
  .control-panel,
  .control-panel-toggle-collapsed,
  .separated-chat,
  .favorite-streams-manager,
  .ad-banner {
    display: none !important;
  }
  
  #container {
    padding: 0 !important;
    height: auto !important;
  }
  
  .stream-box {
    position: relative !important;
    page-break-inside: avoid;
  }
}

/* Cookie 同意橫幅樣式 */
.consent-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-panel);
  border-top: 2px solid var(--border-color-active);
  box-shadow: 0 -4px 20px var(--shadow-color);
  z-index: 10000;
  padding: 20px;
  transform: translateY(100%);
  transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
  max-width: 100%;
}

.consent-banner.show {
  transform: translateY(0);
}

.consent-banner-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 20px;
}

.consent-banner-text {
  flex: 1;
}

.consent-banner-title {
  font-size: 18px;
  font-weight: bold;
  color: var(--text-primary);
  margin: 0 0 10px 0;
  transition: color 0.3s ease;
}

.consent-banner-description {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.6;
  transition: color 0.3s ease;
}

.consent-banner-description a {
  color: var(--text-accent);
  text-decoration: underline;
  transition: color 0.3s ease;
}

.consent-banner-description a:hover {
  color: var(--border-color-active);
}

.consent-banner-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 10px 0;
}

.consent-option {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
  transition: color 0.3s ease;
}

.consent-option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--border-color-active);
}

.consent-banner-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
  align-items: center;
  flex-shrink: 0;
}

.consent-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s ease, color 0.3s ease, transform 0.2s ease;
  white-space: nowrap;
}

.consent-btn:hover {
  transform: translateY(-2px);
}

.consent-btn:active {
  transform: translateY(0);
}

.consent-btn-primary {
  background: var(--bg-button-active);
  color: #fff;
}

.consent-btn-primary:hover {
  background: var(--border-color-active);
  opacity: 0.9;
}

.consent-btn-secondary {
  background: var(--bg-button);
  color: var(--text-primary);
  border: 1px solid var(--border-color-hover);
}

.consent-btn-secondary:hover {
  background: var(--bg-button-hover);
  border-color: var(--border-color-active);
}

.consent-btn-tertiary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.consent-btn-tertiary:hover {
  background: var(--bg-button);
  color: var(--text-primary);
  border-color: var(--border-color-hover);
}

@media (max-width: 768px) {
  .consent-banner {
    padding: 15px;
  }
  
  .consent-banner-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .consent-banner-title {
    font-size: 16px;
  }
  
  .consent-banner-description {
    font-size: 13px;
  }
  
  .consent-banner-buttons {
    width: 100%;
    flex-direction: row;
    justify-content: flex-end;
  }
  
  .consent-btn {
    flex: 0 0 auto;
    padding: 10px 16px;
    font-size: 13px;
  }
}

