/* === Listener — TCOC Design System === */
/* Variables & reset in tokens.css */
:root { --font-size: 1.125rem; }

/* Skip-to-content link（無障礙：鍵盤可見，滑鼠隱藏） */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--main);
  color: #1A1A1A;
  padding: 0.5rem 1rem;
  z-index: 100;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0 0 var(--radius) 0;
  text-decoration: none;
}
.skip-link:focus { top: 0; }

/* Dark mode — system preference (listener only) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1A1A1A;
    --surface: #2D2D2D;
    --surface-hover: #3A3A3A;
    --border: #404040;
    --text: #F0F0F0;
    --text-muted: rgba(255, 255, 255, 0.60);
    --text-light: rgba(255, 255, 255, 0.55);
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
    --main-light: #3D3000;
  }
}

/* Dark mode — manual toggle */
[data-theme="dark"] {
  --bg: #1A1A1A;
  --surface: #2D2D2D;
  --surface-hover: #3A3A3A;
  --border: #404040;
  --text: #F0F0F0;
  --text-muted: rgba(255, 255, 255, 0.60);
  --text-light: rgba(255, 255, 255, 0.40);
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
  --main-light: #3D3000;
}

body {
  font-family: "Noto Sans TC", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.container {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  padding: 0.75rem 1rem;
}

/* 講道資訊 */
.broadcast-meta {
  text-align: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.broadcast-meta h1 {
  font-size: 1.125rem;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.broadcast-meta .meta-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }
.broadcast-meta .meta-desc { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.25rem; }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  flex-wrap: wrap;
}

.toolbar select {
  appearance: none;
  -webkit-appearance: none;
  padding: 0.5rem 2rem 0.5rem 0.5rem;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 0.5rem center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.8125rem;
  min-height: 36px;
}

.btn-icon {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  color: var(--text);
  cursor: pointer;
  font-size: 0.8125rem;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
}
.btn-icon:hover { background: var(--border); }
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }

.toolbar-right { margin-left: auto; display: flex; gap: 0.375rem; }

/* Mode tabs */
.mode-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.tab {
  flex: 1;
  padding: 0.5rem;
  background: var(--surface);
  border: none;
  color: var(--text-muted);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 36px;
}
.tab.active { background: var(--main); color: var(--text); font-weight: 500; }

/* Captions */
main { flex: 1; margin-top: 0.5rem; overflow: hidden; position: relative; }

/* 字幕 frame — 仿 broadcaster 控制台 .transcript-box：固定高度框、內容溢出自動往上捲
   最新永遠在底；user 想看歷史可主動往上滑 */
.captions-area {
  height: 100%;
  min-height: 240px;
  max-height: 65vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  overflow-y: auto;
}
/* kiosk 仍走 viewport-filling 全螢幕模式，不用 frame */
.kiosk-mode .captions-area {
  background: transparent;
  border: none;
  padding: 0.25rem 0;
  max-height: none;
}

.caption-item {
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border);
}

/* 並排 layout（mode === 'side'）：原文左、譯文右 grid */
.caption-item.layout-side {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 0.75rem;
  align-items: start;
}
.caption-item.layout-side .caption-original {
  margin-bottom: 0;
  padding-right: 0.75rem;
  border-right: 1px solid var(--border);
}
/* 窄螢幕（< 480px）並排不夠寬，自動 fallback 垂直堆疊 */
@media (max-width: 480px) {
  .caption-item.layout-side {
    display: block;
  }
  .caption-item.layout-side .caption-original {
    border-right: none;
    padding-right: 0;
    margin-bottom: 0.25rem;
  }
}

/* 新 final 進場動畫：minimal、可讀、spring-like easing */
@keyframes captionFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.caption-final {
  animation: captionFadeIn 250ms ease-out;
}

.caption-streaming .caption-translation {
  color: var(--text-muted);
  opacity: 0.85;
}

/* share-toast 使用（保留 legacy keyframes） */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.caption-original {
  font-size: calc(var(--font-size) * 0.85);
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  line-height: 1.5;
}
.caption-translation { font-size: var(--font-size); line-height: 1.6; }

/* 漸進式渲染：interim → final 平滑過渡 */
.caption-interim-text {
  color: var(--text-muted);
  font-style: italic;
  opacity: 0.7;
  transition: opacity 0.3s ease, color 0.3s ease;
}

