/* =========================================================
   YouTube 日繁雙語字幕播放器 — iPad 橫向/直向專屬樣式
   ========================================================= */

:root {
  --bg-page: #0b1120;
  --bg-surface: #131c31;
  --bg-elevated: #1b2742;
  --bg-stage: #060a14;
  --border-subtle: rgba(148, 163, 184, 0.2);
  --border-strong: rgba(148, 163, 184, 0.35);

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --sub-jp-color: #93c5fd;
  --sub-zh-color: #fef08a;

  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --radius-md: 12px;
  --radius-lg: 16px;

  /* 預設字體尺寸 (md) */
  --sub-jp-size: 1.08rem;
  --sub-zh-size: 1.45rem;
  --list-jp-size: 0.92rem;
  --list-zh-size: 1.02rem;
}

body[data-font-size="sm"] {
  --sub-jp-size: 0.92rem;
  --sub-zh-size: 1.2rem;
  --list-jp-size: 0.85rem;
  --list-zh-size: 0.95rem;
}

body[data-font-size="md"] {
  --sub-jp-size: 1.08rem;
  --sub-zh-size: 1.48rem;
  --list-jp-size: 0.92rem;
  --list-zh-size: 1.04rem;
}

body[data-font-size="lg"] {
  --sub-jp-size: 1.28rem;
  --sub-zh-size: 1.78rem;
  --list-jp-size: 1rem;
  --list-zh-size: 1.15rem;
}

body[data-font-size="xl"] {
  --sub-jp-size: 1.5rem;
  --sub-zh-size: 2.1rem;
  --list-jp-size: 1.08rem;
  --list-zh-size: 1.25rem;
}

/* 切換為「僅繁中」模式時隱藏日文原文 */
body[data-display-mode="zh-only"] .sub-jp,
body[data-display-mode="zh-only"] .cue-row-jp {
  display: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Hiragino Sans",
    "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* =========================================================
   按鈕與輸入框（符合 iPad 觸控 ≥ 44px 規範）
   ========================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

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

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: #243356;
}

.btn-active {
  border-color: rgba(59, 130, 246, 0.7);
  background: rgba(59, 130, 246, 0.18);
  color: #bfdbfe;
}

.btn-success {
  background: var(--success);
  color: #052e16;
}

.btn-warning {
  background: var(--warning);
  color: #1c1917;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-subtle);
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-primary);
}

.btn-compact {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.88rem;
}

.btn-block {
  width: 100%;
}

.text-input {
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 1rem; /* 16px 防止 iPadOS Safari 聚焦自動縮放 */
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.inline-error {
  margin: 8px 0 0;
  color: #fca5a5;
  font-size: 0.9rem;
  line-height: 1.45;
}

/* =========================================================
   密碼鎖定彈窗
   ========================================================= */

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 10, 20, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 28px 24px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.auth-icon {
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.auth-title {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.auth-desc {
  margin: 0 0 20px;
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.55;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.auth-input {
  width: 100%;
}

/* =========================================================
   主外殼與頂部導覽
   ========================================================= */

.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding:
    max(12px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.top-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.top-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.03em;
}

.brand-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.url-form {
  flex: 1 1 320px;
  display: flex;
  gap: 8px;
  min-width: 0;
}

.url-input {
  flex: 1 1 auto;
  min-width: 0;
}

.recent-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.recent-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.recent-list {
  display: flex;
  gap: 6px;
}

.recent-chip {
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}

.recent-chip-active {
  border-color: var(--accent);
  color: #bfdbfe;
  background: rgba(59, 130, 246, 0.2);
}

/* =========================================================
   提示橫幅與翻譯進度條
   ========================================================= */

.status-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-banner {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.94rem;
  line-height: 1.5;
  border: 1px solid transparent;
  white-space: pre-wrap;
  word-break: break-word;
}

.alert-error {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.alert-warning {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.45);
  color: #fde68a;
}

.alert-info {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.45);
  color: #bfdbfe;
}

.ready-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.5);
  color: #a7f3d0;
  font-size: 0.94rem;
  font-weight: 500;
}

.progress-card {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.progress-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.progress-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-percent {
  font-weight: 700;
  font-size: 0.92rem;
  color: #93c5fd;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.16);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #3b82f6, #10b981);
  transition: width 0.25s ease;
}

.progress-error-detail {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fecaca;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.84rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* =========================================================
   主工作區（直向堆疊 / iPad 橫向雙欄）
   ========================================================= */

.workspace-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}

.player-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

/* 16:9 響應式 YouTube 播放器 */
.player-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000000;
  border: 1px solid var(--border-subtle);
}

.yt-player-mount,
.player-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.player-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #172554 0%, #090e1c 75%);
  text-align: center;
}

