:root {
  color-scheme: dark;
  --blue: #75b8f4;
  --red: #cc1926;
  --cream: #f4efe0;
  --muted: #b8c3d1;
}
* { box-sizing: border-box; }
body { margin: 0; background: #0b0d10; color: #f1f2f4; font: 16px system-ui, -apple-system, Segoe UI, sans-serif; }
h1, h2, p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: #ffb9ac; min-height: 1.3rem; margin-top: 10px; }
.eyebrow { color: var(--blue); font-size: .72rem; letter-spacing: .16em; font-weight: 700; }

/* Sign-in */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(430px,100%); padding: 34px; border: 1px solid #29425b; border-radius: 24px; background: rgba(16,32,57,.94); box-shadow: 0 24px 70px #0008; }
.brand-mark { font-size: 3rem; font-weight: 900; letter-spacing: -.16em; margin-bottom: 18px; }
.brand-mark span { color: var(--red); font-size: 1.7rem; margin-left: 5px; }
.login-card h1 { margin: 8px 0; font-size: clamp(2rem,4vw,3.4rem); letter-spacing: -.04em; }
.login-card form { display: grid; gap: 14px; margin-top: 24px; }
.login-card label { display: grid; gap: 7px; color: var(--muted); font-size: .9rem; }
.login-card input { width: 100%; padding: 14px 15px; border: 1px solid #69809a; border-radius: 10px; background: #080e17; color: white; font: inherit; }
.primary, .secondary { border: 0; border-radius: 10px; padding: 13px 18px; background: var(--blue); color: #07101a; font: inherit; font-weight: 800; cursor: pointer; }
.secondary { background: #223d5b; color: var(--cream); }

/* Header */
.topbar { width: 100%; min-height: 52px; padding: 5px 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid #27343e; }
.header-logo { display: block; width: 120px; height: 42px; object-fit: contain; object-position: left center; mix-blend-mode: screen; }
.account-menu { position: relative; margin-left: auto; color: #e6edf3; font-size: .85rem; }
.account-menu summary { list-style: none; cursor: pointer; padding: 9px 14px; border: 1px solid #354653; border-radius: 6px; background: #1b2934; }
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu summary:after { content: '▾'; color: #e22a38; margin-left: 12px; }
.account-menu[open] summary { border-color: #678094; }
.account-menu button { position: absolute; z-index: 10; right: 0; top: calc(100% + 4px); width: 100%; min-width: 120px; border: 1px solid #536675; border-radius: 5px; background: #1b2934; color: #f1f3f4; padding: 10px; cursor: pointer; font: inherit; text-align: left; box-shadow: 0 8px 22px #0009; }
.account-menu button:hover { background: #304451; }

/* Preview and programme details */
.watch-top { display: grid; grid-template-columns: minmax(0,2.2fr) minmax(300px,.9fr); gap: 18px; padding: 20px 16px 10px; min-height: 300px; }
.programme-hero { position: relative; min-height: 290px; border: 1px solid #343b42; border-radius: 12px; padding: 40px 40px 76px; background: linear-gradient(95deg,#18212b 0%,#12171de8 70%,#0c0e12); display: flex; flex-direction: column; justify-content: center; box-shadow: 0 18px 35px #0007; }
/* CTS Watch idle state: the supplied Toronto nightscape replaces placeholder text only
   until a channel or programme is selected. Keep the entire logo in frame. */
.programme-hero.is-empty {
  background: #000 url('/watch/idle-banner.png') center center / contain no-repeat;
  overflow: hidden;
}
.programme-hero.is-empty > * { display: none !important; }
.programme-hero.is-guide-banner {
  background: #000 url('/watch/cts-guide-banner.png') center center / contain no-repeat;
  overflow: hidden;
}
.programme-hero.is-guide-banner > * { display: none !important; }
/* Channel 100 — fixed, user-supplied Weather branding instead of programme text. */
.programme-hero.is-weather-banner {
  background: #000 url('/watch/cts-weather-banner.png') center center / contain no-repeat;
  overflow: hidden;
}
.programme-hero.is-weather-banner > * { display: none !important; }
/* CTS Recently Added on channel 101 replaces the entire programme details card. */
.programme-hero.is-recently-added-banner {
  background: #000 url('/watch/cts-recently-added-banner.png') center center / contain no-repeat;
  overflow: hidden;
}
.programme-hero.is-recently-added-banner > * { display: none !important; }
.programme-hero.is-recommended-banner {
  background: #000 url('/watch/cts-recommended-banner.png') center center / contain no-repeat;
  overflow: hidden;
}
.programme-hero.is-recommended-banner > * { display: none !important; }
.programme-hero.has-artwork { background-size: cover; background-position: center; background-repeat: no-repeat; }
.programme-hero h2 { font-size: clamp(2rem,3.5vw,4rem); margin: 14px 0; line-height: 1.05; max-width: 85%; }
.programme-hero.has-show-logo #detail-context { display: none; }
.programme-hero.has-show-logo h2 { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.detail-channel-logo { position: absolute; top: 18px; right: 20px; width: 84px; height: 54px; object-fit: contain; filter: drop-shadow(0 2px 5px #000b); }
.detail-show-logo { width: min(420px,60%); max-height: 128px; object-fit: contain; object-position: left center; margin: 0 0 12px; filter: drop-shadow(0 2px 4px #0008); }
.detail-channel-logo[hidden], .detail-show-logo[hidden], .hero-episode[hidden], .hero-badges[hidden], .tune-selection[hidden] { display: none; }
.hero-episode { font-weight: 700; margin: 0 0 8px; }
.hero-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.hero-badges span { font-size: .68rem; font-weight: 700; color: #d6dadd; background: #444b50; border-radius: 99px; padding: 3px 8px; }
.hero-time { color: #a9c9da; font-weight: 700; }
.hero-description { color: #c6c9cc; margin-top: 18px; max-width: 65ch; line-height: 1.5; }
.tune-selection { position: absolute; right: 24px; bottom: 20px; border: 1px solid #ef4552; border-radius: 8px; background: #bd1928; color: white; padding: 10px 18px; font: inherit; font-weight: 700; cursor: pointer; }
.tune-selection:hover { background: #dc2637; }
.player-shell { padding: 0; margin: 0; min-width: 0; background: #000; border: 1px solid #343b42; border-radius: 12px; overflow: hidden; display: grid; place-items: center; }
.player-shell video { width: 100%; max-height: none; height: 100%; aspect-ratio: 16/9; object-fit: contain; display: block; background: #000; border-radius: 0; }

/* Guide */
.guide-section { padding: 4px 16px 40px; }
.chips { display: flex; gap: 4px; overflow: auto; padding: 0; margin: 0; align-items: end; scrollbar-color: #476175 #111; }
.chip { background: #1d2730; color: #dce3e7; border: 1px solid #40515e; border-bottom: 0; border-radius: 4px 4px 0 0; font: inherit; font-size: .85rem; white-space: nowrap; padding: 8px 12px; cursor: pointer; }
.chip:hover { background: #304451; }
.chip.active { background: #23475c; color: #eaf8ff; border-color: #64c7e9; }
.guide-scroll { overflow: auto; border: 1px solid #303b43; border-top: 2px solid #40515e; background: #121619; scrollbar-color: #405564 #101316; overscroll-behavior: contain; }
.guide-grid { position: relative; width: calc(180px + var(--schedule-width)); min-width: 100%; }
.timeline { display: flex; height: 38px; position: sticky; top: 0; z-index: 3; background: #151a1d; border-bottom: 1px solid #41505b; color: #b6c1c9; font-size: .74rem; }
.timeline-corner { position: sticky; left: 0; z-index: 4; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 14px; width: 180px; min-width: 180px; background: #151a1d; color: #a9c9da; font-weight: 800; letter-spacing: .12em; }
.timeline-controls { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.timeline-arrow { display: grid; place-items: center; flex: none; width: 26px; height: 26px; background: transparent; border: 0; border-radius: 4px; cursor: pointer; padding: 0; }
.timeline-arrow:hover, .timeline-arrow:focus-visible { background: #364b5a; outline: 1px solid #617e90; }
.timeline-arrow:before { content: ''; width: 0; height: 0; border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.timeline-arrow.earlier:before { border-right: 10px solid #db1e2b; }
.timeline-arrow.later:before { border-left: 10px solid #db1e2b; }
.timeline-tick { width: 220px; min-width: 220px; padding: 12px; border-left: 1px solid #34424c; }
.guide-row { display: flex; height: 88px; border-bottom: 1px solid #15202a; }
.guide-row.active .station { border-left: 3px solid #ca1d2a; }
.station { width: 180px; min-width: 180px; position: sticky; left: 0; z-index: 2; display: flex; align-items: center; gap: 8px; border: 1px solid #252d32; background: #191d20; color: #f1f3f4; text-align: left; cursor: pointer; padding: 10px; font: inherit; }
.station:hover { background: #293640; }
.station img { height: 44px; width: 48px; object-fit: contain; }
.station-number { color: #a9c9da; font-size: .72rem; font-weight: 800; }
.station-name { font-size: .78rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.programme-track { position: relative; height: 88px; background: repeating-linear-gradient(90deg,#273a4a 0,#273a4a 219px,#1a2b36 219px,#1a2b36 220px); }
.programme { position: absolute; top: 0; bottom: 0; border: 1px solid #172630; border-radius: 3px; background: #2b4254; color: #edf5f8; display: flex; flex-direction: column; justify-content: center; gap: 4px; padding: 12px; overflow: hidden; text-align: left; cursor: pointer; font: inherit; }
.programme:hover, .programme.on-now:hover { background: #356582; }
.programme.on-now { background: #304f63; }
.programme.selected { background: #315d72; outline: 2px solid #78c9e7; outline-offset: -2px; z-index: 1; }
.programme strong { font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.programme small { font-size: .7rem; color: #bacbd5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.programme.empty { position: static; width: 100%; height: 100%; color: #aab8c2; background: transparent; }
.programme.ended, .programme.ended:hover { background: #1b2933; color: #7d909c; cursor: default; }
.programme.ended small { color: #738796; }
.now-line { position: absolute; top: 0; bottom: 0; width: 2px; background: #8bc5df; z-index: 2; pointer-events: none; box-shadow: 0 0 9px #85c7e5; }
.now-line:before { content: ''; position: absolute; top: 0; left: -4px; border: 5px solid transparent; border-top-color: #8bc5df; }

/* The guide scrolls while the preview stays visible on desktop. */
@media (min-width: 801px) {
  html, body { height: 100%; overflow: hidden; }
  #app { height: 100dvh; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  .topbar, .watch-top { flex: 0 0 auto; }
  .watch-top { height: clamp(245px,32dvh,355px); min-height: 0; }
  .programme-hero { min-height: 0; overflow: auto; }
  .guide-section { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding-bottom: 12px; }
  .chips { flex: 0 0 auto; }
  .guide-scroll { flex: 1 1 auto; min-height: 0; }
}
@media (max-width: 800px) {
  .topbar { padding: 5px 16px; flex-direction: row; }
  .header-logo { width: 96px; height: 35px; }
  .watch-top { grid-template-columns: 1fr; }
  .player-shell { grid-row: 1; height: auto; aspect-ratio: 16/9; }
  .programme-hero { min-height: 170px; padding: 22px 22px 76px; }
  .programme-hero h2 { font-size: 1.7rem; }
  .guide-scroll { height: clamp(300px,52dvh,620px); }
}

/* Programme actions and guide search */
.detail-actions { position: absolute; top: 27px; right: 116px; display: flex; gap: 7px; flex-wrap: nowrap; }
.programme-menu button, .search-bar button { border: 1px solid #536675; border-radius: 6px; background: #1b2934; color: #f1f3f4; padding: 9px 12px; font: inherit; cursor: pointer; }
.detail-actions button[hidden], .programme-menu[hidden], .reminder-toast[hidden] { display: none; }
.programme-menu button:hover, .search-bar button:hover { background: #304451; }
.detail-actions button { width: 34px; height: 34px; display: grid; place-items: center; padding: 6px; border: 1px solid transparent; border-radius: 50%; background: transparent; color: #e5eff4; cursor: pointer; }
.detail-actions button:hover, .detail-actions button:focus-visible { background: #ffffff22; border-color: #8ba6b5; outline: none; }
.detail-actions button.is-active { color: #79cbea; }
.detail-actions svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.detail-actions #favorite-channel svg { fill: none; }
.detail-actions #favorite-channel.is-active svg { fill: currentColor; }
.programme-menu { position: fixed; z-index: 20; width: min(260px, calc(100vw - 24px)); padding: 5px; border: 1px solid #5a7484; border-radius: 8px; background: #16212b; box-shadow: 0 12px 32px #000b; }
.programme-menu button { display: block; width: 100%; margin: 0; border: 0; text-align: left; background: transparent; }
.guide-search { width: min(620px, calc(100vw - 30px)); max-height: min(650px, 80dvh); padding: 16px; border: 1px solid #5a7484; border-radius: 12px; background: #121a21; color: #f1f3f4; box-shadow: 0 18px 55px #000b; }
.guide-search::backdrop { background: #000b; }
.search-bar { display: flex; align-items: center; gap: 10px; }
.search-bar label { font-size: .9rem; font-weight: 700; white-space: nowrap; }
.search-bar input { min-width: 0; flex: 1; padding: 10px; border: 1px solid #5a7484; border-radius: 6px; background: #0a1016; color: white; font: inherit; }
.search-scope { margin: 10px 0; color: #a9c9da; font-size: .8rem; }
.guide-results { max-height: 52dvh; overflow: auto; }
.guide-results button { width: 100%; padding: 11px 8px; border: 0; border-bottom: 1px solid #304451; background: transparent; color: white; text-align: left; font: inherit; cursor: pointer; }
.guide-results button:hover { background: #304451; }
.guide-results small { display: block; color: #a9c9da; margin-top: 3px; }
.reminder-toast { position: fixed; z-index: 30; right: 18px; bottom: 18px; max-width: min(410px, calc(100vw - 36px)); padding: 14px; border: 1px solid #71c9e6; border-radius: 9px; background: #16212b; box-shadow: 0 12px 32px #000b; }
.reminder-toast button { margin-left: 12px; border: 0; background: transparent; color: #80d3f4; cursor: pointer; font: inherit; }
@media (max-width: 800px) {
  .detail-actions { top: 26px; right: 112px; }
  .programme-hero { padding-top: 92px; padding-bottom: 68px; }
}

/* Compact navigation and first on-demand browse view */
.topbar { position: relative; }
.primary-nav { position: absolute; left: 50%; transform: translateX(-50%); display: flex; gap: 2px; padding: 3px; border: 1px solid #26313a; border-radius: 25px; background: #11161b; white-space: nowrap; }
.section-tab { border: 1px solid transparent; border-radius: 20px; background: transparent; color: #ccd5dc; font: inherit; font-size: .72rem; padding: 6px 12px; cursor: pointer; }
.section-tab:hover, .section-tab:focus-visible { color: white; background: #ffffff18; }
.section-tab.active { color: #76c8f0; background: #25343f; border-color: #496272; }
.library-view { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 22px 24px 50px; scrollbar-color: #405564 #101316; }
.library-header { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 20px; }
.library-header h2 { font-size: 1.5rem; }
.library-heading { display: flex; align-items: center; gap: 14px; }
#library-back, .library-shelf-header button { background: transparent; border: 0; color: #88cdea; cursor: pointer; font: inherit; }
.library-shelf { margin: 0 0 25px; }
.library-shelf-header { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 10px; }
.library-shelf-header h3 { margin: 0; font-size: 1.1rem; }
.library-shelf-track { display: flex; gap: 13px; min-height: 60px; overflow-x: auto; padding: 2px 1px 12px; scrollbar-color: #405564 #101316; scroll-snap-type: x proximity; }
.library-shelf-track .library-card { flex: 0 0 clamp(130px, 12vw, 185px); scroll-snap-align: start; }
#library-search-form { display: flex; gap: 6px; }
#library-query { min-width: 160px; padding: 9px 12px; border: 1px solid #415360; border-radius: 7px; color: white; background: #111c25; font: inherit; }
#library-search-form button, .library-more { padding: 9px 14px; border: 1px solid #476175; border-radius: 7px; background: #1d303e; color: #e9f2f6; font: inherit; cursor: pointer; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(150px,1fr)); gap: 16px; }
.library-card { min-width: 0; padding: 0; border: 1px solid #34434e; border-radius: 9px; overflow: hidden; background: #17212a; color: white; text-align: left; cursor: pointer; font: inherit; }
.library-card:hover, .library-card:focus-visible { border-color: #77cae9; background: #243644; }
.library-card img { display: block; width: 100%; aspect-ratio: 2/3; object-fit: cover; background: #24313a; }
.library-placeholder { display: grid; place-items: center; aspect-ratio: 2/3; background: #24313a; color: #9aafbb; font-size: 2rem; }
.library-card strong { display: block; padding: 9px 9px 2px; font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-card small { display: block; padding: 0 9px 10px; color: #9fb3bf; font-size: .73rem; }
.library-more { display: block; margin: 22px auto; }
.library-detail { position: relative; max-width: 980px; margin-bottom: 22px; padding: 24px; border: 1px solid #40515e; border-radius: 10px; background: #17232d; }
.library-detail h3 { font-size: 1.45rem; margin: 0 30px 8px 0; }
.library-detail p { max-width: 75ch; color: #c8d4dc; line-height: 1.5; margin-top: 10px; }
.library-detail .close-detail { position: absolute; right: 14px; top: 10px; border: 0; background: transparent; color: white; font: inherit; font-size: 1.5rem; cursor: pointer; }
@media(max-width: 850px) {
  .topbar { flex-wrap: wrap; }
  .primary-nav { position: static; order: 3; transform: none; flex: 1 0 100%; justify-content: center; overflow-x: auto; }
  .section-tab { padding: 6px 8px; }
  .library-view { overflow: visible; padding: 18px 16px 36px; }
  .library-header { align-items: stretch; flex-direction: column; }
  #library-query { flex: 1; }
  .library-grid { grid-template-columns: repeat(auto-fill,minmax(125px,1fr)); gap: 10px; }
}
