@supports not (aspect-ratio: 1 / 1) {
  .featured-row .tile { height: 11vw; }
  .poster-row .tile { height: 12vw; }
  .channel-card-row .tile { height: 6vw; }
  .series-card-row .tile, .resume-card-row .tile { height: 7vw; }
  .live-preview .channel-preview, .channel-placeholder { height: 17vw; }
  .tile-play { height: 24px; }
}

@supports not (display: grid) {
  .sidebar { width: 16%; }
  main { flex: 1; }
  .sidebar nav, .stack, .settings-shortcuts { display: flex; flex-direction: column; }
  .stack button, .settings-shortcuts button { margin-bottom: 4px; }
  .shelf-row { display: flex; }
  .shelf-row .tile { flex: 0 0 15%; margin-right: 8px; }
  .featured-row .tile { flex-basis: 32%; }
  .poster-row .tile { flex-basis: 12%; }
  .resume-card-row .tile { flex-basis: 24%; }
  .live-layout, .films-layout, .settings, .guide-line, .guide-hours { display: flex; }
  .live-categories { flex: 1; }
  .live-channels, .live-preview { flex: 1.7; }
  .live-layout .panel { margin-right: 6px; }
  .film-rows { min-width: 0; flex: 1; }
  .film-categories { width: 15%; margin-left: 8px; }
  .guide-line > :first-child { width: 15%; }
  .guide-hours, .guide-track { flex: 1; }
  .guide-hours time { width: 20%; }
  .settings-brand { width: 16%; }
  .settings-forms { width: 46%; margin: 0 10px; }
  .settings-shortcuts { width: 33%; }
  .settings-form label, .settings-forms form label { display: block; }
  .settings-forms form { display: flex; flex-direction: column; }
  .settings-forms label input { display: block; width: 100%; margin: 3px 0 8px; }
}

/* Older TV engines lack :focus-visible. */
button:focus, a:focus, summary:focus, input:focus, select:focus {
  outline: 3px solid #f3bdff;
  outline-offset: 2px;
}

/* Explicit edges for TV engines without the inset shorthand. */
.shelf-row .tile img { top: 0; right: 0; bottom: 0; left: 0; }
.tile-caption { right: 0; bottom: 0; left: 0; }
.channel-card .tile-caption { top: 0; }
.film-hero::before { top: 0; right: 0; bottom: 0; left: 0; }

