

/* ==== features: static/features/tv.css ==== */
/* tv：頻道網格、匯入、管理、編輯。
 * 對照 iOS 的 IPTVGridView／IPTVChannelCell 的度量：格距 6、16:9、圓角 10、
 * 台標內距 12、膠囊 8×4、字 12px 粗體、黑 0.66。
 *
 * 這一支只用 var(--…)。網格那一格是「一塊會動的影像」，底色與膠囊**不跟深淺色走**
 * （影像本身沒有主題，iOS 端也是寫死的近黑漸層與黑 0.66），所以把那幾個值宣告成
 * 這個功能自己的 token，集中在 .tv-grid 上，不散在規則裡。 */

.tv-page { padding-bottom: 12px; }
.tv-title { margin: 0; font-size: 22px; font-weight: 700; }
.tv-head .iconbtn[hidden], .tv-filters[hidden], .tv-group[hidden] { display: none; }

/* ---------- 搜尋列 ---------- */
.tv-filters {
  display: flex;
  gap: var(--gap);
  margin: 0 0 12px;
}
.tv-search, .tv-group {
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.tv-search { flex: 1; }
.tv-group { flex: 0 1 40%; }

/* ---------- 網格（IPTVGridView） ---------- */
.tv-grid {
  /* 格子與格子之間。6 而不是 12：這裡每一格是一塊會動的影像，不是有底色的卡片。
     一整面影像之間留太多空隙，看起來是被切碎的，不是排好的。 */
  --tv-gap: 6px;
  /* 沒在播的時候看到的底（IPTVChannelCell.idleBackdrop）。
     純黑會被讀成「壞掉」，不是「還沒輪到」——所以是一層極淡的漸層，看起來是刻意的空位。 */
  --tv-cell-top: #212121;
  --tv-cell-bottom: #0d0d0d;
  /* 台名膠囊：黑 0.66，推導見 tv.js 的 cell()；字永遠是白。 */
  --tv-caption-bg: rgba(0, 0, 0, 0.66);
  --tv-caption-ink: #ffffff;
  --tv-caption-shadow: rgba(0, 0, 0, 0.85);
  /* 深色台標墊的淺色底板。刻意不是純白：純白在一整面深色網格裡太跳，而且標誌本身
     多半就有白色元素，需要一點色差才看得出邊界。iOS 是 white 0.92。 */
  --tv-plate: #ebebeb;
  --tv-glyph: rgba(255, 255, 255, 0.28);

  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--tv-gap);
  min-height: 120px;
}
.tv-grid[data-state="empty"], .tv-grid[data-state="content"]:has(.tv-empty) { display: block; }
.tv-empty { padding-top: 56px; }
.tv-empty-action { margin-top: 16px; }

.tv-cell {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(var(--tv-cell-top), var(--tv-cell-bottom));
}
.tv-cell-play {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
}
.tv-cell-play:focus-visible { outline-offset: -3px; }
.tv-cell-backdrop { position: absolute; inset: 0; }