/* 打字機游標 */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--main);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* 書籤樣式 */
.caption-item.bookmarked {
  border-left: 3px solid var(--main);
  padding-left: 0.75rem;
  background: var(--main-light);
}
.bookmark-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 50vh;
  overflow-y: auto;
  background: var(--surface);
  border-top: 2px solid var(--main);
  padding: 1rem;
  z-index: 50;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
}
.bookmark-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.bookmark-item:last-child { border-bottom: none; }

/* 翻譯失敗降級提示 */
.caption-failed { border-left: 3px solid var(--warning); padding-left: 0.75rem; }
.caption-fail-hint {
  display: block;
  font-size: 0.6875rem;
  color: var(--warning);
  font-style: italic;
  margin-top: 0.25rem;
}

/* RTL */
[dir="rtl"] .caption-original, [dir="rtl"] .caption-translation { text-align: right; direction: rtl; }
.caption-translation[data-lang="ar"], .caption-translation[data-lang="he"] {
  direction: rtl; text-align: right;
  font-family: 'Noto Sans Arabic', 'Noto Sans Hebrew', sans-serif;
  line-height: 1.8;
}

/* 字幕區底部列：暫停鍵 + scroll-to-bottom */
.captions-footer {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2rem;
  margin-top: 0.25rem;
}

/* 暫停鍵 — 左側常駐 */
.btn-pause {
  position: absolute;
  left: 0;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
}
.btn-pause.paused {
  background: var(--main);
  color: var(--text);
  border-color: var(--main);
}

/* Scroll button — 置中浮現 */
.scroll-to-bottom {
  background: var(--main);
  color: var(--text);
  border: none;
  border-radius: 100px;
  padding: 0.375rem 1rem;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  display: none;
  z-index: 10;
}
.scroll-to-bottom.visible { display: block; }

/* Footer — 含 safe area 底部 padding */
footer {
  padding: 0.5rem 0;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
}
.status { display: flex; align-items: center; gap: 0.5rem; font-size: 0.6875rem; color: var(--text-muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-light); flex-shrink: 0; }
.dot.connected { background: var(--success); }
.dot.error { background: var(--danger); }

/* Dark mode extras */
[data-theme="dark"] .tab.active { color: #1A1A1A; }
[data-theme="dark"] .scroll-to-bottom { color: #1A1A1A; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tab.active { color: #1A1A1A; }
  :root:not([data-theme="light"]) .scroll-to-bottom { color: #1A1A1A; }
}

/* 高對比模式 */
.high-contrast {
  --bg: #000000;
  --surface: #1A1A1A;
  --text: #FFFFFF;
  --text-muted: rgba(255, 255, 255, 0.85);
  --text-light: rgba(255, 255, 255, 0.70);
  --border: #555555;
}
.high-contrast .caption-original { color: rgba(255, 255, 255, 0.85); }
.high-contrast .caption-translation { color: #FFFFFF; font-weight: 500; }
.high-contrast .caption-interim-text { opacity: 0.85; color: #CCCCCC; }

/* 投影/Kiosk 模式 */
.kiosk-mode {
  --font-size: 2.5rem;
}
.kiosk-mode .container { max-width: 100%; padding: 1.5rem 3rem; }
.kiosk-mode .broadcast-meta { padding: 1rem 0; }
.kiosk-mode .broadcast-meta h1 { font-size: 1.5rem; }
.kiosk-mode .toolbar { display: none; }
.kiosk-mode .captions-area {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.kiosk-mode .caption-item {
  padding: 1rem 0;
  border-bottom: none;
}
.kiosk-mode .caption-item:not(:nth-last-child(-n+3)) { display: none; }
.kiosk-mode .caption-original { font-size: calc(var(--font-size) * 0.7); }
.kiosk-mode .caption-translation { font-size: var(--font-size); font-weight: 500; }
.kiosk-mode footer { display: none; }

/* PWA standalone 模式優化 */
@media (display-mode: standalone) {
  .container { padding-top: env(safe-area-inset-top, 0.5rem); }
}

/* 行動裝置 landscape 模式 — 最大化字幕區 */
@media (max-height: 500px) and (orientation: landscape) {
  .broadcast-meta { display: none; }
  .toolbar { padding: 0.25rem 0; }
  .container { padding: 0.25rem 0.5rem; }
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