/* Samsung layout with spacing that also works without flex gap. */
.tv-ui body { padding: 1.6vw; }
.tv-ui main { min-width: 0; margin-left: 1vw; }
.tv-ui .sidebar nav button { min-height: 42px; font-size: 1.2rem; margin-bottom: 5px; }
.tv-ui .sidebar nav .ui-icon, .tv-ui .settings-shortcuts .ui-icon { margin-right: .55em; }
.tv-ui .shelf-heading h3 { font-size: 1.25rem; margin-bottom: 8px; }
.tv-ui .shelf-row { display: flex; padding: 6px; }
.tv-ui .shelf-row .tile { margin-right: 11px; }
.tv-ui .featured-row .tile { flex: 0 0 47%; height: 15vw; }
.tv-ui .poster-row .tile { flex: 0 0 15%; height: 15vw; }
.tv-ui .channel-card-row .tile { flex: 0 0 15%; height: 8vw; }
.tv-ui .channel-card.has-artwork img { top: 8%; bottom: auto; height: 53%; padding: 0 10%; }
.tv-ui .channel-card .tile-caption { top: auto; padding: 2% 5% 5%; background: #251735; }
.tv-ui .tile-caption strong, .tv-ui .tile-caption small,
.tv-ui .shortcut-caption strong, .tv-ui .shortcut-caption small { display: block; }
.tv-ui .tile-caption small, .tv-ui .shortcut-caption small { margin-top: 4px; }
.tv-ui .settings { display: block; margin-top: 1.2vw; }
.tv-ui .settings::before, .tv-ui .settings-brand,
.tv-ui .settings:not(.settings-detail) .settings-forms,
.tv-ui .settings-detail .settings-shortcuts { display: none; }
.tv-ui .settings-forms { width: 66%; margin: 0; }
.tv-ui .settings-back { margin: 0 0 12px; }
.tv-ui .settings-shortcuts { display: flex; flex-wrap: wrap; width: auto; }
.tv-ui .settings-shortcuts button { flex: 0 0 30%; min-height: 86px; margin: 8px; }
.tv-ui button:focus, .tv-ui input:focus, .tv-ui a:focus, .tv-ui summary:focus {
  outline: 3px solid #fff; outline-offset: 2px;
}

.tv-shortcuts { display: flex; flex-wrap: wrap; padding: 12px 6px; }
.tv-key { margin: 0 8px 6px 0; padding: 5px 10px; }
.tv-key::before { content: ''; display: inline-block; width: .7em; height: .7em; border-radius: 50%; margin-right: .5em; }
.tv-key-0::before { background: #ff535a; }
.tv-key-1::before { background: #5ee390; }
.tv-key-2::before { background: #ffe066; }
.tv-key-3::before { background: #5ba9ff; }
.tv-key-feedback { padding: 6px; }
.tv-ui input[type=checkbox]:focus { outline: 3px solid white; outline-offset: 4px; }

.tv-ui .live-layout .stack { display: block; overflow: auto; }
.tv-ui .live-layout .stack button { width: 100%; min-height: 42px; margin-bottom: 5px; }
.tv-ui .live-layout .stack .ui-icon { margin-right: .45em; }

.tv-ui #player[open] {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  width: 100vw; height: 100vh; max-width: none; max-height: none;
  margin: 0; padding: 0; background: #000; border: 0; border-radius: 0; overflow: hidden;
}
.tv-ui #player video { display: block; width: 100%; height: 100%; max-height: none; object-fit: contain; }
.tv-ui #player #playing, .tv-ui #player #error, .tv-ui #player #retry,
.tv-player-actions { position: absolute; z-index: 2; }
.tv-ui #player #playing { top: 3%; left: 4%; right: 4%; margin: 0; padding: 12px; background: rgba(0,0,0,.75); }
.tv-ui #player #error { left: 4%; bottom: 17%; background: rgba(0,0,0,.8); padding: 10px; }
.tv-ui #player #retry { left: 4%; bottom: 11%; }
.tv-player-actions { left: 4%; right: 4%; bottom: 4%; text-align: center; }
.tv-player-actions button { margin: 0 5px; min-width: 100px; background: #281939; }
.tv-ui #player #close { float: none; }
.tv-ui #player:not(.tv-controls-visible) #playing,
.tv-ui #player:not(.tv-controls-visible) .tv-player-actions { opacity: 0; }
.tv-ui .channel-name img { flex: 0 0 48px; width: 48px; height: 32px; max-width: 48px; max-height: 32px; margin-right: 8px; object-fit: contain; }
.tv-ui .guide-line .channel-name img { width: 34px; max-width: 34px; height: 24px; max-height: 24px; flex-basis: 34px; }
.tv-ui .film-categories { display: block; width: 23%; max-height: 55vh; overflow-y: auto; padding: 5px; }
.tv-ui .film-categories button { display: block; width: 100%; min-height: 40px; margin: 0 0 6px; }
.tv-ui .films-layout { display: flex; }
.tv-ui .film-rows { flex: 1; min-width: 0; }
.tv-ui .film-hero img { object-fit: contain; }
.tv-ui .featured-row .portrait-source img { object-fit: contain; }
.tv-ui .grid { display: flex; flex-wrap: wrap; }
.tv-ui .grid .tile { flex: 0 0 15%; width: 15%; height: 16vw; margin: 0 1% 12px 0; }
.tv-ui .tile-caption.with-title { background: rgba(14,9,23,.84); padding-top: 7px; padding-bottom: 7px; }
.tv-ui .list-library { max-width: 900px; }
.tv-ui .settings-shortcuts { display: flex; flex-flow: row wrap; }

.tv-ui .sidebar { height: auto; top: auto; }
.tv-ui .header-meta { gap: 0; }
.tv-ui .clock time, .tv-ui .clock small { display: block; }
.tv-ui .series-categories .stack { display: block; }