.placeholder-inner {
  max-width: 440px;
}

.placeholder-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.placeholder-hint {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.6;
}

/* =========================================================
   播放器下方獨立雙語焦點字幕區塊
   ========================================================= */

.subtitle-stage {
  min-height: 132px;
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  background: var(--bg-stage);
  border: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.subtitle-stage.stage-empty::after {
  content: "· · ·";
  color: rgba(148, 163, 184, 0.25);
  font-size: 1.2rem;
  letter-spacing: 0.35em;
}

.sub-jp {
  font-size: var(--sub-jp-size);
  line-height: 1.5;
  color: var(--sub-jp-color);
  font-weight: 500;
  word-break: break-word;
}

.sub-zh {
  font-size: var(--sub-zh-size);
  line-height: 1.48;
  color: var(--sub-zh-color);
  font-weight: 700;
  word-break: break-word;
}

.sub-translating {
  color: var(--text-muted);
  font-weight: 500;
  font-size: calc(var(--sub-zh-size) * 0.78);
  animation: pulseOpacity 1.4s ease-in-out infinite;
}

.sub-failed {
  color: #fca5a5;
  font-weight: 500;
  font-size: calc(var(--sub-zh-size) * 0.75);
}

@keyframes pulseOpacity {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* 控制列 */
.control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.font-stepper {
  display: inline-flex;
  gap: 6px;
}

/* =========================================================
   折疊式手動匯入備案面板
   ========================================================= */

.manual-card {
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.manual-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.94rem;
  color: var(--text-secondary);
  user-select: none;
}

.manual-summary::-webkit-details-marker {
  display: none;
}

.manual-card[open] .manual-summary {
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.manual-card[open] .manual-chevron {
  transform: rotate(180deg);
}

.manual-chevron {
  transition: transform 0.2s ease;
}

.manual-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.manual-hint {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.55;
}

.manual-hint code {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--bg-page);
  color: #93c5fd;
  font-size: 0.85rem;
}

.manual-textarea {
  width: 100%;
  min-height: 130px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}

.manual-textarea:focus {
  border-color: var(--accent);
}

.manual-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* =========================================================
   完整互動時間軸字幕清單
   ========================================================= */

.transcript-column {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  min-width: 0;
}

.transcript-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(11, 17, 32, 0.35);
}

.transcript-title {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 700;
}

.count-badge {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
}

.cue-list-container {
  position: relative;
  max-height: 46vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cue-list-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.cue-row {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.cue-row:hover {
  background: rgba(148, 163, 184, 0.08);
}

.cue-row-active {
  background: rgba(59, 130, 246, 0.18) !important;
  border-color: rgba(59, 130, 246, 0.65);
}

.cue-time {
  flex-shrink: 0;
  min-width: 48px;
  padding-top: 2px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.cue-row-active .cue-time {
  color: #60a5fa;
}

.cue-texts {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.cue-row-jp {
  font-size: var(--list-jp-size);
  line-height: 1.45;
  color: var(--sub-jp-color);
  word-break: break-word;
}

.cue-row-zh {
  font-size: var(--list-zh-size);
  line-height: 1.48;
  color: var(--text-primary);
  font-weight: 500;
  word-break: break-word;
}

.cue-row-active .cue-row-zh {
  color: var(--sub-zh-color);
  font-weight: 700;
}

.cue-pending {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.88rem;
}

.cue-failed {
  color: #fca5a5;
  font-size: 0.88rem;
}

/* =========================================================
   iPad 橫向大螢幕最佳化（≥ 960px 切換為左右雙欄）
   ========================================================= */

@media (min-width: 960px) {
  .workspace-grid {
    grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr);
    gap: 16px;
  }

  .transcript-column {
    position: sticky;
    top: 12px;
    height: calc(100dvh - 130px);
    min-height: 480px;
  }

  .cue-list-container {
    max-height: none;
    flex: 1 1 auto;
  }

  .subtitle-stage {
    min-height: 146px;
  }
}

/* 小螢幕微調 */
@media (max-width: 600px) {
  .brand-name {
    display: none;
  }

  .subtitle-stage {
    min-height: 116px;
    padding: 14px 12px;
  }
}