/* 台標貼著標誌本身、內距 12；深色的墊底板（is-dark）並多留 6 的內距 */
.tv-logo-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
}
.tv-logo {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.tv-logo[hidden], .tv-glyph[hidden] { display: none; }
.tv-logo-wrap.is-dark .tv-logo {
  padding: 6px;
  border-radius: 6px;
  background: var(--tv-plate);
  max-height: 100%;
}
.tv-glyph { display: grid; place-items: center; color: var(--tv-glyph); }
.tv-glyph .ms { --ms-size: 26px; --ms-opsz: 24; }

.tv-cell-caption {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--tv-caption-bg);
  color: var(--tv-caption-ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px var(--tv-caption-shadow);
}

/* 「⋯」：右上角，44 的可點目標，視覺上小一點但不縮觸控面積 */
.tv-cell-more {
  position: absolute;
  top: 0;
  right: 0;
  color: var(--tv-caption-ink);
  filter: drop-shadow(0 1px 2px var(--tv-caption-shadow));
}
.tv-cell-more .ms { --ms-size: 20px; --ms-opsz: 20; }

.tv-host { margin: 0; color: var(--ink-3); font-size: 13px; }

/* ---------- 表單共用（匯入、編輯、改名、管理） ---------- */
.tv-form { display: grid; gap: 16px; }
.tv-section { margin: 0; }
.tv-section h3 { margin: 0 0 7px 4px; color: var(--ink-3); font-size: 12px; font-weight: 600; }
.tv-fields {
  display: grid;
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--line-soft);
}
.tv-fields > * { background: var(--surface); }
.tv-fields input[type="text"], .tv-fields input[type="url"], .tv-fields input[type="search"] {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 0;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.tv-fields input.is-mono { font-family: ui-monospace, Menlo, monospace; font-size: 16px; }
.tv-fields .tv-row {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  color: var(--ink);
  font-size: 14px;
}
.tv-fields .tv-row-btn {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 0;
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.tv-fields .tv-row-btn:disabled { color: var(--ink-3); cursor: not-allowed; }
.tv-fields .tv-row-btn.is-danger { color: var(--danger); }
.tv-fields .tv-row-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--surface) 88%, var(--accent)); }
.tv-fields .tv-toggle { justify-content: space-between; cursor: pointer; }
.tv-fields .tv-toggle input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.tv-fields .tv-masked { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--ink-3); }
.tv-footer { margin: 7px 4px 0; color: var(--ink-3); font-size: 12px; line-height: 1.5; }
.tv-footer + .tv-footer { margin-top: 6px; }
.tv-result { display: grid; gap: 4px; padding: 10px 12px; }
.tv-result p { margin: 0; font-size: 14px; }
.tv-result .is-sub { color: var(--ink-3); font-size: 12px; }
.tv-result .is-error { color: var(--danger); }
.tv-file { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.tv-list-row { display: flex; flex-direction: column; gap: 2px; min-width: 0; text-align: left; }
.tv-list-sub { color: var(--ink-3); font-size: 12px; }
.tv-row-main { flex: 1; min-width: 0; }
.tv-row .tv-row-del { margin-left: auto; color: var(--danger); }

/* ---------- 目錄選單 ---------- */
.tv-picker { display: grid; gap: 10px; }
.tv-picker .segs { gap: 14px; }
.tv-picker-list { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow: auto; border: 1px solid var(--line-soft); border-radius: var(--radius); }
.tv-picker-list button {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.tv-picker-list li:last-child button { border-bottom: 0; }
.tv-picker-list button:hover { background: color-mix(in srgb, var(--surface) 88%, var(--accent)); }
.tv-picker-list .is-code { color: var(--ink-3); }

/* ---------- 管理（IPTVManageView） ---------- */
.tv-manage { display: grid; gap: 12px; }
.tv-manage-tools { display: flex; align-items: center; gap: 8px; }
.tv-manage-tools .spacer { margin-left: auto; }
.tv-manage-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--line-soft); overflow: hidden; }
.tv-manage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 4px 6px 4px 10px;
  background: var(--surface);
}
.tv-manage-row.is-selected { background: color-mix(in srgb, var(--surface) 86%, var(--accent)); }
.tv-manage-check {
  width: 44px;
  height: 44px;
  margin-left: -8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
}
.tv-manage-row input[type="checkbox"] { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.tv-manage-row .tv-list-row { flex: 1; }
.tv-manage-row .tv-list-row span:first-child, .tv-list-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-manage-row .iconbtn { color: var(--ink-2); }
.tv-manage-row .iconbtn:disabled { opacity: .3; cursor: not-allowed; }
.tv-manage-row .iconbtn .ms { --ms-size: 18px; --ms-opsz: 20; }
.tv-manage-bar {
  position: sticky;
  bottom: 0;
  padding: 10px 0 0;
  background: var(--surface);
}
.tv-manage-bar[hidden] { display: none; }
.tv-manage-bar .ui-btn { width: 100%; }
.tv-manage-bar .ui-btn.is-danger { border-color: transparent; background: var(--danger); color: var(--accent-ink); font-weight: 700; }
.tv-manage-empty { list-style: none; background: var(--surface); }
.tv-manage-empty .tv-empty { padding: 32px 18px; }
.tv-url-value { min-width: 0; }
.tv-url-value .tv-masked { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-url-value input { min-width: 0; }
.tv-edit-error { margin: 0; color: var(--danger); font-size: 13px; }

@media (prefers-reduced-motion: no-preference) {
  .tv-manage-row { transition: background .15s ease; }
}


/* ==== features: static/features/tv-player.css ==== */
/* tv-player：全螢幕播放器、PiP 狀態、格內預覽與流量開關。 */
html.tvplayer-open, html.tvplayer-open body { overflow: hidden; }

.tvplayer {
  --tvplayer-ground: #000;
  --tvplayer-ink: #fff;
  --tvplayer-chrome: rgba(12, 12, 14, .76);
  --tvplayer-chip: rgba(0, 0, 0, .68);
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--tvplayer-ground);
  color: var(--tvplayer-ink);
}
.tvplayer.is-pip { display: none; }
.tvplayer-head {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  min-height: calc(64px + env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(var(--tvplayer-chrome), transparent);
}
.tvplayer-titles { min-width: 0; margin-right: auto; }
.tvplayer-title, .tvplayer-host { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tvplayer-title { font-size: 17px; font-weight: 700; }
.tvplayer-host { margin-top: 2px; color: color-mix(in srgb, var(--tvplayer-ink) 70%, transparent); font-size: 12px; }
.tvplayer-btn { flex: 0 0 44px; color: var(--tvplayer-ink); background: var(--tvplayer-chip); backdrop-filter: blur(16px); }
.tvplayer-btn[hidden] { display: none; }
.tvplayer-btn .ms { --ms-size: 21px; --ms-opsz: 24; }
.tvplayer-stage { grid-row: 1 / -1; position: relative; min-width: 0; min-height: 0; display: grid; place-items: center; }
.tvplayer-video { display: block; width: 100%; height: 100%; object-fit: contain; background: var(--tvplayer-ground); }
.tvplayer-stage > .state-panel {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  background: var(--tvplayer-ground);
  color: var(--tvplayer-ink);
  text-align: center;
}
.tvplayer-stage[data-state="content"] > .state-panel { display: none; }
.tvplayer-stage .state-retry { color: var(--tvplayer-ink); border-color: color-mix(in srgb, var(--tvplayer-ink) 35%, transparent); }
.tvplayer-buffering {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: color-mix(in srgb, var(--tvplayer-ground) 18%, transparent);
}
.tvplayer-buffering[hidden] { display: none; }
.tvplayer-buffering .state-spinner { width: 28px; height: 28px; border-color: rgba(255,255,255,.35); border-top-color: var(--tvplayer-ink); }

/* preview slot 是 tv-core 與播放器的唯一 DOM 契約。 */
.tv-preview-slot { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.tvplayer-preview { position: absolute; inset: 0; overflow: hidden; background: transparent; }
.tvplayer-preview-video { display: block; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tv-cell:has(.tvplayer-preview.is-live) .tv-logo-wrap { opacity: 0; }
.tv-cell-caption, .tv-cell-more { z-index: 3; }
.tvplayer-watching {
  position: absolute;
  top: 8px;
  left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: calc(100% - 60px);
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--tvplayer-chip);
  color: var(--tvplayer-ink);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.tvplayer-watching .ms { --ms-size: 14px; --ms-opsz: 20; }

.tvplayer-footer {
  margin: 18px 0 84px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
}
.tvplayer-toggle { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.tvplayer-toggle-input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.tvplayer-footnote { margin: 5px 0 0; color: var(--ink-3); font-size: 12px; line-height: 1.5; }
.tvplayer-footnote[hidden] { display: none; }

@media (max-width: 600px) {
  .tvplayer-head { padding-left: max(10px, env(safe-area-inset-left)); }
  .tvplayer-title { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .tvplayer-buffering .state-spinner { animation: none; }
}
